@types/node 18.16.3 → 20.0.0

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 (95) hide show
  1. node/README.md +1 -1
  2. node/assert.d.ts +68 -73
  3. node/async_hooks.d.ts +62 -42
  4. node/buffer.d.ts +123 -95
  5. node/child_process.d.ts +50 -54
  6. node/cluster.d.ts +12 -12
  7. node/console.d.ts +5 -5
  8. node/crypto.d.ts +209 -220
  9. node/dgram.d.ts +15 -15
  10. node/diagnostics_channel.d.ts +25 -26
  11. node/dns/promises.d.ts +6 -6
  12. node/dns.d.ts +16 -16
  13. node/domain.d.ts +3 -3
  14. node/events.d.ts +60 -60
  15. node/fs/promises.d.ts +74 -48
  16. node/fs.d.ts +91 -81
  17. node/http.d.ts +147 -144
  18. node/http2.d.ts +42 -46
  19. node/https.d.ts +52 -153
  20. node/index.d.ts +1 -1
  21. node/inspector.d.ts +10 -3
  22. node/module.d.ts +5 -4
  23. node/net.d.ts +21 -18
  24. node/os.d.ts +22 -18
  25. node/package.json +2 -2
  26. node/path.d.ts +4 -4
  27. node/perf_hooks.d.ts +28 -15
  28. node/process.d.ts +43 -46
  29. node/punycode.d.ts +1 -1
  30. node/querystring.d.ts +5 -5
  31. node/readline/promises.d.ts +6 -4
  32. node/readline.d.ts +15 -15
  33. node/repl.d.ts +9 -9
  34. node/stream/consumers.d.ts +1 -1
  35. node/stream.d.ts +74 -136
  36. node/string_decoder.d.ts +6 -6
  37. node/test.d.ts +0 -76
  38. node/timers/promises.d.ts +3 -3
  39. node/timers.d.ts +2 -2
  40. node/tls.d.ts +22 -15
  41. node/trace_events.d.ts +20 -9
  42. node/ts4.8/assert.d.ts +68 -73
  43. node/ts4.8/async_hooks.d.ts +59 -31
  44. node/ts4.8/buffer.d.ts +123 -95
  45. node/ts4.8/child_process.d.ts +50 -54
  46. node/ts4.8/cluster.d.ts +12 -12
  47. node/ts4.8/console.d.ts +5 -5
  48. node/ts4.8/crypto.d.ts +209 -220
  49. node/ts4.8/dgram.d.ts +15 -15
  50. node/ts4.8/diagnostics_channel.d.ts +25 -26
  51. node/ts4.8/dns/promises.d.ts +6 -6
  52. node/ts4.8/dns.d.ts +16 -16
  53. node/ts4.8/domain.d.ts +3 -3
  54. node/ts4.8/events.d.ts +60 -60
  55. node/ts4.8/fs/promises.d.ts +72 -45
  56. node/ts4.8/fs.d.ts +81 -67
  57. node/ts4.8/http.d.ts +133 -126
  58. node/ts4.8/http2.d.ts +42 -46
  59. node/ts4.8/https.d.ts +52 -153
  60. node/ts4.8/inspector.d.ts +10 -3
  61. node/ts4.8/module.d.ts +5 -4
  62. node/ts4.8/net.d.ts +21 -18
  63. node/ts4.8/os.d.ts +22 -18
  64. node/ts4.8/path.d.ts +4 -4
  65. node/ts4.8/perf_hooks.d.ts +28 -15
  66. node/ts4.8/process.d.ts +43 -46
  67. node/ts4.8/punycode.d.ts +1 -1
  68. node/ts4.8/querystring.d.ts +5 -5
  69. node/ts4.8/readline/promises.d.ts +6 -4
  70. node/ts4.8/readline.d.ts +15 -15
  71. node/ts4.8/repl.d.ts +9 -9
  72. node/ts4.8/stream/consumers.d.ts +1 -1
  73. node/ts4.8/stream.d.ts +77 -139
  74. node/ts4.8/string_decoder.d.ts +6 -6
  75. node/ts4.8/test.d.ts +0 -75
  76. node/ts4.8/timers/promises.d.ts +3 -3
  77. node/ts4.8/timers.d.ts +2 -2
  78. node/ts4.8/tls.d.ts +22 -15
  79. node/ts4.8/trace_events.d.ts +20 -9
  80. node/ts4.8/tty.d.ts +4 -5
  81. node/ts4.8/url.d.ts +26 -36
  82. node/ts4.8/util.d.ts +143 -116
  83. node/ts4.8/v8.d.ts +107 -16
  84. node/ts4.8/vm.d.ts +292 -42
  85. node/ts4.8/wasi.d.ts +8 -14
  86. node/ts4.8/worker_threads.d.ts +32 -34
  87. node/ts4.8/zlib.d.ts +11 -11
  88. node/tty.d.ts +4 -5
  89. node/url.d.ts +26 -36
  90. node/util.d.ts +146 -111
  91. node/v8.d.ts +110 -16
  92. node/vm.d.ts +292 -42
  93. node/wasi.d.ts +8 -14
  94. node/worker_threads.d.ts +32 -34
  95. node/zlib.d.ts +11 -11
