codemod 2.0.0-alpha.1 → 2.0.0-alpha.2

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 (89) hide show
  1. package/README.md +57 -2
  2. package/codemod +17 -30
  3. package/package.json +78 -10
  4. package/register.d.mts +11 -0
  5. package/register.mjs +60 -0
  6. package/runtime/addon.mjs +59 -0
  7. package/runtime/ast-grep.mjs +93 -0
  8. package/runtime/context.mjs +77 -0
  9. package/runtime/hooks.mjs +9 -0
  10. package/runtime/host.d.mts +120 -0
  11. package/runtime/host.mjs +390 -0
  12. package/runtime/llm.mjs +11 -0
  13. package/runtime/metrics.mjs +45 -0
  14. package/runtime/modules.mjs +19 -0
  15. package/runtime/orchestrator.mjs +657 -0
  16. package/runtime/runtime.mjs +48 -0
  17. package/runtime/workflow.mjs +135 -0
  18. package/testing/index.d.mts +203 -0
  19. package/testing/index.mjs +638 -0
  20. package/types/index.d.ts +8 -0
  21. package/types/langs/angular.d.ts +5 -0
  22. package/types/langs/c.d.ts +5 -0
  23. package/types/langs/c_sharp.d.ts +5 -0
  24. package/types/langs/cpp.d.ts +5 -0
  25. package/types/langs/css.d.ts +5 -0
  26. package/types/langs/elixir.d.ts +5 -0
  27. package/types/langs/go.d.ts +5 -0
  28. package/types/langs/html.d.ts +5 -0
  29. package/types/langs/java.d.ts +5 -0
  30. package/types/langs/javascript.d.ts +5 -0
  31. package/types/langs/json.d.ts +5 -0
  32. package/types/langs/kotlin.d.ts +5 -0
  33. package/types/langs/php.d.ts +5 -0
  34. package/types/langs/python.d.ts +5 -0
  35. package/types/langs/ruby.d.ts +5 -0
  36. package/types/langs/rust.d.ts +5 -0
  37. package/types/langs/scala.d.ts +5 -0
  38. package/types/langs/toml.d.ts +5 -0
  39. package/types/langs/tsx.d.ts +5 -0
  40. package/types/langs/typescript.d.ts +5 -0
  41. package/types/langs/xml.d.ts +5 -0
  42. package/types/langs/yaml.d.ts +5 -0
  43. package/types/llm.d.ts +6 -0
  44. package/types/llrt/abort.d.ts +69 -0
  45. package/types/llrt/assert.d.ts +39 -0
  46. package/types/llrt/async_hooks.d.ts +210 -0
  47. package/types/llrt/buffer.d.ts +1186 -0
  48. package/types/llrt/child_process.d.ts +447 -0
  49. package/types/llrt/console.d.ts +210 -0
  50. package/types/llrt/crypto.d.ts +854 -0
  51. package/types/llrt/dgram.d.ts +381 -0
  52. package/types/llrt/dns.d.ts +124 -0
  53. package/types/llrt/dom-events.d.ts +51 -0
  54. package/types/llrt/events.d.ts +245 -0
  55. package/types/llrt/exceptions.d.ts +26 -0
  56. package/types/llrt/fetch.d.ts +332 -0
  57. package/types/llrt/fs/promises.d.ts +554 -0
  58. package/types/llrt/fs.d.ts +360 -0
  59. package/types/llrt/globals.d.ts +23 -0
  60. package/types/llrt/https.d.ts +27 -0
  61. package/types/llrt/index.d.ts +33 -0
  62. package/types/llrt/module.d.ts +285 -0
  63. package/types/llrt/navigator.d.ts +9 -0
  64. package/types/llrt/net.d.ts +488 -0
  65. package/types/llrt/os.d.ts +293 -0
  66. package/types/llrt/path.d.ts +150 -0
  67. package/types/llrt/perf_hooks.d.ts +23 -0
  68. package/types/llrt/process.d.ts +502 -0
  69. package/types/llrt/stream/web.d.ts +526 -0
  70. package/types/llrt/stream.d.ts +366 -0
  71. package/types/llrt/string_decoder.d.ts +63 -0
  72. package/types/llrt/timers.d.ts +72 -0
  73. package/types/llrt/timezone.d.ts +101 -0
  74. package/types/llrt/tty.d.ts +11 -0
  75. package/types/llrt/url.d.ts +774 -0
  76. package/types/llrt/util.d.ts +240 -0
  77. package/types/llrt/zlib.d.ts +177 -0
  78. package/types/main.d.ts +5 -0
  79. package/types/metrics.d.ts +5 -0
  80. package/types/modules/ast-grep.d.ts +634 -0
  81. package/types/modules/langs.d.ts +87 -0
  82. package/types/modules/llm.d.ts +23 -0
  83. package/types/modules/metrics.d.ts +107 -0
  84. package/types/modules/runtime.d.ts +66 -0
  85. package/types/modules/workflow.d.ts +750 -0
  86. package/types/runtime.d.ts +6 -0
  87. package/types/workflow.d.ts +5 -0
  88. package/vite.d.mts +24 -0
  89. package/vite.mjs +26 -0
