{"name":"import-meta-resolve","version":"2.0.2","description":"Resolve things like Node.js — ponyfill for `import.meta.resolve`","license":"MIT","keywords":["resolve","node","esm","module"],"repository":{"type":"git","url":"git+https://github.com/wooorm/import-meta-resolve.git"},"bugs":{"url":"https://github.com/wooorm/import-meta-resolve/issues"},"funding":{"type":"github","url":"https://github.com/sponsors/wooorm"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"builtins":"^5.0.0"},"devDependencies":{"@types/node":"^17.0.0","@types/semver":"^7.0.0","@types/tape":"^4.0.0","c8":"^7.0.0","prettier":"^2.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^9.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.49.0"},"scripts":{"generate":"node script.js","prepack":"npm run build && npm run format","build":"rimraf \"{lib/**,test/**,}*.d.ts\" && tsc && 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":"npm run generate && npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"rules":{"complexity":"off","max-depth":"off","max-params":"off","no-constant-condition":"off","no-new":"off","prefer-arrow-callback":"off"},"ignore":["test/node_modules/"]},"remarkConfig":{"plugins":["preset-wooorm",["remark-lint-maximum-heading-length",false]]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true,"ignoreFiles":["lib/errors.d.ts"]},"gitHead":"937d3f33413bf61d2e85e866d4650cb38ebd94cb","homepage":"https://github.com/wooorm/import-meta-resolve#readme","_id":"import-meta-resolve@2.0.2","_nodeVersion":"18.2.0","_npmVersion":"8.9.0","dist":{"integrity":"sha512-e53F4xWZr/pCeLRJreOIJrpKvo9Bm3K1pJSp+xhI6yeuWqSDW1xRiML/VclnSXvke96VCzMkza9avmvd9l9ixA==","shasum":"25a8de8521df7a26775f2ac9c5198f339b9200d7","tarball":"http://registry-npm.ywwl.com/import-meta-resolve/download/import-meta-resolve-2.0.2.tgz","fileCount":13,"unpackedSize":64228,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC86Pawv5Jc44OtbJ2ITbHi9w2n664wS5lztv1nJPqUyQIhAJudr6b6Kb3tBKvllPcvdbxAJ0oJDUwpGDtRcbth2lp4"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJijm1kACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpHwxAAjAsDqJLXcqNSwJF17JkEq+wVLyVt8lH0ON1fpenLT0Cdot5T\r\nECdyU3XVam8sraesaPJ2YVKN9iGGyRCpQOzMaaxsvf2WSDVNBV7ya4B4x0aG\r\niQjOGpDEDJHntMtbvqTvaE/xUkbMifiLicUlHnFEX2lVk0SvCKGHFhS0esgt\r\nwxryiQCUdE1QxTNPwTDiGuYsWjQoWphUFlvTemk7QmtBOfLFrvBibmLuahxV\r\nVUYS5Q6lC3zMLhq+i5SdW3kmxO52UScgLqb/DlXyN+3ANQ4qkVWx9Zf3GQAt\r\n3GAADYbh0oBhgHhzANttQjDYQINL+YDQbJ7c6jXI+zO+QLcT8BdKaDuYNFwO\r\nxVwbsVfS/9vNbEL4KhxmEZqkFmtuZ37TeBhDiNkDr2GV5Nam2fO0+iVtRg9h\r\nMr6k9HxAP6rQI56Pn/SaUSiMdIzP4PuIQcRx+DxzJntvgRDa/hj66g5OqGTp\r\n2x3nxjimJI68mV3W3jqAmEB9DncjwbPaEs9IcqIopkh8cDH6d850dtHPfWde\r\nb7mS3yTzbdZ0auvc81LQ5eGzKMCdW+xtmylGdIerzP+aRcBqnpawBLgnfCwO\r\nZHqzEcsRdSuJeMSL0jIkoW39/wx/gIKW/NvfSzKbM74YG7stM1SIKB8zm+XQ\r\njum5E/iCMtl8dBb7dzv3DH/ce+SBQ1r0vZo=\r\n=NDzl\r\n-----END PGP SIGNATURE-----\r\n","size":16716,"noattachment":false,"key":"/import-meta-resolve/-/import-meta-resolve-2.0.2.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/import-meta-resolve_2.0.2_1653501284628_0.4828846318330906"},"_hasShrinkwrap":false,"readme":"# import-meta-resolve\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n\nResolve things like Node.js.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When to use this?](#when-to-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`resolve(specifier, parent)`](#resolvespecifier-parent)\n  * [`moduleResolve(specifier, parent, conditions, preserveSymlinks)`](#moduleresolvespecifier-parent-conditions-preservesymlinks)\n  * [`ErrnoException`](#errnoexception)\n* [Algorithm](#algorithm)\n* [Differences to Node](#differences-to-node)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a ponyfill for [`import.meta.resolve`][native-resolve].\nIt supports everything you need to resolve files just like modern Node does:\nimport maps, export maps, loading CJS and ESM projects, all of that!\n\n## When to use this?\n\nAs of Node.js 20.0, `import.meta.resolve` is still behind an experimental flag.\nThis package can be used to do what it does in Node 16–20.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install import-meta-resolve\n```\n\n## Use\n\n```js\nimport {resolve} from 'import-meta-resolve'\n\n// A file:\nconsole.log(resolve('./index.js', import.meta.url))\n//=> file:///Users/tilde/Projects/oss/import-meta-resolve/index.js\n\n// A CJS package:\nconsole.log(resolve('builtins', import.meta.url))\n//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/builtins/index.js\n\n// A scoped CJS package:\nconsole.log(resolve('@eslint/eslintrc', import.meta.url))\n//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/@eslint/eslintrc/lib/index.js\n\n// A package with an export map:\nconsole.log(resolve('micromark/lib/parse', import.meta.url))\n//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/micromark/lib/parse.js\n\n// A node builtin:\nconsole.log(resolve('fs', import.meta.url))\n//=> node:fs\n```\n\n## API\n\nThis package exports the identifiers [`moduleResolve`][moduleresolve] and\n[`resolve`][resolve].\nThere is no default export.\n\n### `resolve(specifier, parent)`\n\nMatch `import.meta.resolve` except that `parent` is required (you can pass\n`import.meta.url`).\n\n###### Parameters\n\n* `specifier` (`string`)\n  — the module specifier to resolve relative to parent\n  (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc)\n* `parent` (`string`, example: `import.meta.url`)\n  — the absolute parent module URL to resolve from; you must pass\n  `import.meta.url` or something else\n\n###### Returns\n\nFull `file:`, `data:`, or `node:` URL (`string`) to the found thing\n\n###### Throws\n\nThrows an [`ErrnoException`][errnoexception].\n\n### `moduleResolve(specifier, parent, conditions, preserveSymlinks)`\n\nThe [“Resolver Algorithm Specification”][algo] as detailed in the Node docs\n(which is slightly lower-level than `resolve`).\n\n###### Parameters\n\n* `specifier` (`string`)\n  — `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc\n* `parent` (`URL`, example: `import.meta.url`)\n  — full URL (to a file) that `specifier` is resolved relative from\n* `conditions` (`Set<string>`, default: `new Set(['node', 'import'])`)\n  — conditions\n* `preserveSymlinks` (`boolean`, default: `false`)\n  — keep symlinks instead of resolving them\n\n###### Returns\n\nA URL object (`URL`) to the found thing.\n\n###### Throws\n\nThrows an [`ErrnoException`][errnoexception].\n\n### `ErrnoException`\n\nOne of many different errors that occur when resolving (TypeScript type).\n\n###### Type\n\n```ts\ntype ErrnoExceptionFields = Error & {\n  errnode?: number | undefined\n  code?: string | undefined\n  path?: string | undefined\n  syscall?: string | undefined\n  url?: string | undefined\n}\n```\n\nThe `code` field on errors is one of the following strings:\n\n* `'ERR_INVALID_MODULE_SPECIFIER'`\n  — when `specifier` is invalid (example: `'#'`)\n* `'ERR_INVALID_PACKAGE_CONFIG'`\n  — when a `package.json` is invalid (example: invalid JSON)\n* `'ERR_INVALID_PACKAGE_TARGET'`\n  — when a `package.json` `exports` or `imports` is invalid (example: when it\n  does not start with `'./'`)\n* `'ERR_MODULE_NOT_FOUND'`\n  — when `specifier` cannot be found in `parent` (example: `'some-missing-package'`)\n* `'ERR_NETWORK_IMPORT_DISALLOWED'`\n  — thrown when trying to resolve a local file or builtin from a remote file\n  (`node:fs` relative to `'https://example.com'`)\n* `'ERR_PACKAGE_IMPORT_NOT_DEFINED'`\n  — when a local import is not defined in an import map (example: `'#local'`\n  when not defined)\n* `'ERR_PACKAGE_PATH_NOT_EXPORTED'`\n  — when an export is not defined in an export map (example: `'tape/index.js'`,\n  which is not in its export map)\n* `'ERR_UNSUPPORTED_DIR_IMPORT'`\n  — when attempting to import a directory (example: `'./lib/'`)\n* `'ERR_UNKNOWN_FILE_EXTENSION'`\n  — when somehow reading a file that has an unexpected extensions (`'./readme.md'`)\n* `'ERR_INVALID_ARG_VALUE'`\n  — when `conditions` is incorrect\n\n## Algorithm\n\nThe algorithm for `resolve` matches how Node handles `import.meta.resolve`, with\na couple of differences.\n\nThe algorithm for `moduleResolve` matches the [Resolver Algorithm\nSpecification][algo] as detailed in the Node docs (which is sync and slightly\nlower-level than `resolve`).\n\n## Differences to Node\n\n* `parent` defaulting to `import.meta.url` cannot be ponyfilled: you have to\n  explicitly pass it\n* no support for loaders (that would mean implementing all of loaders)\n* no support for CLI flags:\n  `--conditions`,\n  `--experimental-default-type`,\n  `--experimental-json-modules`,\n  `--experimental-network-imports`,\n  `--experimental-policy`,\n  `--experimental-wasm-modules`,\n  `--input-type`,\n  `--no-addons`,\n  `--preserve-symlinks`, nor\n  `--preserve-symlinks-main`\n  work\n* no support for `WATCH_REPORT_DEPENDENCIES` env variable\n* no attempt is made to add a suggestion based on how things used to work in\n  CJS before to not-found errors\n* prototypal methods are not guarded: Node protects for example `String#slice`\n  or so from being tampered with, whereas this doesn’t\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`ErrnoException`][errnoexception].\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 16 and later.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author] and Node.js contributors\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/wooorm/import-meta-resolve/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/import-meta-resolve/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/import-meta-resolve.svg\n\n[coverage]: https://codecov.io/github/wooorm/import-meta-resolve\n\n[downloads-badge]: https://img.shields.io/npm/dm/import-meta-resolve.svg\n\n[downloads]: https://www.npmjs.com/package/import-meta-resolve\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[algo]: https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_resolver_algorithm\n\n[native-resolve]: https://nodejs.org/api/esm.html#esm_import_meta_resolve_specifier_parent\n\n[resolve]: #resolvespecifier-parent\n\n[moduleresolve]: #moduleResolvespecifier-parent-conditions-preserveSymlinks\n\n[errnoexception]: #errnoexception\n","publish_time":1653501284847,"_cnpm_publish_time":1653501284847,"dist-tags":{"latest":"4.2.0"}}