|
1 |
| -diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js |
2 |
| -index 0e9c36c4fc..66367e51ce 100644 |
3 |
| ---- a/lib/internal/bootstrap_node.js |
4 |
| -+++ b/lib/internal/bootstrap_node.js |
5 |
| -@@ -118,13 +118,16 @@ |
6 |
| - 'ExperimentalWarning', undefined); |
7 |
| - } |
8 |
| - |
9 |
| -+ if (NativeModule.exists('_third_party_main')) { |
10 |
| -+ NativeModule.require('_third_party_main'); |
11 |
| -+ } |
12 |
| - |
13 |
| - // There are various modes that Node can run in. The most common two |
| 1 | +diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js |
| 2 | +index 885546c5d6..f1287bb191 100644 |
| 3 | +--- a/lib/internal/bootstrap/node.js |
| 4 | ++++ b/lib/internal/bootstrap/node.js |
| 5 | +@@ -215,11 +215,16 @@ |
14 | 6 | // are running from a script and running the REPL - but there are a few
|
15 | 7 | // others like the debugger or running --eval arguments. Here we decide
|
16 |
| - // which mode we run in. |
17 |
| - |
18 |
| -- if (NativeModule.exists('_third_party_main')) { |
19 |
| -+ if (NativeModule.exists('_third_party_main_invalid')) { |
| 8 | + // which mode we run in. |
| 9 | ++ |
| 10 | ++ if (NativeModule.exists('_third_party_main')) { |
| 11 | ++ NativeModule.require('_third_party_main'); |
| 12 | ++ } |
| 13 | ++ |
| 14 | + if (internalBinding('worker').getEnvMessagePort() !== undefined) { |
| 15 | + // This means we are in a Worker context, and any script execution |
| 16 | + // will be directed by the worker module. |
| 17 | + NativeModule.require('internal/worker').setupChild(evalScript); |
| 18 | +- } else if (NativeModule.exists('_third_party_main')) { |
| 19 | ++ } else if (NativeModule.exists('_third_party_main_invalid')) { |
20 | 20 | // To allow people to extend Node in different ways, this hook allows
|
21 | 21 | // one to drop a file lib/_third_party_main.js into the build
|
22 | 22 | // directory which will be executed instead of Node's normal loading.
|
23 |
| -diff --git a/lib/module.js b/lib/module.js |
24 |
| -index 642e5cb1f1..3d298fbf01 100644 |
25 |
| ---- a/lib/module.js |
26 |
| -+++ b/lib/module.js |
27 |
| -@@ -36,6 +36,9 @@ const { |
28 |
| - } = process.binding('fs'); |
29 |
| - const preserveSymlinks = !!process.binding('config').preserveSymlinks; |
30 |
| - const experimentalModules = !!process.binding('config').experimentalModules; |
| 23 | +diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js |
| 24 | +index fb3770b729..eb65385afe 100644 |
| 25 | +--- a/lib/internal/modules/cjs/loader.js |
| 26 | ++++ b/lib/internal/modules/cjs/loader.js |
| 27 | +@@ -44,6 +44,9 @@ const { getOptionValue } = require('internal/options'); |
| 28 | + const preserveSymlinks = getOptionValue('--preserve-symlinks'); |
| 29 | + const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); |
| 30 | + const experimentalModules = getOptionValue('--experimental-modules'); |
31 | 31 | +const nbin = require('nbin');
|
32 | 32 | +const os = require('os');
|
33 | 33 | +const zlib = require('zlib');
|
34 | 34 |
|
35 |
| - const errors = require('internal/errors'); |
36 |
| - |
37 |
| -@@ -54,7 +57,8 @@ function stat(filename) { |
| 35 | + const { |
| 36 | + ERR_INVALID_ARG_TYPE, |
| 37 | +@@ -87,7 +90,8 @@ function stat(filename) { |
38 | 38 | const result = cache.get(filename);
|
39 | 39 | if (result !== undefined) return result;
|
40 | 40 | }
|
41 | 41 | - const result = internalModuleStat(filename);
|
42 |
| -+ const s = nbin.statSync(filename); |
43 |
| -+ const result = s.isDirectory ? 1 : s.isFile ? 0 : internalModuleStat(filename); |
| 42 | ++ const s = nbin.statSync(filename); |
| 43 | ++ const result = s.isDirectory ? 1 : s.isFile ? 0 : internalModuleStat(filename); |
44 | 44 | if (cache !== null) cache.set(filename, result);
|
45 | 45 | return result;
|
46 | 46 | }
|
47 |
| -@@ -115,8 +119,13 @@ function readPackage(requestPath) { |
| 47 | +@@ -154,8 +158,13 @@ function readPackage(requestPath) { |
48 | 48 | if (entry)
|
49 | 49 | return entry;
|
50 | 50 |
|
51 |
| -+ let json; |
| 51 | ++ let json; |
52 | 52 | const jsonPath = path.resolve(requestPath, 'package.json');
|
53 |
| -- const json = internalModuleReadFile(path._makeLong(jsonPath)); |
54 |
| -+ if (nbin.existsSync(jsonPath)) { |
55 |
| -+ json = nbin.readFileSync(jsonPath, 'utf8'); |
56 |
| -+ } else { |
57 |
| -+ json = internalModuleReadFile(path._makeLong(jsonPath)); |
58 |
| -+ } |
| 53 | +- const json = internalModuleReadJSON(path.toNamespacedPath(jsonPath)); |
| 54 | ++ if (nbin.existsSync(jsonPath)) { |
| 55 | ++ json = nbin.readFileSync(jsonPath, 'utf8'); |
| 56 | ++ } else { |
| 57 | ++ json = internalModuleReadJSON(path.toNamespacedPath(jsonPath)); |
| 58 | ++ } |
59 | 59 |
|
60 | 60 | if (json === undefined) {
|
61 | 61 | return false;
|
62 |
| -@@ -161,6 +170,9 @@ function tryFile(requestPath, isMain) { |
| 62 | +@@ -199,6 +208,9 @@ function tryFile(requestPath, isMain) { |
63 | 63 | }
|
64 | 64 |
|
65 | 65 | function toRealPath(requestPath) {
|
66 |
| -+ if (nbin.existsSync(requestPath)) { |
67 |
| -+ return requestPath; |
68 |
| -+ } |
| 66 | ++ if (nbin.existsSync(requestPath)) { |
| 67 | ++ return requestPath; |
| 68 | ++ } |
69 | 69 | return fs.realpathSync(requestPath, {
|
70 | 70 | [internalFS.realpathCacheKey]: realpathCache
|
71 | 71 | });
|
72 |
| -@@ -660,14 +672,29 @@ Module.prototype._compile = function(content, filename) { |
| 72 | +@@ -696,14 +708,29 @@ Module.prototype._compile = function(content, filename) { |
73 | 73 |
|
74 | 74 | // Native extension for .js
|
75 | 75 | Module._extensions['.js'] = function(module, filename) {
|
76 | 76 | - var content = fs.readFileSync(filename, 'utf8');
|
77 |
| -+ let content; |
78 |
| -+ if (nbin.existsSync(filename)) { |
79 |
| -+ content = nbin.readFileSync(filename, 'utf8'); |
80 |
| -+ } else { |
81 |
| -+ content = fs.readFileSync(filename, 'utf8'); |
82 |
| -+ } |
83 |
| - module._compile(internalModule.stripBOM(content), filename); |
| 77 | ++ let content; |
| 78 | ++ if (nbin.existsSync(filename)) { |
| 79 | ++ content = nbin.readFileSync(filename, 'utf8'); |
| 80 | ++ } else { |
| 81 | ++ content = fs.readFileSync(filename, 'utf8'); |
| 82 | ++ } |
| 83 | + module._compile(stripBOM(content), filename); |
84 | 84 | };
|
85 | 85 |
|
86 | 86 | +// Native extension for .gz
|
87 | 87 | +Module._extensions['.gz'] = function(module, filename) {
|
88 |
| -+ const content = zlib.gunzipSync(nbin.readFileSync(filename)).toString("utf8"); |
89 |
| -+ module._compile(internalModule.stripBOM(content), filename); |
| 88 | ++ const content = zlib.gunzipSync(nbin.readFileSync(filename)).toString("utf8"); |
| 89 | ++ module._compile(stripBOM(content), filename); |
90 | 90 | +};
|
91 | 91 |
|
92 | 92 | // Native extension for .json
|
93 | 93 | Module._extensions['.json'] = function(module, filename) {
|
94 | 94 | - var content = fs.readFileSync(filename, 'utf8');
|
95 |
| -+ let content; |
96 |
| -+ if (nbin.existsSync(filename)) { |
97 |
| -+ content = nbin.readFileSync(filename, 'utf8'); |
98 |
| -+ } else { |
99 |
| -+ content = fs.readFileSync(filename, 'utf8'); |
100 |
| -+ } |
| 95 | ++ let content; |
| 96 | ++ if (nbin.existsSync(filename)) { |
| 97 | ++ content = nbin.readFileSync(filename, 'utf8'); |
| 98 | ++ } else { |
| 99 | ++ content = fs.readFileSync(filename, 'utf8'); |
| 100 | ++ } |
101 | 101 | try {
|
102 |
| - module.exports = JSON.parse(internalModule.stripBOM(content)); |
| 102 | + module.exports = JSON.parse(stripBOM(content)); |
103 | 103 | } catch (err) {
|
104 |
| -@@ -679,6 +706,11 @@ Module._extensions['.json'] = function(module, filename) { |
| 104 | +@@ -715,7 +742,14 @@ Module._extensions['.json'] = function(module, filename) { |
105 | 105 |
|
106 |
| - //Native extension for .node |
| 106 | + // Native extension for .node |
107 | 107 | Module._extensions['.node'] = function(module, filename) {
|
108 |
| -+ if (nbin.existsSync(filename)) { |
109 |
| -+ const tmpFile = path.join(os.tmpdir(), `.nbin-${path.basename(filename)}`); |
110 |
| -+ fs.writeFileSync(tmpFile, nbin.readFileSync(filename)); |
111 |
| -+ filename = tmpFile; |
112 |
| -+ } |
113 |
| - return process.dlopen(module, path._makeLong(filename)); |
| 108 | +- return process.dlopen(module, path.toNamespacedPath(filename)); |
| 109 | ++ let isInternal = false; |
| 110 | ++ if (nbin.existsSync(filename)) { |
| 111 | ++ const tmpFile = path.join(os.tmpdir(), `.nbin-${path.basename(filename)}`); |
| 112 | ++ fs.writeFileSync(tmpFile, nbin.readFileSync(filename)); |
| 113 | ++ filename = tmpFile; |
| 114 | ++ isInternal = true; |
| 115 | ++ } |
| 116 | ++ return process.dlopen(module, isInternal ? filename : path.toNamespacedPath(filename)); |
114 | 117 | };
|
115 | 118 |
|
| 119 | + if (experimentalModules) { |
116 | 120 | diff --git a/src/node.cc b/src/node.cc
|
117 |
| -index 3d791f04ad..d6ae74884c 100644 |
| 121 | +index 9fb5ab3b8e..d2c9ab3bc3 100644 |
118 | 122 | --- a/src/node.cc
|
119 | 123 | +++ b/src/node.cc
|
120 |
| -@@ -3813,6 +3813,11 @@ void ProcessArgv(int* argc, |
121 |
| - int* exec_argc, |
122 |
| - const char*** exec_argv, |
123 |
| - bool is_env = false) { |
| 124 | +@@ -2439,6 +2439,12 @@ void ProcessArgv(std::vector<std::string>* args, |
| 125 | + std::vector<std::string> v8_args; |
| 126 | + std::vector<std::string> errors{}; |
| 127 | + |
124 | 128 | + if (!getenv("NBIN_BYPASS") && !is_env) {
|
125 |
| -+ *exec_argc = 0; |
| 129 | ++ // *exec_argc = 0; |
126 | 130 | +
|
127 |
| -+ return; |
| 131 | ++ return; |
128 | 132 | + }
|
129 |
| - // Parse a few arguments which are specific to Node. |
130 |
| - int v8_argc; |
131 |
| - const char** v8_argv; |
| 133 | ++ |
| 134 | + { |
| 135 | + // TODO(addaleax): The mutex here should ideally be held during the |
| 136 | + // entire function, but that doesn't play well with the exit() calls below. |
0 commit comments