Skip to content

Commit 4f9cfc4

Browse files
fixup: register & consume findNearestPackageJSON as internal binding
1 parent d7c1cd5 commit 4f9cfc4

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/internal/modules/package_json_reader.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ function getNearestParentPackageJSON(checkPath, everything = false) {
138138
* @returns {URL['pathname']} The fully resolved location of the package.json file.
139139
*/
140140
function findNearestPackageJSON(origin) {
141-
// TODO(@JakobJingleheimer): Write a C++ function that returns only the location.
142-
const result = modulesBinding.getNearestParentPackageJSON(checkPath);
143-
return deserializePackageJSON(checkPath, result).pjsonPath;
141+
return modulesBinding.findNearestPackageJSON(origin);
144142
}
145143

146144
/**

src/node_modules.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data,
469469
SetMethod(isolate, target, "getPackageScopeConfig", GetPackageScopeConfig);
470470
SetMethod(isolate, target, "enableCompileCache", EnableCompileCache);
471471
SetMethod(isolate, target, "getCompileCacheDir", GetCompileCacheDir);
472+
SetMethod(isolate, target, "findNearestPackageJSON", FindNearestParentPackageJSON);
472473
}
473474

474475
void BindingData::CreatePerContextProperties(Local<Object> target,

typings/internalBinding/modules.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export interface ModulesBinding {
2626
getNearestParentPackageJSONType(path: string): PackageConfig['type']
2727
getPackageScopeConfig(path: string): SerializedPackageConfig | undefined
2828
getPackageJSONScripts(): string | undefined
29+
findNearestPackageJSON(origin: URL['pathname']): URL['pathname'] | undefined
2930
}

0 commit comments

Comments
 (0)