extensionless
Advanced tools
Comparing version 1.9.6 to 1.9.7
{ | ||
"name": "extensionless", | ||
"version": "1.9.6", | ||
"version": "1.9.7", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -35,3 +35,3 @@ Node.js loader for import specifiers as file paths without extensions or as directory paths | ||
import mod from '../mod' assert {type: 'json'} | ||
import mod from '../mod' with {type: 'json'} | ||
// ['../mod.json', '../mod/index.json'] | ||
@@ -76,3 +76,3 @@ | ||
import mod from '../mod/' assert {type: 'json'} | ||
import mod from '../mod/' with {type: 'json'} | ||
// ['../mod/index.json'] | ||
@@ -95,3 +95,3 @@ | ||
import mod from '..\\mod\\' assert {type: 'json'} | ||
import mod from '..\\mod\\' with {type: 'json'} | ||
// ['../mod/index.json'] | ||
@@ -98,0 +98,0 @@ |
@@ -33,3 +33,3 @@ import {readFile} from 'fs/promises' | ||
return {lookFor, pkgJsonPath: pkgJson?.path, imports: pkgJson?.body.imports} | ||
return {lookFor, pkgJsonPath: pkgJson?.path} | ||
} |
@@ -11,8 +11,8 @@ import {extname} from 'path' | ||
let indexFiles, candidates, pkgJsonURL, aliases | ||
let indexFiles, candidates | ||
export async function initialize(data) { | ||
let {lookFor, pkgJsonPath, imports} = await getConfig(data) | ||
let {lookFor} = 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://' + 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).sort(([k1], [k2]) => k1.length < k2.length || k1[0].length > k2[0].length || k1[0].length === k2[0].length && k1[1]?.length > k2[1]?.length ? -1 : 1) | ||
indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']] | ||
candidates = indexFiles.map(i => i.map(f => extname(f)).concat(i.map(f => `/${f}`))) | ||
} | ||
@@ -25,11 +25,9 @@ | ||
export async function resolve(specifier, context, nextResolve) { | ||
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 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://' : '' | ||
let error, prefix = winAbsPath.test(specifier) ? 'file://' : '' | ||
if (!prefix && !relSpecs.includes(spec) && !specStarts.some(s => spec.startsWith(s))) { | ||
try {return await nextResolve(spec)} catch (e) {error = e} | ||
if (!prefix && !relSpecs.includes(specifier) && !specStarts.some(s => specifier.startsWith(s))) { | ||
try {return await nextResolve(specifier)} catch (e) {error = e} | ||
} | ||
let trySpec = error ? spec : new URL(prefix + spec, alias ? pkgJsonURL : context.parentURL).href | ||
let trySpec = error ? specifier : new URL(prefix + specifier, context.parentURL).href | ||
let {type} = context.importAttributes ?? context.importAssertions | ||
@@ -36,0 +34,0 @@ let postfixes = (await initPromise, trySpec.endsWith('/') ? indexFiles : knownExts.includes(extname(trySpec)) ? empty : candidates) |
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
6703
61