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.2.1 to 1.2.2

2

package.json
{
"name": "extensionless",
"version": "1.2.1",
"version": "1.2.2",
"type": "module",

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

@@ -29,4 +29,10 @@ Node.js loader for import specifiers as file paths without extensions or as directory paths

import mod from './mod' assert {type: 'json'}
// ['./mod.json', './mod/index.json']
import mod from '../mod' assert {type: 'json'}
// ['../mod.json', '../mod/index.json']
import api from '/apps/api'
// ['/apps/api.js', '/apps/api/index.js']
import web from 'file:///apps/web'
// ['file:///apps/web.js', 'file:///apps/web/index.js']
```

@@ -36,3 +42,3 @@

If the specifier ends with a path separator, it only looks for index files in that directory:
If it can be deduced from the specifier that its target is a directory, the resolver looks for only the index files:

@@ -42,7 +48,19 @@ ```js

import mod from '../mod/'
// ['../mod/index.js']
import cur from '.'
// ['./index.js']
import up from '..'
// ['../index.js']
import mod from './mod/'
// ['./mod/index.js']
import mod from '../mod/' assert {type: 'json'}
// ['../mod/index.json']
import api from '/apps/api/'
// ['/apps/api/index.js']
import web from 'file:///apps/web/'
// ['file:///apps/web/index.js']
```

@@ -49,0 +67,0 @@

import {access, existsSync, readFileSync} from 'fs'
import {dirname, extname, isAbsolute, join, normalize, sep} from 'path'
import {dirname, extname, isAbsolute, join, normalize} from 'path'
import {argv, cwd} from 'process'

@@ -20,14 +20,17 @@ import {fileURLToPath} from 'url'

Array.isArray(lookFor) && lookFor.length && lookFor.every(a => typeof a === 'string' && /^[a-z]+\w*$/i.test(a))
|| (console.error('\x1b[33m%s\x1b[0m', `The package.json field 'extensionless.lookFor' must be an array of alphanumeric strings!`), process.exit(1))
|| (console.error('\x1b[31m%s\x1b[0m', `The package.json field 'extensionless.lookFor' must be an array of alphanumeric strings!`), process.exit(1))
let extToSkip = ['.wasm', '.cjs', '.mjs', '.js', '.json'], none = [[], []]
let indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']]
let candidates = [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)) ? none : candidates
let relatives = indexFiles.map(i => i.map(f => `/${f}`))
let extToSkip = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'], none = [[], []]
let candidates = relatives.map(r => r.map(p => extname(p)).concat(r))
let findPostfix = async (spec, {importAssertions, parentURL}, isAbsPath, isRelSpec) => {
let postfixes = spec.endsWith('/') ? indexFiles : isRelSpec ? relatives
: extToSkip.includes(extname(spec)) ? none : candidates
for (let postfix of postfixes[+(importAssertions?.type === 'json')]) {
let path = isAbsPath ? specifier + postfix : join(dirname(fileURLToPath(parentURL)), specifier + postfix)
let path = join(isAbsPath ? '' : dirname(fileURLToPath(parentURL)), spec + postfix)
if (await new Promise(resolve => access(path, e => resolve(!e)))) {
if (await new Promise(resolve => access(normalize(path), e => resolve(!e)))) {
return postfix

@@ -38,11 +41,12 @@ }

let relPrefixes = [...new Set(['./', '../', `.${sep}`, `..${sep}`])]
let relSpecs = ['.', '..'], relPrefixes = ['./', '../']
export async function resolve(specifier, context, nextResolve) {
let spec = specifier.startsWith('file://') ? fileURLToPath(specifier) : specifier
let isAbsPath = isAbsolute(spec)
let postfix = (isAbsPath || relPrefixes.some(p => spec.startsWith(p)))
&& await findPostfix(normalize(spec), context, isAbsPath) || ''
let isAbsPath = isAbsolute(spec), isRelSpec = relSpecs.includes(spec)
let postfix = (isAbsPath || isRelSpec || relPrefixes.some(p => spec.startsWith(p)))
&& await findPostfix(spec, context, isAbsPath, isRelSpec) || ''
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