{"id":13475106,"url":"https://github.com/lukeed/resolve.exports","last_synced_at":"2025-10-09T18:23:31.335Z","repository":{"id":40623749,"uuid":"328019253","full_name":"lukeed/resolve.exports","owner":"lukeed","description":"A tiny (952b), correct, general-purpose, and configurable `\"exports\"` and `\"imports\"` resolver without file-system reliance","archived":false,"fork":false,"pushed_at":"2024-12-02T16:31:17.000Z","size":106,"stargazers_count":395,"open_issues_count":12,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-10-06T11:31:10.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"lukeed"}},"created_at":"2021-01-08T21:46:01.000Z","updated_at":"2025-10-01T09:36:26.000Z","dependencies_parsed_at":"2024-01-16T07:23:08.244Z","dependency_job_id":"80b15bd0-f42b-41ae-b4c5-0a6c97f5a15e","html_url":"https://github.com/lukeed/resolve.exports","commit_stats":{"total_commits":90,"total_committers":7,"mean_commits":"12.857142857142858","dds":0.06666666666666665,"last_synced_commit":"294192309b7276bc0913f65a7ee73721611ae383"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/lukeed/resolve.exports","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fresolve.exports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fresolve.exports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fresolve.exports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fresolve.exports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/resolve.exports/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fresolve.exports/sbom","scorecard":{"id":604518,"data":{"date":"2025-08-11","repo":{"name":"github.com/lukeed/resolve.exports","commit":"6613167c0b4fc1511fc52171f4f52cb030c928c3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.6,"checks":[{"name":"Code-Review","score":2,"reason":"Found 3/12 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/resolve.exports/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/resolve.exports/ci.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:35","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:46","Warn: downloadThenRun not pinned by hash: .github/workflows/ci.yml:57","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 npmCommand dependencies pinned","Info:   0 out of   1 downloadThenRun dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 23 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T01:16:15.665Z","repository_id":40623749,"created_at":"2025-08-21T01:16:15.665Z","updated_at":"2025-08-21T01:16:15.665Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278621846,"owners_count":26017253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:01:17.411Z","updated_at":"2025-10-09T18:23:31.319Z","avatar_url":"https://github.com/lukeed.png","language":"TypeScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["TypeScript"],"sub_categories":[],"readme":"# resolve.exports [![CI](https://github.com/lukeed/resolve.exports/workflows/CI/badge.svg)](https://github.com/lukeed/resolve.exports/actions) [![licenses](https://licenses.dev/b/npm/resolve.exports)](https://licenses.dev/npm/resolve.exports) [![codecov](https://codecov.io/gh/lukeed/resolve.exports/branch/master/graph/badge.svg?token=4P7d4Omw2h)](https://codecov.io/gh/lukeed/resolve.exports)\n\n\u003e A tiny (952b), correct, general-purpose, and configurable `\"exports\"` and `\"imports\"` resolver without file-system reliance\n\n***Why?***\n\nHopefully, this module may serve as a reference point (and/or be used directly) so that the varying tools and bundlers within the ecosystem can share a common approach with one another **as well as** with the native Node.js implementation.\n\nWith the push for ESM, we must be _very_ careful and avoid fragmentation. If we, as a community, begin propagating different _dialects_ of the resolution algorithm, then we're headed for deep trouble. It will make supporting (and using) `\"exports\"` nearly impossible, which may force its abandonment and along with it, its benefits.\n\nLet's have nice things.\n\n## Install\n\n```sh\n$ npm install resolve.exports\n```\n\n## Usage\n\n\u003e Please see [`/test/`](/test) for examples.\n\n```js\nimport * as resolve from 'resolve.exports';\n\n// package.json contents\nconst pkg = {\n  \"name\": \"foobar\",\n  \"module\": \"dist/module.mjs\",\n  \"main\": \"dist/require.js\",\n  \"imports\": {\n    \"#hash\": {\n      \"import\": {\n        \"browser\": \"./hash/web.mjs\",\n        \"node\": \"./hash/node.mjs\",\n      },\n      \"default\": \"./hash/detect.js\"\n    }\n  },\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/module.mjs\",\n      \"require\": \"./dist/require.js\"\n    },\n    \"./lite\": {\n      \"worker\": {\n        \"browser\": \"./lite/worker.browser.js\",\n        \"node\": \"./lite/worker.node.js\"\n      },\n      \"import\": \"./lite/module.mjs\",\n      \"require\": \"./lite/require.js\"\n    }\n  }\n};\n\n// ---\n// Exports\n// ---\n\n// entry: \"foobar\" === \".\" === default\n// conditions: [\"default\", \"import\", \"node\"]\nresolve.exports(pkg);\nresolve.exports(pkg, '.');\nresolve.exports(pkg, 'foobar');\n//=\u003e [\"./dist/module.mjs\"]\n\n// entry: \"foobar/lite\" === \"./lite\"\n// conditions: [\"default\", \"import\", \"node\"]\nresolve.exports(pkg, 'foobar/lite');\nresolve.exports(pkg, './lite');\n//=\u003e [\"./lite/module.mjs\"]\n\n// Enable `require` condition\n// conditions: [\"default\", \"require\", \"node\"]\nresolve.exports(pkg, 'foobar', { require: true }); //=\u003e [\"./dist/require.js\"]\nresolve.exports(pkg, './lite', { require: true }); //=\u003e [\"./lite/require.js\"]\n\n// Throws \"Missing \u003centry\u003e specifier in \u003cname\u003e package\" Error\nresolve.exports(pkg, 'foobar/hello');\nresolve.exports(pkg, './hello/world');\n\n// Add custom condition(s)\n// conditions: [\"default\", \"worker\", \"import\", \"node\"]\nresolve.exports(pkg, 'foobar/lite', {\n  conditions: ['worker']\n}); //=\u003e [\"./lite/worker.node.js\"]\n\n// Toggle \"browser\" condition\n// conditions: [\"default\", \"worker\", \"import\", \"browser\"]\nresolve.exports(pkg, 'foobar/lite', {\n  conditions: ['worker'],\n  browser: true\n}); //=\u003e [\"./lite/worker.browser.js\"]\n\n// Disable non-\"default\" condition activate\n// NOTE: breaks from Node.js default behavior\n// conditions: [\"default\", \"custom\"]\nresolve.exports(pkg, 'foobar/lite', {\n  conditions: ['custom'],\n  unsafe: true,\n});\n//=\u003e Error: No known conditions for \"./lite\" specifier in \"foobar\" package\n\n// ---\n// Imports\n// ---\n\n// conditions: [\"default\", \"import\", \"node\"]\nresolve.imports(pkg, '#hash');\nresolve.imports(pkg, 'foobar/#hash');\n//=\u003e [\"./hash/node.mjs\"]\n\n// conditions: [\"default\", \"import\", \"browser\"]\nresolve.imports(pkg, '#hash', { browser: true });\nresolve.imports(pkg, 'foobar/#hash');\n//=\u003e [\"./hash/web.mjs\"]\n\n// conditions: [\"default\"]\nresolve.imports(pkg, '#hash', { unsafe: true });\nresolve.imports(pkg, 'foobar/#hash');\n//=\u003e [\"./hash/detect.mjs\"]\n\nresolve.imports(pkg, '#hello/world');\nresolve.imports(pkg, 'foobar/#hello/world');\n//=\u003e Error: Missing \"#hello/world\" specifier in \"foobar\" package\n\n// ---\n// Legacy\n// ---\n\n// prefer \"module\" \u003e \"main\" (default)\nresolve.legacy(pkg); //=\u003e \"dist/module.mjs\"\n\n// customize fields order\nresolve.legacy(pkg, {\n  fields: ['main', 'module']\n}); //=\u003e \"dist/require.js\"\n```\n\n## API\n\nThe [`resolve()`](#resolvepkg-entry-options), [`exports()`](#exportspkg-entry-options), and [`imports()`](#importspkg-target-options) functions share similar API signatures:\n\n```ts\nexport function resolve(pkg: Package, entry?: string, options?: Options): string[] | undefined;\nexport function exports(pkg: Package, entry?: string, options?: Options): string[] | undefined;\nexport function imports(pkg: Package, target: string, options?: Options): string[] | undefined;\n//                                         ^ not optional!\n```\n\nAll three:\n* accept a `package.json` file's contents as a JSON object\n* accept a target/entry identifier\n* may accept an [Options](#options) object\n* return `string[]`, `string`, or `undefined`\n\nThe only difference is that `imports()` must accept a target identifier as there can be no inferred default.\n\nSee below for further API descriptions.\n\n\u003e **Note:** There is also a [Legacy Resolver API](#legacy-resolver)\n\n---\n\n### resolve(pkg, entry?, options?)\nReturns: `string[]` or `undefined`\n\nA convenience helper which automatically reroutes to [`exports()`](#exportspkg-entry-options) or [`imports()`](#importspkg-target-options) depending on the `entry` value.\n\nWhen unspecified, `entry` defaults to the `\".\"` identifier, which means that `exports()` will be invoked.\n\n```js\nimport * as r from 'resolve.exports';\n\nlet pkg = {\n  name: 'foobar',\n  // ...\n};\n\nr.resolve(pkg);\n//~\u003e r.exports(pkg, '.');\n\nr.resolve(pkg, 'foobar');\n//~\u003e r.exports(pkg, '.');\n\nr.resolve(pkg, 'foobar/subpath');\n//~\u003e r.exports(pkg, './subpath');\n\nr.resolve(pkg, '#hash/md5');\n//~\u003e r.imports(pkg, '#hash/md5');\n\nr.resolve(pkg, 'foobar/#hash/md5');\n//~\u003e r.imports(pkg, '#hash/md5');\n```\n\n### exports(pkg, entry?, options?)\nReturns: `string[]` or `undefined`\n\nTraverse the `\"exports\"` within the contents of a `package.json` file. \u003cbr\u003e\nIf the contents _does not_ contain an `\"exports\"` map, then `undefined` will be returned.\n\nSuccessful resolutions will always result in a `string` or `string[]` value. This will be the value of the resolved mapping itself – which means that the output is a relative file path.\n\nThis function may throw an Error if:\n\n* the requested `entry` cannot be resolved (aka, not defined in the `\"exports\"` map)\n* an `entry` _is_ defined but no known conditions were matched (see [`options.conditions`](#optionsconditions))\n\n#### pkg\nType: `object` \u003cbr\u003e\nRequired: `true`\n\nThe `package.json` contents.\n\n#### entry\nType: `string` \u003cbr\u003e\nRequired: `false` \u003cbr\u003e\nDefault: `.` (aka, root)\n\nThe desired target entry, or the original `import` path.\n\nWhen `entry` _is not_ a relative path (aka, does not start with `'.'`), then `entry` is given the `'./'` prefix.\n\nWhen `entry` begins with the package name (determined via the `pkg.name` value), then `entry` is truncated and made relative.\n\nWhen `entry` is already relative, it is accepted as is.\n\n***Examples***\n\nAssume we have a module named \"foobar\" and whose `pkg` contains `\"name\": \"foobar\"`.\n\n| `entry` value | treated as | reason |\n|-|-|-|\n| `null` / `undefined` | `'.'` | default |\n| `'.'` | `'.'` | value was relative |\n| `'foobar'` | `'.'` | value was `pkg.name` |\n| `'foobar/lite'` | `'./lite'` | value had `pkg.name` prefix |\n| `'./lite'` | `'./lite'` | value was relative |\n| `'lite'` | `'./lite'` | value was not relative \u0026 did not have `pkg.name` prefix |\n\n\n### imports(pkg, target, options?)\nReturns: `string[]` or `undefined`\n\nTraverse the `\"imports\"` within the contents of a `package.json` file. \u003cbr\u003e\nIf the contents _does not_ contain an `\"imports\"` map, then `undefined` will be returned.\n\nSuccessful resolutions will always result in a `string` or `string[]` value. This will be the value of the resolved mapping itself – which means that the output is a relative file path.\n\nThis function may throw an Error if:\n\n* the requested `target` cannot be resolved (aka, not defined in the `\"imports\"` map)\n* an `target` _is_ defined but no known conditions were matched (see [`options.conditions`](#optionsconditions))\n\n#### pkg\nType: `object` \u003cbr\u003e\nRequired: `true`\n\nThe `package.json` contents.\n\n#### target\nType: `string` \u003cbr\u003e\nRequired: `true`\n\nThe target import identifier; for example, `#hash` or `#hash/md5`.\n\nImport specifiers _must_ begin with the `#` character, as required by the resolution specification. However, if `target` begins with the package name (determined by the `pkg.name` value), then `resolve.exports` will trim it from the `target` identifier. For example, `\"foobar/#hash/md5\"` will be treated as `\"#hash/md5\"` for the `\"foobar\"` package.\n\n## Options\n\nThe [`resolve()`](#resolvepkg-entry-options), [`imports()`](#importspkg-target-options), and [`exports()`](#exportspkg-entry-options) functions share these options. All properties are optional and you are not required to pass an `options` argument.\n\nCollectively, the `options` are used to assemble a list of [conditions](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports) that should be activated while resolving your target(s).\n\n\u003e **Note:** Although the Node.js documentation primarily showcases conditions alongside `\"exports\"` usage, they also apply to `\"imports\"` maps too. _([example](https://nodejs.org/docs/latest-v18.x/api/packages.html#subpath-imports))_\n\n#### options.require\nType: `boolean` \u003cbr\u003e\nDefault: `false`\n\nWhen truthy, the `\"require\"` field is added to the list of allowed/known conditions. \u003cbr\u003e\nOtherwise the `\"import\"` field is added instead.\n\n#### options.browser\nType: `boolean` \u003cbr\u003e\nDefault: `false`\n\nWhen truthy, the `\"browser\"` field is added to the list of allowed/known conditions. \u003cbr\u003e\nOtherwise the `\"node\"` field is added instead.\n\n#### options.conditions\nType: `string[]` \u003cbr\u003e\nDefault: `[]`\n\nA list of additional/custom conditions that should be accepted when seen.\n\n\u003e **Important:** The order specified within `options.conditions` does not matter. \u003cbr\u003eThe matching order/priority is **always** determined by the `\"exports\"` map's key order.\n\nFor example, you may choose to accept a `\"production\"` condition in certain environments. Given the following `pkg` content:\n\n```js\nconst pkg = {\n  // package.json ...\n  \"exports\": {\n    \"worker\": \"./$worker.js\",\n    \"require\": \"./$require.js\",\n    \"production\": \"./$production.js\",\n    \"import\": \"./$import.mjs\",\n  }\n};\n\nresolve.exports(pkg, '.');\n// Conditions: [\"default\", \"import\", \"node\"]\n//=\u003e [\"./$import.mjs\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production']\n});\n// Conditions: [\"default\", \"production\", \"import\", \"node\"]\n//=\u003e [\"./$production.js\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production'],\n  require: true,\n});\n// Conditions: [\"default\", \"production\", \"require\", \"node\"]\n//=\u003e [\"./$require.js\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production', 'worker'],\n  require: true,\n});\n// Conditions: [\"default\", \"production\", \"worker\", \"require\", \"node\"]\n//=\u003e [\"./$worker.js\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production', 'worker']\n});\n// Conditions: [\"default\", \"production\", \"worker\", \"import\", \"node\"]\n//=\u003e [\"./$worker.js\"]\n```\n\n#### options.unsafe\nType: `boolean` \u003cbr\u003e\nDefault: `false`\n\n\u003e **Important:** You probably do not want this option! \u003cbr\u003eIt will break out of Node's default resolution conditions.\n\nWhen enabled, this option will ignore **all other options** except [`options.conditions`](#optionsconditions). This is because, when enabled, `options.unsafe` **does not** assume or provide any default conditions except the `\"default\"` condition.\n\n```js\nresolve.exports(pkg, '.');\n//=\u003e Conditions: [\"default\", \"import\", \"node\"]\n\nresolve.exports(pkg, '.', { unsafe: true });\n//=\u003e Conditions: [\"default\"]\n\nresolve.exports(pkg, '.', { unsafe: true, require: true, browser: true });\n//=\u003e Conditions: [\"default\"]\n```\n\nIn other words, this means that trying to use `options.require` or `options.browser` alongside `options.unsafe` will have no effect. In order to enable these conditions, you must provide them manually into the `options.conditions` list:\n\n```js\nresolve.exports(pkg, '.', {\n  unsafe: true,\n  conditions: [\"require\"]\n});\n//=\u003e Conditions: [\"default\", \"require\"]\n\nresolve.exports(pkg, '.', {\n  unsafe: true,\n  conditions: [\"browser\", \"require\", \"custom123\"]\n});\n//=\u003e Conditions: [\"default\", \"browser\", \"require\", \"custom123\"]\n```\n\n## Legacy Resolver\n\nAlso included is a \"legacy\" method for resolving non-`\"exports\"` package fields. This may be used as a fallback method when for when no `\"exports\"` mapping is defined. In other words, it's completely optional (and tree-shakeable).\n\n### legacy(pkg, options?)\nReturns: `string` or `undefined`\n\nYou may customize the field priority via [`options.fields`](#optionsfields).\n\nWhen a field is found, its value is returned _as written_. \u003cbr\u003e\nWhen no fields were found, `undefined` is returned. If you wish to mimic Node.js behavior, you can assume this means `'index.js'` – but this module does not make that assumption for you.\n\n#### options.browser\nType: `boolean` or `string` \u003cbr\u003e\nDefault: `false`\n\nWhen truthy, ensures that the `'browser'` field is part of the acceptable `fields` list.\n\n\u003e **Important:** If your custom [`options.fields`](#optionsfields) value includes `'browser'`, then _your_ order is respected. \u003cbr\u003eOtherwise, when truthy, `options.browser` will move `'browser'` to the front of the list, making it the top priority.\n\nWhen `true` and `\"browser\"` is an object, then `legacy()` will return the the entire `\"browser\"` object.\n\nYou may also pass a string value, which will be treated as an import/file path. When this is the case and `\"browser\"` is an object, then `legacy()` may return:\n\n* `false` – if the package author decided a file should be ignored; or\n* your `options.browser` string value – but made relative, if not already\n\n\u003e See the [`\"browser\" field specification](https://github.com/defunctzombie/package-browser-field-spec) for more information.\n\n#### options.fields\nType: `string[]` \u003cbr\u003e\nDefault: `['module', 'main']`\n\nA list of fields to accept. The order of the array determines the priority/importance of each field, with the most important fields at the beginning of the list.\n\nBy default, the `legacy()` method will accept any `\"module\"` and/or \"main\" fields if they are defined. However, if both fields are defined, then \"module\" will be returned.\n\n```js\nimport { legacy } from 'resolve.exports';\n\n// package.json\nconst pkg = {\n  \"name\": \"...\",\n  \"worker\": \"worker.js\",\n  \"module\": \"module.mjs\",\n  \"browser\": \"browser.js\",\n  \"main\": \"main.js\",\n};\n\nlegacy(pkg);\n// fields = [module, main]\n//=\u003e \"module.mjs\"\n\nlegacy(pkg, { browser: true });\n// fields = [browser, module, main]\n//=\u003e \"browser.mjs\"\n\nlegacy(pkg, {\n  fields: ['missing', 'worker', 'module', 'main']\n});\n// fields = [missing, worker, module, main]\n//=\u003e \"worker.js\"\n\nlegacy(pkg, {\n  fields: ['missing', 'worker', 'module', 'main'],\n  browser: true,\n});\n// fields = [browser, missing, worker, module, main]\n//=\u003e \"browser.js\"\n\nlegacy(pkg, {\n  fields: ['module', 'browser', 'main'],\n  browser: true,\n});\n// fields = [module, browser, main]\n//=\u003e \"module.mjs\"\n```\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fresolve.exports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fresolve.exports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fresolve.exports/lists"}