Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extensionless

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extensionless - npm Package Compare versions

Comparing version 1.1.9 to 1.2.0

2

package.json
{
"name": "extensionless",
"version": "1.1.9",
"version": "1.2.0",
"type": "module",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -24,6 +24,9 @@ Node.js loader for import specifiers as file paths without extensions or as directory paths

```js
// imports from the first existing file in the candidates list as follows
import mod from './mod'
// ['./mod.js', './mod/index.js']
// imports from the first existing file in the candidates list as follows
// ['./mod.js', './mod.json', './mod/index.js', './mod/index.json']
import mod from './mod' assert {type: 'json'}
// ['./mod.json', './mod/index.json']
```

@@ -36,6 +39,9 @@

```js
// imports from the first existing file in the candidates list as follows
import mod from '../mod/'
// ['../mod/index.js']
// imports from the first existing file in the candidates list as follows
// ['../mod/index.js', '../mod/index.json']
import mod from '../mod/' assert {type: 'json'}
// ['../mod/index.json']
```

@@ -49,8 +55,8 @@

"extensionless": {
"lookFor": ["mjs", "js", "json"]
"lookFor": ["js", "mjs", "cjs"]
}
```
| Field | Default Value |
| --------- | ----------------- |
| `lookFor` | `["js", "json"]` |
| Field | Default Value |
| --------- | ------------- |
| `lookFor` | `["js"]` |

@@ -16,3 +16,3 @@ import {access, existsSync, readFileSync} from 'fs'

let {
lookFor = ['js', 'json']
lookFor = ['js']
} = pkgJson?.extensionless ?? {}

@@ -23,10 +23,10 @@

let extToSkip = ['.wasm', '.cjs', '.mjs', '.js', '.json']
let indexFiles = lookFor.map(e => `index.${e}`)
let extensions = lookFor.map(e => `.${e}`).concat(indexFiles.map(p => `${sep}${p}`))
let findPostfix = async (specifier, context, isAbs) => {
let postfixes = specifier.endsWith(sep) ? indexFiles : extToSkip.includes(extname(specifier)) ? [] : extensions
let extToSkip = ['.wasm', '.cjs', '.mjs', '.js', '.json'], emptyPostfixes = [[], []]
let indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']]
let extensions = [lookFor.map(e => `.${e}`).concat(lookFor.map(e => `${sep}index.${e}`)), ['.json', `${sep}index.json`]]
let findPostfix = async (specifier, {importAssertions, parentURL}, isAbsPath) => {
let postfixes = specifier.endsWith(sep) ? indexFiles : extToSkip.includes(extname(specifier)) ? emptyPostfixes : extensions
for (let postfix of postfixes) {
let path = isAbs ? specifier + postfix : join(dirname(fileURLToPath(context.parentURL)), specifier + postfix)
for (let postfix of postfixes[+(importAssertions?.type === 'json')]) {
let path = isAbsPath ? specifier + postfix : join(dirname(fileURLToPath(parentURL)), specifier + postfix)

@@ -43,7 +43,7 @@ if (await new Promise(resolve => access(path, e => resolve(!e)))) {

let isAbs = isAbsolute(spec)
let postfix = (isAbs || relPrefixes.some(p => spec.startsWith(p)))
&& await findPostfix(normalize(spec), context, isAbs) || ''
let isAbsPath = isAbsolute(spec)
let postfix = (isAbsPath || relPrefixes.some(p => spec.startsWith(p)))
&& await findPostfix(normalize(spec), context, isAbsPath) || ''
return await nextResolve(specifier + postfix)
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc