LogoPear Docs
ReferencesBareModules

bare-addon-resolve

Low-level addon resolution algorithm for Bare

stable

bare-addon-resolve — Low-level addon resolution algorithm for Bare.

npm i bare-addon-resolve

Usage

For synchronous resolution:

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:

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

Functions

resolve

resolve(specifier: string, parentURL: URL, readPackage?: (url: URL) => JSON | null): Iterable<URL>
Source

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.

Parameters

ParameterTypeDefaultDescription
specifierstringThe module specifier to resolve.
parentURLURLThe URL to resolve specifier relative to.
readPackage?(url: URL) => JSON | nullCalled with the URL of each package manifest encountered; must return the parsed manifest or null. Returning a promise disables synchronous iteration.

Returns Iterable<URL> — Yields candidate resolution URLs for the caller to test, in the order the algorithm tries them.

Throws

  • INVALID_ADDON_SPECIFIER — the addon specifier is not a valid package name or contains an invalid escape sequence.
  • INVALID_PACKAGE_NAME — a package manifest's name field is invalid (e.g. contains __).

Types

ResolveOptions

interface ResolveOptions {
  builtinProtocol?: string
  builtins?: Builtins
  conditions?: Conditions
  extensions?: string[]
  host?: string
  hosts?: string[]
  linked?: boolean
  linkedProtocol?: string
  matchedConditions?: string[]
  resolutions?: ResolutionsMap
}
Source

bare-addon-resolve/errors

AddonResolveError

AddonResolveError.INVALID_ADDON_SPECIFIER(msg: string): AddonResolveError

Source

Parameters

ParameterTypeDefaultDescription
msgstringThe error message.

Returns AddonResolveError — A new AddonResolveError with code INVALID_ADDON_SPECIFIER.

AddonResolveError.INVALID_PACKAGE_NAME(msg: string): AddonResolveError

Source

Parameters

ParameterTypeDefaultDescription
msgstringThe error message.

Returns AddonResolveError — A new AddonResolveError with code INVALID_PACKAGE_NAME.

code: string

Source

See also

On this page