@types/node 22.7.9 → 22.8.1

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.
node/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Wed, 23 Oct 2024 03:36:41 GMT
11
+ * Last updated: Fri, 25 Oct 2024 22:02:20 GMT
12
12
  * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
13
 
14
14
  # Credits
node/module.d.ts CHANGED
@@ -238,12 +238,66 @@ declare module "module" {
238
238
  context: LoadHookContext,
239
239
  nextLoad: (url: string, context?: LoadHookContext) => LoadFnOutput | Promise<LoadFnOutput>,
240
240
  ) => LoadFnOutput | Promise<LoadFnOutput>;
241
+ namespace constants {
242
+ /**
243
+ * The following constants are returned as the `status` field in the object returned by
244
+ * {@link enableCompileCache} to indicate the result of the attempt to enable the
245
+ * [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
246
+ * @since v22.8.0
247
+ */
248
+ namespace compileCacheStatus {
249
+ /**
250
+ * Node.js has enabled the compile cache successfully. The directory used to store the
251
+ * compile cache will be returned in the `directory` field in the
252
+ * returned object.
253
+ */
254
+ const ENABLED: number;
255
+ /**
256
+ * The compile cache has already been enabled before, either by a previous call to
257
+ * {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir`
258
+ * environment variable. The directory used to store the
259
+ * compile cache will be returned in the `directory` field in the
260
+ * returned object.
261
+ */
262
+ const ALREADY_ENABLED: number;
263
+ /**
264
+ * Node.js fails to enable the compile cache. This can be caused by the lack of
265
+ * permission to use the specified directory, or various kinds of file system errors.
266
+ * The detail of the failure will be returned in the `message` field in the
267
+ * returned object.
268
+ */
269
+ const FAILED: number;
270
+ /**
271
+ * Node.js cannot enable the compile cache because the environment variable
272
+ * `NODE_DISABLE_COMPILE_CACHE=1` has been set.
273
+ */
274
+ const DISABLED: number;
275
+ }
276
+ }
241
277
  }
242
278
  interface RegisterOptions<Data> {
243
279
  parentURL: string | URL;
244
280
  data?: Data | undefined;
245
281
  transferList?: any[] | undefined;
246
282
  }
283
+ interface EnableCompileCacheResult {
284
+ /**
285
+ * One of the {@link constants.compileCacheStatus}
286
+ */
287
+ status: number;
288
+ /**
289
+ * If Node.js cannot enable the compile cache, this contains
290
+ * the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
291
+ */
292
+ message?: string;
293
+ /**
294
+ * If the compile cache is enabled, this contains the directory
295
+ * where the compile cache is stored. Only set if `status` is
296
+ * `module.constants.compileCacheStatus.ENABLED` or
297
+ * `module.constants.compileCacheStatus.ALREADY_ENABLED`.
298
+ */
299
+ directory?: string;
300
+ }
247
301
  interface Module extends NodeModule {}
248
302
  class Module {
249
303
  static runMain(): void;
@@ -258,6 +312,43 @@ declare module "module" {
258
312
  options?: RegisterOptions<Data>,
259
313
  ): void;
260
314
  static register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
315
+ /**
316
+ * Enable [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
317
+ * in the current Node.js instance.
318
+ *
319
+ * If `cacheDir` is not specified, Node.js will either use the directory specified by the
320
+ * `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use
321
+ * `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
322
+ * recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
323
+ * so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
324
+ * variable when necessary.
325
+ *
326
+ * Since compile cache is supposed to be a quiet optimization that is not required for the
327
+ * application to be functional, this method is designed to not throw any exception when the
328
+ * compile cache cannot be enabled. Instead, it will return an object containing an error
329
+ * message in the `message` field to aid debugging.
330
+ * If compile cache is enabled successfully, the `directory` field in the returned object
331
+ * contains the path to the directory where the compile cache is stored. The `status`
332
+ * field in the returned object would be one of the `module.constants.compileCacheStatus`
333
+ * values to indicate the result of the attempt to enable the
334
+ * [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
335
+ *
336
+ * This method only affects the current Node.js instance. To enable it in child worker threads,
337
+ * either call this method in child worker threads too, or set the
338
+ * `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
339
+ * be inherited into the child workers. The directory can be obtained either from the
340
+ * `directory` field returned by this method, or with {@link getCompileCacheDir}.
341
+ * @since v22.8.0
342
+ * @param cacheDir Optional path to specify the directory where the compile cache
343
+ * will be stored/retrieved.
344
+ */
345
+ static enableCompileCache(cacheDir?: string): EnableCompileCacheResult;
346
+ /**
347
+ * @since v22.8.0
348
+ * @return Path to the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
349
+ * directory if it is enabled, or `undefined` otherwise.
350
+ */
351
+ static getCompileCacheDir(): string | undefined;
261
352
  constructor(id: string, parent?: Module);
262
353
  }
