LogoPear Docs
ReferencesBareModules

bare-addon-resolve

Reference for bare-addon-resolve: the low-level native-addon resolution algorithm for Bare, exposed as a generator.

bare-addon-resolve implements Bare's low-level resolution algorithm for native addons—the counterpart to bare-module-resolve for .bare / prebuilt binaries. It's a pure-JavaScript generator that yields candidate addon URLs for a specifier.

A low-level building block. Addons normally resolve through the runtime or are bundled by bare-pack; use this directly only in tooling.

npm i bare-addon-resolve

Usage

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

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

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

An asynchronous form is supported by iterating with for await.

API

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

Create an addon resolver. Iterate synchronously or with for await; each yielded value is a candidate addon URL.

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.

These functions are currently subject to change between minor releases. If using them directly, make sure to specify a tilde range (for example, ~1.10.0) when declaring the module dependency.

Sub-generators

resolve.addon, resolve.url, resolve.package, resolve.packageSelf, resolve.preresolved, resolve.file, resolve.directory, and resolve.linked expose the algorithm's steps—including linked, which resolves to linked: specifiers for runtimes that link addons ahead of time (iOS and Android). See the repository README.

Builds on bare-module-resolve and bare-semver (see Bare modules).

See also

On this page