Skip to content

Commit e272af9

Browse files
committed
Switch to TypeScript and add unit tests.
1 parent dbfaf4c commit e272af9

File tree

7 files changed

+213
-37
lines changed

7 files changed

+213
-37
lines changed

packages/remix/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"author": "Sentry",
88
"license": "MIT",
99
"bin": {
10-
"sentry-upload-sourcemaps": "scripts/upload-sourcemaps.js"
10+
"upload-sourcemaps": "build/cjs/scripts/upload-sourcemaps.js"
1111
},
1212
"engines": {
1313
"node": ">=14"
@@ -18,6 +18,7 @@
1818
"types": "build/types/index.server.d.ts",
1919
"private": true,
2020
"dependencies": {
21+
"@sentry/cli": "2.2.0",
2122
"@sentry/core": "7.3.1",
2223
"@sentry/hub": "7.3.1",
2324
"@sentry/integrations": "7.3.1",
@@ -31,7 +32,8 @@
3132
},
3233
"devDependencies": {
3334
"@remix-run/node": "^1.4.3",
34-
"@remix-run/react": "^1.4.3"
35+
"@remix-run/react": "^1.4.3",
36+
"rollup-plugin-hashbang": "^3.0.0"
3537
},
3638
"peerDependencies": {
3739
"@remix-run/node": "^1.4.3",

packages/remix/rollup.npm.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import hashbang from 'rollup-plugin-hashbang';
2+
13
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';
24

35
export default makeNPMConfigVariants(
46
makeBaseNPMConfig({
5-
entrypoints: ['src/index.server.ts', 'src/index.client.tsx'],
7+
entrypoints: ['src/index.server.ts', 'src/index.client.tsx', 'scripts/upload-sourcemaps.ts'],
8+
packageSpecificConfig: {
9+
// Rollup fails when there's a hashbang in the file
10+
// Ref: https://github.com/rollup/rollup/issues/235
11+
// This plugin also gives execution permissions to the output files.
12+
plugins: [hashbang()],
13+
},
614
}),
715
);
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import SentryCliModule from '@sentry/cli';
2+
// Note: ESM import of '@sentry/cli' causes a:
3+
// `TypeError: SentryCli.default is not a constructor`
4+
// When the script is used.
5+
// Probably because the TS types and the actual module mixes up.
6+
// This is a workaround for that.
7+
//
8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
9+
const SentryCli = require('@sentry/cli') as typeof SentryCliModule;
10+
const sentry = new SentryCli();
11+
12+
export async function createRelease(
13+
argv: { release?: string; urlPrefix?: string; buildPath?: string },
14+
DEFAULT_URL_PREFIX: string,
15+
DEFAULT_BUILD_PATH: string,
16+
): Promise<void> {
17+
const RELEASE = argv.release || (await sentry.releases.proposeVersion());
18+
const URL_PREFIX = argv.urlPrefix || DEFAULT_URL_PREFIX;
19+
const BUILD_PATH = argv.buildPath || DEFAULT_BUILD_PATH;
20+
21+
await sentry.releases.new(RELEASE);
22+
23+
await sentry.releases.uploadSourceMaps(RELEASE, {
24+
urlPrefix: URL_PREFIX,
25+
include: [BUILD_PATH],
26+
});
27+
28+
await sentry.releases.finalize(RELEASE);
29+
}

packages/remix/scripts/upload-sourcemaps.js renamed to packages/remix/scripts/upload-sourcemaps.ts

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#! /usr/bin/env node
2-
const SentryCli = require('@sentry/cli');
3-
const yargs = require('yargs/yargs');
1+
#!/usr/bin/env node
2+
import yargs from 'yargs';
3+
4+
import { createRelease } from './createRelease';
45

56
const DEFAULT_URL_PREFIX = '~/build/';
67
const DEFAULT_BUILD_PATH = 'public/build';
@@ -35,21 +36,4 @@ const argv = yargs(process.argv.slice(2))
3536
)
3637
.wrap(120).argv;
3738

38-
const sentry = new SentryCli();
39-
40-
async function createRelease() {
41-
const RELEASE = argv.release || (await sentry.releases.proposeVersion());
42-
const URL_PREFIX = argv.urlPrefix || DEFAULT_URL_PREFIX;
43-
const BUILD_PATH = argv.buildPath || DEFAULT_BUILD_PATH;
44-
45-
await sentry.releases.new(RELEASE);
46-
47-
await sentry.releases.uploadSourceMaps(RELEASE, {
48-
urlPrefix: URL_PREFIX,
49-
include: [BUILD_PATH],
50-
});
51-
52-
await sentry.releases.finalize(RELEASE);
53-
}
54-
55-
createRelease();
39+
void createRelease(argv, DEFAULT_URL_PREFIX, DEFAULT_BUILD_PATH);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
import { createRelease } from '../../scripts/createRelease';
21+
22+
beforeEach(() => {
23+
newMock.mockClear();
24+
uploadSourceMapsMock.mockClear();
25+
finalizeMock.mockClear();
26+
proposeVersionMock.mockClear();
27+
});
28+
29+
describe('createRelease', () => {
30+
it('should use release param when given', async () => {
31+
await createRelease({ release: '0.1.2.3' }, '~/build/', 'public/build');
32+
33+
expect(proposeVersionMock).not.toHaveBeenCalled();
34+
expect(newMock).toHaveBeenCalledWith('0.1.2.3');
35+
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3', {
36+
urlPrefix: '~/build/',
37+
include: ['public/build'],
38+
});
39+
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3');
40+
});
41+
42+
it('should call `proposeVersion` when release param is not given.', async () => {
43+
await createRelease({}, '~/build/', 'public/build');
44+
45+
expect(proposeVersionMock).toHaveBeenCalled();
46+
expect(newMock).toHaveBeenCalledWith('0.1.2.3.4');
47+
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
48+
urlPrefix: '~/build/',
49+
include: ['public/build'],
50+
});
51+
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3.4');
52+
});
53+
54+
it('should use given buildPath and urlPrefix over the defaults when given.', async () => {
55+
await createRelease(
56+
{
57+
urlPrefix: '~/build/subfolder',
58+
buildPath: 'public/build/subfolder',
59+
},
60+
'~/build/',
61+
'public/build',
62+
);
63+
64+
expect(proposeVersionMock).toHaveBeenCalled();
65+
expect(newMock).toHaveBeenCalledWith('0.1.2.3.4');
66+
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
67+
urlPrefix: '~/build/subfolder',
68+
include: ['public/build/subfolder'],
69+
});
70+
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3.4');
71+
});
72+
});

