From cf760c922cb0329f5015dbcc468422a385202180 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 30 Nov 2023 15:21:26 -0800 Subject: [PATCH] feat: add support for sequential groups of webpack builds (#3435) * feat: add support for sequential groups of webpack builds * fix: use webpack multi-compiler dependency specifications to use a single dev server --- packages/plugin/webpack/src/Config.ts | 8 +- packages/plugin/webpack/src/WebpackConfig.ts | 81 ++++++++++++------- packages/plugin/webpack/src/WebpackPlugin.ts | 36 ++++++--- .../webpack/test/AssetRelocatorPatch_spec.ts | 22 +++-- .../plugin/webpack/test/WebpackConfig_spec.ts | 43 +++++----- .../plugin/webpack/test/WebpackPlugin_spec.ts | 4 +- 6 files changed, 125 insertions(+), 69 deletions(-) diff --git a/packages/plugin/webpack/src/Config.ts b/packages/plugin/webpack/src/Config.ts index 0d886f5e94..2a201af825 100644 --- a/packages/plugin/webpack/src/Config.ts +++ b/packages/plugin/webpack/src/Config.ts @@ -138,8 +138,14 @@ export interface WebpackPluginConfig { jsonStats?: boolean; /** * Electron Forge webpack configuration for your renderer process + * + * If this property is configured as an array each group of entryPoints is built sequentially + * such that later indexed renderer configurations can depend on the output of previous ones. + * + * If you want to build multiple targets in parallel please specify multiple entryPoints in a + * single renderer configuration. Most usecases should not set this to an array. */ - renderer: WebpackPluginRendererConfig; + renderer: WebpackPluginRendererConfig | WebpackPluginRendererConfig[]; /** * The TCP port for the dev servers. Defaults to 3000. */ diff --git a/packages/plugin/webpack/src/WebpackConfig.ts b/packages/plugin/webpack/src/WebpackConfig.ts index ffc98168ce..f22c6b88ae 100644 --- a/packages/plugin/webpack/src/WebpackConfig.ts +++ b/packages/plugin/webpack/src/WebpackConfig.ts @@ -5,7 +5,13 @@ import HtmlWebpackPlugin from 'html-webpack-plugin'; import webpack, { Configuration, WebpackPluginInstance } from 'webpack'; import { merge as webpackMerge } from 'webpack-merge'; -import { WebpackPluginConfig, WebpackPluginEntryPoint, WebpackPluginEntryPointLocalWindow, WebpackPluginEntryPointPreloadOnly } from './Config'; +import { + WebpackPluginConfig, + WebpackPluginEntryPoint, + WebpackPluginEntryPointLocalWindow, + WebpackPluginEntryPointPreloadOnly, + WebpackPluginRendererConfig, +} from './Config'; import AssetRelocatorPatch from './util/AssetRelocatorPatch'; import processConfig from './util/processConfig'; import { isLocalOrNoWindowEntries, isLocalWindow, isNoWindow, isPreloadOnly, isPreloadOnlyEntries } from './util/rendererTypeUtils'; @@ -104,9 +110,9 @@ export default class WebpackConfigGenerator { return this.isProd ? 'source-map' : 'eval-source-map'; } - rendererEntryPoint(entryPoint: WebpackPluginEntryPoint, inRendererDir: boolean, basename: string): string { + rendererEntryPoint(entryPoint: WebpackPluginEntryPoint, basename: string): string { if (this.isProd) { - return `\`file://$\{require('path').resolve(__dirname, '..', '${inRendererDir ? 'renderer' : '.'}', '${entryPoint.name}', '${basename}')}\``; + return `\`file://$\{require('path').resolve(__dirname, '..', 'renderer', '${entryPoint.name}', '${basename}')}\``; } const baseUrl = `http://localhost:${this.port}/${entryPoint.name}`; if (basename !== 'index.html') { @@ -133,23 +139,30 @@ export default class WebpackConfigGenerator { } } - getDefines(inRendererDir = true): Record { + private get allPluginRendererOptions() { + return Array.isArray(this.pluginConfig.renderer) ? this.pluginConfig.renderer : [this.pluginConfig.renderer]; + } + + getDefines(): Record { const defines: Record = {}; - if (!this.pluginConfig.renderer.entryPoints || !Array.isArray(this.pluginConfig.renderer.entryPoints)) { - throw new Error('Required config option "renderer.entryPoints" has not been defined'); - } - for (const entryPoint of this.pluginConfig.renderer.entryPoints) { - const entryKey = this.toEnvironmentVariable(entryPoint); - if (isLocalWindow(entryPoint)) { - defines[entryKey] = this.rendererEntryPoint(entryPoint, inRendererDir, 'index.html'); - } else { - defines[entryKey] = this.rendererEntryPoint(entryPoint, inRendererDir, 'index.js'); + + for (const pluginRendererOptions of this.allPluginRendererOptions) { + if (!pluginRendererOptions.entryPoints || !Array.isArray(pluginRendererOptions.entryPoints)) { + throw new Error('Required config option "renderer.entryPoints" has not been defined'); } - defines[`process.env.${entryKey}`] = defines[entryKey]; + for (const entryPoint of pluginRendererOptions.entryPoints) { + const entryKey = this.toEnvironmentVariable(entryPoint); + if (isLocalWindow(entryPoint)) { + defines[entryKey] = this.rendererEntryPoint(entryPoint, 'index.html'); + } else { + defines[entryKey] = this.rendererEntryPoint(entryPoint, 'index.js'); + } + defines[`process.env.${entryKey}`] = defines[entryKey]; - const preloadDefineKey = this.toEnvironmentVariable(entryPoint, true); - defines[preloadDefineKey] = this.getPreloadDefine(entryPoint); - defines[`process.env.${preloadDefineKey}`] = defines[preloadDefineKey]; + const preloadDefineKey = this.toEnvironmentVariable(entryPoint, true); + defines[preloadDefineKey] = this.getPreloadDefine(entryPoint); + defines[`process.env.${preloadDefineKey}`] = defines[preloadDefineKey]; + } } return defines; @@ -194,7 +207,7 @@ export default class WebpackConfigGenerator { ); } - async getRendererConfig(entryPoints: WebpackPluginEntryPoint[]): Promise { + async getRendererConfig(rendererOptions: WebpackPluginRendererConfig): Promise { const entryPointsForTarget = { web: [] as (WebpackPluginEntryPointLocalWindow | WebpackPluginEntryPoint)[], electronRenderer: [] as (WebpackPluginEntryPointLocalWindow | WebpackPluginEntryPoint)[], @@ -202,9 +215,9 @@ export default class WebpackConfigGenerator { sandboxedPreload: [] as WebpackPluginEntryPointPreloadOnly[], }; - for (const entry of entryPoints) { - const target = entry.nodeIntegration ?? this.pluginConfig.renderer.nodeIntegration ? 'electronRenderer' : 'web'; - const preloadTarget = entry.nodeIntegration ?? this.pluginConfig.renderer.nodeIntegration ? 'electronPreload' : 'sandboxedPreload'; + for (const entry of rendererOptions.entryPoints) { + const target = entry.nodeIntegration ?? rendererOptions.nodeIntegration ? 'electronRenderer' : 'web'; + const preloadTarget = entry.nodeIntegration ?? rendererOptions.nodeIntegration ? 'electronPreload' : 'sandboxedPreload'; if (isPreloadOnly(entry)) { entryPointsForTarget[preloadTarget].push(entry); @@ -218,10 +231,10 @@ export default class WebpackConfigGenerator { const rendererConfigs = await Promise.all( [ - await this.buildRendererConfigs(entryPointsForTarget.web, RendererTarget.Web), - await this.buildRendererConfigs(entryPointsForTarget.electronRenderer, RendererTarget.ElectronRenderer), - await this.buildRendererConfigs(entryPointsForTarget.electronPreload, RendererTarget.ElectronPreload), - await this.buildRendererConfigs(entryPointsForTarget.sandboxedPreload, RendererTarget.SandboxedPreload), + await this.buildRendererConfigs(rendererOptions, entryPointsForTarget.web, RendererTarget.Web), + await this.buildRendererConfigs(rendererOptions, entryPointsForTarget.electronRenderer, RendererTarget.ElectronRenderer), + await this.buildRendererConfigs(rendererOptions, entryPointsForTarget.electronPreload, RendererTarget.ElectronPreload), + await this.buildRendererConfigs(rendererOptions, entryPointsForTarget.sandboxedPreload, RendererTarget.SandboxedPreload), ].reduce((configs, allConfigs) => allConfigs.concat(configs)) ); @@ -248,6 +261,7 @@ export default class WebpackConfigGenerator { } async buildRendererConfigForWebOrRendererTarget( + rendererOptions: WebpackPluginRendererConfig, entryPoints: WebpackPluginEntryPoint[], target: RendererTarget.Web | RendererTarget.ElectronRenderer ): Promise { @@ -257,7 +271,7 @@ export default class WebpackConfigGenerator { const entry: webpack.Entry = {}; const baseConfig: webpack.Configuration = this.buildRendererBaseConfig(target); - const rendererConfig = await this.resolveConfig(this.pluginConfig.renderer.config); + const rendererConfig = await this.resolveConfig(rendererOptions.config); const output = { path: path.resolve(this.webpackDir, 'renderer'), @@ -285,6 +299,7 @@ export default class WebpackConfigGenerator { } async buildRendererConfigForPreloadOrSandboxedPreloadTarget( + rendererOptions: WebpackPluginRendererConfig, entryPoints: WebpackPluginEntryPointPreloadOnly[], target: RendererTarget.ElectronPreload | RendererTarget.SandboxedPreload ): Promise { @@ -296,7 +311,7 @@ export default class WebpackConfigGenerator { const entry: webpack.Entry = {}; const baseConfig: webpack.Configuration = this.buildRendererBaseConfig(target); - const rendererConfig = await this.resolveConfig(entryPoints[0].preload?.config || this.pluginConfig.renderer.config); + const rendererConfig = await this.resolveConfig(entryPoints[0].preload?.config || rendererOptions.config); for (const entryPoint of entryPoints) { entry[entryPoint.name] = (entryPoint.prefixedEntries || []).concat([entryPoint.preload.js]); @@ -315,13 +330,17 @@ export default class WebpackConfigGenerator { return webpackMerge(baseConfig, rendererConfig || {}, config); } - async buildRendererConfigs(entryPoints: WebpackPluginEntryPoint[], target: RendererTarget): Promise[]> { + async buildRendererConfigs( + rendererOptions: WebpackPluginRendererConfig, + entryPoints: WebpackPluginEntryPoint[], + target: RendererTarget + ): Promise[]> { if (entryPoints.length === 0) { return []; } const rendererConfigs = []; if (target === RendererTarget.Web || target === RendererTarget.ElectronRenderer) { - rendererConfigs.push(this.buildRendererConfigForWebOrRendererTarget(entryPoints, target)); + rendererConfigs.push(this.buildRendererConfigForWebOrRendererTarget(rendererOptions, entryPoints, target)); return rendererConfigs; } else if (target === RendererTarget.ElectronPreload || target === RendererTarget.SandboxedPreload) { if (!isPreloadOnlyEntries(entryPoints)) { @@ -332,9 +351,9 @@ export default class WebpackConfigGenerator { entryPointsWithoutPreloadConfig: WebpackPluginEntryPointPreloadOnly[] = []; entryPoints.forEach((entryPoint) => (entryPoint.preload.config ? entryPointsWithPreloadConfig : entryPointsWithoutPreloadConfig).push(entryPoint)); - rendererConfigs.push(this.buildRendererConfigForPreloadOrSandboxedPreloadTarget(entryPointsWithoutPreloadConfig, target)); + rendererConfigs.push(this.buildRendererConfigForPreloadOrSandboxedPreloadTarget(rendererOptions, entryPointsWithoutPreloadConfig, target)); entryPointsWithPreloadConfig.forEach((entryPoint) => { - rendererConfigs.push(this.buildRendererConfigForPreloadOrSandboxedPreloadTarget([entryPoint], target)); + rendererConfigs.push(this.buildRendererConfigForPreloadOrSandboxedPreloadTarget(rendererOptions, [entryPoint], target)); }); return rendererConfigs; } else { diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index 9a306ccb44..e0bc32c2d5 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -12,7 +12,7 @@ import webpack, { Configuration, Watching } from 'webpack'; import WebpackDevServer from 'webpack-dev-server'; import { merge } from 'webpack-merge'; -import { WebpackPluginConfig } from './Config'; +import { WebpackPluginConfig, WebpackPluginRendererConfig } from './Config'; import ElectronForgeLoggingPlugin from './util/ElectronForgeLogging'; import EntryPointPreloadPlugin from './util/EntryPointPreloadPlugin'; import once from './util/once'; @@ -111,12 +111,12 @@ export default class WebpackPlugin extends PluginBase { await fs.writeJson(jsonStatsFilename, jsonStats, { spaces: 2 }); } - private runWebpack = async (options: Configuration[], isRenderer = false): Promise => + private runWebpack = async (options: Configuration[], rendererOptions: WebpackPluginRendererConfig | null): Promise => new Promise((resolve, reject) => { webpack(options).run(async (err, stats) => { - if (isRenderer && this.config.renderer.jsonStats) { + if (rendererOptions && rendererOptions.jsonStats) { for (const [index, entryStats] of (stats?.stats ?? []).entries()) { - const name = this.config.renderer.entryPoints[index].name; + const name = rendererOptions.entryPoints[index].name; await this.writeJSONStats('renderer', entryStats, options[index].stats as WebpackToJsonOptions, name); } } @@ -263,7 +263,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe return true; } - if (this.config.renderer.jsonStats && file.endsWith(path.join('.webpack', 'renderer', 'stats.json'))) { + if (this.allRendererOptions.some((r) => r.jsonStats) && file.endsWith(path.join('.webpack', 'renderer', 'stats.json'))) { return true; } @@ -276,6 +276,10 @@ Your packaged app may be larger than expected if you dont ignore everything othe return forgeConfig; }; + private get allRendererOptions() { + return Array.isArray(this.config.renderer) ? this.config.renderer : [this.config.renderer]; + } + packageAfterCopy = async (_forgeConfig: ResolvedForgeConfig, buildPath: string): Promise => { const pj = await fs.readJson(path.resolve(this.projectDir, 'package.json')); @@ -334,14 +338,28 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`); }; compileRenderers = async (watch = false): Promise => { - const stats = await this.runWebpack(await this.configGenerator.getRendererConfig(this.config.renderer.entryPoints), true); - if (!watch && stats?.hasErrors()) { - throw new Error(`Compilation errors in the renderer: ${stats.toString()}`); + for (const rendererOptions of this.allRendererOptions) { + const stats = await this.runWebpack(await this.configGenerator.getRendererConfig(rendererOptions), rendererOptions); + if (!watch && stats?.hasErrors()) { + throw new Error(`Compilation errors in the renderer: ${stats.toString()}`); + } } }; launchRendererDevServers = async (logger: Logger): Promise => { - const configs = await this.configGenerator.getRendererConfig(this.config.renderer.entryPoints); + const configs: Configuration[] = []; + const rollingDependencies: string[] = []; + for (const [i, rendererOptions] of this.allRendererOptions.entries()) { + const groupName = `group_${i}`; + configs.push( + ...(await this.configGenerator.getRendererConfig(rendererOptions)).map((config) => ({ + ...config, + name: groupName, + dependencies: rollingDependencies, + })) + ); + } + if (configs.length === 0) { return; } diff --git a/packages/plugin/webpack/test/AssetRelocatorPatch_spec.ts b/packages/plugin/webpack/test/AssetRelocatorPatch_spec.ts index 70be2d3e09..f4679b001b 100644 --- a/packages/plugin/webpack/test/AssetRelocatorPatch_spec.ts +++ b/packages/plugin/webpack/test/AssetRelocatorPatch_spec.ts @@ -97,6 +97,11 @@ async function yarnStart(): Promise { }); } +const safeFirstRendererConfig = (renderer: WebpackPluginConfig['renderer']) => { + if (Array.isArray(renderer)) return renderer[0]; + return renderer; +}; + describe('AssetRelocatorPatch', () => { const rendererOut = path.join(appPath, '.webpack/renderer'); const mainOut = path.join(appPath, '.webpack/main'); @@ -145,7 +150,7 @@ describe('AssetRelocatorPatch', () => { }); it('builds preload', async () => { - const preloadConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const preloadConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); await asyncWebpack(preloadConfig[0]); await expectOutputFileToHaveTheCorrectNativeModulePath({ @@ -157,7 +162,7 @@ describe('AssetRelocatorPatch', () => { }); it('builds renderer', async () => { - const rendererConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const rendererConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); for (const rendererEntryConfig of rendererConfig) { await asyncWebpack(rendererEntryConfig); } @@ -197,8 +202,11 @@ describe('AssetRelocatorPatch', () => { }); it('builds preload', async () => { - const entryPoint = config.renderer.entryPoints[0] as WebpackPluginEntryPointLocalWindow; - const preloadConfig = await generator.getRendererConfig([entryPoint]); + const entryPoint = safeFirstRendererConfig(config.renderer).entryPoints[0] as WebpackPluginEntryPointLocalWindow; + const preloadConfig = await generator.getRendererConfig({ + ...safeFirstRendererConfig(config.renderer), + entryPoints: [entryPoint], + }); await asyncWebpack(preloadConfig[0]); await expectOutputFileToHaveTheCorrectNativeModulePath({ @@ -210,7 +218,7 @@ describe('AssetRelocatorPatch', () => { }); it('builds renderer', async () => { - const rendererConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const rendererConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); for (const rendererEntryConfig of rendererConfig) { await asyncWebpack(rendererEntryConfig); } @@ -232,10 +240,10 @@ describe('AssetRelocatorPatch', () => { }); it('builds renderer with nodeIntegration = false', async () => { - config.renderer.nodeIntegration = false; + safeFirstRendererConfig(config.renderer).nodeIntegration = false; generator = new WebpackConfigGenerator(config, appPath, true, 3000); - const rendererConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const rendererConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); for (const rendererEntryConfig of rendererConfig) { await asyncWebpack(rendererEntryConfig); } diff --git a/packages/plugin/webpack/test/WebpackConfig_spec.ts b/packages/plugin/webpack/test/WebpackConfig_spec.ts index 48873d955c..8e691d13e3 100644 --- a/packages/plugin/webpack/test/WebpackConfig_spec.ts +++ b/packages/plugin/webpack/test/WebpackConfig_spec.ts @@ -24,6 +24,11 @@ const sampleWebpackConfig = { }, }; +const safeFirstRendererConfig = (renderer: WebpackPluginConfig['renderer']) => { + if (Array.isArray(renderer)) return renderer[0]; + return renderer; +}; + describe('WebpackConfigGenerator', () => { describe('rendererTarget', () => { it('is web if undefined', async () => { @@ -33,7 +38,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, '/', false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); }); @@ -45,7 +50,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, '/', false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); }); @@ -57,7 +62,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, '/', false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('electron-renderer'); }); @@ -69,7 +74,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, '/', false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); }); }); @@ -122,9 +127,9 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, '/', true, 3000); - const defines = generator.getDefines(false); + const defines = generator.getDefines(); - expect(defines.HELLO_WEBPACK_ENTRY).to.equal("`file://${require('path').resolve(__dirname, '..', '.', 'hello', 'index.js')}`"); + expect(defines.HELLO_WEBPACK_ENTRY).to.equal("`file://${require('path').resolve(__dirname, '..', 'renderer', 'hello', 'index.js')}`"); }); it('sets the renderer entry point to an HTML file if both an HTML & JS file are specified', () => { @@ -337,7 +342,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.deep.equal('electron-renderer'); expect(webpackConfig[0].mode).to.equal('development'); expect(webpackConfig[0].entry).to.deep.equal({ @@ -367,7 +372,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].entry).to.deep.equal({ main: ['rendererScript.js'], }); @@ -390,7 +395,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, false, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); expect(webpackConfig[0].mode).to.equal('development'); expect(webpackConfig[0].entry).to.deep.equal({ @@ -419,7 +424,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.deep.equal('web'); expect(webpackConfig[0].mode).to.equal('production'); expect(webpackConfig[0].entry).to.deep.equal({ @@ -449,7 +454,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); expect(webpackConfig[0].mode).to.equal('production'); expect(webpackConfig[0].entry).to.deep.equal({ main: ['preload.js'] }); @@ -478,7 +483,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.deep.equal('web'); expect(webpackConfig[0].mode).to.equal('production'); expect(webpackConfig[0].entry).to.deep.equal({ @@ -510,7 +515,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); }); @@ -532,7 +537,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('electron-preload'); }); @@ -560,7 +565,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig[0].target).to.equal('web'); expect(webpackConfig[0].name).to.equal('preload'); }); @@ -609,7 +614,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); - const webpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + const webpackConfig = await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(webpackConfig.length).to.equal(4); }); @@ -627,7 +632,7 @@ describe('WebpackConfigGenerator', () => { }, } as WebpackPluginConfig; const generator = new WebpackConfigGenerator(config, mockProjectDir, false, 3000); - return generator.getRendererConfig(config.renderer.entryPoints); + return generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); }; const modelWebpackConfig = await generateWebpackConfig({ @@ -694,7 +699,7 @@ describe('WebpackConfigGenerator', () => { await generator.getMainConfig(); expect(getInvokedCounter()).to.equal(1); - await generator.getRendererConfig(config.renderer.entryPoints); + await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(getInvokedCounter()).to.equal(2); }); @@ -724,7 +729,7 @@ describe('WebpackConfigGenerator', () => { await generator.getMainConfig(); expect(getInvokedCounter()).to.equal(1); - await generator.getRendererConfig(config.renderer.entryPoints); + await generator.getRendererConfig(safeFirstRendererConfig(config.renderer)); expect(getInvokedCounter()).to.equal(2); }); }); diff --git a/packages/plugin/webpack/test/WebpackPlugin_spec.ts b/packages/plugin/webpack/test/WebpackPlugin_spec.ts index ddac6344eb..54a2ea6a13 100644 --- a/packages/plugin/webpack/test/WebpackPlugin_spec.ts +++ b/packages/plugin/webpack/test/WebpackPlugin_spec.ts @@ -6,7 +6,7 @@ import { IgnoreFunction } from '@electron/packager'; import { expect } from 'chai'; import * as fs from 'fs-extra'; -import { WebpackPluginConfig } from '../src/Config'; +import { WebpackPluginConfig, WebpackPluginRendererConfig } from '../src/Config'; import { WebpackPlugin } from '../src/WebpackPlugin'; describe('WebpackPlugin', () => { @@ -111,7 +111,7 @@ describe('WebpackPlugin', () => { it('ignores files generated by jsonStats config', async () => { const webpackConfig = { ...baseConfig, jsonStats: true }; - webpackConfig.renderer.jsonStats = true; + (webpackConfig.renderer as WebpackPluginRendererConfig).jsonStats = true; plugin = new WebpackPlugin(webpackConfig); const config = await plugin.resolveForgeConfig({} as ResolvedForgeConfig); const ignore = config.packagerConfig.ignore as IgnoreFunction;