Skip to content

Commit

Permalink
refactor(plugin-webpack): cleanup (#2368)
Browse files Browse the repository at this point in the history
* refactor(plugin-webpack): convert sourceMapOption into a property
* refactor(plugin-webpack): clearer hook signature
* test(plugin-webpack): remove problematic exits-early test
  • Loading branch information
malept committed Jul 11, 2021
1 parent 84aaa8c commit 597e263
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 44 deletions.
12 changes: 6 additions & 6 deletions packages/plugin/webpack/src/WebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export default class WebpackConfigGenerator {
return this.isProd ? 'production' : 'development';
}

get rendererSourceMapOption() {
return this.isProd ? 'source-map' : 'eval-source-map';
}

get rendererTarget() {
return this.pluginConfig.renderer.nodeIntegration ? 'electron-renderer' : 'web';
}
Expand Down Expand Up @@ -124,10 +128,6 @@ export default class WebpackConfigGenerator {
return defines;
}

sourceMapOption() {
return this.isProd ? 'source-map' : 'eval-source-map';
}

getMainConfig() {
const mainConfig = this.resolveConfig(this.pluginConfig.mainConfig);

Expand Down Expand Up @@ -181,7 +181,7 @@ export default class WebpackConfigGenerator {
const prefixedEntries = entryPoint.prefixedEntries || [];

return webpackMerge({
devtool: this.sourceMapOption(),
devtool: this.rendererSourceMapOption,
mode: this.mode,
entry: prefixedEntries.concat([
entryPoint.js,
Expand Down Expand Up @@ -218,7 +218,7 @@ export default class WebpackConfigGenerator {
}) as WebpackPluginInstance).concat([new webpack.DefinePlugin(defines)]);
return webpackMerge({
entry,
devtool: this.sourceMapOption(),
devtool: this.rendererSourceMapOption,
target: this.rendererTarget,
mode: this.mode,
output: {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
await this.compileRenderers();
};
case 'postStart':
return async (_: any, child: ElectronProcess) => {
return async (_config: ForgeConfig, child: ElectronProcess) => {
if (!this.loggedOutputUrl) {
console.info(`\n\nWebpack Output Available: ${(`http://localhost:${this.loggerPort}`).cyan}\n`);
this.loggedOutputUrl = true;
Expand Down
39 changes: 2 additions & 37 deletions packages/plugin/webpack/test/WebpackPlugin_spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'chai';
import { ForgeConfig } from '@electron-forge/shared-types';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { tmpdir } from 'os';

import { WebpackPluginConfig } from '../src/Config';
import WebpackPlugin from '../src/WebpackPlugin';
Expand All @@ -16,7 +16,7 @@ describe('WebpackPlugin', () => {
},
};

const webpackTestDir = path.resolve(tmpdir(), 'electron-forge-plugin-webpack-test');
const webpackTestDir = path.resolve(os.tmpdir(), 'electron-forge-plugin-webpack-test');

describe('TCP port', () => {
it('should fail for privileged ports', () => {
Expand Down Expand Up @@ -107,39 +107,4 @@ describe('WebpackPlugin', () => {
});
});
});

describe('WebpackDevServer', () => {
let plugin: WebpackPlugin;
const webpackDevServerConfig: WebpackPluginConfig = {
mainConfig: {
entry: './foo/main.js',
},
renderer: {
config: {},
entryPoints: [
{
js: './foo/main.js',
name: 'main_window',
},
],
},
};
const mainFile = path.join(webpackTestDir, 'main', 'index.js');
const rendererFile = path.join(webpackTestDir, 'renderer', 'main_window', 'index.js');
before(async () => {
plugin = new WebpackPlugin(webpackDevServerConfig);
plugin.setDirectories(webpackTestDir);
await plugin.startLogic();
});

after(async () => {
plugin.exitHandler({ cleanup: true, exit: true });
await fs.remove(webpackTestDir);
});

it('writesToDisk', async () => {
expect(await fs.pathExists(mainFile)).to.equal(true);
expect(await fs.pathExists(rendererFile)).to.equal(true);
});
});
});

0 comments on commit 597e263

Please sign in to comment.