Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Support newer node versions which changed internalModuleReadJSON #1059

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions prelude/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var removeUplevels = common.removeUplevels;

var FLAG_ENABLE_PROJECT = false;
var NODE_VERSION_MAJOR = process.version.match(/^v(\d+)/)[1] | 0;
var NODE_VERSION_MINOR = process.version.match(/^v\d+.(\d+)/)[1] | 0;

// /////////////////////////////////////////////////////////////////
// ENTRYPOINT //////////////////////////////////////////////////////
Expand Down Expand Up @@ -1195,6 +1196,12 @@ function payloadFileSync (pointer) {
// Used to speed up module loading. Returns the contents of the file as
// a string or undefined when the file cannot be opened. The speedup
// comes from not creating Error objects on failure.
// For newer node versions (after https://github.com/nodejs/node/pull/33229 ):
// Returns an array [string, boolean].
//
var returnArray = (NODE_VERSION_MAJOR === 12 && NODE_VERSION_MINOR >= 19) ||
(NODE_VERSION_MAJOR === 14 && NODE_VERSION_MINOR >= 5) ||
(NODE_VERSION_MAJOR >= 15);

var path = revertMakingLong(long);
var bindingFs = process.binding('fs');
Expand All @@ -1210,10 +1217,10 @@ function payloadFileSync (pointer) {
path = normalizePath(path);
// console.log("internalModuleReadFile", path);
var entity = VIRTUAL_FILESYSTEM[path];
if (!entity) return undefined;
if (!entity) return returnArray ? [ undefined, false ] : undefined;
var entityContent = entity[STORE_CONTENT];
if (!entityContent) return undefined;
return payloadFileSync(entityContent).toString();
if (!entityContent) return returnArray ? [ undefined, false ] : undefined;
return returnArray ? [ payloadFileSync(entityContent).toString(), true ] : payloadFileSync(entityContent).toString();
};
}());

Expand Down