@types/node 20.19.25 → 24.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. {node v20.19 → node v24.10}/README.md +3 -3
  2. node v24.10/assert/strict.d.ts +111 -0
  3. {node v20.19 → node v24.10}/assert.d.ts +150 -97
  4. {node v20.19 → node v24.10}/async_hooks.d.ts +27 -9
  5. {node v20.19 → node v24.10}/buffer.buffer.d.ts +2 -1
  6. {node v20.19 → node v24.10}/buffer.d.ts +6 -8
  7. {node v20.19 → node v24.10}/child_process.d.ts +11 -10
  8. {node v20.19 → node v24.10}/cluster.d.ts +16 -15
  9. {node v20.19 → node v24.10}/console.d.ts +19 -18
  10. {node v20.19 → node v24.10}/crypto.d.ts +1120 -293
  11. {node v20.19 → node v24.10}/dgram.d.ts +5 -2
  12. {node v20.19 → node v24.10}/diagnostics_channel.d.ts +1 -3
  13. {node v20.19 → node v24.10}/dns/promises.d.ts +30 -6
  14. {node v20.19 → node v24.10}/dns.d.ts +69 -17
  15. {node v20.19 → node v24.10}/domain.d.ts +1 -1
  16. {node v20.19 → node v24.10}/events.d.ts +1 -2
  17. {node v20.19 → node v24.10}/fs/promises.d.ts +85 -38
  18. {node v20.19 → node v24.10}/fs.d.ts +387 -48
  19. {node v20.19 → node v24.10}/globals.d.ts +2 -4
  20. {node v20.19 → node v24.10}/globals.typedarray.d.ts +3 -0
  21. {node v20.19 → node v24.10}/http.d.ts +90 -5
  22. {node v20.19 → node v24.10}/http2.d.ts +166 -41
  23. {node v20.19 → node v24.10}/https.d.ts +4 -3
  24. {node v20.19 → node v24.10}/index.d.ts +13 -5
  25. node v24.10/inspector.d.ts +277 -0
  26. {node v20.19 → node v24.10}/inspector.generated.d.ts +1096 -829
  27. {node v20.19 → node v24.10}/module.d.ts +403 -48
  28. {node v20.19 → node v24.10}/net.d.ts +62 -20
  29. {node v20.19 → node v24.10}/os.d.ts +8 -7
  30. {node v20.19 → node v24.10}/package.json +18 -3
  31. {node v20.19 → node v24.10}/path.d.ts +3 -3
  32. {node v20.19 → node v24.10}/perf_hooks.d.ts +37 -16
  33. {node v20.19 → node v24.10}/process.d.ts +133 -16
  34. {node v20.19 → node v24.10}/punycode.d.ts +1 -1
  35. {node v20.19 → node v24.10}/querystring.d.ts +1 -1
  36. {node v20.19 → node v24.10}/readline/promises.d.ts +0 -1
  37. {node v20.19 → node v24.10}/readline.d.ts +19 -14
  38. {node v20.19 → node v24.10}/repl.d.ts +25 -17
  39. {node v20.19 → node v24.10}/sea.d.ts +11 -2
  40. node v24.10/sqlite.d.ts +937 -0
  41. {node v20.19 → node v24.10}/stream/web.d.ts +85 -45
  42. {node v20.19 → node v24.10}/stream.d.ts +36 -28
  43. {node v20.19 → node v24.10}/string_decoder.d.ts +1 -1
  44. {node v20.19 → node v24.10}/test.d.ts +587 -35
  45. {node v20.19 → node v24.10}/timers/promises.d.ts +1 -1
  46. {node v20.19 → node v24.10}/timers.d.ts +4 -5
  47. {node v20.19 → node v24.10}/tls.d.ts +62 -48
  48. {node v20.19 → node v24.10}/trace_events.d.ts +6 -6
  49. node v24.10/ts5.6/compatibility/float16array.d.ts +71 -0
  50. {node v20.19 → node v24.10}/ts5.6/globals.typedarray.d.ts +2 -0
  51. {node v20.19 → node v24.10}/ts5.6/index.d.ts +15 -5
  52. node v24.10/ts5.7/compatibility/float16array.d.ts +72 -0
  53. node v24.10/ts5.7/index.d.ts +103 -0
  54. {node v20.19 → node v24.10}/tty.d.ts +1 -1
  55. {node v20.19 → node v24.10}/url.d.ts +128 -35
  56. {node v20.19 → node v24.10}/util.d.ts +384 -390
  57. {node v20.19 → node v24.10}/v8.d.ts +175 -32
  58. {node v20.19 → node v24.10}/vm.d.ts +246 -67
  59. {node v20.19 → node v24.10}/wasi.d.ts +23 -2
  60. node v24.10/web-globals/crypto.d.ts +32 -0
  61. {node v20.19 → node v24.10}/web-globals/fetch.d.ts +4 -0
  62. node v24.10/web-globals/navigator.d.ts +25 -0
  63. node v24.10/web-globals/storage.d.ts +24 -0
  64. node v24.10/web-globals/streams.d.ts +22 -0
  65. {node v20.19 → node v24.10}/worker_threads.d.ts +205 -24
  66. {node v20.19 → node v24.10}/zlib.d.ts +185 -44
  67. node v20.19/assert/strict.d.ts +0 -8
  68. node v20.19/compatibility/disposable.d.ts +0 -16
  69. node v20.19/compatibility/index.d.ts +0 -9
  70. node v20.19/compatibility/indexable.d.ts +0 -20
  71. {node v20.19 → node v24.10}/LICENSE +0 -0
  72. {node v20.19 → node v24.10}/compatibility/iterators.d.ts +0 -0
  73. {node v20.19 → node v24.10}/constants.d.ts +0 -0
  74. {node v20.19 → node v24.10}/stream/consumers.d.ts +0 -0
  75. {node v20.19 → node v24.10}/stream/promises.d.ts +0 -0
  76. {node v20.19 → node v24.10}/ts5.6/buffer.buffer.d.ts +0 -0
  77. {node v20.19 → node v24.10}/web-globals/abortcontroller.d.ts +0 -0
  78. {node v20.19 → node v24.10}/web-globals/domexception.d.ts +0 -0
  79. {node v20.19 → node v24.10}/web-globals/events.d.ts +0 -0
