Skip to content

Commit

Permalink
fix(plugin-webpack): correctly define the asset relocator base dir (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Quillan committed Nov 25, 2020
1 parent 7e3227b commit 390219f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugin/webpack/src/WebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class WebpackConfigGenerator {

getDefines(inRendererDir = true) {
const defines: { [key: string]: string; } = {
ASSET_RELOCATOR_BASE_DIR: this.assetRelocatorBaseDir(),
ASSET_RELOCATOR_BASE_DIR: this.assetRelocatorBaseDir(inRendererDir),
};
if (
!this.pluginConfig.renderer.entryPoints
Expand Down
62 changes: 62 additions & 0 deletions packages/plugin/webpack/test/WebpackConfig_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,68 @@ describe('WebpackConfigGenerator', () => {
expect(() => generator.getDefines()).to.throw(/renderer.entryPoints.* has not been defined/);
});

it('sets the renderer asset relocator base dir in development', () => {
const config = {
renderer: {
entryPoints: [{
name: 'hello',
js: 'foo.js',
}],
},
} as WebpackPluginConfig;
const generator = new WebpackConfigGenerator(config, '/', false, 3000);
const defines = generator.getDefines(false);

expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal(JSON.stringify(path.resolve('/.webpack', 'renderer', 'any_folder')));
});

it('sets the renderer asset relocator base dir in production', () => {
const config = {
renderer: {
entryPoints: [{
name: 'hello',
js: 'foo.js',
}],
},
} as WebpackPluginConfig;
const generator = new WebpackConfigGenerator(config, '/', true, 3000);
const defines = generator.getDefines(false);

// eslint-disable-next-line no-template-curly-in-string
expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal('process.resourcesPath + "/" + (__filename.includes(".asar") ? "app.asar" : "app") + "/.webpack/renderer/any_folder"');
});

it('sets the main asset relocator base dir in development', () => {
const config = {
renderer: {
entryPoints: [{
name: 'hello',
js: 'foo.js',
}],
},
} as WebpackPluginConfig;
const generator = new WebpackConfigGenerator(config, '/', false, 3000);
const defines = generator.getDefines(true);

expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal(JSON.stringify(path.resolve('/.webpack', 'main', '.')));
});

it('sets the main asset relocator base dir in production', () => {
const config = {
renderer: {
entryPoints: [{
name: 'hello',
js: 'foo.js',
}],
},
} as WebpackPluginConfig;
const generator = new WebpackConfigGenerator(config, '/', true, 3000);
const defines = generator.getDefines(true);

// eslint-disable-next-line no-template-curly-in-string
expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal('process.resourcesPath + "/" + (__filename.includes(".asar") ? "app.asar" : "app") + "/.webpack/main"');
});

it('sets the renderer entry point to a JS file in development', () => {
const config = {
renderer: {
Expand Down

0 comments on commit 390219f

Please sign in to comment.