bare-module-resolve
Reference for bare-module-resolve: the low-level module resolution algorithm for Bare, exposed as a synchronous or asynchronous generator.
bare-module-resolve implements Bare's low-level module resolution algorithm. It's a pure-JavaScript generator that yields candidate URLs for a specifier; the caller supplies package reads and decides which candidate exists.
npm i bare-module-resolveUsage
const resolve = require('bare-module-resolve')
function readPackage (url) {
// Read and parse `url` if it exists, otherwise return null
}
for (const resolution of resolve('./file.js', new URL('file:///directory/'), readPackage)) {
console.log(resolution)
}An asynchronous form is also supported by iterating the resolver with for await.
API
const resolver = resolve(specifier, parentURL[, options][, readPackage])
Create a resolver for specifier relative to parentURL. Iterate it synchronously (for (const resolution of resolver)) or asynchronously (for await); each yielded value is a candidate URL to test.
Sub-generators
The algorithm's steps are exposed for fine-grained use: resolve.module, resolve.url, resolve.preresolved, resolve.deferred, resolve.package, resolve.packageSelf, resolve.packageExports, resolve.packageImports, resolve.packageImportsExports, resolve.packageTarget, resolve.builtinTarget, resolve.file, and resolve.directory. See the repository README for each step's signature and options.
Related modules
Builds on bare-semver. Paired with bare-addon-resolve and bare-module-traverse.
See also
bare-module-traverse—walk a whole module graph using this resolver.bare-addon-resolve—the matching algorithm for native addons.- Bare modules—the full
bare-*catalog.