@umijs/utils 4.0.41 → 4.0.43

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 (46) hide show
  1. package/compiled/filesize/LICENSE +28 -28
  2. package/compiled/filesize/index.js +3 -4
  3. package/compiled/filesize/package.json +1 -1
  4. package/compiled/filesize/types/filesize.d.ts +46 -0
  5. package/compiled/fs-extra/index.d.ts +922 -476
  6. package/compiled/fs-extra/index.js +1 -1
  7. package/compiled/fs-extra/jsonfile/index.d.ts +78 -0
  8. package/compiled/fs-extra/package.json +1 -1
  9. package/compiled/glob/index.d.ts +1 -1
  10. package/compiled/glob/index.js +1 -1
  11. package/compiled/glob/package.json +1 -1
  12. package/compiled/gzip-size/index.d.ts +88 -81
  13. package/compiled/gzip-size/index.js +1 -1
  14. package/compiled/gzip-size/package.json +1 -1
  15. package/compiled/portfinder/index.js +1 -1
  16. package/compiled/portfinder/lib/portfinder.d.ts +16 -1
  17. package/compiled/portfinder/package.json +1 -1
  18. package/compiled/semver/classes/range.d.ts +1 -1
  19. package/compiled/semver/classes/semver.d.ts +1 -1
  20. package/compiled/semver/functions/compare-build.d.ts +6 -1
  21. package/compiled/semver/functions/diff.d.ts +1 -5
  22. package/compiled/semver/functions/satisfies.d.ts +1 -1
  23. package/compiled/semver/index.d.ts +3 -0
  24. package/compiled/semver/index.js +1 -1
  25. package/compiled/semver/package.json +1 -1
  26. package/compiled/semver/ranges/gtr.d.ts +1 -1
  27. package/compiled/semver/ranges/intersects.d.ts +1 -1
  28. package/compiled/semver/ranges/ltr.d.ts +1 -1
  29. package/compiled/semver/ranges/max-satisfying.d.ts +1 -1
  30. package/compiled/semver/ranges/min-satisfying.d.ts +1 -1
  31. package/compiled/semver/ranges/outside.d.ts +1 -1
  32. package/compiled/semver/ranges/subset.d.ts +1 -5
  33. package/compiled/semver/ranges/valid.d.ts +1 -1
  34. package/compiled/yargs-parser/index.js +1 -1
  35. package/compiled/yargs-parser/package.json +1 -1
  36. package/dist/aliasUtils/getAliasValue.d.ts +4 -0
  37. package/dist/aliasUtils/getAliasValue.js +62 -0
  38. package/dist/aliasUtils/index.d.ts +2 -0
  39. package/dist/aliasUtils/index.js +32 -0
  40. package/dist/aliasUtils/parseCircleAlias.d.ts +4 -0
  41. package/dist/aliasUtils/parseCircleAlias.js +66 -0
  42. package/dist/index.d.ts +6 -4
  43. package/dist/index.js +14 -7
  44. package/dist/isMonorepo.d.ts +5 -0
  45. package/dist/isMonorepo.js +43 -0
  46. package/package.json +16 -14
@@ -1,4 +1,4 @@
1
- // Type definitions for fs-extra 9.0
1
+ // Type definitions for fs-extra 11.0
2
2
  // Project: https://github.com/jprichardson/node-fs-extra
3
3
  // Definitions by: Alan Agius <https://github.com/alan-agius4>,
4
4
  // midknight41 <https://github.com/midknight41>,
@@ -9,555 +9,1001 @@
9
9
  // Florian Keller <https://github.com/ffflorian>
10
10
  // Piotr Błażejewicz <https://github.com/peterblazejewicz>
11
11
  // Tiger Oakes <https://github.com/NotWoods>
12
+ // BendingBender <https://github.com/BendingBender>
12
13
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
13
- // Minimum TypeScript Version: 3.9
14
+ // Minimum TypeScript Version: 4.5
14
15
 
15
16
  /// <reference types="node" />
16
17
 
17
18
  import * as fs from 'fs';
18
- import Stats = fs.Stats;
19
- import PathLike = fs.PathLike;
19
+ import * as jsonfile from './jsonfile';
20
+ import { StringifyOptions } from './jsonfile/utils';
20
21
 
21
22
  export * from 'fs';
22
23
 
24
+ /**
25
+ * Copy a file or directory. The directory can have contents.
26
+ *
27
+ * @param src Note that if `src` is a directory it will copy everything inside of this directory,
28
+ * not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).
29
+ * @param dest Note that if `src` is a file, `dest` cannot be a directory
30
+ * (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).
31
+ *
32
+ * @example
33
+ * import * as fs from '../fs-extra'
34
+ *
35
+ * // With a callback:
36
+ * fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
37
+ * if (err) return console.error(err)
38
+ * console.log('success!')
39
+ * }) // copies file
40
+ *
41
+ * fs.copy('/tmp/mydir', '/tmp/mynewdir', err => {
42
+ * if (err) return console.error(err)
43
+ * console.log('success!')
44
+ * }) // copies directory, even if it has subdirectories or files
45
+ *
46
+ * // With Promises:
47
+ * fs.copy('/tmp/myfile', '/tmp/mynewfile')
48
+ * .then(() => {
49
+ * console.log('success!')
50
+ * })
51
+ * .catch(err => {
52
+ * console.error(err)
53
+ * })
54
+ *
55
+ * // With async/await:
56
+ * async function asyncAwait () {
57
+ * try {
58
+ * await fs.copy('/tmp/myfile', '/tmp/mynewfile')
59
+ * console.log('success!')
60
+ * } catch (err) {
61
+ * console.error(err)
62
+ * }
63
+ * }
64
+ *
65
+ * asyncAwait()
66
+ *
67
+ * // Using filter function
68
+ * fs.copy(
69
+ * '/tmp/mydir',
70
+ * '/tmp/mynewdir',
71
+ * {
72
+ * filter(src, dest) {
73
+ * // your logic here
74
+ * // it will be copied if return true
75
+ * }
76
+ * },
77
+ * err => {
78
+ * if (err) return console.error(err)
79
+ * console.log('success!')
80
+ * }
81
+ * )
82
+ */
23
83
  export function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
24
- export function copy(src: string, dest: string, callback: (err: Error) => void): void;
25
- export function copy(src: string, dest: string, options: CopyOptions, callback: (err: Error) => void): void;
84
+ export function copy(src: string, dest: string, callback: NoParamCallbackWithUndefined): void;
85
+ export function copy(src: string, dest: string, options: CopyOptions, callback: NoParamCallbackWithUndefined): void;
86
+ /**
87
+ * Copy a file or directory. The directory can have contents.
88
+ *
89
+ * @param src Note that if `src` is a directory it will copy everything inside of this directory,
90
+ * not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).
91
+ * @param dest Note that if `src` is a file, `dest` cannot be a directory
92
+ * (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).
93
+ *
94
+ * @example
95
+ * import * as fs from '../fs-extra'
96
+ *
97
+ * // copy file
98
+ * fs.copySync('/tmp/myfile', '/tmp/mynewfile')
99
+ *
100
+ * // copy directory, even if it has subdirectories or files
101
+ * fs.copySync('/tmp/mydir', '/tmp/mynewdir')
102
+ *
103
+ * // Using filter function
104
+ * fs.copySync('/tmp/mydir', '/tmp/mynewdir', {
105
+ * filter(src, dest) {
106
+ * // your logic here
107
+ * // it will be copied if return true
108
+ * }
109
+ * })
110
+ */
26
111
  export function copySync(src: string, dest: string, options?: CopyOptionsSync): void;
27
112
 
