extensionless
Advanced tools
Comparing version 1.9.2 to 1.9.3
{ | ||
"name": "extensionless", | ||
"version": "1.9.2", | ||
"version": "1.9.3", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -8,3 +8,3 @@ import {readFile} from 'fs/promises' | ||
let getPkgConfig = async argv1 => { | ||
let getPkgJson = async argv1 => { | ||
let path, dirPath = isAbsolute(argv1 ?? '') ? argv1 : cwd() | ||
@@ -14,3 +14,3 @@ | ||
try { | ||
return {json: JSON.parse(await readFile(path = join(dirPath, 'package.json'), 'utf8')), path} | ||
return {body: JSON.parse(await readFile(path = join(dirPath, 'package.json'), 'utf8')), path} | ||
} catch (e) { | ||
@@ -27,5 +27,5 @@ if (!['ENOTDIR', 'ENOENT', 'EISDIR'].includes(e.code)) { | ||
lookFor: ['js'] | ||
}, pkgConfig = await getPkgConfig(argv1), { | ||
}, pkgJson = await getPkgJson(argv1), { | ||
lookFor | ||
} = {...defaults, ...pkgConfig?.json.extensionless} | ||
} = {...defaults, ...pkgJson?.body.extensionless} | ||
@@ -36,3 +36,3 @@ Array.isArray(lookFor) && lookFor.length && lookFor.every(a => typeof a === 'string' && /^[a-z]\w*$/i.test(a)) || ( | ||
return {lookFor, jsonPath: pkgConfig?.path, imports: pkgConfig?.json.imports} | ||
return {lookFor, pkgJsonPath: pkgJson?.path, imports: pkgJson?.body.imports} | ||
} |
@@ -13,6 +13,6 @@ import {extname} from 'path' | ||
export async function initialize(data) { | ||
let {lookFor, jsonPath, imports} = await getConfig(data) | ||
let {lookFor, pkgJsonPath, 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}`))) | ||
pkgJsonURL = 'file://' + jsonPath, aliases = Object.entries(imports ?? {}).map(([k, v]) => [k.split('*'), (v.node ?? v.default ?? v).split('*')]).filter(([k, v]) => k.length < 3 && k.length === v.length) | ||
pkgJsonURL = 'file://' + pkgJsonPath, aliases = Object.entries(imports ?? {}).map(([k, v]) => [k.split('*'), (v.node ?? v.default ?? v).split('*')]).filter(([k, v]) => k.length < 3 && k.length === v.length) | ||
} | ||
@@ -26,10 +26,10 @@ | ||
let alias = specifier.startsWith('#') && (await initPromise, aliases.find(([k]) => k[1] !== undefined ? specifier.length > k[0].length + k[1].length && specifier.startsWith(k[0]) && specifier.endsWith(k[1]) : specifier === k[0])) | ||
let orgSpec = alias ? alias[1][0] + (alias[0][1] !== undefined ? specifier.substring(alias[0][0].length, specifier.length - alias[0][1].length) + alias[1][1] : '') : specifier | ||
let error, prefix = winAbsPath.test(orgSpec) ? 'file://' : '' | ||
let spec = alias ? alias[1][0] + (alias[0][1] !== undefined ? specifier.substring(alias[0][0].length, specifier.length - alias[0][1].length) + alias[1][1] : '') : specifier | ||
let error, prefix = winAbsPath.test(spec) ? 'file://' : '' | ||
if (!prefix && !relSpecs.includes(orgSpec) && !specStarts.some(s => orgSpec.startsWith(s))) { | ||
try {return await nextResolve(orgSpec)} catch (e) {error = e} | ||
if (!prefix && !relSpecs.includes(spec) && !specStarts.some(s => spec.startsWith(s))) { | ||
try {return await nextResolve(spec)} catch (e) {error = e} | ||
} | ||
let trySpec = error ? orgSpec : new URL(prefix + orgSpec, alias ? pkgJsonURL : context.parentURL).href | ||
let trySpec = error ? spec : new URL(prefix + spec, alias ? pkgJsonURL : context.parentURL).href | ||
let {type} = context.importAttributes ?? context.importAssertions | ||
@@ -36,0 +36,0 @@ let postfixes = (await initPromise, trySpec.endsWith('/') ? indexFiles : knownExts.includes(extname(trySpec)) ? empty : candidates) |
7390