From 80802f12455b24adcef2879de0027554b2ad251b Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Tue, 24 Sep 2024 14:02:28 -0600 Subject: [PATCH] module: change how children are detected Had to change how we read in the package.json path because of how Node.js now reads info using simdjson. --- lib/internal/modules/cjs/loader.js | 7 +++++-- lib/internal/modules/package_json_reader.js | 8 ++++++-- lib/internal/nsolid_module.js | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 8867a3ba22..b0e7c9b240 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -267,9 +267,12 @@ function updateChildren(parent, child, scan) { if (children && !(scan && ArrayPrototypeIncludes(children, child))) { ArrayPrototypePush(children, child); + if (typeof parent.path !== 'string' || typeof child.path !== 'string') { + return; + } try { - let parentPath = packageJsonReader.readPackageScope(parent.path); - let childPath = packageJsonReader.readPackageScope(child.path); + let parentPath = packageJsonReader.getNearestParentPackageJSON(parent.path); + let childPath = packageJsonReader.getNearestParentPackageJSON(child.path); parentPath = !parentPath ? parent.path : parentPath.path; childPath = !childPath ? child.path : childPath.path; if (parentPath && childPath && parentPath !== childPath) { diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js index 19f5d2e0f9..35119a55ee 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js @@ -90,9 +90,13 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { specifier == null ? undefined : `${specifier}`, ); - addPackage(jsonPath, null, true); - return deserializePackageJSON(jsonPath, parsed); + const result = deserializePackageJSON(jsonPath, parsed); + if (result.name) { + addPackage(jsonPath.slice(0, -12), null, true); + } + + return result; } /** diff --git a/lib/internal/nsolid_module.js b/lib/internal/nsolid_module.js index ac93e78e46..73b7cffd54 100644 --- a/lib/internal/nsolid_module.js +++ b/lib/internal/nsolid_module.js @@ -58,7 +58,7 @@ function addPackage(path, json, required = false) { try { const binding = internalBinding('fs'); const { fs: { O_RDONLY } } = internalBinding('constants'); - json = JSONParse(binding.readFileUtf8(path, O_RDONLY)); + json = JSONParse(binding.readFileUtf8(path + '/package.json', O_RDONLY)); } catch { return; }