node/vm.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * The `vm` module enables compiling and running code within V8 Virtual
2
+ * The `node:vm` module enables compiling and running code within V8 Virtual
3
3
  * Machine contexts.
4
4
  *
5
- * **The `vm` module is not a security**
5
+ * **The `node:vm` module is not a security**
6
6
  * **mechanism. Do not use it to run untrusted code.**
7
7
  *
8
8
  * JavaScript code can be compiled and run immediately or
@@ -17,7 +17,7 @@
17
17
  * code are reflected in the context object.
18
18
  *
19
19
  * ```js
20
- * const vm = require('vm');
20
+ * const vm = require('node:vm');
21
21
  *
22
22
  * const x = 1;
23
23
  *
@@ -34,7 +34,7 @@
34
34
  *
35
35
  * console.log(x); // 1; y is not defined.
36
36
  * ```
37
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/vm.js)
37
+ * @see [source](https://github.com/nodejs/node/blob/v20.0.0/lib/vm.js)
38
38
  */
39
39
  declare module 'vm' {
40
40
  interface Context extends NodeJS.Dict<any> {}
@@ -198,11 +198,11 @@ declare module 'vm' {
198
198
  * The globals are contained in the `context` object.
199
199
  *
200
200
  * ```js
201
- * const vm = require('vm');
201
+ * const vm = require('node:vm');
202
202
  *
203
203
  * const context = {
204
204
  * animal: 'cat',
205
- * count: 2
205
+ * count: 2,
206
206
  * };
207
207
  *
208
208
  * const script = new vm.Script('count += 1; name = "kitty";');
@@ -234,7 +234,7 @@ declare module 'vm' {
234
234
  * contained within each individual `context`.
235
235
  *
236
236
  * ```js
237
- * const vm = require('vm');
237
+ * const vm = require('node:vm');
238
238
  *
239
239
  * const script = new vm.Script('globalVar = "set"');
240
240
  *
@@ -259,7 +259,7 @@ declare module 'vm' {
259
259
  * executes that code multiple times:
260
260
  *
261
261
  * ```js
262
- * const vm = require('vm');
262
+ * const vm = require('node:vm');
263
263
  *
264
264
  * global.globalVar = 0;
265
265
  *
@@ -281,6 +281,16 @@ declare module 'vm' {
281
281
  * Creates a code cache that can be used with the `Script` constructor's`cachedData` option. Returns a `Buffer`. This method may be called at any
282
282
  * time and any number of times.
283
283
  *
284
+ * The code cache of the `Script` doesn't contain any JavaScript observable
285
+ * states. The code cache is safe to be saved along side the script source and
286
+ * used to construct new `Script` instances multiple times.
287
+ *
288
+ * Functions in the `Script` source can be marked as lazily compiled and they are
289
+ * not compiled at construction of the `Script`. These functions are going to be
290
+ * compiled when they are invoked the first time. The code cache serializes the
291
+ * metadata that V8 currently knows about the `Script` that it can use to speed up
292
+ * future compilations.
293
+ *
284
294
  * ```js
285
295
  * const script = new vm.Script(`
286
296
  * function add(a, b) {
@@ -290,21 +300,44 @@ declare module 'vm' {
290
300
  * const x = add(1, 2);
291
301
  * `);
292
302
  *
293
- * const cacheWithoutX = script.createCachedData();
303
+ * const cacheWithoutAdd = script.createCachedData();
304
+ * // In `cacheWithoutAdd` the function `add()` is marked for full compilation
305
+ * // upon invocation.
294
306
  *
295
307
  * script.runInThisContext();
296
308
  *
297
- * const cacheWithX = script.createCachedData();
309
+ * const cacheWithAdd = script.createCachedData();
310
+ * // `cacheWithAdd` contains fully compiled function `add()`.
298
311
  * ```
299
312
  * @since v10.6.0
300
313
  */
301
314
  createCachedData(): Buffer;
302
315
  /** @deprecated in favor of `script.createCachedData()` */
303
316
  cachedDataProduced?: boolean | undefined;
317
+ /**
318
+ * When `cachedData` is supplied to create the `vm.Script`, this value will be set
319
+ * to either `true` or `false` depending on acceptance of the data by V8\.
320
+ * Otherwise the value is `undefined`.
321
+ * @since v5.7.0
322
+ */
304
323
  cachedDataRejected?: boolean | undefined;
305
324
  cachedData?: Buffer | undefined;
306
325
  /**
307
- * When the script is compiled from a source that contains a source map magic comment, this property will be set to the URL of the source map.
326
+ * When the script is compiled from a source that contains a source map magic
327
+ * comment, this property will be set to the URL of the source map.
328
+ *
329
+ * ```js
330
+ * import vm from 'node:vm';
331
+ *
332
+ * const script = new vm.Script(`
333
+ * function myFunc() {}
334
+ * //# sourceMappingURL=sourcemap.json
335
+ * `);
336
+ *
337
+ * console.log(script.sourceMapURL);
338
+ * // Prints: sourcemap.json
339
+ * ```
340
+ * @since v19.1.0, v18.13.0
308
341
  */
309
342
  sourceMapURL?: string | undefined;
310
343
  }
@@ -316,7 +349,7 @@ declare module 'vm' {
316
349
  * will remain unchanged.
317
350
  *
318
351
  * ```js
319
- * const vm = require('vm');
352
+ * const vm = require('node:vm');
320
353
  *
321
354
  * global.globalVar = 3;
322
355
  *
@@ -363,7 +396,7 @@ declare module 'vm' {
363
396
  * The following example compiles and executes different scripts using a single `contextified` object:
364
397
  *
365
398
  * ```js
366
- * const vm = require('vm');
399
+ * const vm = require('node:vm');
367
400
  *
368
401
  * const contextObject = { globalVar: 1 };
369
402
  * vm.createContext(contextObject);
@@ -392,11 +425,11 @@ declare module 'vm' {
392
425
  * variable and sets a new one. These globals are contained in the `contextObject`.
393
426
  *
394
427
  * ```js
395
- * const vm = require('vm');
428
+ * const vm = require('node:vm');
396
429
  *
397
430
  * const contextObject = {
398
431
  * animal: 'cat',
399
- * count: 2
432
+ * count: 2,
400
433
  * };
401
434
  *
402
435
  * vm.runInNewContext('count += 1; name = "kitty"', contextObject);
@@ -420,7 +453,7 @@ declare module 'vm' {
420
453
  * the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
421
454
  *
422
455
  * ```js
423
- * const vm = require('vm');
456
+ * const vm = require('node:vm');
424
457
  * let localVar = 'initial value';
425
458
  *
426
459
  * const vmResult = vm.runInThisContext('localVar = "vm";');
@@ -441,17 +474,17 @@ declare module 'vm' {
441
474
  * When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
442
475
  * context. The code passed to this VM context will have its own isolated scope.
443
476
  *
444
- * In order to run a simple web server using the `http` module the code passed to
445
- * the context must either call `require('http')` on its own, or have a reference
446
- * to the `http` module passed to it. For instance:
477
+ * In order to run a simple web server using the `node:http` module the code passed
478
+ * to the context must either call `require('node:http')` on its own, or have a
479
+ * reference to the `node:http` module passed to it. For instance:
447
480
  *
448
481
  * ```js
449
482
  * 'use strict';
450
- * const vm = require('vm');
483
+ * const vm = require('node:vm');
451
484
  *
452
485
  * const code = `
453
486
  * ((require) => {
454
- * const http = require('http');
487
+ * const http = require('node:http');
455
488
  *
456
489
  * http.createServer((request, response) => {
457
490
  * response.writeHead(200, { 'Content-Type': 'text/plain' });
@@ -480,7 +513,11 @@ declare module 'vm' {
480
513
  * @param code The body of the function to compile.
481
514
  * @param params An array of strings containing all parameters for the function.
482
515
  */
483
- function compileFunction(code: string, params?: ReadonlyArray<string>, options?: CompileFunctionOptions): Function & {
516
+ function compileFunction(
517
+ code: string,
518
+ params?: ReadonlyArray<string>,
519
+ options?: CompileFunctionOptions
520
+ ): Function & {
484
521
  cachedData?: Script['cachedData'] | undefined;
485
522
  cachedDataProduced?: Script['cachedDataProduced'] | undefined;
486
523
  cachedDataRejected?: Script['cachedDataRejected'] | undefined;
@@ -498,7 +535,7 @@ declare module 'vm' {
498
535
  * the memory occupied by each heap space in the current V8 instance.
499
536
  *
500
537
  * ```js
501
- * const vm = require('vm');
538
+ * const vm = require('node:vm');
502
539
  * // Measure the memory used by the main context.
503
540
  * vm.measureMemory({ mode: 'summary' })
504
541
  * // This is the same as vm.measureMemory()
@@ -541,21 +578,132 @@ declare module 'vm' {
541
578
  * @experimental
542
579
  */
543
580
  function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
544
-
545
581
  interface ModuleEvaluateOptions {
546
582
  timeout?: RunningScriptOptions['timeout'] | undefined;
547
583
  breakOnSigint?: RunningScriptOptions['breakOnSigint'] | undefined;
548
584
  }
549
- type ModuleLinker = (specifier: string, referencingModule: Module, extra: { assert: Object }) => Module | Promise<Module>;
585
+ type ModuleLinker = (
586
+ specifier: string,
587
+ referencingModule: Module,
588
+ extra: {
589
+ assert: Object;
590
+ }
591
+ ) => Module | Promise<Module>;
550
592
  type ModuleStatus = 'unlinked' | 'linking' | 'linked' | 'evaluating' | 'evaluated' | 'errored';
593
+ /**
594
+ * This feature is only available with the `--experimental-vm-modules` command
595
+ * flag enabled.
596
+ *
597
+ * The `vm.Module` class provides a low-level interface for using
598
+ * ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`class that closely mirrors [Module Record](https://www.ecma-international.org/ecma-262/#sec-abstract-module-records)
599
+ * s as defined in the ECMAScript
600
+ * specification.
601
+ *
602
+ * Unlike `vm.Script` however, every `vm.Module` object is bound to a context from
603
+ * its creation. Operations on `vm.Module` objects are intrinsically asynchronous,
604
+ * in contrast with the synchronous nature of `vm.Script` objects. The use of
605
+ * 'async' functions can help with manipulating `vm.Module` objects.
606
+ *
607
+ * Using a `vm.Module` object requires three distinct steps: creation/parsing,
608
+ * linking, and evaluation. These three steps are illustrated in the following
609
+ * example.
610
+ *
611
+ * This implementation lies at a lower level than the `ECMAScript Module
612
+ * loader`. There is also no way to interact with the Loader yet, though
613
+ * support is planned.
614
+ *
615
+ * ```js
616
+ * import vm from 'node:vm';
617
+ *
618
+ * const contextifiedObject = vm.createContext({
619
+ * secret: 42,
620
+ * print: console.log,
621
+ * });
622
+ *
623
+ * // Step 1
624
+ * //
625
+ * // Create a Module by constructing a new `vm.SourceTextModule` object. This
626
+ * // parses the provided source text, throwing a `SyntaxError` if anything goes
627
+ * // wrong. By default, a Module is created in the top context. But here, we
628
+ * // specify `contextifiedObject` as the context this Module belongs to.
629
+ * //
630
+ * // Here, we attempt to obtain the default export from the module "foo", and
631
+ * // put it into local binding "secret".
632
+ *
633
+ * const bar = new vm.SourceTextModule(`
634
+ * import s from 'foo';
635
+ * s;
636
+ * print(s);
637
+ * `, { context: contextifiedObject });
638
+ *
639
+ * // Step 2
640
+ * //
641
+ * // "Link" the imported dependencies of this Module to it.
642
+ * //
643
+ * // The provided linking callback (the "linker") accepts two arguments: the
644
+ * // parent module (`bar` in this case) and the string that is the specifier of
645
+ * // the imported module. The callback is expected to return a Module that
646
+ * // corresponds to the provided specifier, with certain requirements documented
647
+ * // in `module.link()`.
648
+ * //
649
+ * // If linking has not started for the returned Module, the same linker
650
+ * // callback will be called on the returned Module.
651
+ * //
652
+ * // Even top-level Modules without dependencies must be explicitly linked. The
653
+ * // callback provided would never be called, however.
654
+ * //
655
+ * // The link() method returns a Promise that will be resolved when all the
656
+ * // Promises returned by the linker resolve.
657
+ * //
658
+ * // Note: This is a contrived example in that the linker function creates a new
659
+ * // "foo" module every time it is called. In a full-fledged module system, a
660
+ * // cache would probably be used to avoid duplicated modules.
661
+ *
662
+ * async function linker(specifier, referencingModule) {
663
+ * if (specifier === 'foo') {
664
+ * return new vm.SourceTextModule(`
665
+ * // The "secret" variable refers to the global variable we added to
666
+ * // "contextifiedObject" when creating the context.
667
+ * export default secret;
668
+ * `, { context: referencingModule.context });
669
+ *
670
+ * // Using `contextifiedObject` instead of `referencingModule.context`
671
+ * // here would work as well.
672
+ * }
673
+ * throw new Error(`Unable to resolve dependency: ${specifier}`);
674
+ * }
675
+ * await bar.link(linker);
676
+ *
677
+ * // Step 3
678
+ * //
679
+ * // Evaluate the Module. The evaluate() method returns a promise which will
680
+ * // resolve after the module has finished evaluating.
681
+ *
682
+ * // Prints 42.
683
+ * await bar.evaluate();
684
+ * ```
685
+ * @since v13.0.0, v12.16.0
686
+ * @experimental
687
+ */
551
688
  class Module {
552
689
  /**
553
- * The specifiers of all dependencies of this module.
690
+ * The specifiers of all dependencies of this module. The returned array is frozen
691
+ * to disallow any changes to it.
692
+ *
693
+ * Corresponds to the `[[RequestedModules]]` field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in
694
+ * the ECMAScript specification.
554
695
  */
555
696
  dependencySpecifiers: readonly string[];
556
697
  /**
557
- * If the `module.status` is `'errored'`, this property contains the exception thrown by the module during evaluation.
558
- * If the status is anything else, accessing this property will result in a thrown exception.
698
+ * If the `module.status` is `'errored'`, this property contains the exception
699
+ * thrown by the module during evaluation. If the status is anything else,
700
+ * accessing this property will result in a thrown exception.
701
+ *
702
+ * The value `undefined` cannot be used for cases where there is not a thrown
703
+ * exception due to possible ambiguity with `throw undefined;`.
704
+ *
705
+ * Corresponds to the `[[EvaluationError]]` field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s
706
+ * in the ECMAScript specification.
559
707
  */
560
708
  error: any;
561
709
  /**
@@ -564,30 +712,82 @@ declare module 'vm' {
564
712
  identifier: string;
565
713
  context: Context;
566
714
  /**
567
- * The namespace object of the module. This is only available after linking (`module.link()`) has completed.
715
+ * The namespace object of the module. This is only available after linking
716
+ * (`module.link()`) has completed.
717
+ *
718
+ * Corresponds to the [GetModuleNamespace](https://tc39.es/ecma262/#sec-getmodulenamespace) abstract operation in the ECMAScript
719
+ * specification.
568
720
  */
569
721
  namespace: Object;
570
722
  /**
571
- * The current status of the module.
723
+ * The current status of the module. Will be one of:
724
+ *
725
+ * * `'unlinked'`: `module.link()` has not yet been called.
726
+ * * `'linking'`: `module.link()` has been called, but not all Promises returned
727
+ * by the linker function have been resolved yet.
728
+ * * `'linked'`: The module has been linked successfully, and all of its
729
+ * dependencies are linked, but `module.evaluate()` has not yet been called.
730
+ * * `'evaluating'`: The module is being evaluated through a `module.evaluate()` on
731
+ * itself or a parent module.
732
+ * * `'evaluated'`: The module has been successfully evaluated.
733
+ * * `'errored'`: The module has been evaluated, but an exception was thrown.
734
+ *
735
+ * Other than `'errored'`, this status string corresponds to the specification's [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records)'s `[[Status]]` field. `'errored'`
736
+ * corresponds to`'evaluated'` in the specification, but with `[[EvaluationError]]` set to a
737
+ * value that is not `undefined`.
572
738
  */
573
739
  status: ModuleStatus;
574
740
  /**
575
741
  * Evaluate the module.
576
742
  *
577
- * This must be called after the module has been linked; otherwise it will reject
578
- * It could be called also when the module has already been evaluated, in which case it will either do nothing
579
- * if the initial evaluation ended in success (`module.status` is `'evaluated'`) or it will re-throw the exception
580
- * that the initial evaluation resulted in (`module.status` is `'errored'`).
743
+ * This must be called after the module has been linked; otherwise it will reject.
744
+ * It could be called also when the module has already been evaluated, in which
745
+ * case it will either do nothing if the initial evaluation ended in success
746
+ * (`module.status` is `'evaluated'`) or it will re-throw the exception that the
747
+ * initial evaluation resulted in (`module.status` is `'errored'`).
581
748
  *
582
- * This method cannot be called while the module is being evaluated (`module.status` is `'evaluating'`).
749
+ * This method cannot be called while the module is being evaluated
750
+ * (`module.status` is `'evaluating'`).
751
+ *
752
+ * Corresponds to the [Evaluate() concrete method](https://tc39.es/ecma262/#sec-moduleevaluation) field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in the
753
+ * ECMAScript specification.
754
+ * @return Fulfills with `undefined` upon success.
583
755
  */
584
756
  evaluate(options?: ModuleEvaluateOptions): Promise<void>;
585
757
  /**
586
- * Link module dependencies. This method must be called before evaluation, and can only be called once per module.
758
+ * Link module dependencies. This method must be called before evaluation, and
759
+ * can only be called once per module.
760
+ *
761
+ * The function is expected to return a `Module` object or a `Promise` that
762
+ * eventually resolves to a `Module` object. The returned `Module` must satisfy the
763
+ * following two invariants:
764
+ *
765
+ * * It must belong to the same context as the parent `Module`.
766
+ * * Its `status` must not be `'errored'`.
767
+ *
768
+ * If the returned `Module`'s `status` is `'unlinked'`, this method will be
769
+ * recursively called on the returned `Module` with the same provided `linker`function.
770
+ *
771
+ * `link()` returns a `Promise` that will either get resolved when all linking
772
+ * instances resolve to a valid `Module`, or rejected if the linker function either
773
+ * throws an exception or returns an invalid `Module`.
774
+ *
775
+ * The linker function roughly corresponds to the implementation-defined [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) abstract operation in the
776
+ * ECMAScript
777
+ * specification, with a few key differences:
778
+ *
779
+ * * The linker function is allowed to be asynchronous while [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) is synchronous.
780
+ *
781
+ * The actual [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) implementation used during module
782
+ * linking is one that returns the modules linked during linking. Since at
783
+ * that point all modules would have been fully linked already, the [HostResolveImportedModule](https://tc39.es/ecma262/#sec-hostresolveimportedmodule) implementation is fully synchronous per
784
+ * specification.
785
+ *
786
+ * Corresponds to the [Link() concrete method](https://tc39.es/ecma262/#sec-moduledeclarationlinking) field of [Cyclic Module Record](https://tc39.es/ecma262/#sec-cyclic-module-records) s in
787
+ * the ECMAScript specification.
587
788
  */
588
789
  link(linker: ModuleLinker): Promise<void>;
589
790
  }
590
-
591
791
  interface SourceTextModuleOptions {
592
792
  /**
593
793
  * String used in stack traces.
@@ -604,6 +804,17 @@ declare module 'vm' {
604
804
  initializeImportMeta?: ((meta: ImportMeta, module: SourceTextModule) => void) | undefined;
605
805
  importModuleDynamically?: ScriptOptions['importModuleDynamically'] | undefined;
606
806
  }
807
+ /**
808
+ * This feature is only available with the `--experimental-vm-modules` command
809
+ * flag enabled.
810
+ *
811
+ *
812
+ *
813
+ * The `vm.SourceTextModule` class provides the [Source Text Module Record](https://tc39.es/ecma262/#sec-source-text-module-records) as
814
+ * defined in the ECMAScript specification.
815
+ * @since v9.6.0
816
+ * @experimental
817
+ */
607
818
  class SourceTextModule extends Module {
608
819
  /**
609
820
  * Creates a new `SourceTextModule` instance.
@@ -611,7 +822,6 @@ declare module 'vm' {
611
822
  */
612
823
  constructor(code: string, options?: SourceTextModuleOptions);
613
824
  }
614
-
615
825
  interface SyntheticModuleOptions {
616
826
  /**
617
827
  * String used in stack traces.
@@ -623,6 +833,31 @@ declare module 'vm' {
623
833
  */
624
834
  context?: Context | undefined;
625
835
  }
836
+ /**
837
+ * This feature is only available with the `--experimental-vm-modules` command
838
+ * flag enabled.
839
+ *
840
+ *
841
+ *
842
+ * The `vm.SyntheticModule` class provides the [Synthetic Module Record](https://heycam.github.io/webidl/#synthetic-module-records) as
843
+ * defined in the WebIDL specification. The purpose of synthetic modules is to
844
+ * provide a generic interface for exposing non-JavaScript sources to ECMAScript
845
+ * module graphs.
846
+ *
847
+ * ```js
848
+ * const vm = require('node:vm');
849
+ *
850
+ * const source = '{ "a": 1 }';
851
+ * const module = new vm.SyntheticModule(['default'], function() {
852
+ * const obj = JSON.parse(source);
853
+ * this.setExport('default', obj);
854
+ * });
855
+ *
856
+ * // Use `module` in linking...
857
+ * ```
858
+ * @since v13.0.0, v12.16.0
859
+ * @experimental
860
+ */
626
861
  class SyntheticModule extends Module {
627
862
  /**
628
863
  * Creates a new `SyntheticModule` instance.
@@ -631,10 +866,25 @@ declare module 'vm' {
631
866
  */
632
867
  constructor(exportNames: string[], evaluateCallback: (this: SyntheticModule) => void, options?: SyntheticModuleOptions);
633
868
  /**
634
- * This method is used after the module is linked to set the values of exports.
635
- * If it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error will be thrown.
636
- * @param name
637
- * @param value
869
+ * This method is used after the module is linked to set the values of exports. If
870
+ * it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error
871
+ * will be thrown.
872
+ *
873
+ * ```js
874
+ * import vm from 'node:vm';
875
+ *
876
+ * const m = new vm.SyntheticModule(['x'], () => {
877
+ * m.setExport('x', 1);
878
+ * });
879
+ *
880
+ * await m.link(() => {});
881
+ * await m.evaluate();
882
+ *
883
+ * assert.strictEqual(m.namespace.x, 1);
884
+ * ```
885
+ * @since v13.0.0, v12.16.0
886
+ * @param name Name of the export to set.
887
+ * @param value The value to set the export to.
638
888
  */
639
889
  setExport(name: string, value: any): void;
640
890
  }
node/wasi.d.ts CHANGED
@@ -3,26 +3,23 @@
3
3
  * underlying operating system via a collection of POSIX-like functions.
4
4
  *
5
5
  * ```js
6
- * import { readFile } from 'fs/promises';
6
+ * import { readFile } from 'node:fs/promises';
7
7
  * import { WASI } from 'wasi';
8
- * import { argv, env } from 'process';
8
+ * import { argv, env } from 'node:process';
9
9
  *
10
10
  * const wasi = new WASI({
11
+ * version: 'preview1',
11
12
  * args: argv,
12
13
  * env,
13
14
  * preopens: {
14
- * '/sandbox': '/some/real/path/that/wasm/can/access'
15
- * }
15
+ * '/sandbox': '/some/real/path/that/wasm/can/access',
16
+ * },
16
17
  * });
17
18
  *
18
- * // Some WASI binaries require:
19
- * // const importObject = { wasi_unstable: wasi.wasiImport };
20
- * const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
21
- *
22
19
  * const wasm = await WebAssembly.compile(
23
- * await readFile(new URL('./demo.wasm', import.meta.url))
20
+ * await readFile(new URL('./demo.wasm', import.meta.url)),
24
21
  * );
25
- * const instance = await WebAssembly.instantiate(wasm, importObject);
22
+ * const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject());
26
23
  *
27
24
  * wasi.start(instance);
28
25
  * ```
@@ -64,11 +61,8 @@
64
61
  * ```console
65
62
  * $ wat2wasm demo.wat
66
63
  * ```
67
- *
68
- * The `--experimental-wasi-unstable-preview1` CLI argument is needed for this
69
- * example to run.
70
64
  * @experimental
71
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/wasi.js)
65
+ * @see [source](https://github.com/nodejs/node/blob/v20.0.0/lib/wasi.js)
72
66
  */
73
67
  declare module 'wasi' {
74
68
  interface WASIOptions {