bare-addon-resolve
Low-level addon resolution algorithm for Bare
bare-addon-resolve — Low-level addon resolution algorithm for Bare.
npm i bare-addon-resolveUsage
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>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
| Parameter | Type | Default | Description |
|---|---|---|---|
specifier | string | — | The module specifier to resolve. |
parentURL | URL | — | The URL to resolve specifier relative to. |
readPackage? | (url: URL) => JSON | null | — | Called 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'snamefield 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
}bare-addon-resolve/errors
AddonResolveError
AddonResolveError.INVALID_ADDON_SPECIFIER(msg: string): AddonResolveError
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
msg | string | — | The error message. |
Returns AddonResolveError — A new AddonResolveError with code INVALID_ADDON_SPECIFIER.
AddonResolveError.INVALID_PACKAGE_NAME(msg: string): AddonResolveError
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
msg | string | — | The error message. |
Returns AddonResolveError — A new AddonResolveError with code INVALID_PACKAGE_NAME.
code: string
Source
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.