/
refactor_allow_embedder_overriding_of_internal_fs_calls.patch
64 lines (58 loc) · 2.54 KB
/
refactor_allow_embedder_overriding_of_internal_fs_calls.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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Mon, 22 Apr 2019 13:23:37 -0700
Subject: refactor: allow embedder overriding of internal FS calls
We use this to allow node's 'fs' module to read from ASAR files as if they were
a real filesystem.
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index c872941b974216d94863bcbf0e597b9c09ca50e2..4e7c3c10255a0eae4d5333f88e51cf7178163a44 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -57,6 +57,10 @@ setupBuffer();
process.domain = null;
process._exiting = false;
+// NOTE: Electron deletes this references before user code runs so that
+// internalBinding is not leaked to user code
+process.internalBinding = internalBinding;
+
// process.config is serialized config.gypi
process.config = JSONParse(internalBinding('native_module').config);
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 92554a374d189b3b284546b0e122940e9a175de8..e478c57af873da717c00db73d6719f806280efe1 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -55,10 +55,7 @@ const assert = require('internal/assert');
const fs = require('fs');
const internalFS = require('internal/fs/utils');
const path = require('path');
-const {
- internalModuleReadJSON,
- internalModuleStat
-} = internalBinding('fs');
+const internalFsBinding = internalBinding('fs');
const { safeGetenv } = internalBinding('credentials');
const {
makeRequireFunction,
@@ -144,14 +141,12 @@ function enrichCJSError(err) {
}
function stat(filename) {
- // FIXME(codebytere): determine why this needs to be done and remove
- const internalModuleStat = process.binding('fs').internalModuleStat;
filename = path.toNamespacedPath(filename);
if (statCache !== null) {
const result = statCache.get(filename);
if (result !== undefined) return result;
}
- const result = internalModuleStat(filename);
+ const result = internalFsBinding.internalModuleStat(filename);
if (statCache !== null) statCache.set(filename, result);
return result;
}
@@ -257,7 +252,7 @@ function readPackage(requestPath) {
const existing = packageJsonCache.get(jsonPath);
if (existing !== undefined) return existing;
- const json = internalModuleReadJSON(path.toNamespacedPath(jsonPath));
+ const json = internalFsBinding.internalModuleReadJSON(path.toNamespacedPath(jsonPath));
if (json === undefined) {
packageJsonCache.set(jsonPath, false);
return false;