diff --git a/src/rebuild.ts b/src/rebuild.ts index f427556a..5db1e19a 100644 --- a/src/rebuild.ts +++ b/src/rebuild.ts @@ -139,13 +139,7 @@ export class Rebuilder implements IRebuilder { this.lifecycle.emit('start'); - await this.moduleWalker.walkModules(); - - for (const nodeModulesPath of await this.moduleWalker.nodeModulesPaths) { - await this.moduleWalker.findAllModulesIn(nodeModulesPath); - } - - for (const modulePath of this.moduleWalker.modulesToRebuild) { + for (const modulePath of await this.modulesToRebuild()) { this.rebuilds.push(() => this.rebuildModuleAt(modulePath)); } @@ -160,6 +154,16 @@ export class Rebuilder implements IRebuilder { } } + async modulesToRebuild(): Promise { + await this.moduleWalker.walkModules(); + + for (const nodeModulesPath of await this.moduleWalker.nodeModulesPaths) { + await this.moduleWalker.findAllModulesIn(nodeModulesPath); + } + + return this.moduleWalker.modulesToRebuild; + } + async rebuildModuleAt(modulePath: string): Promise { if (!(await fs.pathExists(path.resolve(modulePath, 'binding.gyp')))) { return; diff --git a/test/fixture/empty-project/node_modules/extra/package.json b/test/fixture/empty-project/node_modules/extra/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/test/fixture/empty-project/node_modules/extra/package.json @@ -0,0 +1 @@ +{} diff --git a/test/fixture/empty-project/package.json b/test/fixture/empty-project/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/test/fixture/empty-project/package.json @@ -0,0 +1 @@ +{} diff --git a/test/helpers/module-setup.ts b/test/helpers/module-setup.ts index b9774b41..fa34f6fd 100644 --- a/test/helpers/module-setup.ts +++ b/test/helpers/module-setup.ts @@ -29,13 +29,3 @@ export async function cleanupTestModule(testModulePath: string): Promise { await fs.remove(testModulePath); resetMSVSVersion(); } - -export async function clearTestModuleDependencies(testModulePath: string): Promise { - const packageJsonPath = path.join(testModulePath, 'package.json'); - const packageJson = await fs.readJSON(packageJsonPath); - packageJson.dependencies = {}; - packageJson.devDependencies = {}; - packageJson.optionalDependencies = {}; - packageJson.peerDependencies = {}; - await fs.writeJSON(packageJsonPath, packageJson, { spaces: 2 }); -} diff --git a/test/rebuild.ts b/test/rebuild.ts index ec5706fa..52559d1e 100644 --- a/test/rebuild.ts +++ b/test/rebuild.ts @@ -1,12 +1,13 @@ +import { EventEmitter } from 'events'; import { expect } from 'chai'; import * as fs from 'fs-extra'; import * as path from 'path'; import * as os from 'os'; -import { cleanupTestModule, clearTestModuleDependencies, MINUTES_IN_MILLISECONDS, resetMSVSVersion, resetTestModule, TIMEOUT_IN_MILLISECONDS } from './helpers/module-setup'; +import { cleanupTestModule, MINUTES_IN_MILLISECONDS, resetMSVSVersion, resetTestModule, TIMEOUT_IN_MILLISECONDS } from './helpers/module-setup'; import { expectNativeModuleToBeRebuilt, expectNativeModuleToNotBeRebuilt } from './helpers/rebuild'; import { getExactElectronVersionSync } from './helpers/electron-version'; -import { rebuild } from '../src/rebuild'; +import { Rebuilder, rebuild } from '../src/rebuild'; const testElectronVersion = getExactElectronVersionSync(); @@ -123,7 +124,6 @@ describe('rebuilder', () => { afterEach(async() => await cleanupTestModule(testModulePath)); it('should rebuild only specified modules', async () => { - await clearTestModuleDependencies(testModulePath); const nativeModuleBinary = path.join(testModulePath, 'node_modules', 'native-hello-world', 'build', 'Release', 'hello_world.node'); expect(await fs.pathExists(nativeModuleBinary)).to.be.true; await fs.remove(nativeModuleBinary); @@ -133,7 +133,6 @@ describe('rebuilder', () => { electronVersion: testElectronVersion, arch: process.arch, onlyModules: ['native-hello-world'], - extraModules: ['native-hello-world', 'ffi-napi', 'ref-napi'], force: true }); let built = 0; @@ -158,6 +157,20 @@ describe('rebuilder', () => { }); }); + describe('with extraModules', () => { + it('should rebuild existing modules in extraModules despite them not being found during the module walk', async () => { + const rebuilder = new Rebuilder({ + buildPath: path.join(__dirname, 'fixture', 'empty-project'), + electronVersion: testElectronVersion, + lifecycle: new EventEmitter(), + extraModules: ['extra'] + }); + const modulesToRebuild = await rebuilder.modulesToRebuild(); + expect(modulesToRebuild).to.have.length(1); + expect(modulesToRebuild[0].endsWith('extra')).to.be.true; + }); + }); + describe('debug rebuild', function() { this.timeout(10 * MINUTES_IN_MILLISECONDS);