@umijs/utils 4.0.0-beta.8 → 4.0.0-canary-20240513.3

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 (197) hide show
  1. package/compiled/@ampproject/remapping/@jridgewell/gen-mapping/dist/types/gen-mapping.d.ts +70 -0
  2. package/compiled/@ampproject/remapping/@jridgewell/gen-mapping/dist/types/sourcemap-segment.d.ts +12 -0
  3. package/compiled/@ampproject/remapping/@jridgewell/gen-mapping/dist/types/types.d.ts +35 -0
  4. package/compiled/@ampproject/remapping/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
  5. package/compiled/@ampproject/remapping/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
  6. package/compiled/@ampproject/remapping/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
  7. package/compiled/@ampproject/remapping/LICENSE +202 -0
  8. package/compiled/@ampproject/remapping/dist/types/remapping.d.ts +19 -0
  9. package/compiled/@ampproject/remapping/dist/types/source-map.d.ts +17 -0
  10. package/compiled/@ampproject/remapping/dist/types/types.d.ts +14 -0
  11. package/compiled/@ampproject/remapping/index.js +1 -0
  12. package/compiled/@ampproject/remapping/package.json +1 -0
  13. package/compiled/@clack/prompts/LICENSE +23 -0
  14. package/compiled/@clack/prompts/dist/index.d.ts +38 -0
  15. package/compiled/@clack/prompts/index.js +1 -0
  16. package/compiled/@clack/prompts/package.json +1 -0
  17. package/compiled/@hapi/joi/index.d.ts +2218 -0
  18. package/compiled/@hapi/joi/index.js +1 -0
  19. package/compiled/@hapi/joi/package.json +1 -0
  20. package/compiled/axios/index.d.ts +29 -14
  21. package/compiled/axios/index.js +1 -1
  22. package/compiled/chalk/LICENSE +1 -1
  23. package/compiled/chalk/index.js +1 -1
  24. package/compiled/chalk/package.json +1 -1
  25. package/compiled/chalk/source/index.d.ts +318 -0
  26. package/compiled/chalk/source/vendor/supports-color/index.d.ts +55 -0
  27. package/compiled/color/color-convert/conversions.d.ts +87 -87
  28. package/compiled/color/color-convert/index.d.ts +75 -60
  29. package/compiled/color/color-convert/route.d.ts +271 -271
  30. package/compiled/color/index.d.ts +118 -121
  31. package/compiled/color/index.js +1 -1
  32. package/compiled/color/package.json +1 -4
  33. package/compiled/debug/LICENSE +10 -9
  34. package/compiled/debug/index.js +1 -1
  35. package/compiled/debug/package.json +1 -1
  36. package/compiled/execa/index.d.ts +467 -445
  37. package/compiled/execa/index.js +1 -1
  38. package/compiled/fastest-levenshtein/index.js +1 -0
  39. package/compiled/fastest-levenshtein/mod.d.ts +3 -0
  40. package/compiled/fastest-levenshtein/package.json +1 -0
  41. package/compiled/filesize/LICENSE +28 -0
  42. package/compiled/filesize/filesize.d.ts +131 -0
  43. package/compiled/filesize/index.js +8 -0
  44. package/compiled/filesize/package.json +1 -0
  45. package/compiled/filesize/types/filesize.d.ts +46 -0
  46. package/compiled/fs-extra/index.d.ts +930 -253
  47. package/compiled/fs-extra/index.js +1 -1
  48. package/compiled/fs-extra/jsonfile/index.d.ts +78 -0
  49. package/compiled/fs-extra/package.json +1 -1
  50. package/compiled/glob/LICENSE +1 -7
  51. package/compiled/glob/index.d.ts +3 -1
  52. package/compiled/glob/index.js +1 -1
  53. package/compiled/glob/package.json +1 -1
  54. package/compiled/gzip-size/LICENSE +9 -0
  55. package/compiled/gzip-size/index.d.ts +103 -0
  56. package/compiled/gzip-size/index.js +1 -0
  57. package/compiled/gzip-size/package.json +1 -0
  58. package/compiled/lodash/common/array.d.ts +0 -0
  59. package/compiled/lodash/common/collection.d.ts +0 -0
  60. package/compiled/lodash/common/common.d.ts +0 -0
  61. package/compiled/lodash/common/date.d.ts +0 -0
  62. package/compiled/lodash/common/function.d.ts +0 -0
  63. package/compiled/lodash/common/lang.d.ts +0 -0
  64. package/compiled/lodash/common/math.d.ts +0 -0
  65. package/compiled/lodash/common/number.d.ts +0 -0
  66. package/compiled/lodash/common/object.d.ts +0 -0
  67. package/compiled/lodash/common/seq.d.ts +0 -0
  68. package/compiled/lodash/common/string.d.ts +0 -0
  69. package/compiled/lodash/common/util.d.ts +0 -0
  70. package/compiled/magic-string/LICENSE +7 -0
  71. package/compiled/magic-string/index.d.ts +250 -0
  72. package/compiled/magic-string/index.js +1 -0
  73. package/compiled/magic-string/package.json +1 -0
  74. package/compiled/pirates/LICENSE +21 -0
  75. package/compiled/pirates/index.d.ts +82 -0
  76. package/compiled/pirates/index.js +1 -0
  77. package/compiled/pirates/package.json +1 -0
  78. package/compiled/pkg-up/LICENSE +1 -1
  79. package/compiled/pkg-up/index.d.ts +55 -44
  80. package/compiled/pkg-up/index.js +1 -1
  81. package/compiled/pkg-up/package.json +1 -1
  82. package/compiled/portfinder/index.js +1 -1
  83. package/compiled/portfinder/lib/portfinder.d.ts +16 -1
  84. package/compiled/portfinder/package.json +1 -1
  85. package/compiled/prettier/index.d.ts +568 -679
  86. package/compiled/prettier/index.js +62 -274
  87. package/compiled/prettier/package.json +1 -5
  88. package/compiled/resolve/index.js +1 -1
  89. package/compiled/semver/classes/range.d.ts +1 -1
  90. package/compiled/semver/classes/semver.d.ts +1 -1
  91. package/compiled/semver/functions/compare-build.d.ts +6 -1
  92. package/compiled/semver/functions/diff.d.ts +1 -5
  93. package/compiled/semver/functions/satisfies.d.ts +1 -1
  94. package/compiled/semver/index.d.ts +3 -0
  95. package/compiled/semver/index.js +1 -1
  96. package/compiled/semver/package.json +1 -1
  97. package/compiled/semver/ranges/gtr.d.ts +1 -1
  98. package/compiled/semver/ranges/intersects.d.ts +1 -1
  99. package/compiled/semver/ranges/ltr.d.ts +1 -1
  100. package/compiled/semver/ranges/max-satisfying.d.ts +1 -1
  101. package/compiled/semver/ranges/min-satisfying.d.ts +1 -1
  102. package/compiled/semver/ranges/outside.d.ts +1 -1
  103. package/compiled/semver/ranges/subset.d.ts +1 -5
  104. package/compiled/semver/ranges/valid.d.ts +1 -1
  105. package/compiled/strip-ansi/LICENSE +1 -1
  106. package/compiled/strip-ansi/index.d.ts +2 -4
  107. package/compiled/strip-ansi/index.js +1 -1
  108. package/compiled/strip-ansi/package.json +1 -1
  109. package/compiled/tar/LICENSE +15 -0
  110. package/compiled/tar/index.d.ts +943 -0
  111. package/compiled/tar/index.js +1 -0
  112. package/compiled/tar/minipass/index.d.ts +150 -0
  113. package/compiled/tar/package.json +1 -0
  114. package/compiled/tsconfig-paths/LICENSE +21 -0
  115. package/compiled/tsconfig-paths/index.js +1 -0
  116. package/compiled/tsconfig-paths/lib/index.d.ts +5 -0
  117. package/compiled/tsconfig-paths/package.json +1 -0
  118. package/compiled/yargs-parser/index.js +1 -1
  119. package/compiled/yargs-parser/package.json +1 -1
  120. package/compiled/zod/LICENSE +21 -0
  121. package/compiled/zod/index.d.ts +2 -0
  122. package/compiled/zod/index.js +1 -0
  123. package/compiled/zod/lib/ZodError.d.ts +159 -0
  124. package/compiled/zod/lib/__tests__/Mocker.d.ts +17 -0
  125. package/compiled/zod/lib/benchmarks/discriminatedUnion.d.ts +5 -0
  126. package/compiled/zod/lib/benchmarks/index.d.ts +1 -0
  127. package/compiled/zod/lib/benchmarks/object.d.ts +5 -0
  128. package/compiled/zod/lib/benchmarks/primitives.d.ts +5 -0
  129. package/compiled/zod/lib/benchmarks/realworld.d.ts +5 -0
  130. package/compiled/zod/lib/benchmarks/string.d.ts +5 -0
  131. package/compiled/zod/lib/benchmarks/union.d.ts +5 -0
  132. package/compiled/zod/lib/errors.d.ts +5 -0
  133. package/compiled/zod/lib/external.d.ts +6 -0
  134. package/compiled/zod/lib/helpers/enumUtil.d.ts +8 -0
  135. package/compiled/zod/lib/helpers/errorUtil.d.ts +9 -0
  136. package/compiled/zod/lib/helpers/parseUtil.d.ts +78 -0
  137. package/compiled/zod/lib/helpers/partialUtil.d.ts +8 -0
  138. package/compiled/zod/lib/helpers/typeAliases.d.ts +2 -0
  139. package/compiled/zod/lib/helpers/util.d.ts +47 -0
  140. package/compiled/zod/lib/index.d.ts +4 -0
  141. package/compiled/zod/lib/locales/en.d.ts +3 -0
  142. package/compiled/zod/lib/types.d.ts +975 -0
  143. package/compiled/zod/package.json +1 -0
  144. package/dist/BaseGenerator/BaseGenerator.d.ts +3 -3
  145. package/dist/BaseGenerator/BaseGenerator.js +78 -54
  146. package/dist/BaseGenerator/generateFile.d.ts +2 -1
  147. package/dist/BaseGenerator/generateFile.js +49 -22
  148. package/dist/Generator/Generator.d.ts +18 -14
  149. package/dist/Generator/Generator.js +97 -70
  150. package/dist/aliasUtils/getAliasValue.d.ts +4 -0
  151. package/dist/aliasUtils/getAliasValue.js +66 -0
  152. package/dist/aliasUtils/index.d.ts +2 -0
  153. package/dist/aliasUtils/index.js +32 -0
  154. package/dist/aliasUtils/parseCircleAlias.d.ts +4 -0
  155. package/dist/aliasUtils/parseCircleAlias.js +66 -0
  156. package/dist/getCorejsVersion.d.ts +1 -0
  157. package/dist/getCorejsVersion.js +35 -0
  158. package/dist/getDevBanner.d.ts +5 -0
  159. package/dist/getDevBanner.js +81 -0
  160. package/dist/getFileGitIno.d.ts +47 -0
  161. package/dist/getFileGitIno.js +130 -0
  162. package/dist/getGitInfo.d.ts +6 -0
  163. package/dist/getGitInfo.js +50 -0
  164. package/dist/importLazy.js +42 -14
  165. package/dist/index.d.ts +26 -3
  166. package/dist/index.js +185 -86
  167. package/dist/installDeps.js +69 -37
  168. package/dist/isJavaScriptFile.d.ts +1 -0
  169. package/dist/isJavaScriptFile.js +32 -0
  170. package/dist/isLocalDev.d.ts +4 -0
  171. package/dist/isLocalDev.js +36 -0
  172. package/dist/isMonorepo.d.ts +5 -0
  173. package/dist/isMonorepo.js +44 -0
  174. package/dist/isStyleFile.d.ts +5 -0
  175. package/dist/isStyleFile.js +44 -0
  176. package/dist/logger.d.ts +13 -6
  177. package/dist/logger.js +166 -25
  178. package/dist/node.d.ts +4 -0
  179. package/dist/node.js +61 -0
  180. package/dist/npmClient.d.ts +3 -2
  181. package/dist/npmClient.js +86 -40
  182. package/dist/printHelp.d.ts +2 -0
  183. package/dist/printHelp.js +64 -0
  184. package/dist/randomColor/randomColor.js +47 -16
  185. package/dist/readDirFiles.d.ts +9 -0
  186. package/dist/readDirFiles.js +62 -0
  187. package/dist/register.d.ts +1 -0
  188. package/dist/register.js +75 -37
  189. package/dist/setNoDeprecation.d.ts +1 -0
  190. package/dist/setNoDeprecation.js +31 -0
  191. package/dist/tryPaths.d.ts +1 -0
  192. package/dist/tryPaths.js +35 -0
  193. package/dist/updatePackageJSON.js +50 -19
  194. package/dist/winPath.js +33 -9
  195. package/dist/zod/isZodSchema.d.ts +2 -0
  196. package/dist/zod/isZodSchema.js +31 -0
  197. package/package.json +70 -44
