UNPKG

4.09 kBTypeScriptView Raw
1/**
2 * @since v0.3.7
3 */
4declare module 'module' {
5 import { URL } from 'node:url';
6 namespace Module {
7 /**
8 * The `module.syncBuiltinESMExports()` method updates all the live bindings for
9 * builtin `ES Modules` to match the properties of the `CommonJS` exports. It
10 * does not add or remove exported names from the `ES Modules`.
11 *
12 * ```js
13 * const fs = require('fs');
14 * const assert = require('assert');
15 * const { syncBuiltinESMExports } = require('module');
16 *
17 * fs.readFile = newAPI;
18 *
19 * delete fs.readFileSync;
20 *
21 * function newAPI() {
22 * // ...
23 * }
24 *
25 * fs.newAPI = newAPI;
26 *
27 * syncBuiltinESMExports();
28 *
29 * import('fs').then((esmFS) => {
30 * // It syncs the existing readFile property with the new value
31 * assert.strictEqual(esmFS.readFile, newAPI);
32 * // readFileSync has been deleted from the required fs
33 * assert.strictEqual('readFileSync' in fs, false);
34 * // syncBuiltinESMExports() does not remove readFileSync from esmFS
35 * assert.strictEqual('readFileSync' in esmFS, true);
36 * // syncBuiltinESMExports() does not add names
37 * assert.strictEqual(esmFS.newAPI, undefined);
38 * });
39 * ```
40 * @since v12.12.0
41 */
42 function syncBuiltinESMExports(): void;
43 /**
44 * `path` is the resolved path for the file for which a corresponding source map
45 * should be fetched.
46 * @since v13.7.0, v12.17.0
47 */
48 function findSourceMap(path: string, error?: Error): SourceMap;
49 interface SourceMapPayload {
50 file: string;
51 version: number;
52 sources: string[];
53 sourcesContent: string[];
54 names: string[];
55 mappings: string;
56 sourceRoot: string;
57 }
58 interface SourceMapping {
59 generatedLine: number;
60 generatedColumn: number;
61 originalSource: string;
62 originalLine: number;
63 originalColumn: number;
64 }
65 /**
66 * @since v13.7.0, v12.17.0
67 */
68 class SourceMap {
69 /**
70 * Getter for the payload used to construct the `SourceMap` instance.
71 */
72 readonly payload: SourceMapPayload;
73 constructor(payload: SourceMapPayload);
74 /**
75 * Given a line number and column number in the generated source file, returns
76 * an object representing the position in the original file. The object returned
77 * consists of the following keys:
78 */
79 findEntry(line: number, column: number): SourceMapping;
80 }
81 }
82 interface Module extends NodeModule {}
83 class Module {
84 static runMain(): void;
85 static wrap(code: string): string;
86 static createRequire(path: string | URL): NodeRequire;
87 static builtinModules: string[];
88 static Module: typeof Module;
89 constructor(id: string, parent?: Module);
90 }
91 global {
92 interface ImportMeta {
93 url: string;
94 /**
95 * @experimental
96 * This feature is only available with the `--experimental-import-meta-resolve`
97 * command flag enabled.
98 *
99 * Provides a module-relative resolution function scoped to each module, returning
100 * the URL string.
101 *
102 * @param specified The module specifier to resolve relative to `parent`.
103 * @param parent The absolute parent module URL to resolve from. If none
104 * is specified, the value of `import.meta.url` is used as the default.
105 */
106 resolve?(specified: string, parent?: string | URL): Promise<string>;
107 }
108 }
109 export = Module;
110}
111declare module 'node:module' {
112 import module = require('module');
113 export = module;
114}