Skip to content

Commit 63aef81

Browse files
committed
feat: Add support for build-from-source argument
1 parent 20107a8 commit 63aef81

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Options:
7979
-b, --debug Build debug version of modules
8080
--prebuild-tag-prefix GitHub tag prefix passed to prebuild-install.
8181
Default is "v"
82+
--force-build-from-source Skip prebuild download and rebuild module from
83+
source. Default is false
8284
8385
Copyright 2016
8486
```

src/cli.ts

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const argv = yargs(process.argv.slice(2)).version(false).options({
2828
sequential: { alias: 's', type: 'boolean', description: 'Rebuild modules sequentially, this is enabled by default on Windows' },
2929
debug: { alias: 'b', type: 'boolean', description: 'Build debug version of modules' },
3030
'prebuild-tag-prefix': { type: 'string', description: 'GitHub tag prefix passed to prebuild-install. Default is "v"' },
31+
'force-build-from-source': { type: 'boolean', description: 'Skip prebuild download and rebuild module from source. Default is false' },
3132
'force-abi': { type: 'number', description: 'Override the ABI version for the version of Electron you are targeting. Only use when targeting Nightly releases.' },
3233
'use-electron-clang': { type: 'boolean', description: 'Use the clang executable that Electron used when building its binary. This will guarantee compiler compatibility' },
3334
'disable-pre-gyp-copy': { type: 'boolean', description: 'Disables the pre-gyp copy step' },
@@ -124,6 +125,7 @@ process.on('unhandledRejection', handler);
124125
mode: argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined),
125126
debug: argv.debug,
126127
prebuildTagPrefix: (argv.prebuildTagPrefix as string) || 'v',
128+
forceBuildFromSource: argv.forceBuildFromSource || false,
127129
forceABI: argv.forceAbi as number,
128130
useElectronClang: !!argv.useElectronClang,
129131
disablePreGypCopy: !!argv.disablePreGypCopy,

src/module-type/prebuild-install.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,30 @@ export class PrebuildInstall extends NativeModule {
1818
}
1919

2020
async run(prebuildInstallPath: string): Promise<void> {
21-
const shimExt = process.env.ELECTRON_REBUILD_TESTS ? 'ts' : 'js';
2221
const executable = process.env.ELECTRON_REBUILD_TESTS ? path.resolve(__dirname, '..', '..', 'node_modules', '.bin', 'ts-node') : process.execPath;
2322

2423
await spawn(
2524
executable,
26-
[
27-
path.resolve(__dirname, '..', `prebuild-shim.${shimExt}`),
28-
prebuildInstallPath,
29-
`--arch=${this.rebuilder.arch}`,
30-
`--platform=${this.rebuilder.platform}`,
31-
`--tag-prefix=${this.rebuilder.prebuildTagPrefix}`,
32-
...await this.getPrebuildInstallRuntimeArgs(),
33-
],
25+
await this.getPrebuildInstallArgs(prebuildInstallPath),
3426
{
3527
cwd: this.modulePath,
3628
}
3729
);
3830
}
3931

32+
async getPrebuildInstallArgs(prebuildInstallPath: string): Promise<string[]> {
33+
const shimExt = process.env.ELECTRON_REBUILD_TESTS ? 'ts' : 'js';
34+
return [
35+
path.resolve(__dirname, '..', `prebuild-shim.${shimExt}`),
36+
prebuildInstallPath,
37+
`--arch=${this.rebuilder.arch}`,
38+
`--platform=${this.rebuilder.platform}`,
39+
`--tag-prefix=${this.rebuilder.prebuildTagPrefix}`,
40+
this.rebuilder.forceBuildFromSource ? `--build-from-source` : '',
41+
...(await this.getPrebuildInstallRuntimeArgs()),
42+
].filter(Boolean);
43+
}
44+
4045
async findPrebuiltModule(): Promise<boolean> {
4146
const prebuildInstallPath = await this.locateBinary();
4247
if (prebuildInstallPath) {

src/rebuild.ts

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface RebuildOptions {
2525
useElectronClang?: boolean;
2626
cachePath?: string;
2727
prebuildTagPrefix?: string;
28+
forceBuildFromSource?: boolean;
2829
projectRootPath?: string;
2930
forceABI?: number;
3031
disablePreGypCopy?: boolean;
@@ -57,6 +58,7 @@ export class Rebuilder implements IRebuilder {
5758
public useCache: boolean;
5859
public cachePath: string;
5960
public prebuildTagPrefix: string;
61+
public forceBuildFromSource: boolean;
6062
public msvsVersion?: string;
6163
public useElectronClang: boolean;
6264
public disablePreGypCopy: boolean;
@@ -74,6 +76,7 @@ export class Rebuilder implements IRebuilder {
7476
this.useElectronClang = options.useElectronClang || false;
7577
this.cachePath = options.cachePath || path.resolve(os.homedir(), '.electron-rebuild-cache');
7678
this.prebuildTagPrefix = options.prebuildTagPrefix || 'v';
79+
this.forceBuildFromSource = options.forceBuildFromSource || false;
7780
this.msvsVersion = process.env.GYP_MSVS_VERSION;
7881
this.disablePreGypCopy = options.disablePreGypCopy || false;
7982

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IRebuilder {
2323
msvsVersion?: string;
2424
platform: string;
2525
prebuildTagPrefix: string;
26+
forceBuildFromSource: boolean;
2627
useCache: boolean;
2728
useElectronClang: boolean;
2829
}

test/module-type-prebuild-install.ts

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ describe('prebuild-install', () => {
4242
])
4343
});
4444

45+
it('should pass --build-from-source to prebuild-install when forceBuildFromSource is true', async () => {
46+
const rebuilder = new Rebuilder({
47+
...rebuilderArgs,
48+
forceBuildFromSource: true,
49+
});
50+
const prebuildInstall = new PrebuildInstall(rebuilder, modulePath);
51+
console.log(await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path'))
52+
expect(
53+
await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path')
54+
).to.include('--build-from-source');
55+
});
56+
4557
it('should not fail running prebuild-install', async () => {
4658
const rebuilder = new Rebuilder(rebuilderArgs);
4759
const prebuildInstall = new PrebuildInstall(rebuilder, modulePath);

0 commit comments

Comments
 (0)