@@ -1,4 +1,4 @@
1
- // Type definitions for fs-extra 8.1
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>,
@@ -8,325 +8,1002 @@
8
8
  // Sang Dang <https://github.com/sangdth>,
9
9
  // Florian Keller <https://github.com/ffflorian>
10
10
  // Piotr Błażejewicz <https://github.com/peterblazejewicz>
11
+ // Tiger Oakes <https://github.com/NotWoods>
12
+ // BendingBender <https://github.com/BendingBender>
11
13
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
12
- // TypeScript Version: 2.2
14
+ // Minimum TypeScript Version: 4.5
13
15
 
14
16
  /// <reference types="node" />
15
17
 
16
18
  import * as fs from 'fs';
17
- import Stats = fs.Stats;
19
+ import * as jsonfile from './jsonfile';
20
+ import { StringifyOptions } from './jsonfile/utils';
18
21
 
19
- export * from "fs";
22
+ export * from 'fs';
20
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
+ */
21
83
  export function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
22
- export function copy(src: string, dest: string, callback: (err: Error) => void): void;
23
- 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
+ */
24
111
  export function copySync(src: string, dest: string, options?: CopyOptionsSync): void;
25
112
 
26
- export function copyFile(src: string, dest: string, flags?: number): Promise<void>;
27
- export function copyFile(src: string, dest: string, callback: (err: Error) => void): void;
28
- export function copyFile(src: string, dest: string, flags: number, callback: (err: Error) => void): void;
29
-
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
+ */
30
157
  export function move(src: string, dest: string, options?: MoveOptions): Promise<void>;
