Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
barhun committed May 26, 2024
1 parent e87257e commit b0719c4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "extensionless",
"version": "1.9.7",
"version": "1.9.9",
"type": "module",
"exports": {
".": "./src/index.js",
Expand Down
16 changes: 8 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {cwd} from 'process'
let warn = (field, desc) => console.warn('⚠️ \x1b[33m%s\x1b[0m',
`Warning: The package.json field 'extensionless.${field}' must be ${desc}! Using the default value instead...`)

let getPkgJson = async argv1 => {
let path, dirPath = isAbsolute(argv1 ?? '') ? argv1 : cwd()

let getPkgJson = async dirPath => {
do {
let path = join(dirPath, 'package.json')

try {
return {body: JSON.parse(await readFile(path = join(dirPath, 'package.json'), 'utf8')), path}
return {body: JSON.parse(await readFile(path, 'utf8')), path}
} catch (e) {
if (!['ENOTDIR', 'ENOENT', 'EISDIR'].includes(e.code)) {
throw new Error('Cannot retrieve package.json', {cause: e})
Expand All @@ -19,16 +19,16 @@ let getPkgJson = async argv1 => {
} while (dirPath !== (dirPath = dirname(dirPath)))
}

export async function getConfig({argv1} = {}) {
export async function getConfig({argv1 = ''} = {}) {
let defaults = {
lookFor: ['js']
}, pkgJson = await getPkgJson(argv1), {
}, dirPath = isAbsolute(argv1) ? argv1 : cwd(), {
lookFor
} = {...defaults, ...pkgJson?.body.extensionless}
} = {...defaults, ...(await getPkgJson(dirPath))?.body.extensionless}

Array.isArray(lookFor) && lookFor.length && lookFor.every(a => typeof a === 'string' && /^[a-z]\w*$/i.test(a)) || (
lookFor = defaults.lookFor, warn('lookFor', 'an array of alphanumeric strings')
)

return {lookFor, pkgJsonPath: pkgJson?.path}
return {lookFor}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export async function resolve(specifier, context, nextResolve) {
try {return await nextResolve(specifier)} catch (e) {error = e}
}

let trySpec = error ? specifier : new URL(prefix + specifier, context.parentURL).href
let {type} = context.importAttributes ?? context.importAssertions
let trySpec = error ? specifier : new URL(prefix + specifier, context.parentURL).href
let postfixes = (await initPromise, trySpec.endsWith('/') ? indexFiles : knownExts.includes(extname(trySpec)) ? empty : candidates)

for (let postfix of postfixes[+(type === 'json')]) {
Expand Down

0 comments on commit b0719c4

Please sign in to comment.