@@ -3,7 +3,6 @@
3
3
  */
4
4
  declare module "module" {
5
5
  import { URL } from "node:url";
6
- import { MessagePort } from "node:worker_threads";
7
6
  class Module {
8
7
  constructor(id: string, parent?: Module);
9
8
  }
@@ -27,6 +26,156 @@ declare module "module" {
27
26
  * string.
28
27
  */
29
28
  function createRequire(path: string | URL): NodeJS.Require;
29
+ namespace constants {
30
+ /**
31
+ * The following constants are returned as the `status` field in the object returned by
32
+ * {@link enableCompileCache} to indicate the result of the attempt to enable the
33
+ * [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache).
34
+ * @since v22.8.0
35
+ */
36
+ namespace compileCacheStatus {
37
+ /**
38
+ * Node.js has enabled the compile cache successfully. The directory used to store the
39
+ * compile cache will be returned in the `directory` field in the
40
+ * returned object.
41
+ */
42
+ const ENABLED: number;
43
+ /**
44
+ * The compile cache has already been enabled before, either by a previous call to
45
+ * {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir`
46
+ * environment variable. The directory used to store the
47
+ * compile cache will be returned in the `directory` field in the
48
+ * returned object.
49
+ */
50
+ const ALREADY_ENABLED: number;
51
+ /**
52
+ * Node.js fails to enable the compile cache. This can be caused by the lack of
53
+ * permission to use the specified directory, or various kinds of file system errors.
54
+ * The detail of the failure will be returned in the `message` field in the
55
+ * returned object.
56
+ */
57
+ const FAILED: number;
58
+ /**
59
+ * Node.js cannot enable the compile cache because the environment variable
60
+ * `NODE_DISABLE_COMPILE_CACHE=1` has been set.
61
+ */
62
+ const DISABLED: number;
63
+ }
64
+ }
65
+ interface EnableCompileCacheResult {
66
+ /**
67
+ * One of the {@link constants.compileCacheStatus}
68
+ */
69
+ status: number;
70
+ /**
71
+ * If Node.js cannot enable the compile cache, this contains
72
+ * the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
73
+ */
74
+ message?: string;
75
+ /**
76
+ * If the compile cache is enabled, this contains the directory
77
+ * where the compile cache is stored. Only set if `status` is
78
+ * `module.constants.compileCacheStatus.ENABLED` or
79
+ * `module.constants.compileCacheStatus.ALREADY_ENABLED`.
80
+ */
81
+ directory?: string;
82
+ }
83
+ /**
84
+ * Enable [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
85
+ * in the current Node.js instance.
86
+ *
87
+ * If `cacheDir` is not specified, Node.js will either use the directory specified by the
88
+ * `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use
89
+ * `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
90
+ * recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
91
+ * so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
92
+ * variable when necessary.
93
+ *
94
+ * Since compile cache is supposed to be a quiet optimization that is not required for the
95
+ * application to be functional, this method is designed to not throw any exception when the
96
+ * compile cache cannot be enabled. Instead, it will return an object containing an error
97
+ * message in the `message` field to aid debugging.
98
+ * If compile cache is enabled successfully, the `directory` field in the returned object
99
+ * contains the path to the directory where the compile cache is stored. The `status`
100
+ * field in the returned object would be one of the `module.constants.compileCacheStatus`
101
+ * values to indicate the result of the attempt to enable the
102
+ * [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache).
103
+ *
104
+ * This method only affects the current Node.js instance. To enable it in child worker threads,
105
+ * either call this method in child worker threads too, or set the
106
+ * `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
107
+ * be inherited into the child workers. The directory can be obtained either from the
108
+ * `directory` field returned by this method, or with {@link getCompileCacheDir}.
109
+ * @since v22.8.0
110
+ * @param cacheDir Optional path to specify the directory where the compile cache
111
+ * will be stored/retrieved.
112
+ */
113
+ function enableCompileCache(cacheDir?: string): EnableCompileCacheResult;
114
+ /**
115
+ * Flush the [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
116
+ * accumulated from modules already loaded
117
+ * in the current Node.js instance to disk. This returns after all the flushing
118
+ * file system operations come to an end, no matter they succeed or not. If there
119
+ * are any errors, this will fail silently, since compile cache misses should not
120
+ * interfere with the actual operation of the application.
121
+ * @since v22.10.0
122
+ */
123
+ function flushCompileCache(): void;
124
+ /**
125
+ * @since v22.8.0
126
+ * @return Path to the [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
127
+ * directory if it is enabled, or `undefined` otherwise.
128
+ */
129
+ function getCompileCacheDir(): string | undefined;
130
+ /**
131
+ * ```text
132
+ * /path/to/project
133
+ * ├ packages/
134
+ * ├ bar/
135
+ * ├ bar.js
136
+ * └ package.json // name = '@foo/bar'
137
+ * └ qux/
138
+ * ├ node_modules/
139
+ * └ some-package/
140
+ * └ package.json // name = 'some-package'
141
+ * ├ qux.js
142
+ * └ package.json // name = '@foo/qux'
143
+ * ├ main.js
144
+ * └ package.json // name = '@foo'
145
+ * ```
146
+ * ```js
147
+ * // /path/to/project/packages/bar/bar.js
148
+ * import { findPackageJSON } from 'node:module';
149
+ *
150
+ * findPackageJSON('..', import.meta.url);
151
+ * // '/path/to/project/package.json'
152
+ * // Same result when passing an absolute specifier instead:
153
+ * findPackageJSON(new URL('../', import.meta.url));
154
+ * findPackageJSON(import.meta.resolve('../'));
155
+ *
156
+ * findPackageJSON('some-package', import.meta.url);
157
+ * // '/path/to/project/packages/bar/node_modules/some-package/package.json'
158
+ * // When passing an absolute specifier, you might get a different result if the
159
+ * // resolved module is inside a subfolder that has nested `package.json`.
160
+ * findPackageJSON(import.meta.resolve('some-package'));
161
+ * // '/path/to/project/packages/bar/node_modules/some-package/some-subfolder/package.json'
162
+ *
163
+ * findPackageJSON('@foo/qux', import.meta.url);
164
+ * // '/path/to/project/packages/qux/package.json'
165
+ * ```
166
+ * @since v22.14.0
167
+ * @param specifier The specifier for the module whose `package.json` to
168
+ * retrieve. When passing a _bare specifier_, the `package.json` at the root of
169
+ * the package is returned. When passing a _relative specifier_ or an _absolute specifier_,
170
+ * the closest parent `package.json` is returned.
171
+ * @param base The absolute location (`file:` URL string or FS path) of the
172
+ * containing module. For CJS, use `__filename` (not `__dirname`!); for ESM, use
173
+ * `import.meta.url`. You do not need to pass it if `specifier` is an _absolute specifier_.
174
+ * @returns A path if the `package.json` is found. When `startLocation`
175
+ * is a package, the package's root `package.json`; when a relative or unresolved, the closest
176
+ * `package.json` to the `startLocation`.
177
+ */
178
+ function findPackageJSON(specifier: string | URL, base?: string | URL): string | undefined;
30
179
  /**
31
180
  * @since v18.6.0, v16.17.0
32
181
  */
@@ -45,7 +194,7 @@ declare module "module" {
45
194
  */
46
195
  data?: Data | undefined;
47
196
  /**
48
- * [Transferable objects](https://nodejs.org/docs/latest-v20.x/api/worker_threads.html#portpostmessagevalue-transferlist)
197
+ * [Transferable objects](https://nodejs.org/docs/latest-v24.x/api/worker_threads.html#portpostmessagevalue-transferlist)
49
198
  * to be passed into the `initialize` hook.
50
199
  */
51
200
  transferList?: any[] | undefined;
@@ -54,7 +203,10 @@ declare module "module" {
54
203
  /**
55
204
  * Register a module that exports hooks that customize Node.js module
56
205
  * resolution and loading behavior. See
57
- * [Customization hooks](https://nodejs.org/docs/latest-v20.x/api/module.html#customization-hooks).
206
+ * [Customization hooks](https://nodejs.org/docs/latest-v24.x/api/module.html#customization-hooks).
207
+ *
208
+ * This feature requires `--allow-worker` if used with the
209
+ * [Permission Model](https://nodejs.org/docs/latest-v24.x/api/permissions.html#permission-model).
58
210
  * @since v20.6.0, v18.19.0
59
211
  * @param specifier Customization hooks to be registered; this should be
60
212
  * the same string that would be passed to `import()`, except that if it is
@@ -68,6 +220,105 @@ declare module "module" {
68
220
  options?: RegisterOptions<Data>,
69
221
  ): void;
70
222
  function register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
223
+ interface RegisterHooksOptions {
224
+ /**
225
+ * See [load hook](https://nodejs.org/docs/latest-v24.x/api/module.html#loadurl-context-nextload).
226
+ * @default undefined
227
+ */
228
+ load?: LoadHookSync | undefined;
229
+ /**
230
+ * See [resolve hook](https://nodejs.org/docs/latest-v24.x/api/module.html#resolvespecifier-context-nextresolve).
231
+ * @default undefined
232
+ */
233
+ resolve?: ResolveHookSync | undefined;
234
+ }
235
+ interface ModuleHooks {
236
+ /**
237
+ * Deregister the hook instance.
238
+ */
239
+ deregister(): void;
240
+ }
241
+ /**
242
+ * Register [hooks](https://nodejs.org/docs/latest-v24.x/api/module.html#customization-hooks)
243
+ * that customize Node.js module resolution and loading behavior.
244
+ * @since v22.15.0
245
+ * @experimental
246
+ */
247
+ function registerHooks(options: RegisterHooksOptions): ModuleHooks;
248
+ interface StripTypeScriptTypesOptions {
249
+ /**
250
+ * Possible values are:
251
+ * * `'strip'` Only strip type annotations without performing the transformation of TypeScript features.
252
+ * * `'transform'` Strip type annotations and transform TypeScript features to JavaScript.
253
+ * @default 'strip'
254
+ */
255
+ mode?: "strip" | "transform" | undefined;
256
+ /**
257
+ * Only when `mode` is `'transform'`, if `true`, a source map
258
+ * will be generated for the transformed code.
259
+ * @default false
260
+ */
261
+ sourceMap?: boolean | undefined;
262
+ /**
263
+ * Specifies the source url used in the source map.
264
+ */
265
+ sourceUrl?: string | undefined;
266
+ }
267
+ /**
268
+ * `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It
269
+ * can be used to strip type annotations from TypeScript code before running it
270
+ * with `vm.runInContext()` or `vm.compileFunction()`.
271
+ * By default, it will throw an error if the code contains TypeScript features
272
+ * that require transformation such as `Enums`,
273
+ * see [type-stripping](https://nodejs.org/docs/latest-v24.x/api/typescript.md#type-stripping) for more information.
274
+ * When mode is `'transform'`, it also transforms TypeScript features to JavaScript,
275
+ * see [transform TypeScript features](https://nodejs.org/docs/latest-v24.x/api/typescript.md#typescript-features) for more information.
276
+ * When mode is `'strip'`, source maps are not generated, because locations are preserved.
277
+ * If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown.
278
+ *
279
+ * _WARNING_: The output of this function should not be considered stable across Node.js versions,
280
+ * due to changes in the TypeScript parser.
281
+ *
282
+ * ```js
283
+ * import { stripTypeScriptTypes } from 'node:module';
284
+ * const code = 'const a: number = 1;';
285
+ * const strippedCode = stripTypeScriptTypes(code);
286
+ * console.log(strippedCode);
287
+ * // Prints: const a = 1;
288
+ * ```
289
+ *
290
+ * If `sourceUrl` is provided, it will be used appended as a comment at the end of the output:
291
+ *
292
+ * ```js
293
+ * import { stripTypeScriptTypes } from 'node:module';
294
+ * const code = 'const a: number = 1;';
295
+ * const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' });
296
+ * console.log(strippedCode);
297
+ * // Prints: const a = 1\n\n//# sourceURL=source.ts;
298
+ * ```
299
+ *
300
+ * When `mode` is `'transform'`, the code is transformed to JavaScript:
301
+ *
302
+ * ```js
303
+ * import { stripTypeScriptTypes } from 'node:module';
304
+ * const code = `
305
+ * namespace MathUtil {
306
+ * export const add = (a: number, b: number) => a + b;
307
+ * }`;
308
+ * const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true });
309
+ * console.log(strippedCode);
310
+ * // Prints:
311
+ * // var MathUtil;
312
+ * // (function(MathUtil) {
313
+ * // MathUtil.add = (a, b)=>a + b;
314
+ * // })(MathUtil || (MathUtil = {}));
315
+ * // # sourceMappingURL=data:application/json;base64, ...
316
+ * ```
317
+ * @since v22.13.0
318
+ * @param code The code to strip type annotations from.
319
+ * @returns The code with type annotations stripped.
320
+ */
321
+ function stripTypeScriptTypes(code: string, options?: StripTypeScriptTypesOptions): string;
71
322
  /* eslint-enable @definitelytyped/no-unnecessary-generics */
72
323
  /**
73
324
  * The `module.syncBuiltinESMExports()` method updates all the live bindings for
@@ -105,12 +356,19 @@ declare module "module" {
105
356
  * @since v12.12.0
106
357
  */
107
358
  function syncBuiltinESMExports(): void;
108
- /** @deprecated Use `ImportAttributes` instead */
109
- interface ImportAssertions extends ImportAttributes {}
110
359
  interface ImportAttributes extends NodeJS.Dict<string> {
111
360
  type?: string | undefined;
112
361
  }
113
- type ModuleFormat = "builtin" | "commonjs" | "json" | "module" | "wasm";
362
+ type ImportPhase = "source" | "evaluation";
363
+ type ModuleFormat =
364
+ | "addon"
365
+ | "builtin"
366
+ | "commonjs"
367
+ | "commonjs-typescript"
368
+ | "json"
369
+ | "module"
370
+ | "module-typescript"
371
+ | "wasm";
114
372
  type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
115
373
  /**
116
374
  * The `initialize` hook provides a way to define a custom function that runs in
@@ -128,10 +386,6 @@ declare module "module" {
128
386
  * Export conditions of the relevant `package.json`
129
387
  */
130
388
  conditions: string[];
131
- /**
132
- * @deprecated Use `importAttributes` instead
133
- */
134
- importAssertions: ImportAttributes;
135
389
  /**
136
390
  * An object whose key-value pairs represent the assertions for the module to import
137
391
  */
@@ -143,13 +397,9 @@ declare module "module" {
143
397
  }
144
398
  interface ResolveFnOutput {
145
399
  /**
146
- * A hint to the load hook (it might be ignored)
400
+ * A hint to the load hook (it might be ignored); can be an intermediary value.
147
401
  */
148
- format?: ModuleFormat | null | undefined;
149
- /**
150
- * @deprecated Use `importAttributes` instead
151
- */
152
- importAssertions?: ImportAttributes | undefined;
402
+ format?: string | null | undefined;
153
403
  /**
154
404
  * The import attributes to use when caching the module (optional; if excluded the input will be used)
155
405
  */
@@ -181,19 +431,23 @@ declare module "module" {
181
431
  context?: Partial<ResolveHookContext>,
182
432
  ) => ResolveFnOutput | Promise<ResolveFnOutput>,
183
433
  ) => ResolveFnOutput | Promise<ResolveFnOutput>;
434
+ type ResolveHookSync = (
435
+ specifier: string,
436
+ context: ResolveHookContext,
437
+ nextResolve: (
438
+ specifier: string,
439
+ context?: Partial<ResolveHookContext>,
440
+ ) => ResolveFnOutput,
441
+ ) => ResolveFnOutput;
184
442
  interface LoadHookContext {
185
443
  /**
186
444
  * Export conditions of the relevant `package.json`
187
445
  */
188
446
  conditions: string[];
189
447
  /**
190
- * The format optionally supplied by the `resolve` hook chain
448
+ * The format optionally supplied by the `resolve` hook chain (can be an intermediary value).
191
449
  */
192
- format: ModuleFormat | null | undefined;
193
- /**
194
- * @deprecated Use `importAttributes` instead
195
- */
196
- importAssertions: ImportAttributes;
450
+ format: string | null | undefined;
197
451
  /**
198
452
  * An object whose key-value pairs represent the assertions for the module to import
199
453
  */
@@ -224,18 +478,34 @@ declare module "module" {
224
478
  context?: Partial<LoadHookContext>,
225
479
  ) => LoadFnOutput | Promise<LoadFnOutput>,
226
480
  ) => LoadFnOutput | Promise<LoadFnOutput>;
227
- interface GlobalPreloadContext {
228
- port: MessagePort;
481
+ type LoadHookSync = (
482
+ url: string,
483
+ context: LoadHookContext,
484
+ nextLoad: (
485
+ url: string,
486
+ context?: Partial<LoadHookContext>,
487
+ ) => LoadFnOutput,
488
+ ) => LoadFnOutput;
489
+ interface SourceMapsSupport {
490
+ /**
491
+ * If the source maps support is enabled
492
+ */
493
+ enabled: boolean;
494
+ /**
495
+ * If the support is enabled for files in `node_modules`.
496
+ */
497
+ nodeModules: boolean;
498
+ /**
499
+ * If the support is enabled for generated code from `eval` or `new Function`.
500
+ */
501
+ generatedCode: boolean;
229
502
  }
230
503
  /**
231
- * Sometimes it might be necessary to run some code inside of the same global
232
- * scope that the application runs in. This hook allows the return of a string
233
- * that is run as a sloppy-mode script on startup.
234
- * @deprecated This hook will be removed in a future version. Use
235
- * `initialize` instead. When a hooks module has an `initialize` export,
236
- * `globalPreload` will be ignored.
504
+ * This method returns whether the [Source Map v3](https://tc39.es/ecma426/) support for stack
505
+ * traces is enabled.
506
+ * @since v23.7.0, v22.14.0
237
507
  */
238
- type GlobalPreloadHook = (context: GlobalPreloadContext) => string;
508
+ function getSourceMapsSupport(): SourceMapsSupport;
239
509
  /**
240
510
  * `path` is the resolved path for the file for which a corresponding source map
241
511
  * should be fetched.
@@ -243,9 +513,36 @@ declare module "module" {
243
513
  * @return Returns `module.SourceMap` if a source map is found, `undefined` otherwise.
244
514
  */
245
515
  function findSourceMap(path: string): SourceMap | undefined;
516
+ interface SetSourceMapsSupportOptions {
517
+ /**
518
+ * If enabling the support for files in `node_modules`.
519
+ * @default false
520
+ */
521
+ nodeModules?: boolean | undefined;
522
+ /**
523
+ * If enabling the support for generated code from `eval` or `new Function`.
524
+ * @default false
525
+ */
526
+ generatedCode?: boolean | undefined;
527
+ }
528
+ /**
529
+ * This function enables or disables the [Source Map v3](https://tc39.es/ecma426/) support for
530
+ * stack traces.
531
+ *
532
+ * It provides same features as launching Node.js process with commandline options
533
+ * `--enable-source-maps`, with additional options to alter the support for files
534
+ * in `node_modules` or generated codes.
535
+ *
536
+ * Only source maps in JavaScript files that are loaded after source maps has been
537
+ * enabled will be parsed and loaded. Preferably, use the commandline options
538
+ * `--enable-source-maps` to avoid losing track of source maps of modules loaded
539
+ * before this API call.
540
+ * @since v23.7.0, v22.14.0
541
+ */
542
+ function setSourceMapsSupport(enabled: boolean, options?: SetSourceMapsSupportOptions): void;
246
543
  interface SourceMapConstructorOptions {
247
544
  /**
248
- * @since v20.5.0
545
+ * @since v21.0.0, v20.5.0
249
546
  */
250
547
  lineLengths?: readonly number[] | undefined;
251
548
  }
@@ -328,34 +625,91 @@ declare module "module" {
328
625
  global {
329
626
  interface ImportMeta {
330
627
  /**
331
- * The directory name of the current module. This is the same as the `path.dirname()` of the `import.meta.filename`.
332
- * **Caveat:** only present on `file:` modules.
628
+ * The directory name of the current module.
629
+ *
630
+ * This is the same as the `path.dirname()` of the `import.meta.filename`.
631
+ *
632
+ * > **Caveat**: only present on `file:` modules.
633
+ * @since v21.2.0, v20.11.0
333
634
  */
334
635
  dirname: string;
335
636
  /**
336
- * The full absolute path and filename of the current module, with symlinks resolved.
637
+ * The full absolute path and filename of the current module, with
638
+ * symlinks resolved.
639
+ *
337
640
  * This is the same as the `url.fileURLToPath()` of the `import.meta.url`.
338
- * **Caveat:** only local modules support this property. Modules not using the `file:` protocol will not provide it.
641
+ *
642
+ * > **Caveat** only local modules support this property. Modules not using the
643
+ * > `file:` protocol will not provide it.
644
+ * @since v21.2.0, v20.11.0
339
645
  */
340
646
  filename: string;
341
647
  /**
342
648
  * The absolute `file:` URL of the module.
649
+ *
650
+ * This is defined exactly the same as it is in browsers providing the URL of the
651
+ * current module file.
652
+ *
653
+ * This enables useful patterns such as relative file loading:
654
+ *
655
+ * ```js
656
+ * import { readFileSync } from 'node:fs';
657
+ * const buffer = readFileSync(new URL('./data.proto', import.meta.url));
658
+ * ```
343
659
  */
344
660
  url: string;
345
661
  /**
346
- * Provides a module-relative resolution function scoped to each module, returning
347
- * the URL string.
662
+ * `import.meta.resolve` is a module-relative resolution function scoped to
663
+ * each module, returning the URL string.
664
+ *
665
+ * ```js
666
+ * const dependencyAsset = import.meta.resolve('component-lib/asset.css');
667
+ * // file:///app/node_modules/component-lib/asset.css
668
+ * import.meta.resolve('./dep.js');
669
+ * // file:///app/dep.js
670
+ * ```
671
+ *
672
+ * All features of the Node.js module resolution are supported. Dependency
673
+ * resolutions are subject to the permitted exports resolutions within the package.
674
+ *
675
+ * **Caveats**:
676
+ *
677
+ * * This can result in synchronous file-system operations, which
678
+ * can impact performance similarly to `require.resolve`.
679
+ * * This feature is not available within custom loaders (it would
680
+ * create a deadlock).
681
+ * @since v13.9.0, v12.16.0
682
+ * @param specifier The module specifier to resolve relative to the
683
+ * current module.
684
+ * @param parent An optional absolute parent module URL to resolve from.
685
+ * **Default:** `import.meta.url`
686
+ * @returns The absolute URL string that the specifier would resolve to.
687
+ */
688
+ resolve(specifier: string, parent?: string | URL): string;
689
+ /**
690
+ * `true` when the current module is the entry point of the current process; `false` otherwise.
691
+ *
692
+ * Equivalent to `require.main === module` in CommonJS.
693
+ *
694
+ * Analogous to Python's `__name__ == "__main__"`.
348
695
  *
349
- * Second `parent` parameter is only used when the `--experimental-import-meta-resolve`
350
- * command flag enabled.
696
+ * ```js
697
+ * export function foo() {
698
+ * return 'Hello, world';
699
+ * }
351
700
  *
352
- * @since v20.6.0
701
+ * function main() {
702
+ * const message = foo();
703
+ * console.log(message);
704
+ * }
353
705
  *
354
- * @param specifier The module specifier to resolve relative to `parent`.
355
- * @param parent The absolute parent module URL to resolve from.
356
- * @returns The absolute (`file:`) URL string for the resolved module.
706
+ * if (import.meta.main) main();
707
+ * // `foo` can be imported from another module without possible side-effects from `main`
708
+ * ```
709
+ * @since v24.2.0
710
+ * @experimental
357
711
  */
358
- resolve(specifier: string, parent?: string | URL | undefined): string;
712
+ main: boolean;
359
713
  }
360
714
  namespace NodeJS {
361
715
  interface Module {
@@ -430,7 +784,7 @@ declare module "module" {
430
784
  * Modules are cached in this object when they are required. By deleting a key
431
785
  * value from this object, the next `require` will reload the module.
432
786
  * This does not apply to
433
- * [native addons](https://nodejs.org/docs/latest-v20.x/api/addons.html),
787
+ * [native addons](https://nodejs.org/docs/latest-v24.x/api/addons.html),
434
788
  * for which reloading will result in an error.
435
789
  * @since v0.3.0
436
790
  */
@@ -464,7 +818,7 @@ declare module "module" {
464
818
  * Paths to resolve module location from. If present, these
465
819
  * paths are used instead of the default resolution paths, with the exception
466
820
  * of
467
- * [GLOBAL\_FOLDERS](https://nodejs.org/docs/latest-v20.x/api/modules.html#loading-from-the-global-folders)
821
+ * [GLOBAL\_FOLDERS](https://nodejs.org/docs/latest-v24.x/api/modules.html#loading-from-the-global-folders)
468
822
  * like `$HOME/.node_modules`, which are
469
823
  * always included. Each of these paths is used as a starting point for
470
824
  * the module resolution algorithm, meaning that the `node_modules` hierarchy
@@ -482,7 +836,7 @@ declare module "module" {
482
836
  * @since v0.3.0
483
837
  * @param request The module path to resolve.
484
838
  */
485
- (id: string, options?: RequireResolveOptions): string;
839
+ (request: string, options?: RequireResolveOptions): string;
486
840
  /**
487
841
  * Returns an array containing the paths searched during resolution of `request` or
488
842
  * `null` if the `request` string references a core module, for example `http` or
@@ -524,6 +878,7 @@ declare module "module" {
524
878
  */
525
879
  var require: NodeJS.Require;
526
880
  // Global-scope aliases for backwards compatibility with @types/node <13.0.x
881
+ // TODO: consider removing in a future major version update
527
882
  /** @deprecated Use `NodeJS.Module` instead. */
528
883
  interface NodeModule extends NodeJS.Module {}
529
884
  /** @deprecated Use `NodeJS.Require` instead. */