From 14798157f3ae7ea9f0f8387a517c70c5536a921f Mon Sep 17 00:00:00 2001 From: Zac Jacobson Date: Thu, 14 Oct 2021 23:19:07 -0700 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20ignoreSourcema?= =?UTF-8?q?p=20to=20WebpackPluginConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ignoreSourcemap to WebpackPluginConfig and use this to restrict generated source-map files from being included in the packaged application. ✅ Closes: #2573 --- packages/plugin/webpack/src/Config.ts | 6 ++++++ packages/plugin/webpack/src/WebpackPlugin.ts | 4 ++++ packages/plugin/webpack/test/WebpackPlugin_spec.ts | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/packages/plugin/webpack/src/Config.ts b/packages/plugin/webpack/src/Config.ts index 4af7e45a1d..e89fc57ab9 100644 --- a/packages/plugin/webpack/src/Config.ts +++ b/packages/plugin/webpack/src/Config.ts @@ -84,6 +84,12 @@ export interface WebpackPluginConfig { * The webpack config for your main process */ mainConfig: WebpackConfiguration | string; + /** + * In the event that webpack has been configured with `devtool: sourcemap` (or any other option + * which results in a `.map` file being generated), this option will cause it to not be + * packaged with your app. + */ + ignoreSourcemap?: boolean; /** * Instructs webpack to emit a JSON file containing statistics about modules, the dependency * graph, and various other build information for the main process. This file is located in diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index 3a6f6d1ed2..485fa0c7fd 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -203,6 +203,10 @@ Your packaged app may be larger than expected if you dont ignore everything othe return true; } + if (this.config.ignoreSourcemap && /[^/\\]+\.js\.map$/.test(file)) { + return true; + } + return !/^[/\\]\.webpack($|[/\\]).*$/.test(file); }; return forgeConfig; diff --git a/packages/plugin/webpack/test/WebpackPlugin_spec.ts b/packages/plugin/webpack/test/WebpackPlugin_spec.ts index 00bc9696c4..68810fb110 100644 --- a/packages/plugin/webpack/test/WebpackPlugin_spec.ts +++ b/packages/plugin/webpack/test/WebpackPlugin_spec.ts @@ -118,6 +118,18 @@ describe('WebpackPlugin', () => { expect(ignore(path.join('foo', 'bar', '.webpack', 'main', 'stats.json'))).to.equal(true); expect(ignore(path.join('foo', 'bar', '.webpack', 'renderer', 'stats.json'))).to.equal(true); }); + + it('ignores sourcemap files', async () => { + const webpackConfig = { ...baseConfig, ignoreSourcemap: true }; + plugin = new WebpackPlugin(webpackConfig); + const config = await plugin.resolveForgeConfig({} as ForgeConfig); + const ignore = config.packagerConfig.ignore as IgnoreFunction; + + expect(ignore(path.join('/.webpack', 'main', 'index.js'))).to.equal(false); + expect(ignore(path.join('/.webpack', 'main', 'index.js.map'))).to.equal(true); + expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js'))).to.equal(false); + expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js.map'))).to.equal(true); + }); }); }); From 2062c16fae9346e47f27ef7dc141e3e27eed3dd9 Mon Sep 17 00:00:00 2001 From: Zac Jacobson Date: Thu, 21 Apr 2022 20:58:03 -0700 Subject: [PATCH 2/3] PR feedback: exclude source map by default --- packages/plugin/webpack/src/Config.ts | 6 +++--- packages/plugin/webpack/src/WebpackPlugin.ts | 2 +- .../plugin/webpack/test/WebpackPlugin_spec.ts | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/plugin/webpack/src/Config.ts b/packages/plugin/webpack/src/Config.ts index e89fc57ab9..7b00a9c718 100644 --- a/packages/plugin/webpack/src/Config.ts +++ b/packages/plugin/webpack/src/Config.ts @@ -86,10 +86,10 @@ export interface WebpackPluginConfig { mainConfig: WebpackConfiguration | string; /** * In the event that webpack has been configured with `devtool: sourcemap` (or any other option - * which results in a `.map` file being generated), this option will cause it to not be - * packaged with your app. + * which results in a `.map` file being generated), this option will cause the source map files be + * packaged with your app. By default they are not included. */ - ignoreSourcemap?: boolean; + includeSourceMap?: boolean; /** * Instructs webpack to emit a JSON file containing statistics about modules, the dependency * graph, and various other build information for the main process. This file is located in diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index 485fa0c7fd..be8b6fb795 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -203,7 +203,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe return true; } - if (this.config.ignoreSourcemap && /[^/\\]+\.js\.map$/.test(file)) { + if (!this.config.includeSourceMap && /[^/\\]+\.js\.map$/.test(file)) { return true; } diff --git a/packages/plugin/webpack/test/WebpackPlugin_spec.ts b/packages/plugin/webpack/test/WebpackPlugin_spec.ts index 68810fb110..99f95459e6 100644 --- a/packages/plugin/webpack/test/WebpackPlugin_spec.ts +++ b/packages/plugin/webpack/test/WebpackPlugin_spec.ts @@ -119,8 +119,8 @@ describe('WebpackPlugin', () => { expect(ignore(path.join('foo', 'bar', '.webpack', 'renderer', 'stats.json'))).to.equal(true); }); - it('ignores sourcemap files', async () => { - const webpackConfig = { ...baseConfig, ignoreSourcemap: true }; + it('ignores source map files by default', async () => { + const webpackConfig = { ...baseConfig }; plugin = new WebpackPlugin(webpackConfig); const config = await plugin.resolveForgeConfig({} as ForgeConfig); const ignore = config.packagerConfig.ignore as IgnoreFunction; @@ -130,6 +130,18 @@ describe('WebpackPlugin', () => { expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js'))).to.equal(false); expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js.map'))).to.equal(true); }); + + it('includes source map files when specified by config', async () => { + const webpackConfig = { ...baseConfig, includeSourceMap: true }; + plugin = new WebpackPlugin(webpackConfig); + const config = await plugin.resolveForgeConfig({} as ForgeConfig); + const ignore = config.packagerConfig.ignore as IgnoreFunction; + + expect(ignore(path.join('/.webpack', 'main', 'index.js'))).to.equal(false); + expect(ignore(path.join('/.webpack', 'main', 'index.js.map'))).to.equal(false); + expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js'))).to.equal(false); + expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js.map'))).to.equal(false); + }); }); }); From 8fa63203216e9dfb5e294c208dba01d8a42d7c49 Mon Sep 17 00:00:00 2001 From: Zac Jacobson Date: Wed, 27 Apr 2022 21:02:38 -0700 Subject: [PATCH 3/3] rename option to packageSourceMaps --- packages/plugin/webpack/src/Config.ts | 12 ++++++------ packages/plugin/webpack/src/WebpackPlugin.ts | 2 +- packages/plugin/webpack/test/WebpackPlugin_spec.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/plugin/webpack/src/Config.ts b/packages/plugin/webpack/src/Config.ts index 7b00a9c718..af86b25280 100644 --- a/packages/plugin/webpack/src/Config.ts +++ b/packages/plugin/webpack/src/Config.ts @@ -84,12 +84,6 @@ export interface WebpackPluginConfig { * The webpack config for your main process */ mainConfig: WebpackConfiguration | string; - /** - * In the event that webpack has been configured with `devtool: sourcemap` (or any other option - * which results in a `.map` file being generated), this option will cause the source map files be - * packaged with your app. By default they are not included. - */ - includeSourceMap?: boolean; /** * Instructs webpack to emit a JSON file containing statistics about modules, the dependency * graph, and various other build information for the main process. This file is located in @@ -108,6 +102,12 @@ export interface WebpackPluginConfig { * The TCP port for web-multi-logger. Defaults to 9000. */ loggerPort?: number; + /** + * In the event that webpack has been configured with `devtool: sourcemap` (or any other option + * which results in `.map` files being generated), this option will cause the source map files be + * packaged with your app. By default they are not included. + */ + packageSourceMaps?: boolean; /** * Sets the [`Content-Security-Policy` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) * for the Webpack development server. diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index be8b6fb795..59eff4752c 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -203,7 +203,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe return true; } - if (!this.config.includeSourceMap && /[^/\\]+\.js\.map$/.test(file)) { + if (!this.config.packageSourceMaps && /[^/\\]+\.js\.map$/.test(file)) { return true; } diff --git a/packages/plugin/webpack/test/WebpackPlugin_spec.ts b/packages/plugin/webpack/test/WebpackPlugin_spec.ts index 99f95459e6..dfc743fcd3 100644 --- a/packages/plugin/webpack/test/WebpackPlugin_spec.ts +++ b/packages/plugin/webpack/test/WebpackPlugin_spec.ts @@ -132,7 +132,7 @@ describe('WebpackPlugin', () => { }); it('includes source map files when specified by config', async () => { - const webpackConfig = { ...baseConfig, includeSourceMap: true }; + const webpackConfig = { ...baseConfig, packageSourceMaps: true }; plugin = new WebpackPlugin(webpackConfig); const config = await plugin.resolveForgeConfig({} as ForgeConfig); const ignore = config.packagerConfig.ignore as IgnoreFunction;