packages/remix/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33

4-
"include": ["src/**/*"],
4+
"include": ["src/**/*", "scripts/**/*"],
55

66
"compilerOptions": {
77
"jsx": "react"

yarn.lock

+93-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"
@@ -22585,6 +22634,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
2258522634
hash-base "^3.0.0"
2258622635
inherits "^2.0.1"
2258722636

22637+
rollup-plugin-hashbang@^3.0.0:
22638+
version "3.0.0"
22639+
resolved "https://registry.yarnpkg.com/rollup-plugin-hashbang/-/rollup-plugin-hashbang-3.0.0.tgz#6173df959592ba73d2e8ce01816a37c511a5e005"
22640+
integrity sha512-nNC2NeNcvkklPhPCUF8Yb+2a19xI0dSBBJJ2x814+Al2BqIEWOyaGIgEjPVSjjgxhoabkJC5vbO4AeI3cxx3wg==
22641+
dependencies:
22642+
magic-string "^0.25.7"
22643+
2258822644
rollup-plugin-license@^2.6.1:
2258922645
version "2.6.1"
2259022646
resolved "https://registry.yarnpkg.com/rollup-plugin-license/-/rollup-plugin-license-2.6.1.tgz#20f15cc37950f362f8eefdc6e3a2e659d0cad9eb"
@@ -23141,7 +23197,7 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
2314123197
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
2314223198
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==
2314323199

23144-
signal-exit@^3.0.3:
23200+
signal-exit@^3.0.3, signal-exit@^3.0.7:
2314523201
version "3.0.7"
2314623202
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
2314723203
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
@@ -23983,6 +24039,15 @@ string-width@^1.0.1:
2398324039
is-fullwidth-code-point "^2.0.0"
2398424040
strip-ansi "^4.0.0"
2398524041

24042+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.2.2, string-width@^4.2.3:
24043+
version "4.2.3"
24044+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
24045+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
24046+
dependencies:
24047+
emoji-regex "^8.0.0"
24048+
is-fullwidth-code-point "^3.0.0"
24049+
strip-ansi "^6.0.1"
24050+
2398624051
string-width@^3.0.0, string-width@^3.1.0:
2398724052
version "3.1.0"
2398824053
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
@@ -23992,15 +24057,6 @@ string-width@^3.0.0, string-width@^3.1.0:
2399224057
is-fullwidth-code-point "^2.0.0"
2399324058
strip-ansi "^5.1.0"
2399424059

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-
2400424060
string-width@^4.1.0, string-width@^4.2.0:
2400524061
version "4.2.2"
2400624062
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5"
@@ -26359,6 +26415,13 @@ [email protected], wide-align@^1.1.0:
2635926415
dependencies:
2636026416
string-width "^1.0.2 || 2"
2636126417

26418+
wide-align@^1.1.5:
26419+
version "1.1.5"
26420+
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3"
26421+
integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==
26422+
dependencies:
26423+
string-width "^1.0.2 || 2 || 3 || 4"
26424+
2636226425
widest-line@^3.1.0:
2636326426
version "3.1.0"
2636426427
resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca"
@@ -26668,6 +26731,11 @@ yargs-parser@^20.2.3:
2666826731
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a"
2666926732
integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==
2667026733

26734+
yargs-parser@^21.0.0:
26735+
version "21.0.1"
26736+
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
26737+
integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==
26738+
2667126739
2667226740
version "1.6.0"
2667326741
resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-1.6.0.tgz#ef25c2c769ff6bd09e4b0f9d7c605fb27846ea9f"
@@ -26741,6 +26809,19 @@ yargs@^16.1.1, yargs@^16.2.0:
2674126809
y18n "^5.0.5"
2674226810
yargs-parser "^20.2.2"
2674326811

26812+
yargs@^17.5.1:
26813+
version "17.5.1"
26814+
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.5.1.tgz#e109900cab6fcb7fd44b1d8249166feb0b36e58e"
26815+
integrity sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==
26816+
dependencies:
26817+
cliui "^7.0.2"
26818+
escalade "^3.1.1"
26819+
get-caller-file "^2.0.5"
26820+
require-directory "^2.1.1"
26821+
string-width "^4.2.3"
26822+
y18n "^5.0.5"
26823+
yargs-parser "^21.0.0"
26824+
2674426825
yauzl@^2.10.0:
2674526826
version "2.10.0"
2674626827
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"

0 commit comments

Comments
 (0)