{"name":"exsolve","version":"0.4.0","license":"MIT","_id":"exsolve@0.4.0","maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"homepage":"https://github.com/unjs/exsolve#readme","bugs":{"url":"https://github.com/unjs/exsolve/issues"},"dist":{"shasum":"b969c13c1f12d3c14a3bf1fdce493b0a8eaacc4e","tarball":"http://registry-npm.ywwl.com/exsolve/download/exsolve-0.4.0.tgz","fileCount":5,"integrity":"sha512-z4qgr19noI181wWs/Bd1PM6Gaf3m5Y1RHDUVdbhft28yD2C0a/7HLhLWbphwOHx2RObWG9CkLHFmUbvFdOfj7w==","signatures":[{"sig":"MEUCIQDQFjY3QDLsWhQD7Pz01ludEcYaaVMzdUFnIP4XzNIgWQIgbFlAZl+s7CV1rShbEI7mJwkJOA6LNZT/5W7MUttwZDg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":57696,"size":15115,"noattachment":false,"key":"/exsolve/-/exsolve-0.4.0.tgz"},"type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"}},"gitHead":"c18fd2a84d2de67ef528dea28e57870c9621b3c0","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","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.14.0","_hasShrinkwrap":false,"packageManager":"pnpm@9.15.4","devDependencies":{"jiti":"^2.4.2","automd":"^0.3.12","eslint":"^9.21.0","vitest":"^3.0.6","unbuild":"^3.3.1","prettier":"^3.5.2","typescript":"^5.7.3","@types/node":"^22.13.5","changelogen":"^0.5.7","eslint-config-unjs":"^0.4.2","@vitest/coverage-v8":"^3.0.6"},"_npmOperationalInternal":{"tmp":"tmp/exsolve_0.4.0_1740500788850_0.6427724260390453","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":1740500789052,"_cnpm_publish_time":1740500789052,"dist-tags":{"latest":"1.2.0"}}