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: enforce extraModules to be a set of strings #888

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions src/module-walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ModuleWalker {
}

for (const key of depKeys) {
this.prodDeps[key] = true;
this.prodDeps.add(key);
const modulePaths: string[] = await searchForModule(
this.buildPath,
key,
Expand Down Expand Up @@ -97,11 +97,11 @@ export class ModuleWalker {

const callback = this.markChildrenAsProdDeps.bind(this);
for (const key of Object.keys(childPackageJson.dependencies || {}).concat(Object.keys(childPackageJson.optionalDependencies || {}))) {
if (this.prodDeps[key]) {
if (this.prodDeps.has(key)) {
continue;
}

this.prodDeps[key] = true;
this.prodDeps.add(key);

moduleWait.push(this.findModule(key, modulePath, callback));
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export class ModuleWalker {
}
this.realModulePaths.add(realPath);

if (this.prodDeps[`${prefix}${modulePath}`] && (!this.onlyModules || this.onlyModules.includes(modulePath))) {
if (this.prodDeps.has(`${prefix}${modulePath}`) && (!this.onlyModules || this.onlyModules.includes(modulePath))) {
this.modulesToRebuild.push(realPath);
}

Expand Down
20 changes: 12 additions & 8 deletions src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Rebuilder implements IRebuilder {

this.ABIVersion = options.forceABI?.toString();
const onlyModules = options.onlyModules || null;
const extraModules = (options.extraModules || []).reduce((acc: Set<string>, x: string) => acc.add(x), new Set<string>());
const extraModules = new Set(options.extraModules);
const types = options.types || defaultTypes;
this.moduleWalker = new ModuleWalker(
this.buildPath,
Expand Down Expand Up @@ -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));
}

Expand All @@ -160,6 +154,16 @@ export class Rebuilder implements IRebuilder {
}
}

async modulesToRebuild(): Promise<string[]> {
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<void> {
if (!(await fs.pathExists(path.resolve(modulePath, 'binding.gyp')))) {
return;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixture/empty-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
17 changes: 16 additions & 1 deletion test/rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EventEmitter } from 'events';
import { expect } from 'chai';
import * as fs from 'fs-extra';
import * as path from 'path';
Expand All @@ -6,7 +7,7 @@ import * as os from 'os';
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();

Expand Down Expand Up @@ -156,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);

Expand Down