31
- export function move(src: string, dest: string, callback: (err: Error) => void): void;
32
- 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
+ */
33
173
  export function moveSync(src: string, dest: string, options?: MoveOptions): void;
34
174
 
35
- export function createFile(file: string): Promise<void>;
36
- export function createFile(file: string, callback: (err: Error) => void): void;
37
- export function createFileSync(file: string): void;
38
-
39
- export function createSymlink(src: string, dest: string, type: SymlinkType): Promise<void>;
40
- export function createSymlink(src: string, dest: string, type: SymlinkType, callback?: (err: Error) => void): void;
41
- export function createSymlinkSync(src: string, dest: string, type: SymlinkType): void;
42
-
43
- export function ensureDir(path: string, options?: EnsureOptions | number): Promise<void>;
44
- export function ensureDir(path: string, options?: EnsureOptions | number, callback?: (err: Error) => void): void;
45
- export function ensureDirSync(path: string, options?: EnsureOptions | number): void;
46
-
47
- export function mkdirs(dir: string): Promise<void>;
48
- export function mkdirs(dir: string, callback: (err: Error) => void): void;
49
- export function mkdirp(dir: string): Promise<void>;
50
- export function mkdirp(dir: string, callback: (err: Error) => void): void;
51
- export function mkdirsSync(dir: string): void;
52
- export function mkdirpSync(dir: string): void;
53
-
54
- export function outputFile(file: string, data: any, options?: WriteFileOptions | string): Promise<void>;
55
- export function outputFile(file: string, data: any, callback: (err: Error) => void): void;
56
- export function outputFile(file: string, data: any, options: WriteFileOptions | string, callback: (err: Error) => void): void;
57
- export function outputFileSync(file: string, data: any, options?: WriteFileOptions | string): void;
58
-
59
- export function readJson(file: string, options?: ReadOptions): Promise<any>;
60
- export function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void;
61
- export function readJson(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void;
62
- export function readJSON(file: string, options?: ReadOptions): Promise<any>;
63
- export function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void;
64
- export function readJSON(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void;
65
-
66
- export function readJsonSync(file: string, options?: ReadOptions): any;
67
- export function readJSONSync(file: string, options?: ReadOptions): any;
68
-
69
- export function remove(dir: string): Promise<void>;
70
- export function remove(dir: string, callback: (err: Error) => void): void;
71
- export function removeSync(dir: string): void;
72
-
73
- export function outputJSON(file: string, data: any, options?: WriteOptions): Promise<void>;
74
- export function outputJSON(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void;
75
- export function outputJSON(file: string, data: any, callback: (err: Error) => void): void;
76
- export function outputJson(file: string, data: any, options?: WriteOptions): Promise<void>;
77
- export function outputJson(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void;
78
- export function outputJson(file: string, data: any, callback: (err: Error) => void): void;
79
- export function outputJsonSync(file: string, data: any, options?: WriteOptions): void;
80
- export function outputJSONSync(file: string, data: any, options?: WriteOptions): void;
81
-
82
- export function writeJSON(file: string, object: any, options?: WriteOptions): Promise<void>;
83
- export function writeJSON(file: string, object: any, callback: (err: Error) => void): void;
84
- export function writeJSON(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void;
85
- export function writeJson(file: string, object: any, options?: WriteOptions): Promise<void>;
86
- export function writeJson(file: string, object: any, callback: (err: Error) => void): void;
87
- export function writeJson(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void;
88
-
89
- export function writeJsonSync(file: string, object: any, options?: WriteOptions): void;
90
- export function writeJSONSync(file: string, object: any, options?: WriteOptions): void;
91
-
92
- export function ensureFile(path: string): Promise<void>;
93
- export function ensureFile(path: string, callback: (err: Error) => void): void;
94
- 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;
95
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
+ */
96
272
  export function ensureLink(src: string, dest: string): Promise<void>;
97
- export function ensureLink(src: string, dest: string, callback: (err: Error) => void): void;
273
+ export function ensureLink(src: string, dest: string, callback: fs.NoParamCallback): void;
274
+ /**
275
+ * @see ensureLink
276
+ */
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
+ */
98
289
  export function ensureLinkSync(src: string, dest: string): void;
290
+ /**
291
+ * @see ensureLinkSync
292
+ */
293
+ export const createLinkSync: typeof ensureLinkSync;
99
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
+ */
100
333
  export function ensureSymlink(src: string, dest: string, type?: SymlinkType): Promise<void>;
101
- export function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: (err: Error) => void): void;
102
- 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
+ */
103
353
  export function ensureSymlinkSync(src: string, dest: string, type?: SymlinkType): void;
104
-
105
- export function emptyDir(path: string): Promise<void>;
106
- export function emptyDir(path: string, callback: (err: Error) => void): void;
107
- export function emptyDirSync(path: string): void;
108
-
109
- export function pathExists(path: string): Promise<boolean>;
110
- export function pathExists(path: string, callback: (err: Error, exists: boolean) => void): void;
111
- export function pathExistsSync(path: string): boolean;
112
-
113
- // fs async methods
114
- // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v6/index.d.ts
115
-
116
- export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
117
- export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException) => void): void;
118
- export function access(path: string | Buffer, mode?: number): Promise<void>;
119
-
120
- export function appendFile(file: string | Buffer | number, data: any, options: { encoding?: string | undefined; mode?: number | string | undefined; flag?: string | undefined; },
121
- callback: (err: NodeJS.ErrnoException) => void): void;
122
- export function appendFile(file: string | Buffer | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
123
- export function appendFile(file: string | Buffer | number, data: any, options?: { encoding?: string | undefined; mode?: number | string | undefined; flag?: string | undefined; }): Promise<void>;
124
-
125
- export function chmod(path: string | Buffer, mode: string | number, callback: (err: NodeJS.ErrnoException) => void): void;
126
- export function chmod(path: string | Buffer, mode: string | number): Promise<void>;
127
-
128
- export function chown(path: string | Buffer, uid: number, gid: number): Promise<void>;
129
- export function chown(path: string | Buffer, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
130
-
131
- export function close(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
132
- export function close(fd: number): Promise<void>;
133
-
134
- export function fchmod(fd: number, mode: string | number, callback: (err: NodeJS.ErrnoException) => void): void;
135
- export function fchmod(fd: number, mode: string | number): Promise<void>;
136
-
137
- export function fchown(fd: number, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
138
- export function fchown(fd: number, uid: number, gid: number): Promise<void>;
139
-
140
- export function fdatasync(fd: number, callback: () => void): void;
141
- export function fdatasync(fd: number): Promise<void>;
142
-
143
- export function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
144
- export function fstat(fd: number): Promise<Stats>;
145
-
146
- export function fsync(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
147
- export function fsync(fd: number): Promise<void>;
148
-
149
- export function ftruncate(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
150
- export function ftruncate(fd: number, len: number, callback: (err: NodeJS.ErrnoException) => void): void;
151
- export function ftruncate(fd: number, len?: number): Promise<void>;
152
-
153
- export function futimes(fd: number, atime: number, mtime: number, callback: (err: NodeJS.ErrnoException) => void): void;
154
- export function futimes(fd: number, atime: Date, mtime: Date, callback: (err: NodeJS.ErrnoException) => void): void;
155
- export function futimes(fd: number, atime: number, mtime: number): Promise<void>;
156
- export function futimes(fd: number, atime: Date, mtime: Date): Promise<void>;
157
-
158
- export function lchown(path: string | Buffer, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
159
- export function lchown(path: string | Buffer, uid: number, gid: number): Promise<void>;
160
-
161
- export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
162
- export function link(srcpath: string | Buffer, dstpath: string | Buffer): Promise<void>;
163
-
164
- export function lstat(path: string | Buffer, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
165
- export function lstat(path: string | Buffer): Promise<Stats>;
354
+ /**
355
+ * @see ensureSymlinkSync
356
+ */
357
+ export const createSymlinkSync: typeof ensureSymlinkSync;
166
358
 
167
359
  /**
168
- * 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.
169
361
  *
170
- * @param callback No arguments other than a possible exception are given to the completion callback.
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
+ * })
382
+ *
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()
171
422
  */
172
- export function mkdir(path: string | Buffer, 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;
173
426
  /**
174
- * 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'
175
432
  *
176
- * @param callback No arguments other than a possible exception are given to the completion callback.
433
+ * const dir = '/tmp/this/path/does/not/exist'
434
+ *
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
177
448
  */
178
- export function mkdir(path: string | Buffer, mode: number | string, callback: (err: NodeJS.ErrnoException) => void): void;
179
- export function mkdir(path: string | Buffer): Promise<void>;
449
+ export function ensureDirSync(path: string, options?: EnsureDirOptions | number): void;
180
450
 
181
- export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
182
- export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
183
- export function open(path: string | Buffer, flags: string | number, mode?: number): Promise<number>;
451
+ /**
452
+ * @see ensureDir
453
+ */
454
+ export const mkdirs: typeof ensureDir;
455
+ /**
456
+ * @see ensureDirSync
457
+ */
458
+ export const mkdirsSync: typeof ensureDirSync;
184
459
 
185
- export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null,
186
- callback: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void;
187
- export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null): Promise<ReadResult>;
460
+ /**
461
+ * @see ensureDir
462
+ */
463
+ export const mkdirp: typeof ensureDir;
464
+ /**
465
+ * @see ensureDirSync
466
+ */
467
+ export const mkdirpSync: typeof ensureDirSync;
188
468
 
189
- export function readFile(file: string | Buffer | number, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
190
- export function readFile(file: string | Buffer | number, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
191
- export function readFile(
192
- file: string | Buffer | number,
193
- options: { flag?: string | undefined; } | { encoding: string; flag?: string | undefined; },
194
- callback: (err: NodeJS.ErrnoException, data: Buffer) => void
469
+ /**
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'
477
+ *
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()
512
+ */
513
+ export function outputFile(
514
+ file: string,
515
+ data: string | NodeJS.ArrayBufferView,
516
+ options?: fs.WriteFileOptions,
517
+ ): Promise<void>;
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,
195
524
  ): void;
196
- export function readFile(file: string | Buffer | number, options: { flag?: string | undefined; } | { encoding: string; flag?: string | undefined; }): Promise<string>;
197
- // tslint:disable-next-line:unified-signatures
198
- export function readFile(file: string | Buffer | number, encoding: string): Promise<string>;
199
- export function readFile(file: string | Buffer | number): Promise<Buffer>;
200
-
201
- export function readdir(path: string | Buffer, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void;
202
- export function readdir(path: string | Buffer): Promise<string[]>;
203
-
204
- export function readlink(path: string | Buffer, callback: (err: NodeJS.ErrnoException, linkString: string) => any): void;
205
- export function readlink(path: string | Buffer): Promise<string>;
206
-
207
- export function realpath(path: string | Buffer, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
208
- export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
209
- export function realpath(path: string | Buffer, cache?: { [path: string]: string }): Promise<string>;
210
-
211
- export function rename(oldPath: string, newPath: string, callback: (err: NodeJS.ErrnoException) => void): void;
212
- export function rename(oldPath: string, newPath: string): Promise<void>;
213
-
214
525
  /**
215
- * 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'
531
+ *
532
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
533
+ * fs.outputFileSync(file, 'hello!')
216
534
  *
217
- * @param callback No arguments other than a possible exception are given to the completion callback.
535
+ * const data = fs.readFileSync(file, 'utf8')
536
+ * console.log(data) // => hello!
218
537
  */
219
- export function rmdir(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
220
- export function rmdir(path: string | Buffer): Promise<void>;
221
-
222
- export function stat(path: string | Buffer, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
223
- export function stat(path: string | Buffer): Promise<Stats>;
224
-
225
- export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type: FsSymlinkType | undefined, callback: (err: NodeJS.ErrnoException) => void): void;
226
- export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
227
- export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: FsSymlinkType): Promise<void>;
228
-
229
- export function truncate(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
230
- export function truncate(path: string | Buffer, len: number, callback: (err: NodeJS.ErrnoException) => void): void;
231
- export function truncate(path: string | Buffer, len?: number): Promise<void>;
538
+ export function outputFileSync(
539
+ file: string,
540
+ data: string | NodeJS.ArrayBufferView,
541
+ options?: fs.WriteFileOptions,
542
+ ): void;
232
543
 
233
544
  /**
234
- * 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)
235
623
  *
236
- * @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
237
626
  */
238
- export function unlink(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
239
- export function unlink(path: string | Buffer): Promise<void>;
627
+ export const readJsonSync: typeof jsonfile.readFileSync;
628
+ /**
629
+ * @see readJsonSync
630
+ */
631
+ export const readJSONSync: typeof jsonfile.readFileSync;
240
632
 
241
- export function utimes(path: string | Buffer, atime: number, mtime: number, callback: (err: NodeJS.ErrnoException) => void): void;
242
- export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback: (err: NodeJS.ErrnoException) => void): void;
243
- export function utimes(path: string | Buffer, atime: number, mtime: number): Promise<void>;
244
- export function utimes(path: string | Buffer, atime: Date, mtime: Date): Promise<void>;
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;
245
684
 
246
- export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
247
- export function write(fd: number, buffer: Buffer, offset: number, length: number, callback: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
248
- export function write(fd: number, data: any, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
249
- export function write(fd: number, data: any, offset: number, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
250
- export function write(fd: number, data: any, offset: number, encoding: string, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
251
- export function write(fd: number, buffer: Buffer, offset?: number, length?: number, position?: number | null): Promise<WriteResult>;
252
- export function write(fd: number, data: any, offset?: number, encoding?: string): Promise<WriteResult>;
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;
253
752
 
254
- export function writeFile(file: string | Buffer | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
255
- export function writeFile(file: string | Buffer | number, data: any, options?: WriteFileOptions | string): Promise<void>;
256
- export function writeFile(file: string | Buffer | number, data: any, options: WriteFileOptions | string, callback: (err: NodeJS.ErrnoException) => void): void;
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;
257
806
 
258
807
  /**
259
- * 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
+ * })
260
829
  *
261
- * @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
262
846
  */
263
- export function mkdtemp(prefix: string): Promise<string>;
264
- export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException, folder: string) => void): void;
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
861
+ */
862
+ export const emptydirSync: typeof emptyDirSync;
265
863
 
266
- export interface PathEntry {
267
- path: string;
268
- stats: Stats;
269
- }
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;
270
900
 
271
- export interface PathEntryStream {
272
- read(): PathEntry | null;
273
- }
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;
274
948
 
275
949
  export type CopyFilterSync = (src: string, dest: string) => boolean;
276
950
  export type CopyFilterAsync = (src: string, dest: string) => Promise<boolean>;
277
951
 
278
- export type SymlinkType = "dir" | "file";
279
- export type FsSymlinkType = "dir" | "file" | "junction";
280
-
281
952
  export interface CopyOptions {
953
+ /**
954
+ * Dereference symlinks.
955
+ * @default false
956
+ */
282
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
+ */
283
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
+ */
284
970
  preserveTimestamps?: boolean | undefined;
971
+ /**
972
+ * When `overwrite` is `false` and the destination exists, throw an error.
973
+ * @default false
974
+ */
285
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
+ */
286
980
  filter?: CopyFilterSync | CopyFilterAsync | undefined;
287
- recursive?: boolean | undefined;
288
981
  }
289
982
 
290
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
+ */
291
987
  filter?: CopyFilterSync | undefined;
292
988
  }
293
989
 
294
- export interface EnsureOptions {
990
+ export interface EnsureDirOptions {
295
991
  mode?: number | undefined;
296
992
  }
297
993
 
298
994
  export interface MoveOptions {
995
+ /**
996
+ * Overwrite existing file or directory.
997
+ * @default false
998
+ */
299
999
  overwrite?: boolean | undefined;
300
- limit?: number | undefined;
301
- }
302
-
303
- export interface ReadOptions {
304
- throws?: boolean | undefined;
305
- fs?: object | undefined;
306
- reviver?: any;
307
- encoding?: string | undefined;
308
- flag?: string | undefined;
309
- }
310
-
311
- export interface WriteFileOptions {
312
- encoding?: string | undefined;
313
- flag?: string | undefined;
314
- mode?: number | undefined;
315
- }
316
-
317
- export interface WriteOptions extends WriteFileOptions {
318
- fs?: object | undefined;
319
- replacer?: any;
320
- spaces?: number | string | undefined;
321
- EOL?: string | undefined;
1000
+ /**
1001
+ * Dereference symlinks.
1002
+ * @default false
1003
+ */
1004
+ dereference?: boolean | undefined;
322
1005
  }
323
1006
 
324
- export interface ReadResult {
325
- bytesRead: number;
326
- buffer: Buffer;
327
- }
1007
+ export { JFReadOptions as JsonReadOptions, JFWriteOptions as JsonWriteOptions } from 'jsonfile';
328
1008
 
329
- export interface WriteResult {
330
- bytesWritten: number;
331
- buffer: Buffer;
332
- }
1009
+ export type JsonOutputOptions = fs.WriteFileOptions & StringifyOptions;