{"name":"bare-addon-resolve","version":"1.5.2","author":{"name":"Holepunch"},"license":"Apache-2.0","_id":"bare-addon-resolve@1.5.2","homepage":"https://github.com/holepunchto/bare-addon-resolve#readme","bugs":{"url":"https://github.com/holepunchto/bare-addon-resolve/issues"},"dist":{"shasum":"9349965817773eb6b48491f948e2ed4a62e18272","tarball":"http://registry-npm.ywwl.com/bare-addon-resolve/download/bare-addon-resolve-1.5.2.tgz","fileCount":5,"integrity":"sha512-jgSdukaM3k8aK8+XXM/bL/CptcKPSes2FSmNmOgHBCcPlMJm2BO0ZYLo1n7T1SXjvDK2i0w+RycKBOKC0EH03g==","signatures":[{"sig":"MEQCIBAFBzuIEYFiAgTN3iG0NMpq9r+u1wCo8h9WjkpTvHpXAiBu6drmuCCX6CuEYvPjaJ8vxtssZINnXey6OahQ3tV/zg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25146,"size":7597,"noattachment":false,"key":"/bare-addon-resolve/-/bare-addon-resolve-1.5.2.tgz"},"exports":{".":"./index.js","./errors":"./lib/errors.js","./package":"./package.json"},"gitHead":"848b366369798857e521a567cad9e1cee2dd2a1a","scripts":{"test":"standard && bare test.js"},"_npmUser":{"name":"kasperisager","email":"kasperisager@hey.com"},"repository":{"url":"git+https://github.com/holepunchto/bare-addon-resolve.git","type":"git"},"_npmVersion":"10.8.3","description":"Low-level addon resolution algorithm for Bare","directories":{},"_nodeVersion":"22.9.0","dependencies":{"bare-module-resolve":"^1.5.0"},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.2.1","standard":"^17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/bare-addon-resolve_1.5.2_1730472568186_0.48994782263786973","host":"s3://npm-registry-packages"},"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(\n  './addon',\n  new URL('file:///directory/'),\n  readPackage\n)) {\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(\n  './addon',\n  new URL('file:///directory/'),\n  readPackage\n)) {\n  console.log(resolution)\n}\n```\n\n## API\n\n#### `const resolver = resolve(specifier, parentURL[, options][, readPackage])`\n\nResolve `specifier` relative to `parentURL`, which must be a WHATWG `URL` instance. `readPackage` is called with a `URL` instance for every package manifest to be read and must either return the parsed JSON package manifest, if it exists, or `null`. If `readPackage` returns a promise, synchronous iteration is not supported.\n\nOptions include:\n\n```js\noptions = {\n  // A list of builtin addon specifiers. If matched, the protocol of the\n  // resolved URL will be `builtinProtocol`.\n  builtins: [],\n  // The protocol to use for resolved builtin addon specifiers.\n  builtinProtocol: 'builtin:',\n  // Whether or not addons linked ahead-of-time should be resolved.\n  linked: true,\n  // The protocol to use for addons linked ahead-of-time.\n  linkedProtocol: 'linked:',\n  // The supported import conditions. \"default\" is always recognized.\n  conditions: [],\n  // An array reference which will contain the matched conditions when yielding\n  // resolutions.\n  matchedConditions: [],\n  // The `<platform>-<arch>` combinations to look for when resolving dynamic\n  // addons. If empty, only builtin specifiers can be resolved. In Bare,\n  // pass `[Bare.Addon.host]`.\n  hosts: [],\n  // The file extensions to look for when resolving dynamic addons.\n  extensions: [],\n  // A map of preresolved imports with keys being serialized directory URLs and\n  // values being \"imports\" maps.\n  resolutions\n}\n```\n\n#### `for (const resolution of resolver)`\n\nSynchronously iterate the addon resolution candidates. The resolved addon is the first candidate that exists as a file on the file system.\n\n#### `for await (const resolution of resolver)`\n\nAsynchronously iterate the addon resolution candidates. If `readPackage` returns promises, these will be awaited. The same comments as `for (const resolution of resolver)` apply.\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\n#### `const generator = resolve.addon(specifier, parentURL[, options])`\n\n#### `const generator = resolve.url(url, parentURL[, options])`\n\n#### `const generator = resolve.package(packageSpecifier, packageVersion, parentURL[, options])`\n\n#### `const generator = resolve.packageSelf(packageName, packageSubpath, packageVersion, parentURL[, options])`\n\n#### `const generator = resolve.preresolved(directoryURL, resolutions[, options])`\n\n#### `const generator = resolve.file(filename, parentURL[, options])`\n\n#### `const generator = resolve.directory(dirname, version, parentURL[, options])`\n\n#### `const generator = resolve.linked(name, version[, options])`\n\n## License\n\nApache-2.0\n","publish_time":1730472568349,"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"kasperisager","email":"kasperisager@hey.com"}],"_cnpm_publish_time":1730472568349,"dist-tags":{"latest":"1.11.1"}}