$ npm install @loaderkit/resolve
An accurate & abstract implementation of the nodejs module resolution algorithms. It implements both the CommonJS and modules algorithms. Originally authored for arethetypeswrong.
See also: resolve, enhanced-resolve, and esm-resolve. The main point of this package is accuracy with the default nodejs resolution algorithms.
import { resolve, resolveSync } from '@loaderkit/resolve/esm';
import { resolve as resolveRequire, resolveSync as resolveRequireSync } from '@loaderkit/resolve/cjs';
import { defaultAsyncFileSystem, defaultSyncFileSystem } from '@loaderkit/resolve/fs';
// Async module resolution
const resolution = await resolve(defaultAsyncFileSystem, 'react', new URL(import.meta.url));
console.log(resolution.format, resolution.url);
// format: "addon" | "builtin" | "commonjs" | "json" | "module" | "wasm"
// url: typeof URL
// Synchronous module resolution
resolveSync(defaultSyncFileSystem, 'react', new URL(import.meta.url));
// CommonJS module resolution
await resolveRequire(defaultAsyncFileSystem, 'lodash', new URL(import.meta.url));
resolveRequireSync(defaultSyncFileSystem, 'lodash', new URL(import.meta.url));
The FileSystemAsync and FileSystemSync interfaces can be implemented by client code as
necessary. For example, you could write a delegate to load the module source files from a zip file,
from the internet, or whatever you want.
© 2010 - cnpmjs.org x YWFE | Home | YWFE