{"name":"bare-addon-resolve","version":"1.10.1","description":"Low-level addon resolution algorithm for Bare","exports":{"./package":"./package.json",".":{"types":"./index.d.ts","default":"./index.js"},"./errors":{"types":"./lib/errors.d.ts","default":"./lib/errors.js"}},"scripts":{"format":"prettier --write . && lunte --fix","lint":"prettier --check . && lunte","test":"npm run test:bare && npm run test:node","test:bare":"brittle-bare --coverage test.js","test:node":"brittle-node --coverage test.js"},"repository":{"type":"git","url":"git+https://github.com/holepunchto/bare-addon-resolve.git"},"author":{"name":"Holepunch"},"license":"Apache-2.0","bugs":{"url":"https://github.com/holepunchto/bare-addon-resolve/issues"},"homepage":"https://github.com/holepunchto/bare-addon-resolve#readme","dependencies":{"bare-module-resolve":"^1.10.0","bare-semver":"^1.0.0"},"devDependencies":{"bare-url":"^2.1.3","brittle":"^3.2.1","lunte":"^1.8.4","prettier":"^3.3.3","prettier-config-holepunch":"^2.0.0"},"peerDependencies":{"bare-url":"*"},"peerDependenciesMeta":{"bare-url":{"optional":true}},"gitHead":"ed517fb0d5a09621828ff1d929934f6b55144550","types":"./index.d.ts","_id":"bare-addon-resolve@1.10.1","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-F/SD2du8keuYSb4xipnGz5j2E6yhNdHA8ZVxtHae6h2uOrpBIjjbhXvjzKZbr5XUOzqBzh/i8GVFycj2DlFQIA==","shasum":"d88174ee1c1d6ce09c3224d76f5ce7bb748d28fe","tarball":"http://registry-npm.ywwl.com/bare-addon-resolve/download/bare-addon-resolve-1.10.1.tgz","fileCount":7,"unpackedSize":32082,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/bare-addon-resolve@1.10.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIG62os1QqmycSrR5IhpnoXV0PiLGcSMk8GAA4UDiSem/AiBYJQl7g6USoPpML/yBnUM4cQdxQGdoIOz9CKQ/6XWg1A=="}],"size":9259,"noattachment":false,"key":"/bare-addon-resolve/-/bare-addon-resolve-1.10.1.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:e5f1bc39-84c8-4c6b-87b2-be52b7248123"}},"directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bare-addon-resolve_1.10.1_1784134904090_0.5771015808415838"},"_hasShrinkwrap":false,"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\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":1784134904246,"_cnpm_publish_time":1784134904246,"dist-tags":{"latest":"1.11.1"}}