extensionless
Advanced tools
Comparing version 1.3.2 to 1.3.3
{ | ||
"name": "extensionless", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
import {access, existsSync, readFileSync} from 'fs' | ||
import {dirname, extname, isAbsolute, join, posix, win32} from 'path' | ||
import {dirname, extname, isAbsolute, join} from 'path' | ||
import {argv, cwd} from 'process' | ||
@@ -23,29 +23,27 @@ | ||
let indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']] | ||
let relatives = indexFiles.map(i => i.map(f => `/${f}`)) | ||
let candidates = relatives.map(r => r.map(p => extname(p)).concat(r)) | ||
let indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']], empty = [[], []] | ||
let candidates = indexFiles.map(i => i.map(f => extname(f)).concat(i.map(f => `/${f}`))) | ||
let relSpecs = ['.', '..'], separators = [posix.sep, win32.sep] | ||
let relPrefixes = separators.flatMap(s => relSpecs.map(r => r + s)) | ||
let extToSkip = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'], empty = [[''], ['']] | ||
let relSpecs = ['.', '..'], relPres = ['./', '../', '.\\', '..\\'] | ||
let extToSkip = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'] | ||
export async function resolve(specifier, {importAssertions, parentURL}, nextResolve) { | ||
let isAbs = isAbsolute(specifier), isRelSpec = relSpecs.includes(specifier) | ||
let isRelative = isRelSpec || relPrefixes.some(p => specifier.startsWith(p)) | ||
let isAbs = isAbsolute(specifier) | ||
let isRel = relSpecs.includes(specifier) || relPres.some(p => specifier.startsWith(p)) | ||
if (specifier.startsWith('file://') || isAbs || isRelative) { | ||
let postfixes = isRelSpec ? relatives | ||
: separators.some(s => specifier.endsWith(s)) ? indexFiles | ||
: extToSkip.includes(extname(specifier)) ? empty : candidates | ||
if (!specifier.startsWith('file://') && !isAbs && !isRel) { | ||
return await nextResolve(specifier) | ||
} | ||
for (let postfix of postfixes[+(importAssertions?.type === 'json')]) { | ||
let fileURL = new URL((isAbs ? 'file://' : '') + specifier + postfix, parentURL) | ||
let selfURL = new URL((isAbs ? 'file://' : '') + specifier, parentURL).href | ||
let postfixes = selfURL.endsWith('/') ? indexFiles | ||
: extToSkip.includes(extname(selfURL)) ? empty : candidates | ||
if (!postfix || await new Promise(r => access(fileURL, e => r(!e)))) { | ||
return await nextResolve(fileURL.href) | ||
} | ||
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) | ||
} | ||
} | ||
return await nextResolve(specifier) | ||
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
5526
37