Skip to content

Commit 9323ee6

Browse files
authored
Merge pull request webpack#6398 from addaleax/no-binding
Avoid relying on Node’s internals
2 parents c7cbc35 + 8da8b93 commit 9323ee6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/EnvironmentPlugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
const DefinePlugin = require("./DefinePlugin");
99

10+
const needsEnvVarFix = ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
11+
process.platform === "win32";
12+
1013
class EnvironmentPlugin {
1114
constructor(keys) {
1215
if(Array.isArray(keys)) {
@@ -23,6 +26,13 @@ class EnvironmentPlugin {
2326

2427
apply(compiler) {
2528
const definitions = this.keys.reduce((defs, key) => {
29+
// TODO remove once the fix has made its way into Node 8.
30+
// Work around https://github.com/nodejs/node/pull/18463,
31+
// affecting Node 8 & 9 by performing an OS-level
32+
// operation that always succeeds before reading
33+
// environment variables:
34+
if(needsEnvVarFix) require("os").cpus();
35+
2636
const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key];
2737

2838
if(value === undefined) {

lib/node/NodeTargetPlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
const ExternalsPlugin = require("../ExternalsPlugin");
88

9+
const builtins = require("module").builtinModules || Object.keys(process.binding("natives"));
10+
911
class NodeTargetPlugin {
1012
apply(compiler) {
11-
new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
13+
new ExternalsPlugin("commonjs", builtins).apply(compiler);
1214
}
1315
}
1416

0 commit comments

Comments
 (0)