{"name":"bare-addon-resolve","version":"1.11.0","author":{"name":"Holepunch"},"license":"Apache-2.0","_id":"bare-addon-resolve@1.11.0","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"homepage":"https://github.com/holepunchto/bare-addon-resolve#readme","bugs":{"url":"https://github.com/holepunchto/bare-addon-resolve/issues"},"dist":{"shasum":"848cf5a17c4da1e051e729bebd1ece8bc003bce4","tarball":"http://registry-npm.ywwl.com/bare-addon-resolve/download/bare-addon-resolve-1.11.0.tgz","fileCount":7,"integrity":"sha512-bTUBSqBjzQQzo2/iIk6KxAClZfahy38EPsJV2bPJ+p2+kS8h+hT5TE5QggpkFUrCnLL4HDTA4DDM+YiNdyol0w==","signatures":[{"sig":"MEYCIQD+6Pp6sGICuxGwMud2n7xwwQb8WgJlxFmkLNcdKrgjDwIhAJxlQffs8JbxMmDPAw+gL/53wiW51f5gn0tzZv+ahlAr","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIFKKD6Q2noQ9DFAJ1WLd76/iNGS/WaMYr0rgdRbRsVPbAiEAzsgiFyRjBWbHeBqt8046ddINDitim9/JjHmhfzCdX8Y=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/bare-addon-resolve@1.11.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":39713,"size":10876,"noattachment":false,"key":"/bare-addon-resolve/-/bare-addon-resolve-1.11.0.tgz"},"types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","default":"./index.js"},"./errors":{"types":"./lib/errors.d.ts","default":"./lib/errors.js"},"./package":"./package.json"},"gitHead":"6daddc3bfee6e6cce13cb3b842ad1114567cebf5","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"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"e5f1bc39-84c8-4c6b-87b2-be52b7248123"}},"repository":{"url":"git+https://github.com/holepunchto/bare-addon-resolve.git","type":"git"},"_npmVersion":"11.19.0","description":"Low-level addon resolution algorithm for Bare","directories":{},"_nodeVersion":"24.21.0","dependencies":{"bare-semver":"^1.0.0","bare-module-resolve":"^1.10.0"},"_hasShrinkwrap":false,"devDependencies":{"lunte":"^1.8.4","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":{"tmp":"tmp/bare-addon-resolve_1.11.0_1791472022205_0.9551663509961621","host":"s3://npm-registry-packages-npm-production"},"readme":"# bare-addon-resolve\n\nLow-level addon 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-addon-resolve\n```\n\n## Usage\n\nFor synchronous resolution:\n\n```js\nconst resolve = require('bare-addon-resolve')\n\nfunction readPackage(url) {\n  // Read and parse `url` if it exists, otherwise `null`\n}\n\nfor (const resolution of resolve('./addon', new URL('file:///directory/'), readPackage)) {\n  console.log(resolution)\n}\n```\n\nFor asynchronous resolution:\n\n```js\nconst resolve = require('bare-addon-resolve')\n\nasync function readPackage(url) {\n  // Read and parse `url` if it exists, otherwise `null`\n}\n\nfor await (const resolution of resolve('./addon', new URL('file:///directory/'), readPackage)) {\n  console.log(resolution)\n}\n```\n\n## API\n\nSee the [`bare-addon-resolve` reference](https://docs.pears.com/reference/bare/modules/bare-addon-resolve).\n\n## Algorithm\n\nThe following generator functions implement the resolution algorithm. 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 addon 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.addon(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\nThe `preresolved`, `builtinTarget`, and `lookupPackageScope` generators referenced below are provided by [`bare-module-resolve`](https://github.com/holepunchto/bare-module-resolve) and behave as documented there.\n\n### `const generator = resolve.addon(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 a resolution that isn't deferred, return.\n3.  If `url(specifier, parentURL, options)` yields, return.\n4.  Let `version` be `null`.\n5.  Let `i` be the index of the last `@` in `specifier`.\n6.  If `i` is greater than `0`:\n    1.  Set `version` to the substring of `specifier` following `i`.\n    2.  If `version` is a valid semantic version:\n        1.  Set `specifier` to the substring of `specifier` until `i`.\n    3.  Otherwise, set `version` to `null`.\n7.  If `specifier` equals `.` or `..`, or if `specifier` starts with `/`, `\\`, `./`, `.\\`, `../`, or `..\\`:\n    1.  If `file(specifier, parentURL, options)` resolves, return.\n    2.  Return `directory(specifier, version, parentURL, options)`.\n8.  Return `package(specifier, version, parentURL, options)`.\n\n### `const generator = resolve.url(url, parentURL[, options])`\n\n1.  If `url` is not a valid URL, return.\n2.  Yield `url`.\n\n### `const generator = resolve.package(packageSpecifier, packageVersion, 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.  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.\n4.  If `packageName` starts with `.` or includes `\\` or `%`, throw.\n5.  Let `packageSubpath` be `.` concatenated with the substring of `packageSpecifier` from the position at the length of `packageName`.\n6.  If `parentURL` has an opaque path, return.\n7.  If `packageSelf(packageName, packageSubpath, packageVersion, parentURL, options)` yields, return.\n8.  Repeat:\n    1.  Let `packageURL` be the resolution of `node_modules/` concatenated with `packageName` and `/` relative to `parentURL`.\n    2.  Set `parentURL` to its parent directory.\n    3.  Let `info` be the result of yielding the resolution of `package.json` relative to `packageURL`.\n    4.  If `info` is not `null`:\n        1.  Return `directory(packageSubpath, packageVersion, packageURL, options)`.\n    5.  If the path of `parentURL` is empty or `/`, return.\n\n### `const generator = resolve.packageSelf(packageName, packageSubpath, packageVersion, 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.  Return `directory(packageSubpath, packageVersion, packageURL, options)`.\n\n### `const generator = resolve.file(filename, parentURL[, 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.  For each value `ext` of `options.extensions`:\n    1.  If `filename` ends with `ext`, set `ext` to the empty string.\n    2.  Yield the resolution of `filename` concatenated with `ext` relative to `parentURL`; if it resolves, return.\n\n### `const generator = resolve.directory(dirname, version, parentURL[, options])`\n\n1.  If `parentURL` has an opaque path, return.\n2.  If `dirname` ends with `/` or `\\`:\n    1.  Let `directoryURL` be the resolution of `dirname` relative to `parentURL`.\n3.  Otherwise:\n    1.  Let `directoryURL` be the resolution of `dirname` concatenated with `/` relative to `parentURL`.\n4.  Let `unversioned` be `true` if `version` is `null`, otherwise `false`.\n5.  Let `info` be the result of yielding the resolution of `package.json` relative to `directoryURL`.\n6.  If `info` is `null`, return.\n7.  If `info.name` is a non-empty string:\n    1.  If `info.name` includes `__`, throw.\n    2.  Let `name` be `info.name` with every `/` replaced by `__` and any leading `@` removed.\n8.  Otherwise, return.\n9.  If `info.version` is a non-empty string:\n    1.  If `version` is not `null` and `info.version` does not equal `version`, return.\n    2.  Set `version` to `info.version`.\n10. If `builtinTarget(name, version, options.builtins, options)` yields, return.\n11. Let `pending` be the values of `options.hosts` that do not start with `wasi-`, and `wasm` the values that do.\n12. Let `resolved` be `false`.\n13. If `prebuilds(name, version, unversioned, directoryURL, pending, options)` resolves, set `resolved` to `true`.\n14. If `resolved` is `true` and `pending` is empty, return.\n15. For each value `host` of `pending`:\n    1.  If `linked(name, version, options)` with `options.hosts` set to `[host]` resolves, remove `host` from `pending` and set `resolved` to `true`.\n16. If `resolved` is `true` and `pending` is empty, return.\n17. Return `prebuilds(name, version, unversioned, directoryURL, wasm, options)` with `options.extensions` set to `['.wasm']`.\n\n#### `const generator = prebuilds(name, version, unversioned, directoryURL, hosts, options)`\n\nEach host is resolved for in the closest scope that has a prebuild for it, and is removed from `hosts` once it is.\n\n1.  For each value `prebuildsURL` of `lookupPrebuildsScope(directoryURL, options)`:\n    1.  For each value `host` of `hosts`:\n        1.  Let `found` be `false`.\n        2.  Let `conditions` be the result of splitting `host` on `-`.\n        3.  If `host` is one of `darwin-arm64`, `darwin-x64`, `ios-arm64-simulator`, or `ios-x64-simulator`, let `universal` be `host` with its second component replaced by `universal`; otherwise let `universal` be `null`.\n        4.  Append the values of `conditions` to `options.matchedConditions`.\n        5.  If `version` is not `null`:\n            1.  If `file(host + '/' + name + '@' + version, prebuildsURL, options)` resolves, set `found` to `true`.\n            2.  If `universal` is not `null` and `file(universal + '/' + name + '@' + version, prebuildsURL, options)` resolves, set `found` to `true`.\n        6.  If `unversioned` is `true`:\n            1.  If `file(host + '/' + name, prebuildsURL, options)` resolves, set `found` to `true`.\n            2.  If `universal` is not `null` and `file(universal + '/' + name, prebuildsURL, options)` resolves, set `found` to `true`.\n        7.  Remove the values of `conditions` from `options.matchedConditions`.\n        8.  If `found` is `true`, remove `host` from `hosts`.\n    2.  If `hosts` is empty, return.\n\n### `const generator = resolve.linked(name, version[, options])`\n\n1.  If `options.linked` is `false` or `options.hosts` is empty, return.\n2.  For each value `host` of `options.hosts`:\n    1.  Let `platform` be the substring of `host` until the first `-`.\n    2.  If `platform` is the empty string, continue.\n    3.  Append `platform` to `options.matchedConditions`.\n    4.  Let `candidates` be the following artefact names, in order, where each entry containing `<version>` is only included when `version` is not `null`:\n        1.  If `platform` is `darwin` or `ios`:\n            1.  `<name>.<version>.framework/<name>.<version>`\n            2.  `lib<name>.<version>.dylib`, only if `platform` is `darwin`\n            3.  `<name>.framework/<name>`\n            4.  `lib<name>.dylib`, only if `platform` is `darwin`\n        2.  Otherwise, if `platform` is `linux` or `android`:\n            1.  `lib<name>.<version>.so`\n            2.  `lib<name>.so`\n        3.  Otherwise, if `platform` is `win32`:\n            1.  `<name>-<version>.dll`\n            2.  `<name>.dll`\n    5.  For each value `candidate` of `candidates`:\n        1.  Yield `options.linkedProtocol` concatenated with `candidate`; if it resolves, stop iterating `candidates`.\n    6.  Remove `platform` from `options.matchedConditions`.\n\n## License\n\nApache-2.0\n","publish_time":1791472022291,"_cnpm_publish_time":1791472022291,"dist-tags":{"latest":"1.11.1"}}