mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
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.
114 lines
5.0 KiB
TypeScript
114 lines
5.0 KiB
TypeScript
/// <reference path="./stream.d.ts" />
|
|
|
|
/* node:worker_threads — native workers use statically compiled entry points.
|
|
* Lowering and runtime diagnostics define the supported options and methods. */
|
|
declare module "worker_threads" {
|
|
export const isMainThread: boolean;
|
|
export const isInternalThread: boolean;
|
|
export const threadId: number;
|
|
export interface ResourceLimits {
|
|
maxYoungGenerationSizeMb?: number;
|
|
maxOldGenerationSizeMb?: number;
|
|
codeRangeSizeMb?: number;
|
|
stackSizeMb?: number;
|
|
}
|
|
/* {} in the main thread */
|
|
export const resourceLimits: ResourceLimits;
|
|
/* the Worker's name option, trimmed ("WorkerThread" by default); "" in the main thread */
|
|
export const threadName: string | null;
|
|
export interface WorkerOptions {
|
|
workerData?: unknown;
|
|
transferList?: readonly unknown[];
|
|
argv?: readonly unknown[];
|
|
name?: string;
|
|
resourceLimits?: ResourceLimits;
|
|
stdout?: boolean;
|
|
stderr?: boolean;
|
|
stdin?: boolean;
|
|
[option: string]: unknown;
|
|
}
|
|
export class Worker {
|
|
constructor(filename: string | URL, options?: WorkerOptions);
|
|
readonly threadId: number;
|
|
readonly resourceLimits?: ResourceLimits;
|
|
readonly threadName: string | null;
|
|
/* with the stdout/stderr options: the worker's writes to those streams */
|
|
readonly stdout: import("stream").Readable;
|
|
readonly stderr: import("stream").Readable;
|
|
/* with the stdin option: what the worker reads from process.stdin */
|
|
readonly stdin: import("stream").Writable | null;
|
|
/* terminate(), resolving with undefined once the worker exited */
|
|
[Symbol.asyncDispose](): Promise<void>;
|
|
on(event: "online", listener: () => void): this;
|
|
on(event: "message", listener: (value: any) => void): this;
|
|
on(event: "error", listener: (error: any) => void): this;
|
|
on(event: "exit", listener: (code: number) => void): this;
|
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
off(event: string, listener: (...args: any[]) => void): this;
|
|
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
postMessage(value: unknown, transferList?: readonly unknown[]): void;
|
|
ref(): void;
|
|
unref(): void;
|
|
terminate(): Promise<number>;
|
|
removeAllListeners(event?: string): this;
|
|
listenerCount(event: string, listener?: (...args: any[]) => void): number;
|
|
}
|
|
export class MessagePort {
|
|
on(event: "message", listener: (value: any) => void): this;
|
|
on(event: "close", listener: () => void): this;
|
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
off(event: string, listener: (...args: any[]) => void): this;
|
|
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
postMessage(value: unknown, transferList?: readonly unknown[]): void;
|
|
start(): void;
|
|
close(callback?: () => void): void;
|
|
ref(): void;
|
|
unref(): void;
|
|
hasRef(): boolean;
|
|
removeAllListeners(event?: string): this;
|
|
listenerCount(event: string, listener?: (...args: any[]) => void): number;
|
|
}
|
|
/* Two entangled ports; a port moves to another thread through a
|
|
* postMessage or workerData transferList. */
|
|
export class MessageChannel {
|
|
readonly port1: MessagePort;
|
|
readonly port2: MessagePort;
|
|
}
|
|
export function receiveMessageOnPort(port: MessagePort): { message: any } | undefined;
|
|
/* This thread's environment data; each new Worker starts from a clone. */
|
|
export function setEnvironmentData(key: any, value?: any): void;
|
|
export function getEnvironmentData(key: any): any;
|
|
/* A marked object cannot be listed in a transfer list. */
|
|
export function markAsUntransferable(object: any): void;
|
|
/* structuredClone and postMessage throw DataCloneError for a marked
|
|
* object, error or class instance */
|
|
export function markAsUncloneable(object: any): void;
|
|
export function isMarkedAsUntransferable(object: any): boolean;
|
|
/* Delivers each message to every other open channel with the name, in
|
|
* any thread, as a 'message' MessageEvent. */
|
|
export class BroadcastChannel extends EventTarget {
|
|
constructor(name: string);
|
|
readonly name: string;
|
|
onmessage: ((event: MessageEvent) => void) | null;
|
|
onmessageerror: ((event: MessageEvent) => void) | null;
|
|
postMessage(message: unknown): void;
|
|
close(): void;
|
|
ref(): this;
|
|
unref(): this;
|
|
}
|
|
export const parentPort: MessagePort | null;
|
|
export const workerData: any;
|
|
}
|
|
|
|
declare module "node:worker_threads" {
|
|
export * from "worker_threads";
|
|
}
|