Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require node-gyp@^8.4.0 & handle old Electron versions #907

Merged
merged 7 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"lzma-native": "^8.0.1",
"node-abi": "^3.0.0",
"node-api-version": "^0.1.4",
"node-gyp": "^8.1.0",
"node-gyp": "^8.4.0",
"ora": "^5.1.0",
"tar": "^6.0.5",
"yargs": "^17.0.1"
Expand Down
11 changes: 11 additions & 0 deletions src/module-type/node-gyp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ export class NodeGyp extends NativeModule {
args.push(`--msvs_version=${this.rebuilder.msvsVersion}`);
}

// Headers of old Electron versions do not have a valid config.gypi file
// and --force-process-config must be passed to node-gyp >= 8.4.0 to
// correctly build modules for them.
// See also https://github.com/nodejs/node-gyp/pull/2497
const [major, minor] = this.rebuilder.electronVersion.split('.').slice(0, 2).map(n => parseInt(n, 10));
if ((major <= 13) ||
(major == 14 && minor <= 1) ||
(major == 15 && minor <= 2)) {
malept marked this conversation as resolved.
Show resolved Hide resolved
args.push('--force-process-config');
}

return args;
}

Expand Down
6 changes: 4 additions & 2 deletions test/helpers/module-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export function resetMSVSVersion(): void {
}
}

