Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaël Nison <nison.mael@gmail.com>2022-09-18 13:50:52 +0300
committerJuan José Arboleda <soyjuanarbol@gmail.com>2022-10-11 22:45:26 +0300
commit1bb394e691aa66fdadb23c8261bd249728c29926 (patch)
treef60f7eda891ff8a0b755ae122208f1dc55b22ec5 /lib
parent1a8aada69d757b583e4db2b070caf83f59725589 (diff)
module: open stat/readPackage to mutations
PR-URL: https://github.com/nodejs/node/pull/44537 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/modules/cjs/loader.js44
1 files changed, 37 insertions, 7 deletions
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index dde5ccaad75..7a996e9ef11 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -79,7 +79,13 @@ const {
maybeCacheSourceMap,
} = require('internal/source_map/source_map_cache');
const { pathToFileURL, fileURLToPath, isURLInstance } = require('internal/url');
-const { deprecate, kEmptyObject, filterOwnProperties, setOwnProperty } = require('internal/util');
+const {
+ deprecate,
+ emitExperimentalWarning,
+ kEmptyObject,
+ filterOwnProperties,
+ setOwnProperty,
+} = require('internal/util');
const vm = require('vm');
const assert = require('internal/assert');
const fs = require('fs');
@@ -162,6 +168,18 @@ function stat(filename) {
return result;
}
+let _stat = stat;
+ObjectDefineProperty(Module, '_stat', {
+ __proto__: null,
+ get() { return _stat; },
+ set(stat) {
+ emitExperimentalWarning('Module._stat');
+ _stat = stat;
+ return true;
+ },
+ configurable: true,
+});
+
function updateChildren(parent, child, scan) {
const children = parent?.children;
if (children && !(scan && ArrayPrototypeIncludes(children, child)))
@@ -328,6 +346,18 @@ function readPackage(requestPath) {
}
}
+let _readPackage = readPackage;
+ObjectDefineProperty(Module, '_readPackage', {
+ __proto__: null,
+ get() { return _readPackage; },
+ set(readPackage) {
+ emitExperimentalWarning('Module._readPackage');
+ _readPackage = readPackage;
+ return true;
+ },
+ configurable: true,
+});
+
function readPackageScope(checkPath) {
const rootSeparatorIndex = StringPrototypeIndexOf(checkPath, sep);
let separatorIndex;
@@ -336,7 +366,7 @@ function readPackageScope(checkPath) {
checkPath = StringPrototypeSlice(checkPath, 0, separatorIndex);
if (StringPrototypeEndsWith(checkPath, sep + 'node_modules'))
return false;
- const pjson = readPackage(checkPath + sep);
+ const pjson = _readPackage(checkPath + sep);
if (pjson) return {
data: pjson,
path: checkPath,
@@ -346,7 +376,7 @@ function readPackageScope(checkPath) {
}
function tryPackage(requestPath, exts, isMain, originalPath) {
- const pkg = readPackage(requestPath)?.main;
+ const pkg = _readPackage(requestPath)?.main;
if (!pkg) {
return tryExtensions(path.resolve(requestPath, 'index'), exts, isMain);
@@ -392,7 +422,7 @@ const realpathCache = new SafeMap();
// keep symlinks intact, otherwise resolve to the
// absolute realpath.
function tryFile(requestPath, isMain) {
- const rc = stat(requestPath);
+ const rc = _stat(requestPath);
if (rc !== 0) return;
if (preserveSymlinks && !isMain) {
return path.resolve(requestPath);
@@ -486,7 +516,7 @@ function resolveExports(nmPath, request) {
if (!name)
return;
const pkgPath = path.resolve(nmPath, name);
- const pkg = readPackage(pkgPath);
+ const pkg = _readPackage(pkgPath);
if (pkg?.exports != null) {
try {
return finalizeEsmResolution(packageExportsResolve(
@@ -526,7 +556,7 @@ Module._findPath = function(request, paths, isMain) {
for (let i = 0; i < paths.length; i++) {
// Don't search further if path doesn't exist
const curPath = paths[i];
- if (curPath && stat(curPath) < 1) continue;
+ if (curPath && _stat(curPath) < 1) continue;
if (!absoluteRequest) {
const exportsResolved = resolveExports(curPath, request);
@@ -537,7 +567,7 @@ Module._findPath = function(request, paths, isMain) {
const basePath = path.resolve(curPath, request);
let filename;
- const rc = stat(basePath);
+ const rc = _stat(basePath);
if (!trailingSlash) {
if (rc === 0) { // File.
if (!isMain) {