Skip to content

Commit

Permalink
esm: add removePackageJsonFromPath
Browse files Browse the repository at this point in the history
  • Loading branch information
shackijj committed May 18, 2020
1 parent 3d0ac05 commit e5f3182
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/internal/modules/esm/resolve.js
Expand Up @@ -73,6 +73,14 @@ function tryStatSync(path) {
}
}

/**
*
* '/foo/package.json' -> '/foo'
*/
function removePackageJsonFromPath(path) {
return StringPrototypeSlice(path, 0, path.length - 13);
}

function getPackageConfig(path) {
const existing = packageJSONCache.get(path);
if (existing !== undefined) {
Expand All @@ -95,7 +103,7 @@ function getPackageConfig(path) {
try {
packageJSON = JSONParse(source);
} catch (error) {
const errorPath = StringPrototypeSlice(path, 0, path.length - 13);
const errorPath = removePackageJsonFromPath(path);
throw new ERR_INVALID_PACKAGE_CONFIG(errorPath, error.message, true);
}

Expand Down Expand Up @@ -550,8 +558,7 @@ function packageResolve(specifier, base, conditions) {
let packageJSONPath = fileURLToPath(packageJSONUrl);
let lastPath;
do {
const stat = tryStatSync(
StringPrototypeSlice(packageJSONPath, 0, packageJSONPath.length - 13));
const stat = tryStatSync(removePackageJsonFromPath(packageJSONPath));
if (!stat.isDirectory()) {
lastPath = packageJSONPath;
packageJSONUrl = new URL((isScoped ?
Expand Down

0 comments on commit e5f3182

Please sign in to comment.