export async function resetTestModule(testModulePath: string): Promise<void> {
export async function resetTestModule(testModulePath: string, installModules = true): Promise<void> {
await fs.remove(testModulePath);
await fs.mkdir(testModulePath, { recursive: true });
await fs.copyFile(
path.resolve(__dirname, '../../test/fixture/native-app1/package.json'),
path.resolve(testModulePath, 'package.json')
);
await spawn('npm', ['install'], { cwd: testModulePath });
if (installModules) {
await spawn('npm', ['install'], { cwd: testModulePath });
}
resetMSVSVersion();
}

Expand Down
61 changes: 61 additions & 0 deletions test/module-type-node-gyp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { EventEmitter } from 'events';
import { expect } from 'chai';
import os from 'os';
import path from 'path';

import { cleanupTestModule, resetTestModule } from './helpers/module-setup';
import { NodeGyp } from '../src/module-type/node-gyp';
import { Rebuilder } from '../src/rebuild';

describe('node-gyp', () => {
describe('buildArgs', () => {
const testModulePath = path.resolve(os.tmpdir(), 'electron-rebuild-test');

before(async () => await resetTestModule(testModulePath, false));
after(async () => await cleanupTestModule(testModulePath));

function nodeGypArgsForElectronVersion(electronVersion: string): Promise<string[]> {
const rebuilder = new Rebuilder({
buildPath: testModulePath,
electronVersion: electronVersion,
lifecycle: new EventEmitter()
});
const nodeGyp = new NodeGyp(rebuilder, testModulePath);
return nodeGyp.buildArgs([]);
}

context('sufficiently old Electron versions which lack a bundled config.gypi', () => {
it('adds --force-process-config for < 14', async () => {
const args = await nodeGypArgsForElectronVersion('12.0.0');
expect(args).to.include('--force-process-config');
});

it('adds --force-process-config for between 14.0.0 and < 14.2.0', async () => {
const args = await nodeGypArgsForElectronVersion('14.1.0');
expect(args).to.include('--force-process-config');
});

it('adds --force-process-config for versions between 15.0.0 and < 15.3.0', async () => {
const args = await nodeGypArgsForElectronVersion('15.2.0');
expect(args).to.include('--force-process-config');
});
});

context('for sufficiently new Electron versions', () => {
it('does not add --force-process-config for ^14.2.0', async () => {
const args = await nodeGypArgsForElectronVersion('14.2.0');
expect(args).to.not.include('--force-process-config');
});

it('does not add --force-process-config for ^15.3.0', async () => {
const args = await nodeGypArgsForElectronVersion('15.3.0');
expect(args).to.not.include('--force-process-config');
});

it('does not add --force-process-config for >= 16.0.0', async () => {
const args = await nodeGypArgsForElectronVersion('16.0.0-beta.1');
expect(args).to.not.include('--force-process-config');
});
});
});
});
42 changes: 26 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4624,13 +4624,13 @@ make-fetch-happen@^5.0.0:
socks-proxy-agent "^4.0.0"
ssri "^6.0.0"

make-fetch-happen@^8.0.14:
version "8.0.14"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-8.0.14.tgz#aaba73ae0ab5586ad8eaa68bd83332669393e222"
integrity sha512-EsS89h6l4vbfJEtBZnENTOFk8mCRpY5ru36Xe5bcX1KYIli2mkSHqoFsp5O1wMDvTJJzxe/4THpCTtygjeeGWQ==
make-fetch-happen@^9.0.1, make-fetch-happen@^9.0.4:
version "9.0.4"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-9.0.4.tgz#ceaa100e60e0ef9e8d1ede94614bb2ba83c8bb24"
integrity sha512-sQWNKMYqSmbAGXqJg2jZ+PmHh5JAybvwu0xM8mZR/bsTjGiTASj3ldXJV7KFHy1k/IJIBkjxQFoWIVsv9+PQMg==
dependencies:
agentkeepalive "^4.1.3"
cacache "^15.0.5"
cacache "^15.2.0"
http-cache-semantics "^4.1.0"
http-proxy-agent "^4.0.1"
https-proxy-agent "^5.0.0"
Expand All @@ -4641,14 +4641,15 @@ make-fetch-happen@^8.0.14:
minipass-fetch "^1.3.2"
minipass-flush "^1.0.5"
minipass-pipeline "^1.2.4"
negotiator "^0.6.2"
promise-retry "^2.0.1"
socks-proxy-agent "^5.0.0"
ssri "^8.0.0"

make-fetch-happen@^9.0.1, make-fetch-happen@^9.0.4:
version "9.0.4"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-9.0.4.tgz#ceaa100e60e0ef9e8d1ede94614bb2ba83c8bb24"
integrity sha512-sQWNKMYqSmbAGXqJg2jZ+PmHh5JAybvwu0xM8mZR/bsTjGiTASj3ldXJV7KFHy1k/IJIBkjxQFoWIVsv9+PQMg==
make-fetch-happen@^9.1.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz#53085a09e7971433e6765f7971bf63f4e05cb968"
integrity sha512-+zopwDy7DNknmwPQplem5lAZX/eCOzSvSNNcSKm5eVwTkOBzoktEfXsa9L23J/GIRhxRsaxzkPEhrJEpE2F4Gg==
dependencies:
agentkeepalive "^4.1.3"
cacache "^15.2.0"
Expand All @@ -4664,7 +4665,7 @@ make-fetch-happen@^9.0.1, make-fetch-happen@^9.0.4:
minipass-pipeline "^1.2.4"
negotiator "^0.6.2"
promise-retry "^2.0.1"
socks-proxy-agent "^5.0.0"
socks-proxy-agent "^6.0.0"
ssri "^8.0.0"

map-obj@^1.0.0:
Expand Down Expand Up @@ -5100,15 +5101,15 @@ node-gyp@^7.1.0, node-gyp@^7.1.2:
tar "^6.0.2"
which "^2.0.2"

node-gyp@^8.1.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.2.0.tgz#ef509ccdf5cef3b4d93df0690b90aa55ff8c7977"
integrity sha512-KG8SdcoAnw2d6augGwl1kOayALUrXW/P2uOAm2J2+nmW/HjZo7y+8TDg7LejxbekOOSv3kzhq+NSUYkIDAX8eA==
node-gyp@^8.4.0:
version "8.4.0"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.0.tgz#6e1112b10617f0f8559c64b3f737e8109e5a8338"
integrity sha512-Bi/oCm5bH6F+FmzfUxJpPaxMEyIhszULGR3TprmTeku8/dMFcdTcypk120NeZqEt54r1BrgEKtm2jJiuIKE28Q==
dependencies:
env-paths "^2.2.0"
glob "^7.1.4"
graceful-fs "^4.2.6"
make-fetch-happen "^8.0.14"
make-fetch-happen "^9.1.0"
nopt "^5.0.0"
npmlog "^4.1.2"
rimraf "^3.0.2"
Expand Down Expand Up @@ -6851,7 +6852,16 @@ socks-proxy-agent@^5.0.0:
debug "4"
socks "^2.3.3"

socks@^2.3.3:
socks-proxy-agent@^6.0.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-6.1.0.tgz#869cf2d7bd10fea96c7ad3111e81726855e285c3"
integrity sha512-57e7lwCN4Tzt3mXz25VxOErJKXlPfXmkMLnk310v/jwW20jWRVcgsOit+xNkN3eIEdB47GwnfAEBLacZ/wVIKg==
dependencies:
agent-base "^6.0.2"
debug "^4.3.1"
socks "^2.6.1"

socks@^2.3.3, socks@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/socks/-/socks-2.6.1.tgz#989e6534a07cf337deb1b1c94aaa44296520d30e"
integrity sha512-kLQ9N5ucj8uIcxrDwjm0Jsqk06xdpBjGNQtpXy4Q8/QY2k+fY7nZH8CARy+hkbG+SGAovmzzuauCpBlb8FrnBA==
Expand Down