Skip to content

Commit b5de8fc

Browse files
committed
feat(remix): Add debugid injection and map deletion to sourcemaps script
1 parent 448406a commit b5de8fc

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

packages/remix/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"access": "public"
2828
},
2929
"dependencies": {
30-
"@sentry/cli": "2.2.0",
30+
"@sentry/cli": "2.20.4",
3131
"@sentry/core": "7.64.0",
3232
"@sentry/node": "7.64.0",
3333
"@sentry/react": "7.64.0",

packages/remix/scripts/createRelease.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1+
/* eslint-disable no-console */
12
const SentryCli = require('@sentry/cli');
3+
4+
const { deleteSourcemaps } = require('./deleteSourcemaps');
5+
26
const sentry = new SentryCli();
37

4-
async function createRelease(argv, DEFAULT_URL_PREFIX, DEFAULT_BUILD_PATH) {
8+
async function createRelease(argv, URL_PREFIX, BUILD_PATH) {
59
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;
810

911
await sentry.releases.new(RELEASE);
1012

1113
await sentry.releases.uploadSourceMaps(RELEASE, {
1214
urlPrefix: URL_PREFIX,
1315
include: [BUILD_PATH],
16+
useArtifactBundle: !argv.disableDebugIds,
1417
});
1518

1619
await sentry.releases.finalize(RELEASE);
20+
21+
if (argv.deleteAfterUpload) {
22+
try {
23+
deleteSourcemaps(BUILD_PATH);
24+
} catch (error) {
25+
console.warn(`Failed to delete sourcemaps in build directory: ${BUILD_PATH}`);
26+
console.error(error);
27+
}
28+
}
1729
}
1830

1931
module.exports = {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-disable no-console */
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
function deleteSourcemaps(buildPath) {
6+
console.info(`Deleting sourcemaps from ${buildPath}`);
7+
8+
const files = fs.readdirSync(buildPath);
9+
10+
files.forEach(file => {
11+
if (file.endsWith('.map')) {
12+
fs.unlinkSync(path.join(buildPath, file));
13+
14+
console.info(`Deleted ${file}`);
15+
}
16+
});
17+
}
18+
19+
module.exports = {
20+
deleteSourcemaps,
21+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable no-console */
2+
const { execSync } = require('child_process');
3+
4+
function injectDebugId(buildPath) {
5+
try {
6+
execSync(`node ./node_modules/@sentry/cli/bin/sentry-cli sourcemaps inject ${buildPath}`);
7+
} catch (error) {
8+
console.warn('Failed to inject debug ids.');
9+
console.error(error);
10+
}
11+
}
12+
13+
module.exports = {
14+
injectDebugId,
15+
};

packages/remix/scripts/sentry-upload-sourcemaps.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env node
2+
/* eslint-disable no-console */
23
const yargs = require('yargs');
34

45
const { createRelease } = require('./createRelease');
6+
const { injectDebugId } = require('./injectDebugId');
57

68
const DEFAULT_URL_PREFIX = '~/build/';
79
const DEFAULT_BUILD_PATH = 'public/build';
@@ -24,16 +26,35 @@ const argv = yargs(process.argv.slice(2))
2426
describe: 'The path to the build directory',
2527
default: DEFAULT_BUILD_PATH,
2628
})
29+
.option('disableDebugIds', {
30+
type: 'boolean',
31+
describe: 'Disable the injection and upload of debug ids',
32+
default: false,
33+
})
34+
.option('deleteAfterUpload', {
35+
type: 'boolean',
36+
describe: 'Delete sourcemaps after uploading',
37+
default: true,
38+
})
2739
.usage(
2840
'Usage: $0\n' +
2941
' [--release RELEASE]\n' +
3042
' [--urlPrefix URL_PREFIX]\n' +
3143
' [--buildPath BUILD_PATH]\n\n' +
44+
' [--disableDebugIds true|false]\n\n' +
45+
' [--deleteAfterUpload true|false]\n\n' +
3246
'This CLI tool will upload sourcemaps to Sentry for the given release.\n' +
3347
'It has defaults for URL prefix and build path for Remix builds, but you can override them.\n\n' +
3448
'If you need a more advanced configuration, you can use `sentry-cli` instead.\n' +
3549
'https://github.com/getsentry/sentry-cli',
3650
)
3751
.wrap(120).argv;
3852

39-
createRelease(argv, DEFAULT_URL_PREFIX, DEFAULT_BUILD_PATH);
53+
const buildPath = argv.buildPath || DEFAULT_BUILD_PATH;
54+
const urlPrefix = argv.urlPrefix || DEFAULT_URL_PREFIX;
55+
56+
if (!argv.disableDebugIds) {
57+
injectDebugId(buildPath);
58+
}
59+
60+
createRelease(argv, urlPrefix, buildPath);

packages/remix/test/scripts/upload-sourcemaps.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('createRelease', () => {
3636
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3', {
3737
urlPrefix: '~/build/',
3838
include: ['public/build'],
39+
useArtifactBundle: true,
3940
});
4041
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3');
4142
});
@@ -48,6 +49,7 @@ describe('createRelease', () => {
4849
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
4950
urlPrefix: '~/build/',
5051
include: ['public/build'],
52+
useArtifactBundle: true,
5153
});
5254
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3.4');
5355
});
@@ -67,6 +69,7 @@ describe('createRelease', () => {
6769
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
6870
urlPrefix: '~/build/subfolder',
6971
include: ['public/build/subfolder'],
72+
useArtifactBundle: true,
7073
});
7174
expect(finalizeMock).toHaveBeenCalledWith('0.1.2.3.4');
7275
});

yarn.lock

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,14 +4428,13 @@
44284428
unplugin "1.0.1"
44294429
webpack-sources "3.2.3"
44304430

4431-
"@sentry/cli@2.2.0":
4432-
version "2.2.0"
4433-
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-2.2.0.tgz#0cf4d529d87e290dea54d7e58fa5ff87ea200e4e"
4434-
integrity sha512-ywFtB8VHyWN248LuM67fsRtdMLif/SOHYY3zyef5WybvnAmRLDmGTWK//hSUCebsHBpehRIkmt4iMiyUXwgd5w==
4431+
"@sentry/cli@2.20.4":
4432+
version "2.20.4"
4433+
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-2.20.4.tgz#755719aeaa58dbd3910ee23cc020decc16f5a5bf"
4434+
integrity sha512-mycBCKQmLdaJpSKpXc3IXrQwb5HLxrdjgJgLGbb8saFHIkXl/1ePH171j+REq4dIP1uetu0bdDgEYj6AQjkleQ==
44354435
dependencies:
44364436
https-proxy-agent "^5.0.0"
44374437
node-fetch "^2.6.7"
4438-
npmlog "^6.0.1"
44394438
progress "^2.0.3"
44404439
proxy-from-env "^1.1.0"
44414440
which "^2.0.2"
@@ -20552,7 +20551,7 @@ npmlog@^4.1.2:
2055220551
gauge "~2.7.3"
2055320552
set-blocking "~2.0.0"
2055420553

20555-
npmlog@^6.0.0, npmlog@^6.0.1, npmlog@^6.0.2:
20554+
npmlog@^6.0.0, npmlog@^6.0.2:
2055620555
version "6.0.2"
2055720556
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-6.0.2.tgz#c8166017a42f2dea92d6453168dd865186a70830"
2055820557
integrity sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==

0 commit comments

Comments
 (0)