import-meta-resolve
Advanced tools
Comparing version 2.1.0 to 2.2.0
/** | ||
* Provides a module-relative resolution function scoped to each module, | ||
* returning the URL string. | ||
* `import.meta.resolve` also accepts a second argument which is the parent | ||
* module from which to resolve from. | ||
* Match `import.meta.resolve` except that `parent` is required (you can pass | ||
* `import.meta.url`). | ||
* | ||
* This function is asynchronous because the ES module resolver in Node.js is | ||
* allowed to be asynchronous. | ||
* | ||
* @param {string} specifier The module specifier to resolve relative to parent. | ||
* @param {string} parent The absolute parent module URL to resolve from. | ||
* You should pass `import.meta.url` or something else | ||
* @param {string} specifier | ||
* The module specifier to resolve relative to parent | ||
* (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, | ||
* etc). | ||
* @param {string} parent | ||
* The absolute parent module URL to resolve from. | ||
* You should pass `import.meta.url` or something else. | ||
* @returns {Promise<string>} | ||
* Returns a promise that resolves to a full `file:`, `data:`, or `node:` URL | ||
* to the found thing. | ||
*/ | ||
@@ -15,0 +16,0 @@ export function resolve(specifier: string, parent: string): Promise<string> |
21
index.js
@@ -8,14 +8,15 @@ /** | ||
/** | ||
* Provides a module-relative resolution function scoped to each module, | ||
* returning the URL string. | ||
* `import.meta.resolve` also accepts a second argument which is the parent | ||
* module from which to resolve from. | ||
* Match `import.meta.resolve` except that `parent` is required (you can pass | ||
* `import.meta.url`). | ||
* | ||
* This function is asynchronous because the ES module resolver in Node.js is | ||
* allowed to be asynchronous. | ||
* | ||
* @param {string} specifier The module specifier to resolve relative to parent. | ||
* @param {string} parent The absolute parent module URL to resolve from. | ||
* You should pass `import.meta.url` or something else | ||
* @param {string} specifier | ||
* The module specifier to resolve relative to parent | ||
* (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, | ||
* etc). | ||
* @param {string} parent | ||
* The absolute parent module URL to resolve from. | ||
* You should pass `import.meta.url` or something else. | ||
* @returns {Promise<string>} | ||
* Returns a promise that resolves to a full `file:`, `data:`, or `node:` URL | ||
* to the found thing. | ||
*/ | ||
@@ -22,0 +23,0 @@ export async function resolve(specifier, parent) { |
@@ -17,4 +17,5 @@ /** | ||
// Manually “tree shaken” from: | ||
// <https://github.com/nodejs/node/blob/d859e9e/lib/internal/errors.js> | ||
// Last checked on: May 22, 2022. | ||
// <https://github.com/nodejs/node/blob/3ebe753/lib/internal/errors.js> | ||
// Last checked on: Nov 23, 2022. | ||
import v8 from 'node:v8' | ||
import process from 'node:process' | ||
@@ -288,2 +289,11 @@ import assert from 'node:assert' | ||
function isErrorStackTraceLimitWritable() { | ||
// Do no touch Error.stackTraceLimit as V8 would attempt to install | ||
// it again during deserialization. | ||
try { | ||
// @ts-expect-error: not in types? | ||
if (v8.startupSnapshot.isBuildingSnapshot()) { | ||
return false | ||
} | ||
} catch {} | ||
const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit') | ||
@@ -301,4 +311,5 @@ if (desc === undefined) { | ||
* This function removes unnecessary frames from Node.js core errors. | ||
* @template {(...args: Array<any>) => unknown} T | ||
* @type {(fn: T) => T} | ||
* @template {(...args: unknown[]) => unknown} T | ||
* @param {T} fn | ||
* @returns {T} | ||
*/ | ||
@@ -318,2 +329,3 @@ function hideStackFrames(fn) { | ||
*/ | ||
// @ts-expect-error: fine | ||
function (error) { | ||
@@ -354,3 +366,5 @@ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable() | ||
const expectedLength = (message.match(/%[dfijoOs]/g) || []).length | ||
const regex = /%[dfijoOs]/g | ||
let expectedLength = 0 | ||
while (regex.exec(message) !== null) expectedLength++ | ||
assert( | ||
@@ -357,0 +371,0 @@ expectedLength === args.length, |
@@ -1,2 +0,2 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/** | ||
@@ -16,3 +16,3 @@ * @param {URL} url | ||
* @param {{parentURL: string}} context | ||
* @returns {string|null} | ||
* @returns {string|null|void} | ||
*/ | ||
@@ -24,3 +24,3 @@ export function defaultGetFormat( | ||
} | ||
): string | null | ||
): string | null | void | ||
export type ProtocolHandler = ( | ||
@@ -32,3 +32,3 @@ parsed: URL, | ||
ignoreErrors: boolean | ||
) => string | null | ||
) => string | null | void | ||
import {URL} from 'url' |
// Manually “tree shaken” from: | ||
// <https://github.com/nodejs/node/blob/40fa2e9/lib/internal/modules/esm/get_format.js> | ||
// Last checked on: May 22, 2022. | ||
// <https://github.com/nodejs/node/blob/3ebe753/lib/internal/modules/esm/get_format.js> | ||
// Last checked on: Nov 23, 2022. | ||
@@ -43,3 +43,3 @@ import path from 'node:path' | ||
* @param {boolean} ignoreErrors | ||
* @returns {string|null} | ||
* @returns {string|null|void} | ||
*/ | ||
@@ -50,3 +50,5 @@ | ||
*/ | ||
const protocolHandlers = Object.assign(Object.create(null), { | ||
const protocolHandlers = { | ||
// @ts-expect-error: hush. | ||
__proto__: null, | ||
'data:': getDataProtocolModuleFormat, | ||
@@ -59,3 +61,3 @@ 'file:': getFileProtocolModuleFormat, | ||
} | ||
}) | ||
} | ||
@@ -84,4 +86,8 @@ /** | ||
if (format) return format | ||
if (ignoreErrors) return null | ||
// Explicit undefined return indicates load hook should rerun format check | ||
if (ignoreErrors) { | ||
return undefined | ||
} | ||
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath) | ||
@@ -104,3 +110,3 @@ } | ||
return protocolHandlers[url.protocol](url, context, true) | ||
return protocolHandlers[url.protocol](url, context, true) || null | ||
} | ||
@@ -111,3 +117,3 @@ | ||
* @param {{parentURL: string}} context | ||
* @returns {string|null} | ||
* @returns {string|null|void} | ||
*/ | ||
@@ -114,0 +120,0 @@ export function defaultGetFormat(url, context) { |
// Manually “tree shaken” from: | ||
// <https://github.com/nodejs/node/blob/40fa2e9/lib/internal/modules/package_json_reader.js> | ||
// Last checked on: May 22, 2022. | ||
// Last checked on: Nov 23, 2022. | ||
// Removed the native dependency. | ||
@@ -5,0 +5,0 @@ // Also: no need to cache, we do that in resolve already. |
@@ -1,2 +0,2 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/** | ||
@@ -12,6 +12,11 @@ * @param {URL} url | ||
* @param {string} specifier | ||
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc. | ||
* @param {URL} base | ||
* Full URL (to a file) that `specifier` is resolved relative from. | ||
* @param {Set<string>} [conditions] | ||
* Conditions. | ||
* @param {boolean} [preserveSymlinks] | ||
* Keep symlinks instead of resolving them. | ||
* @returns {URL} | ||
* A URL object to the found thing. | ||
*/ | ||
@@ -32,21 +37,12 @@ export function moduleResolve( | ||
context?: { | ||
parentURL?: string | undefined | ||
conditions?: string[] | undefined | ||
parentURL?: string | ||
conditions?: Array<string> | ||
} | ||
): { | ||
url: string | ||
format?: string | null | undefined | ||
format?: string | null | ||
} | ||
export type ErrnoException = import('./errors.js').ErrnoException | ||
export type PackageType = 'module' | 'commonjs' | 'none' | ||
export type Format = 'module' | 'commonjs' | ||
export type PackageConfig = { | ||
pjsonPath: string | ||
exists: boolean | ||
main: string | undefined | ||
name: string | undefined | ||
type: PackageType | ||
exports: Record<string, unknown> | undefined | ||
imports: Record<string, unknown> | undefined | ||
} | ||
export type PackageConfig = import('./package-config.js').PackageConfig | ||
export type PackageType = import('./package-config.js').PackageType | ||
import {URL} from 'url' |
// Manually “tree shaken” from: | ||
// <https://github.com/nodejs/node/blob/40fa2e9/lib/internal/modules/esm/resolve.js> | ||
// Last checked on: May 22, 2022. | ||
// <https://github.com/nodejs/node/blob/3ebe753/lib/internal/modules/esm/resolve.js> | ||
// Last checked on: Nov 23, 2022. | ||
/** | ||
* @typedef {import('./errors.js').ErrnoException} ErrnoException | ||
* | ||
* @typedef {'module'|'commonjs'|'none'} PackageType | ||
* | ||
* @typedef {'module'|'commonjs'} Format | ||
* | ||
* @typedef PackageConfig | ||
* @property {string} pjsonPath | ||
* @property {boolean} exists | ||
* @property {string|undefined} main | ||
* @property {string|undefined} name | ||
* @property {PackageType} type | ||
* @property {Record<string, unknown>|undefined} exports | ||
* @property {Record<string, unknown>|undefined} imports | ||
* @typedef {import('./package-config.js').PackageConfig} PackageConfig | ||
* @typedef {import('./package-config.js').PackageType} PackageType | ||
*/ | ||
@@ -28,5 +17,5 @@ | ||
import {builtinModules} from 'node:module' | ||
import packageJsonReader from './package-json-reader.js' | ||
import {defaultGetFormatWithoutErrors} from './get-format.js' | ||
import {codes} from './errors.js' | ||
import {getPackageConfig, getPackageScopeConfig} from './package-config.js' | ||
@@ -57,2 +46,4 @@ const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace] | ||
const invalidSegmentRegEx = | ||
/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i | ||
const deprecatedInvalidSegmentRegEx = | ||
/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i | ||
@@ -64,6 +55,43 @@ const invalidPackageNameRegEx = /^\.|%|\\/ | ||
const emittedPackageWarnings = new Set() | ||
/** @type {Map<string, PackageConfig>} */ | ||
const packageJsonCache = new Map() | ||
const doubleSlashRegEx = /[/\\]{2}/ | ||
/** | ||
* | ||
* @param {string} target | ||
* @param {string} request | ||
* @param {string} match | ||
* @param {URL} packageJsonUrl | ||
* @param {boolean} internal | ||
* @param {URL} base | ||
* @param {boolean} isTarget | ||
*/ | ||
function emitInvalidSegmentDeprecation( | ||
target, | ||
request, | ||
match, | ||
packageJsonUrl, | ||
internal, | ||
base, | ||
isTarget | ||
) { | ||
const pjsonPath = fileURLToPath(packageJsonUrl) | ||
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null | ||
process.emitWarning( | ||
`Use of deprecated ${ | ||
double ? 'double slash' : 'leading or trailing slash matching' | ||
} resolving "${target}" for module ` + | ||
`request "${request}" ${ | ||
request === match ? '' : `matched to "${match}" ` | ||
}in the "${ | ||
internal ? 'imports' : 'exports' | ||
}" field module resolution of the package at ${pjsonPath}${ | ||
base ? ` imported from ${fileURLToPath(base)}` : '' | ||
}.`, | ||
'DeprecationWarning', | ||
'DEP0166' | ||
) | ||
} | ||
/** | ||
* @param {URL} url | ||
@@ -135,104 +163,2 @@ * @param {URL} packageJsonUrl | ||
/** | ||
* @param {string} path | ||
* @param {string|URL} specifier Note: `specifier` is actually optional, not base. | ||
* @param {URL} [base] | ||
* @returns {PackageConfig} | ||
*/ | ||
function getPackageConfig(path, specifier, base) { | ||
const existing = packageJsonCache.get(path) | ||
if (existing !== undefined) { | ||
return existing | ||
} | ||
const source = packageJsonReader.read(path).string | ||
if (source === undefined) { | ||
/** @type {PackageConfig} */ | ||
const packageConfig = { | ||
pjsonPath: path, | ||
exists: false, | ||
main: undefined, | ||
name: undefined, | ||
type: 'none', | ||
exports: undefined, | ||
imports: undefined | ||
} | ||
packageJsonCache.set(path, packageConfig) | ||
return packageConfig | ||
} | ||
/** @type {Record<string, unknown>} */ | ||
let packageJson | ||
try { | ||
packageJson = JSON.parse(source) | ||
} catch (error) { | ||
const exception = /** @type {ErrnoException} */ (error) | ||
throw new ERR_INVALID_PACKAGE_CONFIG( | ||
path, | ||
(base ? `"${specifier}" from ` : '') + fileURLToPath(base || specifier), | ||
exception.message | ||
) | ||
} | ||
const {exports, imports, main, name, type} = packageJson | ||
/** @type {PackageConfig} */ | ||
const packageConfig = { | ||
pjsonPath: path, | ||
exists: true, | ||
main: typeof main === 'string' ? main : undefined, | ||
name: typeof name === 'string' ? name : undefined, | ||
type: type === 'module' || type === 'commonjs' ? type : 'none', | ||
// @ts-expect-error Assume `Record<string, unknown>`. | ||
exports, | ||
// @ts-expect-error Assume `Record<string, unknown>`. | ||
imports: imports && typeof imports === 'object' ? imports : undefined | ||
} | ||
packageJsonCache.set(path, packageConfig) | ||
return packageConfig | ||
} | ||
/** | ||
* @param {URL} resolved | ||
* @returns {PackageConfig} | ||
*/ | ||
function getPackageScopeConfig(resolved) { | ||
let packageJsonUrl = new URL('package.json', resolved) | ||
while (true) { | ||
const packageJsonPath = packageJsonUrl.pathname | ||
if (packageJsonPath.endsWith('node_modules/package.json')) break | ||
const packageConfig = getPackageConfig( | ||
fileURLToPath(packageJsonUrl), | ||
resolved | ||
) | ||
if (packageConfig.exists) return packageConfig | ||
const lastPackageJsonUrl = packageJsonUrl | ||
packageJsonUrl = new URL('../package.json', packageJsonUrl) | ||
// Terminates at root where ../package.json equals ../../package.json | ||
// (can't just check "/package.json" for Windows support). | ||
if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) break | ||
} | ||
const packageJsonPath = fileURLToPath(packageJsonUrl) | ||
/** @type {PackageConfig} */ | ||
const packageConfig = { | ||
pjsonPath: packageJsonPath, | ||
exists: false, | ||
main: undefined, | ||
name: undefined, | ||
type: 'none', | ||
exports: undefined, | ||
imports: undefined | ||
} | ||
packageJsonCache.set(packageJsonPath, packageConfig) | ||
return packageConfig | ||
} | ||
/** | ||
* Legacy CommonJS main resolution: | ||
@@ -324,3 +250,3 @@ * 1. let M = pkg_url + (json main field) | ||
function finalizeResolution(resolved, base, preserveSymlinks) { | ||
if (encodedSepRegEx.test(resolved.pathname)) | ||
if (encodedSepRegEx.exec(resolved.pathname) !== null) | ||
throw new ERR_INVALID_MODULE_SPECIFIER( | ||
@@ -368,6 +294,6 @@ resolved.pathname, | ||
* @param {URL} base | ||
* @returns {never} | ||
* @returns {Error} | ||
*/ | ||
function throwImportNotDefined(specifier, packageJsonUrl, base) { | ||
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED( | ||
function importNotDefined(specifier, packageJsonUrl, base) { | ||
return new ERR_PACKAGE_IMPORT_NOT_DEFINED( | ||
specifier, | ||
@@ -383,6 +309,6 @@ packageJsonUrl && fileURLToPath(new URL('.', packageJsonUrl)), | ||
* @param {URL} base | ||
* @returns {never} | ||
* @returns {Error} | ||
*/ | ||
function throwExportsNotFound(subpath, packageJsonUrl, base) { | ||
throw new ERR_PACKAGE_PATH_NOT_EXPORTED( | ||
function exportsNotFound(subpath, packageJsonUrl, base) { | ||
return new ERR_PACKAGE_PATH_NOT_EXPORTED( | ||
fileURLToPath(new URL('.', packageJsonUrl)), | ||
@@ -395,3 +321,4 @@ subpath, | ||
/** | ||
* @param {string} subpath | ||
* @param {string} request | ||
* @param {string} match | ||
* @param {URL} packageJsonUrl | ||
@@ -402,9 +329,8 @@ * @param {boolean} internal | ||
*/ | ||
function throwInvalidSubpath(subpath, packageJsonUrl, internal, base) { | ||
const reason = `request is not a valid subpath for the "${ | ||
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) { | ||
const reason = `request is not a valid match in pattern "${match}" for the "${ | ||
internal ? 'imports' : 'exports' | ||
}" resolution of ${fileURLToPath(packageJsonUrl)}` | ||
throw new ERR_INVALID_MODULE_SPECIFIER( | ||
subpath, | ||
request, | ||
reason, | ||
@@ -421,11 +347,5 @@ base && fileURLToPath(base) | ||
* @param {URL} [base] | ||
* @returns {never} | ||
* @returns {Error} | ||
*/ | ||
function throwInvalidPackageTarget( | ||
subpath, | ||
target, | ||
packageJsonUrl, | ||
internal, | ||
base | ||
) { | ||
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) { | ||
target = | ||
@@ -436,3 +356,3 @@ typeof target === 'object' && target !== null | ||
throw new ERR_INVALID_PACKAGE_TARGET( | ||
return new ERR_INVALID_PACKAGE_TARGET( | ||
fileURLToPath(new URL('.', packageJsonUrl)), | ||
@@ -454,2 +374,3 @@ subpath, | ||
* @param {boolean} internal | ||
* @param {boolean} isPathMap | ||
* @param {Set<string>|undefined} conditions | ||
@@ -466,6 +387,7 @@ * @returns {URL} | ||
internal, | ||
isPathMap, | ||
conditions | ||
) { | ||
if (subpath !== '' && !pattern && target[target.length - 1] !== '/') | ||
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
@@ -496,7 +418,32 @@ if (!target.startsWith('./')) { | ||
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
} | ||
if (invalidSegmentRegEx.test(target.slice(2))) | ||
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) { | ||
if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) { | ||
if (!isPathMap) { | ||
const request = pattern | ||
? match.replace('*', () => subpath) | ||
: match + subpath | ||
const resolvedTarget = pattern | ||
? RegExpPrototypeSymbolReplace.call( | ||
patternRegEx, | ||
target, | ||
() => subpath | ||
) | ||
: target | ||
emitInvalidSegmentDeprecation( | ||
resolvedTarget, | ||
request, | ||
match, | ||
packageJsonUrl, | ||
internal, | ||
base, | ||
true | ||
) | ||
} | ||
} else { | ||
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
} | ||
} | ||
@@ -508,11 +455,32 @@ const resolved = new URL(target, packageJsonUrl) | ||
if (!resolvedPath.startsWith(packagePath)) | ||
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base) | ||
if (subpath === '') return resolved | ||
if (invalidSegmentRegEx.test(subpath)) { | ||
if (invalidSegmentRegEx.exec(subpath) !== null) { | ||
const request = pattern | ||
? match.replace('*', () => subpath) | ||
: match + subpath | ||
throwInvalidSubpath(request, packageJsonUrl, internal, base) | ||
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) { | ||
if (!isPathMap) { | ||
const resolvedTarget = pattern | ||
? RegExpPrototypeSymbolReplace.call( | ||
patternRegEx, | ||
target, | ||
() => subpath | ||
) | ||
: target | ||
emitInvalidSegmentDeprecation( | ||
resolvedTarget, | ||
request, | ||
match, | ||
packageJsonUrl, | ||
internal, | ||
base, | ||
false | ||
) | ||
} | ||
} else { | ||
throwInvalidSubpath(request, match, packageJsonUrl, internal, base) | ||
} | ||
} | ||
@@ -551,2 +519,3 @@ | ||
* @param {boolean} internal | ||
* @param {boolean} isPathMap | ||
* @param {Set<string>|undefined} conditions | ||
@@ -563,2 +532,3 @@ * @returns {URL|null} | ||
internal, | ||
isPathMap, | ||
conditions | ||
@@ -575,2 +545,3 @@ ) { | ||
internal, | ||
isPathMap, | ||
conditions | ||
@@ -602,2 +573,3 @@ ) | ||
internal, | ||
isPathMap, | ||
conditions | ||
@@ -659,2 +631,3 @@ ) | ||
internal, | ||
isPathMap, | ||
conditions | ||
@@ -674,3 +647,3 @@ ) | ||
throwInvalidPackageTarget( | ||
throw invalidPackageTarget( | ||
packageSubpath, | ||
@@ -772,6 +745,7 @@ target, | ||
false, | ||
false, | ||
conditions | ||
) | ||
if (resolveResult === null || resolveResult === undefined) { | ||
throwExportsNotFound(packageSubpath, packageJsonUrl, base) | ||
throw exportsNotFound(packageSubpath, packageJsonUrl, base) | ||
} | ||
@@ -837,2 +811,3 @@ | ||
false, | ||
packageSubpath.endsWith('/'), | ||
conditions | ||
@@ -842,3 +817,3 @@ ) | ||
if (resolveResult === null || resolveResult === undefined) { | ||
throwExportsNotFound(packageSubpath, packageJsonUrl, base) | ||
throw exportsNotFound(packageSubpath, packageJsonUrl, base) | ||
} | ||
@@ -849,3 +824,3 @@ | ||
throwExportsNotFound(packageSubpath, packageJsonUrl, base) | ||
throw exportsNotFound(packageSubpath, packageJsonUrl, base) | ||
} | ||
@@ -901,2 +876,3 @@ | ||
true, | ||
false, | ||
conditions | ||
@@ -944,2 +920,3 @@ ) | ||
true, | ||
false, | ||
conditions | ||
@@ -956,3 +933,3 @@ ) | ||
throwImportNotDefined(name, packageJsonUrl, base) | ||
throw importNotDefined(name, packageJsonUrl, base) | ||
} | ||
@@ -1124,6 +1101,11 @@ | ||
* @param {string} specifier | ||
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc. | ||
* @param {URL} base | ||
* Full URL (to a file) that `specifier` is resolved relative from. | ||
* @param {Set<string>} [conditions] | ||
* Conditions. | ||
* @param {boolean} [preserveSymlinks] | ||
* Keep symlinks instead of resolving them. | ||
* @returns {URL} | ||
* A URL object to the found thing. | ||
*/ | ||
@@ -1130,0 +1112,0 @@ export function moduleResolve(specifier, base, conditions, preserveSymlinks) { |
{ | ||
"name": "import-meta-resolve", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Resolve things like Node.js — ponyfill for `import.meta.resolve`", | ||
@@ -31,7 +31,5 @@ "license": "MIT", | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"@types/semver": "^7.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
@@ -41,15 +39,14 @@ "prettier": "^2.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"semver": "^7.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.51.0" | ||
"xo": "^0.53.0" | ||
}, | ||
"scripts": { | ||
"generate": "node script.js", | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"{lib/**,test/**,}*.d.ts\" && tsc && type-coverage", | ||
"prepack": "npm run generate && npm run build && npm run format", | ||
"generate": "node --conditions development script.js", | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --experimental-import-meta-resolve test/baseline.js && node test/index.js", | ||
"test-coverage": "node --experimental-import-meta-resolve test/baseline.js && c8 --check-coverage --branches 75 --functions 75 --lines 75 --statements 75 --reporter lcov node test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 75 --functions 75 --lines 75 --statements 75 --reporter lcov npm run test-api", | ||
"test": "npm run generate && npm run build && npm run format && npm run test-coverage" | ||
@@ -56,0 +53,0 @@ }, |
@@ -34,3 +34,3 @@ # import-meta-resolve | ||
As of Node.js 18.2, `import.meta.resolve` is still behind an experimental flag. | ||
As of Node.js 19.1, `import.meta.resolve` is still behind an experimental flag. | ||
This package can be used to do what it does in Node 14–18. | ||
@@ -41,3 +41,3 @@ | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+, 16.0+, or 18.0+), install with [npm][]: | ||
In Node.js (version 14.14+, 16.0+), install with [npm][]: | ||
@@ -87,5 +87,7 @@ ```sh | ||
* `specifier` (`string`) | ||
— `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc | ||
— the module specifier to resolve relative to parent | ||
(`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc). | ||
* `parent` (`string`, example: `import.meta.url`) | ||
— full URL (to a file) that `specifier` is resolved relative from | ||
— the absolute parent module URL to resolve from. | ||
You should pass `import.meta.url` or something else. | ||
@@ -130,3 +132,3 @@ ###### Returns | ||
explicitly pass it | ||
* No support for CLI flags: `--experimental-specifier-resolution`, | ||
* no support for CLI flags: | ||
`--experimental-json-modules`, `--experimental-wasm-modules`, | ||
@@ -136,5 +138,6 @@ `--experimental-policy`, `--experimental-network-imports`, `--no-addons`, | ||
`--preserve-symlinks-main`, nor `--conditions` work | ||
* No attempt is made to add a suggestion based on how things used to work in | ||
* no support for `WATCH_REPORT_DEPENDENCIES` env variable | ||
* no attempt is made to add a suggestion based on how things used to work in | ||
CJS before to not-found errors | ||
* Prototypal methods are not guarded: Node protects for example `String#slice` | ||
* prototypal methods are not guarded: Node protects for example `String#slice` | ||
or so from being tampered with, whereas this doesn’t | ||
@@ -179,3 +182,3 @@ | ||
This package is at least compatible with all maintained versions of Node.js. | ||
As of now, that is Node.js 14.14+, 16.0+, and 18.0+. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
@@ -182,0 +185,0 @@ ## Contribute |
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
69582
10
15
1899
217