263
354
  global {
node/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "22.7.9",
3
+ "version": "22.8.1",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -217,9 +217,9 @@
217
217
  },
218
218
  "scripts": {},
219
219
  "dependencies": {
220
- "undici-types": "~6.19.2"
220
+ "undici-types": "~6.19.8"
221
221
  },
222
222
  "peerDependencies": {},
223
- "typesPublisherContentHash": "49b712614616bc7f8a0b0f6596d6add73e659a4a4d0695f61e4ab90a468876d3",
223
+ "typesPublisherContentHash": "679317e7cae6b391e6bf63e356e0496420e31113098d850dbc95b3d22c17a6c6",
224
224
  "typeScriptVersion": "4.8"
225
225
  }
node/perf_hooks.d.ts CHANGED
@@ -116,6 +116,20 @@ declare module "perf_hooks" {
116
116
  class PerformanceMeasure extends PerformanceEntry {
117
117
  readonly entryType: "measure";
118
118
  }
119
+ interface UVMetrics {
120
+ /**
121
+ * Number of event loop iterations.
122
+ */
123
+ readonly loopCount: number;
124
+ /**
125
+ * Number of events that have been processed by the event handler.
126
+ */
127
+ readonly events: number;
128
+ /**
129
+ * Number of events that were waiting to be processed when the event provider was called.
130
+ */
131
+ readonly eventsWaiting: number;
132
+ }
119
133
  /**
120
134
  * _This property is an extension by Node.js. It is not available in Web browsers._
121
135
  *
@@ -166,6 +180,16 @@ declare module "perf_hooks" {
166
180
  * @since v8.5.0
167
181
  */
168
182
  readonly nodeStart: number;
183
+ /**
184
+ * This is a wrapper to the `uv_metrics_info` function.
185
+ * It returns the current set of event loop metrics.
186
+ *
187
+ * It is recommended to use this property inside a function whose execution was
188
+ * scheduled using `setImmediate` to avoid collecting metrics before finishing all
189
+ * operations scheduled during the current loop iteration.
190
+ * @since v22.8.0, v20.18.0
191
+ */
192
+ readonly uvMetricsInfo: UVMetrics;
169
193
  /**
170
194
  * The high resolution millisecond timestamp at which the V8 platform was
171
195
  * initialized.
node/test.d.ts CHANGED
@@ -340,11 +340,22 @@ declare module "node:test" {
340
340
  globPatterns?: readonly string[] | undefined;
341
341
  /**
342
342
  * Sets inspector port of test child process.
343
- * If a nullish value is provided, each process gets its own port,
344
- * incremented from the primary's `process.debugPort`.
343
+ * This can be a number, or a function that takes no arguments and returns a
344
+ * number. If a nullish value is provided, each process gets its own port,
345
+ * incremented from the primary's `process.debugPort`. This option is ignored
346
+ * if the `isolation` option is set to `'none'` as no child processes are
347
+ * spawned.
345
348
  * @default undefined
346
349
  */
347
350
  inspectPort?: number | (() => number) | undefined;
351
+ /**
352
+ * Configures the type of test isolation. If set to
353
+ * `'process'`, each test file is run in a separate child process. If set to
354
+ * `'none'`, all test files run in the current process.
355
+ * @default 'process'
356
+ * @since v22.8.0
357
+ */
358
+ isolation?: "process" | "none" | undefined;
348
359
  /**
349
360
  * If truthy, the test context will only run tests that have the `only` option set
350
361
  */
@@ -1635,9 +1646,10 @@ declare module "node:test" {
1635
1646
  * This function is used to set a custom resolver for the location of the snapshot file used for snapshot testing.
1636
1647
  * By default, the snapshot filename is the same as the entry point filename with `.snapshot` appended.
1637
1648
  * @since v22.3.0
1638
- * @param fn A function which returns a string specifying the location of the snapshot file.
1639
- * The function receives the path of the test file as its only argument.
1640
- * If `process.argv[1]` is not associated with a file (for example in the REPL), the input is undefined.
1649
+ * @param fn A function used to compute the location of the snapshot file.
1650
+ * The function receives the path of the test file as its only argument. If the
1651
+ * test is not associated with a file (for example in the REPL), the input is
1652
+ * undefined. `fn()` must return a string specifying the location of the snapshot file.
1641
1653
  */
1642
1654
  function setResolveSnapshotPath(fn: (path: string | undefined) => string): void;
1643
1655
  }
node/vm.d.ts CHANGED
@@ -230,16 +230,23 @@ declare module "vm" {
230
230
  */
231
231
  runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
232
232
  /**
233
- * First contextifies the given `contextObject`, runs the compiled code contained
234
- * by the `vm.Script` object within the created context, and returns the result.
235
- * Running code does not have access to local scope.
233
+ * This method is a shortcut to `script.runInContext(vm.createContext(options), options)`.
234
+ * It does several things at once:
235
+ *
236
+ * 1. Creates a new context.
237
+ * 2. If `contextObject` is an object, contextifies it with the new context.
238
+ * If `contextObject` is undefined, creates a new object and contextifies it.
239
+ * If `contextObject` is `vm.constants.DONT_CONTEXTIFY`, don't contextify anything.
240
+ * 3. Runs the compiled code contained by the `vm.Script` object within the created context. The code
241
+ * does not have access to the scope in which this method is called.
242
+ * 4. Returns the result.
236
243
  *
237
244
  * The following example compiles code that sets a global variable, then executes
238
245
  * the code multiple times in different contexts. The globals are set on and
239
246
  * contained within each individual `context`.
240
247
  *
241
248
  * ```js
242
- * import vm from 'node:vm';
249
+ * const vm = require('node:vm');
243
250
  *
244
251
  * const script = new vm.Script('globalVar = "set"');
245
252
  *
@@ -250,12 +257,22 @@ declare module "vm" {
250
257
  *
251
258
  * console.log(contexts);
252
259
  * // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
260
+ *
261
+ * // This would throw if the context is created from a contextified object.
262
+ * // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary
263
+ * // global objects that can be frozen.
264
+ * const freezeScript = new vm.Script('Object.freeze(globalThis); globalThis;');
265
+ * const frozenContext = freezeScript.runInNewContext(vm.constants.DONT_CONTEXTIFY);
253
266
  * ```
254
267
  * @since v0.3.1
255
- * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
268
+ * @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
269
+ * If `undefined`, an empty contextified object will be created for backwards compatibility.
256
270
  * @return the result of the very last statement executed in the script.
257
271
  */
258
- runInNewContext(contextObject?: Context, options?: RunningScriptInNewContextOptions): any;
272
+ runInNewContext(
273
+ contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
274
+ options?: RunningScriptInNewContextOptions,
275
+ ): any;
259
276
  /**
260
277
  * Runs the compiled code contained by the `vm.Script` within the context of the
261
278
  * current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
@@ -347,17 +364,17 @@ declare module "vm" {
347
364
  sourceMapURL?: string | undefined;
348
365
  }
349
366
  /**
350
- * If given a `contextObject`, the `vm.createContext()` method will
367
+ * If the given `contextObject` is an object, the `vm.createContext()` method will
351
368
  * [prepare that object](https://nodejs.org/docs/latest-v22.x/api/vm.html#what-does-it-mean-to-contextify-an-object)
352
- * and return a reference to it so that it can be used in `{@link runInContext}` or
353
- * [`script.runInContext()`](https://nodejs.org/docs/latest-v22.x/api/vm.html#scriptrunincontextcontextifiedobject-options). Inside such
354
- * scripts, the `contextObject` will be the global object, retaining all of its
355
- * existing properties but also having the built-in objects and functions any
356
- * standard [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global
369
+ * and return a reference to it so that it can be used in calls to {@link runInContext} or
370
+ * [`script.runInContext()`](https://nodejs.org/docs/latest-v22.x/api/vm.html#scriptrunincontextcontextifiedobject-options).
371
+ * Inside such scripts, the global object will be wrapped by the `contextObject`, retaining all of its
372
+ * existing properties but also having the built-in objects and functions any standard
373
+ * [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global
357
374
  * variables will remain unchanged.
358
375
  *
359
376
  * ```js
360
- * import vm from 'node:vm';
377
+ * const vm = require('node:vm');
361
378
  *
362
379
  * global.globalVar = 3;
363
380
  *
@@ -374,7 +391,12 @@ declare module "vm" {
374
391
  * ```
375
392
  *
376
393
  * If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
377
- * empty `contextified` object will be returned.
394
+ * empty contextified object will be returned.
395
+ *
396
+ * When the global object in the newly created context is contextified, it has some quirks
397
+ * compared to ordinary global objects. For example, it cannot be frozen. To create a context
398
+ * without the contextifying quirks, pass `vm.constants.DONT_CONTEXTIFY` as the `contextObject`
399
+ * argument. See the documentation of `vm.constants.DONT_CONTEXTIFY` for details.
378
400
  *
379
401
  * The `vm.createContext()` method is primarily useful for creating a single
380
402
  * context that can be used to run multiple scripts. For instance, if emulating a
@@ -385,11 +407,17 @@ declare module "vm" {
385
407
  * The provided `name` and `origin` of the context are made visible through the
386
408
  * Inspector API.
387
409
  * @since v0.3.1
410
+ * @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
411
+ * If `undefined`, an empty contextified object will be created for backwards compatibility.
388
412
  * @return contextified object.
389
413
  */
390
- function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
414
+ function createContext(
415
+ contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
416
+ options?: CreateContextOptions,
417
+ ): Context;
391
418
  /**
392
- * Returns `true` if the given `object` object has been `contextified` using {@link createContext}.
419
+ * Returns `true` if the given `object` object has been contextified using {@link createContext},
420
+ * or if it's the global object of a context created using `vm.constants.DONT_CONTEXTIFY`.
393
421
  * @since v0.11.7
394
422
  */
395
423
  function isContext(sandbox: Context): boolean;
@@ -422,18 +450,26 @@ declare module "vm" {
422
450
  */
423
451
  function runInContext(code: string, contextifiedObject: Context, options?: RunningCodeOptions | string): any;
424
452
  /**
425
- * The `vm.runInNewContext()` first contextifies the given `contextObject` (or
426
- * creates a new `contextObject` if passed as `undefined`), compiles the `code`,
427
- * runs it within the created context, then returns the result. Running code
428
- * does not have access to the local scope.
429
- *
453
+ * This method is a shortcut to
454
+ * `(new vm.Script(code, options)).runInContext(vm.createContext(options), options)`.
430
455
  * If `options` is a string, then it specifies the filename.
431
456
  *
457
+ * It does several things at once:
458
+ *
459
+ * 1. Creates a new context.
460
+ * 2. If `contextObject` is an object, contextifies it with the new context.
461
+ * If `contextObject` is undefined, creates a new object and contextifies it.
462
+ * If `contextObject` is `vm.constants.DONT_CONTEXTIFY`, don't contextify anything.
463
+ * 3. Compiles the code as a`vm.Script`
464
+ * 4. Runs the compield code within the created context. The code does not have access to the scope in
465
+ * which this method is called.
466
+ * 5. Returns the result.
467
+ *
432
468
  * The following example compiles and executes code that increments a global
433
469
  * variable and sets a new one. These globals are contained in the `contextObject`.
434
470
  *
435
471
  * ```js
436
- * import vm from 'node:vm';
472
+ * const vm = require('node:vm');
437
473
  *
438
474
  * const contextObject = {
439
475
  * animal: 'cat',
@@ -443,15 +479,21 @@ declare module "vm" {
443
479
  * vm.runInNewContext('count += 1; name = "kitty"', contextObject);
444
480
  * console.log(contextObject);
445
481
  * // Prints: { animal: 'cat', count: 3, name: 'kitty' }
482
+ *
483
+ * // This would throw if the context is created from a contextified object.
484
+ * // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary global objects that
485
+ * // can be frozen.
486
+ * const frozenContext = vm.runInNewContext('Object.freeze(globalThis); globalThis;', vm.constants.DONT_CONTEXTIFY);
446
487
  * ```
447
488
  * @since v0.3.1
448
489
  * @param code The JavaScript code to compile and run.
449
- * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
490
+ * @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
491
+ * If `undefined`, an empty contextified object will be created for backwards compatibility.
450
492
  * @return the result of the very last statement executed in the script.
451
493
  */
452
494
  function runInNewContext(
453
495
  code: string,
454
- contextObject?: Context,
496
+ contextObject?: Context | typeof constants.DONT_CONTEXTIFY,
455
497
  options?: RunningCodeInNewContextOptions | string,
456
498
  ): any;
457
499
  /**
@@ -902,19 +944,31 @@ declare module "vm" {
902
944
  }
903
945
  /**
904
946
  * Returns an object containing commonly used constants for VM operations.
905
- * @since v20.12.0
947
+ * @since v21.7.0, v20.12.0
906
948
  */
907
949
  namespace constants {
908
950
  /**
909
- * Stability: 1.1 - Active development
910
- *
911
951
  * A constant that can be used as the `importModuleDynamically` option to `vm.Script`
912
952
  * and `vm.compileFunction()` so that Node.js uses the default ESM loader from the main
913
953
  * context to load the requested module.
914
954
  *
915
955
  * For detailed information, see [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v22.x/api/vm.html#support-of-dynamic-import-in-compilation-apis).
956
+ * @since v21.7.0, v20.12.0
916
957
  */
917
958
  const USE_MAIN_CONTEXT_DEFAULT_LOADER: number;
959
+ /**
960
+ * This constant, when used as the `contextObject` argument in vm APIs, instructs Node.js to create
961
+ * a context without wrapping its global object with another object in a Node.js-specific manner.
962
+ * As a result, the `globalThis` value inside the new context would behave more closely to an ordinary
963
+ * one.
964
+ *
965
+ * When `vm.constants.DONT_CONTEXTIFY` is used as the `contextObject` argument to {@link createContext},
966
+ * the returned object is a proxy-like object to the global object in the newly created context with
967
+ * fewer Node.js-specific quirks. It is reference equal to the `globalThis` value in the new context,
968
+ * can be modified from outside the context, and can be used to access built-ins in the new context directly.
969
+ * @since v22.8.0
970
+ */
971
+ const DONT_CONTEXTIFY: number;
918
972
  }
919
973
  }
920
974
  declare module "node:vm" {
node/worker_threads.d.ts CHANGED
@@ -267,7 +267,7 @@ declare module "worker_threads" {
267
267
  trackUnmanagedFds?: boolean | undefined;
268
268
  /**
269
269
  * An optional `name` to be appended to the worker title
270
- * for debuggin/identification purposes, making the final title as
270
+ * for debugging/identification purposes, making the final title as
271
271
  * `[worker ${id}] ${name}`.
272
272
  */
273
273
  name?: string | undefined;