{"_id":"@es-joy/resolve.exports","_rev":"4249706","name":"@es-joy/resolve.exports","description":"A tiny (952b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance","dist-tags":{"latest":"1.2.0"},"maintainers":[{"name":"brettz9","email":"brettz9@yahoo.com"},{"name":"voxpelli","email":""}],"time":{"modified":"2026-03-29T21:54:11.000Z","created":"2025-10-23T16:09:18.246Z","1.2.0":"2025-10-28T16:42:19.737Z","1.1.0":"2025-10-28T16:17:49.342Z","1.0.0":"2025-10-23T16:09:18.246Z"},"users":{},"author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"repository":{"type":"git","url":"git+https://github.com/es-joy/resolve.exports.git"},"versions":{"1.2.0":{"version":"1.2.0","name":"@es-joy/resolve.exports","repository":{"type":"git","url":"git+https://github.com/es-joy/resolve.exports.git"},"description":"A tiny (952b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance","module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"contributors":[{"name":"Brett Zamir"}],"engines":{"node":">=10"},"exports":{".":{"types":"./index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"},"./package.json":"./package.json"},"keywords":["esm","exports","esmodules","fields","modules","resolution","resolve"],"devDependencies":{"bundt":"next","tsm":"2.3.0","typescript":"5.9.3","uvu":"0.5.6"},"scripts":{"build":"bundt -m","types":"tsc --noEmit","test":"uvu -r tsm test"},"_id":"@es-joy/resolve.exports@1.2.0","bugs":{"url":"https://github.com/es-joy/resolve.exports/issues"},"homepage":"https://github.com/es-joy/resolve.exports#readme","_integrity":"sha512-Q9hjxWI5xBM+qW2enxfe8wDKdFWMfd0Z29k5ZJnuBqD/CasY5Zryj09aCA6owbGATWz+39p5uIdaHXpopOcG8g==","_resolved":"/private/var/folders/2n/_szg3q3d15n9mn2jd_q91cym0000gn/T/1c6281f88fcca6c53a116840ffce37f7/es-joy-resolve.exports-1.2.0.tgz","_from":"file:es-joy-resolve.exports-1.2.0.tgz","_nodeVersion":"22.16.0","_npmVersion":"11.6.2","dist":{"shasum":"fe541a68aa080255f798c8561714ac8fad72cdd5","size":8053,"noattachment":false,"key":"/@es-joy/resolve.exports/-/@es-joy/resolve.exports-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@es-joy/resolve.exports/download/@es-joy/resolve.exports-1.2.0.tgz"},"_npmUser":{"name":"brettz9","email":"brettz9@yahoo.com"},"directories":{},"maintainers":[{"name":"brettz9","email":"brettz9@yahoo.com"},{"name":"voxpelli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/resolve.exports_1.2.0_1761669739513_0.8136832421849227"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-10-28T16:42:19.737Z","publish_time":1761669739737,"_source_registry_name":"default","_cnpm_publish_time":1761669739737},"1.1.0":{"version":"1.1.0","name":"@es-joy/resolve.exports","repository":{"type":"git","url":"git+https://github.com/es-joy/resolve.exports.git"},"description":"A tiny (952b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance","module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"contributors":[{"name":"Brett Zamir"}],"engines":{"node":">=10"},"exports":{".":{"types":"./index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"},"./package.json":"./package.json"},"keywords":["esm","exports","esmodules","fields","modules","resolution","resolve"],"devDependencies":{"bundt":"next","tsm":"2.3.0","typescript":"5.9.3","uvu":"0.5.6"},"scripts":{"build":"bundt -m","types":"tsc --noEmit","test":"uvu -r tsm test"},"_id":"@es-joy/resolve.exports@1.1.0","bugs":{"url":"https://github.com/es-joy/resolve.exports/issues"},"homepage":"https://github.com/es-joy/resolve.exports#readme","_integrity":"sha512-CrFs6x2lvauKO7c7BJEdxmu3+L/I9Wtd+rivBIyukowq1vlcV8q0RNSPQeKDqyScI/0GebQJcYwTfItQj5Fl2A==","_resolved":"/private/var/folders/2n/_szg3q3d15n9mn2jd_q91cym0000gn/T/0be9fe8cc1bbe51f0dce345ba32bc4a8/es-joy-resolve.exports-1.1.0.tgz","_from":"file:es-joy-resolve.exports-1.1.0.tgz","_nodeVersion":"22.16.0","_npmVersion":"11.6.2","dist":{"shasum":"0cae1dc0c554e17cabd9231c5dcb900758f2d57d","size":8017,"noattachment":false,"key":"/@es-joy/resolve.exports/-/@es-joy/resolve.exports-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@es-joy/resolve.exports/download/@es-joy/resolve.exports-1.1.0.tgz"},"_npmUser":{"name":"brettz9","email":"brettz9@yahoo.com"},"directories":{},"maintainers":[{"name":"brettz9","email":"brettz9@yahoo.com"},{"name":"voxpelli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/resolve.exports_1.1.0_1761668269150_0.9227831562795383"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-10-28T16:17:49.342Z","publish_time":1761668269342,"_source_registry_name":"default","_cnpm_publish_time":1761668269342},"1.0.0":{"version":"1.0.0","name":"@es-joy/resolve.exports","repository":{"type":"git","url":"git+https://github.com/es-joy/resolve.exports.git"},"description":"A tiny (952b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance","module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"contributors":[{"name":"Brett Zamir"}],"engines":{"node":">=10"},"exports":{".":{"types":"./index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"},"./package.json":"./package.json"},"keywords":["esm","exports","esmodules","fields","modules","resolution","resolve"],"devDependencies":{"bundt":"next","tsm":"2.3.0","typescript":"4.9.4","uvu":"0.5.4"},"scripts":{"build":"bundt -m","types":"tsc --noEmit","test":"uvu -r tsm test"},"_id":"@es-joy/resolve.exports@1.0.0","bugs":{"url":"https://github.com/es-joy/resolve.exports/issues"},"homepage":"https://github.com/es-joy/resolve.exports#readme","_integrity":"sha512-bbrmzsAZ9GA/3oBS6r8PWMtZarEhKHr413hak8ArwMEZ5DtaLErnkcyEWUsXy7urBcmVu/TpDzHPDVM5uIbx9A==","_resolved":"/private/var/folders/2n/_szg3q3d15n9mn2jd_q91cym0000gn/T/3bd6f19dd7d91ed73567670f442d39c4/es-joy-resolve.exports-1.0.0.tgz","_from":"file:es-joy-resolve.exports-1.0.0.tgz","_nodeVersion":"22.16.0","_npmVersion":"11.6.2","dist":{"shasum":"ae5869ff890836c33569591f0780db3174bf386b","size":7553,"noattachment":false,"key":"/@es-joy/resolve.exports/-/@es-joy/resolve.exports-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@es-joy/resolve.exports/download/@es-joy/resolve.exports-1.0.0.tgz"},"_npmUser":{"name":"brettz9","email":"brettz9@yahoo.com"},"directories":{},"maintainers":[{"name":"brettz9","email":"brettz9@yahoo.com"},{"name":"voxpelli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/resolve.exports_1.0.0_1761235758048_0.20408331834808657"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-10-23T16:09:18.246Z","publish_time":1761235758246,"_source_registry_name":"default","_cnpm_publish_time":1761235758246}},"readme":"# @es-joy/resolve.exports [![CI](https://github.com/es-joy/resolve.exports/workflows/CI/badge.svg)](https://github.com/es-joy/resolve.exports/actions) [![licenses](https://licenses.dev/b/npm/resolve.exports)](https://licenses.dev/npm/resolve.exports) [![codecov](https://codecov.io/gh/es-joy/resolve.exports/branch/master/graph/badge.svg?token=4P7d4Omw2h)](https://codecov.io/gh/es-joy/resolve.exports)\n\n> 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 @es-joy/resolve.exports\n```\n\n## Usage\n\n> Please see [`/test/`](/test) for examples.\n\n```js\nimport * as resolve from '@es-joy/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//=> [\"./dist/module.mjs\"]\n\n// entry: \"foobar/lite\" === \"./lite\"\n// conditions: [\"default\", \"import\", \"node\"]\nresolve.exports(pkg, 'foobar/lite');\nresolve.exports(pkg, './lite');\n//=> [\"./lite/module.mjs\"]\n\n// Enable `require` condition\n// conditions: [\"default\", \"require\", \"node\"]\nresolve.exports(pkg, 'foobar', { require: true }); //=> [\"./dist/require.js\"]\nresolve.exports(pkg, './lite', { require: true }); //=> [\"./lite/require.js\"]\n\n// Throws \"Missing <entry> specifier in <name> 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}); //=> [\"./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}); //=> [\"./lite/worker.browser.js\"]\n\n// ---\n// Types-only resolution\n// ---\n\n// Find only `types` entries (or its synonym `typings`), even when nested under\n//   conditions like `import`/`require`\n// Defaults to following the active branch (`import` by default, `require` when set)\nresolve.types({\n  name: 'pkg',\n  exports: {\n    '.': {\n      import: { types: './index.d.ts', default: './index.mjs' },\n      require: { types: './index.cjs.d.ts', default: './index.cjs' }\n    }\n  }\n});\n//=> [\"./index.d.ts\"]\n\nresolve.types({\n  name: 'pkg',\n  exports: {\n    '.': {\n      import: { types: './index.d.ts', default: './index.mjs' },\n      require: { types: './index.cjs.d.ts', default: './index.cjs' }\n    }\n  }\n}, '.', { require: true });\n//=> [\"./index.cjs.d.ts\"]\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//=> 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//=> [\"./hash/node.mjs\"]\n\n// conditions: [\"default\", \"import\", \"browser\"]\nresolve.imports(pkg, '#hash', { browser: true });\nresolve.imports(pkg, 'foobar/#hash');\n//=> [\"./hash/web.mjs\"]\n\n// conditions: [\"default\"]\nresolve.imports(pkg, '#hash', { unsafe: true });\nresolve.imports(pkg, 'foobar/#hash');\n//=> [\"./hash/detect.mjs\"]\n\nresolve.imports(pkg, '#hello/world');\nresolve.imports(pkg, 'foobar/#hello/world');\n//=> Error: Missing \"#hello/world\" specifier in \"foobar\" package\n\n// ---\n// Legacy\n// ---\n\n// prefer \"module\" > \"main\" (default)\nresolve.legacy(pkg); //=> \"dist/module.mjs\"\n\n// customize fields order\nresolve.legacy(pkg, {\n  fields: ['main', 'module']\n}); //=> \"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;\nexport function types(pkg: Package, entry?: 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> **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 '@es-joy/resolve.exports';\n\nlet pkg = {\n  name: 'foobar',\n  // ...\n};\n\nr.resolve(pkg);\n//~> r.exports(pkg, '.');\n\nr.resolve(pkg, 'foobar');\n//~> r.exports(pkg, '.');\n\nr.resolve(pkg, 'foobar/subpath');\n//~> r.exports(pkg, './subpath');\n\nr.resolve(pkg, '#hash/md5');\n//~> r.imports(pkg, '#hash/md5');\n\nr.resolve(pkg, 'foobar/#hash/md5');\n//~> 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. <br>\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` <br>\nRequired: `true`\n\nThe `package.json` contents.\n\n#### entry\nType: `string` <br>\nRequired: `false` <br>\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 & 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. <br>\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` <br>\nRequired: `true`\n\nThe `package.json` contents.\n\n#### target\nType: `string` <br>\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> **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` <br>\nDefault: `false`\n\nWhen truthy, the `\"require\"` field is added to the list of allowed/known conditions. <br>\nOtherwise the `\"import\"` field is added instead.\n\n#### options.browser\nType: `boolean` <br>\nDefault: `false`\n\nWhen truthy, the `\"browser\"` field is added to the list of allowed/known conditions. <br>\nOtherwise the `\"node\"` field is added instead.\n\n#### options.conditions\nType: `string[]` <br>\nDefault: `[]`\n\nA list of additional/custom conditions that should be accepted when seen.\n\n> **Important:** The order specified within `options.conditions` does not matter. <br>The 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//=> [\"./$import.mjs\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production']\n});\n// Conditions: [\"default\", \"production\", \"import\", \"node\"]\n//=> [\"./$production.js\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production'],\n  require: true,\n});\n// Conditions: [\"default\", \"production\", \"require\", \"node\"]\n//=> [\"./$require.js\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production', 'worker'],\n  require: true,\n});\n// Conditions: [\"default\", \"production\", \"worker\", \"require\", \"node\"]\n//=> [\"./$worker.js\"]\n\nresolve.exports(pkg, '.', {\n  conditions: ['production', 'worker']\n});\n// Conditions: [\"default\", \"production\", \"worker\", \"import\", \"node\"]\n//=> [\"./$worker.js\"]\n```\n\nIf you want to remove a condition, you can use the `!` prefix. For example, you only need `\"types\"`:\n\n```js\nresolve.exports(pkg, '.', {\n  conditions: ['!default', '!import', '!node', 'types']\n});\n// Conditions: [\"types\"]\n```\n\n#### options.unsafe\nType: `boolean` <br>\nDefault: `false`\n\n> **Important:** You probably do not want this option! <br>It 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//=> Conditions: [\"default\", \"import\", \"node\"]\n\nresolve.exports(pkg, '.', { unsafe: true });\n//=> Conditions: [\"default\"]\n\nresolve.exports(pkg, '.', { unsafe: true, require: true, browser: true });\n//=> 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//=> Conditions: [\"default\", \"require\"]\n\nresolve.exports(pkg, '.', {\n  unsafe: true,\n  conditions: [\"browser\", \"require\", \"custom123\"]\n});\n//=> 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_. <br>\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` <br>\nDefault: `false`\n\nWhen truthy, ensures that the `'browser'` field is part of the acceptable `fields` list.\n\n> **Important:** If your custom [`options.fields`](#optionsfields) value includes `'browser'`, then _your_ order is respected. <br>Otherwise, 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> See the [`\"browser\" field specification](https://github.com/defunctzombie/package-browser-field-spec) for more information.\n\n#### options.fields\nType: `string[]` <br>\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 '@es-joy/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//=> \"module.mjs\"\n\nlegacy(pkg, { browser: true });\n// fields = [browser, module, main]\n//=> \"browser.mjs\"\n\nlegacy(pkg, {\n  fields: ['missing', 'worker', 'module', 'main']\n});\n// fields = [missing, worker, module, main]\n//=> \"worker.js\"\n\nlegacy(pkg, {\n  fields: ['missing', 'worker', 'module', 'main'],\n  browser: true,\n});\n// fields = [browser, missing, worker, module, main]\n//=> \"browser.js\"\n\nlegacy(pkg, {\n  fields: ['module', 'browser', 'main'],\n  browser: true,\n});\n// fields = [module, browser, main]\n//=> \"module.mjs\"\n```\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/es-joy/resolve.exports#readme","bugs":{"url":"https://github.com/es-joy/resolve.exports/issues"},"license":"MIT"}