@types/node 25.6.2 → 25.7.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.
- node/README.md +1 -1
- node/events.d.ts +6 -9
- node/fs/promises.d.ts +24 -1
- node/fs.d.ts +126 -6
- node/http2.d.ts +12 -0
- node/package.json +3 -3
- node/process.d.ts +29 -24
- node/stream.d.ts +1 -1
- node/test/reporters.d.ts +1 -0
- node/test.d.ts +9 -0
- node/url.d.ts +24 -2
- node/vm.d.ts +50 -85
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:
|
|
11
|
+
* Last updated: Mon, 11 May 2026 20:06:09 GMT
|
|
12
12
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
|
13
13
|
|
|
14
14
|
# Credits
|
node/events.d.ts
CHANGED
|
@@ -528,15 +528,12 @@ declare module "node:events" {
|
|
|
528
528
|
* import { addAbortListener } from 'node:events';
|
|
529
529
|
*
|
|
530
530
|
* function example(signal) {
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* } finally {
|
|
538
|
-
* disposable?.[Symbol.dispose]();
|
|
539
|
-
* }
|
|
531
|
+
* signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
|
|
532
|
+
* // addAbortListener() returns a disposable, so the `using` keyword ensures
|
|
533
|
+
* // the abort listener is automatically removed when this scope exits.
|
|
534
|
+
* using _ = addAbortListener(signal, (e) => {
|
|
535
|
+
* // Do something when signal is aborted.
|
|
536
|
+
* });
|
|
540
537
|
* }
|
|
541
538
|
* ```
|
|
542
539
|
* @since v20.5.0
|
node/fs/promises.d.ts
CHANGED
|
@@ -802,19 +802,42 @@ declare module "node:fs/promises" {
|
|
|
802
802
|
* @since v10.0.0
|
|
803
803
|
* @return Fulfills with the {fs.Stats} object for the given `path`.
|
|
804
804
|
*/
|
|
805
|
+
function stat(path: PathLike): Promise<Stats>;
|
|
805
806
|
function stat(
|
|
806
807
|
path: PathLike,
|
|
807
808
|
opts?: StatOptions & {
|
|
808
809
|
bigint?: false | undefined;
|
|
810
|
+
throwIfNoEntry?: true | undefined;
|
|
809
811
|
},
|
|
810
812
|
): Promise<Stats>;
|
|
811
813
|
function stat(
|
|
812
814
|
path: PathLike,
|
|
813
815
|
opts: StatOptions & {
|
|
814
816
|
bigint: true;
|
|
817
|
+
throwIfNoEntry?: true | undefined;
|
|
815
818
|
},
|
|
816
819
|
): Promise<BigIntStats>;
|
|
817
|
-
function stat(
|
|
820
|
+
function stat(
|
|
821
|
+
path: PathLike,
|
|
822
|
+
opts: StatOptions & {
|
|
823
|
+
bigint?: false | undefined;
|
|
824
|
+
throwIfNoEntry: false;
|
|
825
|
+
},
|
|
826
|
+
): Promise<Stats | undefined>;
|
|
827
|
+
function stat(
|
|
828
|
+
path: PathLike,
|
|
829
|
+
opts: StatOptions & {
|
|
830
|
+
bigint: true;
|
|
831
|
+
throwIfNoEntry: false;
|
|
832
|
+
},
|
|
833
|
+
): Promise<BigIntStats | undefined>;
|
|
834
|
+
function stat(
|
|
835
|
+
path: PathLike,
|
|
836
|
+
opts: StatOptions & {
|
|
837
|
+
throwIfNoEntry?: true | undefined;
|
|
838
|
+
},
|
|
839
|
+
): Promise<Stats | BigIntStats>;
|
|
840
|
+
function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats | undefined>;
|
|
818
841
|
/**
|
|
819
842
|
* @since v19.6.0, v18.15.0
|
|
820
843
|
* @return Fulfills with the {fs.StatFs} object for the given `path`.
|
node/fs.d.ts
CHANGED
|
@@ -1144,6 +1144,7 @@ declare module "node:fs" {
|
|
|
1144
1144
|
options:
|
|
1145
1145
|
| (StatOptions & {
|
|
1146
1146
|
bigint?: false | undefined;
|
|
1147
|
+
throwIfNoEntry?: true | undefined;
|
|
1147
1148
|
})
|
|
1148
1149
|
| undefined,
|
|
1149
1150
|
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void,
|
|
@@ -1152,33 +1153,82 @@ declare module "node:fs" {
|
|
|
1152
1153
|
path: PathLike,
|
|
1153
1154
|
options: StatOptions & {
|
|
1154
1155
|
bigint: true;
|
|
1156
|
+
throwIfNoEntry?: true | undefined;
|
|
1155
1157
|
},
|
|
1156
1158
|
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void,
|
|
1157
1159
|
): void;
|
|
1158
1160
|
function stat(
|
|
1159
1161
|
path: PathLike,
|
|
1160
|
-
options: StatOptions
|
|
1162
|
+
options: StatOptions & {
|
|
1163
|
+
bigint?: false | undefined;
|
|
1164
|
+
throwIfNoEntry: false;
|
|
1165
|
+
},
|
|
1166
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats | undefined) => void,
|
|
1167
|
+
): void;
|
|
1168
|
+
function stat(
|
|
1169
|
+
path: PathLike,
|
|
1170
|
+
options: StatOptions & {
|
|
1171
|
+
bigint: true;
|
|
1172
|
+
throwIfNoEntry: false;
|
|
1173
|
+
},
|
|
1174
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats | undefined) => void,
|
|
1175
|
+
): void;
|
|
1176
|
+
function stat(
|
|
1177
|
+
path: PathLike,
|
|
1178
|
+
options: StatOptions & {
|
|
1179
|
+
throwIfNoEntry?: true | undefined;
|
|
1180
|
+
},
|
|
1161
1181
|
callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void,
|
|
1162
1182
|
): void;
|
|
1183
|
+
function stat(
|
|
1184
|
+
path: PathLike,
|
|
1185
|
+
options: StatOptions | undefined,
|
|
1186
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats | undefined) => void,
|
|
1187
|
+
): void;
|
|
1163
1188
|
namespace stat {
|
|
1189
|
+
// TODO: aliased promisify signatures
|
|
1164
1190
|
/**
|
|
1165
1191
|
* Asynchronous stat(2) - Get file status.
|
|
1166
1192
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1167
1193
|
*/
|
|
1194
|
+
function __promisify__(path: PathLike): Promise<Stats>;
|
|
1168
1195
|
function __promisify__(
|
|
1169
1196
|
path: PathLike,
|
|
1170
1197
|
options?: StatOptions & {
|
|
1171
1198
|
bigint?: false | undefined;
|
|
1199
|
+
throwIfNoEntry?: true | undefined;
|
|
1172
1200
|
},
|
|
1173
1201
|
): Promise<Stats>;
|
|
1174
1202
|
function __promisify__(
|
|
1175
1203
|
path: PathLike,
|
|
1176
1204
|
options: StatOptions & {
|
|
1177
1205
|
bigint: true;
|
|
1206
|
+
throwIfNoEntry?: true | undefined;
|
|
1178
1207
|
},
|
|
1179
1208
|
): Promise<BigIntStats>;
|
|
1180
|
-
function __promisify__(
|
|
1209
|
+
function __promisify__(
|
|
1210
|
+
path: PathLike,
|
|
1211
|
+
options: StatOptions & {
|
|
1212
|
+
bigint?: false | undefined;
|
|
1213
|
+
throwIfNoEntry: false;
|
|
1214
|
+
},
|
|
1215
|
+
): Promise<Stats | undefined>;
|
|
1216
|
+
function __promisify__(
|
|
1217
|
+
path: PathLike,
|
|
1218
|
+
options: StatOptions & {
|
|
1219
|
+
bigint: true;
|
|
1220
|
+
throwIfNoEntry: false;
|
|
1221
|
+
},
|
|
1222
|
+
): Promise<BigIntStats | undefined>;
|
|
1223
|
+
function __promisify__(
|
|
1224
|
+
path: PathLike,
|
|
1225
|
+
options: StatOptions & {
|
|
1226
|
+
throwIfNoEntry?: true | undefined;
|
|
1227
|
+
},
|
|
1228
|
+
): Promise<Stats | BigIntStats>;
|
|
1229
|
+
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats | undefined>;
|
|
1181
1230
|
}
|
|
1231
|
+
/** @deprecated This orphaned interface will be removed in a future version. */
|
|
1182
1232
|
interface StatSyncFn extends Function {
|
|
1183
1233
|
(path: PathLike, options?: undefined): Stats;
|
|
1184
1234
|
(
|
|
@@ -1220,7 +1270,42 @@ declare module "node:fs" {
|
|
|
1220
1270
|
* Synchronous stat(2) - Get file status.
|
|
1221
1271
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1222
1272
|
*/
|
|
1223
|
-
|
|
1273
|
+
function statSync(path: PathLike): Stats;
|
|
1274
|
+
function statSync(
|
|
1275
|
+
path: PathLike,
|
|
1276
|
+
options?: StatOptions & {
|
|
1277
|
+
bigint?: false | undefined;
|
|
1278
|
+
throwIfNoEntry?: true | undefined;
|
|
1279
|
+
},
|
|
1280
|
+
): Stats;
|
|
1281
|
+
function statSync(
|
|
1282
|
+
path: PathLike,
|
|
1283
|
+
options: StatOptions & {
|
|
1284
|
+
bigint: true;
|
|
1285
|
+
throwIfNoEntry?: true | undefined;
|
|
1286
|
+
},
|
|
1287
|
+
): BigIntStats;
|
|
1288
|
+
function statSync(
|
|
1289
|
+
path: PathLike,
|
|
1290
|
+
options: StatOptions & {
|
|
1291
|
+
bigint?: false | undefined;
|
|
1292
|
+
throwIfNoEntry: false;
|
|
1293
|
+
},
|
|
1294
|
+
): Stats | undefined;
|
|
1295
|
+
function statSync(
|
|
1296
|
+
path: PathLike,
|
|
1297
|
+
options: StatOptions & {
|
|
1298
|
+
bigint: true;
|
|
1299
|
+
throwIfNoEntry: false;
|
|
1300
|
+
},
|
|
1301
|
+
): BigIntStats | undefined;
|
|
1302
|
+
function statSync(
|
|
1303
|
+
path: PathLike,
|
|
1304
|
+
options: StatOptions & {
|
|
1305
|
+
throwIfNoEntry?: true | undefined;
|
|
1306
|
+
},
|
|
1307
|
+
): Stats | BigIntStats;
|
|
1308
|
+
function statSync(path: PathLike, options?: StatOptions): Stats | BigIntStats | undefined;
|
|
1224
1309
|
/**
|
|
1225
1310
|
* Invokes the callback with the `fs.Stats` for the file descriptor.
|
|
1226
1311
|
*
|
|
@@ -1410,7 +1495,42 @@ declare module "node:fs" {
|
|
|
1410
1495
|
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
1411
1496
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1412
1497
|
*/
|
|
1413
|
-
|
|
1498
|
+
function lstatSync(path: PathLike): Stats;
|
|
1499
|
+
function lstatSync(
|
|
1500
|
+
path: PathLike,
|
|
1501
|
+
options?: StatOptions & {
|
|
1502
|
+
bigint?: false | undefined;
|
|
1503
|
+
throwIfNoEntry?: true | undefined;
|
|
1504
|
+
},
|
|
1505
|
+
): Stats;
|
|
1506
|
+
function lstatSync(
|
|
1507
|
+
path: PathLike,
|
|
1508
|
+
options: StatOptions & {
|
|
1509
|
+
bigint: true;
|
|
1510
|
+
throwIfNoEntry?: true | undefined;
|
|
1511
|
+
},
|
|
1512
|
+
): BigIntStats;
|
|
1513
|
+
function lstatSync(
|
|
1514
|
+
path: PathLike,
|
|
1515
|
+
options: StatOptions & {
|
|
1516
|
+
bigint?: false | undefined;
|
|
1517
|
+
throwIfNoEntry: false;
|
|
1518
|
+
},
|
|
1519
|
+
): Stats | undefined;
|
|
1520
|
+
function lstatSync(
|
|
1521
|
+
path: PathLike,
|
|
1522
|
+
options: StatOptions & {
|
|
1523
|
+
bigint: true;
|
|
1524
|
+
throwIfNoEntry: false;
|
|
1525
|
+
},
|
|
1526
|
+
): BigIntStats | undefined;
|
|
1527
|
+
function lstatSync(
|
|
1528
|
+
path: PathLike,
|
|
1529
|
+
options: StatOptions & {
|
|
1530
|
+
throwIfNoEntry?: true | undefined;
|
|
1531
|
+
},
|
|
1532
|
+
): Stats | BigIntStats;
|
|
1533
|
+
function lstatSync(path: PathLike, options?: StatOptions): Stats | BigIntStats | undefined;
|
|
1414
1534
|
/**
|
|
1415
1535
|
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. No arguments other than
|
|
1416
1536
|
* a possible
|
|
@@ -4461,10 +4581,10 @@ declare module "node:fs" {
|
|
|
4461
4581
|
}
|
|
4462
4582
|
interface StatOptions {
|
|
4463
4583
|
bigint?: boolean | undefined;
|
|
4464
|
-
}
|
|
4465
|
-
interface StatSyncOptions extends StatOptions {
|
|
4466
4584
|
throwIfNoEntry?: boolean | undefined;
|
|
4467
4585
|
}
|
|
4586
|
+
/** @deprecated This orphaned interface will be removed in a future version. Use `StatOptions` instead. */
|
|
4587
|
+
interface StatSyncOptions extends StatOptions {}
|
|
4468
4588
|
interface CopyOptionsBase {
|
|
4469
4589
|
/**
|
|
4470
4590
|
* Dereference symlinks
|
node/http2.d.ts
CHANGED
|
@@ -1242,10 +1242,14 @@ declare module "node:http2" {
|
|
|
1242
1242
|
> extends SessionOptions {
|
|
1243
1243
|
streamResetBurst?: number | undefined;
|
|
1244
1244
|
streamResetRate?: number | undefined;
|
|
1245
|
+
/** @deprecated Use `http1Options.IncomingMessage` instead. */
|
|
1245
1246
|
Http1IncomingMessage?: Http1Request | undefined;
|
|
1247
|
+
/** @deprecated Use `http1Options.ServerResponse` instead. */
|
|
1246
1248
|
Http1ServerResponse?: Http1Response | undefined;
|
|
1249
|
+
http1Options?: Http1Options<Http1Request, Http1Response> | undefined;
|
|
1247
1250
|
Http2ServerRequest?: Http2Request | undefined;
|
|
1248
1251
|
Http2ServerResponse?: Http2Response | undefined;
|
|
1252
|
+
strictSingleValueFields?: boolean | undefined;
|
|
1249
1253
|
}
|
|
1250
1254
|
interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions {}
|
|
1251
1255
|
interface SecureServerSessionOptions<
|
|
@@ -1269,6 +1273,14 @@ declare module "node:http2" {
|
|
|
1269
1273
|
allowHTTP1?: boolean | undefined;
|
|
1270
1274
|
origins?: string[] | undefined;
|
|
1271
1275
|
}
|
|
1276
|
+
interface Http1Options<
|
|
1277
|
+
Request extends typeof IncomingMessage,
|
|
1278
|
+
Response extends typeof ServerResponse<InstanceType<Request>>,
|
|
1279
|
+
> {
|
|
1280
|
+
IncomingMessage?: Request | undefined;
|
|
1281
|
+
ServerResponse?: Response | undefined;
|
|
1282
|
+
keepAliveTimeout?: number | undefined;
|
|
1283
|
+
}
|
|
1272
1284
|
interface Http2ServerCommon {
|
|
1273
1285
|
setTimeout(msec?: number, callback?: () => void): this;
|
|
1274
1286
|
/**
|
node/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.7.0",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -147,9 +147,9 @@
|
|
|
147
147
|
},
|
|
148
148
|
"scripts": {},
|
|
149
149
|
"dependencies": {
|
|
150
|
-
"undici-types": "~7.
|
|
150
|
+
"undici-types": "~7.21.0"
|
|
151
151
|
},
|
|
152
152
|
"peerDependencies": {},
|
|
153
|
-
"typesPublisherContentHash": "
|
|
153
|
+
"typesPublisherContentHash": "eddf50137d03f63ae7f6e4766ed9b825cc70a85ef2f7d5c89290fba06040ceed",
|
|
154
154
|
"typeScriptVersion": "5.3"
|
|
155
155
|
}
|
node/process.d.ts
CHANGED
|
@@ -1474,30 +1474,35 @@ declare module "node:process" {
|
|
|
1474
1474
|
* Will generate an object similar to:
|
|
1475
1475
|
*
|
|
1476
1476
|
* ```console
|
|
1477
|
-
* { node: '
|
|
1478
|
-
* acorn: '8.
|
|
1479
|
-
* ada: '
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1482
|
-
* brotli: '1.0
|
|
1483
|
-
*
|
|
1484
|
-
* cldr: '
|
|
1485
|
-
* icu: '
|
|
1486
|
-
* llhttp: '
|
|
1487
|
-
* modules: '
|
|
1488
|
-
* napi: '
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
*
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1477
|
+
* { node: '26.0.0-pre',
|
|
1478
|
+
* acorn: '8.15.0',
|
|
1479
|
+
* ada: '3.4.1',
|
|
1480
|
+
* amaro: '1.1.5',
|
|
1481
|
+
* ares: '1.34.6',
|
|
1482
|
+
* brotli: '1.2.0',
|
|
1483
|
+
* merve: '1.0.0',
|
|
1484
|
+
* cldr: '48.0',
|
|
1485
|
+
* icu: '78.2',
|
|
1486
|
+
* llhttp: '9.3.0',
|
|
1487
|
+
* modules: '144',
|
|
1488
|
+
* napi: '10',
|
|
1489
|
+
* nbytes: '0.1.1',
|
|
1490
|
+
* ncrypto: '0.0.1',
|
|
1491
|
+
* nghttp2: '1.68.0',
|
|
1492
|
+
* nghttp3: '',
|
|
1493
|
+
* ngtcp2: '',
|
|
1494
|
+
* openssl: '3.5.4',
|
|
1495
|
+
* simdjson: '4.2.4',
|
|
1496
|
+
* simdutf: '7.3.3',
|
|
1497
|
+
* sqlite: '3.51.2',
|
|
1498
|
+
* tz: '2025c',
|
|
1499
|
+
* undici: '7.18.2',
|
|
1500
|
+
* unicode: '17.0',
|
|
1501
|
+
* uv: '1.51.0',
|
|
1502
|
+
* uvwasi: '0.0.23',
|
|
1503
|
+
* v8: '14.3.127.18-node.10',
|
|
1504
|
+
* zlib: '1.3.1-e00f703',
|
|
1505
|
+
* zstd: '1.5.7' }
|
|
1501
1506
|
* ```
|
|
1502
1507
|
* @since v0.2.0
|
|
1503
1508
|
*/
|
node/stream.d.ts
CHANGED
|
@@ -1067,7 +1067,7 @@ declare module "node:stream" {
|
|
|
1067
1067
|
writableCorked?: number | undefined;
|
|
1068
1068
|
}
|
|
1069
1069
|
interface DuplexToWebOptions {
|
|
1070
|
-
|
|
1070
|
+
readableType?: web.ReadableStreamType | undefined;
|
|
1071
1071
|
}
|
|
1072
1072
|
interface DuplexEventMap extends ReadableEventMap, WritableEventMap {}
|
|
1073
1073
|
/**
|
node/test/reporters.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare module "node:test/reporters" {
|
|
|
8
8
|
| { type: "test:diagnostic"; data: EventData.TestDiagnostic }
|
|
9
9
|
| { type: "test:enqueue"; data: EventData.TestEnqueue }
|
|
10
10
|
| { type: "test:fail"; data: EventData.TestFail }
|
|
11
|
+
| { type: "test:interrupted"; data: EventData.TestInterrupted }
|
|
11
12
|
| { type: "test:pass"; data: EventData.TestPass }
|
|
12
13
|
| { type: "test:plan"; data: EventData.TestPlan }
|
|
13
14
|
| { type: "test:start"; data: EventData.TestStart }
|
node/test.d.ts
CHANGED
|
@@ -334,6 +334,7 @@ declare module "node:test" {
|
|
|
334
334
|
* This options is not compatible with `isolation='none'`. These variables will override
|
|
335
335
|
* those from the main process, and are not merged with `process.env`.
|
|
336
336
|
* @since v25.6.0
|
|
337
|
+
* @default process.env
|
|
337
338
|
*/
|
|
338
339
|
env?: NodeJS.ProcessEnv | undefined;
|
|
339
340
|
}
|
|
@@ -345,6 +346,7 @@ declare module "node:test" {
|
|
|
345
346
|
"test:diagnostic": [data: EventData.TestDiagnostic];
|
|
346
347
|
"test:enqueue": [data: EventData.TestEnqueue];
|
|
347
348
|
"test:fail": [data: EventData.TestFail];
|
|
349
|
+
"test:interrupted": [data: EventData.TestInterrupted];
|
|
348
350
|
"test:pass": [data: EventData.TestPass];
|
|
349
351
|
"test:plan": [data: EventData.TestPlan];
|
|
350
352
|
"test:start": [data: EventData.TestStart];
|
|
@@ -736,6 +738,13 @@ declare module "node:test" {
|
|
|
736
738
|
*/
|
|
737
739
|
skip?: string | boolean;
|
|
738
740
|
}
|
|
741
|
+
interface TestInterrupted {
|
|
742
|
+
/**
|
|
743
|
+
* An array of objects containing information about the
|
|
744
|
+
* interrupted tests.
|
|
745
|
+
*/
|
|
746
|
+
tests: TestStart[];
|
|
747
|
+
}
|
|
739
748
|
interface TestPass extends LocationInfo {
|
|
740
749
|
/**
|
|
741
750
|
* Additional execution metadata.
|
node/url.d.ts
CHANGED
|
@@ -229,9 +229,31 @@ declare module "node:url" {
|
|
|
229
229
|
* * `result` is returned.
|
|
230
230
|
* @since v0.1.25
|
|
231
231
|
* @legacy Use the WHATWG URL API instead.
|
|
232
|
-
* @param urlObject A URL object (as returned by `url.parse()` or constructed otherwise).
|
|
232
|
+
* @param urlObject A URL object (as returned by `url.parse()` or constructed otherwise).
|
|
233
|
+
*/
|
|
234
|
+
function format(urlObject: UrlObject): string;
|
|
235
|
+
/**
|
|
236
|
+
* `url.format(urlString)` is shorthand for `url.format(url.parse(urlString))`.
|
|
237
|
+
*
|
|
238
|
+
* Because it invokes the deprecated `url.parse()`, passing a string argument
|
|
239
|
+
* to `url.format()` is itself deprecated.
|
|
240
|
+
*
|
|
241
|
+
* Canonicalizing a URL string can be performed using the WHATWG URL API, by
|
|
242
|
+
* constructing a new URL object and calling `url.toString()`.
|
|
243
|
+
*
|
|
244
|
+
* ```js
|
|
245
|
+
* import { URL } from 'node:url';
|
|
246
|
+
*
|
|
247
|
+
* const unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';
|
|
248
|
+
* const formatted = new URL(unformatted).toString();
|
|
249
|
+
*
|
|
250
|
+
* console.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc
|
|
251
|
+
* ```
|
|
252
|
+
* @since v0.1.25
|
|
253
|
+
* @deprecated Use the WHATWG URL API instead.
|
|
254
|
+
* @param urlString A string that will be passed to `url.parse()` and then formatted.
|
|
233
255
|
*/
|
|
234
|
-
function format(
|
|
256
|
+
function format(urlString: string): string;
|
|
235
257
|
/**
|
|
236
258
|
* The `url.resolve()` method resolves a target URL relative to a base URL in a
|
|
237
259
|
* manner similar to that of a web browser resolving an anchor tag.
|
node/vm.d.ts
CHANGED
|
@@ -200,16 +200,16 @@ declare module "node:vm" {
|
|
|
200
200
|
* The globals are contained in the `context` object.
|
|
201
201
|
*
|
|
202
202
|
* ```js
|
|
203
|
-
* import
|
|
203
|
+
* import { createContext, Script } from 'node:vm';
|
|
204
204
|
*
|
|
205
205
|
* const context = {
|
|
206
206
|
* animal: 'cat',
|
|
207
207
|
* count: 2,
|
|
208
208
|
* };
|
|
209
209
|
*
|
|
210
|
-
* const script = new
|
|
210
|
+
* const script = new Script('count += 1; name = "kitty";');
|
|
211
211
|
*
|
|
212
|
-
*
|
|
212
|
+
* createContext(context);
|
|
213
213
|
* for (let i = 0; i < 10; ++i) {
|
|
214
214
|
* script.runInContext(context);
|
|
215
215
|
* }
|
|
@@ -243,9 +243,9 @@ declare module "node:vm" {
|
|
|
243
243
|
* contained within each individual `context`.
|
|
244
244
|
*
|
|
245
245
|
* ```js
|
|
246
|
-
*
|
|
246
|
+
* import { constants, Script } from 'node:vm';
|
|
247
247
|
*
|
|
248
|
-
* const script = new
|
|
248
|
+
* const script = new Script('globalVar = "set"');
|
|
249
249
|
*
|
|
250
250
|
* const contexts = [{}, {}, {}];
|
|
251
251
|
* contexts.forEach((context) => {
|
|
@@ -256,10 +256,10 @@ declare module "node:vm" {
|
|
|
256
256
|
* // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
|
|
257
257
|
*
|
|
258
258
|
* // This would throw if the context is created from a contextified object.
|
|
259
|
-
* //
|
|
259
|
+
* // constants.DONT_CONTEXTIFY allows creating contexts with ordinary
|
|
260
260
|
* // global objects that can be frozen.
|
|
261
|
-
* const freezeScript = new
|
|
262
|
-
* const frozenContext = freezeScript.runInNewContext(
|
|
261
|
+
* const freezeScript = new Script('Object.freeze(globalThis); globalThis;');
|
|
262
|
+
* const frozenContext = freezeScript.runInNewContext(constants.DONT_CONTEXTIFY);
|
|
263
263
|
* ```
|
|
264
264
|
* @since v0.3.1
|
|
265
265
|
* @param contextObject Either `vm.constants.DONT_CONTEXTIFY` or an object that will be contextified.
|
|
@@ -278,11 +278,11 @@ declare module "node:vm" {
|
|
|
278
278
|
* executes that code multiple times:
|
|
279
279
|
*
|
|
280
280
|
* ```js
|
|
281
|
-
* import
|
|
281
|
+
* import { Script } from 'node:vm';
|
|
282
282
|
*
|
|
283
283
|
* global.globalVar = 0;
|
|
284
284
|
*
|
|
285
|
-
* const script = new
|
|
285
|
+
* const script = new Script('globalVar += 1', { filename: 'myfile.vm' });
|
|
286
286
|
*
|
|
287
287
|
* for (let i = 0; i < 1000; ++i) {
|
|
288
288
|
* script.runInThisContext();
|
|
@@ -371,14 +371,14 @@ declare module "node:vm" {
|
|
|
371
371
|
* variables will remain unchanged.
|
|
372
372
|
*
|
|
373
373
|
* ```js
|
|
374
|
-
*
|
|
374
|
+
* import { createContext, runInContext } from 'node:vm';
|
|
375
375
|
*
|
|
376
376
|
* global.globalVar = 3;
|
|
377
377
|
*
|
|
378
378
|
* const context = { globalVar: 1 };
|
|
379
|
-
*
|
|
379
|
+
* createContext(context);
|
|
380
380
|
*
|
|
381
|
-
*
|
|
381
|
+
* runInContext('globalVar *= 2;', context);
|
|
382
382
|
*
|
|
383
383
|
* console.log(context);
|
|
384
384
|
* // Prints: { globalVar: 2 }
|
|
@@ -429,13 +429,13 @@ declare module "node:vm" {
|
|
|
429
429
|
* The following example compiles and executes different scripts using a single `contextified` object:
|
|
430
430
|
*
|
|
431
431
|
* ```js
|
|
432
|
-
* import
|
|
432
|
+
* import { createContext, runInContext } from 'node:vm';
|
|
433
433
|
*
|
|
434
434
|
* const contextObject = { globalVar: 1 };
|
|
435
|
-
*
|
|
435
|
+
* createContext(contextObject);
|
|
436
436
|
*
|
|
437
437
|
* for (let i = 0; i < 10; ++i) {
|
|
438
|
-
*
|
|
438
|
+
* runInContext('globalVar *= 2;', contextObject);
|
|
439
439
|
* }
|
|
440
440
|
* console.log(contextObject);
|
|
441
441
|
* // Prints: { globalVar: 1024 }
|
|
@@ -466,21 +466,24 @@ declare module "node:vm" {
|
|
|
466
466
|
* variable and sets a new one. These globals are contained in the `contextObject`.
|
|
467
467
|
*
|
|
468
468
|
* ```js
|
|
469
|
-
*
|
|
469
|
+
* import { runInNewContext, constants } from 'node:vm';
|
|
470
470
|
*
|
|
471
471
|
* const contextObject = {
|
|
472
472
|
* animal: 'cat',
|
|
473
473
|
* count: 2,
|
|
474
474
|
* };
|
|
475
475
|
*
|
|
476
|
-
*
|
|
476
|
+
* runInNewContext('count += 1; name = "kitty"', contextObject);
|
|
477
477
|
* console.log(contextObject);
|
|
478
478
|
* // Prints: { animal: 'cat', count: 3, name: 'kitty' }
|
|
479
479
|
*
|
|
480
480
|
* // This would throw if the context is created from a contextified object.
|
|
481
481
|
* // vm.constants.DONT_CONTEXTIFY allows creating contexts with ordinary global objects that
|
|
482
482
|
* // can be frozen.
|
|
483
|
-
* const frozenContext =
|
|
483
|
+
* const frozenContext = runInNewContext(
|
|
484
|
+
* 'Object.freeze(globalThis); globalThis;',
|
|
485
|
+
* constants.DONT_CONTEXTIFY,
|
|
486
|
+
* );
|
|
484
487
|
* ```
|
|
485
488
|
* @since v0.3.1
|
|
486
489
|
* @param code The JavaScript code to compile and run.
|
|
@@ -504,10 +507,10 @@ declare module "node:vm" {
|
|
|
504
507
|
* the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
|
|
505
508
|
*
|
|
506
509
|
* ```js
|
|
507
|
-
* import
|
|
510
|
+
* import { runInThisContext } from 'node:vm';
|
|
508
511
|
* let localVar = 'initial value';
|
|
509
512
|
*
|
|
510
|
-
* const vmResult =
|
|
513
|
+
* const vmResult = runInThisContext('localVar = "vm";');
|
|
511
514
|
* console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
|
|
512
515
|
* // Prints: vmResult: 'vm', localVar: 'initial value'
|
|
513
516
|
*
|
|
@@ -519,38 +522,6 @@ declare module "node:vm" {
|
|
|
519
522
|
* Because `vm.runInThisContext()` does not have access to the local scope, `localVar` is unchanged. In contrast,
|
|
520
523
|
* [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
|
|
521
524
|
* local scope, so the value `localVar` is changed. In this way `vm.runInThisContext()` is much like an [indirect `eval()` call](https://es5.github.io/#x10.4.2), e.g.`(0,eval)('code')`.
|
|
522
|
-
*
|
|
523
|
-
* ## Example: Running an HTTP server within a VM
|
|
524
|
-
*
|
|
525
|
-
* When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
|
|
526
|
-
* context. The code passed to this VM context will have its own isolated scope.
|
|
527
|
-
*
|
|
528
|
-
* In order to run a simple web server using the `node:http` module the code passed
|
|
529
|
-
* to the context must either import `node:http` on its own, or have a
|
|
530
|
-
* reference to the `node:http` module passed to it. For instance:
|
|
531
|
-
*
|
|
532
|
-
* ```js
|
|
533
|
-
* 'use strict';
|
|
534
|
-
* import vm from 'node:vm';
|
|
535
|
-
*
|
|
536
|
-
* const code = `
|
|
537
|
-
* ((require) => {
|
|
538
|
-
* const http = require('node:http');
|
|
539
|
-
*
|
|
540
|
-
* http.createServer((request, response) => {
|
|
541
|
-
* response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
542
|
-
* response.end('Hello World\\n');
|
|
543
|
-
* }).listen(8124);
|
|
544
|
-
*
|
|
545
|
-
* console.log('Server running at http://127.0.0.1:8124/');
|
|
546
|
-
* })`;
|
|
547
|
-
*
|
|
548
|
-
* vm.runInThisContext(code)(require);
|
|
549
|
-
* ```
|
|
550
|
-
*
|
|
551
|
-
* The `require()` in the above case shares the state with the context it is
|
|
552
|
-
* passed from. This may introduce risks when untrusted code is executed, e.g.
|
|
553
|
-
* altering objects in the context in unwanted ways.
|
|
554
525
|
* @since v0.3.1
|
|
555
526
|
* @param code The JavaScript code to compile and run.
|
|
556
527
|
* @return the result of the very last statement executed in the script.
|
|
@@ -582,44 +553,32 @@ declare module "node:vm" {
|
|
|
582
553
|
* the memory occupied by each heap space in the current V8 instance.
|
|
583
554
|
*
|
|
584
555
|
* ```js
|
|
585
|
-
* import
|
|
556
|
+
* import { createContext, measureMemory } from 'node:vm';
|
|
586
557
|
* // Measure the memory used by the main context.
|
|
587
|
-
*
|
|
558
|
+
* measureMemory({ mode: 'summary' })
|
|
588
559
|
* // This is the same as vm.measureMemory()
|
|
589
560
|
* .then((result) => {
|
|
590
561
|
* // The current format is:
|
|
591
562
|
* // {
|
|
592
|
-
* // total: {
|
|
593
|
-
* //
|
|
594
|
-
* // }
|
|
563
|
+
* // total: { jsMemoryEstimate: 1601828, jsMemoryRange: [1601828, 5275288] },
|
|
564
|
+
* // WebAssembly: { code: 0, metadata: 33962 },
|
|
595
565
|
* // }
|
|
596
566
|
* console.log(result);
|
|
597
567
|
* });
|
|
598
568
|
*
|
|
599
|
-
* const context =
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
* // jsMemoryRange: [ 2438996, 2768636 ]
|
|
613
|
-
* // },
|
|
614
|
-
* // other: [
|
|
615
|
-
* // {
|
|
616
|
-
* // jsMemoryEstimate: 135736,
|
|
617
|
-
* // jsMemoryRange: [ 135736, 465376 ]
|
|
618
|
-
* // }
|
|
619
|
-
* // ]
|
|
620
|
-
* // }
|
|
621
|
-
* console.log(result);
|
|
622
|
-
* });
|
|
569
|
+
* const context = createContext({ a: 1 });
|
|
570
|
+
* measureMemory({ mode: 'detailed', execution: 'eager' }).then((result) => {
|
|
571
|
+
* // Reference the context here so that it won't be GC'ed
|
|
572
|
+
* // until the measurement is complete.
|
|
573
|
+
* console.log('Context:', context.a);
|
|
574
|
+
* // {
|
|
575
|
+
* // total: { jsMemoryEstimate: 1767100, jsMemoryRange: [1767100, 5440560] },
|
|
576
|
+
* // WebAssembly: { code: 0, metadata: 33962 },
|
|
577
|
+
* // current: { jsMemoryEstimate: 1601828, jsMemoryRange: [1601828, 5275288] },
|
|
578
|
+
* // other: [{ jsMemoryEstimate: 165272, jsMemoryRange: [Array] }],
|
|
579
|
+
* // }
|
|
580
|
+
* console.log(result);
|
|
581
|
+
* });
|
|
623
582
|
* ```
|
|
624
583
|
* @since v13.10.0
|
|
625
584
|
* @experimental
|
|
@@ -1092,15 +1051,21 @@ declare module "node:vm" {
|
|
|
1092
1051
|
* module graphs.
|
|
1093
1052
|
*
|
|
1094
1053
|
* ```js
|
|
1095
|
-
* import
|
|
1054
|
+
* import { SyntheticModule } from 'node:vm';
|
|
1096
1055
|
*
|
|
1097
1056
|
* const source = '{ "a": 1 }';
|
|
1098
|
-
* const
|
|
1057
|
+
* const syntheticModule = new SyntheticModule(['default'], function() {
|
|
1099
1058
|
* const obj = JSON.parse(source);
|
|
1100
1059
|
* this.setExport('default', obj);
|
|
1101
1060
|
* });
|
|
1102
1061
|
*
|
|
1103
|
-
* // Use `
|
|
1062
|
+
* // Use `syntheticModule` in linking
|
|
1063
|
+
* (async () => {
|
|
1064
|
+
* await syntheticModule.link(() => {});
|
|
1065
|
+
* await syntheticModule.evaluate();
|
|
1066
|
+
*
|
|
1067
|
+
* console.log('Default export:', syntheticModule.namespace.default);
|
|
1068
|
+
* })();
|
|
1104
1069
|
* ```
|
|
1105
1070
|
* @since v13.0.0, v12.16.0
|
|
1106
1071
|
* @experimental
|