Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
refactor: allow embedder overriding of internal FS calls
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Apr 22, 2019
1 parent 696d8fb commit a86a4a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/internal/bootstrap/node.js
Expand Up @@ -64,6 +64,10 @@ if (ownsProcessState) {
);
}

// 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 = JSON.parse(internalBinding('native_module').config);

Expand Down
11 changes: 3 additions & 8 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -29,10 +29,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,
Expand Down Expand Up @@ -87,13 +84,11 @@ const isWindows = process.platform === 'win32';
let requireDepth = 0;
let statCache = new Map();
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) statCache = new Map();
let result = statCache.get(filename);
if (result !== undefined) return result;
result = internalModuleStat(filename);
result = internalFsBinding.internalModuleStat(filename);
statCache.set(filename, result);
return result;
}
Expand Down Expand Up @@ -206,7 +201,7 @@ function readPackage(requestPath) {
return entry;

const jsonPath = path.resolve(requestPath, 'package.json');
const json = internalModuleReadJSON(path.toNamespacedPath(jsonPath));
const json = internalFsBinding.internalModuleReadJSON(path.toNamespacedPath(jsonPath));

if (json === undefined) {
return false;
Expand Down

0 comments on commit a86a4a1

Please sign in to comment.