diff --git a/src/rebuild.ts b/src/rebuild.ts index 4d0dc179..44d8070a 100644 --- a/src/rebuild.ts +++ b/src/rebuild.ts @@ -29,6 +29,7 @@ export interface RebuildOptions { forceABI?: number; disablePreGypCopy?: boolean; buildFromSource?: boolean; + ignoreModules?: string[]; } export interface RebuilderOptions extends RebuildOptions { @@ -62,6 +63,7 @@ export class Rebuilder implements IRebuilder { public useElectronClang: boolean; public disablePreGypCopy: boolean; public buildFromSource: boolean; + public ignoreModules: string[]; constructor(options: RebuilderOptions) { this.lifecycle = options.lifecycle; @@ -79,6 +81,8 @@ export class Rebuilder implements IRebuilder { this.msvsVersion = process.env.GYP_MSVS_VERSION; this.disablePreGypCopy = options.disablePreGypCopy || false; this.buildFromSource = options.buildFromSource || false; + this.ignoreModules = options.ignoreModules || []; + d('ignoreModules', this.ignoreModules); 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.'); @@ -170,17 +174,31 @@ export class Rebuilder implements IRebuilder { const moduleRebuilder = new ModuleRebuilder(this, modulePath); - this.lifecycle.emit('module-found', path.basename(modulePath)); + let moduleName = path.basename(modulePath); + const parentName = path.basename(path.dirname(modulePath)); + if (parentName !== 'node_modules') { + moduleName = `${parentName}/${moduleName}`; + } + + this.lifecycle.emit('module-found', moduleName); if (!this.force && await moduleRebuilder.alreadyBuiltByRebuild()) { - d(`skipping: ${path.basename(modulePath)} as it is already built`); - this.lifecycle.emit('module-done'); - this.lifecycle.emit('module-skip'); + d(`skipping: ${moduleName} as it is already built`); + this.lifecycle.emit('module-done', moduleName); + this.lifecycle.emit('module-skip', moduleName); + return; + } + + d('checking', moduleName, 'against', this.ignoreModules); + if (this.ignoreModules.includes(moduleName)) { + d(`skipping: ${moduleName} as it is in the ignoreModules array`); + this.lifecycle.emit('module-done', moduleName); + this.lifecycle.emit('module-skip', moduleName); return; } if (await moduleRebuilder.prebuildInstallNativeModuleExists()) { - d(`skipping: ${path.basename(modulePath)} as it was prebuilt`); + d(`skipping: ${moduleName} as it was prebuilt`); return; } @@ -198,13 +216,13 @@ export class Rebuilder implements IRebuilder { const applyDiffFn = await lookupModuleState(this.cachePath, cacheKey); if (typeof applyDiffFn === 'function') { await applyDiffFn(modulePath); - this.lifecycle.emit('module-done'); + this.lifecycle.emit('module-done', moduleName); return; } } if (await moduleRebuilder.rebuild(cacheKey)) { - this.lifecycle.emit('module-done'); + this.lifecycle.emit('module-done', moduleName); } } } diff --git a/test/rebuild.ts b/test/rebuild.ts index 4b072af4..f5dfdd68 100644 --- a/test/rebuild.ts +++ b/test/rebuild.ts @@ -112,6 +112,33 @@ describe('rebuilder', () => { }); }); + describe('ignore rebuild', function() { + this.timeout(2 * MINUTES_IN_MILLISECONDS); + + before(async () => await resetTestModule(testModulePath)); + after(async () => await cleanupTestModule(testModulePath)); + afterEach(resetMSVSVersion); + + const buildPath = testModulePath; + const electronVersion = testElectronVersion; + const arch = process.arch; + + it('should rebuild all modules again when enabled', async function() { + if (process.platform === 'win32') { + this.timeout(5 * MINUTES_IN_MILLISECONDS); + } + await rebuild({ buildPath, electronVersion, arch }); + resetMSVSVersion(); + const rebuilder = rebuild({ buildPath, electronVersion, arch, ignoreModules: ['native-hello-world'], force: true }); + let skipped = 0; + rebuilder.lifecycle.on('module-skip', () => { + skipped++; + }); + await rebuilder; + expect(skipped).to.equal(1); + }); + }); + describe('only rebuild', function() { this.timeout(2 * MINUTES_IN_MILLISECONDS);