Skip to content

Commit 7e044b1

Browse files
authored
feat(remix): Add release / sourcemap upload script. (#5312)
Adds a mini CLI tool to create releases and upload Remix sourcemaps with a default path / prefix. Uses `sentry-cli` under the hood and requires a valid `.sentryclirc` to work. Usage: ```sh $ upload-sourcemaps Usage: upload-sourcemaps --release RELEASE [--urlPrefix URL_PREFIX] [--buildPath BUILD_PATH] Options: --help Show help [boolean] --version Show version number [boolean] --release The release number [string] [required] --urlPrefix The url prefix for the sourcemaps [string] --buildPath The path to the build directory [string] ``` Also removed `webpack`-related dependencies from Remix SDK, as we don't need them.
1 parent 893e157 commit 7e044b1

File tree

5 files changed

+229
-21
lines changed

5 files changed

+229
-21
lines changed

packages/remix/package.json

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/remix",
77
"author": "Sentry",
88
"license": "MIT",
9+
"bin": {
10+
"upload-sourcemaps": "scripts/upload-sourcemaps.js"
11+
},
912
"engines": {
1013
"node": ">=14"
1114
},
@@ -15,6 +18,7 @@
1518
"types": "build/types/index.server.d.ts",
1619
"private": true,
1720
"dependencies": {
21+
"@sentry/cli": "2.2.0",
1822
"@sentry/core": "7.3.1",
1923
"@sentry/hub": "7.3.1",
2024
"@sentry/integrations": "7.3.1",
@@ -28,19 +32,12 @@
2832
},
2933
"devDependencies": {
3034
"@remix-run/node": "^1.4.3",
31-
"@remix-run/react": "^1.4.3",
32-
"@types/webpack": "^4.41.31"
35+
"@remix-run/react": "^1.4.3"
3336
},
3437
"peerDependencies": {
3538
"@remix-run/node": "^1.4.3",
3639
"@remix-run/react": "^1.4.3",
37-
"react": "16.x || 17.x || 18.x",
38-
"webpack": ">=4.0.0"
39-
},
40-
"peerDependenciesMeta": {
41-
"webpack": {
42-
"optional": true
43-
}
40+
"react": "16.x || 17.x || 18.x"
4441
},
4542
"scripts": {
4643
"build": "run-p build:rollup build:types",
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const SentryCli = require('@sentry/cli');
2+
const sentry = new SentryCli();
3+
4+
async function createRelease(argv, DEFAULT_URL_PREFIX, DEFAULT_BUILD_PATH) {
5+
const RELEASE = argv.release || (await sentry.releases.proposeVersion());
6+
const URL_PREFIX = argv.urlPrefix || DEFAULT_URL_PREFIX;
7+
const BUILD_PATH = argv.buildPath || DEFAULT_BUILD_PATH;
8+
9+
await sentry.releases.new(RELEASE);
10+
11+
await sentry.releases.uploadSourceMaps(RELEASE, {
12+
urlPrefix: URL_PREFIX,
13+
include: [BUILD_PATH],
14+
});
15+
16+
await sentry.releases.finalize(RELEASE);
17+
}
18+
19+
module.exports = {
20+
createRelease,
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env node
2+
const yargs = require('yargs');
3+
4+
const { createRelease } = require('./createRelease');
5+
6+
const DEFAULT_URL_PREFIX = '~/build/';
7+
const DEFAULT_BUILD_PATH = 'public/build';
8+
9+
const argv = yargs(process.argv.slice(2))
10+
.option('release', {
11+
type: 'string',
12+
describe:
13+
'The release number\n' +
14+
"If not provided, a new release id will be determined by Sentry CLI's `propose-version`.\n" +
15+
'See: https://docs.sentry.io/product/releases/suspect-commits/#using-the-cli\n',
16+
})
17+
.option('urlPrefix', {
18+
type: 'string',
19+
describe: 'URL prefix to add to the beginning of all filenames',
20+
default: DEFAULT_URL_PREFIX,
21+
})
22+
.option('buildPath', {
23+
type: 'string',
24+
describe: 'The path to the build directory',
25+
default: DEFAULT_BUILD_PATH,
26+
})
27+
.usage(
28+
'Usage: $0\n' +
29+
' [--release RELEASE]\n' +
30+
' [--urlPrefix URL_PREFIX]\n' +
31+
' [--buildPath BUILD_PATH]\n\n' +
32+
'This CLI tool will upload sourcemaps to Sentry for the given release.\n' +
33+
'It has defaults for URL prefix and build path for Remix builds, but you can override them.\n\n' +
34+
'If you need a more advanced configuration, you can use `sentry-cli` instead.\n' +
35+
'https://github.com/getsentry/sentry-cli',
36+
)
37+
.wrap(120).argv;
38+
39+
createRelease(argv, DEFAULT_URL_PREFIX, DEFAULT_BUILD_PATH);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const newMock = jest.fn();
2+
const uploadSourceMapsMock = jest.fn();
3+
const finalizeMock = jest.fn();
4+
const proposeVersionMock = jest.fn(() => '0.1.2.3.4');
5+
6+
jest.mock('@sentry/cli', () => {
7+
return jest.fn().mockImplementation(() => {
8+
return {
9+
execute: jest.fn(),
10+
releases: {
11+
new: newMock,
12+
uploadSourceMaps: uploadSourceMapsMock,
13+
finalize: finalizeMock,
14+
proposeVersion: proposeVersionMock,
15+
},
16+
};
17+
});
18+
});
19+
20+
// eslint-disable-next-line @typescript-eslint/no-var-requires
21+
const { createRelease } = require('../../scripts/createRelease');
22+
23+
beforeEach(() => {
24+
newMock.mockClear();
25+
uploadSourceMapsMock.mockClear();
26+
finalizeMock.mockClear();
27+
proposeVersionMock.mockClear();
28+
});
29+
30+
describe('createRelease', () => {
31+
it('should use release param when given', async () => {
32+
await createRelease({ release: '0.1.2.3' }, '~/build/', 'public/build');
33+
34+
expect(proposeVersionMock).not.toHaveBeenCalled();
35+
expect(newMock).toHaveBeenCalledWith('0.1.2.3');
36+
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3', {
37+
urlPrefix: '~/build/',
38+
include: ['public/build'],
39+
});
40+
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3');
41+
});
42+
43+
it('should call `proposeVersion` when release param is not given.', async () => {
44+
await createRelease({}, '~/build/', 'public/build');
45+
46+
expect(proposeVersionMock).toHaveBeenCalled();
47+
expect(newMock).toHaveBeenCalledWith('0.1.2.3.4');
48+
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
49+
urlPrefix: '~/build/',
50+
include: ['public/build'],
51+
});
52+
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3.4');
53+
});
54+
55+
it('should use given buildPath and urlPrefix over the defaults when given.', async () => {
56+
await createRelease(
57+
{
58+
urlPrefix: '~/build/subfolder',
59+
buildPath: 'public/build/subfolder',
60+
},
61+
'~/build/',
62+
'public/build',
63+
);
64+
65+
expect(proposeVersionMock).toHaveBeenCalled();
66+
expect(newMock).toHaveBeenCalledWith('0.1.2.3.4');
67+
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
68+
urlPrefix: '~/build/subfolder',
69+
include: ['public/build/subfolder'],
70+
});
71+
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3.4');
72+
});
73+
});
74+
75+
// To avoid `--isolatedModules` flag as we're not importing
76+
// anything for these tests.
77+
export {};

