CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mlly

Missing ECMAScript module utils for Node.js

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

module-resolution.mddocs/

Module Resolution

ESM-compliant module resolution with support for custom conditions, extensions, and multiple search paths. Handles Node.js built-ins, file system paths, and various URL protocols following the ECMAScript Resolver algorithm.

Capabilities

Resolve Function

Asynchronously resolves a module path based on the given options.

/**
 * Asynchronously resolves a module path based on the given options
 * @param id - The identifier or path of the module to resolve
 * @param options - Options for resolving the module
 * @returns A promise to resolve the URL as a string
 */
function resolve(id: string, options?: ResolveOptions): Promise<string>;

Usage Examples:

import { resolve } from "mlly";

// Resolve relative module
const url = await resolve("./utils.mjs", { url: import.meta.url });
// Result: "file:///path/to/project/utils.mjs"

// Resolve npm package  
const lodashUrl = await resolve("lodash", { url: import.meta.url });

// Resolve with custom conditions
const devUrl = await resolve("my-package", { 
  conditions: ["development", "import", "node"] 
});

Resolve Sync Function

Synchronously resolves a module path based on the options provided.

/**
 * Synchronously resolves a module path based on the options provided
 * @param id - The identifier or path of the module to resolve
 * @param options - Options to resolve the module
 * @returns The resolved URL as a string
 */
function resolveSync(id: string, options?: ResolveOptions): string;

Resolve Path Function

Asynchronously resolves a module path to a local file path based on the options provided.

/**
 * Asynchronously resolves a module path to a local file path based on the options provided
 * @param id - The identifier or path of the module to resolve
 * @param options - Options for resolving the module
 * @returns A promise to resolve to the file path
 */
function resolvePath(id: string, options?: ResolveOptions): Promise<string>;

Resolve Path Sync Function

Synchronously resolves a module path to a local file path based on the given options.

/**
 * Synchronously resolves a module path to a local file path based on the given options
 * @param id - The identifier or path of the module to resolve
 * @param options - Options to resolve the module
 * @returns The resolved file path
 */
function resolvePathSync(id: string, options?: ResolveOptions): string;

Create Resolve Function

Creates a resolver function with default options that can be used to resolve module identifiers.

/**
 * Creates a resolver function with default options that can be used to resolve module identifiers
 * @param defaults - Default options to use for all resolutions
 * @returns A resolver function that takes an identifier and an optional URL, and resolves the identifier using the default options and the given URL
 */
function createResolve(defaults?: ResolveOptions): (id: string, url?: ResolveOptions["url"]) => Promise<string>;

Usage Example:

import { createResolve } from "mlly";

// Create resolver with defaults
const resolver = createResolve({ url: import.meta.url });

// Use resolver
const moduleUrl = await resolver("./config.mjs");

Parse Node Module Path Function

Parses a node module path to extract the directory, name, and subpath.

/**
 * Parses a node module path to extract the directory, name, and subpath
 * @param path - The path to parse
 * @returns An object containing the directory, module name, and subpath of the node module
 */
function parseNodeModulePath(path: string): {
  dir?: string;
  name?: string;
  subpath?: string;
};

Usage Example:

import { parseNodeModulePath } from "mlly";

const result = parseNodeModulePath("/project/node_modules/lodash/dist/lodash.js");
// Result: { dir: "/project/node_modules/", name: "lodash", subpath: "./dist/lodash.js" }

Lookup Node Module Subpath Function

Attempts to reverse engineer a subpath export within a node module.

/**
 * Attempts to reverse engineer a subpath export within a node module
 * @param path - The path within the node module
 * @returns A promise that resolves to the detected subpath or undefined if not found
 */
function lookupNodeModuleSubpath(path: string): Promise<string | undefined>;

Types

interface ResolveOptions {
  /** A URL, path or array of URLs/paths to resolve against */
  url?: string | URL | (string | URL)[];
  /** File extensions to consider when resolving modules */
  extensions?: string[];
  /** Conditions to consider when resolving package exports */
  conditions?: string[];
}

docs

commonjs-context.md

import-export-analysis.md

index.md

module-evaluation.md

module-resolution.md

syntax-detection.md

utility-functions.md

tile.json