Skip to content

Commit

Permalink
fix(plugin-webpack): rebuild native modules before packaging (#2584)
Browse files Browse the repository at this point in the history
* feat(core): add platform/arch arguments to prePackage hook
  • Loading branch information
malept authored Oct 18, 2021
1 parent f0f96c6 commit 21310bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/api/core/src/api/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default async ({
}

await runHook(forgeConfig, 'generateAssets', platform, arch);
await runHook(forgeConfig, 'prePackage');
await runHook(forgeConfig, 'prePackage', platform, arch);

d('packaging with options', packageOpts);

Expand Down
6 changes: 6 additions & 0 deletions packages/api/core/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BuildIdentifierConfig, BuildIdentifierMap, fromBuildIdentifier } from './forge-config';
import { getElectronVersion } from './electron-version';
import { hasYarn, yarnOrNpmSpawn } from './yarn-or-npm';
import rebuildHook from './rebuild';

export default class ForgeUtils {
/**
Expand All @@ -13,7 +15,11 @@ export default class ForgeUtils {
return fromBuildIdentifier(map);
}

getElectronVersion = getElectronVersion;

hasYarn = hasYarn;

rebuildHook = rebuildHook;

yarnOrNpmSpawn = yarnOrNpmSpawn;
}
1 change: 1 addition & 0 deletions packages/plugin/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@electron-forge/async-ora": "6.0.0-beta.61",
"@electron-forge/core": "^6.0.0-beta.61",
"@electron-forge/plugin-base": "6.0.0-beta.61",
"@electron-forge/shared-types": "6.0.0-beta.61",
"@electron-forge/web-multi-logger": "6.0.0-beta.61",
Expand Down
13 changes: 11 additions & 2 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* eslint "no-console": "off" */
import { asyncOra } from '@electron-forge/async-ora';
import PluginBase from '@electron-forge/plugin-base';
import { ElectronProcess, ForgeConfig, ForgeHookFn } from '@electron-forge/shared-types';
import { ElectronProcess, ForgeArch, ForgeConfig, ForgeHookFn, ForgePlatform } from '@electron-forge/shared-types';
import Logger, { Tab } from '@electron-forge/web-multi-logger';
import debug from 'debug';
import fs from 'fs-extra';
import http from 'http';
import { merge } from 'webpack-merge';
import path from 'path';
import { utils } from '@electron-forge/core';
import webpack, { Configuration, Watching } from 'webpack';
import WebpackDevServer from 'webpack-dev-server';

import { WebpackPluginConfig } from './Config';
import ElectronForgeLoggingPlugin from './util/ElectronForgeLogging';
import once from './util/once';
Expand Down Expand Up @@ -152,8 +154,15 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
switch (name) {
case 'prePackage':
this.isProd = true;
return async () => {
return async (config: ForgeConfig, platform: ForgePlatform, arch: ForgeArch) => {
await fs.remove(this.baseDir);
await utils.rebuildHook(
this.projectDir,
await utils.getElectronVersion(this.projectDir, await fs.readJson(path.join(this.projectDir, 'package.json'))),
platform,
arch,
config.electronRebuildConfig
);
await this.compileMain();
await this.compileRenderers();
};
Expand Down

0 comments on commit 21310bb

Please sign in to comment.