Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libdefs: add typings for node's built-in Module module #8540

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,68 @@ type net$connectOptions = {
...
};

declare module "module" {
declare type FilePath = string;
gorakong marked this conversation as resolved.
Show resolved Hide resolved

declare class Module {
constructor(id: FilePath, parent?: Module): void;
id: string;
path: FilePath;
paths: FilePath[];
exports: {|[export: string]: mixed|};
filename: string;
loaded: boolean;
children: Module[];
globalPaths: FilePath[];
load(fileName: string): void;
require: (request: string) => {|[export: string]: mixed|};
syncBuiltinESMExports(): void;

static runMain(): void;
static wrap(code: string): string;

/**
* Deprecated since: v12.2.0. Please use createRequire() instead.
*/
static createRequireFromPath(path: string): (request: string) => {|[export: string]: mixed|};
static createRequire(path: string | URL): (request: string) => {|[export: string]: mixed|};
static builtinModules: string[];
static _cache: {|[key: FilePath]: Module|};
static _pathCache: {|[cacheKey: string]: FilePath|};
static _nodeModulePaths(from: FilePath): FilePath[];
static _initPaths(): void;
static findPnpApi(lookupSource: string): PnpApi | null;

static _findPath(
request: FilePath,
paths: FilePath[],
isMain: boolean,
): FilePath | false;

static _extensions: {|
[extension: string]: (module: Module, fileName: string) => void,
|};

static _resolveLookupPaths(
request: FilePath,
parent: Module,
): FilePath[] | null;

static _load(
request: FilePath,
parent: Module,
isMain: boolean,
): {|[export: string]: mixed|};

static _resolveFilename: (
request: string,
parent?: Module,
isMain?: boolean,
options?: {|paths?: FilePath[]|},
) => string | false;
}
}

declare module "net" {

declare class Server extends net$Server {}
Expand Down