{"name":"exsolve","version":"1.0.7","license":"MIT","_id":"exsolve@1.0.7","maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"homepage":"https://github.com/unjs/exsolve#readme","bugs":{"url":"https://github.com/unjs/exsolve/issues"},"dist":{"shasum":"3b74e4c7ca5c5f9a19c3626ca857309fa99f9e9e","tarball":"http://registry-npm.ywwl.com/exsolve/download/exsolve-1.0.7.tgz","fileCount":5,"integrity":"sha512-VO5fQUzZtI6C+vx4w/4BWJpg3s/5l+6pRQEHzFRM8WFi4XffSP1Z+4qi7GbjWbvRQEbdIco5mIMq+zX4rPuLrw==","signatures":[{"sig":"MEYCIQCjr886kpedq83s1G8jGuX91FfRJT6bTQ+OuiNqtTDjPwIhAMPuaNpsSbnGi4OEx/g8W3fvZhU5fZmYGlBjIySHVc5D","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59615,"size":15666,"noattachment":false,"key":"/exsolve/-/exsolve-1.0.7.tgz"},"type":"module","types":"./dist/index.d.mts","exports":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"gitHead":"b031f768fc90d564dd1e1cf57d8d9d0373fa9014","scripts":{"dev":"vitest dev","lint":"eslint . && prettier -c .","test":"pnpm lint && pnpm test:types && vitest run --coverage","build":"unbuild","node-ts":"node --disable-warning=ExperimentalWarning --experimental-strip-types","prepack":"pnpm build","release":"pnpm test && changelogen --release && npm publish && git push --follow-tags","lint:fix":"automd && eslint . --fix && prettier -w .","test:types":"tsc --noEmit --skipLibCheck"},"_npmUser":{"name":"pi0","actor":{"name":"pi0","type":"user","email":"pyapar@gmail.com"},"email":"pyapar@gmail.com"},"repository":{"url":"git+https://github.com/unjs/exsolve.git","type":"git"},"_npmVersion":"10.9.2","description":"Module resolution utilities based on Node.js upstream implementation.","directories":{},"sideEffects":false,"_nodeVersion":"22.13.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.12.1","devDependencies":{"jiti":"^2.4.2","automd":"^0.4.0","eslint":"^9.29.0","vitest":"^3.2.4","unbuild":"^3.5.0","prettier":"^3.5.3","happy-dom":"^18.0.1","typescript":"^5.8.3","@types/node":"^24.0.3","changelogen":"^0.6.1","eslint-config-unjs":"^0.4.2","@vitest/coverage-v8":"^3.2.4"},"_npmOperationalInternal":{"tmp":"tmp/exsolve_1.0.7_1750411309123_0.6617920864760749","host":"s3://npm-registry-packages-npm-production"},"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":1750411309306,"_cnpm_publish_time":1750411309306,"dist-tags":{"latest":"1.2.0"}}