@anthropic-ai/claude-code 0.2.14 → 0.2.18

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 (103) hide show
  1. package/cli.mjs +483 -468
  2. package/package.json +3 -5
  3. package/scripts/preinstall.js +15 -0
  4. package/vendor/sdk/node_modules/@types/node/LICENSE +0 -21
  5. package/vendor/sdk/node_modules/@types/node/README.md +0 -15
  6. package/vendor/sdk/node_modules/@types/node/assert/strict.d.ts +0 -8
  7. package/vendor/sdk/node_modules/@types/node/assert.d.ts +0 -985
  8. package/vendor/sdk/node_modules/@types/node/async_hooks.d.ts +0 -522
  9. package/vendor/sdk/node_modules/@types/node/buffer.buffer.d.ts +0 -385
  10. package/vendor/sdk/node_modules/@types/node/buffer.d.ts +0 -1903
  11. package/vendor/sdk/node_modules/@types/node/child_process.d.ts +0 -1549
  12. package/vendor/sdk/node_modules/@types/node/cluster.d.ts +0 -578
  13. package/vendor/sdk/node_modules/@types/node/compatibility/disposable.d.ts +0 -14
  14. package/vendor/sdk/node_modules/@types/node/compatibility/index.d.ts +0 -9
  15. package/vendor/sdk/node_modules/@types/node/compatibility/indexable.d.ts +0 -20
  16. package/vendor/sdk/node_modules/@types/node/compatibility/iterators.d.ts +0 -20
  17. package/vendor/sdk/node_modules/@types/node/console.d.ts +0 -452
  18. package/vendor/sdk/node_modules/@types/node/constants.d.ts +0 -19
  19. package/vendor/sdk/node_modules/@types/node/crypto.d.ts +0 -4453
  20. package/vendor/sdk/node_modules/@types/node/dgram.d.ts +0 -596
  21. package/vendor/sdk/node_modules/@types/node/diagnostics_channel.d.ts +0 -546
  22. package/vendor/sdk/node_modules/@types/node/dns/promises.d.ts +0 -475
  23. package/vendor/sdk/node_modules/@types/node/dns.d.ts +0 -853
  24. package/vendor/sdk/node_modules/@types/node/dom-events.d.ts +0 -124
  25. package/vendor/sdk/node_modules/@types/node/domain.d.ts +0 -170
  26. package/vendor/sdk/node_modules/@types/node/events.d.ts +0 -819
  27. package/vendor/sdk/node_modules/@types/node/fs/promises.d.ts +0 -1205
  28. package/vendor/sdk/node_modules/@types/node/fs.d.ts +0 -4237
  29. package/vendor/sdk/node_modules/@types/node/globals.d.ts +0 -442
  30. package/vendor/sdk/node_modules/@types/node/globals.typedarray.d.ts +0 -21
  31. package/vendor/sdk/node_modules/@types/node/http.d.ts +0 -1839
  32. package/vendor/sdk/node_modules/@types/node/http2.d.ts +0 -2517
  33. package/vendor/sdk/node_modules/@types/node/https.d.ts +0 -544
  34. package/vendor/sdk/node_modules/@types/node/index.d.ts +0 -90
  35. package/vendor/sdk/node_modules/@types/node/inspector.d.ts +0 -2775
  36. package/vendor/sdk/node_modules/@types/node/module.d.ts +0 -291
  37. package/vendor/sdk/node_modules/@types/node/net.d.ts +0 -924
  38. package/vendor/sdk/node_modules/@types/node/os.d.ts +0 -473
  39. package/vendor/sdk/node_modules/@types/node/package.json +0 -225
  40. package/vendor/sdk/node_modules/@types/node/path.d.ts +0 -191
  41. package/vendor/sdk/node_modules/@types/node/perf_hooks.d.ts +0 -753
  42. package/vendor/sdk/node_modules/@types/node/process.d.ts +0 -1553
  43. package/vendor/sdk/node_modules/@types/node/punycode.d.ts +0 -117
  44. package/vendor/sdk/node_modules/@types/node/querystring.d.ts +0 -141
  45. package/vendor/sdk/node_modules/@types/node/readline/promises.d.ts +0 -154
  46. package/vendor/sdk/node_modules/@types/node/readline.d.ts +0 -715
  47. package/vendor/sdk/node_modules/@types/node/repl.d.ts +0 -430
  48. package/vendor/sdk/node_modules/@types/node/stream/consumers.d.ts +0 -12
  49. package/vendor/sdk/node_modules/@types/node/stream/promises.d.ts +0 -90
  50. package/vendor/sdk/node_modules/@types/node/stream/web.d.ts +0 -523
  51. package/vendor/sdk/node_modules/@types/node/stream.d.ts +0 -1731
  52. package/vendor/sdk/node_modules/@types/node/string_decoder.d.ts +0 -67
  53. package/vendor/sdk/node_modules/@types/node/test.d.ts +0 -1245
  54. package/vendor/sdk/node_modules/@types/node/timers/promises.d.ts +0 -93
  55. package/vendor/sdk/node_modules/@types/node/timers.d.ts +0 -126
  56. package/vendor/sdk/node_modules/@types/node/tls.d.ts +0 -1203
  57. package/vendor/sdk/node_modules/@types/node/trace_events.d.ts +0 -171
  58. package/vendor/sdk/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +0 -385
  59. package/vendor/sdk/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -19
  60. package/vendor/sdk/node_modules/@types/node/ts5.6/index.d.ts +0 -90
  61. package/vendor/sdk/node_modules/@types/node/tty.d.ts +0 -206
  62. package/vendor/sdk/node_modules/@types/node/url.d.ts +0 -957
  63. package/vendor/sdk/node_modules/@types/node/util.d.ts +0 -2083
  64. package/vendor/sdk/node_modules/@types/node/v8.d.ts +0 -753
  65. package/vendor/sdk/node_modules/@types/node/vm.d.ts +0 -666
  66. package/vendor/sdk/node_modules/@types/node/wasi.d.ts +0 -160
  67. package/vendor/sdk/node_modules/@types/node/worker_threads.d.ts +0 -695
  68. package/vendor/sdk/node_modules/@types/node/zlib.d.ts +0 -517
  69. package/vendor/sdk/node_modules/undici-types/README.md +0 -6
  70. package/vendor/sdk/node_modules/undici-types/agent.d.ts +0 -31
  71. package/vendor/sdk/node_modules/undici-types/api.d.ts +0 -43
  72. package/vendor/sdk/node_modules/undici-types/balanced-pool.d.ts +0 -18
  73. package/vendor/sdk/node_modules/undici-types/cache.d.ts +0 -36
  74. package/vendor/sdk/node_modules/undici-types/client.d.ts +0 -97
  75. package/vendor/sdk/node_modules/undici-types/connector.d.ts +0 -34
  76. package/vendor/sdk/node_modules/undici-types/content-type.d.ts +0 -21
  77. package/vendor/sdk/node_modules/undici-types/cookies.d.ts +0 -28
  78. package/vendor/sdk/node_modules/undici-types/diagnostics-channel.d.ts +0 -67
  79. package/vendor/sdk/node_modules/undici-types/dispatcher.d.ts +0 -241
  80. package/vendor/sdk/node_modules/undici-types/errors.d.ts +0 -128
  81. package/vendor/sdk/node_modules/undici-types/fetch.d.ts +0 -209
  82. package/vendor/sdk/node_modules/undici-types/file.d.ts +0 -39
  83. package/vendor/sdk/node_modules/undici-types/filereader.d.ts +0 -54
  84. package/vendor/sdk/node_modules/undici-types/formdata.d.ts +0 -108
  85. package/vendor/sdk/node_modules/undici-types/global-dispatcher.d.ts +0 -9
  86. package/vendor/sdk/node_modules/undici-types/global-origin.d.ts +0 -7
  87. package/vendor/sdk/node_modules/undici-types/handlers.d.ts +0 -9
  88. package/vendor/sdk/node_modules/undici-types/header.d.ts +0 -4
  89. package/vendor/sdk/node_modules/undici-types/index.d.ts +0 -63
  90. package/vendor/sdk/node_modules/undici-types/interceptors.d.ts +0 -5
  91. package/vendor/sdk/node_modules/undici-types/mock-agent.d.ts +0 -50
  92. package/vendor/sdk/node_modules/undici-types/mock-client.d.ts +0 -25
  93. package/vendor/sdk/node_modules/undici-types/mock-errors.d.ts +0 -12
  94. package/vendor/sdk/node_modules/undici-types/mock-interceptor.d.ts +0 -93
  95. package/vendor/sdk/node_modules/undici-types/mock-pool.d.ts +0 -25
  96. package/vendor/sdk/node_modules/undici-types/package.json +0 -55
  97. package/vendor/sdk/node_modules/undici-types/patch.d.ts +0 -71
  98. package/vendor/sdk/node_modules/undici-types/pool-stats.d.ts +0 -19
  99. package/vendor/sdk/node_modules/undici-types/pool.d.ts +0 -28
  100. package/vendor/sdk/node_modules/undici-types/proxy-agent.d.ts +0 -30
  101. package/vendor/sdk/node_modules/undici-types/readable.d.ts +0 -61
  102. package/vendor/sdk/node_modules/undici-types/webidl.d.ts +0 -220
  103. package/vendor/sdk/node_modules/undici-types/websocket.d.ts +0 -131