@@ -0,0 +1,554 @@
1
+ /**
2
+ * The `fs/promises` API provides asynchronous file system methods that return
3
+ * promises.
4
+ */
5
+ declare module "fs/promises" {
6
+ import { Buffer, BufferEncoding } from "buffer";
7
+ import {
8
+ constants as fsConstants,
9
+ Dirent,
10
+ MakeDirectoryOptions,
11
+ Mode,
12
+ PathLike,
13
+ RmDirOptions,
14
+ RmOptions,
15
+ Stats,
16
+ } from "fs";
17
+
18
+ export type FileSystemFlags =
19
+ | "a"
20
+ | "ax"
21
+ | "a+"
22
+ | "r"
23
+ | "r+"
24
+ | "w"
25
+ | "wx"
26
+ | "w+"
27
+ | "wx+";
28
+
29
+ interface FileReadResult<T extends QuickJS.ArrayBufferView> {
30
+ bytesRead: number;
31
+ buffer: T;
32
+ }
33
+
34
+ interface FileReadOptions<T extends QuickJS.ArrayBufferView = Buffer> {
35
+ /**
36
+ * @default `Buffer.alloc(16384)`
37
+ */
38
+ buffer?: T;
39
+ /**
40
+ * @default 0
41
+ */
42
+ offset?: number | null;
43
+ /**
44
+ * @default `buffer.byteLength - offset`
45
+ */
46
+ length?: number | null;
47
+ position?: number | null;
48
+ }
49
+
50
+ class FileHandle {
51
+ /**
52
+ * The numeric file descriptor managed by the {FileHandle} object.
53
+ */
54
+ readonly fd: number;
55
+
56
+ /**
57
+ * Changes the ownership of the file. A wrapper for [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html).
58
+ * @param uid The file's new owner's user id.
59
+ * @param gid The file's new group's group id.
60
+ * @return Fulfills with `undefined` upon success.
61
+ */
62
+ chown(uid: number, gid: number): Promise<void>;
63
+
64
+ /**
65
+ * Modifies the permissions on the file. See [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html).
66
+ * @param mode the file mode bit mask.
67
+ * @return Fulfills with `undefined` upon success.
68
+ */
69
+ chmod(mode: Mode): Promise<void>;
70
+
71
+ /**
72
+ * Forces all currently queued I/O operations associated with the file to the
73
+ * operating system's synchronized I/O completion state. Refer to the POSIX [`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details.
74
+ *
75
+ * Unlike `filehandle.sync` this method does not flush modified metadata.
76
+ * @return Fulfills with `undefined` upon success.
77
+ */
78
+ datasync(): Promise<void>;
79
+
80
+ /**
81
+ * Request that all data for the open file descriptor is flushed to the storage
82
+ * device. The specific implementation is operating system and device specific.
83
+ * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.
84
+ * @return Fulfills with `undefined` upon success.
85
+ */
86
+ sync(): Promise<void>;
87
+
88
+ /**
89
+ * Reads data from the file and stores that in the given buffer.
90
+ *
91
+ * If the file is not modified concurrently, the end-of-file is reached when the
92
+ * number of bytes read is zero.
93
+ * @param buffer A buffer that will be filled with the file data read.
94
+ * @param offset The location in the buffer at which to start filling.
95
+ * @param length The number of bytes to read.
96
+ * @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an
97
+ * integer, the current file position will remain unchanged.
98
+ * @return Fulfills upon success with an object with two properties: bytesRead and buffer
99
+ */
100
+ read<T extends QuickJS.ArrayBufferView>(
101
+ buffer: T,
102
+ offset?: number | null,
103
+ length?: number | null,
104
+ position?: number | null
105
+ ): Promise<FileReadResult<T>>;
106
+ read<T extends QuickJS.ArrayBufferView = Buffer>(
107
+ buffer: T,
108
+ options?: FileReadOptions<T>
109
+ ): Promise<FileReadResult<T>>;
110
+ read<T extends QuickJS.ArrayBufferView = Buffer>(
111
+ options?: FileReadOptions<T>
112
+ ): Promise<FileReadResult<T>>;
113
+
114
+ /**
115
+ * Asynchronously reads the entire contents of a file.
116
+ *
117
+ * If `options` is a string, then it specifies the `encoding`.
118
+ *
119
+ * The `FileHandle` has to support reading.
120
+ *
121
+ * If one or more `filehandle.read()` calls are made on a file handle and then a `filehandle.readFile()` call is made, the data will be read from the current
122
+ * position till the end of the file. It doesn't always read from the beginning
123
+ * of the file.
124
+ * @return Fulfills upon a successful read with the contents of the file. If no encoding is specified (using `options.encoding`), the data is returned as a {Buffer} object. Otherwise, the
125
+ * data will be a string.
126
+ */
127
+ readFile(
128
+ options?: {
129
+ encoding?: null | undefined;
130
+ } | null
131
+ ): Promise<Buffer>;
132
+ readFile(
133
+ options:
134
+ | {
135
+ encoding: BufferEncoding;
136
+ }
137
+ | BufferEncoding
138
+ ): Promise<string>;
139
+
140
+ /**
141
+ * Get {FileHandle} status.
142
+ * @return Fulfills with the {fs.Stats} object.
143
+ */
144
+ stat(): Promise<Stats>;
145
+
146
+ /**
147
+ * Truncates the file.
148
+ *
149
+ * If the file was larger than `len` bytes, only the first `len` bytes will be
150
+ * retained in the file.
151
+ *
152
+ * The following example retains only the first four bytes of the file:
153
+ *
154
+ * ```js
155
+ * import { open } from 'fs/promises';
156
+ *
157
+ * let filehandle = null;
158
+ * try {
159
+ * filehandle = await open('temp.txt', 'r+');
160
+ * await filehandle.truncate(4);
161
+ * } finally {
162
+ * await filehandle?.close();
163
+ * }
164
+ * ```
165
+ *
166
+ * If the file previously was shorter than `len` bytes, it is extended, and the
167
+ * extended part is filled with null bytes (`'\0'`):
168
+ *
169
+ * @param [len=0]
170
+ * @return Fulfills with `undefined` upon success.
171
+ */
172
+ truncate(len?: number): Promise<void>;
173
+
174
+ /**
175
+ * Asynchronously writes data to a file, replacing the file if it already exists.
176
+ *
177
+ * If `options` is a string, then it specifies the `encoding`.
178
+ *
179
+ * The `FileHandle` has to support writing.
180
+ *
181
+ * It is unsafe to use `filehandle.writeFile()` multiple times on the same file
182
+ * without waiting for the promise to be fulfilled (or rejected).
183
+ *
184
+ * If one or more `filehandle.write()` calls are made on a file handle and then a`filehandle.writeFile()` call is made, the data will be written from the
185
+ * current position till the end of the file. It doesn't always write from the beginning of the file.
186
+ */
187
+ writeFile(
188
+ data: string | QuickJS.ArrayBufferView,
189
+ options?:
190
+ | {
191
+ encoding?: BufferEncoding | null;
192
+ }
193
+ | BufferEncoding
194
+ | null
195
+ ): Promise<void>;
196
+
197
+ /**
198
+ * Write `buffer` to the file.
199
+ *
200
+ * The promise is fulfilled with an object containing two properties:
201
+ *
202
+ * It is unsafe to use `filehandle.write()` multiple times on the same file
203
+ * without waiting for the promise to be fulfilled (or rejected). For this
204
+ * scenario, use `filehandle.createWriteStream()`.
205
+ *
206
+ * On Linux, positional writes do not work when the file is opened in append mode.
207
+ * The kernel ignores the position argument and always appends the data to
208
+ * the end of the file.
209
+ * @param offset The start position from within `buffer` where the data to write begins.
210
+ * @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
211
+ * @param [position='null'] The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current
212
+ * position. See the POSIX pwrite(2) documentation for more detail.
213
+ */
214
+ write<TBuffer extends QuickJS.ArrayBufferView>(
215
+ buffer: TBuffer,
216
+ offset?: number | null,
217
+ length?: number | null,
218
+ position?: number | null
219
+ ): Promise<{
220
+ bytesWritten: number;
221
+ buffer: TBuffer;
222
+ }>;
223
+ write<TBuffer extends QuickJS.ArrayBufferView>(
224
+ buffer: TBuffer,
225
+ options?: {
226
+ offset?: number | null;
227
+ length?: number | null;
228
+ position?: number | null;
229
+ } | null
230
+ ): Promise<{
231
+ bytesWritten: number;
232
+ buffer: TBuffer;
233
+ }>;
234
+ write(
235
+ data: string,
236
+ position?: number | null,
237
+ encoding?: BufferEncoding | null
238
+ ): Promise<{
239
+ bytesWritten: number;
240
+ buffer: string;
241
+ }>;
242
+
243
+ /**
244
+ * Closes the file handle after waiting for any pending operation on the handle to
245
+ * complete.
246
+ *
247
+ * ```js
248
+ * import { open } from 'fs/promises';
249
+ *
250
+ * let filehandle;
251
+ * try {
252
+ * filehandle = await open('thefile.txt', 'r');
253
+ * } finally {
254
+ * await filehandle?.close();
255
+ * }
256
+ * ```
257
+ * @return Fulfills with `undefined` upon success.
258
+ */
259
+ close(): Promise<void>;
260
+ }
261
+
262
+ const constants: typeof fsConstants;
263
+
264
+ /**
265
+ * Tests a user's permissions for the file or directory specified by `path`.
266
+ * The `mode` argument is an optional integer that specifies the accessibility
267
+ * checks to be performed. `mode` should be either the value `fs.constants.F_OK` or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`, `fs.constants.W_OK`, and `fs.constants.X_OK`
268
+ * (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
269
+ * possible values of `mode`.
270
+ *
271
+ * If the accessibility check is successful, the promise is fulfilled with no
272
+ * value. If any of the accessibility checks fail, the promise is rejected
273
+ * with an [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object. The following example checks if the file`/etc/passwd` can be read and
274
+ * written by the current process.
275
+ *
276
+ * ```js
277
+ * import { access, constants } from 'fs/promises';
278
+ *
279
+ * try {
280
+ * await access('/etc/passwd', constants.R_OK | constants.W_OK);
281
+ * console.log('can access');
282
+ * } catch {
283
+ * console.error('cannot access');
284
+ * }
285
+ * ```
286
+ *
287
+ * Using `fsPromises.access()` to check for the accessibility of a file before
288
+ * calling `fsPromises.open()` is not recommended. Doing so introduces a race
289
+ * condition, since other processes may change the file's state between the two
290
+ * calls. Instead, user code should open/read/write the file directly and handle
291
+ * the error raised if the file is not accessible.
292
+ * @param [mode=fs.constants.F_OK]
293
+ * @return Fulfills with `undefined` upon success.
294
+ */
295
+ function access(path: PathLike, mode?: Mode): Promise<void>;
296
+
297
+ /**
298
+ * Opens a `FileHandle`.
299
+ *
300
+ * Refer to the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more detail.
301
+ *
302
+ * Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
303
+ * by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file).
304
+ * @param [flags='r'] See {FileSystemFlags}.
305
+ * @param [mode=0o666] Sets the file mode if the file is created (UNIX).
306
+ * @return Fulfills with a {FileHandle} object.
307
+ */
308
+ function open(
309
+ path: PathLike,
310
+ flags?: FileSystemFlags,
311
+ mode?: Mode
312
+ ): Promise<FileHandle>;
313
+
314
+ /**
315
+ * Removes the directory identified by `path`.
316
+ *
317
+ * Using `fsPromises.rmdir()` on a file (not a directory) results in the
318
+ * promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR` error on POSIX.
319
+ *
320
+ * To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
321
+ * @return Fulfills with `undefined` upon success.
322
+ */
323
+ function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
324
+
325
+ /**
326
+ * Removes files and directories (modeled on the standard POSIX `rm` utility).
327
+ * @return Fulfills with `undefined` upon success.
328
+ */
329
+ function rm(path: PathLike, options?: RmOptions): Promise<void>;
330
+
331
+ /**
332
+ * Asynchronously creates a directory.
333
+ *
334
+ * The optional `options` argument can be an object with a `mode` property and a `recursive` property indicating whether parent directories should be created.
335
+ * Calling `fsPromises.mkdir()` when `path` is a directory that exists results in a rejection only when `recursive` is false.
336
+ *
337
+ * ```js
338
+ * import { mkdir } from 'fs/promises';
339
+ *
340
+ * try {
341
+ * const projectFolder = './test/project/123';
342
+ * const createDir = await mkdir(projectFolder, { recursive: true });
343
+ *
344
+ * console.log(`created ${createDir}`);
345
+ * } catch (err) {
346
+ * console.error(err.message);
347
+ * }
348
+ * ```
349
+ * @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
350
+ */
351
+ function mkdir(
352
+ path: PathLike,
353
+ options?: MakeDirectoryOptions
354
+ ): Promise<string>;
355
+
356
+ /**
357
+ * Reads the contents of a directory.
358
+ *
359
+ * If `options.withFileTypes` is set to `true`, the returned array will contain `fs.Dirent` objects.
360
+ *
361
+ * ```js
362
+ * import { readdir } from 'fs/promises';
363
+ *
364
+ * try {
365
+ * const files = await readdir(path);
366
+ * for (const file of files)
367
+ * console.log(file);
368
+ * } catch (err) {
369
+ * console.error(err);
370
+ * }
371
+ * ```
372
+ * @return Fulfills with an array of the names of the files in the directory excluding `'.'` and `'..'`.
373
+ */
374
+ function readdir(
375
+ path: PathLike,
376
+ options?: {
377
+ withFileTypes?: false | undefined;
378
+ recursive?: boolean | undefined;
379
+ }
380
+ ): Promise<string[]>;
381
+
382
+ /**
383
+ * Asynchronous readdir(2) - read a directory.
384
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
385
+ * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
386
+ */
387
+ function readdir(
388
+ path: PathLike,
389
+ options: {
390
+ withFileTypes: true;
391
+ recursive?: boolean | undefined;
392
+ }
393
+ ): Promise<Dirent[]>;
394
+
395
+ /**
396
+ * Asynchronous stat - Get file status.
397
+ * @param path A path to a file.
398
+ * @return Fulfills with the {fs.Stats} object for the given `path`.
399
+ */
400
+ function stat(path: PathLike): Promise<Stats>;
401
+
402
+ /**
403
+ * Creates a symbolic link.
404
+ *
405
+ * The `type` argument is only used on Windows platforms and can be one of `'dir'`, `'file'`, or `'junction'`. If the `type` argument is not a string, LLRT will
406
+ * autodetect `target` type and use `'file'` or `'dir'`. If the `target` does not
407
+ * exist, `'file'` will be used. Windows junction points require the destination
408
+ * path to be absolute. When using `'junction'`, the `target` argument will
409
+ * automatically be normalized to absolute path. Junction points on NTFS volumes
410
+ * can only point to directories.
411
+ * @param [type='null']
412
+ * @return Fulfills with `undefined` upon success.
413
+ */
414
+ function symlink(
415
+ target: PathLike,
416
+ path: PathLike,
417
+ type?: "dir" | "file" | "junction" | null
418
+ ): Promise<void>;
419
+
420
+ /**
421
+ * Creates a unique temporary directory. A unique directory name is generated by
422
+ * appending six random characters to the end of the provided `prefix`. Due to
423
+ * platform inconsistencies, avoid trailing `X` characters in `prefix`. Some
424
+ * platforms, notably the BSDs, can return more than six random characters, and
425
+ * replace trailing `X` characters in `prefix` with random characters.
426
+ *
427
+ * ```js
428
+ * import { mkdtemp } from 'fs/promises';
429
+ * import { join } from 'path';
430
+ * import { tmpdir } from 'os';
431
+ *
432
+ * try {
433
+ * await mkdtemp(join(tmpdir(), 'foo-'));
434
+ * } catch (err) {
435
+ * console.error(err);
436
+ * }
437
+ * ```
438
+ *
439
+ * The `fsPromises.mkdtemp()` method will append the six randomly selected
440
+ * characters directly to the `prefix` string. For instance, given a directory `/tmp`, if the intention is to create a temporary directory _within_ `/tmp`, the `prefix` must end with a trailing
441
+ * platform-specific path separator
442
+ * (`require('path').sep`).
443
+ * @return Fulfills with a string containing the file system path of the newly created temporary directory.
444
+ */
445
+ function mkdtemp(prefix: string): Promise<string>;
446
+
447
+ /**
448
+ * Asynchronously writes data to a file, replacing the file if it already exists.
449
+ *
450
+ * The `encoding` option is ignored if `data` is a buffer.
451
+ *
452
+ * It is unsafe to use `fsPromises.writeFile()` multiple times on the same file
453
+ * without waiting for the promise to be settled.
454
+ *
455
+ * Similarly to `fsPromises.readFile` \- `fsPromises.writeFile` is a convenience
456
+ * method that performs multiple `write` calls internally to write the buffer
457
+ * passed to it.
458
+ *
459
+ * @param file filename or `FileHandle`
460
+ * @return Fulfills with `undefined` upon success.
461
+ */
462
+ function writeFile(
463
+ file: PathLike,
464
+ data:
465
+ | string
466
+ | Buffer
467
+ | QuickJS.ArrayBufferView
468
+ | ArrayBuffer
469
+ | SharedArrayBuffer,
470
+ options?:
471
+ | {
472
+ mode?: Mode | undefined;
473
+ }
474
+ | undefined
475
+ ): Promise<void>;
476
+
477
+ /**
478
+ * Asynchronously reads the entire contents of a file.
479
+ *
480
+ * If no encoding is specified (using `options.encoding`), the data is returned
481
+ * as a `Buffer` object. Otherwise, the data will be a string.
482
+ *
483
+ * If `options` is a string, then it specifies the encoding.
484
+ *
485
+ * When the `path` is a directory, the behavior of `fsPromises.readFile()` is
486
+ * platform-specific. On macOS, Linux, and Windows, the promise will be rejected
487
+ * with an error. On FreeBSD, a representation of the directory's contents will be
488
+ * returned.
489
+ *
490
+ * An example of reading a `package.json` file.
491
+ *
492
+ * ```js
493
+ * import { readFile } from 'fs/promises';
494
+ * try {
495
+ * const filePath = './package.json';
496
+ * const contents = await readFile(filePath, { encoding: 'utf8' });
497
+ * console.log(contents);
498
+ * } catch (err) {
499
+ * console.error(err.message);
500
+ * }
501
+ * ```
502
+ *
503
+ * @param path filename or `FileHandle`
504
+ * @return Fulfills with the contents of the file.
505
+ */
506
+ function readFile(
507
+ path: PathLike,
508
+ options?: {
509
+ encoding?: null | undefined;
510
+ } | null
511
+ ): Promise<Buffer>;
512
+
513
+ /**
514
+ * Asynchronously reads the entire contents of a file.
515
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
516
+ * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
517
+ * @param options An object that may contain an optional flag.
518
+ * If a flag is not provided, it defaults to `'r'`.
519
+ */
520
+ function readFile(
521
+ path: PathLike,
522
+ options:
523
+ | {
524
+ encoding: BufferEncoding;
525
+ }
526
+ | BufferEncoding
527
+ ): Promise<string>;
528
+
529
+ /**
530
+ * Changes the permissions of a file.
531
+ * @return Fulfills with `undefined` upon success.
532
+ */
533
+ function chmod(path: PathLike, mode: Mode): Promise<void>;
534
+
535
+ /**
536
+ * Asynchronously renames a file or directory from `oldPath` to `newPath`.
537
+ *
538
+ * ```js
539
+ * import { rename } from 'fs/promises';
540
+ *
541
+ * try {
542
+ * await rename('oldfile.txt', 'newfile.txt');
543
+ * console.log('Rename complete!');
544
+ * } catch (err) {
545
+ * console.error(err);
546
+ * }
547
+ * ```
548
+ *
549
+ * @param oldPath A path to a file or directory.
550
+ * @param newPath The new path for the file or directory.
551
+ * @return Fulfills with `undefined` upon success.
552
+ */
553
+ function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
554
+ }