yarn.lock

+86-12
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,18 @@
44204420
semver "7.3.2"
44214421
semver-intersect "1.4.0"
44224422

4423+
4424+
version "2.2.0"
4425+
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-2.2.0.tgz#0cf4d529d87e290dea54d7e58fa5ff87ea200e4e"
4426+
integrity sha512-ywFtB8VHyWN248LuM67fsRtdMLif/SOHYY3zyef5WybvnAmRLDmGTWK//hSUCebsHBpehRIkmt4iMiyUXwgd5w==
4427+
dependencies:
4428+
https-proxy-agent "^5.0.0"
4429+
node-fetch "^2.6.7"
4430+
npmlog "^6.0.1"
4431+
progress "^2.0.3"
4432+
proxy-from-env "^1.1.0"
4433+
which "^2.0.2"
4434+
44234435
"@sentry/cli@^1.74.4":
44244436
version "1.74.4"
44254437
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.74.4.tgz#7df82f68045a155e1885bfcbb5d303e5259eb18e"
@@ -6353,11 +6365,19 @@ aproba@^1.0.3, aproba@^1.1.1:
63536365
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
63546366
integrity sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==
63556367

6356-
aproba@^2.0.0:
6368+
"aproba@^1.0.3 || ^2.0.0", aproba@^2.0.0:
63576369
version "2.0.0"
63586370
resolved "https://registry.yarnpkg.com/aproba/-/aproba-2.0.0.tgz#52520b8ae5b569215b354efc0caa3fe1e45a8adc"
63596371
integrity sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==
63606372

