extensionless
Advanced tools
Comparing version 1.1.3 to 1.1.4
{ | ||
"name": "extensionless", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"type": "module", | ||
@@ -10,4 +10,4 @@ "main": "src/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/barhun/extensionless.git" | ||
"type": "git", | ||
"url": "git+https://github.com/barhun/extensionless.git" | ||
}, | ||
@@ -14,0 +14,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
Node.js loader for import specifiers of file paths with no extensions and, optionally, of directory paths | ||
Node.js loader for import specifiers as file paths with no extensions or directory paths | ||
@@ -22,5 +22,5 @@ | ||
"extensionless": { | ||
"lookFor": ["js", "json"], // default: ["mjs", "js", "json"] | ||
"resolveDirs": true // default: false | ||
"lookFor": ["mjs", "js", "json"], // default: ["js", "json"] | ||
"resolveDirs": true // default: false | ||
} | ||
``` | ||
``` |
@@ -17,3 +17,3 @@ import {access, existsSync, readFileSync} from 'fs' | ||
let { | ||
lookFor = ['mjs', 'js', 'json'], | ||
lookFor = ['js', 'json'], | ||
resolveDirs = false | ||
@@ -30,10 +30,8 @@ } = pkgJson?.extensionless ?? {} | ||
let indexFiles = resolveDirs ? lookFor.map(e => `index.${e}`) : [] | ||
let postfixes = lookFor.map(e => `.${e}`).concat(indexFiles.map(p => `${sep}${p}`)) | ||
let extensions = lookFor.map(e => `.${e}`).concat(indexFiles.map(p => `${sep}${p}`)) | ||
let findPostfix = async (specifier, context, isAbs) => { | ||
let postfixCandidates = specifier.endsWith(sep) ? indexFiles | ||
: extToSkip.includes(extname(specifier)) ? [] : postfixes | ||
let postfixes = specifier.endsWith(sep) ? indexFiles : extToSkip.includes(extname(specifier)) ? [] : extensions | ||
for (let postfix of postfixCandidates) { | ||
let path = isAbs ? specifier + postfix | ||
: join(dirname(fileURLToPath(context.parentURL)), specifier + postfix) | ||
for (let postfix of postfixes) { | ||
let path = isAbs ? specifier + postfix : join(dirname(fileURLToPath(context.parentURL)), specifier + postfix) | ||
@@ -40,0 +38,0 @@ if (await new Promise(resolve => access(path, e => resolve(!e)))) { |
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
4102
40