{"_id":"bare-module-resolve@1.12.6","bugs":{"url":"https://github.com/holepunchto/bare-module-resolve/issues"},"dist":{"shasum":"69a342928f62ced1a1efa5e40d8c98e3f41b3182","tarball":"http://registry-npm.ywwl.com/bare-module-resolve/download/bare-module-resolve-1.12.6.tgz","fileCount":7,"integrity":"sha512-tsoOqHmtF6VmNX4LYDBZwvQVkSmEagnbykNjK31LMxz/amyKfjCs4K976n7uJd1bvWfxbpLQ3Fy7qq8an6jR6Q==","signatures":[{"sig":"MEUCID6ElcXc493/lrynf+nHKyb2PS6m8yXNti5AYXR1GeN5AiEAjW0YxVbziIrfPHWjSlUFbUrq+xBAG0QWiBTQI1eKKH0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC9hHBmixdIjtM+QjF5pwBGc9LaHaRUoofVfLR9+RigOAIgT1vRR2cLyApMbulzecixr5ZgILDNA7zq3nS1DJVYkTU="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/bare-module-resolve@1.12.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":59021,"size":13660,"noattachment":false,"key":"/bare-module-resolve/-/bare-module-resolve-1.12.6.tgz"},"name":"bare-module-resolve","types":"./index.d.ts","author":{"name":"Holepunch"},"exports":{".":{"types":"./index.d.ts","default":"./index.js"},"./errors":{"types":"./lib/errors.d.ts","default":"./lib/errors.js"},"./package":"./package.json"},"gitHead":"adeb0fbac21907b83c5b51ff0614595b7e31c128","license":"Apache-2.0","scripts":{"lint":"prettier --check . && lunte","test":"npm run test:bare && npm run test:node","format":"prettier --write . && lunte --fix","test:bare":"brittle-bare --coverage test.js","test:node":"brittle-node --coverage test.js"},"version":"1.12.6","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"8ac298a1-b48f-41f5-b5bd-36a8d4a7ff4b"}},"homepage":"https://github.com/holepunchto/bare-module-resolve#readme","repository":{"url":"git+https://github.com/holepunchto/bare-module-resolve.git","type":"git"},"_npmVersion":"11.19.0","description":"Low-level module resolution algorithm for Bare","directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_nodeVersion":"24.21.0","dependencies":{"bare-semver":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"lunte":"^1.7.0","brittle":"^3.2.1","bare-url":"^2.1.3","prettier":"^3.3.3","prettier-config-holepunch":"^2.0.0"},"peerDependencies":{"bare-url":"*"},"peerDependenciesMeta":{"bare-url":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bare-module-resolve_1.12.6_1791471906281_0.8184553317923702"},"readme":"# bare-module-resolve\n\nLow-level module resolution algorithm for Bare. The algorithm is implemented as a generator function that yields either package manifests to be read or resolution candidates to be tested by the caller. As a convenience, the main export is a synchronous and asynchronous iterable that relies on package manifests being read by a callback. For asynchronous iteration, the callback may return promises which will be awaited before being passed to the generator.\n\n```\nnpm i bare-module-resolve\n```\n\n## Usage\n\nFor synchronous resolution:\n\n```js\nconst resolve = require('bare-module-resolve')\n\nfunction readPackage(url) {\n  // Read and parse `url` if it exists, otherwise `null`\n}\n\nfor (const resolution of resolve('./file.js', new URL('file:///directory/'), readPackage)) {\n  console.log(resolution)\n}\n```\n\nFor asynchronous resolution:\n\n```js\nconst resolve = require('bare-module-resolve')\n\nasync function readPackage(url) {\n  // Read and parse `url` if it exists, otherwise `null`\n}\n\nfor await (const resolution of resolve('./file.js', new URL('file:///directory/'), readPackage)) {\n  console.log(resolution)\n}\n```\n\n## API\n\nSee the [`bare-module-resolve` reference](https://docs.pears.com/reference/bare/modules/bare-module-resolve).\n\n## Algorithm\n\nThe following generator functions implement the resolution algorithm, which has been adapted from the Node.js resolution algorithms for CommonJS and ES modules. Unlike Node.js, Bare uses the same resolution algorithm for both module formats. The yielded values have the following shape:\n\n**Package manifest**\n\n```js\nnext.value = {\n  package: URL\n}\n```\n\nIf the package manifest identified by `next.value.package` exists, `generator.next()` must be passed the parsed JSON value of the manifest. If it does not exist, pass `null` instead.\n\n**Resolution candidate**\n\n```js\nnext.value = {\n  resolution: URL\n}\n```\n\nIf the module identified by `next.value.resolution` exists, `generator.next()` may be passed `true` to signal that the resolution for the current set of conditions has been identified. If it does not exist, pass `false` instead.\n\nTo drive the generator functions, a loop like the following can be used:\n\n```js\nconst generator = resolve.module(specifier, parentURL)\n\nlet next = generator.next()\n\nwhile (next.done !== true) {\n  const value = next.value\n\n  if (value.package) {\n    // Read and parse `value.package` if it exists, otherwise `null`\n    let info\n\n    next = generator.next(info)\n  } else {\n    const resolution = value.resolution\n\n    // `true` if `resolution` was the correct candidate, otherwise `false`\n    let resolved\n\n    next = generator.next(resolved)\n  }\n}\n```\n\nOptions are the same as `resolve()` for all functions.\n\n> [!WARNING]\n> These functions are currently subject to change between minor releases. If using them directly, make sure to specify a tilde range (`~1.2.3`) when declaring the module dependency.\n\n### `const generator = resolve.module(specifier, parentURL[, options])`\n\n1.  If `specifier` [starts with a Windows drive letter](https://url.spec.whatwg.org/#start-with-a-windows-drive-letter):\n    1.  Prepend `/` to `specifier`.\n2.  If `options.resolutions` is set:\n    1.  If `preresolved(specifier, options.resolutions, parentURL, options)` yields, return.\n3.  If `url(specifier, parentURL, options)` yields, return.\n4.  If `packageImports(specifier, parentURL, options)` yields, return.\n5.  If `specifier` equals `.` or `..`, or if `specifier` starts with `/`, `\\`, `./`, `.\\`, `../`, or `..\\`:\n    1.  If `options.imports` is set:\n        1.  If `packageImportsExports(specifier, options.imports, parentURL, true, options)` yields, return.\n    2.  If `deferred(specifier, options)` yields, return.\n    3.  If `file(specifier, parentURL, false, options)` resolves, return.\n    4.  Return `directory(specifier, parentURL, options)`.\n6.  Return `package(specifier, parentURL, options)`.\n\n### `const generator = resolve.url(url, parentURL[, options])`\n\n1.  If `url` is not a valid URL, return.\n2.  If `options.imports` is set:\n    1.  If `packageImportsExports(url.href, options.imports, parentURL, true, options)` yields, return.\n3.  If `url.protocol` equals `options.deferredProtocol`:\n    1.  Let `specifier` be `url.pathname`.\n    2.  If `options.resolutions` is set:\n        1.  Let `imports` be `options.resolutions[parentURL]`.\n        2.  If `imports` is a non-`null` object:\n            1.  Set `imports[specifier]` to `null`.\n    3.  Return `module(specifier, parentURL, options)`.\n4.  If `url.protocol` equals `node:`:\n    1.  Let `specifier` be `url.pathname`.\n    2.  If `specifier` equals `.` or `..`, or if `specifier` starts with `/`, `\\`, `./`, `.\\`, `../`, or `..\\`, throw.\n    3.  Return `package(specifier, parentURL, options)`.\n5.  Yield `url`.\n\n### `const generator = resolve.preresolved(specifier, resolutions, parentURL[, options])`\n\n1.  Let `imports` be `resolutions[parentURL]`.\n2.  If `imports` is a non-`null` object:\n    1.  Return `packageImportsExports(specifier, imports, parentURL, true, options)`.\n\n### `const generator = resolve.deferred(specifier[, options])`\n\n1.  If `options.defer` includes `specifier`:\n    1.  Yield `options.deferredProtocol` concatenated with `specifier` and return.\n\n### `const generator = resolve.package(packageSpecifier, parentURL[, options])`\n\n1.  If `packageSpecifier` is the empty string, throw.\n2.  If `packageSpecifier` does not start with `@`:\n    1.  Set `packageName` to the substring of `packageSpecifier` until the first `/` or the end of the string.\n3.  Let `packageName` be `undefined`.\n4.  Otherwise:\n    1.  If `packageSpecifier` does not include `/`, throw.\n    2.  Set `packageName` to the substring of `packageSpecifier` until the second `/` or the end of the string.\n5.  If `packageName` starts with `.` or includes `\\` or `%`, throw.\n6.  If `builtinTarget(packageSpecifier, null, options.builtins, options)` yields, return.\n7.  If `deferred(packageSpecifier, options)` yields, return.\n8.  Let `packageSubpath` be `.` concatenated with the substring of `packageSpecifier` from the position at the length of `packageName`.\n9.  If `packageSelf(packageName, packageSubpath, parentURL, options)` yields, return.\n10. For each value `packageURL` of `lookupPackageRoot(packageName, parentURL, options)`:\n    1.  Let `info` be the result of yielding `packageURL`.\n    2.  If `info` is not `null`:\n        1.  If `info.engines` is set:\n            1.  Call `validateEngines(packageURL, info.engines, options)`.\n        2.  If `info.exports` is set:\n            1.  Return `packageExports(packageURL, packageSubpath, info.exports, options)`.\n        3.  If `packageSubpath` is `.`:\n            1.  If `info.main` is a non-empty string:\n                1.  Set `packageSubpath` to `info.main`.\n            2.  Otherwise:\n                1.  Return `file('index', packageURL, true, options)`.\n        4.  If `file(packageSubpath, packageURL, false, options)` resolves, return.\n        5.  Return `directory(packageSubpath, packageURL, options)`.\n\n### `const generator = resolve.packageSelf(packageName, packageSubpath, parentURL[, options])`\n\n1.  For each value `packageURL` of `lookupPackageScope(parentURL, options)`:\n    1.  Let `info` be the result of yielding `packageURL`.\n    2.  If `info` is not `null`:\n        1.  If `info.name` does not equal `packageName`, return.\n        2.  If `info.exports` is set:\n            1.  Return `packageExports(packageURL, packageSubpath, info.exports, options)`.\n        3.  If `packageSubpath` is `.`:\n            1.  If `info.main` is a non-empty string:\n                1.  Set `packageSubpath` to `info.main`.\n            2.  Otherwise:\n                1.  Return `file('index', packageURL, true, options)`.\n        4.  If `file(packageSubpath, packageURL, false, options)` resolves, return.\n        5.  Return `directory(packageSubpath, packageURL, options)`.\n\n### `const generator = resolve.packageExports(packageURL, subpath, exports[, options])`\n\n1.  If `exports` is a non-`null`, non-array object whose keys are a mix of ones that start with `.` and ones that don't, throw.\n2.  If `subpath` is `.`:\n    1.  Let `mainExport` be `undefined`.\n    2.  If `exports` is a string or an array:\n        1.  Set `mainExport` to `exports`.\n    3.  If `exports` is a non-`null` object:\n        1.  If some keys of `exports` start with `.`:\n            1.  If `.` is a key of `exports`:\n                1.  Set `mainExport` to `exports['.']`.\n        2.  Otherwise:\n            1.  Set `mainExport` to `exports`.\n    4.  If `mainExport` is not `undefined`:\n        1.  If `packageTarget(packageURL, mainExport, null, false, options)` yields, return.\n3.  Otherwise, if `exports` is a non-`null` object:\n    1.  If every key of `exports` starts with `.`:\n        1.  If `packageImportsExports(subpath, exports, packageURL, false, options)` yields, return.\n4.  Throw.\n\n### `const generator = resolve.packageImports(specifier, parentURL[, options])`\n\n1.  If `specifier` is `#` or starts with `#/`, throw.\n2.  For each value `packageURL` of `lookupPackageScope(parentURL, options)`:\n    1.  Let `info` be the result of yielding `packageURL`.\n    2.  If `info` is not `null`:\n        1.  If `info.imports` is set:\n            1.  If `packageImportsExports(specifier, info.imports, packageURL, true, options)` yields, return.\n        2.  If specifier starts with `#`, throw.\n        3.  Return.\n3.  If `options.imports` is set:\n    1.  If `packageImportsExports(url.href, options.imports, parentURL, true, options)` yields, return.\n\n### `const generator = resolve.packageImportsExports(matchKey, matchObject, packageURL, isImports[, options])`\n\n1.  If `matchKey` is a key of `matchObject` and `matchKey` does not include `*`:\n    1.  Let `target` be `matchObject[matchKey]`.\n    2.  Return `packageTarget(packageURL, target, null, isImports, options)`.\n2.  Let `expansionKeys` be the keys of `matchObject` that include `*` sorted by `patternKeyCompare`.\n3.  For each value `expansionKey` of `expansionKeys`:\n    1.  Let `patternBase` be the substring of `expansionKey` until the first `*`.\n    2.  If `matchKey` starts with but isn't equal to `patternBase`:\n        1.  Let `patternTrailer` be the substring of `expansionKey` from the position at the index after the first `*`.\n        2.  If `patternTrailer` is the empty string, or if `matchKey` ends with `patternTrailer` and the length of `matchKey` is greater than or equal to the length of `expansionKey`:\n            1.  Let `target` be `matchObject[expansionKey]`.\n            2.  Let `patternMatch` be the substring of `matchKey` from the position at the length of `patternBase` until the length of `matchKey` minus the length of `patternTrailer`.\n            3.  Return `packageTarget(packageURL, target, patternMatch, isImports, options)`.\n\n### `const generator = resolve.packageTarget(packageURL, target, patternMatch, isImports[, options])`\n\n1.  If `target` is a string:\n    1.  If `target` does not start with `./` and `isImports` is `false`, throw.\n    2.  If `patternMatch` is not `null`:\n        1.  Replace every instance of `*` in `target` with `patternMatch`.\n    3.  If `options.matchedTargets` includes `target`, return, having detected a resolution cycle.\n    4.  Append `target` to `options.matchedTargets` for the remainder of these steps, removing it again before returning.\n    5.  If `url(target, packageURL, options)` yields, or if `target` is a valid URL, return.\n    6.  If `target` equals `.` or `..`, or if `target` starts with `/`, `./`, or `../`:\n        1.  If `packageURL` has an opaque path, return.\n        2.  Yield the resolution of `target` relative to `packageURL` and return.\n    7.  Return `package(target, packageURL, options)`.\n2.  If `target` is an array:\n    1.  For each value `targetValue` of `target`:\n        1.  If `packageTarget(packageURL, targetValue, patternMatch, isImports, options)` resolves, return.\n3.  If `target` is a non-`null` object:\n    1.  For each key `condition` of `target`:\n        1.  If `condition` equals `default` or if `options.conditions` includes `condition`:\n            1.  Let `targetValue` be `target[condition]`.\n            2.  Append `condition` to `options.matchedConditions`.\n            3.  Let `status` be the result of `packageTarget(packageURL, targetValue, patternMatch, isImports, options)`.\n            4.  Remove `condition` from `options.matchedConditions`.\n            5.  Return `status`.\n\n### `const generator = resolve.builtinTarget(packageSpecifier, packageVersion, target[, options])`\n\n1.  If `target` is a string:\n    1.  If `target` does not start with `@`:\n        1.  Let `targetName` be the substring of `target` until the first `@` or the end of the string.\n        2.  Let `targetVersion` be the substring of `target` from the character following the first `@` and to the end of string, or `null` if no such substring exists.\n    2.  Otherwise:\n        1.  Let `targetName` be the substring of `target` until the second `@` or the end of the string.\n        2.  Let `targetVersion` be the substring of `target` from the character following the second `@` and to the end of string, or `null` if no such substring exists.\n    3.  If `packageSpecifier` equals `targetName`:\n        1.  If `packageVersion` is `null` and `targetVersion` is `null`:\n            1.  Yield `options.builtinProtocol` concatenated with `packageSpecifier` and return.\n        2.  Let `version` be `null`.\n        3.  If `packageVersion` is `null`, let `version` be `targetVersion`.\n        4.  Otherwise, if `targetVersion` is either `null` or equals `packageVersion`, let `version` be `packageVersion`\n        5.  If `version` is not `null`:\n            1.  Yield `options.builtinProtocol` concatenated with `packageSpecifier`, `@`, and `version` and return.\n2.  If `target` is an array:\n    1.  For each value `targetValue` of `target`:\n        1.  If `builtinTarget(packageSpecifier, packageVersion, targetValue, options)` resolves, return.\n3.  If `target` is a non-`null` object:\n    1.  For each key `condition` of `target`:\n        1.  If `condition` equals `default` or if `options.conditions` includes `condition`:\n            1.  Let `targetValue` be `target[condition]`.\n            2.  Append `condition` to `options.matchedConditions`.\n            3.  Let `status` be the result of `builtinTarget(packageSpecifier, packageVersion, targetValue, options)`.\n            4.  Remove `condition` from `options.matchedConditions`.\n            5.  Return `status`.\n\n### `const generator = resolve.file(filename, parentURL, isIndex[, options])`\n\n1.  If `filename` equals `.` or `..`, or if `filename` ends with `/` or `\\`, return.\n2.  If `parentURL` has an opaque path, return.\n3.  If `parentURL` is a `file:` URL and `filename` includes encoded `/` or `\\`, throw.\n4.  If `isIndex` is `false`:\n    1.  Yield the resolution of `filename` relative to `parentURL`.\n5.  For each value `ext` of `options.extensions`:\n    1.  If `filename` ends with `ext`, continue.\n    2.  Yield the resolution of `filename` concatenated with `ext` relative to `parentURL`.\n\n### `const generator = resolve.directory(dirname, parentURL[, options])`\n\n1.  If `parentURL` has an opaque path, return.\n2.  Let `directoryURL` be `undefined`.\n3.  If `dirname` ends with `/` or `\\`:\n    1.  Set `directoryURL` to the resolution of `dirname` relative to `parentURL`.\n4.  Otherwise:\n    1.  Set `directoryURL` to the resolution of `dirname` concatenated with `/` relative to `parentURL`.\n5.  If `options.directories` is `true`:\n    1.  Yield `directoryURL`.\n6.  Let `info` be the result of yielding the resolution of `package.json` relative to `directoryURL`.\n7.  If `info` is not `null`:\n    1.  If `info.exports` is set:\n        1.  Return `packageExports(directoryURL, '.', info.exports, options)`.\n    2.  If `info.main` is a non-empty string:\n        1.  If `file(info.main, directoryURL, false, options)` resolves, return.\n        2.  Return `directory(info.main, directoryURL, options)`.\n8.  Return `file('index', directoryURL, true, options)`.\n\n## License\n\nApache-2.0\n","publish_time":1791471906412,"_cnpm_publish_time":1791471906412,"dist-tags":{"latest":"1.12.6"}}