{"name":"unrs-resolver","version":"1.12.2","description":"UnRS Resolver Node API","homepage":"https://github.com/unrs/unrs-resolver","license":"MIT","repository":{"type":"git","url":"git+https://github.com/unrs/unrs-resolver.git"},"funding":{"url":"https://opencollective.com/unrs-resolver"},"main":"index.js","browser":"browser.js","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"scripts":{"postinstall":"node postinstall.js"},"dependencies":{"napi-postinstall":"^0.3.4"},"napi":{"binaryName":"resolver","packageName":"@unrs/resolver-binding","targets":["aarch64-apple-darwin","aarch64-linux-android","aarch64-pc-windows-msvc","aarch64-unknown-linux-gnu","aarch64-unknown-linux-musl","aarch64-unknown-linux-ohos","armv7-linux-androideabi","armv7-unknown-linux-gnueabihf","armv7-unknown-linux-musleabihf","i686-pc-windows-msvc","loongarch64-unknown-linux-gnu","loongarch64-unknown-linux-musl","powerpc64le-unknown-linux-gnu","riscv64gc-unknown-linux-gnu","riscv64gc-unknown-linux-musl","s390x-unknown-linux-gnu","wasm32-wasip1-threads","x86_64-apple-darwin","x86_64-pc-windows-msvc","x86_64-unknown-freebsd","x86_64-unknown-linux-gnu","x86_64-unknown-linux-musl"],"wasm":{"browser":{"fs":true}}},"optionalDependencies":{"@unrs/resolver-binding-darwin-arm64":"1.12.2","@unrs/resolver-binding-android-arm64":"1.12.2","@unrs/resolver-binding-win32-arm64-msvc":"1.12.2","@unrs/resolver-binding-linux-arm64-gnu":"1.12.2","@unrs/resolver-binding-linux-arm64-musl":"1.12.2","@unrs/resolver-binding-openharmony-arm64":"1.12.2","@unrs/resolver-binding-android-arm-eabi":"1.12.2","@unrs/resolver-binding-linux-arm-gnueabihf":"1.12.2","@unrs/resolver-binding-linux-arm-musleabihf":"1.12.2","@unrs/resolver-binding-win32-ia32-msvc":"1.12.2","@unrs/resolver-binding-linux-loong64-gnu":"1.12.2","@unrs/resolver-binding-linux-loong64-musl":"1.12.2","@unrs/resolver-binding-linux-ppc64-gnu":"1.12.2","@unrs/resolver-binding-linux-riscv64-gnu":"1.12.2","@unrs/resolver-binding-linux-riscv64-musl":"1.12.2","@unrs/resolver-binding-linux-s390x-gnu":"1.12.2","@unrs/resolver-binding-wasm32-wasi":"1.12.2","@unrs/resolver-binding-darwin-x64":"1.12.2","@unrs/resolver-binding-win32-x64-msvc":"1.12.2","@unrs/resolver-binding-freebsd-x64":"1.12.2","@unrs/resolver-binding-linux-x64-gnu":"1.12.2","@unrs/resolver-binding-linux-x64-musl":"1.12.2"},"gitHead":"ccb26d205e2938b16069c64a28996b48ee97ff94","types":"./index.d.ts","_id":"unrs-resolver@1.12.2","bugs":{"url":"https://github.com/unrs/unrs-resolver/issues"},"_nodeVersion":"22.22.3","_npmVersion":"11.14.1","dist":{"integrity":"sha512-dmlRxBJJayXjqTwC+JtF1HhJmgf3ftQ3YejFcZrf4+KKtJv0qDsK1pjqaaVjG7wJ5NJ6UVP1OqRMQ71Z4C3rxQ==","shasum":"a6c6888396abba5adaac4cab6587df866f1d7afd","tarball":"http://registry-npm.ywwl.com/unrs-resolver/download/unrs-resolver-1.12.2.tgz","fileCount":6,"unpackedSize":60433,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/unrs-resolver@1.12.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCzxMWJ6AdQyxrqQ5TdUTtBnnZcdChV4631dUTVXgdqcgIhALoPqTTVrQGZFWCoM93OHx8YQeZ5OqIN9tGzFIY/dKvO"}],"size":11371,"noattachment":false,"key":"/unrs-resolver/-/unrs-resolver-1.12.2.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:b3f81ddc-f969-4c6e-964a-f6440e1294f6"}},"directories":{},"maintainers":[{"name":"jounqin","email":"admin@1stg.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/unrs-resolver_1.12.2_1779194004932_0.7718515257107177"},"_hasShrinkwrap":false,"readme":"<div align=\"center\">\n\n[![Crates.io][crates-badge]][crates-url]\n[![npmjs.com][npm-badge]][npm-url]\n\n[![Docs.rs][docs-badge]][docs-url]\n[![Build Status][ci-badge]][ci-url]\n[![Code Coverage][code-coverage-badge]][code-coverage-url]\n[![CodSpeed Badge][codspeed-badge]][codspeed-url]\n[![Sponsors][sponsors-badge]][sponsors-url]\n[![MIT licensed][license-badge]][license-url]\n\n</div>\n\n# UnRS Resolver\n\nRust port of [enhanced-resolve], [tsconfig-paths-webpack-plugin] and [tsconfck]\n\n- Released on [crates.io][crates-url] and [npm][npm-url].\n- Implements the [ESM](https://nodejs.org/api/esm.html#resolution-algorithm) and [CommonJS](https://nodejs.org/api/modules.html#all-together) module resolution algorithm specification.\n- Built-in [tsconfig-paths-webpack-plugin]\n  - support extending tsconfig defined in `tsconfig.extends`\n  - support paths alias defined in `tsconfig.compilerOptions.paths`\n  - support project references defined `tsconfig.references`\n  - support [template variable ${configDir} for substitution of config files directory path](https://github.com/microsoft/TypeScript/pull/58042)\n- Built-in tsconfig discovery ([tsconfck])\n- Supports in-memory file system via the `FileSystem` trait.\n- Contains `tracing` instrumentation.\n\n## Usage\n\n### npm package\n\nSee `index.d.ts` for `resolveSync` and `ResolverFactory` API.\n\nQuick example:\n\n```javascript\nimport assert from \"node:assert\";\nimport path from \"node:path\";\n\nimport resolve, { ResolverFactory } from \"unrs-resolver\";\n\n// `resolve`\nassert(resolve.sync(process.cwd(), \"./index.js\").path, path.resolve(\"index.js\"));\n\n// `ResolverFactory`\nconst resolver = new ResolverFactory();\nassert(resolver.sync(process.cwd(), \"./index.js\").path, path.resolve(\"index.js\"));\n```\n\n#### File-based Resolution\n\nFor file-based resolution with automatic tsconfig discovery, use `resolveFileSync` or `resolveFileAsync`:\n\n```javascript\nconst resolver = new ResolverFactory();\n\n// Resolves from a file path (not directory)\nconst result = resolver.resolveFileSync(\"/path/to/file.ts\", \"./module\");\n\n// Async version\nconst result = await resolver.resolveFileAsync(\"/path/to/file.ts\", \"./module\");\n```\n\n**Key Differences:**\n\n- `sync(directory, specifier)` - Takes a **directory path**, uses manually configured tsconfig if provided\n- `resolveFileSync(file, specifier)` - Takes a **file path**, automatically discovers tsconfig.json by traversing parent directories\n\n**Why use `resolveFileSync`?**\n\nWhen resolving from a specific file (e.g., in bundlers, linters, or language servers), `resolveFileSync` automatically finds the correct `tsconfig.json` by:\n\n- Traversing parent directories from the file location\n- Respecting TypeScript project references\n- Honoring `include`, `exclude`, and `files` fields to determine which tsconfig applies\n- Ensuring tsconfig `paths` aliases work correctly based on the file's context\n\n#### Supports WASM\n\nSee https://stackblitz.com/edit/unrs-resolver for usage example.\n\n### Rust\n\nSee [docs.rs/unrs_resolver](https://docs.rs/unrs_resolver/latest/unrs_resolver/).\n\n### [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp)\n\n- For node.js, yarn pnp should work without any configuration, given the following conditions:\n  - the program is called with the `yarn` command, where the value [`process.versions.pnp`](https://yarnpkg.com/advanced/pnpapi#processversionspnp) is set.\n  - `.pnp.cjs` manifest file exists in the closest directory, searched from the current working directory,\n  - no multi-project setup, per second bullet point in [FIND_PNP_MANIFEST](https://yarnpkg.com/advanced/pnp-spec#find_pnp_manifest)\n\n## Terminology\n\n### `directory`\n\nAn **absolute** path to a directory where the specifier is resolved against.\n\nFor CommonJS modules, it is the `__dirname` variable that contains the absolute path to the folder containing current module.\n\nFor ECMAScript modules, it is the value of `import.meta.dirname`.\n\nBehavior is undefined when given a path to a file.\n\n### `specifier`\n\nThe string passed to `require` or `import`, i.e. `require(\"specifier\")` or `import \"specifier\"`\n\n## Errors and Trouble Shooting\n\n- `Error: Package subpath '.' is not defined by \"exports\" in` - occurs when resolving without `conditionNames`.\n\n## Configuration\n\nThe following usages apply to both Rust and Node.js; the code snippets are written in JavaScript.\n\nTo handle the `exports` field in `package.json`, ESM and CJS need to be differentiated.\n\n### ESM\n\nPer [ESM Resolution algorithm](https://nodejs.org/api/esm.html#resolution-and-loading-algorithm)\n\n> defaultConditions is the conditional environment name array, [\"node\", \"import\"].\n\nThis means when the caller is an ESM import (`import \"module\"`), resolve options should be\n\n```javascript\n{\n  \"conditionNames\": [\"node\", \"import\"]\n}\n```\n\n### CJS\n\nPer [CJS Resolution algorithm](https://nodejs.org/api/modules.html#all-together)\n\n> LOAD_PACKAGE_EXPORTS(X, DIR)\n>\n> 5. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(DIR/NAME), \".\" + SUBPATH,\n>    `package.json` \"exports\", [\"node\", \"require\"]) defined in the ESM resolver.\n\nThis means when the caller is a CJS require (`require(\"module\")`), resolve options should be\n\n```javascript\n{\n  \"conditionNames\": [\"node\", \"require\"]\n}\n```\n\n### Cache\n\nTo support both CJS and ESM with the same cache:\n\n```javascript\nconst esmResolver = new ResolverFactory({\n  conditionNames: [\"node\", \"import\"],\n});\n\nconst cjsResolver = esmResolver.cloneWithOptions({\n  conditionNames: [\"node\", \"require\"],\n});\n```\n\n### Browser Field\n\nFrom this [non-standard spec](https://github.com/defunctzombie/package-browser-field-spec):\n\n> The `browser` field is provided to JavaScript bundlers or component tools when packaging modules for client side use.\n\nThe option is\n\n```javascript\n{\n  \"aliasFields\": [\"browser\"]\n}\n```\n\n### Main Field\n\n```javascript\n{\n  \"mainFields\": [\"module\", \"main\"]\n}\n```\n\nQuoting esbuild's documentation:\n\n- `main` - This is [the standard field](https://docs.npmjs.com/files/package.json#main) for all packages that are meant to be used with node. The name main is hard-coded in to node's module resolution logic itself. Because it's intended for use with node, it's reasonable to expect that the file path in this field is a CommonJS-style module.\n- `module` - This field came from a [proposal](https://github.com/dherman/defense-of-dot-js/blob/f31319be735b21739756b87d551f6711bd7aa283/proposal.md) for how to integrate ECMAScript modules into node. Because of this, it's reasonable to expect that the file path in this field is an ECMAScript-style module. This proposal wasn't adopted by node (node uses \"type\": \"module\" instead) but it was adopted by major bundlers because ECMAScript-style modules lead to better tree shaking, or dead code removal.\n- `browser` - This field came from a [proposal](https://gist.github.com/defunctzombie/4339901/49493836fb873ddaa4b8a7aa0ef2352119f69211) that allows bundlers to replace node-specific files or modules with their browser-friendly versions. It lets you specify an alternate browser-specific entry point. Note that it is possible for a package to use both the browser and module field together (see the note below).\n\n## Options\n\nThe following options are aligned with [enhanced-resolve], and is implemented for Rust crate usage.\n\nSee [index.d.ts](https://github.com/unrs/unrs-resolver/blob/main/napi/index.d.ts) for Node.js usage.\n\n| Field                                 | Default                   | Description                                                                                                                                               |\n| ------------------------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| alias                                 | {}                        | A hash map of module alias configurations                                                                                                                 |\n| aliasFields                           | []                        | A list of alias fields in description files                                                                                                               |\n| extensionAlias                        | {}                        | An object which maps extension to extension aliases                                                                                                       |\n| conditionNames                        | []                        | A list of exports field condition names                                                                                                                   |\n| enforceExtension                      | false                     | Enforce that an extension from extensions must be used                                                                                                    |\n| exportsFields                         | [\"exports\"]               | A list of exports fields in description files                                                                                                             |\n| extensions                            | [\".js\", \".json\", \".node\"] | A list of extensions which should be tried for files                                                                                                      |\n| fallback                              | {}                        | Same as `alias`, but only used if default resolving fails                                                                                                 |\n| fileSystem                            |                           | The file system which should be used                                                                                                                      |\n| fullySpecified                        | false                     | Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests) |\n| mainFields                            | [\"main\"]                  | A list of main fields in description files                                                                                                                |\n| mainFiles                             | [\"index\"]                 | A list of main files in directories                                                                                                                       |\n| modules                               | [\"node_modules\"]          | A list of directories to resolve modules from, can be absolute path or folder name. Absolute `NODE_PATH` entries are appended automatically when set.     |\n| resolveToContext                      | false                     | Resolve to a context instead of a file                                                                                                                    |\n| preferRelative                        | false                     | Prefer to resolve module requests as relative request and fallback to resolving as module                                                                 |\n| preferAbsolute                        | false                     | Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots                                                          |\n| restrictions                          | []                        | A list of resolve restrictions                                                                                                                            |\n| roots                                 | []                        | A list of root paths                                                                                                                                      |\n| symlinks                              | true                      | Whether to resolve symlinks to their symlinked location                                                                                                   |\n| allowPackageExportsInDirectoryResolve | false                     | Allow `exports` field in `require('../directory')`. Not part of `enhanced-resolve`.                                                                       |\n\n### TypeScript Configuration\n\n| Field               | Default | Description                                                                                                                                                                          |\n| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| tsconfig            | None    | TypeScript related config for resolver                                                                                                                                               |\n| tsconfig.configFile |         | A relative path to the tsconfig file based on `cwd`, or an absolute path to the tsconfig file.                                                                                       |\n| tsconfig.references | `[]`    | - 'auto': inherits from TypeScript config <br/> - `string []`: relative path (based on directory of the referencing tsconfig file) or absolute path of referenced project's tsconfig |\n\n### Unimplemented Options\n\n| Field            | Default                     | Description                                                                                                                                   |\n| ---------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |\n| descriptionFiles | [\"package.json\"]            | A list of description files to read from                                                                                                      |\n| cachePredicate   | function() { return true }; | A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties. |\n| cacheWithContext | true                        | If unsafe cache is enabled, includes `request.context` in the cache key                                                                       |\n| plugins          | []                          | A list of additional resolve plugins which should be applied                                                                                  |\n| resolver         | undefined                   | A prepared Resolver to which the plugins are attached                                                                                         |\n| unsafeCache      | false                       | Use this cache object to unsafely cache the successful requests                                                                               |\n\n## Debugging\n\nThe following environment variable emits tracing information for the `unrs_resolver::resolve` function.\n\ne.g.\n\n```\n2024-06-11T07:12:20.003537Z DEBUG unrs_resolver: options: ResolveOptions { ... }, path: \"...\", specifier: \"...\", ret: \"...\"\n    at /path/to/unrs_resolver-1.8.1/src/lib.rs:212\n    in unrs_resolver::resolve with path: \"...\", specifier: \"...\"\n```\n\nThe input values are `options`, `path` and `specifier`, the returned value is `ret`.\n\n### NAPI\n\n```\nUNRS_LOG=DEBUG your_program\n```\n\n## Test\n\nTests are ported from\n\n- [enhanced-resolve](https://github.com/webpack/enhanced-resolve/tree/main/test)\n- [tsconfig-path](https://github.com/dividab/tsconfig-paths/blob/master/src/__tests__/data/match-path-data.ts) and [parcel-resolver](https://github.com/parcel-bundler/parcel/tree/v2/packages/utils/node-resolver-core/test/fixture/tsconfig) for tsconfig-paths\n\nTest cases are located in `./src/tests`, fixtures are located in `./tests`\n\n- [x] alias.test.js\n- [x] browserField.test.js\n- [x] dependencies.test.js\n- [x] exportsField.test.js\n- [x] extension-alias.test.js\n- [x] extensions.test.js\n- [x] fallback.test.js\n- [x] fullSpecified.test.js\n- [x] identifier.test.js (see unit test in `crates/unrs_resolver/src/request.rs`)\n- [x] importsField.test.js\n- [x] incorrect-description-file.test.js (need to add ctx.fileDependencies)\n- [x] missing.test.js\n- [x] path.test.js (see unit test in `crates/unrs_resolver/src/path.rs`)\n- [ ] plugins.test.js\n- [ ] pnp.test.js\n- [x] resolve.test.js\n- [x] restrictions.test.js (partially done, regex is not supported yet)\n- [x] roots.test.js\n- [x] scoped-packages.test.js\n- [x] simple.test.js\n- [x] symlink.test.js\n\nIrrelevant tests\n\n- CachedInputFileSystem.test.js\n- SyncAsyncFileSystemDecorator.test.js\n- forEachBail.test.js\n- getPaths.test.js\n- pr-53.test.js\n- unsafe-cache.test.js\n- yield.test.js\n\n## [Sponsored By](https://github.com/sponsors/JounQin)\n\n[![Sponsors](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)\n\n### Sponsors\n\n| 1stG                                                                                                                               | UnRs                                                                                                                               | UnTS                                                                                                                               |\n| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |\n| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/organizations.svg)](https://opencollective.com/1stG) | [![UnRs Open Collective backers and sponsors](https://opencollective.com/unrs/organizations.svg)](https://opencollective.com/unrs) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/organizations.svg)](https://opencollective.com/unts) |\n\n### Backers\n\n| 1stG                                                                                                                             | UnRs                                                                                                                             | UnTS                                                                                                                             |\n| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |\n| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![UnRs Open Collective backers and sponsors](https://opencollective.com/unrs/individuals.svg)](https://opencollective.com/unrs) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |\n\n## 📖 License\n\n`unrs_resolver` is free and open-source software licensed under the [MIT License](./LICENSE).\n\nUnRS partially copies code from the following projects.\n\n| Project                                                                   | License                                                                         |\n| ------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |\n| [webpack/enhanced-resolve](https://github.com/webpack/enhanced-resolve)   | [MIT](https://github.com/webpack/enhanced-resolve/blob/main/LICENSE)            |\n| [dividab/tsconfig-paths](https://github.com/dividab/tsconfig-paths)       | [MIT](https://github.com/dividab/tsconfig-paths/blob/master/LICENSE)            |\n| [parcel-bundler/parcel](https://github.com/parcel-bundler/parcel)         | [MIT](https://github.com/parcel-bundler/parcel/blob/v2/LICENSE)                 |\n| [tmccombs/json-comments-rs](https://github.com/tmccombs/json-comments-rs) | [Apache 2.0](https://github.com/tmccombs/json-comments-rs/blob/main/LICENSE)    |\n| [dominikg/tsconfck](https://github.com/dominikg/tsconfck)                 | [MIT](https://github.com/dominikg/tsconfck/blob/main/packages/tsconfck/LICENSE) |\n\n[enhanced-resolve]: https://github.com/webpack/enhanced-resolve\n[tsconfig-paths-webpack-plugin]: https://github.com/dividab/tsconfig-paths-webpack-plugin\n[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[license-url]: https://github.com/unrs/unrs-resolver/blob/main/LICENSE\n[ci-badge]: https://github.com/unrs/unrs-resolver/actions/workflows/ci.yml/badge.svg?event=push&branch=main\n[ci-url]: https://github.com/unrs/unrs-resolver/actions/workflows/ci.yml?query=event%3Apush+branch%3Amain\n[code-coverage-badge]: https://codecov.io/github/unrs/unrs-resolver/branch/main/graph/badge.svg\n[code-coverage-url]: https://codecov.io/gh/unrs/unrs-resolver\n[sponsors-badge]: https://img.shields.io/github/sponsors/JounQin\n[sponsors-url]: https://github.com/sponsors/JounQin\n[codspeed-badge]: https://img.shields.io/endpoint?url=https://codspeed.io/badge.json\n[codspeed-url]: https://codspeed.io/unrs/unrs-resolver\n[crates-badge]: https://img.shields.io/crates/dr/unrs_resolver\n[crates-url]: https://crates.io/crates/unrs_resolver\n[docs-badge]: https://img.shields.io/docsrs/unrs_resolver\n[docs-url]: https://docs.rs/unrs_resolver/latest/unrs_resolver/\n[npm-badge]: https://img.shields.io/npm/dw/unrs-resolver?label=npm\n[npm-url]: https://npmx.dev/package/unrs-resolver\n[tsconfck]: https://github.com/dominikg/tsconfck\n","publish_time":1779194005064,"_cnpm_publish_time":1779194005064,"dist-tags":{"latest":"1.13.0"}}