{"_id":"exsolve@1.1.3","bugs":{"url":"https://github.com/unjs/exsolve/issues"},"dist":{"shasum":"175a6336d6cb1c9cfee822a092665ee0b79e716d","tarball":"http://registry-npm.ywwl.com/exsolve/download/exsolve-1.1.3.tgz","fileCount":5,"integrity":"sha512-kuzL9zherLQoqDeQaS55AiiIg1kb4KYXaSusTtgZTPlvKP2gGCI82LNmBNh5RjDVUXIcmgx+/Mx7vPwRzBbhJA==","signatures":[{"sig":"MEUCIDF9lUNN5X4KfUDD8tYJbk9a6QJAKBag+SShd4jMh6ZUAiEA8MoCglHohYfxrAMRtLe3YzAZCVfAzMUFDR17BDUrfM4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDCEEg7+vFloAsdF9In+i3E3QHDnIvFS8l5xaRhqo6VNAiBiNVjxHoaf0A8EreAs5E6kzOYslHGEvxhve0OvneUkPA=="}],"unpackedSize":55426,"size":14966,"noattachment":false,"key":"/exsolve/-/exsolve-1.1.3.tgz"},"name":"exsolve","type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs"},"license":"MIT","scripts":{"dev":"vitest dev","fmt":"automd && oxlint && oxfmt .","lint":"oxlint . && oxfmt --check .","test":"pnpm lint && pnpm test:types && vitest run --coverage","build":"obuild","node-ts":"node --disable-warning=ExperimentalWarning --experimental-strip-types","prepack":"pnpm build","release":"pnpm test && pnpm build && changelogen --release && npm publish && git push --follow-tags","test:types":"tsc --noEmit --skipLibCheck"},"version":"1.1.3","_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"homepage":"https://github.com/unjs/exsolve#readme","repository":{"url":"git+https://github.com/unjs/exsolve.git","type":"git"},"_npmVersion":"12.1.0","description":"Module resolution utilities based on Node.js upstream implementation.","directories":{},"maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.21.0","_hasShrinkwrap":false,"packageManager":"pnpm@11.17.0","devDependencies":{"jiti":"^2.7.0","oxfmt":"^0.60.0","automd":"^0.4.3","obuild":"^0.4.38","oxlint":"^1.75.0","vitest":"^4.1.10","happy-dom":"^20.11.1","typescript":"^7.0.2","@types/node":"^26.1.1","changelogen":"^0.6.2","eslint-config-unjs":"^0.6.2","@vitest/coverage-v8":"^4.1.10"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/exsolve_1.1.3_1791020218804_0.40672553913041676"},"readme":"# exsolve\n\n[![npm version](https://img.shields.io/npm/v/exsolve?color=yellow)](https://npmjs.com/package/exsolve)\n[![npm downloads](https://img.shields.io/npm/dm/exsolve?color=yellow)](https://npm.chart.dev/exsolve)\n[![pkg size](https://img.shields.io/npm/unpacked-size/exsolve?color=yellow)](https://packagephobia.com/result?p=exsolve)\n\n> Module resolution utilities for Node.js (based on previous work in [unjs/mlly](https://github.com/unjs/mlly), [wooorm/import-meta-resolve](https://github.com/wooorm/import-meta-resolve), and the upstream [Node.js](https://github.com/nodejs/node) implementation).\n\nThis library exposes an API similar to [`import.meta.resolve`](https://nodejs.org/api/esm.html#importmetaresolvespecifier) based on Node.js's upstream implementation and [resolution algorithm](https://nodejs.org/api/esm.html#esm_resolution_algorithm). It supports all built-in functionalities—import maps, export maps, CJS, and ESM—with some additions:\n\n- Pure JS with no native dependencies (only Node.js is required).\n- Built-in resolve [cache](#resolve-cache).\n- Throws an error (or [try](#try)) if the resolved path does not exist in the filesystem.\n- Can override the default [conditions](#conditions).\n- Can resolve [from](#from) one or more parent URLs.\n- Can resolve with custom [suffixes](#suffixes).\n- Can resolve with custom [extensions](#extensions).\n\n## Usage\n\nInstall the package:\n\n```sh\n# ✨ Auto-detect (npm, yarn, pnpm, bun, deno)\nnpx nypm install exsolve\n```\n\nImport:\n\n```ts\n// ESM import\nimport { resolveModuleURL, resolveModulePath, createResolver, clearResolveCache } from \"exsolve\";\n\n// Or using dynamic import\nconst { resolveModulePath } = await import(\"exsolve\");\n```\n\n```ts\nresolveModuleURL(id, {/* options */});\n\nresolveModulePath(id, {/* options */});\n```\n\nDifferences between `resolveModuleURL` and `resolveModulePath`:\n\n- `resolveModuleURL` returns a URL string like `file:///app/dep.mjs`.\n- `resolveModulePath` returns an absolute path like `/app/dep.mjs`.\n  - If the resolved URL does not use the `file://` scheme (e.g., `data:` or `node:`), it will throw an error.\n\n## Resolver with Options\n\nYou can create a custom resolver instance with default [options](#resolve-options) using `createResolver`.\n\n**Example:**\n\n```ts\nimport { createResolver } from \"exsolve\";\n\nconst { resolveModuleURL, resolveModulePath } = createResolver({\n  suffixes: [\"\", \"/index\"],\n  extensions: [\".mjs\", \".cjs\", \".js\", \".mts\", \".cts\", \".ts\", \".json\"],\n  conditions: [\"node\", \"import\", \"production\"],\n});\n```\n\n## Resolve Cache\n\nTo speed up resolution, resolved values (and errors) are globally cached with a unique key based on id and options.\n\n**Example:** Invalidate all (global) cache entries (to support file-system changes).\n\n```ts\nimport { clearResolveCache } from \"exsolve\";\n\nclearResolveCache();\n```\n\n**Example:** Custom resolver with custom cache object.\n\n```ts\nimport { createResolver } from \"exsolve\";\n\nconst { clearResolveCache, resolveModulePath } = createResolver({\n  cache: new Map(),\n});\n```\n\n**Example:** Resolve without cache.\n\n```ts\nimport { resolveModulePath } from \"exsolve\";\n\nresolveModulePath(\"id\", { cache: false });\n```\n\n## Resolve Options\n\n### `try`\n\nIf set to `true` and the module cannot be resolved, the resolver returns `undefined` instead of throwing an error.\n\n**Example:**\n\n```ts\n// undefined\nconst resolved = resolveModuleURL(\"non-existing-package\", { try: true });\n```\n\n### `from`\n\nA URL, path, or array of URLs/paths from which to resolve the module.\n\nIf not provided, resolution starts from the current working directory. Setting this option is recommended.\n\nYou can use `import.meta.url` for `from` to mimic the behavior of `import.meta.resolve()`.\n\n> [!TIP]\n> For better performance, ensure the value is a `file://` URL or at least ends with `/`.\n>\n> If it is set to an absolute path, the resolver must first check the filesystem to see if it is a file or directory.\n> If the input is a `file://` URL or ends with `/`, the resolver can skip this check.\n\n### `conditions`\n\nConditions to apply when resolving package exports (default: `[\"node\", \"import\"]`).\n\n**Example:**\n\n```ts\n// \"/app/src/index.ts\"\nconst src = resolveModuleURL(\"pkg-name\", {\n  conditions: [\"deno\", \"node\", \"import\", \"production\"],\n});\n```\n\n> [!NOTE]\n> Conditions are applied **without order**. The order is determined by the `exports` field in `package.json`.\n\n### `extensions`\n\nAdditional file extensions to check as fallbacks.\n\n**Example:**\n\n```ts\n// \"/app/src/index.ts\"\nconst src = resolveModulePath(\"./src/index\", {\n  extensions: [\".mjs\", \".cjs\", \".js\", \".mts\", \".cts\", \".ts\", \".json\"],\n});\n```\n\n> [!TIP]\n> For better performance, use explicit extensions and avoid this option.\n\n### `suffixes`\n\nPath suffixes to check.\n\n**Example:**\n\n```ts\n// \"/app/src/utils/index.ts\"\nconst src = resolveModulePath(\"./src/utils\", {\n  suffixes: [\"\", \"/index\"],\n  extensions: [\".mjs\", \".cjs\", \".js\"],\n});\n```\n\n> [!TIP]\n> For better performance, use explicit `/index` when needed and avoid this option.\n\n### `cache`\n\nResolve cache (enabled by default with a shared global object).\n\nCan be set to `false` to disable or a custom `Map` to bring your own cache object.\n\nSee [cache](#resolve-cache) for more info.\n\n## Other Performance Tips\n\n**Use explicit module extensions `.mjs` or `.cjs` instead of `.js`:**\n\nThis allows the resolution fast path to skip reading the closest `package.json` for the [`type`](https://nodejs.org/api/packages.html#type).\n\n## Development\n\n<details>\n\n<summary>local development</summary>\n\n- Clone this repository\n- Install the latest LTS version of [Node.js](https://nodejs.org/en/)\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n</details>\n\n## License\n\nPublished under the [MIT](https://github.com/unjs/exsolve/blob/main/LICENSE) license.\n\nBased on previous work in [unjs/mlly](https://github.com/unjs/mlly), [wooorm/import-meta-resolve](https://github.com/wooorm/import-meta-resolve) and [Node.js](https://github.com/nodejs/node) original implementation.\n","publish_time":1791020218881,"_cnpm_publish_time":1791020218881,"dist-tags":{"latest":"1.2.0"}}