$ npm install 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
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)
}
See the bare-addon-resolve reference.
The following generator functions implement the resolution algorithm. The yielded values have the following shape:
Package manifest
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
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:
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.
The preresolved, builtinTarget, and lookupPackageScope generators referenced below are provided by bare-module-resolve and behave as documented there.
const generator = resolve.addon(specifier, parentURL[, options])specifier starts with a Windows drive letter:
/ to specifier.options.resolutions is set:
preresolved(specifier, options.resolutions, parentURL, options) yields a resolution that isn't deferred, return.url(specifier, parentURL, options) yields, return.version be null.i be the index of the last @ in specifier.i is greater than 0:
version to the substring of specifier following i.version is a valid semantic version:
specifier to the substring of specifier until i.version to null.specifier equals . or .., or if specifier starts with /, \, ./, .\, ../, or ..\:
file(specifier, parentURL, options) resolves, return.directory(specifier, version, parentURL, options).package(specifier, version, parentURL, options).const generator = resolve.url(url, parentURL[, options])url is not a valid URL, return.url.const generator = resolve.package(packageSpecifier, packageVersion, parentURL[, options])packageSpecifier is the empty string, throw.packageSpecifier does not start with @:
packageName to the substring of packageSpecifier until the first / or the end of the string.packageSpecifier does not include /, throw.packageName to the substring of packageSpecifier until the second / or the end of the string.packageName starts with . or includes \ or %, throw.packageSubpath be . concatenated with the substring of packageSpecifier from the position at the length of packageName.parentURL has an opaque path, return.packageSelf(packageName, packageSubpath, packageVersion, parentURL, options) yields, return.packageURL be the resolution of node_modules/ concatenated with packageName and / relative to parentURL.parentURL to its parent directory.info be the result of yielding the resolution of package.json relative to packageURL.info is not null:
directory(packageSubpath, packageVersion, packageURL, options).parentURL is empty or /, return.const generator = resolve.packageSelf(packageName, packageSubpath, packageVersion, parentURL[, options])packageURL of lookupPackageScope(parentURL, options):
info be the result of yielding packageURL.info is not null:
info.name does not equal packageName, return.directory(packageSubpath, packageVersion, packageURL, options).const generator = resolve.file(filename, parentURL[, options])filename equals . or .., or if filename ends with / or \, return.parentURL has an opaque path, return.parentURL is a file: URL and filename includes encoded / or \, throw.ext of options.extensions:
filename ends with ext, set ext to the empty string.filename concatenated with ext relative to parentURL; if it resolves, return.const generator = resolve.directory(dirname, version, parentURL[, options])parentURL has an opaque path, return.dirname ends with / or \:
directoryURL be the resolution of dirname relative to parentURL.directoryURL be the resolution of dirname concatenated with / relative to parentURL.unversioned be true if version is null, otherwise false.info be the result of yielding the resolution of package.json relative to directoryURL.info is null, return.info.name is a non-empty string:
info.name includes __, throw.name be info.name with every / replaced by __ and any leading @ removed.info.version is a non-empty string:
version is not null and info.version does not equal version, return.version to info.version.builtinTarget(name, version, options.builtins, options) yields, return.pending be the values of options.hosts that do not start with wasi-, and wasm the values that do.resolved be false.prebuilds(name, version, unversioned, directoryURL, pending, options) resolves, set resolved to true.resolved is true and pending is empty, return.host of pending:
linked(name, version, options) with options.hosts set to [host] resolves, remove host from pending and set resolved to true.resolved is true and pending is empty, return.prebuilds(name, version, unversioned, directoryURL, wasm, options) with options.extensions set to ['.wasm'].const generator = prebuilds(name, version, unversioned, directoryURL, hosts, options)Each host is resolved for in the closest scope that has a prebuild for it, and is removed from hosts once it is.
prebuildsURL of lookupPrebuildsScope(directoryURL, options):
host of hosts:
found be false.conditions be the result of splitting host on -.host is one of darwin-arm64, darwin-x64, ios-arm64-simulator, or ios-x64-simulator, let universal be host with its second component replaced by universal; otherwise let universal be null.conditions to options.matchedConditions.version is not null:
file(host + '/' + name + '@' + version, prebuildsURL, options) resolves, set found to true.universal is not null and file(universal + '/' + name + '@' + version, prebuildsURL, options) resolves, set found to true.unversioned is true:
file(host + '/' + name, prebuildsURL, options) resolves, set found to true.universal is not null and file(universal + '/' + name, prebuildsURL, options) resolves, set found to true.conditions from options.matchedConditions.found is true, remove host from hosts.hosts is empty, return.const generator = resolve.linked(name, version[, options])options.linked is false or options.hosts is empty, return.host of options.hosts:
platform be the substring of host until the first -.platform is the empty string, continue.platform to options.matchedConditions.candidates be the following artefact names, in order, where each entry containing <version> is only included when version is not null:
platform is darwin or ios:
<name>.<version>.framework/<name>.<version>lib<name>.<version>.dylib, only if platform is darwin<name>.framework/<name>lib<name>.dylib, only if platform is darwinplatform is linux or android:
lib<name>.<version>.solib<name>.soplatform is win32:
<name>-<version>.dll<name>.dllcandidate of candidates:
options.linkedProtocol concatenated with candidate; if it resolves, stop iterating candidates.platform from options.matchedConditions.Apache-2.0
© 2010 - cnpmjs.org x YWFE | Home | YWFE