Skip to content

Commit

Permalink
Merge branch 'develop' into sig/build-output-path-correction
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d authored Sep 19, 2024
2 parents 9f27d70 + fc7634e commit 01e25cd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/gatsby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ module.exports = {
};
```

Additionally, you can delete source map files after they have been uploaded by setting the `deleteSourcemapsAfterUpload`
option to be `true`.

```javascript
module.exports = {
// ...
plugins: [
{
resolve: '@sentry/gatsby',
options: {
deleteSourcemapsAfterUpload: true,
},
},
// ...
],
};
```

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ const SENTRY_USER_CONFIG = ['./sentry.config.js', './sentry.config.ts'];
exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => {
const enableClientWebpackPlugin = options.enableClientWebpackPlugin !== false;
if (process.env.NODE_ENV === 'production' && enableClientWebpackPlugin) {
const deleteSourcemapsAfterUpload = options.deleteSourcemapsAfterUpload === true;
actions.setWebpackConfig({
plugins: [
sentryWebpackPlugin({
sourcemaps: {
// Only include files from the build output directory
assets: ['./public/**'],
// Delete source files after uploading
filesToDeleteAfterUpload: deleteSourcemapsAfterUpload ? ['./public/**/*.map'] : undefined,
// Ignore files that aren't users' source code related
ignore: [
'polyfill-*', // related to polyfills
Expand Down
31 changes: 31 additions & 0 deletions packages/gatsby/test/gatsby-node.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
import { onCreateWebpackConfig } from '../gatsby-node';

jest.mock('@sentry/webpack-plugin', () => ({
sentryWebpackPlugin: jest.fn().mockReturnValue({
apply: jest.fn(),
}),
}));

describe('onCreateWebpackConfig', () => {
let originalNodeEnv: string | undefined;

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

afterEach(() => {
jest.clearAllMocks();
});

it('sets a webpack config', () => {
const actions = {
setWebpackConfig: jest.fn(),
Expand All @@ -36,4 +47,24 @@ describe('onCreateWebpackConfig', () => {

expect(actions.setWebpackConfig).toHaveBeenCalledTimes(0);
});

it('sets sourceMapFilesToDeleteAfterUpload when provided in options', () => {
const actions = {
setWebpackConfig: jest.fn(),
};

const getConfig = jest.fn();

onCreateWebpackConfig({ actions, getConfig }, { deleteSourcemapsAfterUpload: true });

expect(actions.setWebpackConfig).toHaveBeenCalledTimes(1);

expect(sentryWebpackPlugin).toHaveBeenCalledWith(
expect.objectContaining({
sourcemaps: expect.objectContaining({
filesToDeleteAfterUpload: ['./public/**/*.map'],
}),
}),
);
});
});

0 comments on commit 01e25cd

Please sign in to comment.