{"name":"import-meta-resolve","version":"0.1.0","description":"Resolve paths in node when using es modules (or commonjs). Ponyfill for import.meta.resolve as it is behind a flag","license":"MIT","author":{"name":"Thomas Allmer","email":"d4kmor@gmail.com"},"main":"index.js","module":"index.mjs","engines":{"node":">=10.0.0"},"scripts":{"test":"mocha test/**/*.test.js test/*.test.js","test:watch":"mocha test/**/*.test.js --watch","format":"npm run format:eslint && npm run format:prettier","format:eslint":"eslint --ext .ts,.js,.mjs,.cjs . --fix","format:prettier":"node node_modules/prettier/bin-prettier.js \"**/*.{ts,js,mjs,cjs,md}\" \"**/package.json\" --write --ignore-path .eslintignore","install-puppeteer-firefox":"cd node_modules/puppeteer && PUPPETEER_PRODUCT=firefox node install.js","lint":"npm run lint:eslint && npm run lint:prettier","lint:eslint":"eslint --ext .ts,.js,.mjs,.cjs .","lint:md":"remark ./docs","lint:prettier":"node node_modules/prettier/bin-prettier.js \"**/*.{ts,js,mjs,cjs,md}\" --check --ignore-path .eslintignore","build":"rm tsconfig.tsbuildinfo && tsc","prepublish":"npm run build"},"keywords":["import","meta","resolve"],"devDependencies":{"@types/chai":"^4.2.11","@types/mocha":"^8.0.01","@types/node":"^14.6.0","@typescript-eslint/eslint-plugin":"^3.7.0","@typescript-eslint/parser":"^3.7.0","chai":"^4.2.0","eslint":"^7.5.0","eslint-config-prettier":"^6.11.0","husky":"^1.0.0","lint-staged":"^8.0.0","mocha":"^8.1.1","prettier":"^2.0.5","prettier-plugin-package":"^1.0.0","typescript":"^4.0.0"},"eslintConfig":{"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint"],"extends":["eslint:recommended","eslint-config-prettier","plugin:@typescript-eslint/recommended"],"env":{"browser":true,"node":true,"mocha":true,"es2020":true},"rules":{"@typescript-eslint/no-non-null-assertion":"off","@typescript-eslint/explicit-module-boundary-types":"off","@typescript-eslint/no-explicit-any":"off","@typescript-eslint/no-empty-interface":"off","@typescript-eslint/no-unused-vars":"error","@typescript-eslint/no-var-requires":"off"}},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.js":["eslint --fix","prettier --write --ignore-path .eslintignore","git add"]},"prettier":{"singleQuote":true,"arrowParens":"avoid","printWidth":100,"trailingComma":"all"},"types":"dist/importMetaResolve.d.ts","exports":{".":{"import":"./index.mjs","require":"./index.js"}},"gitHead":"3c1f1d7fb0194c8048188ad4921ba97b3c9181fc","_id":"import-meta-resolve@0.1.0","_nodeVersion":"14.9.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-Fmrdns/Ckw/fpzxiUu3Bv6UDzASh3ZW6TpvyWU6RpZ4xQl0YmCyfA4mcifG3QRUrPUk+iQm3upQSM1SBvlHrTw==","shasum":"027220eaa2298589d8d29b437a92a22db1bec6b2","tarball":"http://registry-npm.ywwl.com/import-meta-resolve/download/import-meta-resolve-0.1.0.tgz","fileCount":8,"unpackedSize":9948,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfTtu1CRA9TVsSAnZWagAAFFoP/21kyXaH47p1R1BneRm8\nf85nn66OZco8O2dwastuRVT2yzlWweIOpyBD9C9kHykQ561ykKvs2N8wjRxW\neMq4Dr4pXrBJfq1xKVIpMcNuBy4uypt/LFCFJhP1MIvSXTqtcztbviOCX8n1\nHpzKd9Bdw69+jyKsk321Lb6xv9RtOuCasbQErxguoK7YFmb5iXm+8ubydlFX\nbqQ6q+OkwN3Pl5Sy/bYzg3oys+T4wd4sHzsU1BJAnh9O2Ln2UhePq+xD/ArW\nB3sH4ykRxU0rM2g1Jj2d+u5gKScXUNrGMyk+iTKbGw9OmjD6ITsgHQoP7dxJ\nEtsIRSJxpkHHRYzy52tMhWEV9nwKGZ0zLNCtn+VfAKpnLzpYS0q43YSmCrMS\nBDQLt1g94VhzBfkkDhD53SA/diDk+w97L6vhaGaFiPdDoDK7c06VfZPiEi8l\nczL4VUwyDURCRIF752gYnNFfG73VJEOJXcqLz0XMdUEJmFFdXeZr9BYuYNut\nW8fFuZIxgpnzeXN3aavUWV35CtYcIivx/wmpW+OT6dL8F+5maC7LWjYr3q8m\nl36KicwQIIDAm8LIDPe6bsgWmYO4htYybOSasakrvDp0TJwtImQxf5ArhPjv\nlmgsyRe1dWwev0fUJNcFE8sytWLLt5X2XwX6tdVDAzQMm3HJCVhqysRrnl7Y\nPhJK\r\n=jFmj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDvlBrnk++XLBwQINLol4tT/3xQI9kkVezCuipiOW1RQQIgU8L+pJfIKdarUO23o4sUx78/eaG5gDUyk7Jf+OL4zxE="}],"size":3672,"noattachment":false,"key":"/import-meta-resolve/-/import-meta-resolve-0.1.0.tgz"},"maintainers":[{"name":"d4kmor","email":"d4kmor@gmail.com"}],"_npmUser":{"name":"d4kmor","email":"d4kmor@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/import-meta-resolve_0.1.0_1599003572797_0.06215230816644768"},"_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":1599003572929,"_cnpm_publish_time":1599003572929,"dist-tags":{"latest":"4.2.0"}}