From 38c89c527dd924d7d529e02d8601d98c7fa50b21 Mon Sep 17 00:00:00 2001 From: Julian Garcia Castillo Date: Fri, 6 Sep 2024 23:04:15 +0200 Subject: [PATCH 1/6] feat(gatsby): Add optional filesToDeleteAfterUpload --- packages/gatsby/README.md | 3 +++ packages/gatsby/gatsby-node.js | 2 ++ packages/gatsby/test/gatsby-node.test.ts | 32 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 5de12ed78410..e449e5c2d0bc 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -50,6 +50,8 @@ Sentry.init({ The Gatsby SDK also automatically sets up sourcemaps uploading for you. To disable this functionality, set the `enableClientWebpackPlugin` option to be `false`. +Additionally, you can delete source map files after they have been uploaded by setting the `filesToDeleteAfterUpload` option. Check [here](https://www.npmjs.com/package/@sentry/vite-plugin#sourcemapsfilestodeleteafterupload) to learn how to use it. + ```javascript module.exports = { // ... @@ -58,6 +60,7 @@ module.exports = { resolve: '@sentry/gatsby', options: { enableClientWebpackPlugin: false, + filesToDeleteAfterUpload: "./public/**/*.map" }, }, // ... diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index d60914a03061..1ebe52b67e94 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -13,6 +13,8 @@ exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => { sourcemaps: { // Only include files from the build output directory assets: ['public'], + // Delete source files after uploading + filesToDeleteAfterUpload: options.filesToDeleteAfterUpload, // Ignore files that aren't users' source code related ignore: [ 'polyfill-*', // related to polyfills diff --git a/packages/gatsby/test/gatsby-node.test.ts b/packages/gatsby/test/gatsby-node.test.ts index 2e80ac03dcaa..a2190dbaea08 100644 --- a/packages/gatsby/test/gatsby-node.test.ts +++ b/packages/gatsby/test/gatsby-node.test.ts @@ -1,4 +1,11 @@ import { onCreateWebpackConfig } from '../gatsby-node'; +import { sentryWebpackPlugin } from '@sentry/webpack-plugin'; + +jest.mock('@sentry/webpack-plugin', () => ({ + sentryWebpackPlugin: jest.fn().mockReturnValue({ + apply: jest.fn(), + }), +})); describe('onCreateWebpackConfig', () => { let originalNodeEnv: string | undefined; @@ -12,6 +19,10 @@ describe('onCreateWebpackConfig', () => { process.env.NODE_ENV = originalNodeEnv; }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('sets a webpack config', () => { const actions = { setWebpackConfig: jest.fn(), @@ -36,4 +47,25 @@ describe('onCreateWebpackConfig', () => { expect(actions.setWebpackConfig).toHaveBeenCalledTimes(0); }); + + it('sets filesToDeleteAfterUpload when provided in options', () => { + const actions = { + setWebpackConfig: jest.fn(), + }; + + const getConfig = jest.fn(); + + const filesToDelete = ['file1.js', 'file2.js']; + onCreateWebpackConfig({ actions, getConfig }, { filesToDeleteAfterUpload: filesToDelete }); + + expect(actions.setWebpackConfig).toHaveBeenCalledTimes(1); + + expect(sentryWebpackPlugin).toHaveBeenCalledWith( + expect.objectContaining({ + sourcemaps: expect.objectContaining({ + filesToDeleteAfterUpload: filesToDelete, + }), + }) + ); + }); }); From 874ff92ffc85765d1ba89487de8c87a628b99b89 Mon Sep 17 00:00:00 2001 From: Julian Garcia Castillo Date: Fri, 6 Sep 2024 23:10:21 +0200 Subject: [PATCH 2/6] refactor(gatsby): Rename sourceMapFilesToDeleteAfterUpload --- packages/gatsby/README.md | 4 ++-- packages/gatsby/gatsby-node.js | 2 +- packages/gatsby/test/gatsby-node.test.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index e449e5c2d0bc..a7532b41c81f 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -50,7 +50,7 @@ Sentry.init({ The Gatsby SDK also automatically sets up sourcemaps uploading for you. To disable this functionality, set the `enableClientWebpackPlugin` option to be `false`. -Additionally, you can delete source map files after they have been uploaded by setting the `filesToDeleteAfterUpload` option. Check [here](https://www.npmjs.com/package/@sentry/vite-plugin#sourcemapsfilestodeleteafterupload) to learn how to use it. +Additionally, you can delete source map files after they have been uploaded by setting the `sourceMapFilesToDeleteAfterUpload` option. Check [here](https://www.npmjs.com/package/@sentry/vite-plugin#sourcemapsfilestodeleteafterupload) to learn how to use it. ```javascript module.exports = { @@ -60,7 +60,7 @@ module.exports = { resolve: '@sentry/gatsby', options: { enableClientWebpackPlugin: false, - filesToDeleteAfterUpload: "./public/**/*.map" + sourceMapFilesToDeleteAfterUpload: "./public/**/*.map" }, }, // ... diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 3b13cbac6a54..a2b6e1975f5e 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -14,7 +14,7 @@ exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => { // Only include files from the build output directory assets: ['./public/**'], // Delete source files after uploading - filesToDeleteAfterUpload: options.filesToDeleteAfterUpload, + filesToDeleteAfterUpload: options.sourceMapFilesToDeleteAfterUpload, // Ignore files that aren't users' source code related ignore: [ 'polyfill-*', // related to polyfills diff --git a/packages/gatsby/test/gatsby-node.test.ts b/packages/gatsby/test/gatsby-node.test.ts index a2190dbaea08..3d0d8de8384e 100644 --- a/packages/gatsby/test/gatsby-node.test.ts +++ b/packages/gatsby/test/gatsby-node.test.ts @@ -48,7 +48,7 @@ describe('onCreateWebpackConfig', () => { expect(actions.setWebpackConfig).toHaveBeenCalledTimes(0); }); - it('sets filesToDeleteAfterUpload when provided in options', () => { + it('sets sourceMapFilesToDeleteAfterUpload when provided in options', () => { const actions = { setWebpackConfig: jest.fn(), }; @@ -56,7 +56,7 @@ describe('onCreateWebpackConfig', () => { const getConfig = jest.fn(); const filesToDelete = ['file1.js', 'file2.js']; - onCreateWebpackConfig({ actions, getConfig }, { filesToDeleteAfterUpload: filesToDelete }); + onCreateWebpackConfig({ actions, getConfig }, { sourceMapFilesToDeleteAfterUpload: filesToDelete }); expect(actions.setWebpackConfig).toHaveBeenCalledTimes(1); From 31d5185320ea67f7596cc6ab4e4e94ef601d0deb Mon Sep 17 00:00:00 2001 From: Julian Garcia Castillo Date: Tue, 10 Sep 2024 16:29:12 +0200 Subject: [PATCH 3/6] fix(gatsby): Avoid exposing API by using custom boolean --- packages/gatsby/README.md | 18 +++++++++++++++--- packages/gatsby/gatsby-node.js | 3 ++- packages/gatsby/test/gatsby-node.test.ts | 5 ++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index a7532b41c81f..c13616096668 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -50,8 +50,6 @@ Sentry.init({ The Gatsby SDK also automatically sets up sourcemaps uploading for you. To disable this functionality, set the `enableClientWebpackPlugin` option to be `false`. -Additionally, you can delete source map files after they have been uploaded by setting the `sourceMapFilesToDeleteAfterUpload` option. Check [here](https://www.npmjs.com/package/@sentry/vite-plugin#sourcemapsfilestodeleteafterupload) to learn how to use it. - ```javascript module.exports = { // ... @@ -60,13 +58,27 @@ module.exports = { resolve: '@sentry/gatsby', options: { enableClientWebpackPlugin: false, - sourceMapFilesToDeleteAfterUpload: "./public/**/*.map" }, }, // ... ], }; ``` +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 diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index a2b6e1975f5e..911fcda7b437 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -7,6 +7,7 @@ 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({ @@ -14,7 +15,7 @@ exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => { // Only include files from the build output directory assets: ['./public/**'], // Delete source files after uploading - filesToDeleteAfterUpload: options.sourceMapFilesToDeleteAfterUpload, + filesToDeleteAfterUpload: deleteSourcemapsAfterUpload ? ['./public/**/*.map'] : undefined, // Ignore files that aren't users' source code related ignore: [ 'polyfill-*', // related to polyfills diff --git a/packages/gatsby/test/gatsby-node.test.ts b/packages/gatsby/test/gatsby-node.test.ts index 3d0d8de8384e..e185f9960855 100644 --- a/packages/gatsby/test/gatsby-node.test.ts +++ b/packages/gatsby/test/gatsby-node.test.ts @@ -55,15 +55,14 @@ describe('onCreateWebpackConfig', () => { const getConfig = jest.fn(); - const filesToDelete = ['file1.js', 'file2.js']; - onCreateWebpackConfig({ actions, getConfig }, { sourceMapFilesToDeleteAfterUpload: filesToDelete }); + onCreateWebpackConfig({ actions, getConfig }, { deleteSourcemapsAfterUpload: true }); expect(actions.setWebpackConfig).toHaveBeenCalledTimes(1); expect(sentryWebpackPlugin).toHaveBeenCalledWith( expect.objectContaining({ sourcemaps: expect.objectContaining({ - filesToDeleteAfterUpload: filesToDelete, + filesToDeleteAfterUpload: ["./public/**/*.map"], }), }) ); From beabc312ff8585e11afd7e8a2a21d0a27e17e58f Mon Sep 17 00:00:00 2001 From: Julian Garcia Castillo Date: Tue, 10 Sep 2024 16:33:17 +0200 Subject: [PATCH 4/6] fix(gatsby): fix lint --- packages/gatsby/test/gatsby-node.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/test/gatsby-node.test.ts b/packages/gatsby/test/gatsby-node.test.ts index e185f9960855..89e4f0970fbd 100644 --- a/packages/gatsby/test/gatsby-node.test.ts +++ b/packages/gatsby/test/gatsby-node.test.ts @@ -62,7 +62,7 @@ describe('onCreateWebpackConfig', () => { expect(sentryWebpackPlugin).toHaveBeenCalledWith( expect.objectContaining({ sourcemaps: expect.objectContaining({ - filesToDeleteAfterUpload: ["./public/**/*.map"], + filesToDeleteAfterUpload: ['./public/**/*.map'], }), }) ); From ca021286366e622bdaec5356be3267c5a92e7616 Mon Sep 17 00:00:00 2001 From: Julian Garcia Castillo Date: Tue, 10 Sep 2024 16:36:32 +0200 Subject: [PATCH 5/6] fix(gatsby): Fix lint readme --- packages/gatsby/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index c13616096668..1cd159f7e046 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -64,7 +64,8 @@ module.exports = { ], }; ``` -Additionally, you can delete source map files after they have been uploaded by setting the `deleteSourcemapsAfterUpload` option to be `true`. +Additionally, you can delete source map files after they have been uploaded by setting the `deleteSourcemapsAfterUpload` +option to be `true`. ```javascript module.exports = { @@ -79,6 +80,7 @@ module.exports = { // ... ], }; +``` ## Links From 58fc276a82e270838d42b58bbb6bbdbb9327c0cd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 19 Sep 2024 08:25:57 +0000 Subject: [PATCH 6/6] lint --- packages/gatsby/README.md | 1 + packages/gatsby/test/gatsby-node.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 1cd159f7e046..cf5eadf7045b 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -64,6 +64,7 @@ module.exports = { ], }; ``` + Additionally, you can delete source map files after they have been uploaded by setting the `deleteSourcemapsAfterUpload` option to be `true`. diff --git a/packages/gatsby/test/gatsby-node.test.ts b/packages/gatsby/test/gatsby-node.test.ts index 89e4f0970fbd..006cb6f9e2c0 100644 --- a/packages/gatsby/test/gatsby-node.test.ts +++ b/packages/gatsby/test/gatsby-node.test.ts @@ -1,5 +1,5 @@ -import { onCreateWebpackConfig } from '../gatsby-node'; import { sentryWebpackPlugin } from '@sentry/webpack-plugin'; +import { onCreateWebpackConfig } from '../gatsby-node'; jest.mock('@sentry/webpack-plugin', () => ({ sentryWebpackPlugin: jest.fn().mockReturnValue({ @@ -64,7 +64,7 @@ describe('onCreateWebpackConfig', () => { sourcemaps: expect.objectContaining({ filesToDeleteAfterUpload: ['./public/**/*.map'], }), - }) + }), ); }); });