Skip to content

Commit 395cfa6

Browse files
fixup: update consumption of readPackage & read()
fixup: de-lint
1 parent eef2b60 commit 395cfa6

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

lib/internal/modules/cjs/loader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ ObjectDefineProperty(Module, '_readPackage', {
476476
* @param {string} originalPath The specifier passed to `require`
477477
*/
478478
function tryPackage(requestPath, exts, isMain, originalPath) {
479-
const { main: pkg, pjsonPath } = _readPackage(requestPath);
479+
const { data: { main: pkg }, path: pjsonPath } = _readPackage(requestPath);
480480

481481
if (!pkg) {
482482
return tryExtensions(path.resolve(requestPath, 'index'), exts, isMain);
@@ -632,16 +632,16 @@ function resolveExports(nmPath, request) {
632632
RegExpPrototypeExec(EXPORTS_PATTERN, request) || kEmptyObject;
633633
if (!name) { return; }
634634
const pkgPath = path.resolve(nmPath, name);
635-
const pkg = _readPackage(pkgPath);
636-
if (pkg.exists && pkg.exports != null) {
635+
const { data: pkg, path: pjsonPath } = _readPackage(pkgPath);
636+
if (pkg.type !== 'none' && pkg.exports != null) {
637637
try {
638638
const { packageExportsResolve } = require('internal/modules/esm/resolve');
639639
return finalizeEsmResolution(packageExportsResolve(
640-
pathToFileURL(pkgPath + '/package.json'), '.' + expansion, pkg, null,
640+
pathToFileURL(pjsonPath), '.' + expansion, pkg, null,
641641
getCjsConditions()), null, pkgPath);
642642
} catch (e) {
643643
if (e.code === 'ERR_MODULE_NOT_FOUND') {
644-
throw createEsmNotFoundErr(request, pkgPath + '/package.json');
644+
throw createEsmNotFoundErr(request, pjsonPath);
645645
}
646646
throw e;
647647
}

lib/internal/modules/esm/resolve.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,12 @@ function packageResolve(specifier, base, conditions) {
818818
}
819819

820820
// Package match.
821-
const packageConfig = packageJsonReader.read(packageJSONPath, { __proto__: null, specifier, base, isESM: true });
821+
const { data: packageConfig } = packageJsonReader.read(packageJSONPath, {
822+
__proto__: null,
823+
base,
824+
isESM: true,
825+
specifier,
826+
});
822827
if (packageConfig.exports != null) {
823828
return packageExportsResolve(
824829
packageJSONUrl, packageSubpath, packageConfig, base, conditions);

0 commit comments

Comments
 (0)