This repository was archived by the owner on May 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnode.patch
131 lines (118 loc) · 4.39 KB
/
node.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js
index 0e9c36c4fc..66367e51ce 100644
--- a/lib/internal/bootstrap_node.js
+++ b/lib/internal/bootstrap_node.js
@@ -118,13 +118,16 @@
'ExperimentalWarning', undefined);
}
+ if (NativeModule.exists('_third_party_main')) {
+ NativeModule.require('_third_party_main');
+ }
// There are various modes that Node can run in. The most common two
// are running from a script and running the REPL - but there are a few
// others like the debugger or running --eval arguments. Here we decide
// which mode we run in.
- if (NativeModule.exists('_third_party_main')) {
+ if (NativeModule.exists('_third_party_main_invalid')) {
// To allow people to extend Node in different ways, this hook allows
// one to drop a file lib/_third_party_main.js into the build
// directory which will be executed instead of Node's normal loading.
diff --git a/lib/module.js b/lib/module.js
index 642e5cb1f1..3d298fbf01 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -36,6 +36,9 @@ const {
} = process.binding('fs');
const preserveSymlinks = !!process.binding('config').preserveSymlinks;
const experimentalModules = !!process.binding('config').experimentalModules;
+const nbin = require('nbin');
+const os = require('os');
+const zlib = require('zlib');
const errors = require('internal/errors');
@@ -54,7 +57,8 @@ function stat(filename) {
const result = cache.get(filename);
if (result !== undefined) return result;
}
- const result = internalModuleStat(filename);
+ const s = nbin.statSync(filename);
+ const result = s.isDirectory ? 1 : s.isFile ? 0 : internalModuleStat(filename);
if (cache !== null) cache.set(filename, result);
return result;
}
@@ -115,8 +119,13 @@ function readPackage(requestPath) {
if (entry)
return entry;
+ let json;
const jsonPath = path.resolve(requestPath, 'package.json');
- const json = internalModuleReadFile(path._makeLong(jsonPath));
+ if (nbin.existsSync(jsonPath)) {
+ json = nbin.readFileSync(jsonPath, 'utf8');
+ } else {
+ json = internalModuleReadFile(path._makeLong(jsonPath));
+ }
if (json === undefined) {
return false;
@@ -161,6 +170,9 @@ function tryFile(requestPath, isMain) {
}
function toRealPath(requestPath) {
+ if (nbin.existsSync(requestPath)) {
+ return requestPath;
+ }
return fs.realpathSync(requestPath, {
[internalFS.realpathCacheKey]: realpathCache
});
@@ -660,14 +672,29 @@ Module.prototype._compile = function(content, filename) {
// Native extension for .js
Module._extensions['.js'] = function(module, filename) {
- var content = fs.readFileSync(filename, 'utf8');
+ let content;
+ if (nbin.existsSync(filename)) {
+ content = nbin.readFileSync(filename, 'utf8');
+ } else {
+ content = fs.readFileSync(filename, 'utf8');
+ }
module._compile(internalModule.stripBOM(content), filename);
};
+// Native extension for .gz
+Module._extensions['.gz'] = function(module, filename) {
+ const content = zlib.gunzipSync(nbin.readFileSync(filename)).toString("utf8");
+ module._compile(internalModule.stripBOM(content), filename);
+};
// Native extension for .json
Module._extensions['.json'] = function(module, filename) {
- var content = fs.readFileSync(filename, 'utf8');
+ let content;
+ if (nbin.existsSync(filename)) {
+ content = nbin.readFileSync(filename, 'utf8');
+ } else {
+ content = fs.readFileSync(filename, 'utf8');
+ }
try {
module.exports = JSON.parse(internalModule.stripBOM(content));
} catch (err) {
@@ -679,6 +706,11 @@ Module._extensions['.json'] = function(module, filename) {
//Native extension for .node
Module._extensions['.node'] = function(module, filename) {
+ if (nbin.existsSync(filename)) {
+ const tmpFile = path.join(os.tmpdir(), `.nbin-${path.basename(filename)}`);
+ fs.writeFileSync(tmpFile, nbin.readFileSync(filename));
+ filename = tmpFile;
+ }
return process.dlopen(module, path._makeLong(filename));
};
diff --git a/src/node.cc b/src/node.cc
index 3d791f04ad..d6ae74884c 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -3813,6 +3813,11 @@ void ProcessArgv(int* argc,
int* exec_argc,
const char*** exec_argv,
bool is_env = false) {
+ if (!getenv("NBIN_BYPASS") && !is_env) {
+ *exec_argc = 0;
+
+ return;
+ }
// Parse a few arguments which are specific to Node.
int v8_argc;
const char** v8_argv;