# bare-addon-resolve

> Low-level addon resolution algorithm for Bare

Latest version **1.10.1** (published 2026-07-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install bare-addon-resolve
pnpm add bare-addon-resolve
yarn add bare-addon-resolve
bun add bare-addon-resolve
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.10.1 |
| Published | 2026-07-15 |
| First published | 2024-01-31 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 31.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Holepunch |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/bare-addon-resolve
- Repository: https://github.com/holepunchto/bare-addon-resolve
- Homepage: https://github.com/holepunchto/bare-addon-resolve#readme
- Issues: https://github.com/holepunchto/bare-addon-resolve/issues
- npm.io page: https://npm.io/package/bare-addon-resolve

## Dependencies (2)

- [bare-semver](https://npm.io/package/bare-semver.md) ^1.0.0
- [bare-module-resolve](https://npm.io/package/bare-module-resolve.md) ^1.10.0

## Recent versions

- 1.10.1 (latest) — 2026-07-15
- 1.10.0 — 2026-02-10
- 1.9.7 — 2026-02-02
- 1.9.6 — 2025-11-08
- 1.9.5 — 2025-10-16
- 1.9.4 — 2025-03-28
- 1.9.3 — 2025-02-18
- 1.9.2 — 2025-02-18
- 1.9.1 — 2024-12-16
- 1.9.0 — 2024-12-16
- 1.8.0 — 2024-12-13
- 1.7.2 — 2024-11-22
- 1.7.1 — 2024-11-21
- 1.7.0 — 2024-11-16
- 1.6.0 — 2024-11-04
- … 11 more at https://npm.io/package/bare-addon-resolve/versions

## README

# bare-addon-resolve

Low-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.

```
npm i bare-addon-resolve
```

## Usage

For synchronous resolution:

```js
const resolve = require('bare-addon-resolve')

function readPackage(url) {
  // Read and parse `url` if it exists, otherwise `null`
}

for (const resolution of resolve('./addon', new URL('file:///directory/'), readPackage)) {
  console.log(resolution)
}
```

For asynchronous resolution:

```js
const resolve = require('bare-addon-resolve')

async function readPackage(url) {
  // Read and parse `url` if it exists, otherwise `null`
}

for await (const resolution of resolve('./addon', new URL('file:///directory/'), readPackage)) {
  console.log(resolution)
}
```

## API

#### `const resolver = resolve(specifier, parentURL[, options][, readPackage])`

Resolve `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.

Options include:

```js
options = {
  // A list of builtin addon specifiers. If matched, the protocol of the
  // resolved URL will be `builtinProtocol`.
  builtins: [],
  // The protocol to use for resolved builtin addon specifiers.
  builtinProtocol: 'builtin:',
  // Whether or not addons linked ahead-of-time should be resolved.
  linked: true,
  // The protocol to use for addons linked ahead-of-time.
  linkedProtocol: 'linked:',
  // The supported import conditions. "default" is always recognized.
  conditions: [],
  // An array reference which will contain the matched conditions when yielding
  // resolutions.
  matchedConditions: [],
  // The `<platform>-<arch>` combinations to look for when resolving dynamic
  // addons. If empty, only builtin specifiers can be resolved. In Bare,
  // pass `[Bare.Addon.host]`.
  hosts: [],
  // The file extensions to look for when resolving dynamic addons.
  extensions: [],
  // A map of preresolved imports with keys being serialized directory URLs and
  // values being "imports" maps.
  resolutions
}
```

#### `for (const resolution of resolver)`

Synchronously iterate the addon resolution candidates. The resolved addon is the first candidate that exists as a file on the file system.

#### `for await (const resolution of resolver)`

Asynchronously iterate the addon resolution candidates. If `readPackage` returns promises, these will be awaited. The same comments as `for (const resolution of resolver)` apply.

### Algorithm

The following generator functions implement the resolution algorithm. The yielded values have the following shape:

**Package manifest**

```js
next.value = {
  package: URL
}
```

If 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.

**Resolution candidate**

```js
next.value = {
  resolution: URL
}
```

If 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.

To drive the generator functions, a loop like the following can be used:

```js
const generator = resolve.addon(specifier, parentURL)

let next = generator.next()

while (next.done !== true) {
  const value = next.value

  if (value.package) {
    // Read and parse `value.package` if it exists, otherwise `null`
    let info

    next = generator.next(info)
  } else {
    const resolution = value.resolution

    // `true` if `resolution` was the correct candidate, otherwise `false`
    let resolved

    next = generator.next(resolved)
  }
}
```

Options are the same as `resolve()` for all functions.

> [!WARNING]
> 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.

#### `const generator = resolve.addon(specifier, parentURL[, options])`

#### `const generator = resolve.url(url, parentURL[, options])`

#### `const generator = resolve.package(packageSpecifier, packageVersion, parentURL[, options])`

#### `const generator = resolve.packageSelf(packageName, packageSubpath, packageVersion, parentURL[, options])`

#### `const generator = resolve.preresolved(directoryURL, resolutions[, options])`

#### `const generator = resolve.file(filename, parentURL[, options])`

#### `const generator = resolve.directory(dirname, version, parentURL[, options])`

#### `const generator = resolve.linked(name, version[, options])`

## License

Apache-2.0

---
_Source: https://npm.io/package/bare-addon-resolve · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