6373+
are-we-there-yet@^3.0.0:
6374+
version "3.0.0"
6375+
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz#ba20bd6b553e31d62fc8c31bd23d22b95734390d"
6376+
integrity sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw==
6377+
dependencies:
6378+
delegates "^1.0.0"
6379+
readable-stream "^3.6.0"
6380+
63616381
are-we-there-yet@~1.1.2:
63626382
version "1.1.5"
63636383
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz#4b35c2944f062a8bfcda66410760350fe9ddfc21"
@@ -9421,6 +9441,11 @@ color-string@^1.5.4:
94219441
color-name "^1.0.0"
94229442
simple-swizzle "^0.2.2"
94239443

9444+
color-support@^1.1.3:
9445+
version "1.1.3"
9446+
resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2"
9447+
integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==
9448+
94249449
color@^3.0.0:
94259450
version "3.1.3"
94269451
resolved "https://registry.yarnpkg.com/color/-/color-3.1.3.tgz#ca67fb4e7b97d611dcde39eceed422067d91596e"
@@ -9651,7 +9676,7 @@ console-browserify@^1.1.0:
96519676
resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.2.0.tgz#67063cef57ceb6cf4993a2ab3a55840ae8c49336"
96529677
integrity sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==
96539678

9654-
console-control-strings@^1.0.0, console-control-strings@~1.1.0:
9679+
console-control-strings@^1.0.0, console-control-strings@^1.1.0, console-control-strings@~1.1.0:
96559680
version "1.1.0"
96569681
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
96579682
integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=
@@ -13633,6 +13658,20 @@ functions-have-names@^1.2.2:
1363313658
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
1363413659
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
1363513660

13661+
gauge@^4.0.3:
13662+
version "4.0.4"
13663+
resolved "https://registry.yarnpkg.com/gauge/-/gauge-4.0.4.tgz#52ff0652f2bbf607a989793d53b751bef2328dce"
13664+
integrity sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==
13665+
dependencies:
13666+
aproba "^1.0.3 || ^2.0.0"
13667+
color-support "^1.1.3"
13668+
console-control-strings "^1.1.0"
13669+
has-unicode "^2.0.1"
13670+
signal-exit "^3.0.7"
13671+
string-width "^4.2.3"
13672+
strip-ansi "^6.0.1"
13673+
wide-align "^1.1.5"
13674+
1363613675
gauge@~2.7.3:
1363713676
version "2.7.4"
1363813677
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
@@ -19409,6 +19448,16 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1:
1940919448
gauge "~2.7.3"
1941019449
set-blocking "~2.0.0"
1941119450

