From be3893c56a9905b8b1406cb84b36e51fd66ad62c Mon Sep 17 00:00:00 2001 From: George Xu <33054982+georgexu99@users.noreply.github.com> Date: Mon, 21 Aug 2023 11:29:03 -0700 Subject: [PATCH] Revert "feat: add node-pre-gyp support (#1095)" This reverts commit e71316b6a508e1bd349f61df8f3631d40f91e123. --- package.json | 2 +- src/cli.ts | 1 - src/module-rebuilder.ts | 31 ++---------- src/module-type/node-pre-gyp.ts | 68 --------------------------- src/rebuild.ts | 3 -- src/types.ts | 1 - test/fixture/native-app1/package.json | 3 +- test/helpers/module-setup.ts | 2 +- test/module-type-node-pre-gyp.ts | 50 -------------------- test/module-type-prebuild-install.ts | 5 +- test/rebuild-napibuildversion.ts | 5 +- test/rebuild.ts | 2 +- yarn.lock | 8 ++-- 13 files changed, 14 insertions(+), 167 deletions(-) delete mode 100644 src/module-type/node-pre-gyp.ts delete mode 100644 test/module-type-node-pre-gyp.ts diff --git a/package.json b/package.json index a80f5e20..3ba4bc43 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "detect-libc": "^2.0.1", "fs-extra": "^10.0.0", "got": "^11.7.0", - "node-abi": "^3.45.0", + "node-abi": "^3.0.0", "node-api-version": "^0.1.4", "node-gyp": "^9.0.0", "ora": "^5.1.0", diff --git a/src/cli.ts b/src/cli.ts index caf8ea75..358a10ff 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -128,7 +128,6 @@ process.on('unhandledRejection', handler); useElectronClang: !!argv.useElectronClang, disablePreGypCopy: !!argv.disablePreGypCopy, projectRootPath, - buildFromSource: !!argv.buildFromSource, }); const lifecycle = rebuilder.lifecycle; diff --git a/src/module-rebuilder.ts b/src/module-rebuilder.ts index 368ca249..f6850ca9 100644 --- a/src/module-rebuilder.ts +++ b/src/module-rebuilder.ts @@ -6,7 +6,6 @@ import { cacheModuleState } from './cache'; import { NodeGyp } from './module-type/node-gyp/node-gyp'; import { Prebuildify } from './module-type/prebuildify'; import { PrebuildInstall } from './module-type/prebuild-install'; -import { NodePreGyp } from './module-type/node-pre-gyp'; import { IRebuilder } from './types'; const d = debug('electron-rebuild'); @@ -17,7 +16,6 @@ export class ModuleRebuilder { private rebuilder: IRebuilder; private prebuildify: Prebuildify; private prebuildInstall: PrebuildInstall; - private nodePreGyp: NodePreGyp; constructor(rebuilder: IRebuilder, modulePath: string) { this.modulePath = modulePath; @@ -26,7 +24,6 @@ export class ModuleRebuilder { this.nodeGyp = new NodeGyp(rebuilder, modulePath); this.prebuildify = new Prebuildify(rebuilder, modulePath); this.prebuildInstall = new PrebuildInstall(rebuilder, modulePath); - this.nodePreGyp = new NodePreGyp(rebuilder, modulePath); } get metaPath(): string { @@ -92,21 +89,6 @@ export class ModuleRebuilder { return false; } - async findNodePreGypInstallModule(cacheKey: string): Promise { - if (await this.nodePreGyp.usesTool()) { - d(`assuming is node-pre-gyp powered: ${this.nodePreGyp.moduleName}`); - - if (await this.nodePreGyp.findPrebuiltModule()) { - d('installed prebuilt module:', this.nodePreGyp.moduleName); - await this.writeMetadata(); - await this.cacheModuleState(cacheKey); - return true; - } - } - - return false; - } - async rebuildNodeGypModule(cacheKey: string): Promise { await this.nodeGyp.rebuildModule(); d('built via node-gyp:', this.nodeGyp.moduleName); @@ -142,15 +124,8 @@ export class ModuleRebuilder { } async rebuild(cacheKey: string): Promise { - if ( - !this.rebuilder.buildFromSource && ( - (await this.findPrebuildifyModule(cacheKey)) || - (await this.findPrebuildInstallModule(cacheKey)) || - (await this.findNodePreGypInstallModule(cacheKey))) - ) { - return true; - } - - return await this.rebuildNodeGypModule(cacheKey); + return (await this.findPrebuildifyModule(cacheKey)) || + (await this.findPrebuildInstallModule(cacheKey)) || + (await this.rebuildNodeGypModule(cacheKey)); } } diff --git a/src/module-type/node-pre-gyp.ts b/src/module-type/node-pre-gyp.ts deleted file mode 100644 index 6be2f193..00000000 --- a/src/module-type/node-pre-gyp.ts +++ /dev/null @@ -1,68 +0,0 @@ -import debug from 'debug'; -import { spawn } from '@malept/cross-spawn-promise'; - -import { locateBinary, NativeModule } from '.'; -const d = debug('electron-rebuild'); - -export class NodePreGyp extends NativeModule { - async usesTool(): Promise { - const dependencies = await this.packageJSONFieldWithDefault('dependencies', {}); - // eslint-disable-next-line no-prototype-builtins - return dependencies.hasOwnProperty('@mapbox/node-pre-gyp'); - } - - async locateBinary(): Promise { - return locateBinary(this.modulePath, 'node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp'); - } - - async run(nodePreGypPath: string): Promise { - await spawn( - process.execPath, - [ - nodePreGypPath, - 'reinstall', - '--fallback-to-build', - `--arch=${this.rebuilder.arch}`, - `--platform=${this.rebuilder.platform}`, - ...await this.getNodePreGypRuntimeArgs(), - ], - { - cwd: this.modulePath, - } - ); - } - - async findPrebuiltModule(): Promise { - const nodePreGypPath = await this.locateBinary(); - if (nodePreGypPath) { - d(`triggering prebuild download step: ${this.moduleName}`); - try { - await this.run(nodePreGypPath); - return true; - } catch (err) { - d('failed to use node-pre-gyp:', err); - - if (err?.message?.includes('requires Node-API but Electron')) { - throw err; - } - } - } else { - d(`could not find node-pre-gyp relative to: ${this.modulePath}`); - } - - return false; - } - - async getNodePreGypRuntimeArgs(): Promise { - const moduleNapiVersions = await this.getSupportedNapiVersions(); - if (moduleNapiVersions) { - return []; - } else { - return [ - '--runtime=electron', - `--target=${this.rebuilder.electronVersion}`, - `--dist-url=${this.rebuilder.headerURL}`, - ]; - } - } -} diff --git a/src/rebuild.ts b/src/rebuild.ts index 4d0dc179..58a54d14 100644 --- a/src/rebuild.ts +++ b/src/rebuild.ts @@ -28,7 +28,6 @@ export interface RebuildOptions { projectRootPath?: string; forceABI?: number; disablePreGypCopy?: boolean; - buildFromSource?: boolean; } export interface RebuilderOptions extends RebuildOptions { @@ -61,7 +60,6 @@ export class Rebuilder implements IRebuilder { public msvsVersion?: string; public useElectronClang: boolean; public disablePreGypCopy: boolean; - public buildFromSource: boolean; constructor(options: RebuilderOptions) { this.lifecycle = options.lifecycle; @@ -78,7 +76,6 @@ export class Rebuilder implements IRebuilder { this.prebuildTagPrefix = options.prebuildTagPrefix || 'v'; this.msvsVersion = process.env.GYP_MSVS_VERSION; this.disablePreGypCopy = options.disablePreGypCopy || false; - this.buildFromSource = options.buildFromSource || false; if (this.useCache && this.force) { console.warn('[WARNING]: Electron Rebuild has force enabled and cache enabled, force take precedence and the cache will not be used.'); diff --git a/src/types.ts b/src/types.ts index 393fee3d..59fa5c92 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,7 +23,6 @@ export interface IRebuilder { msvsVersion?: string; platform: string; prebuildTagPrefix: string; - buildFromSource: boolean; useCache: boolean; useElectronClang: boolean; } diff --git a/test/fixture/native-app1/package.json b/test/fixture/native-app1/package.json index 582aee4d..52b70d73 100644 --- a/test/fixture/native-app1/package.json +++ b/test/fixture/native-app1/package.json @@ -22,8 +22,7 @@ "farmhash": "3.2.1", "level": "6.0.0", "native-hello-world": "2.0.0", - "ref-napi": "1.4.2", - "sqlite3": "5.1.6" + "ref-napi": "1.4.2" }, "optionalDependencies": { "bcrypt": "3.0.6" diff --git a/test/helpers/module-setup.ts b/test/helpers/module-setup.ts index 3a784fa3..05a77fe8 100644 --- a/test/helpers/module-setup.ts +++ b/test/helpers/module-setup.ts @@ -35,7 +35,7 @@ export async function resetTestModule(testModulePath: string, installModules = t } export async function cleanupTestModule(testModulePath: string): Promise { - await fs.rmdir(testModulePath, { recursive: true, maxRetries: 10 }); + await fs.remove(testModulePath); resetMSVSVersion(); } diff --git a/test/module-type-node-pre-gyp.ts b/test/module-type-node-pre-gyp.ts deleted file mode 100644 index 8c375e34..00000000 --- a/test/module-type-node-pre-gyp.ts +++ /dev/null @@ -1,50 +0,0 @@ -import chai, { expect } from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import { EventEmitter } from 'events'; -import path from 'path'; - -import { cleanupTestModule, resetTestModule, TIMEOUT_IN_MILLISECONDS, TEST_MODULE_PATH as testModulePath } from './helpers/module-setup'; -import { NodePreGyp } from '../lib/module-type/node-pre-gyp'; -import { Rebuilder } from '../lib/rebuild'; - -chai.use(chaiAsPromised); - -describe('node-pre-gyp', () => { - const modulePath = path.join(testModulePath, 'node_modules', 'sqlite3'); - const rebuilderArgs = { - buildPath: testModulePath, - electronVersion: '8.0.0', - arch: process.arch, - lifecycle: new EventEmitter() - }; - - describe('Node-API support', function() { - this.timeout(TIMEOUT_IN_MILLISECONDS); - - before(async () => await resetTestModule(testModulePath)); - after(async () => await cleanupTestModule(testModulePath)); - - it('should find correct napi version and select napi args', async () => { - const rebuilder = new Rebuilder(rebuilderArgs); - const nodePreGyp = new NodePreGyp(rebuilder, modulePath); - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - expect(nodePreGyp.nodeAPI.getNapiVersion((await nodePreGyp.getSupportedNapiVersions())!)).to.equal(3); - expect(await nodePreGyp.getNodePreGypRuntimeArgs()).to.deep.equal([]) - }); - - it('should not fail running node-pre-gyp', async () => { - const rebuilder = new Rebuilder(rebuilderArgs); - const nodePreGyp = new NodePreGyp(rebuilder, modulePath); - expect(await nodePreGyp.findPrebuiltModule()).to.equal(true); - }); - - it('should throw error with unsupported Electron version', async () => { - const rebuilder = new Rebuilder({ - ...rebuilderArgs, - electronVersion: '2.0.0', - }); - const nodePreGyp = new NodePreGyp(rebuilder, modulePath); - expect(nodePreGyp.findPrebuiltModule()).to.eventually.be.rejectedWith("Native module 'sqlite3' requires Node-API but Electron v2.0.0 does not support Node-API"); - }); - }); -}); diff --git a/test/module-type-prebuild-install.ts b/test/module-type-prebuild-install.ts index a9ed893b..e812dcc7 100644 --- a/test/module-type-prebuild-install.ts +++ b/test/module-type-prebuild-install.ts @@ -35,10 +35,7 @@ describe('prebuild-install', () => { ]) }); - it('should not fail running prebuild-install', async function () { - if (process.platform === 'darwin' && process.arch === 'arm64') { - this.skip(); // farmhash module has no prebuilt binaries for ARM64 - } + it('should not fail running prebuild-install', async () => { const rebuilder = new Rebuilder(rebuilderArgs); const prebuildInstall = new PrebuildInstall(rebuilder, modulePath); expect(await prebuildInstall.findPrebuiltModule()).to.equal(true); diff --git a/test/rebuild-napibuildversion.ts b/test/rebuild-napibuildversion.ts index 1873f9b0..a579ea31 100644 --- a/test/rebuild-napibuildversion.ts +++ b/test/rebuild-napibuildversion.ts @@ -26,7 +26,7 @@ describe('rebuild with napi_build_versions in binary config', async function () // https://github.com/electron/rebuild/issues/554 const archs = ['x64', 'arm64'] for (const arch of archs) { - it(`${ arch } arch should have rebuilt binary with 'napi_build_versions' array and 'libc' provided`, async () => { + it(`${ arch } arch should have rebuilt bianry with 'napi_build_versions' array and 'libc' provided`, async () => { const libc = await detectLibc.family() || 'unknown' const binaryPath = napiBuildVersionSpecificPath(arch, libc) @@ -38,8 +38,7 @@ describe('rebuild with napi_build_versions in binary config', async function () await rebuild({ buildPath: testModulePath, electronVersion: testElectronVersion, - arch, - buildFromSource: true, // need to skip node-pre-gyp prebuilt binary + arch }); await expectNativeModuleToBeRebuilt(testModulePath, 'sqlite3'); diff --git a/test/rebuild.ts b/test/rebuild.ts index 4b072af4..b08afece 100644 --- a/test/rebuild.ts +++ b/test/rebuild.ts @@ -81,7 +81,7 @@ describe('rebuilder', () => { skipped++; }); await rebuilder; - expect(skipped).to.equal(8); + expect(skipped).to.equal(7); }); it('should rebuild all modules again when disabled but the electron ABI changed', async () => { diff --git a/yarn.lock b/yarn.lock index d7cfbc55..938b5142 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3210,10 +3210,10 @@ nerf-dart@^1.0.0: resolved "https://registry.yarnpkg.com/nerf-dart/-/nerf-dart-1.0.0.tgz#e6dab7febf5ad816ea81cf5c629c5a0ebde72c1a" integrity sha512-EZSPZB70jiVsivaBLYDCyntd5eH8NTSMOn3rB+HxwdmKThGELLdYv8qVIMWvZEFy9w8ZZpW9h9OB32l1rGtj7g== -node-abi@^3.45.0: - version "3.45.0" - resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.45.0.tgz#f568f163a3bfca5aacfce1fbeee1fa2cc98441f5" - integrity sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ== +node-abi@^3.0.0: + version "3.30.0" + resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.30.0.tgz#d84687ad5d24ca81cdfa912a36f2c5c19b137359" + integrity sha512-qWO5l3SCqbwQavymOmtTVuCWZE23++S+rxyoHjXqUmPyzRcaoI4lA2gO55/drddGnedAyjA7sk76SfQ5lfUMnw== dependencies: semver "^7.3.5"