@@ -1,666 +0,0 @@
1
- /**
2
- * The `vm` module enables compiling and running code within V8 Virtual
3
- * Machine contexts.
4
- *
5
- * **The `vm` module is not a security**
6
- * **mechanism. Do not use it to run untrusted code.**
7
- *
8
- * JavaScript code can be compiled and run immediately or
9
- * compiled, saved, and run later.
10
- *
11
- * A common use case is to run the code in a different V8 Context. This means
12
- * invoked code has a different global object than the invoking code.
13
- *
14
- * One can provide the context by `contextifying` an
15
- * object. The invoked code treats any property in the context like a
16
- * global variable. Any changes to global variables caused by the invoked
17
- * code are reflected in the context object.
18
- *
19
- * ```js
20
- * import vm from 'node:vm';
21
- *
22
- * const x = 1;
23
- *
24
- * const context = { x: 2 };
25
- * vm.createContext(context); // Contextify the object.
26
- *
27
- * const code = 'x += 40; var y = 17;';
28
- * // `x` and `y` are global variables in the context.
29
- * // Initially, x has the value 2 because that is the value of context.x.
30
- * vm.runInContext(code, context);
31
- *
32
- * console.log(context.x); // 42
33
- * console.log(context.y); // 17
34
- *
35
- * console.log(x); // 1; y is not defined.
36
- * ```
37
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/vm.js)
38
- */
39
- declare module "vm" {
40
- import { ImportAttributes } from "node:module";
41
- interface Context extends NodeJS.Dict<any> {}
42
- interface BaseOptions {
43
- /**
44
- * Specifies the filename used in stack traces produced by this script.
45
- * Default: `''`.
46
- */
47
- filename?: string | undefined;
48
- /**
49
- * Specifies the line number offset that is displayed in stack traces produced by this script.
50
- * Default: `0`.
51
- */
52
- lineOffset?: number | undefined;
53
- /**
54
- * Specifies the column number offset that is displayed in stack traces produced by this script.
55
- * @default 0
56
- */
57
- columnOffset?: number | undefined;
58
- }
59
- interface ScriptOptions extends BaseOptions {
60
- /**
61
- * V8's code cache data for the supplied source.
62
- */
63
- cachedData?: Buffer | NodeJS.ArrayBufferView | undefined;
64
- /** @deprecated in favor of `script.createCachedData()` */
65
- produceCachedData?: boolean | undefined;
66
- /**
67
- * Called during evaluation of this module when `import()` is called.
68
- * If this option is not specified, calls to `import()` will reject with `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`.
69
- */
70
- importModuleDynamically?:
71
- | ((specifier: string, script: Script, importAttributes: ImportAttributes) => Module)
72
- | undefined;
73
- }
74
- interface RunningScriptOptions extends BaseOptions {
75
- /**
76
- * When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
77
- * Default: `true`.
78
- */
79
- displayErrors?: boolean | undefined;
80
- /**
81
- * Specifies the number of milliseconds to execute code before terminating execution.
82
- * If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
83
- */
84
- timeout?: number | undefined;
85
- /**
86
- * If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
87
- * Existing handlers for the event that have been attached via `process.on('SIGINT')` will be disabled during script execution, but will continue to work after that.
88
- * If execution is terminated, an `Error` will be thrown.
89
- * Default: `false`.
90
- */
91
- breakOnSigint?: boolean | undefined;
92
- }
93
- interface RunningScriptInNewContextOptions extends RunningScriptOptions {
94
- /**
95
- * Human-readable name of the newly created context.
96
- */
97
- contextName?: CreateContextOptions["name"];
98
- /**
99
- * Origin corresponding to the newly created context for display purposes. The origin should be formatted like a URL,
100
- * but with only the scheme, host, and port (if necessary), like the value of the `url.origin` property of a `URL` object.
101
- * Most notably, this string should omit the trailing slash, as that denotes a path.
102
- */
103
- contextOrigin?: CreateContextOptions["origin"];
104
- contextCodeGeneration?: CreateContextOptions["codeGeneration"];
105
- /**
106
- * If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
107
- */
108
- microtaskMode?: CreateContextOptions["microtaskMode"];
109
- }
110
- interface RunningCodeOptions extends RunningScriptOptions {
111
- cachedData?: ScriptOptions["cachedData"];
112
- importModuleDynamically?: ScriptOptions["importModuleDynamically"];
113
- }
114
- interface RunningCodeInNewContextOptions extends RunningScriptInNewContextOptions {
115
- cachedData?: ScriptOptions["cachedData"];
116
- importModuleDynamically?: ScriptOptions["importModuleDynamically"];
117
- }
118
- interface CompileFunctionOptions extends BaseOptions {
119
- /**
120
- * Provides an optional data with V8's code cache data for the supplied source.
121
- */
122
- cachedData?: Buffer | undefined;
123
- /**
124
- * Specifies whether to produce new cache data.
125
- * Default: `false`,
126
- */
127
- produceCachedData?: boolean | undefined;
128
- /**
129
- * The sandbox/context in which the said function should be compiled in.
130
- */
131
- parsingContext?: Context | undefined;
132
- /**
133
- * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
134
- */
135
- contextExtensions?: Object[] | undefined;
136
- }
137
- interface CreateContextOptions {
138
- /**
139
- * Human-readable name of the newly created context.
140
- * @default 'VM Context i' Where i is an ascending numerical index of the created context.
141
- */
142
- name?: string | undefined;
143
- /**
144
- * Corresponds to the newly created context for display purposes.
145
- * The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
146
- * like the value of the `url.origin` property of a URL object.
147
- * Most notably, this string should omit the trailing slash, as that denotes a path.
148
- * @default ''
149
- */
150
- origin?: string | undefined;
151
- codeGeneration?:
152
- | {
153
- /**
154
- * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
155
- * will throw an EvalError.
156
- * @default true
157
- */
158
- strings?: boolean | undefined;
159
- /**
160
- * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
161
- * @default true
162
- */
163
- wasm?: boolean | undefined;
164
- }
165
- | undefined;
166
- /**
167
- * If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
168
- */
169
- microtaskMode?: "afterEvaluate" | undefined;
170
- }
171
- type MeasureMemoryMode = "summary" | "detailed";
172
- interface MeasureMemoryOptions {
173
- /**
174
- * @default 'summary'
175
- */
176
- mode?: MeasureMemoryMode | undefined;
177
- /**
178
- * @default 'default'
179
- */
180
- execution?: "default" | "eager" | undefined;
181
- }
182
- interface MemoryMeasurement {
183
- total: {
184
- jsMemoryEstimate: number;
185
- jsMemoryRange: [number, number];
186
- };
187
- }
188
- /**
189
- * Instances of the `vm.Script` class contain precompiled scripts that can be
190
- * executed in specific contexts.
191
- * @since v0.3.1
192
- */
193
- class Script {
194
- constructor(code: string, options?: ScriptOptions | string);
195
- /**
196
- * Runs the compiled code contained by the `vm.Script` object within the given`contextifiedObject` and returns the result. Running code does not have access
197
- * to local scope.
198
- *
199
- * The following example compiles code that increments a global variable, sets
200
- * the value of another global variable, then execute the code multiple times.
201
- * The globals are contained in the `context` object.
202
- *
203
- * ```js
204
- * import vm from 'node:vm';
205
- *
206
- * const context = {
207
- * animal: 'cat',
208
- * count: 2
209
- * };
210
- *
211
- * const script = new vm.Script('count += 1; name = "kitty";');
212
- *
213
- * vm.createContext(context);
214
- * for (let i = 0; i < 10; ++i) {
215
- * script.runInContext(context);
216
- * }
217
- *
218
- * console.log(context);
219
- * // Prints: { animal: 'cat', count: 12, name: 'kitty' }
220
- * ```
221
- *
222
- * Using the `timeout` or `breakOnSigint` options will result in new event loops
223
- * and corresponding threads being started, which have a non-zero performance
224
- * overhead.
225
- * @since v0.3.1
226
- * @param contextifiedObject A `contextified` object as returned by the `vm.createContext()` method.
227
- * @return the result of the very last statement executed in the script.
228
- */
229
- runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
230
- /**
231
- * First contextifies the given `contextObject`, runs the compiled code contained
232
- * by the `vm.Script` object within the created context, and returns the result.
233
- * Running code does not have access to local scope.
234
- *
235
- * The following example compiles code that sets a global variable, then executes
236
- * the code multiple times in different contexts. The globals are set on and
237
- * contained within each individual `context`.
238
- *
239
- * ```js
240
- * import vm from 'node:vm';
241
- *
242
- * const script = new vm.Script('globalVar = "set"');
243
- *
244
- * const contexts = [{}, {}, {}];
245
- * contexts.forEach((context) => {
246
- * script.runInNewContext(context);
247
- * });
248
- *
249
- * console.log(contexts);
250
- * // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
251
- * ```
252
- * @since v0.3.1
253
- * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
254
- * @return the result of the very last statement executed in the script.
255
- */
256
- runInNewContext(contextObject?: Context, options?: RunningScriptInNewContextOptions): any;
257
- /**
258
- * Runs the compiled code contained by the `vm.Script` within the context of the
259
- * current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
260
- *
261
- * The following example compiles code that increments a `global` variable then
262
- * executes that code multiple times:
263
- *
264
- * ```js
265
- * import vm from 'node:vm';
266
- *
267
- * global.globalVar = 0;
268
- *
269
- * const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });
270
- *
271
- * for (let i = 0; i < 1000; ++i) {
272
- * script.runInThisContext();
273
- * }
274
- *
275
- * console.log(globalVar);
276
- *
277
- * // 1000
278
- * ```
279
- * @since v0.3.1
280
- * @return the result of the very last statement executed in the script.
281
- */
282
- runInThisContext(options?: RunningScriptOptions): any;
283
- /**
284
- * 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
285
- * time and any number of times.
286
- *
287
- * ```js
288
- * const script = new vm.Script(`
289
- * function add(a, b) {
290
- * return a + b;
291
- * }
292
- *
293
- * const x = add(1, 2);
294
- * `);
295
- *
296
- * const cacheWithoutX = script.createCachedData();
297
- *
298
- * script.runInThisContext();
299
- *
300
- * const cacheWithX = script.createCachedData();
301
- * ```
302
- * @since v10.6.0
303
- */
304
- createCachedData(): Buffer;
305
- /** @deprecated in favor of `script.createCachedData()` */
306
- cachedDataProduced?: boolean | undefined;
307
- cachedDataRejected?: boolean | undefined;
308
- cachedData?: Buffer | undefined;
309
- /**
310
- * 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.
311
- */
312
- sourceMapURL?: string | undefined;
313
- }
314
- /**
315
- * If given a `contextObject`, the `vm.createContext()` method will `prepare
316
- * that object` so that it can be used in calls to {@link runInContext} or `script.runInContext()`. Inside such scripts,
317
- * the `contextObject` will be the global object, retaining all of its existing
318
- * properties but also having the built-in objects and functions any standard [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global variables
319
- * will remain unchanged.
320
- *
321
- * ```js
322
- * import vm from 'node:vm';
323
- *
324
- * global.globalVar = 3;
325
- *
326
- * const context = { globalVar: 1 };
327
- * vm.createContext(context);
328
- *
329
- * vm.runInContext('globalVar *= 2;', context);
330
- *
331
- * console.log(context);
332
- * // Prints: { globalVar: 2 }
333
- *
334
- * console.log(global.globalVar);
335
- * // Prints: 3
336
- * ```
337
- *
338
- * If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
339
- * empty `contextified` object will be returned.
340
- *
341
- * The `vm.createContext()` method is primarily useful for creating a single
342
- * context that can be used to run multiple scripts. For instance, if emulating a
343
- * web browser, the method can be used to create a single context representing a
344
- * window's global object, then run all `<script>` tags together within that
345
- * context.
346
- *
347
- * The provided `name` and `origin` of the context are made visible through the
348
- * Inspector API.
349
- * @since v0.3.1
350
- * @return contextified object.
351
- */
352
- function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
353
- /**
354
- * Returns `true` if the given `object` object has been `contextified` using {@link createContext}.
355
- * @since v0.11.7
356
- */
357
- function isContext(sandbox: Context): boolean;
358
- /**
359
- * The `vm.runInContext()` method compiles `code`, runs it within the context of
360
- * the `contextifiedObject`, then returns the result. Running code does not have
361
- * access to the local scope. The `contextifiedObject` object _must_ have been
362
- * previously `contextified` using the {@link createContext} method.
363
- *
364
- * If `options` is a string, then it specifies the filename.
365
- *
366
- * The following example compiles and executes different scripts using a single `contextified` object:
367
- *
368
- * ```js
369
- * import vm from 'node:vm';
370
- *
371
- * const contextObject = { globalVar: 1 };
372
- * vm.createContext(contextObject);
373
- *
374
- * for (let i = 0; i < 10; ++i) {
375
- * vm.runInContext('globalVar *= 2;', contextObject);
376
- * }
377
- * console.log(contextObject);
378
- * // Prints: { globalVar: 1024 }
379
- * ```
380
- * @since v0.3.1
381
- * @param code The JavaScript code to compile and run.
382
- * @param contextifiedObject The `contextified` object that will be used as the `global` when the `code` is compiled and run.
383
- * @return the result of the very last statement executed in the script.
384
- */
385
- function runInContext(code: string, contextifiedObject: Context, options?: RunningCodeOptions | string): any;
386
- /**
387
- * The `vm.runInNewContext()` first contextifies the given `contextObject` (or
388
- * creates a new `contextObject` if passed as `undefined`), compiles the `code`,
389
- * runs it within the created context, then returns the result. Running code
390
- * does not have access to the local scope.
391
- *
392
- * If `options` is a string, then it specifies the filename.
393
- *
394
- * The following example compiles and executes code that increments a global
395
- * variable and sets a new one. These globals are contained in the `contextObject`.
396
- *
397
- * ```js
398
- * import vm from 'node:vm';
399
- *
400
- * const contextObject = {
401
- * animal: 'cat',
402
- * count: 2
403
- * };
404
- *
405
- * vm.runInNewContext('count += 1; name = "kitty"', contextObject);
406
- * console.log(contextObject);
407
- * // Prints: { animal: 'cat', count: 3, name: 'kitty' }
408
- * ```
409
- * @since v0.3.1
410
- * @param code The JavaScript code to compile and run.
411
- * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
412
- * @return the result of the very last statement executed in the script.
413
- */
414
- function runInNewContext(
415
- code: string,
416
- contextObject?: Context,
417
- options?: RunningCodeInNewContextOptions | string,
418
- ): any;
419
- /**
420
- * `vm.runInThisContext()` compiles `code`, runs it within the context of the
421
- * current `global` and returns the result. Running code does not have access to
422
- * local scope, but does have access to the current `global` object.
423
- *
424
- * If `options` is a string, then it specifies the filename.
425
- *
426
- * The following example illustrates using both `vm.runInThisContext()` and
427
- * the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
428
- *
429
- * ```js
430
- * import vm from 'node:vm';
431
- * let localVar = 'initial value';
432
- *
433
- * const vmResult = vm.runInThisContext('localVar = "vm";');
434
- * console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
435
- * // Prints: vmResult: 'vm', localVar: 'initial value'
436
- *
437
- * const evalResult = eval('localVar = "eval";');
438
- * console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);
439
- * // Prints: evalResult: 'eval', localVar: 'eval'
440
- * ```
441
- *
442
- * Because `vm.runInThisContext()` does not have access to the local scope,`localVar` is unchanged. In contrast,
443
- * [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
444
- * 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')`.
445
- *
446
- * ## Example: Running an HTTP server within a VM
447
- *
448
- * When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
449
- * context. The code passed to this VM context will have its own isolated scope.
450
- *
451
- * In order to run a simple web server using the `http` module the code passed to
452
- * the context must either call `require('http')` on its own, or have a reference
453
- * to the `http` module passed to it. For instance:
454
- *
455
- * ```js
456
- * 'use strict';
457
- * import vm from 'node:vm';
458
- *
459
- * const code = `
460
- * ((require) => {
461
- * const http = require('node:http');
462
- * http.createServer((request, response) => {
463
- * response.writeHead(200, { 'Content-Type': 'text/plain' });
464
- * response.end('Hello World\\n');
465
- * }).listen(8124);
466
- *
467
- * console.log('Server running at http://127.0.0.1:8124/');
468
- * })`;
469
- *
470
- * vm.runInThisContext(code)(require);
471
- * ```
472
- *
473
- * The `require()` in the above case shares the state with the context it is
474
- * passed from. This may introduce risks when untrusted code is executed, e.g.
475
- * altering objects in the context in unwanted ways.
476
- * @since v0.3.1
477
- * @param code The JavaScript code to compile and run.
478
- * @return the result of the very last statement executed in the script.
479
- */
480
- function runInThisContext(code: string, options?: RunningCodeOptions | string): any;
481
- /**
482
- * Compiles the given code into the provided context (if no context is
483
- * supplied, the current context is used), and returns it wrapped inside a
484
- * function with the given `params`.
485
- * @since v10.10.0
486
- * @param code The body of the function to compile.
487
- * @param params An array of strings containing all parameters for the function.
488
- */
489
- function compileFunction(
490
- code: string,
491
- params?: readonly string[],
492
- options?: CompileFunctionOptions,
493
- ): Function & {
494
- cachedData?: Script["cachedData"] | undefined;
495
- cachedDataProduced?: Script["cachedDataProduced"] | undefined;
496
- cachedDataRejected?: Script["cachedDataRejected"] | undefined;
497
- };
498
- /**
499
- * Measure the memory known to V8 and used by all contexts known to the
500
- * current V8 isolate, or the main context.
501
- *
502
- * The format of the object that the returned Promise may resolve with is
503
- * specific to the V8 engine and may change from one version of V8 to the next.
504
- *
505
- * The returned result is different from the statistics returned by`v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
506
- * memory reachable by each V8 specific contexts in the current instance of
507
- * the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
508
- * the memory occupied by each heap space in the current V8 instance.
509
- *
510
- * ```js
511
- * import vm from 'node:vm';
512
- * // Measure the memory used by the main context.
513
- * vm.measureMemory({ mode: 'summary' })
514
- * // This is the same as vm.measureMemory()
515
- * .then((result) => {
516
- * // The current format is:
517
- * // {
518
- * // total: {
519
- * // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
520
- * // }
521
- * // }
522
- * console.log(result);
523
- * });
524
- *
525
- * const context = vm.createContext({ a: 1 });
526
- * vm.measureMemory({ mode: 'detailed', execution: 'eager' })
527
- * .then((result) => {
528
- * // Reference the context here so that it won't be GC'ed
529
- * // until the measurement is complete.
530
- * console.log(context.a);
531
- * // {
532
- * // total: {
533
- * // jsMemoryEstimate: 2574732,
534
- * // jsMemoryRange: [ 2574732, 2904372 ]
535
- * // },
536
- * // current: {
537
- * // jsMemoryEstimate: 2438996,
538
- * // jsMemoryRange: [ 2438996, 2768636 ]
539
- * // },
540
- * // other: [
541
- * // {
542
- * // jsMemoryEstimate: 135736,
543
- * // jsMemoryRange: [ 135736, 465376 ]
544
- * // }
545
- * // ]
546
- * // }
547
- * console.log(result);
548
- * });
549
- * ```
550
- * @since v13.10.0
551
- * @experimental
552
- */
553
- function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
554
-
555
- interface ModuleEvaluateOptions {
556
- timeout?: RunningScriptOptions["timeout"] | undefined;
557
- breakOnSigint?: RunningScriptOptions["breakOnSigint"] | undefined;
558
- }
559
- type ModuleLinker = (
560
- specifier: string,
561
- referencingModule: Module,
562
- extra: {
563
- /** @deprecated Use `attributes` instead */
564
- assert: ImportAttributes;
565
- attributes: ImportAttributes;
566
- },
567
- ) => Module | Promise<Module>;
568
- type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
569
- class Module {
570
- /**
571
- * The specifiers of all dependencies of this module.
572
- */
573
- dependencySpecifiers: readonly string[];
574
- /**
575
- * If the `module.status` is `'errored'`, this property contains the exception thrown by the module during evaluation.
576
- * If the status is anything else, accessing this property will result in a thrown exception.
577
- */
578
- error: any;
579
- /**
580
- * The identifier of the current module, as set in the constructor.
581
- */
582
- identifier: string;
583
- context: Context;
584
- /**
585
- * The namespace object of the module. This is only available after linking (`module.link()`) has completed.
586
- */
587
- namespace: Object;
588
- /**
589
- * The current status of the module.
590
- */
591
- status: ModuleStatus;
592
- /**
593
- * Evaluate the module.
594
- *
595
- * This must be called after the module has been linked; otherwise it will reject
596
- * It could be called also when the module has already been evaluated, in which case it will either do nothing
597
- * if the initial evaluation ended in success (`module.status` is `'evaluated'`) or it will re-throw the exception
598
- * that the initial evaluation resulted in (`module.status` is `'errored'`).
599
- *
600
- * This method cannot be called while the module is being evaluated (`module.status` is `'evaluating'`).
601
- */
602
- evaluate(options?: ModuleEvaluateOptions): Promise<void>;
603
- /**
604
- * Link module dependencies. This method must be called before evaluation, and can only be called once per module.
605
- */
606
- link(linker: ModuleLinker): Promise<void>;
607
- }
608
-
609
- interface SourceTextModuleOptions {
610
- /**
611
- * String used in stack traces.
612
- * @default 'vm:module(i)' where i is a context-specific ascending index.
613
- */
614
- identifier?: string | undefined;
615
- cachedData?: ScriptOptions["cachedData"] | undefined;
616
- context?: Context | undefined;
617
- lineOffset?: BaseOptions["lineOffset"] | undefined;
618
- columnOffset?: BaseOptions["columnOffset"] | undefined;
619
- /**
620
- * Called during evaluation of this module to initialize the `import.meta`.
621
- */
622
- initializeImportMeta?: ((meta: ImportMeta, module: SourceTextModule) => void) | undefined;
623
- importModuleDynamically?: ScriptOptions["importModuleDynamically"] | undefined;
624
- }
625
- class SourceTextModule extends Module {
626
- /**
627
- * Creates a new `SourceTextModule` instance.
628
- * @param code JavaScript Module code to parse
629
- */
630
- constructor(code: string, options?: SourceTextModuleOptions);
631
- }
632
-
633
- interface SyntheticModuleOptions {
634
- /**
635
- * String used in stack traces.
636
- * @default 'vm:module(i)' where i is a context-specific ascending index.
637
- */
638
- identifier?: string | undefined;
639
- /**
640
- * The contextified object as returned by the `vm.createContext()` method, to compile and evaluate this module in.
641
- */
642
- context?: Context | undefined;
643
- }
644
- class SyntheticModule extends Module {
645
- /**
646
- * Creates a new `SyntheticModule` instance.
647
- * @param exportNames Array of names that will be exported from the module.
648
- * @param evaluateCallback Called when the module is evaluated.
649
- */
650
- constructor(
651
- exportNames: string[],
652
- evaluateCallback: (this: SyntheticModule) => void,
653
- options?: SyntheticModuleOptions,
654
- );
655
- /**
656
- * This method is used after the module is linked to set the values of exports.
657
- * If it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error will be thrown.
658
- * @param name
659
- * @param value
660
- */
661
- setExport(name: string, value: any): void;
662
- }
663
- }
664
- declare module "node:vm" {
665
- export * from "vm";
666
- }