19451+
npmlog@^6.0.1:
19452+
version "6.0.2"
19453+
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-6.0.2.tgz#c8166017a42f2dea92d6453168dd865186a70830"
19454+
integrity sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==
19455+
dependencies:
19456+
are-we-there-yet "^3.0.0"
19457+
console-control-strings "^1.1.0"
19458+
gauge "^4.0.3"
19459+
set-blocking "^2.0.0"
19460+
1941219461
nth-check@^1.0.2:
1941319462
version "1.0.2"
1941419463
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.2.tgz#b2bd295c37e3dd58a3bf0700376663ba4d9cf05c"
@@ -23141,7 +23190,7 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
2314123190
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
2314223191
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==
2314323192

23144-
signal-exit@^3.0.3:
23193+
signal-exit@^3.0.3, signal-exit@^3.0.7:
2314523194
version "3.0.7"
2314623195
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
2314723196
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
@@ -23983,6 +24032,15 @@ string-width@^1.0.1:
2398324032
is-fullwidth-code-point "^2.0.0"
2398424033
strip-ansi "^4.0.0"
2398524034

24035+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.2.2, string-width@^4.2.3:
24036+
version "4.2.3"
24037+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
24038+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
24039+
dependencies:
24040+
emoji-regex "^8.0.0"
24041+
is-fullwidth-code-point "^3.0.0"
24042+
strip-ansi "^6.0.1"
24043+
2398624044
string-width@^3.0.0, string-width@^3.1.0:
2398724045
version "3.1.0"
2398824046
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
@@ -23992,15 +24050,6 @@ string-width@^3.0.0, string-width@^3.1.0:
2399224050
is-fullwidth-code-point "^2.0.0"
2399324051
strip-ansi "^5.1.0"
2399424052

23995-
string-width@^4.0.0, string-width@^4.2.2:
23996-
version "4.2.3"
23997-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
23998-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
23999-
dependencies:
24000-
emoji-regex "^8.0.0"
24001-
is-fullwidth-code-point "^3.0.0"
24002-
strip-ansi "^6.0.1"
24003-
2400424053
string-width@^4.1.0, string-width@^4.2.0:
2400524054
version "4.2.2"
2400624055
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5"
@@ -26359,6 +26408,13 @@ [email protected], wide-align@^1.1.0:
2635926408
dependencies:
2636026409
string-width "^1.0.2 || 2"
2636126410

26411+
wide-align@^1.1.5:
26412+
version "1.1.5"
26413+
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3"
26414+
integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==
26415+
dependencies:
26416+
string-width "^1.0.2 || 2 || 3 || 4"
26417+
2636226418
widest-line@^3.1.0:
2636326419
version "3.1.0"
2636426420
resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca"
@@ -26668,6 +26724,11 @@ yargs-parser@^20.2.3:
2666826724
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a"
2666926725
integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==
2667026726

26727+
yargs-parser@^21.0.0:
26728+
version "21.0.1"
26729+
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
26730+
integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==
26731+
2667126732
2667226733
version "1.6.0"
2667326734
resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-1.6.0.tgz#ef25c2c769ff6bd09e4b0f9d7c605fb27846ea9f"
@@ -26741,6 +26802,19 @@ yargs@^16.1.1, yargs@^16.2.0:
2674126802
y18n "^5.0.5"
2674226803
yargs-parser "^20.2.2"
2674326804

26805+
yargs@^17.5.1:
26806+
version "17.5.1"
26807+
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.5.1.tgz#e109900cab6fcb7fd44b1d8249166feb0b36e58e"
26808+
integrity sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==
26809+
dependencies:
26810+
cliui "^7.0.2"
26811+
escalade "^3.1.1"
26812+
get-caller-file "^2.0.5"
26813+
require-directory "^2.1.1"
26814+
string-width "^4.2.3"
26815+
y18n "^5.0.5"
26816+
yargs-parser "^21.0.0"
26817+
2674426818
yauzl@^2.10.0:
2674526819
version "2.10.0"
2674626820
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"

0 commit comments

Comments
 (0)