28
- export function copyFile(src: string, dest: string, flags?: number): Promise<void>;
29
- export function copyFile(src: string, dest: string, callback: (err: Error) => void): void;
30
- export function copyFile(src: string, dest: string, flags: number, callback: (err: Error) => void): void;
31
-
113
+ /**
114
+ * Moves a file or directory, even across devices.
115
+ *
116
+ * @param dest Note: When `src` is a file, `dest` must be a file and when `src` is a directory, `dest` must be a directory.
117
+ *
118
+ * @example
119
+ * import * as fs from '../fs-extra'
120
+ *
121
+ * const src = '/tmp/file.txt'
122
+ * const dest = '/tmp/this/path/does/not/exist/file.txt'
123
+ *
124
+ * // With a callback:
125
+ * fs.move(src, dest, err => {
126
+ * if (err) return console.error(err)
127
+ * console.log('success!')
128
+ * })
129
+ *
130
+ * // With Promises:
131
+ * fs.move(src, dest)
132
+ * .then(() => {
133
+ * console.log('success!')
134
+ * })
135
+ * .catch(err => {
136
+ * console.error(err)
137
+ * })
138
+ *
139
+ * // With async/await:
140
+ * async function asyncAwait () {
141
+ * try {
142
+ * await fs.move(src, dest)
143
+ * console.log('success!')
144
+ * } catch (err) {
145
+ * console.error(err)
146
+ * }
147
+ * }
148
+ *
149
+ * asyncAwait()
150
+ *
151
+ * // Using `overwrite` option
152
+ * fs.move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => {
153
+ * if (err) return console.error(err)
154
+ * console.log('success!')
155
+ * })
156
+ */
32
157
  export function move(src: string, dest: string, options?: MoveOptions): Promise<void>;
33
- export function move(src: string, dest: string, callback: (err: Error) => void): void;
34
- export function move(src: string, dest: string, options: MoveOptions, callback: (err: Error) => void): void;
158
+ export function move(src: string, dest: string, callback: NoParamCallbackWithUndefined): void;
159
+ export function move(src: string, dest: string, options: MoveOptions, callback: NoParamCallbackWithUndefined): void;
160
+ /**
161
+ * Moves a file or directory, even across devices.
162
+ *
163
+ * @param dest Note: When `src` is a file, `dest` must be a file and when `src` is a directory, `dest` must be a directory.
164
+ *
165
+ * @example
166
+ * import * as fs from '../fs-extra'
167
+ *
168
+ * fs.moveSync('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')
169
+ *
170
+ * // Using `overwrite` option
171
+ * fs.moveSync('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true })
172
+ */
35
173
  export function moveSync(src: string, dest: string, options?: MoveOptions): void;
36
174
 
37
- export function createFile(file: string): Promise<void>;
38
- export function createFile(file: string, callback: (err: Error) => void): void;
39
- export function createFileSync(file: string): void;
40
-
41
- export function createSymlink(src: string, dest: string, type: SymlinkType): Promise<void>;
42
- export function createSymlink(src: string, dest: string, type: SymlinkType, callback?: (err: Error) => void): void;
43
- export function createSymlinkSync(src: string, dest: string, type: SymlinkType): void;
44
-
45
- export function ensureDir(path: string, options?: EnsureOptions | number): Promise<void>;
46
- export function ensureDir(path: string, callback?: (err: Error) => void): void;
47
- export function ensureDir(path: string, options?: EnsureOptions | number, callback?: (err: Error) => void): void;
48
- export function ensureDirSync(path: string, options?: EnsureOptions | number): void;
49
-
50
- export function mkdirs(dir: string): Promise<void>;
51
- export function mkdirs(dir: string, callback: (err: Error) => void): void;
52
- export function mkdirp(dir: string): Promise<void>;
53
- export function mkdirp(dir: string, callback: (err: Error) => void): void;
54
- export function mkdirsSync(dir: string): void;
55
- export function mkdirpSync(dir: string): void;
56
-
57
- export function outputFile(
58
- file: string,
59
- data: any,
60
- options?: WriteFileOptions | BufferEncoding | string,
61
- ): Promise<void>;
62
- export function outputFile(file: string, data: any, callback: (err: Error) => void): void;
63
- export function outputFile(
64
- file: string,
65
- data: any,
66
- options: WriteFileOptions | string,
67
- callback: (err: Error) => void,
68
- ): void;
69
- export function outputFileSync(file: string, data: any, options?: WriteFileOptions | BufferEncoding | string): void;
70
-
71
- export function readJson(file: string, options?: ReadOptions | BufferEncoding | string): Promise<any>;
72
- export function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void;
73
- export function readJson(
74
- file: string,
75
- options: ReadOptions | BufferEncoding | string,
76
- callback: (err: Error, jsonObject: any) => void,
77
- ): void;
78
- export function readJSON(file: string, options?: ReadOptions | BufferEncoding | string): Promise<any>;
79
- export function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void;
80
- export function readJSON(
81
- file: string,
82
- options: ReadOptions | BufferEncoding | string,
83
- callback: (err: Error, jsonObject: any) => void,
84
- ): void;
85
-
86
- export function readJsonSync(file: string, options?: ReadOptions | BufferEncoding | string): any;
87
- export function readJSONSync(file: string, options?: ReadOptions | BufferEncoding | string): any;
88
-
89
- export function remove(dir: string, callback: (err: Error) => void): void;
90
- export function remove(dir: string, callback?: (err: Error) => void): Promise<void>;
91
- export function removeSync(dir: string): void;
92
-
93
- export function outputJSON(file: string, data: any, options?: WriteOptions | BufferEncoding | string): Promise<void>;
94
- export function outputJSON(
95
- file: string,
96
- data: any,
97
- options: WriteOptions | BufferEncoding | string,
98
- callback: (err: Error) => void,
99
- ): void;
100
- export function outputJSON(file: string, data: any, callback: (err: Error) => void): void;
101
- export function outputJson(file: string, data: any, options?: WriteOptions | BufferEncoding | string): Promise<void>;
102
- export function outputJson(
103
- file: string,
104
- data: any,
105
- options: WriteOptions | BufferEncoding | string,
106
- callback: (err: Error) => void,
107
- ): void;
108
- export function outputJson(file: string, data: any, callback: (err: Error) => void): void;
109
- export function outputJsonSync(file: string, data: any, options?: WriteOptions | BufferEncoding | string): void;
110
- export function outputJSONSync(file: string, data: any, options?: WriteOptions | BufferEncoding | string): void;
111
-
112
- export function writeJSON(file: string, object: any, options?: WriteOptions | BufferEncoding | string): Promise<void>;
113
- export function writeJSON(file: string, object: any, callback: (err: Error) => void): void;
114
- export function writeJSON(
115
- file: string,
116
- object: any,
117
- options: WriteOptions | BufferEncoding | string,
118
- callback: (err: Error) => void,
119
- ): void;
120
- export function writeJson(file: string, object: any, options?: WriteOptions | BufferEncoding | string): Promise<void>;
121
- export function writeJson(file: string, object: any, callback: (err: Error) => void): void;
122
- export function writeJson(
123
- file: string,
124
- object: any,
125
- options: WriteOptions | BufferEncoding | string,
126
- callback: (err: Error) => void,
127
- ): void;
128
-
129
- export function writeJsonSync(file: string, object: any, options?: WriteOptions | BufferEncoding | string): void;
130
- export function writeJSONSync(file: string, object: any, options?: WriteOptions | BufferEncoding | string): void;
131
-
132
- export function ensureFile(path: string): Promise<void>;
133
- export function ensureFile(path: string, callback: (err: Error) => void): void;
134
- export function ensureFileSync(path: string): void;
175
+ /**
176
+ * Ensures that the file exists. If the file that is requested to be created is in
177
+ * directories that do not exist, these directories are created. If the file already
178
+ * exists, it is **NOT MODIFIED**.
179
+ *
180
+ * @example
181
+ * import * as fs from '../fs-extra'
182
+ *
183
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
184
+ *
185
+ * // With a callback:
186
+ * fs.ensureFile(file, err => {
187
+ * console.log(err) // => null
188
+ * // file has now been created, including the directory it is to be placed in
189
+ * })
190
+ *
191
+ * // With Promises:
192
+ * fs.ensureFile(file)
193
+ * .then(() => {
194
+ * console.log('success!')
195
+ * })
196
+ * .catch(err => {
197
+ * console.error(err)
198
+ * })
199
+ *
200
+ * // With async/await:
201
+ * async function asyncAwait () {
202
+ * try {
203
+ * await fs.ensureFile(file)
204
+ * console.log('success!')
205
+ * } catch (err) {
206
+ * console.error(err)
207
+ * }
208
+ * }
209
+ *
210
+ * asyncAwait()
211
+ */
212
+ export function ensureFile(file: string): Promise<void>;
213
+ export function ensureFile(file: string, callback: NoParamCallbackWithUndefined): void;
214
+ /**
215
+ * @see ensureFile
216
+ */
217
+ export const createFile: typeof ensureFile;
218
+ /**
219
+ * Ensures that the file exists. If the file that is requested to be created is in
220
+ * directories that do not exist, these directories are created. If the file already
221
+ * exists, it is **NOT MODIFIED**.
222
+ *
223
+ * @example
224
+ * import * as fs from '../fs-extra'
225
+ *
226
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
227
+ * fs.ensureFileSync(file)
228
+ * // file has now been created, including the directory it is to be placed in
229
+ */
230
+ export function ensureFileSync(file: string): void;
231
+ /**
232
+ * @see ensureFileSync
233
+ */
234
+ export const createFileSync: typeof ensureFileSync;
135
235
 
