Comparing version 1.0.3 to 2.0.0
@@ -9,4 +9,10 @@ const findUp = require('find-up') | ||
) => { | ||
const [ pjsonFile, pjson ] = resolve(expand(target)) || [] | ||
const packageName = extractPackageName(request) | ||
if (!packageName) { | ||
return false | ||
} | ||
const [ pjsonFile, pjson ] = resolve(expand(target), packageName) || [] | ||
if (!pjsonFile) { | ||
@@ -19,8 +25,7 @@ return false | ||
// TODO: it's more nuanced than startsWith, we need at least a \b | ||
return request.startsWith(pjson.name) | ||
return true | ||
} | ||
// see https://nodejs.org/api/esm.html#esm_resolver_algorithm_specification | ||
const findNamedManifestOnDisk = (file) => { | ||
const findNamedManifestOnDisk = (file, name) => { | ||
const pjsonFile = findUp.sync('package.json', { cwd: path.dirname(file) }) | ||
@@ -34,3 +39,3 @@ | ||
if (pjson.name) { | ||
if (pjson.name && pjson.name === name) { | ||
return [pjsonFile, pjson] | ||
@@ -44,1 +49,16 @@ } | ||
const identity = x => x | ||
const extractPackageName = specifier => { | ||
if (specifier.startsWith('@')) { | ||
const scope = specifier.split('/').slice(0, 2).join('/') | ||
if (scope.endsWith('/')) { | ||
return null | ||
} | ||
return scope | ||
} | ||
else { | ||
return specifier.split('/')[0] | ||
} | ||
} |
{ | ||
"name": "esmac", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Control access to ES modules", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
14624
194