Skip to content

Commit fc7634e

Browse files
julianCastlforst
andauthored
feat(gatsby): Add optional deleteSourcemapsAfterUpload (#13610)
Related #13582 This work adds the `deleteSourcemapsAfterUpload` option to the Gatsby plugin, allowing it to be passed to the Webpack plugin to set the `sourceMapFilesToDeleteAfterUpload` without exposing the API. This simplifies our workflow by eliminating the need to apply a Yarn patch to modify the package whenever we want to use `filesToDeleteAfterUpload`. Before submitting a pull request, please take a look at our [Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md) guidelines and verify: - [x] If you've added code that should be tested, please add tests. - [x] Ensure your code lints and the test suite passes (`yarn lint`) & (`yarn test`). --------- Co-authored-by: Luca Forstner <[email protected]>
1 parent 1e9a1a3 commit fc7634e

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

packages/gatsby/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ module.exports = {
6565
};
6666
```
6767

68+
Additionally, you can delete source map files after they have been uploaded by setting the `deleteSourcemapsAfterUpload`
69+
option to be `true`.
70+
71+
```javascript
72+
module.exports = {
73+
// ...
74+
plugins: [
75+
{
76+
resolve: '@sentry/gatsby',
77+
options: {
78+
deleteSourcemapsAfterUpload: true,
79+
},
80+
},
81+
// ...
82+
],
83+
};
84+
```
85+
6886
## Links
6987

7088
- [Official SDK Docs](https://docs.sentry.io/quickstart/)

packages/gatsby/gatsby-node.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ const SENTRY_USER_CONFIG = ['./sentry.config.js', './sentry.config.ts'];
77
exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => {
88
const enableClientWebpackPlugin = options.enableClientWebpackPlugin !== false;
99
if (process.env.NODE_ENV === 'production' && enableClientWebpackPlugin) {
10+
const deleteSourcemapsAfterUpload = options.deleteSourcemapsAfterUpload === true;
1011
actions.setWebpackConfig({
1112
plugins: [
1213
sentryWebpackPlugin({
1314
sourcemaps: {
1415
// Only include files from the build output directory
1516
assets: ['./public/**'],
17+
// Delete source files after uploading
18+
filesToDeleteAfterUpload: deleteSourcemapsAfterUpload ? ['./public/**/*.map'] : undefined,
1619
// Ignore files that aren't users' source code related
1720
ignore: [
1821
'polyfill-*', // related to polyfills

packages/gatsby/test/gatsby-node.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
12
import { onCreateWebpackConfig } from '../gatsby-node';
23

4+
jest.mock('@sentry/webpack-plugin', () => ({
5+
sentryWebpackPlugin: jest.fn().mockReturnValue({
6+
apply: jest.fn(),
7+
}),
8+
}));
9+
310
describe('onCreateWebpackConfig', () => {
411
let originalNodeEnv: string | undefined;
512

@@ -12,6 +19,10 @@ describe('onCreateWebpackConfig', () => {
1219
process.env.NODE_ENV = originalNodeEnv;
1320
});
1421

22+
afterEach(() => {
23+
jest.clearAllMocks();
24+
});
25+
1526
it('sets a webpack config', () => {
1627
const actions = {
1728
setWebpackConfig: jest.fn(),
@@ -36,4 +47,24 @@ describe('onCreateWebpackConfig', () => {
3647

3748
expect(actions.setWebpackConfig).toHaveBeenCalledTimes(0);
3849
});
50+
51+
it('sets sourceMapFilesToDeleteAfterUpload when provided in options', () => {
52+
const actions = {
53+
setWebpackConfig: jest.fn(),
54+
};
55+
56+
const getConfig = jest.fn();
57+
58+
onCreateWebpackConfig({ actions, getConfig }, { deleteSourcemapsAfterUpload: true });
59+
60+
expect(actions.setWebpackConfig).toHaveBeenCalledTimes(1);
61+
62+
expect(sentryWebpackPlugin).toHaveBeenCalledWith(
63+
expect.objectContaining({
64+
sourcemaps: expect.objectContaining({
65+
filesToDeleteAfterUpload: ['./public/**/*.map'],
66+
}),
67+
}),
68+
);
69+
});
3970
});

0 commit comments

Comments
 (0)