Skip to content

Commit

Permalink
module: change how children are detected
Browse files Browse the repository at this point in the history
Had to change how we read in the package.json path because of how
Node.js now reads info using simdjson.
  • Loading branch information
trevnorris committed Sep 24, 2024
1 parent 4799f61 commit 80802f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions lib/internal/modules/package_json_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/nsolid_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 80802f1

Please sign in to comment.