Files
scriptc/packages/compiler/ambient/node-fallback/path.d.ts
T
Chris Tate f0f91ac1ff Load a Node module's fallback declarations only when the program names it
Without @types/node, every program loaded scriptc-node-fallback.d.ts whole:
the console and process globals and 47 Node modules, about 8,100 lines,
parsed, bound and checked in every cold build whether or not the program
imported them.

- The fallback file keeps the globals and the modules they name (console,
  readline, readline/promises, perf_hooks, tty). Every other module, under
  both spellings, has its own file in ambient/node-fallback/, which
  references the files of the modules its declarations name.
- A module's file joins the program when one of the program's files names
  the module in a string literal: imports, requires, import types and JSDoc
  types all name modules that way. The entry is read before the first
  program; the program-root discovery passes add modules that other files
  name. Files are read as tsgo reads them, and the TypeScript libraries and
  scriptc's own declarations are skipped.
- The checks that recognized the fallback file by its path recognize every
  fallback file.
2026-10-25 15:36:08 -05:00

56 lines
2.4 KiB
TypeScript

/// <reference path="./path-posix.d.ts" />
/// <reference path="./path-win32.d.ts" />
/* node:path — the TARGET platform's implementation (Node's rule): posix
* on posix triples, path.win32 under a win32 triple, with the posix and
* win32 namespaces answering their own platform anywhere. Every function
* is a pure string algorithm matching Node's implementations
* exactly; join/resolve are variadic like Node's. */
declare module "path" {
export function join(...paths: string[]): string;
export function resolve(...paths: string[]): string;
export function normalize(path: string): string;
export function dirname(path: string): string;
export function basename(path: string, suffix?: string): string;
export function extname(path: string): string;
export function isAbsolute(path: string): boolean;
export function relative(from: string, to: string): string;
export function toNamespacedPath(path: string): string;
/* matchesGlob() is Node's glob matcher: brace expansion, extglobs, POSIX
* classes and the ** and dot rules. */
export function matchesGlob(path: string, pattern: string): boolean;
/* parse() splits a path into its root, directory, base, extension and
* name; format() joins those fields back (Node's `||` defaults). */
export interface ParsedPath {
root: string;
dir: string;
base: string;
ext: string;
name: string;
}
export interface FormatInputPathObject {
root?: string | undefined;
dir?: string | undefined;
base?: string | undefined;
ext?: string | undefined;
name?: string | undefined;
}
export function parse(path: string): ParsedPath;
export function format(pathObject: FormatInputPathObject): string;
/* The union @types/node declares: the bare module answers the TARGET
* platform's value (a compile-time constant — "\\"/";" under a win32
* triple, "/"/":" everywhere else). */
export const sep: "\\" | "/";
export const delimiter: ";" | ":";
/* The platform-specific namespaces (real Node submodules too —
* "node:path/posix" resolves). Each carries the FULL surface and
* answers ITS platform's rules on any target, Node's own contract;
* the bare module IS the target platform's implementation. */
export const posix: typeof import("path/posix");
export const win32: typeof import("path/win32");
}
declare module "node:path" {
export * from "path";
}