Gathering detailed insights and metrics for import-meta-resolve
Gathering detailed insights and metrics for import-meta-resolve
Gathering detailed insights and metrics for import-meta-resolve
Gathering detailed insights and metrics for import-meta-resolve
@dual-bundle/import-meta-resolve
A fork of `import-meta-resolve` with commonjs + ESM support at the same time, AKA dual package.
@ctx-core/import-meta-resolve
ctx-core import-meta-resolve
resolve-pathname
Resolve URL pathnames using JavaScript
mlly
Missing ECMAScript module utils for Node.js
Resolve things like Node.js — ponyfill for `import.meta.resolve`
npm install import-meta-resolve
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
129 Stars
82 Commits
15 Forks
4 Watching
2 Branches
8 Contributors
Updated on 04 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.3%
899,490
Compared to previous day
Last week
3.4%
4,763,162
Compared to previous week
Last month
10.6%
19,996,260
Compared to previous month
Last year
372.6%
161,617,545
Compared to previous year
Resolve things like Node.js.
This package is a ponyfill for import.meta.resolve
.
It supports everything you need to resolve files just like modern Node does:
import maps, export maps, loading CJS and ESM projects, all of that!
As of Node.js 20.0, import.meta.resolve
is still behind an experimental flag.
This package can be used to do what it does in Node 16–20.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install import-meta-resolve
1import {resolve} from 'import-meta-resolve' 2 3// A file: 4console.log(resolve('./index.js', import.meta.url)) 5//=> file:///Users/tilde/Projects/oss/import-meta-resolve/index.js 6 7// A CJS package: 8console.log(resolve('builtins', import.meta.url)) 9//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/builtins/index.js 10 11// A scoped CJS package: 12console.log(resolve('@eslint/eslintrc', import.meta.url)) 13//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/@eslint/eslintrc/lib/index.js 14 15// A package with an export map: 16console.log(resolve('micromark/lib/parse', import.meta.url)) 17//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/micromark/lib/parse.js 18 19// A node builtin: 20console.log(resolve('fs', import.meta.url)) 21//=> node:fs
This package exports the identifiers moduleResolve
and
resolve
.
There is no default export.
resolve(specifier, parent)
Match import.meta.resolve
except that parent
is required (you can pass
import.meta.url
).
specifier
(string
)
— the module specifier to resolve relative to parent
(/example.js
, ./example.js
, ../example.js
, some-package
, fs
, etc)parent
(string
, example: import.meta.url
)
— the absolute parent module URL to resolve from; you must pass
import.meta.url
or something elseFull file:
, data:
, or node:
URL (string
) to the found thing
Throws an ErrnoException
.
moduleResolve(specifier, parent, conditions, preserveSymlinks)
The “Resolver Algorithm Specification” as detailed in the Node docs
(which is slightly lower-level than resolve
).
specifier
(string
)
— /example.js
, ./example.js
, ../example.js
, some-package
, fs
, etcparent
(URL
, example: import.meta.url
)
— full URL (to a file) that specifier
is resolved relative fromconditions
(Set<string>
, default: new Set(['node', 'import'])
)
— conditionspreserveSymlinks
(boolean
, default: false
)
— keep symlinks instead of resolving themA URL object (URL
) to the found thing.
Throws an ErrnoException
.
ErrnoException
One of many different errors that occur when resolving (TypeScript type).
1type ErrnoExceptionFields = Error & { 2 errnode?: number | undefined 3 code?: string | undefined 4 path?: string | undefined 5 syscall?: string | undefined 6 url?: string | undefined 7}
The code
field on errors is one of the following strings:
'ERR_INVALID_MODULE_SPECIFIER'
— when specifier
is invalid (example: '#'
)'ERR_INVALID_PACKAGE_CONFIG'
— when a package.json
is invalid (example: invalid JSON)'ERR_INVALID_PACKAGE_TARGET'
— when a package.json
exports
or imports
is invalid (example: when it
does not start with './'
)'ERR_MODULE_NOT_FOUND'
— when specifier
cannot be found in parent
(example: 'some-missing-package'
)'ERR_NETWORK_IMPORT_DISALLOWED'
— thrown when trying to resolve a local file or builtin from a remote file
(node:fs
relative to 'https://example.com'
)'ERR_PACKAGE_IMPORT_NOT_DEFINED'
— when a local import is not defined in an import map (example: '#local'
when not defined)'ERR_PACKAGE_PATH_NOT_EXPORTED'
— when an export is not defined in an export map (example: 'tape/index.js'
,
which is not in its export map)'ERR_UNSUPPORTED_DIR_IMPORT'
— when attempting to import a directory (example: './lib/'
)'ERR_UNKNOWN_FILE_EXTENSION'
— when somehow reading a file that has an unexpected extensions ('./readme.md'
)'ERR_INVALID_ARG_VALUE'
— when conditions
is incorrectThe algorithm for resolve
matches how Node handles import.meta.resolve
, with
a couple of differences.
The algorithm for moduleResolve
matches the Resolver Algorithm
Specification as detailed in the Node docs (which is sync and slightly
lower-level than resolve
).
parent
defaulting to import.meta.url
cannot be ponyfilled: you have to
explicitly pass it--conditions
,
--experimental-default-type
,
--experimental-json-modules
,
--experimental-network-imports
,
--experimental-policy
,
--experimental-wasm-modules
,
--input-type
,
--no-addons
,
--preserve-symlinks
, nor
--preserve-symlinks-main
workWATCH_REPORT_DEPENDENCIES
env variableString#slice
or so from being tampered with, whereas this doesn’tThis package is fully typed with TypeScript.
It exports the additional type ErrnoException
.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 16 and later.
Yes please! See How to Contribute to Open Source.
MIT © Titus Wormer and Node.js contributors
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More