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

Automatically mark 'electron' as a builtin module #6615

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions packages/utils/node-resolver-core/src/NodeResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,19 @@ export default class NodeResolver {
};
}

let builtin = this.findBuiltin(filename, env);
if (builtin === null) {
return null;
}

if (!this.shouldIncludeNodeModule(env, filename)) {
if (sourcePath && env.isLibrary) {
await this.checkExcludedDependency(sourcePath, filename, ctx);
}
return null;
}

let builtin = this.findBuiltin(filename, env);
if (builtin || builtin === null) {
if (builtin) {
return builtin;
}

Expand Down Expand Up @@ -505,6 +509,10 @@ export default class NodeResolver {
}
return {filePath: builtins[filename] || empty};
}

if (env.isElectron() && filename === 'electron') {
return null;
}
}

findNodeModulePath(
Expand Down
18 changes: 18 additions & 0 deletions packages/utils/node-resolver-core/test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ describe('resolver', function() {
});
assert.deepEqual(resolved, {isExcluded: true});
});

it('should exclude the electron module in electron environments', async function() {
let resolved = await resolver.resolve({
env: new Environment(
createEnvironment({
context: 'electron-main',
isLibrary: true,
}),
DEFAULT_OPTIONS,
),
filename: 'electron',
isURL: false,
parent: path.join(rootDir, 'foo.js'),
sourcePath: path.join(rootDir, 'foo.js'),
});

assert.deepEqual(resolved, {isExcluded: true});
});
});

describe('node_modules', function() {
Expand Down