extensionless
Advanced tools
Comparing version 1.8.0 to 1.8.1
{ | ||
"name": "extensionless", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -25,5 +25,5 @@ import {readFile} from 'fs/promises' | ||
lookFor: ['js'] | ||
}, { | ||
}, pkgJson = await getPkgJson(argv1), { | ||
lookFor | ||
} = {...defaults, ...(await getPkgJson(argv1))?.extensionless} | ||
} = {...defaults, ...pkgJson?.extensionless} | ||
@@ -34,3 +34,3 @@ Array.isArray(lookFor) && lookFor.length && lookFor.every(a => typeof a === 'string' && /^[a-z]\w*$/i.test(a)) || ( | ||
return {lookFor} | ||
return {lookFor, imports: pkgJson?.imports ?? {}} | ||
} |
@@ -11,33 +11,33 @@ import {extname} from 'path' | ||
let indexFiles, candidates | ||
let indexFiles, candidates, aliases | ||
export async function initialize(data) { | ||
let {lookFor} = await getConfig(data) | ||
let {lookFor, imports} = await getConfig(data) | ||
indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']] | ||
candidates = indexFiles.map(i => i.map(f => extname(f)).concat(i.map(f => `/${f}`))) | ||
aliases = Object.entries(imports).map(([k, v]) => [k.split('*'), (v.node ?? v.default ?? v).split('*')]) | ||
} | ||
let winAbsPath = /^[/\\]?[a-z]:[/\\]/i, relSpecs = ['.', '..'] | ||
let specStarts = ['./', '../', '/', '#', 'file://', 'https://', '.\\', '..\\', '\\'] | ||
let specStarts = ['./', '../', '/', 'file://', 'https://', '.\\', '..\\', '\\'] | ||
let knownExts = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'], empty = [[], []] | ||
export async function resolve(specifier, context, nextResolve) { | ||
let prefix = winAbsPath.test(specifier) ? 'file://' : '' | ||
let alias = specifier.startsWith('#') && aliases.find(a => a[0][1] !== undefined ? specifier.length > a[0][0].length + a[0][1].length && specifier.startsWith(a[0][0]) && specifier.endsWith(a[0][1]) : specifier === a[0][0]) | ||
let spec = alias ? alias[1][0] + (alias[1][1] !== undefined && alias[0][1] !== undefined ? specifier.substring(alias[0][0].length, specifier.length - alias[0][1].length) + alias[1][1] : '') : specifier | ||
let prefix = winAbsPath.test(spec) ? 'file://' : '' | ||
if (!prefix && !relSpecs.includes(specifier) && !specStarts.some(p => specifier.startsWith(p))) { | ||
return await nextResolve(specifier) | ||
if (!prefix && !relSpecs.includes(spec) && !specStarts.some(s => spec.startsWith(s))) { | ||
return await nextResolve(spec) | ||
} | ||
let trySpec = specifier[0] === '#' ? specifier : new URL(prefix + specifier, context.parentURL).href | ||
let selfURL = new URL(prefix + spec, context.parentURL).href | ||
let {type} = context.importAttributes ?? context.importAssertions | ||
let postfixes = (await initPromise, trySpec.endsWith('/') ? indexFiles : knownExts.includes(extname(trySpec)) ? empty : candidates) | ||
let postfixes = (await initPromise, selfURL.endsWith('/') ? indexFiles : knownExts.includes(extname(selfURL)) ? empty : candidates) | ||
for (let postfix of postfixes[+(type === 'json')]) { | ||
try { | ||
return await nextResolve(trySpec + postfix) | ||
} catch {} | ||
try {return await nextResolve(selfURL + postfix)} catch {} | ||
} | ||
return await nextResolve(trySpec) | ||
return await nextResolve(selfURL) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7116
63