Skip to content

Commit 5fdaaa7

Browse files
authored
feat(remix): Add debugid injection and map deletion to sourcemaps script (#8814)
Updated `sentry-upload-sourcemaps` script: - Updated `sentry-cli` to: `2.20.4` - Added a script to Inject debugids invoking `sentry-cli` (as this feature is not available in JS SDK of `sentry-cli` yet) - Added a script to delete sourcemaps after uploading them to Sentry. (default is to delete, created a new flag to prevent deletion)
1 parent 32befda commit 5fdaaa7

File tree

7 files changed

+90
-15
lines changed

7 files changed

+90
-15
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.5",
3131
"@sentry/core": "7.66.0",
3232
"@sentry/node": "7.66.0",
3333
"@sentry/react": "7.66.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(`[sentry] Failed to delete sourcemaps in build directory: ${BUILD_PATH}`);
26+
console.error(error);
27+
}
28+
}
1729
}
1830

1931
module.exports = {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable no-console */
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const glob = require('glob');
6+
7+
function deleteSourcemaps(buildPath) {
8+
console.info(`[sentry] Deleting sourcemaps from ${buildPath}`);
9+
10+
// Delete all .map files in the build folder and its subfolders
11+
const mapFiles = glob.sync('**/*.map', { cwd: buildPath });
12+
13+
mapFiles.forEach(file => {
14+
fs.unlinkSync(path.join(buildPath, file));
15+
16+
console.info(`[sentry] Deleted ${file}`);
17+
});
18+
}
19+
20+
module.exports = {
21+
deleteSourcemaps,
22+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable no-console */
2+
const { execSync } = require('child_process');
3+
4+
const SentryCli = require('@sentry/cli');
5+
6+
function injectDebugId(buildPath) {
7+
const cliPath = SentryCli.getPath();
8+
9+
try {
10+
execSync(`${cliPath} sourcemaps inject ${buildPath}`);
11+
} catch (error) {
12+
console.warn('[sentry] Failed to inject debug ids.');
13+
console.error(error);
14+
}
15+
}
16+
17+
module.exports = {
18+
injectDebugId,
19+
};

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const yargs = require('yargs');
33

44
const { createRelease } = require('./createRelease');
5+
const { injectDebugId } = require('./injectDebugId');
56

67
const DEFAULT_URL_PREFIX = '~/build/';
78
const DEFAULT_BUILD_PATH = 'public/build';
@@ -24,16 +25,35 @@ const argv = yargs(process.argv.slice(2))
2425
describe: 'The path to the build directory',
2526
default: DEFAULT_BUILD_PATH,
2627
})
28+
.option('disableDebugIds', {
29+
type: 'boolean',
30+
describe: 'Disable the injection and upload of debug ids',
31+
default: false,
32+
})
33+
.option('deleteAfterUpload', {
34+
type: 'boolean',
35+
describe: 'Delete sourcemaps after uploading',
36+
default: true,
37+
})
2738
.usage(
2839
'Usage: $0\n' +
2940
' [--release RELEASE]\n' +
3041
' [--urlPrefix URL_PREFIX]\n' +
3142
' [--buildPath BUILD_PATH]\n\n' +
43+
' [--disableDebugIds true|false]\n\n' +
44+
' [--deleteAfterUpload true|false]\n\n' +
3245
'This CLI tool will upload sourcemaps to Sentry for the given release.\n' +
3346
'It has defaults for URL prefix and build path for Remix builds, but you can override them.\n\n' +
3447
'If you need a more advanced configuration, you can use `sentry-cli` instead.\n' +
3548
'https://github.com/getsentry/sentry-cli',
3649
)
3750
.wrap(120).argv;
3851

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

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

Lines changed: 7 additions & 4 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,15 +49,16 @@ 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
});
5456

5557
it('should use given buildPath and urlPrefix over the defaults when given.', async () => {
5658
await createRelease(
5759
{
58-
urlPrefix: '~/build/subfolder',
59-
buildPath: 'public/build/subfolder',
60+
urlPrefix: '~/build/',
61+
buildPath: 'public/build',
6062
},
6163
'~/build/',
6264
'public/build',
@@ -65,8 +67,9 @@ describe('createRelease', () => {
6567
expect(proposeVersionMock).toHaveBeenCalled();
6668
expect(newMock).toHaveBeenCalledWith('0.1.2.3.4');
6769
expect(uploadSourceMapsMock).toHaveBeenCalledWith('0.1.2.3.4', {
68-
urlPrefix: '~/build/subfolder',
69-
include: ['public/build/subfolder'],
70+
urlPrefix: '~/build/',
71+
include: ['public/build'],
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.5":
4432+
version "2.20.5"
4433+
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-2.20.5.tgz#255a5388ca24c211a0eae01dcc4ad813a7ff335a"
4434+
integrity sha512-ZvWb86eF0QXH9C5Mbi87aUmr8SH848yEpXJmlM2AoBowpE9kKDnewCAKvyXUihojUFwCSEEjoJhrRMMgmCZqXA==
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)