Skip to content

Commit

Permalink
fixup: update consumption of readPackage & read()
Browse files Browse the repository at this point in the history
fixup: de-lint
  • Loading branch information
JakobJingleheimer committed Oct 8, 2024
1 parent eef2b60 commit 395cfa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ ObjectDefineProperty(Module, '_readPackage', {
* @param {string} originalPath The specifier passed to `require`
*/
function tryPackage(requestPath, exts, isMain, originalPath) {
const { main: pkg, pjsonPath } = _readPackage(requestPath);
const { data: { main: pkg }, path: pjsonPath } = _readPackage(requestPath);

if (!pkg) {
return tryExtensions(path.resolve(requestPath, 'index'), exts, isMain);
Expand Down Expand Up @@ -632,16 +632,16 @@ function resolveExports(nmPath, request) {
RegExpPrototypeExec(EXPORTS_PATTERN, request) || kEmptyObject;
if (!name) { return; }
const pkgPath = path.resolve(nmPath, name);
const pkg = _readPackage(pkgPath);
if (pkg.exists && pkg.exports != null) {
const { data: pkg, path: pjsonPath } = _readPackage(pkgPath);
if (pkg.type !== 'none' && pkg.exports != null) {
try {
const { packageExportsResolve } = require('internal/modules/esm/resolve');
return finalizeEsmResolution(packageExportsResolve(
pathToFileURL(pkgPath + '/package.json'), '.' + expansion, pkg, null,
pathToFileURL(pjsonPath), '.' + expansion, pkg, null,
getCjsConditions()), null, pkgPath);
} catch (e) {
if (e.code === 'ERR_MODULE_NOT_FOUND') {
throw createEsmNotFoundErr(request, pkgPath + '/package.json');
throw createEsmNotFoundErr(request, pjsonPath);
}
throw e;
}
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,12 @@ function packageResolve(specifier, base, conditions) {
}

// Package match.
const packageConfig = packageJsonReader.read(packageJSONPath, { __proto__: null, specifier, base, isESM: true });
const { data: packageConfig } = packageJsonReader.read(packageJSONPath, {
__proto__: null,
base,
isESM: true,
specifier,
});
if (packageConfig.exports != null) {
return packageExportsResolve(
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
Expand Down

0 comments on commit 395cfa6

Please sign in to comment.