extensionless
Advanced tools
Comparing version 1.3.3 to 1.3.4
{ | ||
"name": "extensionless", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -23,13 +23,12 @@ import {access, existsSync, readFileSync} from 'fs' | ||
let indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']], empty = [[], []] | ||
let indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']] | ||
let candidates = indexFiles.map(i => i.map(f => extname(f)).concat(i.map(f => `/${f}`))) | ||
let relSpecs = ['.', '..'], relPres = ['./', '../', '.\\', '..\\'] | ||
let extToSkip = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'] | ||
let relSpecs = ['.', '..'], prefixes = ['./', '../', 'file://', '.\\', '..\\'] | ||
let extToSkip = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'], empty = [[], []] | ||
export async function resolve(specifier, {importAssertions, parentURL}, nextResolve) { | ||
let isAbs = isAbsolute(specifier) | ||
let isRel = relSpecs.includes(specifier) || relPres.some(p => specifier.startsWith(p)) | ||
if (!specifier.startsWith('file://') && !isAbs && !isRel) { | ||
if (!isAbs && !relSpecs.includes(specifier) && !prefixes.some(p => specifier.startsWith(p))) { | ||
return await nextResolve(specifier) | ||
@@ -39,8 +38,9 @@ } | ||
let selfURL = new URL((isAbs ? 'file://' : '') + specifier, parentURL).href | ||
let postfixes = selfURL.endsWith('/') ? indexFiles | ||
: extToSkip.includes(extname(selfURL)) ? empty : candidates | ||
let postfixes = selfURL.endsWith('/') ? indexFiles : extToSkip.includes(extname(selfURL)) ? empty : candidates | ||
for (let postfix of postfixes[+(importAssertions?.type === 'json')]) { | ||
if (await new Promise(r => access(new URL(selfURL + postfix), e => r(!e)))) { | ||
return await nextResolve(selfURL + postfix) | ||
let testURL = selfURL + postfix | ||
if (await new Promise(r => access(new URL(testURL), e => r(!e)))) { | ||
return await nextResolve(testURL) | ||
} | ||
@@ -47,0 +47,0 @@ } |
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
5497
36