ores
v0.1.0
Published
Module resolution utilities based on Node.js upstream implementation.
Downloads
1
Readme
ores
Module resolution utilities for Node.js (based on previous work in unjs/mlly, wooorm/import-meta-resolve, and the upstream Node.js implementation).
This library exposes an API similar to import.meta.resolve based on Node.js upstream implementation and resolution algorithm. It supports all built-in functionalities—package.json, import maps, export maps, CJS, and ESM—with some additions:
- Pure JS with no native dependencies (only Node.js is required).
- Stable and versioned behavior.
- Throws an error if the resolved path does not exist in the filesystem.
- Can resolve
fromusing one or more parent URLs. - Can override the default
conditions.
Usage
Install package:
# ✨ Auto-detect (npm, yarn, pnpm, bun, deno)
npx nypm install oresImport:
// ESM import
import { resolveModuleURL, resolveModulePath } from "ores";
// Or using dynamic import
const { resolveModuleURL, resolveModulePath } = await import("ores");resolveModuleURL(id, {
/* options */
});
resolveModulePath(id, {
/* options */
});Differences between resolveModuleURL and resolveModulePath:
resolveModuleURLreturns a URL string likefile:///app/dep.mjs.resolveModulePathreturns an absolute path like/app/dep.mjs.- If the resolved URL does not use the
file://scheme (for example,data:ornode:), it will throw an error.
- If the resolved URL does not use the
Resolve options
from
- Default: (current working directory)
A URL, path or array of URLs/paths to resolve module against them.
extensions
- Default
[".mjs", ".cjs", ".js", ".json"]
Additional file extensions to consider when resolving modules.
conditions
- Default:
["node", "import"]
Conditions to apply when resolving package exports.
Development
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Run interactive tests using
pnpm dev
License
Published under the MIT license.
Based on previous work in unjs/mlly, wooorm/import-meta-resolve and Node.js original implementation.