236
+ /**
237
+ * Ensures that the link exists. If the directory structure does not exist, it is created.
238
+ *
239
+ * @example
240
+ * import * as fs from '../fs-extra'
241
+ *
242
+ * const srcPath = '/tmp/file.txt'
243
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
244
+ *
245
+ * // With a callback:
246
+ * fs.ensureLink(srcPath, destPath, err => {
247
+ * console.log(err) // => null
248
+ * // link has now been created, including the directory it is to be placed in
249
+ * })
250
+ *
251
+ * // With Promises:
252
+ * fs.ensureLink(srcPath, destPath)
253
+ * .then(() => {
254
+ * console.log('success!')
255
+ * })
256
+ * .catch(err => {
257
+ * console.error(err)
258
+ * })
259
+ *
260
+ * // With async/await:
261
+ * async function asyncAwait () {
262
+ * try {
263
+ * await fs.ensureLink(srcPath, destPath)
264
+ * console.log('success!')
265
+ * } catch (err) {
266
+ * console.error(err)
267
+ * }
268
+ * }
269
+ *
270
+ * asyncAwait()
271
+ */
136
272
  export function ensureLink(src: string, dest: string): Promise<void>;
137
- export function ensureLink(src: string, dest: string, callback: (err: Error) => void): void;
138
- // alias for ensureLink
273
+ export function ensureLink(src: string, dest: string, callback: fs.NoParamCallback): void;
274
+ /**
275
+ * @see ensureLink
276
+ */
139
277
  export const createLink: typeof ensureLink;
278
+ /**
279
+ * Ensures that the link exists. If the directory structure does not exist, it is created.
280
+ *
281
+ * @example
282
+ * import * as fs from '../fs-extra'
283
+ *
284
+ * const srcPath = '/tmp/file.txt'
285
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
286
+ * fs.ensureLinkSync(srcPath, destPath)
287
+ * // link has now been created, including the directory it is to be placed in
288
+ */
140
289
  export function ensureLinkSync(src: string, dest: string): void;
141
- // aliased as
290
+ /**
291
+ * @see ensureLinkSync
292
+ */
142
293
  export const createLinkSync: typeof ensureLinkSync;
143
294
 
295
+ /**
296
+ * Ensures that the symlink exists. If the directory structure does not exist, it is created.
297
+ *
298
+ * @param type It is only available on Windows and ignored on other platforms.
299
+ *
300
+ * @example
301
+ * import * as fs from '../fs-extra'
302
+ *
303
+ * const srcPath = '/tmp/file.txt'
304
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
305
+ *
306
+ * // With a callback:
307
+ * fs.ensureSymlink(srcPath, destPath, err => {
308
+ * console.log(err) // => null
309
+ * // symlink has now been created, including the directory it is to be placed in
310
+ * })
311
+ *
312
+ * // With Promises:
313
+ * fs.ensureSymlink(srcPath, destPath)
314
+ * .then(() => {
315
+ * console.log('success!')
316
+ * })
317
+ * .catch(err => {
318
+ * console.error(err)
319
+ * })
320
+ *
321
+ * // With async/await:
322
+ * async function asyncAwait () {
323
+ * try {
324
+ * await fs.ensureSymlink(srcPath, destPath)
325
+ * console.log('success!')
326
+ * } catch (err) {
327
+ * console.error(err)
328
+ * }
329
+ * }
330
+ *
331
+ * asyncAwait()
332
+ */
144
333
  export function ensureSymlink(src: string, dest: string, type?: SymlinkType): Promise<void>;
145
- export function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: (err: Error) => void): void;
146
- export function ensureSymlink(src: string, dest: string, callback: (err: Error) => void): void;
334
+ export function ensureSymlink(src: string, dest: string, callback: fs.NoParamCallback): void;
335
+ export function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: fs.NoParamCallback): void;
336
+ /**
337
+ * @see ensureSymlink
338
+ */
339
+ export const createSymlink: typeof ensureSymlink;
340
+ /**
341
+ * Ensures that the symlink exists. If the directory structure does not exist, it is created.
342
+ *
343
+ * @param type It is only available on Windows and ignored on other platforms.
344
+ *
345
+ * @example
346
+ * import * as fs from '../fs-extra'
347
+ *
348
+ * const srcPath = '/tmp/file.txt'
349
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
350
+ * fs.ensureSymlinkSync(srcPath, destPath)
351
+ * // symlink has now been created, including the directory it is to be placed in
352
+ */
147
353
  export function ensureSymlinkSync(src: string, dest: string, type?: SymlinkType): void;
148
-
149
- export function emptyDir(path: string): Promise<void>;
150
- export function emptyDir(path: string, callback: (err: Error) => void): void;
151
- export const emptydir: typeof emptyDir;
152
-
153
- export function emptyDirSync(path: string): void;
154
- export const emptydirSync: typeof emptyDirSync;
155
-
156
- export function pathExists(path: string): Promise<boolean>;
157
- export function pathExists(path: string, callback: (err: Error, exists: boolean) => void): void;
158
- export function pathExistsSync(path: string): boolean;
159
-
160
- // fs async methods
161
- // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v6/index.d.ts
162
-
163
- export function access(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
164
- export function access(path: PathLike, mode: number, callback: (err: NodeJS.ErrnoException) => void): void;
165
- export function access(path: PathLike, mode?: number): Promise<void>;
166
-
167
- export function appendFile(
168
- file: PathLike | number,
169
- data: any,
170
- options: {
171
- encoding?: BufferEncoding | string | undefined;
172
- mode?: number | string | undefined;
173
- flag?: string | undefined;
174
- },
175
- callback: (err: NodeJS.ErrnoException) => void,
176
- ): void;
177
- export function appendFile(file: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
178
- export function appendFile(
179
- file: PathLike | number,
180
- data: any,
181
- options?:
182
- | {
183
- encoding?: BufferEncoding | string | undefined;
184
- mode?: number | string | undefined;
185
- flag?: string | undefined;
186
- }
187
- | BufferEncoding
188
- | string,
189
- ): Promise<void>;
190
-
191
- export function chmod(path: PathLike, mode: Mode, callback: (err: NodeJS.ErrnoException) => void): void;
192
- export function chmod(path: PathLike, mode: Mode): Promise<void>;
193
-
194
- export function chown(path: PathLike, uid: number, gid: number): Promise<void>;
195
- export function chown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
196
-
197
- export function close(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
198
- export function close(fd: number): Promise<void>;
199
-
200
- export function fchmod(fd: number, mode: Mode, callback: (err: NodeJS.ErrnoException) => void): void;
201
- export function fchmod(fd: number, mode: Mode): Promise<void>;
202
-
203
- export function fchown(fd: number, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
204
- export function fchown(fd: number, uid: number, gid: number): Promise<void>;
205
-
206
- export function fdatasync(fd: number, callback: () => void): void;
207
- export function fdatasync(fd: number): Promise<void>;
208
-
209
- export function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
210
- export function fstat(fd: number): Promise<Stats>;
211
-
212
- export function fsync(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
213
- export function fsync(fd: number): Promise<void>;
214
-
215
- export function ftruncate(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
216
- export function ftruncate(fd: number, len: number, callback: (err: NodeJS.ErrnoException) => void): void;
217
- export function ftruncate(fd: number, len?: number): Promise<void>;
218
-
219
- export function futimes(fd: number, atime: number, mtime: number, callback: (err: NodeJS.ErrnoException) => void): void;
220
- export function futimes(fd: number, atime: Date, mtime: Date, callback: (err: NodeJS.ErrnoException) => void): void;
221
- export function futimes(fd: number, atime: number, mtime: number): Promise<void>;
222
- export function futimes(fd: number, atime: Date, mtime: Date): Promise<void>;
223
-
224
- export function lchown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
225
- export function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
226
-
227
- export function link(existingPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
228
- export function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
229
-
230
- export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
231
- export function lstat(path: PathLike): Promise<Stats>;
354
+ /**
355
+ * @see ensureSymlinkSync
356
+ */
357
+ export const createSymlinkSync: typeof ensureSymlinkSync;
232
358
 
233
359
  /**
234
- * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
360
+ * Ensures that the directory exists. If the directory structure does not exist, it is created.
361
+ *
362
+ * @example
363
+ * import * as fs from '../fs-extra'
364
+ *
365
+ * const dir = '/tmp/this/path/does/not/exist'
366
+ * const desiredMode = 0o2775
367
+ * const options = {
368
+ * mode: 0o2775
369
+ * }
370
+ *
371
+ * // With a callback:
372
+ * fs.ensureDir(dir, err => {
373
+ * console.log(err) // => null
374
+ * // dir has now been created, including the directory it is to be placed in
375
+ * })
376
+ *
377
+ * // With a callback and a mode integer
378
+ * fs.ensureDir(dir, desiredMode, err => {
379
+ * console.log(err) // => null
380
+ * // dir has now been created with mode 0o2775, including the directory it is to be placed in
381
+ * })
235
382
  *
236
- * @param callback No arguments other than a possible exception are given to the completion callback.
383
+ * // With Promises:
384
+ * fs.ensureDir(dir)
385
+ * .then(() => {
386
+ * console.log('success!')
387
+ * })
388
+ * .catch(err => {
389
+ * console.error(err)
390
+ * })
391
+ *
392
+ * // With Promises and a mode integer:
393
+ * fs.ensureDir(dir, desiredMode)
394
+ * .then(() => {
395
+ * console.log('success!')
396
+ * })
397
+ * .catch(err => {
398
+ * console.error(err)
399
+ * })
400
+ *
401
+ * // With async/await:
402
+ * async function asyncAwait () {
403
+ * try {
404
+ * await fs.ensureDir(dir)
405
+ * console.log('success!')
406
+ * } catch (err) {
407
+ * console.error(err)
408
+ * }
409
+ * }
410
+ * asyncAwait()
411
+ *
412
+ * // With async/await and an options object, containing mode:
413
+ * async function asyncAwaitMode () {
414
+ * try {
415
+ * await fs.ensureDir(dir, options)
416
+ * console.log('success!')
417
+ * } catch (err) {
418
+ * console.error(err)
419
+ * }
420
+ * }
421
+ * asyncAwaitMode()
237
422
  */
238
- export function mkdir(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
423
+ export function ensureDir(path: string, options?: EnsureDirOptions | number): Promise<void>;
424
+ export function ensureDir(path: string, callback: fs.NoParamCallback): void;
425
+ export function ensureDir(path: string, options: EnsureDirOptions | number, callback: fs.NoParamCallback): void;
239
426
  /**
240
- * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
427
+ * Ensures that the directory exists. If the directory structure does not exist, it is created.
428
+ * If provided, options may specify the desired mode for the directory.
429
+ *
430
+ * @example
431
+ * import * as fs from '../fs-extra'
432
+ *
433
+ * const dir = '/tmp/this/path/does/not/exist'
241
434
  *
242
- * @param callback No arguments other than a possible exception are given to the completion callback.
435
+ * const desiredMode = 0o2775
436
+ * const options = {
437
+ * mode: 0o2775
438
+ * }
439
+ *
440
+ * fs.ensureDirSync(dir)
441
+ * // dir has now been created, including the directory it is to be placed in
442
+ *
443
+ * fs.ensureDirSync(dir, desiredMode)
444
+ * // dir has now been created, including the directory it is to be placed in with permission 0o2775
445
+ *
446
+ * fs.ensureDirSync(dir, options)
447
+ * // dir has now been created, including the directory it is to be placed in with permission 0o2775
243
448
  */
244
- export function mkdir(
245
- path: PathLike,
246
- options: Mode | fs.MakeDirectoryOptions | null,
247
- callback: (err: NodeJS.ErrnoException) => void,
248
- ): void;
249
- export function mkdir(path: PathLike, options?: Mode | fs.MakeDirectoryOptions | null): Promise<void>;
250
- export function mkdirSync(path: PathLike, options?: Mode | fs.MakeDirectoryOptions | null): void;
251
-
252
- export function open(
253
- path: PathLike,
254
- flags: string | number,
255
- callback: (err: NodeJS.ErrnoException, fd: number) => void,
256
- ): void;
257
- export function open(
258
- path: PathLike,
259
- flags: string | number,
260
- mode: Mode,
261
- callback: (err: NodeJS.ErrnoException, fd: number) => void,
262
- ): void;
263
- export function open(path: PathLike, flags: string | number, mode?: Mode | null): Promise<number>;
264
-
265
- export function opendir(path: string, cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void): void;
266
- export function opendir(
267
- path: string,
268
- options: fs.OpenDirOptions,
269
- cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void,
270
- ): void;
271
- export function opendir(path: string, options?: fs.OpenDirOptions): Promise<fs.Dir>;
449
+ export function ensureDirSync(path: string, options?: EnsureDirOptions | number): void;
272
450
 
273
- export function read<TBuffer extends ArrayBufferView>(
274
- fd: number,
275
- buffer: TBuffer,
276
- offset: number,
277
- length: number,
278
- position: number | null,
279
- callback: (err: NodeJS.ErrnoException, bytesRead: number, buffer: TBuffer) => void,
280
- ): void;
281
- export function read<TBuffer extends ArrayBufferView>(
282
- fd: number,
283
- buffer: TBuffer,
284
- offset: number,
285
- length: number,
286
- position: number | null,
287
- ): Promise<{ bytesRead: number; buffer: TBuffer }>;
288
-
289
- export function readFile(file: PathLike | number, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
290
- export function readFile(
291
- file: PathLike | number,
292
- encoding: BufferEncoding | string,
293
- callback: (err: NodeJS.ErrnoException, data: string) => void,
294
- ): void;
295
- export function readFile(
296
- file: PathLike | number,
297
- options: { flag?: string | undefined } | { encoding: BufferEncoding | string; flag?: string | undefined },
298
- callback: (err: NodeJS.ErrnoException, data: Buffer) => void,
299
- ): void;
300
- export function readFile(
301
- file: PathLike | number,
302
- options: { flag?: string | undefined } | { encoding: BufferEncoding | string; flag?: string | undefined },
303
- ): Promise<string>;
304
- // tslint:disable-next-line:unified-signatures
305
- export function readFile(file: PathLike | number, encoding: BufferEncoding | string): Promise<string>;
306
- export function readFile(file: PathLike | number): Promise<Buffer>;
307
-
308
- export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void;
309
- export function readdir(
310
- path: PathLike,
311
- options: 'buffer' | { encoding: 'buffer'; withFileTypes?: false | undefined },
312
- ): Promise<Buffer[]>;
313
- export function readdir(
314
- path: PathLike,
315
- options?:
316
- | { encoding: BufferEncoding | string | null; withFileTypes?: false | undefined }
317
- | BufferEncoding
318
- | string
319
- | null,
320
- ): Promise<string[]>;
321
- export function readdir(
322
- path: PathLike,
323
- options?: { encoding?: BufferEncoding | string | null | undefined; withFileTypes?: false | undefined },
324
- ): Promise<string[] | Buffer[]>;
325
- export function readdir(
326
- path: PathLike,
327
- options: { encoding?: BufferEncoding | string | null | undefined; withFileTypes: true },
328
- ): Promise<fs.Dirent[]>;
329
-
330
- export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException, linkString: string) => any): void;
331
- export function readlink(path: PathLike): Promise<string>;
332
-
333
- export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
334
- export function realpath(
335
- path: PathLike,
336
- cache: { [path: string]: string },
337
- callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any,
338
- ): void;
339
- export function realpath(path: PathLike, cache?: { [path: string]: string }): Promise<string>;
340
-
341
- /* tslint:disable:unified-signatures */
342
- export namespace realpath {
343
- const native: {
344
- (path: PathLike, options: { encoding: 'buffer' } | 'buffer'): Promise<Buffer>;
345
- (
346
- path: PathLike,
347
- options: { encoding: BufferEncoding | string | null } | BufferEncoding | string | undefined | null,
348
- ): Promise<string>;
349
- (path: PathLike, options: { encoding: BufferEncoding | string | null } | string | undefined | null): Promise<
350
- string | Buffer
351
- >;
352
- (path: PathLike): Promise<string>;
353
- } & typeof fs.realpath.native;
354
- }
355
- /* tslint:enable:unified-signatures */
451
+ /**
452
+ * @see ensureDir
453
+ */
454
+ export const mkdirs: typeof ensureDir;
455
+ /**
456
+ * @see ensureDirSync
457
+ */
458
+ export const mkdirsSync: typeof ensureDirSync;
356
459
 
357
- export function rename(oldPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
358
- export function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
460
+ /**
461
+ * @see ensureDir
462
+ */
463
+ export const mkdirp: typeof ensureDir;
464
+ /**
465
+ * @see ensureDirSync
466
+ */
467
+ export const mkdirpSync: typeof ensureDirSync;
359
468
 
360
469
  /**
361
- * Asynchronously removes files and directories (modeled on the standard POSIX
362
- * `rm` utility).
470
+ * Almost the same as `writeFile` (i.e. it overwrites), except that if the parent directory
471
+ * does not exist, it's created.
472
+ *
473
+ * @example
474
+ * import * as fs from '../fs-extra'
475
+ *
476
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
363
477
  *
364
- * Only available in node >= v14.14.0
478
+ * // With a callback:
479
+ * fs.outputFile(file, 'hello!', err => {
480
+ * console.log(err) // => null
481
+ *
482
+ * fs.readFile(file, 'utf8', (err, data) => {
483
+ * if (err) return console.error(err)
484
+ * console.log(data) // => hello!
485
+ * })
486
+ * })
487
+ *
488
+ * // With Promises:
489
+ * fs.outputFile(file, 'hello!')
490
+ * .then(() => fs.readFile(file, 'utf8'))
491
+ * .then(data => {
492
+ * console.log(data) // => hello!
493
+ * })
494
+ * .catch(err => {
495
+ * console.error(err)
496
+ * })
497
+ *
498
+ * // With async/await:
499
+ * async function asyncAwait () {
500
+ * try {
501
+ * await fs.outputFile(file, 'hello!')
502
+ *
503
+ * const data = await fs.readFile(file, 'utf8')
504
+ *
505
+ * console.log(data) // => hello!
506
+ * } catch (err) {
507
+ * console.error(err)
508
+ * }
509
+ * }
510
+ *
511
+ * asyncAwait()
365
512
  */
366
- export function rm(
367
- path: PathLike,
368
- options?: {
369
- force?: boolean | undefined;
370
- maxRetries?: number | undefined;
371
- recursive?: boolean | undefined;
372
- retryDelay?: number | undefined;
373
- },
513
+ export function outputFile(
514
+ file: string,
515
+ data: string | NodeJS.ArrayBufferView,
516
+ options?: fs.WriteFileOptions,
374
517
  ): Promise<void>;
375
-
518
+ export function outputFile(file: string, data: string | NodeJS.ArrayBufferView, callback: fs.NoParamCallback): void;
519
+ export function outputFile(
520
+ file: string,
521
+ data: string | NodeJS.ArrayBufferView,
522
+ options: fs.WriteFileOptions,
523
+ callback: fs.NoParamCallback,
524
+ ): void;
376
525
  /**
377
- * Asynchronous rmdir - removes the directory specified in {path}
526
+ * Almost the same as `writeFileSync` (i.e. it overwrites), except that if the parent directory
527
+ * does not exist, it's created.
528
+ *
529
+ * @example
530
+ * import * as fs from '../fs-extra'
378
531
  *
379
- * @param callback No arguments other than a possible exception are given to the completion callback.
532
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
533
+ * fs.outputFileSync(file, 'hello!')
534
+ *
535
+ * const data = fs.readFileSync(file, 'utf8')
536
+ * console.log(data) // => hello!
380
537
  */
381
- export function rmdir(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
382
- export function rmdir(path: PathLike, options?: fs.RmDirOptions): Promise<void>;
383
-
384
- export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
385
- export function stat(path: PathLike): Promise<Stats>;
386
-
387
- export function symlink(
388
- target: PathLike,
389
- path: PathLike,
390
- type: SymlinkType | undefined,
391
- callback: (err: NodeJS.ErrnoException) => void,
538
+ export function outputFileSync(
539
+ file: string,
540
+ data: string | NodeJS.ArrayBufferView,
541
+ options?: fs.WriteFileOptions,
392
542
  ): void;
393
- export function symlink(target: PathLike, path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
394
- export function symlink(target: PathLike, path: PathLike, type?: SymlinkType): Promise<void>;
395
-
396
- export function truncate(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
397
- export function truncate(path: PathLike, len: number, callback: (err: NodeJS.ErrnoException) => void): void;
398
- export function truncate(path: PathLike, len?: number): Promise<void>;
399
543
 
400
544
  /**
401
- * Asynchronous unlink - deletes the file specified in {path}
545
+ * Reads a JSON file and then parses it into an object.
546
+ *
547
+ * @example
548
+ * import * as fs from '../fs-extra'
549
+ *
550
+ * // With a callback:
551
+ * fs.readJson('./package.json', (err, packageObj) => {
552
+ * if (err) console.error(err)
553
+ * console.log(packageObj.version) // => 0.1.3
554
+ * })
555
+ *
556
+ * // With Promises:
557
+ * fs.readJson('./package.json')
558
+ * .then(packageObj => {
559
+ * console.log(packageObj.version) // => 0.1.3
560
+ * })
561
+ * .catch(err => {
562
+ * console.error(err)
563
+ * })
564
+ *
565
+ * // With async/await:
566
+ * async function asyncAwait () {
567
+ * try {
568
+ * const packageObj = await fs.readJson('./package.json')
569
+ * console.log(packageObj.version) // => 0.1.3
570
+ * } catch (err) {
571
+ * console.error(err)
572
+ * }
573
+ * }
574
+ *
575
+ * asyncAwait()
576
+ *
577
+ * // `readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:
578
+ * const file = '/tmp/some-invalid.json'
579
+ * const data = '{not valid JSON'
580
+ * fs.writeFileSync(file, data)
581
+ *
582
+ * // With a callback:
583
+ * fs.readJson(file, { throws: false }, (err, obj) => {
584
+ * if (err) console.error(err)
585
+ * console.log(obj) // => null
586
+ * })
587
+ *
588
+ * // With Promises:
589
+ * fs.readJson(file, { throws: false })
590
+ * .then(obj => {
591
+ * console.log(obj) // => null
592
+ * })
593
+ * .catch(err => {
594
+ * console.error(err) // Not called
595
+ * })
596
+ *
597
+ * // With async/await:
598
+ * async function asyncAwaitThrows () {
599
+ * const obj = await fs.readJson(file, { throws: false })
600
+ * console.log(obj) // => null
601
+ * }
602
+ *
603
+ * asyncAwaitThrows()
604
+ */
605
+ export const readJson: typeof jsonfile.readFile;
606
+ /**
607
+ * @see readJson
608
+ */
609
+ export const readJSON: typeof jsonfile.readFile;
610
+ /**
611
+ * Reads a JSON file and then parses it into an object.
612
+ *
613
+ * @example
614
+ * import * as fs from '../fs-extra'
615
+ *
616
+ * const packageObj = fs.readJsonSync('./package.json')
617
+ * console.log(packageObj.version) // => 2.0.0
618
+ *
619
+ * // `readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:
620
+ * const file = '/tmp/some-invalid.json'
621
+ * const data = '{not valid JSON'
622
+ * fs.writeFileSync(file, data)
402
623
  *
403
- * @param callback No arguments other than a possible exception are given to the completion callback.
624
+ * const obj = fs.readJsonSync(file, { throws: false })
625
+ * console.log(obj) // => null
404
626
  */
405
- export function unlink(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
406
- export function unlink(path: PathLike): Promise<void>;
407
-
408
- export function utimes(
409
- path: PathLike,
410
- atime: number,
411
- mtime: number,
412
- callback: (err: NodeJS.ErrnoException) => void,
413
- ): void;
414
- export function utimes(path: PathLike, atime: Date, mtime: Date, callback: (err: NodeJS.ErrnoException) => void): void;
415
- export function utimes(path: PathLike, atime: number, mtime: number): Promise<void>;
416
- export function utimes(path: PathLike, atime: Date, mtime: Date): Promise<void>;
627
+ export const readJsonSync: typeof jsonfile.readFileSync;
628
+ /**
629
+ * @see readJsonSync
630
+ */
631
+ export const readJSONSync: typeof jsonfile.readFileSync;
417
632
 
418
- export function write<TBuffer extends ArrayBufferView>(
419
- fd: number,
420
- buffer: TBuffer,
421
- offset: number,
422
- length: number,
423
- position: number | null,
424
- callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void,
425
- ): void;
426
- export function write<TBuffer extends ArrayBufferView>(
427
- fd: number,
428
- buffer: TBuffer,
429
- offset: number,
430
- length: number,
431
- callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void,
432
- ): void;
433
- export function write(
434
- fd: number,
435
- data: any,
436
- callback: (err: NodeJS.ErrnoException, written: number, str: string) => void,
437
- ): void;
438
- export function write(
439
- fd: number,
440
- data: any,
441
- offset: number,
442
- callback: (err: NodeJS.ErrnoException, written: number, str: string) => void,
443
- ): void;
444
- export function write(
445
- fd: number,
446
- data: any,
447
- offset: number,
448
- encoding: BufferEncoding | string,
449
- callback: (err: NodeJS.ErrnoException, written: number, str: string) => void,
450
- ): void;
451
- export function write<TBuffer extends ArrayBufferView>(
452
- fd: number,
453
- buffer: TBuffer,
454
- offset?: number,
455
- length?: number,
456
- position?: number | null,
457
- ): Promise<{ bytesWritten: number; buffer: TBuffer }>;
458
- export function write(
459
- fd: number,
460
- data: any,
461
- offset?: number,
462
- encoding?: BufferEncoding | string,
463
- ): Promise<{ bytesWritten: number; buffer: string }>;
633
+ /**
634
+ * Writes an object to a JSON file.
635
+ *
636
+ * @example
637
+ * import * as fs from '../fs-extra'
638
+ *
639
+ * // With a callback:
640
+ * fs.writeJson('./package.json', {name: 'fs-extra'}, err => {
641
+ * if (err) return console.error(err)
642
+ * console.log('success!')
643
+ * })
644
+ *
645
+ * // With Promises:
646
+ * fs.writeJson('./package.json', {name: 'fs-extra'})
647
+ * .then(() => {
648
+ * console.log('success!')
649
+ * })
650
+ * .catch(err => {
651
+ * console.error(err)
652
+ * })
653
+ *
654
+ * // With async/await:
655
+ * async function asyncAwait () {
656
+ * try {
657
+ * await fs.writeJson('./package.json', {name: 'fs-extra'})
658
+ * console.log('success!')
659
+ * } catch (err) {
660
+ * console.error(err)
661
+ * }
662
+ * }
663
+ *
664
+ * asyncAwait()
665
+ */
666
+ export const writeJson: typeof jsonfile.writeFile;
667
+ /**
668
+ * @see writeJson
669
+ */
670
+ export const writeJSON: typeof jsonfile.writeFile;
671
+ /**
672
+ * Writes an object to a JSON file.
673
+ *
674
+ * @example
675
+ * import * as fs from '../fs-extra'
676
+ *
677
+ * fs.writeJsonSync('./package.json', {name: 'fs-extra'})
678
+ */
679
+ export const writeJsonSync: typeof jsonfile.writeFileSync;
680
+ /**
681
+ * @see writeJsonSync
682
+ */
683
+ export const writeJSONSync: typeof jsonfile.writeFileSync;
464
684
 
465
- export function writeFile(file: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
466
- export function writeFile(
467
- file: PathLike | number,
468
- data: any,
469
- options?: WriteFileOptions | BufferEncoding | string,
470
- ): Promise<void>;
471
- export function writeFile(
472
- file: PathLike | number,
473
- data: any,
474
- options: WriteFileOptions | BufferEncoding | string,
475
- callback: (err: NodeJS.ErrnoException) => void,
476
- ): void;
685
+ /**
686
+ * Almost the same as `writeJson`, except that if the directory does not exist, it's created.
687
+ *
688
+ * @example
689
+ * import * as fs from '../fs-extra'
690
+ *
691
+ * const file = '/tmp/this/path/does/not/exist/file.json'
692
+ *
693
+ * // With a callback:
694
+ * fs.outputJson(file, {name: 'JP'}, err => {
695
+ * console.log(err) // => null
696
+ *
697
+ * fs.readJson(file, (err, data) => {
698
+ * if (err) return console.error(err)
699
+ * console.log(data.name) // => JP
700
+ * })
701
+ * })
702
+ *
703
+ * // With Promises:
704
+ * fs.outputJson(file, {name: 'JP'})
705
+ * .then(() => fs.readJson(file))
706
+ * .then(data => {
707
+ * console.log(data.name) // => JP
708
+ * })
709
+ * .catch(err => {
710
+ * console.error(err)
711
+ * })
712
+ *
713
+ * // With async/await:
714
+ * async function asyncAwait () {
715
+ * try {
716
+ * await fs.outputJson(file, {name: 'JP'})
717
+ *
718
+ * const data = await fs.readJson(file)
719
+ *
720
+ * console.log(data.name) // => JP
721
+ * } catch (err) {
722
+ * console.error(err)
723
+ * }
724
+ * }
725
+ *
726
+ * asyncAwait()
727
+ */
728
+ export function outputJson(file: string, data: any, options?: JsonOutputOptions): Promise<void>;
729
+ export function outputJson(file: string, data: any, options: JsonOutputOptions, callback: fs.NoParamCallback): void;
730
+ export function outputJson(file: string, data: any, callback: fs.NoParamCallback): void;
731
+ /**
732
+ * @see outputJson
733
+ */
734
+ export const outputJSON: typeof outputJson;
735
+ /**
736
+ * Almost the same as `writeJsonSync`, except that if the directory does not exist, it's created.
737
+ *
738
+ * @example
739
+ * import * as fs from '../fs-extra'
740
+ *
741
+ * const file = '/tmp/this/path/does/not/exist/file.json'
742
+ * fs.outputJsonSync(file, {name: 'JP'})
743
+ *
744
+ * const data = fs.readJsonSync(file)
745
+ * console.log(data.name) // => JP
746
+ */
747
+ export function outputJsonSync(file: string, data: any, options?: JsonOutputOptions): void;
748
+ /**
749
+ * @see outputJsonSync
750
+ */
751
+ export const outputJSONSync: typeof outputJsonSync;
477
752
 
478
- export function writev(
479
- fd: number,
480
- buffers: NodeJS.ArrayBufferView[],
481
- position: number,
482
- cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void,
483
- ): void;
484
- export function writev(
485
- fd: number,
486
- buffers: NodeJS.ArrayBufferView[],
487
- cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void,
488
- ): void;
489
- export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number): Promise<WritevResult>;
753
+ /**
754
+ * Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.
755
+ *
756
+ * @example
757
+ * import * as fs from '../fs-extra'
758
+ *
759
+ * // remove file
760
+ * // With a callback:
761
+ * fs.remove('/tmp/myfile', err => {
762
+ * if (err) return console.error(err)
763
+ * console.log('success!')
764
+ * })
765
+ *
766
+ * fs.remove('/home/jprichardson', err => {
767
+ * if (err) return console.error(err)
768
+ * console.log('success!') // I just deleted my entire HOME directory.
769
+ * })
770
+ *
771
+ * // With Promises:
772
+ * fs.remove('/tmp/myfile')
773
+ * .then(() => {
774
+ * console.log('success!')
775
+ * })
776
+ * .catch(err => {
777
+ * console.error(err)
778
+ * })
779
+ *
780
+ * // With async/await:
781
+ * async function asyncAwait () {
782
+ * try {
783
+ * await fs.remove('/tmp/myfile')
784
+ * console.log('success!')
785
+ * } catch (err) {
786
+ * console.error(err)
787
+ * }
788
+ * }
789
+ *
790
+ * asyncAwait()
791
+ */
792
+ export function remove(dir: string): Promise<void>;
793
+ export function remove(dir: string, callback: fs.NoParamCallback): void;
794
+ /**
795
+ * Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.
796
+ *
797
+ * @example
798
+ * import * as fs from '../fs-extra'
799
+ *
800
+ * // remove file
801
+ * fs.removeSync('/tmp/myfile')
802
+ *
803
+ * fs.removeSync('/home/jprichardson') // I just deleted my entire HOME directory.
804
+ */
805
+ export function removeSync(dir: string): void;
490
806
 
491
807
  /**
492
- * Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
808
+ * Ensures that a directory is empty. Deletes directory contents if the directory is not empty.
809
+ * If the directory does not exist, it is created. The directory itself is not deleted.
810
+ *
811
+ * @example
812
+ * import * as fs from '../fs-extra'
813
+ *
814
+ * // assume this directory has a lot of files and folders
815
+ * // With a callback:
816
+ * fs.emptyDir('/tmp/some/dir', err => {
817
+ * if (err) return console.error(err)
818
+ * console.log('success!')
819
+ * })
820
+ *
821
+ * // With Promises:
822
+ * fs.emptyDir('/tmp/some/dir')
823
+ * .then(() => {
824
+ * console.log('success!')
825
+ * })
826
+ * .catch(err => {
827
+ * console.error(err)
828
+ * })
493
829
  *
494
- * @param callback The created folder path is passed as a string to the callback's second parameter.
830
+ * // With async/await:
831
+ * async function asyncAwait () {
832
+ * try {
833
+ * await fs.emptyDir('/tmp/some/dir')
834
+ * console.log('success!')
835
+ * } catch (err) {
836
+ * console.error(err)
837
+ * }
838
+ * }
839
+ *
840
+ * asyncAwait()
841
+ */
842
+ export function emptyDir(path: string): Promise<void>;
843
+ export function emptyDir(path: string, callback: fs.NoParamCallback): void;
844
+ /**
845
+ * @see emptyDir
846
+ */
847
+ export const emptydir: typeof emptyDir;
848
+ /**
849
+ * Ensures that a directory is empty. Deletes directory contents if the directory is not empty.
850
+ * If the directory does not exist, it is created. The directory itself is not deleted.
851
+ *
852
+ * @example
853
+ * import * as fs from '../fs-extra'
854
+ *
855
+ * // assume this directory has a lot of files and folders
856
+ * fs.emptyDirSync('/tmp/some/dir')
857
+ */
858
+ export function emptyDirSync(path: string): void;
859
+ /**
860
+ * @see emptyDirSync
495
861
  */
496
- export function mkdtemp(prefix: string): Promise<string>;
497
- export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException, folder: string) => void): void;
862
+ export const emptydirSync: typeof emptyDirSync;
498
863
 
499
- export interface PathEntry {
500
- path: string;
501
- stats: Stats;
502
- }
864
+ /**
865
+ * Test whether or not the given path exists by checking with the file system. Like
866
+ * [`fs.exists`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback), but with a normal
867
+ * callback signature (err, exists). Uses `fs.access` under the hood.
868
+ *
869
+ * @example
870
+ * import * as fs from '../fs-extra'
871
+ *
872
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
873
+ *
874
+ * // With a callback:
875
+ * fs.pathExists(file, (err, exists) => {
876
+ * console.log(err) // => null
877
+ * console.log(exists) // => false
878
+ * })
879
+ *
880
+ * // Promise usage:
881
+ * fs.pathExists(file)
882
+ * .then(exists => console.log(exists)) // => false
883
+ *
884
+ * // With async/await:
885
+ * async function asyncAwait () {
886
+ * const exists = await fs.pathExists(file)
887
+ *
888
+ * console.log(exists) // => false
889
+ * }
890
+ *
891
+ * asyncAwait()
892
+ */
893
+ export function pathExists(path: string): Promise<boolean>;
894
+ export function pathExists(path: string, callback: (err: NodeJS.ErrnoException | null, exists: boolean) => void): void;
895
+ /**
896
+ * An alias for [`fs.existsSync`](https://nodejs.org/api/fs.html#fs_fs_existssync_path), created for
897
+ * consistency with `pathExists`.
898
+ */
899
+ export function pathExistsSync(path: string): boolean;
503
900
 
504
- export interface PathEntryStream {
505
- read(): PathEntry | null;
506
- }
901
+ export const access: typeof fs.access.__promisify__ & typeof fs.access;
902
+ export const appendFile: typeof fs.appendFile.__promisify__ & typeof fs.appendFile;
903
+ export const chmod: typeof fs.chmod.__promisify__ & typeof fs.chmod;
904
+ export const chown: typeof fs.chown.__promisify__ & typeof fs.chown;
905
+ export const close: typeof fs.close.__promisify__ & typeof fs.close;
906
+ export const copyFile: typeof fs.copyFile.__promisify__ & typeof fs.copyFile;
907
+ export const exists: typeof fs.exists.__promisify__ & typeof fs.exists;
908
+ export const fchmod: typeof fs.fchmod.__promisify__ & typeof fs.fchmod;
909
+ export const fchown: typeof fs.fchown.__promisify__ & typeof fs.fchown;
910
+ export const fdatasync: typeof fs.fdatasync.__promisify__ & typeof fs.fdatasync;
911
+ export const fstat: typeof fs.fstat.__promisify__ & typeof fs.fstat;
912
+ export const fsync: typeof fs.fsync.__promisify__ & typeof fs.fsync;
913
+ export const ftruncate: typeof fs.ftruncate.__promisify__ & typeof fs.ftruncate;
914
+ export const futimes: typeof fs.futimes.__promisify__ & typeof fs.futimes;
915
+ export const lchmod: typeof fs.lchmod.__promisify__ & typeof fs.lchmod;
916
+ export const lchown: typeof fs.lchown.__promisify__ & typeof fs.lchown;
917
+ export const link: typeof fs.link.__promisify__ & typeof fs.link;
918
+ export const lstat: typeof fs.lstat.__promisify__ & typeof fs.lstat;
919
+ export const mkdir: typeof fs.mkdir.__promisify__ & typeof fs.mkdir;
920
+ export const mkdtemp: typeof fs.mkdtemp.__promisify__ & typeof fs.mkdtemp;
921
+ export const open: typeof fs.open.__promisify__ & typeof fs.open;
922
+ export const opendir: typeof fs.opendir.__promisify__ & typeof fs.opendir;
923
+ export const read: typeof fs.read.__promisify__ & typeof fs.read;
924
+ export const readv: typeof fs.readv.__promisify__ & typeof fs.readv;
925
+ export const readdir: typeof fs.readdir.__promisify__ & typeof fs.readdir;
926
+ export const readFile: typeof fs.readFile.__promisify__ & typeof fs.readFile;
927
+ export const readlink: typeof fs.readlink.__promisify__ & typeof fs.readlink;
928
+ export const realpath: typeof fs.realpath.__promisify__ &
929
+ typeof fs.realpath & {
930
+ native(path: fs.PathLike, options?: fs.EncodingOption): Promise<string>;
931
+ native(path: fs.PathLike, options: fs.BufferEncodingOption): Promise<Buffer>;
932
+ };
933
+ export const rename: typeof fs.rename.__promisify__ & typeof fs.rename;
934
+ export const rm: typeof fs.rm.__promisify__ & typeof fs.rm;
935
+ export const rmdir: typeof fs.rmdir.__promisify__ & typeof fs.rmdir;
936
+ export const stat: typeof fs.stat.__promisify__ & typeof fs.stat;
937
+ export const symlink: typeof fs.symlink.__promisify__ & typeof fs.symlink;
938
+ export const truncate: typeof fs.truncate.__promisify__ & typeof fs.truncate;
939
+ export const unlink: typeof fs.unlink.__promisify__ & typeof fs.unlink;
940
+ export const utimes: typeof fs.utimes.__promisify__ & typeof fs.utimes;
941
+ export const write: typeof fs.write.__promisify__ & typeof fs.write;
942
+ export const writev: typeof fs.writev.__promisify__ & typeof fs.writev;
943
+ export const writeFile: typeof fs.writeFile.__promisify__ & typeof fs.writeFile;
944
+
945
+ export type NoParamCallbackWithUndefined = (err: NodeJS.ErrnoException | null | undefined) => void;
946
+
947
+ export type SymlinkType = fs.symlink.Type;
507
948
 
508
949
  export type CopyFilterSync = (src: string, dest: string) => boolean;
509
950
  export type CopyFilterAsync = (src: string, dest: string) => Promise<boolean>;
510
951
 
511
- export type SymlinkType = 'dir' | 'file' | 'junction';
512
-
513
- export type Mode = string | number;
514
-
515
- export type ArrayBufferView = NodeJS.TypedArray | DataView;
516
-
517
952
  export interface CopyOptions {
953
+ /**
954
+ * Dereference symlinks.
955
+ * @default false
956
+ */
518
957
  dereference?: boolean | undefined;
958
+ /**
959
+ * Overwrite existing file or directory.
960
+ * _Note that the copy operation will silently fail if you set this to `false` and the destination exists._
961
+ * Use the `errorOnExist` option to change this behavior.
962
+ * @default true
963
+ */
519
964
  overwrite?: boolean | undefined;
965
+ /**
966
+ * When `true`, will set last modification and access times to the ones of the original source files.
967
+ * When `false`, timestamp behavior is OS-dependent.
968
+ * @default false
969
+ */
520
970
  preserveTimestamps?: boolean | undefined;
971
+ /**
972
+ * When `overwrite` is `false` and the destination exists, throw an error.
973
+ * @default false
974
+ */
521
975
  errorOnExist?: boolean | undefined;
976
+ /**
977
+ * Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it.
978
+ * Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function).
979
+ */
522
980
  filter?: CopyFilterSync | CopyFilterAsync | undefined;
523
- recursive?: boolean | undefined;
524
981
  }
525
982
 
526
983
  export interface CopyOptionsSync extends CopyOptions {
984
+ /**
985
+ * Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it.
986
+ */
527
987
  filter?: CopyFilterSync | undefined;
528
988
  }
529
989
 
530
- export interface EnsureOptions {
990
+ export interface EnsureDirOptions {
531
991
  mode?: number | undefined;
532
992
  }
533
993
 
534
994
  export interface MoveOptions {
995
+ /**
996
+ * Overwrite existing file or directory.
997
+ * @default false
998
+ */
535
999
  overwrite?: boolean | undefined;
536
- limit?: number | undefined;
537
- }
538
-
539
- export interface ReadOptions {
540
- throws?: boolean | undefined;
541
- fs?: object | undefined;
542
- reviver?: any;
543
- encoding?: BufferEncoding | string | undefined;
544
- flag?: string | undefined;
545
- }
546
-
547
- export interface WriteFileOptions {
548
- encoding?: BufferEncoding | string | null | undefined;
549
- flag?: string | undefined;
550
- mode?: number | undefined;
1000
+ /**
1001
+ * Dereference symlinks.
1002
+ * @default false
1003
+ */
1004
+ dereference?: boolean | undefined;
551
1005
  }
552
1006
 
553
- export interface WriteOptions extends WriteFileOptions {
554
- fs?: object | undefined;
555
- replacer?: any;
556
- spaces?: number | string | undefined;
557
- EOL?: string | undefined;
558
- }
1007
+ export { JFReadOptions as JsonReadOptions, JFWriteOptions as JsonWriteOptions } from 'jsonfile';
559
1008
 
560
- export interface WritevResult {
561
- bytesWritten: number;
562
- buffers: ArrayBufferView[];
563
- }
1009
+ export type JsonOutputOptions = fs.WriteFileOptions & StringifyOptions;