@lousy-agents/cli 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/145.js +29 -0
  2. package/dist/145.js.map +1 -0
  3. package/dist/190.js +1765 -0
  4. package/dist/190.js.map +1 -0
  5. package/dist/255.js +1850 -0
  6. package/dist/255.js.map +1 -0
  7. package/dist/31.js +127 -0
  8. package/dist/31.js.map +1 -0
  9. package/dist/399.js +13 -0
  10. package/dist/399.js.map +1 -0
  11. package/dist/610.js +254 -0
  12. package/dist/610.js.map +1 -0
  13. package/dist/651.js +39 -0
  14. package/dist/651.js.map +1 -0
  15. package/dist/659.js +16 -0
  16. package/dist/659.js.map +1 -0
  17. package/dist/709.js +47 -0
  18. package/dist/709.js.map +1 -0
  19. package/dist/835.js +298 -0
  20. package/dist/835.js.map +1 -0
  21. package/dist/index.js +30651 -9
  22. package/dist/index.js.map +1 -1
  23. package/dist/mcp-server.js +46530 -5
  24. package/dist/mcp-server.js.map +1 -1
  25. package/package.json +4 -2
  26. package/dist/commands/copilot-setup.d.ts +0 -5
  27. package/dist/commands/copilot-setup.d.ts.map +0 -1
  28. package/dist/commands/copilot-setup.js +0 -97
  29. package/dist/commands/copilot-setup.js.map +0 -1
  30. package/dist/commands/init.d.ts +0 -13
  31. package/dist/commands/init.d.ts.map +0 -1
  32. package/dist/commands/init.js +0 -109
  33. package/dist/commands/init.js.map +0 -1
  34. package/dist/commands/new.d.ts +0 -21
  35. package/dist/commands/new.d.ts.map +0 -1
  36. package/dist/commands/new.js +0 -94
  37. package/dist/commands/new.js.map +0 -1
  38. package/dist/entities/copilot-agent.d.ts +0 -15
  39. package/dist/entities/copilot-agent.d.ts.map +0 -1
  40. package/dist/entities/copilot-agent.js +0 -53
  41. package/dist/entities/copilot-agent.js.map +0 -1
  42. package/dist/entities/copilot-setup.d.ts +0 -65
  43. package/dist/entities/copilot-setup.d.ts.map +0 -1
  44. package/dist/entities/copilot-setup.js +0 -6
  45. package/dist/entities/copilot-setup.js.map +0 -1
  46. package/dist/entities/index.d.ts +0 -7
  47. package/dist/entities/index.d.ts.map +0 -1
  48. package/dist/entities/index.js +0 -7
  49. package/dist/entities/index.js.map +0 -1
  50. package/dist/entities/skill.d.ts +0 -15
  51. package/dist/entities/skill.d.ts.map +0 -1
  52. package/dist/entities/skill.js +0 -63
  53. package/dist/entities/skill.js.map +0 -1
  54. package/dist/gateways/action-version-gateway.d.ts +0 -39
  55. package/dist/gateways/action-version-gateway.d.ts.map +0 -1
  56. package/dist/gateways/action-version-gateway.js +0 -47
  57. package/dist/gateways/action-version-gateway.js.map +0 -1
  58. package/dist/gateways/agent-file-gateway.d.ts +0 -50
  59. package/dist/gateways/agent-file-gateway.d.ts.map +0 -1
  60. package/dist/gateways/agent-file-gateway.js +0 -34
  61. package/dist/gateways/agent-file-gateway.js.map +0 -1
  62. package/dist/gateways/environment-gateway.d.ts +0 -30
  63. package/dist/gateways/environment-gateway.d.ts.map +0 -1
  64. package/dist/gateways/environment-gateway.js +0 -56
  65. package/dist/gateways/environment-gateway.js.map +0 -1
  66. package/dist/gateways/file-system-utils.d.ts +0 -8
  67. package/dist/gateways/file-system-utils.d.ts.map +0 -1
  68. package/dist/gateways/file-system-utils.js +0 -17
  69. package/dist/gateways/file-system-utils.js.map +0 -1
  70. package/dist/gateways/file-system-workflow-gateway.d.ts +0 -27
  71. package/dist/gateways/file-system-workflow-gateway.d.ts.map +0 -1
  72. package/dist/gateways/file-system-workflow-gateway.js +0 -99
  73. package/dist/gateways/file-system-workflow-gateway.js.map +0 -1
  74. package/dist/gateways/index.d.ts +0 -10
  75. package/dist/gateways/index.d.ts.map +0 -1
  76. package/dist/gateways/index.js +0 -10
  77. package/dist/gateways/index.js.map +0 -1
  78. package/dist/gateways/skill-file-gateway.d.ts +0 -59
  79. package/dist/gateways/skill-file-gateway.d.ts.map +0 -1
  80. package/dist/gateways/skill-file-gateway.js +0 -37
  81. package/dist/gateways/skill-file-gateway.js.map +0 -1
  82. package/dist/gateways/workflow-gateway.d.ts +0 -43
  83. package/dist/gateways/workflow-gateway.d.ts.map +0 -1
  84. package/dist/gateways/workflow-gateway.js +0 -6
  85. package/dist/gateways/workflow-gateway.js.map +0 -1
  86. package/dist/index.d.ts +0 -3
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/lib/config.d.ts +0 -28
  89. package/dist/lib/config.d.ts.map +0 -1
  90. package/dist/lib/config.js +0 -406
  91. package/dist/lib/config.js.map +0 -1
  92. package/dist/lib/copilot-setup-config.d.ts +0 -79
  93. package/dist/lib/copilot-setup-config.d.ts.map +0 -1
  94. package/dist/lib/copilot-setup-config.js +0 -119
  95. package/dist/lib/copilot-setup-config.js.map +0 -1
  96. package/dist/lib/filesystem-structure.d.ts +0 -45
  97. package/dist/lib/filesystem-structure.d.ts.map +0 -1
  98. package/dist/lib/filesystem-structure.js +0 -69
  99. package/dist/lib/filesystem-structure.js.map +0 -1
  100. package/dist/lib/mcp-test-client.d.ts +0 -43
  101. package/dist/lib/mcp-test-client.d.ts.map +0 -1
  102. package/dist/lib/mcp-test-client.js +0 -167
  103. package/dist/lib/mcp-test-client.js.map +0 -1
  104. package/dist/lib/project-name-validation.d.ts +0 -43
  105. package/dist/lib/project-name-validation.d.ts.map +0 -1
  106. package/dist/lib/project-name-validation.js +0 -131
  107. package/dist/lib/project-name-validation.js.map +0 -1
  108. package/dist/mcp/index.d.ts +0 -5
  109. package/dist/mcp/index.d.ts.map +0 -1
  110. package/dist/mcp/index.js +0 -5
  111. package/dist/mcp/index.js.map +0 -1
  112. package/dist/mcp/server.d.ts +0 -15
  113. package/dist/mcp/server.d.ts.map +0 -1
  114. package/dist/mcp/server.js +0 -120
  115. package/dist/mcp/server.js.map +0 -1
  116. package/dist/mcp/tools/analyze-action-versions.d.ts +0 -9
  117. package/dist/mcp/tools/analyze-action-versions.d.ts.map +0 -1
  118. package/dist/mcp/tools/analyze-action-versions.js +0 -81
  119. package/dist/mcp/tools/analyze-action-versions.js.map +0 -1
  120. package/dist/mcp/tools/create-copilot-setup-workflow.d.ts +0 -9
  121. package/dist/mcp/tools/create-copilot-setup-workflow.d.ts.map +0 -1
  122. package/dist/mcp/tools/create-copilot-setup-workflow.js +0 -121
  123. package/dist/mcp/tools/create-copilot-setup-workflow.js.map +0 -1
  124. package/dist/mcp/tools/discover-environment.d.ts +0 -9
  125. package/dist/mcp/tools/discover-environment.d.ts.map +0 -1
  126. package/dist/mcp/tools/discover-environment.js +0 -30
  127. package/dist/mcp/tools/discover-environment.js.map +0 -1
  128. package/dist/mcp/tools/discover-workflow-setup-actions.d.ts +0 -9
  129. package/dist/mcp/tools/discover-workflow-setup-actions.d.ts.map +0 -1
  130. package/dist/mcp/tools/discover-workflow-setup-actions.js +0 -37
  131. package/dist/mcp/tools/discover-workflow-setup-actions.js.map +0 -1
  132. package/dist/mcp/tools/index.d.ts +0 -11
  133. package/dist/mcp/tools/index.d.ts.map +0 -1
  134. package/dist/mcp/tools/index.js +0 -11
  135. package/dist/mcp/tools/index.js.map +0 -1
  136. package/dist/mcp/tools/read-copilot-setup-workflow.d.ts +0 -9
  137. package/dist/mcp/tools/read-copilot-setup-workflow.d.ts.map +0 -1
  138. package/dist/mcp/tools/read-copilot-setup-workflow.js +0 -38
  139. package/dist/mcp/tools/read-copilot-setup-workflow.js.map +0 -1
  140. package/dist/mcp/tools/resolve-action-versions.d.ts +0 -10
  141. package/dist/mcp/tools/resolve-action-versions.d.ts.map +0 -1
  142. package/dist/mcp/tools/resolve-action-versions.js +0 -61
  143. package/dist/mcp/tools/resolve-action-versions.js.map +0 -1
  144. package/dist/mcp/tools/types.d.ts +0 -67
  145. package/dist/mcp/tools/types.d.ts.map +0 -1
  146. package/dist/mcp/tools/types.js +0 -24
  147. package/dist/mcp/tools/types.js.map +0 -1
  148. package/dist/mcp-server.d.ts +0 -7
  149. package/dist/mcp-server.d.ts.map +0 -1
  150. package/dist/use-cases/action-resolution.d.ts +0 -66
  151. package/dist/use-cases/action-resolution.d.ts.map +0 -1
  152. package/dist/use-cases/action-resolution.js +0 -107
  153. package/dist/use-cases/action-resolution.js.map +0 -1
  154. package/dist/use-cases/candidate-builder.d.ts +0 -17
  155. package/dist/use-cases/candidate-builder.d.ts.map +0 -1
  156. package/dist/use-cases/candidate-builder.js +0 -67
  157. package/dist/use-cases/candidate-builder.js.map +0 -1
  158. package/dist/use-cases/copilot-setup.d.ts +0 -8
  159. package/dist/use-cases/copilot-setup.d.ts.map +0 -1
  160. package/dist/use-cases/copilot-setup.js +0 -10
  161. package/dist/use-cases/copilot-setup.js.map +0 -1
  162. package/dist/use-cases/create-copilot-agent.d.ts +0 -29
  163. package/dist/use-cases/create-copilot-agent.d.ts.map +0 -1
  164. package/dist/use-cases/create-copilot-agent.js +0 -73
  165. package/dist/use-cases/create-copilot-agent.js.map +0 -1
  166. package/dist/use-cases/create-skill.d.ts +0 -30
  167. package/dist/use-cases/create-skill.d.ts.map +0 -1
  168. package/dist/use-cases/create-skill.js +0 -75
  169. package/dist/use-cases/create-skill.js.map +0 -1
  170. package/dist/use-cases/index.d.ts +0 -10
  171. package/dist/use-cases/index.d.ts.map +0 -1
  172. package/dist/use-cases/index.js +0 -10
  173. package/dist/use-cases/index.js.map +0 -1
  174. package/dist/use-cases/setup-step-discovery.d.ts +0 -87
  175. package/dist/use-cases/setup-step-discovery.d.ts.map +0 -1
  176. package/dist/use-cases/setup-step-discovery.js +0 -202
  177. package/dist/use-cases/setup-step-discovery.js.map +0 -1
  178. package/dist/use-cases/workflow-generator.d.ts +0 -34
  179. package/dist/use-cases/workflow-generator.d.ts.map +0 -1
  180. package/dist/use-cases/workflow-generator.js +0 -195
  181. package/dist/use-cases/workflow-generator.js.map +0 -1
package/dist/190.js ADDED
@@ -0,0 +1,1765 @@
1
+ export const __rspack_esm_id = "190";
2
+ export const __rspack_esm_ids = ["190"];
3
+ export const __webpack_modules__ = {
4
+ 8253(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
5
+ // ESM COMPAT FLAG
6
+ __webpack_require__.r(__webpack_exports__);
7
+
8
+ // EXPORTS
9
+ __webpack_require__.d(__webpack_exports__, {
10
+ WatchHelper: () => (/* binding */ WatchHelper),
11
+ "default": () => (/* binding */ chokidar),
12
+ watch: () => (/* binding */ watch),
13
+ FSWatcher: () => (/* binding */ FSWatcher)
14
+ });
15
+
16
+ // EXTERNAL MODULE: external "node:events"
17
+ var external_node_events_ = __webpack_require__(8474);
18
+ // EXTERNAL MODULE: external "node:fs"
19
+ var external_node_fs_ = __webpack_require__(3024);
20
+ // EXTERNAL MODULE: external "node:fs/promises"
21
+ var promises_ = __webpack_require__(1455);
22
+ // EXTERNAL MODULE: external "node:path"
23
+ var external_node_path_ = __webpack_require__(6760);
24
+ // EXTERNAL MODULE: external "node:stream"
25
+ var external_node_stream_ = __webpack_require__(7075);
26
+ ;// CONCATENATED MODULE: ./node_modules/c12/node_modules/readdirp/index.js
27
+
28
+
29
+
30
+ const EntryTypes = {
31
+ FILE_TYPE: 'files',
32
+ DIR_TYPE: 'directories',
33
+ FILE_DIR_TYPE: 'files_directories',
34
+ EVERYTHING_TYPE: 'all',
35
+ };
36
+ const defaultOptions = {
37
+ root: '.',
38
+ fileFilter: (_entryInfo) => true,
39
+ directoryFilter: (_entryInfo) => true,
40
+ type: EntryTypes.FILE_TYPE,
41
+ lstat: false,
42
+ depth: 2147483648,
43
+ alwaysStat: false,
44
+ highWaterMark: 4096,
45
+ };
46
+ Object.freeze(defaultOptions);
47
+ const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
48
+ const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
49
+ const ALL_TYPES = [
50
+ EntryTypes.DIR_TYPE,
51
+ EntryTypes.EVERYTHING_TYPE,
52
+ EntryTypes.FILE_DIR_TYPE,
53
+ EntryTypes.FILE_TYPE,
54
+ ];
55
+ const DIR_TYPES = new Set([
56
+ EntryTypes.DIR_TYPE,
57
+ EntryTypes.EVERYTHING_TYPE,
58
+ EntryTypes.FILE_DIR_TYPE,
59
+ ]);
60
+ const FILE_TYPES = new Set([
61
+ EntryTypes.EVERYTHING_TYPE,
62
+ EntryTypes.FILE_DIR_TYPE,
63
+ EntryTypes.FILE_TYPE,
64
+ ]);
65
+ const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
66
+ const wantBigintFsStats = process.platform === 'win32';
67
+ const emptyFn = (_entryInfo) => true;
68
+ const normalizeFilter = (filter) => {
69
+ if (filter === undefined)
70
+ return emptyFn;
71
+ if (typeof filter === 'function')
72
+ return filter;
73
+ if (typeof filter === 'string') {
74
+ const fl = filter.trim();
75
+ return (entry) => entry.basename === fl;
76
+ }
77
+ if (Array.isArray(filter)) {
78
+ const trItems = filter.map((item) => item.trim());
79
+ return (entry) => trItems.some((f) => entry.basename === f);
80
+ }
81
+ return emptyFn;
82
+ };
83
+ /** Readable readdir stream, emitting new files as they're being listed. */
84
+ class ReaddirpStream extends external_node_stream_.Readable {
85
+ parents;
86
+ reading;
87
+ parent;
88
+ _stat;
89
+ _maxDepth;
90
+ _wantsDir;
91
+ _wantsFile;
92
+ _wantsEverything;
93
+ _root;
94
+ _isDirent;
95
+ _statsProp;
96
+ _rdOptions;
97
+ _fileFilter;
98
+ _directoryFilter;
99
+ constructor(options = {}) {
100
+ super({
101
+ objectMode: true,
102
+ autoDestroy: true,
103
+ highWaterMark: options.highWaterMark,
104
+ });
105
+ const opts = { ...defaultOptions, ...options };
106
+ const { root, type } = opts;
107
+ this._fileFilter = normalizeFilter(opts.fileFilter);
108
+ this._directoryFilter = normalizeFilter(opts.directoryFilter);
109
+ const statMethod = opts.lstat ? promises_.lstat : promises_.stat;
110
+ // Use bigint stats if it's windows and stat() supports options (node 10+).
111
+ if (wantBigintFsStats) {
112
+ this._stat = (path) => statMethod(path, { bigint: true });
113
+ }
114
+ else {
115
+ this._stat = statMethod;
116
+ }
117
+ this._maxDepth =
118
+ opts.depth != null && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth;
119
+ this._wantsDir = type ? DIR_TYPES.has(type) : false;
120
+ this._wantsFile = type ? FILE_TYPES.has(type) : false;
121
+ this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
122
+ this._root = (0,external_node_path_.resolve)(root);
123
+ this._isDirent = !opts.alwaysStat;
124
+ this._statsProp = this._isDirent ? 'dirent' : 'stats';
125
+ this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
126
+ // Launch stream with one parent, the root dir.
127
+ this.parents = [this._exploreDir(root, 1)];
128
+ this.reading = false;
129
+ this.parent = undefined;
130
+ }
131
+ async _read(batch) {
132
+ if (this.reading)
133
+ return;
134
+ this.reading = true;
135
+ try {
136
+ while (!this.destroyed && batch > 0) {
137
+ const par = this.parent;
138
+ const fil = par && par.files;
139
+ if (fil && fil.length > 0) {
140
+ const { path, depth } = par;
141
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
142
+ const awaited = await Promise.all(slice);
143
+ for (const entry of awaited) {
144
+ if (!entry)
145
+ continue;
146
+ if (this.destroyed)
147
+ return;
148
+ const entryType = await this._getEntryType(entry);
149
+ if (entryType === 'directory' && this._directoryFilter(entry)) {
150
+ if (depth <= this._maxDepth) {
151
+ this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
152
+ }
153
+ if (this._wantsDir) {
154
+ this.push(entry);
155
+ batch--;
156
+ }
157
+ }
158
+ else if ((entryType === 'file' || this._includeAsFile(entry)) &&
159
+ this._fileFilter(entry)) {
160
+ if (this._wantsFile) {
161
+ this.push(entry);
162
+ batch--;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ else {
168
+ const parent = this.parents.pop();
169
+ if (!parent) {
170
+ this.push(null);
171
+ break;
172
+ }
173
+ this.parent = await parent;
174
+ if (this.destroyed)
175
+ return;
176
+ }
177
+ }
178
+ }
179
+ catch (error) {
180
+ this.destroy(error);
181
+ }
182
+ finally {
183
+ this.reading = false;
184
+ }
185
+ }
186
+ async _exploreDir(path, depth) {
187
+ let files;
188
+ try {
189
+ files = await (0,promises_.readdir)(path, this._rdOptions);
190
+ }
191
+ catch (error) {
192
+ this._onError(error);
193
+ }
194
+ return { files, depth, path };
195
+ }
196
+ async _formatEntry(dirent, path) {
197
+ let entry;
198
+ const basename = this._isDirent ? dirent.name : dirent;
199
+ try {
200
+ const fullPath = (0,external_node_path_.resolve)((0,external_node_path_.join)(path, basename));
201
+ entry = { path: (0,external_node_path_.relative)(this._root, fullPath), fullPath, basename };
202
+ entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
203
+ }
204
+ catch (err) {
205
+ this._onError(err);
206
+ return;
207
+ }
208
+ return entry;
209
+ }
210
+ _onError(err) {
211
+ if (isNormalFlowError(err) && !this.destroyed) {
212
+ this.emit('warn', err);
213
+ }
214
+ else {
215
+ this.destroy(err);
216
+ }
217
+ }
218
+ async _getEntryType(entry) {
219
+ // entry may be undefined, because a warning or an error were emitted
220
+ // and the statsProp is undefined
221
+ if (!entry && this._statsProp in entry) {
222
+ return '';
223
+ }
224
+ const stats = entry[this._statsProp];
225
+ if (stats.isFile())
226
+ return 'file';
227
+ if (stats.isDirectory())
228
+ return 'directory';
229
+ if (stats && stats.isSymbolicLink()) {
230
+ const full = entry.fullPath;
231
+ try {
232
+ const entryRealPath = await (0,promises_.realpath)(full);
233
+ const entryRealPathStats = await (0,promises_.lstat)(entryRealPath);
234
+ if (entryRealPathStats.isFile()) {
235
+ return 'file';
236
+ }
237
+ if (entryRealPathStats.isDirectory()) {
238
+ const len = entryRealPath.length;
239
+ if (full.startsWith(entryRealPath) && full.substr(len, 1) === external_node_path_.sep) {
240
+ const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
241
+ // @ts-ignore
242
+ recursiveError.code = RECURSIVE_ERROR_CODE;
243
+ return this._onError(recursiveError);
244
+ }
245
+ return 'directory';
246
+ }
247
+ }
248
+ catch (error) {
249
+ this._onError(error);
250
+ return '';
251
+ }
252
+ }
253
+ }
254
+ _includeAsFile(entry) {
255
+ const stats = entry && entry[this._statsProp];
256
+ return stats && this._wantsEverything && !stats.isDirectory();
257
+ }
258
+ }
259
+ /**
260
+ * Streaming version: Reads all files and directories in given root recursively.
261
+ * Consumes ~constant small amount of RAM.
262
+ * @param root Root directory
263
+ * @param options Options to specify root (start directory), filters and recursion depth
264
+ */
265
+ function readdirp(root, options = {}) {
266
+ // @ts-ignore
267
+ let type = options.entryType || options.type;
268
+ if (type === 'both')
269
+ type = EntryTypes.FILE_DIR_TYPE; // backwards-compatibility
270
+ if (type)
271
+ options.type = type;
272
+ if (!root) {
273
+ throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
274
+ }
275
+ else if (typeof root !== 'string') {
276
+ throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
277
+ }
278
+ else if (type && !ALL_TYPES.includes(type)) {
279
+ throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
280
+ }
281
+ options.root = root;
282
+ return new ReaddirpStream(options);
283
+ }
284
+ /**
285
+ * Promise version: Reads all files and directories in given root recursively.
286
+ * Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
287
+ * @returns array of paths and their entry infos
288
+ */
289
+ function readdirpPromise(root, options = {}) {
290
+ return new Promise((resolve, reject) => {
291
+ const files = [];
292
+ readdirp(root, options)
293
+ .on('data', (entry) => files.push(entry))
294
+ .on('end', () => resolve(files))
295
+ .on('error', (error) => reject(error));
296
+ });
297
+ }
298
+ /* export default */ const node_modules_readdirp = ((/* unused pure expression or super */ null && (readdirp)));
299
+
300
+ // EXTERNAL MODULE: external "node:os"
301
+ var external_node_os_ = __webpack_require__(8161);
302
+ ;// CONCATENATED MODULE: ./node_modules/c12/node_modules/chokidar/handler.js
303
+
304
+
305
+
306
+
307
+ const STR_DATA = 'data';
308
+ const STR_END = 'end';
309
+ const STR_CLOSE = 'close';
310
+ const EMPTY_FN = () => { };
311
+ const IDENTITY_FN = (val) => val;
312
+ const pl = process.platform;
313
+ const isWindows = pl === 'win32';
314
+ const isMacos = pl === 'darwin';
315
+ const isLinux = pl === 'linux';
316
+ const isFreeBSD = pl === 'freebsd';
317
+ const isIBMi = (0,external_node_os_.type)() === 'OS400';
318
+ const EVENTS = {
319
+ ALL: 'all',
320
+ READY: 'ready',
321
+ ADD: 'add',
322
+ CHANGE: 'change',
323
+ ADD_DIR: 'addDir',
324
+ UNLINK: 'unlink',
325
+ UNLINK_DIR: 'unlinkDir',
326
+ RAW: 'raw',
327
+ ERROR: 'error',
328
+ };
329
+ const EV = EVENTS;
330
+ const THROTTLE_MODE_WATCH = 'watch';
331
+ const statMethods = { lstat: promises_.lstat, stat: promises_.stat };
332
+ const KEY_LISTENERS = 'listeners';
333
+ const KEY_ERR = 'errHandlers';
334
+ const KEY_RAW = 'rawEmitters';
335
+ const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
336
+ // prettier-ignore
337
+ const binaryExtensions = new Set([
338
+ '3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
339
+ 'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
340
+ 'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
341
+ 'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
342
+ 'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
343
+ 'dtshd', 'dvb', 'dwg', 'dxf',
344
+ 'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
345
+ 'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
346
+ 'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
347
+ 'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
348
+ 'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
349
+ 'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
350
+ 'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
351
+ 'mobi', 'mov', 'movie', 'mp3',
352
+ 'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
353
+ 'nef', 'npx', 'numbers', 'nupkg',
354
+ 'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
355
+ 'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
356
+ 'potx', 'ppa', 'ppam',
357
+ 'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
358
+ 'qt',
359
+ 'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
360
+ 's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
361
+ 'stl', 'suo', 'sub', 'swf',
362
+ 'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
363
+ 'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
364
+ 'viv', 'vob',
365
+ 'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
366
+ 'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
367
+ 'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
368
+ 'xmind', 'xpi', 'xpm', 'xwd', 'xz',
369
+ 'z', 'zip', 'zipx',
370
+ ]);
371
+ const isBinaryPath = (filePath) => binaryExtensions.has(external_node_path_.extname(filePath).slice(1).toLowerCase());
372
+ // TODO: emit errors properly. Example: EMFILE on Macos.
373
+ const foreach = (val, fn) => {
374
+ if (val instanceof Set) {
375
+ val.forEach(fn);
376
+ }
377
+ else {
378
+ fn(val);
379
+ }
380
+ };
381
+ const addAndConvert = (main, prop, item) => {
382
+ let container = main[prop];
383
+ if (!(container instanceof Set)) {
384
+ main[prop] = container = new Set([container]);
385
+ }
386
+ container.add(item);
387
+ };
388
+ const clearItem = (cont) => (key) => {
389
+ const set = cont[key];
390
+ if (set instanceof Set) {
391
+ set.clear();
392
+ }
393
+ else {
394
+ delete cont[key];
395
+ }
396
+ };
397
+ const delFromSet = (main, prop, item) => {
398
+ const container = main[prop];
399
+ if (container instanceof Set) {
400
+ container.delete(item);
401
+ }
402
+ else if (container === item) {
403
+ delete main[prop];
404
+ }
405
+ };
406
+ const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
407
+ const FsWatchInstances = new Map();
408
+ /**
409
+ * Instantiates the fs_watch interface
410
+ * @param path to be watched
411
+ * @param options to be passed to fs_watch
412
+ * @param listener main event handler
413
+ * @param errHandler emits info about errors
414
+ * @param emitRaw emits raw event data
415
+ * @returns {NativeFsWatcher}
416
+ */
417
+ function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
418
+ const handleEvent = (rawEvent, evPath) => {
419
+ listener(path);
420
+ emitRaw(rawEvent, evPath, { watchedPath: path });
421
+ // emit based on events occurring for files from a directory's watcher in
422
+ // case the file's watcher misses it (and rely on throttling to de-dupe)
423
+ if (evPath && path !== evPath) {
424
+ fsWatchBroadcast(external_node_path_.resolve(path, evPath), KEY_LISTENERS, external_node_path_.join(path, evPath));
425
+ }
426
+ };
427
+ try {
428
+ return (0,external_node_fs_.watch)(path, {
429
+ persistent: options.persistent,
430
+ }, handleEvent);
431
+ }
432
+ catch (error) {
433
+ errHandler(error);
434
+ return undefined;
435
+ }
436
+ }
437
+ /**
438
+ * Helper for passing fs_watch event data to a collection of listeners
439
+ * @param fullPath absolute path bound to fs_watch instance
440
+ */
441
+ const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
442
+ const cont = FsWatchInstances.get(fullPath);
443
+ if (!cont)
444
+ return;
445
+ foreach(cont[listenerType], (listener) => {
446
+ listener(val1, val2, val3);
447
+ });
448
+ };
449
+ /**
450
+ * Instantiates the fs_watch interface or binds listeners
451
+ * to an existing one covering the same file system entry
452
+ * @param path
453
+ * @param fullPath absolute path
454
+ * @param options to be passed to fs_watch
455
+ * @param handlers container for event listener functions
456
+ */
457
+ const setFsWatchListener = (path, fullPath, options, handlers) => {
458
+ const { listener, errHandler, rawEmitter } = handlers;
459
+ let cont = FsWatchInstances.get(fullPath);
460
+ let watcher;
461
+ if (!options.persistent) {
462
+ watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
463
+ if (!watcher)
464
+ return;
465
+ return watcher.close.bind(watcher);
466
+ }
467
+ if (cont) {
468
+ addAndConvert(cont, KEY_LISTENERS, listener);
469
+ addAndConvert(cont, KEY_ERR, errHandler);
470
+ addAndConvert(cont, KEY_RAW, rawEmitter);
471
+ }
472
+ else {
473
+ watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
474
+ fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
475
+ if (!watcher)
476
+ return;
477
+ watcher.on(EV.ERROR, async (error) => {
478
+ const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
479
+ if (cont)
480
+ cont.watcherUnusable = true; // documented since Node 10.4.1
481
+ // Workaround for https://github.com/joyent/node/issues/4337
482
+ if (isWindows && error.code === 'EPERM') {
483
+ try {
484
+ const fd = await (0,promises_.open)(path, 'r');
485
+ await fd.close();
486
+ broadcastErr(error);
487
+ }
488
+ catch (err) {
489
+ // do nothing
490
+ }
491
+ }
492
+ else {
493
+ broadcastErr(error);
494
+ }
495
+ });
496
+ cont = {
497
+ listeners: listener,
498
+ errHandlers: errHandler,
499
+ rawEmitters: rawEmitter,
500
+ watcher,
501
+ };
502
+ FsWatchInstances.set(fullPath, cont);
503
+ }
504
+ // const index = cont.listeners.indexOf(listener);
505
+ // removes this instance's listeners and closes the underlying fs_watch
506
+ // instance if there are no more listeners left
507
+ return () => {
508
+ delFromSet(cont, KEY_LISTENERS, listener);
509
+ delFromSet(cont, KEY_ERR, errHandler);
510
+ delFromSet(cont, KEY_RAW, rawEmitter);
511
+ if (isEmptySet(cont.listeners)) {
512
+ // Check to protect against issue gh-730.
513
+ // if (cont.watcherUnusable) {
514
+ cont.watcher.close();
515
+ // }
516
+ FsWatchInstances.delete(fullPath);
517
+ HANDLER_KEYS.forEach(clearItem(cont));
518
+ // @ts-ignore
519
+ cont.watcher = undefined;
520
+ Object.freeze(cont);
521
+ }
522
+ };
523
+ };
524
+ // fs_watchFile helpers
525
+ // object to hold per-process fs_watchFile instances
526
+ // (may be shared across chokidar FSWatcher instances)
527
+ const FsWatchFileInstances = new Map();
528
+ /**
529
+ * Instantiates the fs_watchFile interface or binds listeners
530
+ * to an existing one covering the same file system entry
531
+ * @param path to be watched
532
+ * @param fullPath absolute path
533
+ * @param options options to be passed to fs_watchFile
534
+ * @param handlers container for event listener functions
535
+ * @returns closer
536
+ */
537
+ const setFsWatchFileListener = (path, fullPath, options, handlers) => {
538
+ const { listener, rawEmitter } = handlers;
539
+ let cont = FsWatchFileInstances.get(fullPath);
540
+ // let listeners = new Set();
541
+ // let rawEmitters = new Set();
542
+ const copts = cont && cont.options;
543
+ if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
544
+ // "Upgrade" the watcher to persistence or a quicker interval.
545
+ // This creates some unlikely edge case issues if the user mixes
546
+ // settings in a very weird way, but solving for those cases
547
+ // doesn't seem worthwhile for the added complexity.
548
+ // listeners = cont.listeners;
549
+ // rawEmitters = cont.rawEmitters;
550
+ (0,external_node_fs_.unwatchFile)(fullPath);
551
+ cont = undefined;
552
+ }
553
+ if (cont) {
554
+ addAndConvert(cont, KEY_LISTENERS, listener);
555
+ addAndConvert(cont, KEY_RAW, rawEmitter);
556
+ }
557
+ else {
558
+ // TODO
559
+ // listeners.add(listener);
560
+ // rawEmitters.add(rawEmitter);
561
+ cont = {
562
+ listeners: listener,
563
+ rawEmitters: rawEmitter,
564
+ options,
565
+ watcher: (0,external_node_fs_.watchFile)(fullPath, options, (curr, prev) => {
566
+ foreach(cont.rawEmitters, (rawEmitter) => {
567
+ rawEmitter(EV.CHANGE, fullPath, { curr, prev });
568
+ });
569
+ const currmtime = curr.mtimeMs;
570
+ if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
571
+ foreach(cont.listeners, (listener) => listener(path, curr));
572
+ }
573
+ }),
574
+ };
575
+ FsWatchFileInstances.set(fullPath, cont);
576
+ }
577
+ // const index = cont.listeners.indexOf(listener);
578
+ // Removes this instance's listeners and closes the underlying fs_watchFile
579
+ // instance if there are no more listeners left.
580
+ return () => {
581
+ delFromSet(cont, KEY_LISTENERS, listener);
582
+ delFromSet(cont, KEY_RAW, rawEmitter);
583
+ if (isEmptySet(cont.listeners)) {
584
+ FsWatchFileInstances.delete(fullPath);
585
+ (0,external_node_fs_.unwatchFile)(fullPath);
586
+ cont.options = cont.watcher = undefined;
587
+ Object.freeze(cont);
588
+ }
589
+ };
590
+ };
591
+ /**
592
+ * @mixin
593
+ */
594
+ class NodeFsHandler {
595
+ fsw;
596
+ _boundHandleError;
597
+ constructor(fsW) {
598
+ this.fsw = fsW;
599
+ this._boundHandleError = (error) => fsW._handleError(error);
600
+ }
601
+ /**
602
+ * Watch file for changes with fs_watchFile or fs_watch.
603
+ * @param path to file or dir
604
+ * @param listener on fs change
605
+ * @returns closer for the watcher instance
606
+ */
607
+ _watchWithNodeFs(path, listener) {
608
+ const opts = this.fsw.options;
609
+ const directory = external_node_path_.dirname(path);
610
+ const basename = external_node_path_.basename(path);
611
+ const parent = this.fsw._getWatchedDir(directory);
612
+ parent.add(basename);
613
+ const absolutePath = external_node_path_.resolve(path);
614
+ const options = {
615
+ persistent: opts.persistent,
616
+ };
617
+ if (!listener)
618
+ listener = EMPTY_FN;
619
+ let closer;
620
+ if (opts.usePolling) {
621
+ const enableBin = opts.interval !== opts.binaryInterval;
622
+ options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
623
+ closer = setFsWatchFileListener(path, absolutePath, options, {
624
+ listener,
625
+ rawEmitter: this.fsw._emitRaw,
626
+ });
627
+ }
628
+ else {
629
+ closer = setFsWatchListener(path, absolutePath, options, {
630
+ listener,
631
+ errHandler: this._boundHandleError,
632
+ rawEmitter: this.fsw._emitRaw,
633
+ });
634
+ }
635
+ return closer;
636
+ }
637
+ /**
638
+ * Watch a file and emit add event if warranted.
639
+ * @returns closer for the watcher instance
640
+ */
641
+ _handleFile(file, stats, initialAdd) {
642
+ if (this.fsw.closed) {
643
+ return;
644
+ }
645
+ const dirname = external_node_path_.dirname(file);
646
+ const basename = external_node_path_.basename(file);
647
+ const parent = this.fsw._getWatchedDir(dirname);
648
+ // stats is always present
649
+ let prevStats = stats;
650
+ // if the file is already being watched, do nothing
651
+ if (parent.has(basename))
652
+ return;
653
+ const listener = async (path, newStats) => {
654
+ if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
655
+ return;
656
+ if (!newStats || newStats.mtimeMs === 0) {
657
+ try {
658
+ const newStats = await (0,promises_.stat)(file);
659
+ if (this.fsw.closed)
660
+ return;
661
+ // Check that change event was not fired because of changed only accessTime.
662
+ const at = newStats.atimeMs;
663
+ const mt = newStats.mtimeMs;
664
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) {
665
+ this.fsw._emit(EV.CHANGE, file, newStats);
666
+ }
667
+ if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
668
+ this.fsw._closeFile(path);
669
+ prevStats = newStats;
670
+ const closer = this._watchWithNodeFs(file, listener);
671
+ if (closer)
672
+ this.fsw._addPathCloser(path, closer);
673
+ }
674
+ else {
675
+ prevStats = newStats;
676
+ }
677
+ }
678
+ catch (error) {
679
+ // Fix issues where mtime is null but file is still present
680
+ this.fsw._remove(dirname, basename);
681
+ }
682
+ // add is about to be emitted if file not already tracked in parent
683
+ }
684
+ else if (parent.has(basename)) {
685
+ // Check that change event was not fired because of changed only accessTime.
686
+ const at = newStats.atimeMs;
687
+ const mt = newStats.mtimeMs;
688
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) {
689
+ this.fsw._emit(EV.CHANGE, file, newStats);
690
+ }
691
+ prevStats = newStats;
692
+ }
693
+ };
694
+ // kick off the watcher
695
+ const closer = this._watchWithNodeFs(file, listener);
696
+ // emit an add event if we're supposed to
697
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
698
+ if (!this.fsw._throttle(EV.ADD, file, 0))
699
+ return;
700
+ this.fsw._emit(EV.ADD, file, stats);
701
+ }
702
+ return closer;
703
+ }
704
+ /**
705
+ * Handle symlinks encountered while reading a dir.
706
+ * @param entry returned by readdirp
707
+ * @param directory path of dir being read
708
+ * @param path of this item
709
+ * @param item basename of this item
710
+ * @returns true if no more processing is needed for this entry.
711
+ */
712
+ async _handleSymlink(entry, directory, path, item) {
713
+ if (this.fsw.closed) {
714
+ return;
715
+ }
716
+ const full = entry.fullPath;
717
+ const dir = this.fsw._getWatchedDir(directory);
718
+ if (!this.fsw.options.followSymlinks) {
719
+ // watch symlink directly (don't follow) and detect changes
720
+ this.fsw._incrReadyCount();
721
+ let linkPath;
722
+ try {
723
+ linkPath = await (0,promises_.realpath)(path);
724
+ }
725
+ catch (e) {
726
+ this.fsw._emitReady();
727
+ return true;
728
+ }
729
+ if (this.fsw.closed)
730
+ return;
731
+ if (dir.has(item)) {
732
+ if (this.fsw._symlinkPaths.get(full) !== linkPath) {
733
+ this.fsw._symlinkPaths.set(full, linkPath);
734
+ this.fsw._emit(EV.CHANGE, path, entry.stats);
735
+ }
736
+ }
737
+ else {
738
+ dir.add(item);
739
+ this.fsw._symlinkPaths.set(full, linkPath);
740
+ this.fsw._emit(EV.ADD, path, entry.stats);
741
+ }
742
+ this.fsw._emitReady();
743
+ return true;
744
+ }
745
+ // don't follow the same symlink more than once
746
+ if (this.fsw._symlinkPaths.has(full)) {
747
+ return true;
748
+ }
749
+ this.fsw._symlinkPaths.set(full, true);
750
+ }
751
+ _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
752
+ // Normalize the directory name on Windows
753
+ directory = external_node_path_.join(directory, '');
754
+ const throttleKey = target ? `${directory}:${target}` : directory;
755
+ throttler = this.fsw._throttle('readdir', throttleKey, 1000);
756
+ if (!throttler)
757
+ return;
758
+ const previous = this.fsw._getWatchedDir(wh.path);
759
+ const current = new Set();
760
+ let stream = this.fsw._readdirp(directory, {
761
+ fileFilter: (entry) => wh.filterPath(entry),
762
+ directoryFilter: (entry) => wh.filterDir(entry),
763
+ });
764
+ if (!stream)
765
+ return;
766
+ stream
767
+ .on(STR_DATA, async (entry) => {
768
+ if (this.fsw.closed) {
769
+ stream = undefined;
770
+ return;
771
+ }
772
+ const item = entry.path;
773
+ let path = external_node_path_.join(directory, item);
774
+ current.add(item);
775
+ if (entry.stats.isSymbolicLink() &&
776
+ (await this._handleSymlink(entry, directory, path, item))) {
777
+ return;
778
+ }
779
+ if (this.fsw.closed) {
780
+ stream = undefined;
781
+ return;
782
+ }
783
+ // Files that present in current directory snapshot
784
+ // but absent in previous are added to watch list and
785
+ // emit `add` event.
786
+ if (item === target || (!target && !previous.has(item))) {
787
+ this.fsw._incrReadyCount();
788
+ // ensure relativeness of path is preserved in case of watcher reuse
789
+ path = external_node_path_.join(dir, external_node_path_.relative(dir, path));
790
+ this._addToNodeFs(path, initialAdd, wh, depth + 1);
791
+ }
792
+ })
793
+ .on(EV.ERROR, this._boundHandleError);
794
+ return new Promise((resolve, reject) => {
795
+ if (!stream)
796
+ return reject();
797
+ stream.once(STR_END, () => {
798
+ if (this.fsw.closed) {
799
+ stream = undefined;
800
+ return;
801
+ }
802
+ const wasThrottled = throttler ? throttler.clear() : false;
803
+ resolve(undefined);
804
+ // Files that absent in current directory snapshot
805
+ // but present in previous emit `remove` event
806
+ // and are removed from @watched[directory].
807
+ previous
808
+ .getChildren()
809
+ .filter((item) => {
810
+ return item !== directory && !current.has(item);
811
+ })
812
+ .forEach((item) => {
813
+ this.fsw._remove(directory, item);
814
+ });
815
+ stream = undefined;
816
+ // one more time for any missed in case changes came in extremely quickly
817
+ if (wasThrottled)
818
+ this._handleRead(directory, false, wh, target, dir, depth, throttler);
819
+ });
820
+ });
821
+ }
822
+ /**
823
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
824
+ * @param dir fs path
825
+ * @param stats
826
+ * @param initialAdd
827
+ * @param depth relative to user-supplied path
828
+ * @param target child path targeted for watch
829
+ * @param wh Common watch helpers for this path
830
+ * @param realpath
831
+ * @returns closer for the watcher instance.
832
+ */
833
+ async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
834
+ const parentDir = this.fsw._getWatchedDir(external_node_path_.dirname(dir));
835
+ const tracked = parentDir.has(external_node_path_.basename(dir));
836
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
837
+ this.fsw._emit(EV.ADD_DIR, dir, stats);
838
+ }
839
+ // ensure dir is tracked (harmless if redundant)
840
+ parentDir.add(external_node_path_.basename(dir));
841
+ this.fsw._getWatchedDir(dir);
842
+ let throttler;
843
+ let closer;
844
+ const oDepth = this.fsw.options.depth;
845
+ if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
846
+ if (!target) {
847
+ await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
848
+ if (this.fsw.closed)
849
+ return;
850
+ }
851
+ closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
852
+ // if current directory is removed, do nothing
853
+ if (stats && stats.mtimeMs === 0)
854
+ return;
855
+ this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
856
+ });
857
+ }
858
+ return closer;
859
+ }
860
+ /**
861
+ * Handle added file, directory, or glob pattern.
862
+ * Delegates call to _handleFile / _handleDir after checks.
863
+ * @param path to file or ir
864
+ * @param initialAdd was the file added at watch instantiation?
865
+ * @param priorWh depth relative to user-supplied path
866
+ * @param depth Child path actually targeted for watch
867
+ * @param target Child path actually targeted for watch
868
+ */
869
+ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
870
+ const ready = this.fsw._emitReady;
871
+ if (this.fsw._isIgnored(path) || this.fsw.closed) {
872
+ ready();
873
+ return false;
874
+ }
875
+ const wh = this.fsw._getWatchHelpers(path);
876
+ if (priorWh) {
877
+ wh.filterPath = (entry) => priorWh.filterPath(entry);
878
+ wh.filterDir = (entry) => priorWh.filterDir(entry);
879
+ }
880
+ // evaluate what is at the path we're being asked to watch
881
+ try {
882
+ const stats = await statMethods[wh.statMethod](wh.watchPath);
883
+ if (this.fsw.closed)
884
+ return;
885
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
886
+ ready();
887
+ return false;
888
+ }
889
+ const follow = this.fsw.options.followSymlinks;
890
+ let closer;
891
+ if (stats.isDirectory()) {
892
+ const absPath = external_node_path_.resolve(path);
893
+ const targetPath = follow ? await (0,promises_.realpath)(path) : path;
894
+ if (this.fsw.closed)
895
+ return;
896
+ closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
897
+ if (this.fsw.closed)
898
+ return;
899
+ // preserve this symlink's target path
900
+ if (absPath !== targetPath && targetPath !== undefined) {
901
+ this.fsw._symlinkPaths.set(absPath, targetPath);
902
+ }
903
+ }
904
+ else if (stats.isSymbolicLink()) {
905
+ const targetPath = follow ? await (0,promises_.realpath)(path) : path;
906
+ if (this.fsw.closed)
907
+ return;
908
+ const parent = external_node_path_.dirname(wh.watchPath);
909
+ this.fsw._getWatchedDir(parent).add(wh.watchPath);
910
+ this.fsw._emit(EV.ADD, wh.watchPath, stats);
911
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
912
+ if (this.fsw.closed)
913
+ return;
914
+ // preserve this symlink's target path
915
+ if (targetPath !== undefined) {
916
+ this.fsw._symlinkPaths.set(external_node_path_.resolve(path), targetPath);
917
+ }
918
+ }
919
+ else {
920
+ closer = this._handleFile(wh.watchPath, stats, initialAdd);
921
+ }
922
+ ready();
923
+ if (closer)
924
+ this.fsw._addPathCloser(path, closer);
925
+ return false;
926
+ }
927
+ catch (error) {
928
+ if (this.fsw._handleError(error)) {
929
+ ready();
930
+ return path;
931
+ }
932
+ }
933
+ }
934
+ }
935
+
936
+ ;// CONCATENATED MODULE: ./node_modules/c12/node_modules/chokidar/index.js
937
+ /*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
938
+
939
+
940
+
941
+
942
+
943
+
944
+ const SLASH = '/';
945
+ const SLASH_SLASH = '//';
946
+ const ONE_DOT = '.';
947
+ const TWO_DOTS = '..';
948
+ const STRING_TYPE = 'string';
949
+ const BACK_SLASH_RE = /\\/g;
950
+ const DOUBLE_SLASH_RE = /\/\//g;
951
+ const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
952
+ const REPLACER_RE = /^\.[/\\]/;
953
+ function arrify(item) {
954
+ return Array.isArray(item) ? item : [item];
955
+ }
956
+ const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
957
+ function createPattern(matcher) {
958
+ if (typeof matcher === 'function')
959
+ return matcher;
960
+ if (typeof matcher === 'string')
961
+ return (string) => matcher === string;
962
+ if (matcher instanceof RegExp)
963
+ return (string) => matcher.test(string);
964
+ if (typeof matcher === 'object' && matcher !== null) {
965
+ return (string) => {
966
+ if (matcher.path === string)
967
+ return true;
968
+ if (matcher.recursive) {
969
+ const relative = external_node_path_.relative(matcher.path, string);
970
+ if (!relative) {
971
+ return false;
972
+ }
973
+ return !relative.startsWith('..') && !external_node_path_.isAbsolute(relative);
974
+ }
975
+ return false;
976
+ };
977
+ }
978
+ return () => false;
979
+ }
980
+ function normalizePath(path) {
981
+ if (typeof path !== 'string')
982
+ throw new Error('string expected');
983
+ path = external_node_path_.normalize(path);
984
+ path = path.replace(/\\/g, '/');
985
+ let prepend = false;
986
+ if (path.startsWith('//'))
987
+ prepend = true;
988
+ path = path.replace(DOUBLE_SLASH_RE, '/');
989
+ if (prepend)
990
+ path = '/' + path;
991
+ return path;
992
+ }
993
+ function matchPatterns(patterns, testString, stats) {
994
+ const path = normalizePath(testString);
995
+ for (let index = 0; index < patterns.length; index++) {
996
+ const pattern = patterns[index];
997
+ if (pattern(path, stats)) {
998
+ return true;
999
+ }
1000
+ }
1001
+ return false;
1002
+ }
1003
+ function anymatch(matchers, testString) {
1004
+ if (matchers == null) {
1005
+ throw new TypeError('anymatch: specify first argument');
1006
+ }
1007
+ // Early cache for matchers.
1008
+ const matchersArray = arrify(matchers);
1009
+ const patterns = matchersArray.map((matcher) => createPattern(matcher));
1010
+ if (testString == null) {
1011
+ return (testString, stats) => {
1012
+ return matchPatterns(patterns, testString, stats);
1013
+ };
1014
+ }
1015
+ return matchPatterns(patterns, testString);
1016
+ }
1017
+ const unifyPaths = (paths_) => {
1018
+ const paths = arrify(paths_).flat();
1019
+ if (!paths.every((p) => typeof p === STRING_TYPE)) {
1020
+ throw new TypeError(`Non-string provided as watch path: ${paths}`);
1021
+ }
1022
+ return paths.map(normalizePathToUnix);
1023
+ };
1024
+ // If SLASH_SLASH occurs at the beginning of path, it is not replaced
1025
+ // because "//StoragePC/DrivePool/Movies" is a valid network path
1026
+ const toUnix = (string) => {
1027
+ let str = string.replace(BACK_SLASH_RE, SLASH);
1028
+ let prepend = false;
1029
+ if (str.startsWith(SLASH_SLASH)) {
1030
+ prepend = true;
1031
+ }
1032
+ str = str.replace(DOUBLE_SLASH_RE, SLASH);
1033
+ if (prepend) {
1034
+ str = SLASH + str;
1035
+ }
1036
+ return str;
1037
+ };
1038
+ // Our version of upath.normalize
1039
+ // TODO: this is not equal to path-normalize module - investigate why
1040
+ const normalizePathToUnix = (path) => toUnix(external_node_path_.normalize(toUnix(path)));
1041
+ // TODO: refactor
1042
+ const normalizeIgnored = (cwd = '') => (path) => {
1043
+ if (typeof path === 'string') {
1044
+ return normalizePathToUnix(external_node_path_.isAbsolute(path) ? path : external_node_path_.join(cwd, path));
1045
+ }
1046
+ else {
1047
+ return path;
1048
+ }
1049
+ };
1050
+ const getAbsolutePath = (path, cwd) => {
1051
+ if (external_node_path_.isAbsolute(path)) {
1052
+ return path;
1053
+ }
1054
+ return external_node_path_.join(cwd, path);
1055
+ };
1056
+ const EMPTY_SET = Object.freeze(new Set());
1057
+ /**
1058
+ * Directory entry.
1059
+ */
1060
+ class DirEntry {
1061
+ path;
1062
+ _removeWatcher;
1063
+ items;
1064
+ constructor(dir, removeWatcher) {
1065
+ this.path = dir;
1066
+ this._removeWatcher = removeWatcher;
1067
+ this.items = new Set();
1068
+ }
1069
+ add(item) {
1070
+ const { items } = this;
1071
+ if (!items)
1072
+ return;
1073
+ if (item !== ONE_DOT && item !== TWO_DOTS)
1074
+ items.add(item);
1075
+ }
1076
+ async remove(item) {
1077
+ const { items } = this;
1078
+ if (!items)
1079
+ return;
1080
+ items.delete(item);
1081
+ if (items.size > 0)
1082
+ return;
1083
+ const dir = this.path;
1084
+ try {
1085
+ await (0,promises_.readdir)(dir);
1086
+ }
1087
+ catch (err) {
1088
+ if (this._removeWatcher) {
1089
+ this._removeWatcher(external_node_path_.dirname(dir), external_node_path_.basename(dir));
1090
+ }
1091
+ }
1092
+ }
1093
+ has(item) {
1094
+ const { items } = this;
1095
+ if (!items)
1096
+ return;
1097
+ return items.has(item);
1098
+ }
1099
+ getChildren() {
1100
+ const { items } = this;
1101
+ if (!items)
1102
+ return [];
1103
+ return [...items.values()];
1104
+ }
1105
+ dispose() {
1106
+ this.items.clear();
1107
+ this.path = '';
1108
+ this._removeWatcher = EMPTY_FN;
1109
+ this.items = EMPTY_SET;
1110
+ Object.freeze(this);
1111
+ }
1112
+ }
1113
+ const STAT_METHOD_F = 'stat';
1114
+ const STAT_METHOD_L = 'lstat';
1115
+ class WatchHelper {
1116
+ fsw;
1117
+ path;
1118
+ watchPath;
1119
+ fullWatchPath;
1120
+ dirParts;
1121
+ followSymlinks;
1122
+ statMethod;
1123
+ constructor(path, follow, fsw) {
1124
+ this.fsw = fsw;
1125
+ const watchPath = path;
1126
+ this.path = path = path.replace(REPLACER_RE, '');
1127
+ this.watchPath = watchPath;
1128
+ this.fullWatchPath = external_node_path_.resolve(watchPath);
1129
+ this.dirParts = [];
1130
+ this.dirParts.forEach((parts) => {
1131
+ if (parts.length > 1)
1132
+ parts.pop();
1133
+ });
1134
+ this.followSymlinks = follow;
1135
+ this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
1136
+ }
1137
+ entryPath(entry) {
1138
+ return external_node_path_.join(this.watchPath, external_node_path_.relative(this.watchPath, entry.fullPath));
1139
+ }
1140
+ filterPath(entry) {
1141
+ const { stats } = entry;
1142
+ if (stats && stats.isSymbolicLink())
1143
+ return this.filterDir(entry);
1144
+ const resolvedPath = this.entryPath(entry);
1145
+ // TODO: what if stats is undefined? remove !
1146
+ return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
1147
+ }
1148
+ filterDir(entry) {
1149
+ return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
1150
+ }
1151
+ }
1152
+ /**
1153
+ * Watches files & directories for changes. Emitted events:
1154
+ * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
1155
+ *
1156
+ * new FSWatcher()
1157
+ * .add(directories)
1158
+ * .on('add', path => log('File', path, 'was added'))
1159
+ */
1160
+ class FSWatcher extends external_node_events_.EventEmitter {
1161
+ closed;
1162
+ options;
1163
+ _closers;
1164
+ _ignoredPaths;
1165
+ _throttled;
1166
+ _streams;
1167
+ _symlinkPaths;
1168
+ _watched;
1169
+ _pendingWrites;
1170
+ _pendingUnlinks;
1171
+ _readyCount;
1172
+ _emitReady;
1173
+ _closePromise;
1174
+ _userIgnored;
1175
+ _readyEmitted;
1176
+ _emitRaw;
1177
+ _boundRemove;
1178
+ _nodeFsHandler;
1179
+ // Not indenting methods for history sake; for now.
1180
+ constructor(_opts = {}) {
1181
+ super();
1182
+ this.closed = false;
1183
+ this._closers = new Map();
1184
+ this._ignoredPaths = new Set();
1185
+ this._throttled = new Map();
1186
+ this._streams = new Set();
1187
+ this._symlinkPaths = new Map();
1188
+ this._watched = new Map();
1189
+ this._pendingWrites = new Map();
1190
+ this._pendingUnlinks = new Map();
1191
+ this._readyCount = 0;
1192
+ this._readyEmitted = false;
1193
+ const awf = _opts.awaitWriteFinish;
1194
+ const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
1195
+ const opts = {
1196
+ // Defaults
1197
+ persistent: true,
1198
+ ignoreInitial: false,
1199
+ ignorePermissionErrors: false,
1200
+ interval: 100,
1201
+ binaryInterval: 300,
1202
+ followSymlinks: true,
1203
+ usePolling: false,
1204
+ // useAsync: false,
1205
+ atomic: true, // NOTE: overwritten later (depends on usePolling)
1206
+ ..._opts,
1207
+ // Change format
1208
+ ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
1209
+ awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
1210
+ };
1211
+ // Always default to polling on IBM i because fs.watch() is not available on IBM i.
1212
+ if (isIBMi)
1213
+ opts.usePolling = true;
1214
+ // Editor atomic write normalization enabled by default with fs.watch
1215
+ if (opts.atomic === undefined)
1216
+ opts.atomic = !opts.usePolling;
1217
+ // opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
1218
+ // Global override. Useful for developers, who need to force polling for all
1219
+ // instances of chokidar, regardless of usage / dependency depth
1220
+ const envPoll = process.env.CHOKIDAR_USEPOLLING;
1221
+ if (envPoll !== undefined) {
1222
+ const envLower = envPoll.toLowerCase();
1223
+ if (envLower === 'false' || envLower === '0')
1224
+ opts.usePolling = false;
1225
+ else if (envLower === 'true' || envLower === '1')
1226
+ opts.usePolling = true;
1227
+ else
1228
+ opts.usePolling = !!envLower;
1229
+ }
1230
+ const envInterval = process.env.CHOKIDAR_INTERVAL;
1231
+ if (envInterval)
1232
+ opts.interval = Number.parseInt(envInterval, 10);
1233
+ // This is done to emit ready only once, but each 'add' will increase that?
1234
+ let readyCalls = 0;
1235
+ this._emitReady = () => {
1236
+ readyCalls++;
1237
+ if (readyCalls >= this._readyCount) {
1238
+ this._emitReady = EMPTY_FN;
1239
+ this._readyEmitted = true;
1240
+ // use process.nextTick to allow time for listener to be bound
1241
+ process.nextTick(() => this.emit(EVENTS.READY));
1242
+ }
1243
+ };
1244
+ this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
1245
+ this._boundRemove = this._remove.bind(this);
1246
+ this.options = opts;
1247
+ this._nodeFsHandler = new NodeFsHandler(this);
1248
+ // You’re frozen when your heart’s not open.
1249
+ Object.freeze(opts);
1250
+ }
1251
+ _addIgnoredPath(matcher) {
1252
+ if (isMatcherObject(matcher)) {
1253
+ // return early if we already have a deeply equal matcher object
1254
+ for (const ignored of this._ignoredPaths) {
1255
+ if (isMatcherObject(ignored) &&
1256
+ ignored.path === matcher.path &&
1257
+ ignored.recursive === matcher.recursive) {
1258
+ return;
1259
+ }
1260
+ }
1261
+ }
1262
+ this._ignoredPaths.add(matcher);
1263
+ }
1264
+ _removeIgnoredPath(matcher) {
1265
+ this._ignoredPaths.delete(matcher);
1266
+ // now find any matcher objects with the matcher as path
1267
+ if (typeof matcher === 'string') {
1268
+ for (const ignored of this._ignoredPaths) {
1269
+ // TODO (43081j): make this more efficient.
1270
+ // probably just make a `this._ignoredDirectories` or some
1271
+ // such thing.
1272
+ if (isMatcherObject(ignored) && ignored.path === matcher) {
1273
+ this._ignoredPaths.delete(ignored);
1274
+ }
1275
+ }
1276
+ }
1277
+ }
1278
+ // Public methods
1279
+ /**
1280
+ * Adds paths to be watched on an existing FSWatcher instance.
1281
+ * @param paths_ file or file list. Other arguments are unused
1282
+ */
1283
+ add(paths_, _origAdd, _internal) {
1284
+ const { cwd } = this.options;
1285
+ this.closed = false;
1286
+ this._closePromise = undefined;
1287
+ let paths = unifyPaths(paths_);
1288
+ if (cwd) {
1289
+ paths = paths.map((path) => {
1290
+ const absPath = getAbsolutePath(path, cwd);
1291
+ // Check `path` instead of `absPath` because the cwd portion can't be a glob
1292
+ return absPath;
1293
+ });
1294
+ }
1295
+ paths.forEach((path) => {
1296
+ this._removeIgnoredPath(path);
1297
+ });
1298
+ this._userIgnored = undefined;
1299
+ if (!this._readyCount)
1300
+ this._readyCount = 0;
1301
+ this._readyCount += paths.length;
1302
+ Promise.all(paths.map(async (path) => {
1303
+ const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
1304
+ if (res)
1305
+ this._emitReady();
1306
+ return res;
1307
+ })).then((results) => {
1308
+ if (this.closed)
1309
+ return;
1310
+ results.forEach((item) => {
1311
+ if (item)
1312
+ this.add(external_node_path_.dirname(item), external_node_path_.basename(_origAdd || item));
1313
+ });
1314
+ });
1315
+ return this;
1316
+ }
1317
+ /**
1318
+ * Close watchers or start ignoring events from specified paths.
1319
+ */
1320
+ unwatch(paths_) {
1321
+ if (this.closed)
1322
+ return this;
1323
+ const paths = unifyPaths(paths_);
1324
+ const { cwd } = this.options;
1325
+ paths.forEach((path) => {
1326
+ // convert to absolute path unless relative path already matches
1327
+ if (!external_node_path_.isAbsolute(path) && !this._closers.has(path)) {
1328
+ if (cwd)
1329
+ path = external_node_path_.join(cwd, path);
1330
+ path = external_node_path_.resolve(path);
1331
+ }
1332
+ this._closePath(path);
1333
+ this._addIgnoredPath(path);
1334
+ if (this._watched.has(path)) {
1335
+ this._addIgnoredPath({
1336
+ path,
1337
+ recursive: true,
1338
+ });
1339
+ }
1340
+ // reset the cached userIgnored anymatch fn
1341
+ // to make ignoredPaths changes effective
1342
+ this._userIgnored = undefined;
1343
+ });
1344
+ return this;
1345
+ }
1346
+ /**
1347
+ * Close watchers and remove all listeners from watched paths.
1348
+ */
1349
+ close() {
1350
+ if (this._closePromise) {
1351
+ return this._closePromise;
1352
+ }
1353
+ this.closed = true;
1354
+ // Memory management.
1355
+ this.removeAllListeners();
1356
+ const closers = [];
1357
+ this._closers.forEach((closerList) => closerList.forEach((closer) => {
1358
+ const promise = closer();
1359
+ if (promise instanceof Promise)
1360
+ closers.push(promise);
1361
+ }));
1362
+ this._streams.forEach((stream) => stream.destroy());
1363
+ this._userIgnored = undefined;
1364
+ this._readyCount = 0;
1365
+ this._readyEmitted = false;
1366
+ this._watched.forEach((dirent) => dirent.dispose());
1367
+ this._closers.clear();
1368
+ this._watched.clear();
1369
+ this._streams.clear();
1370
+ this._symlinkPaths.clear();
1371
+ this._throttled.clear();
1372
+ this._closePromise = closers.length
1373
+ ? Promise.all(closers).then(() => undefined)
1374
+ : Promise.resolve();
1375
+ return this._closePromise;
1376
+ }
1377
+ /**
1378
+ * Expose list of watched paths
1379
+ * @returns for chaining
1380
+ */
1381
+ getWatched() {
1382
+ const watchList = {};
1383
+ this._watched.forEach((entry, dir) => {
1384
+ const key = this.options.cwd ? external_node_path_.relative(this.options.cwd, dir) : dir;
1385
+ const index = key || ONE_DOT;
1386
+ watchList[index] = entry.getChildren().sort();
1387
+ });
1388
+ return watchList;
1389
+ }
1390
+ emitWithAll(event, args) {
1391
+ this.emit(event, ...args);
1392
+ if (event !== EVENTS.ERROR)
1393
+ this.emit(EVENTS.ALL, event, ...args);
1394
+ }
1395
+ // Common helpers
1396
+ // --------------
1397
+ /**
1398
+ * Normalize and emit events.
1399
+ * Calling _emit DOES NOT MEAN emit() would be called!
1400
+ * @param event Type of event
1401
+ * @param path File or directory path
1402
+ * @param stats arguments to be passed with event
1403
+ * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1404
+ */
1405
+ async _emit(event, path, stats) {
1406
+ if (this.closed)
1407
+ return;
1408
+ const opts = this.options;
1409
+ if (isWindows)
1410
+ path = external_node_path_.normalize(path);
1411
+ if (opts.cwd)
1412
+ path = external_node_path_.relative(opts.cwd, path);
1413
+ const args = [path];
1414
+ if (stats != null)
1415
+ args.push(stats);
1416
+ const awf = opts.awaitWriteFinish;
1417
+ let pw;
1418
+ if (awf && (pw = this._pendingWrites.get(path))) {
1419
+ pw.lastChange = new Date();
1420
+ return this;
1421
+ }
1422
+ if (opts.atomic) {
1423
+ if (event === EVENTS.UNLINK) {
1424
+ this._pendingUnlinks.set(path, [event, ...args]);
1425
+ setTimeout(() => {
1426
+ this._pendingUnlinks.forEach((entry, path) => {
1427
+ this.emit(...entry);
1428
+ this.emit(EVENTS.ALL, ...entry);
1429
+ this._pendingUnlinks.delete(path);
1430
+ });
1431
+ }, typeof opts.atomic === 'number' ? opts.atomic : 100);
1432
+ return this;
1433
+ }
1434
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
1435
+ event = EVENTS.CHANGE;
1436
+ this._pendingUnlinks.delete(path);
1437
+ }
1438
+ }
1439
+ if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
1440
+ const awfEmit = (err, stats) => {
1441
+ if (err) {
1442
+ event = EVENTS.ERROR;
1443
+ args[0] = err;
1444
+ this.emitWithAll(event, args);
1445
+ }
1446
+ else if (stats) {
1447
+ // if stats doesn't exist the file must have been deleted
1448
+ if (args.length > 1) {
1449
+ args[1] = stats;
1450
+ }
1451
+ else {
1452
+ args.push(stats);
1453
+ }
1454
+ this.emitWithAll(event, args);
1455
+ }
1456
+ };
1457
+ this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
1458
+ return this;
1459
+ }
1460
+ if (event === EVENTS.CHANGE) {
1461
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
1462
+ if (isThrottled)
1463
+ return this;
1464
+ }
1465
+ if (opts.alwaysStat &&
1466
+ stats === undefined &&
1467
+ (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
1468
+ const fullPath = opts.cwd ? external_node_path_.join(opts.cwd, path) : path;
1469
+ let stats;
1470
+ try {
1471
+ stats = await (0,promises_.stat)(fullPath);
1472
+ }
1473
+ catch (err) {
1474
+ // do nothing
1475
+ }
1476
+ // Suppress event when fs_stat fails, to avoid sending undefined 'stat'
1477
+ if (!stats || this.closed)
1478
+ return;
1479
+ args.push(stats);
1480
+ }
1481
+ this.emitWithAll(event, args);
1482
+ return this;
1483
+ }
1484
+ /**
1485
+ * Common handler for errors
1486
+ * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1487
+ */
1488
+ _handleError(error) {
1489
+ const code = error && error.code;
1490
+ if (error &&
1491
+ code !== 'ENOENT' &&
1492
+ code !== 'ENOTDIR' &&
1493
+ (!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
1494
+ this.emit(EVENTS.ERROR, error);
1495
+ }
1496
+ return error || this.closed;
1497
+ }
1498
+ /**
1499
+ * Helper utility for throttling
1500
+ * @param actionType type being throttled
1501
+ * @param path being acted upon
1502
+ * @param timeout duration of time to suppress duplicate actions
1503
+ * @returns tracking object or false if action should be suppressed
1504
+ */
1505
+ _throttle(actionType, path, timeout) {
1506
+ if (!this._throttled.has(actionType)) {
1507
+ this._throttled.set(actionType, new Map());
1508
+ }
1509
+ const action = this._throttled.get(actionType);
1510
+ if (!action)
1511
+ throw new Error('invalid throttle');
1512
+ const actionPath = action.get(path);
1513
+ if (actionPath) {
1514
+ actionPath.count++;
1515
+ return false;
1516
+ }
1517
+ // eslint-disable-next-line prefer-const
1518
+ let timeoutObject;
1519
+ const clear = () => {
1520
+ const item = action.get(path);
1521
+ const count = item ? item.count : 0;
1522
+ action.delete(path);
1523
+ clearTimeout(timeoutObject);
1524
+ if (item)
1525
+ clearTimeout(item.timeoutObject);
1526
+ return count;
1527
+ };
1528
+ timeoutObject = setTimeout(clear, timeout);
1529
+ const thr = { timeoutObject, clear, count: 0 };
1530
+ action.set(path, thr);
1531
+ return thr;
1532
+ }
1533
+ _incrReadyCount() {
1534
+ return this._readyCount++;
1535
+ }
1536
+ /**
1537
+ * Awaits write operation to finish.
1538
+ * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
1539
+ * @param path being acted upon
1540
+ * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
1541
+ * @param event
1542
+ * @param awfEmit Callback to be called when ready for event to be emitted.
1543
+ */
1544
+ _awaitWriteFinish(path, threshold, event, awfEmit) {
1545
+ const awf = this.options.awaitWriteFinish;
1546
+ if (typeof awf !== 'object')
1547
+ return;
1548
+ const pollInterval = awf.pollInterval;
1549
+ let timeoutHandler;
1550
+ let fullPath = path;
1551
+ if (this.options.cwd && !external_node_path_.isAbsolute(path)) {
1552
+ fullPath = external_node_path_.join(this.options.cwd, path);
1553
+ }
1554
+ const now = new Date();
1555
+ const writes = this._pendingWrites;
1556
+ function awaitWriteFinishFn(prevStat) {
1557
+ (0,external_node_fs_.stat)(fullPath, (err, curStat) => {
1558
+ if (err || !writes.has(path)) {
1559
+ if (err && err.code !== 'ENOENT')
1560
+ awfEmit(err);
1561
+ return;
1562
+ }
1563
+ const now = Number(new Date());
1564
+ if (prevStat && curStat.size !== prevStat.size) {
1565
+ writes.get(path).lastChange = now;
1566
+ }
1567
+ const pw = writes.get(path);
1568
+ const df = now - pw.lastChange;
1569
+ if (df >= threshold) {
1570
+ writes.delete(path);
1571
+ awfEmit(undefined, curStat);
1572
+ }
1573
+ else {
1574
+ timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
1575
+ }
1576
+ });
1577
+ }
1578
+ if (!writes.has(path)) {
1579
+ writes.set(path, {
1580
+ lastChange: now,
1581
+ cancelWait: () => {
1582
+ writes.delete(path);
1583
+ clearTimeout(timeoutHandler);
1584
+ return event;
1585
+ },
1586
+ });
1587
+ timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
1588
+ }
1589
+ }
1590
+ /**
1591
+ * Determines whether user has asked to ignore this path.
1592
+ */
1593
+ _isIgnored(path, stats) {
1594
+ if (this.options.atomic && DOT_RE.test(path))
1595
+ return true;
1596
+ if (!this._userIgnored) {
1597
+ const { cwd } = this.options;
1598
+ const ign = this.options.ignored;
1599
+ const ignored = (ign || []).map(normalizeIgnored(cwd));
1600
+ const ignoredPaths = [...this._ignoredPaths];
1601
+ const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
1602
+ this._userIgnored = anymatch(list, undefined);
1603
+ }
1604
+ return this._userIgnored(path, stats);
1605
+ }
1606
+ _isntIgnored(path, stat) {
1607
+ return !this._isIgnored(path, stat);
1608
+ }
1609
+ /**
1610
+ * Provides a set of common helpers and properties relating to symlink handling.
1611
+ * @param path file or directory pattern being watched
1612
+ */
1613
+ _getWatchHelpers(path) {
1614
+ return new WatchHelper(path, this.options.followSymlinks, this);
1615
+ }
1616
+ // Directory helpers
1617
+ // -----------------
1618
+ /**
1619
+ * Provides directory tracking objects
1620
+ * @param directory path of the directory
1621
+ */
1622
+ _getWatchedDir(directory) {
1623
+ const dir = external_node_path_.resolve(directory);
1624
+ if (!this._watched.has(dir))
1625
+ this._watched.set(dir, new DirEntry(dir, this._boundRemove));
1626
+ return this._watched.get(dir);
1627
+ }
1628
+ // File helpers
1629
+ // ------------
1630
+ /**
1631
+ * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
1632
+ */
1633
+ _hasReadPermissions(stats) {
1634
+ if (this.options.ignorePermissionErrors)
1635
+ return true;
1636
+ return Boolean(Number(stats.mode) & 0o400);
1637
+ }
1638
+ /**
1639
+ * Handles emitting unlink events for
1640
+ * files and directories, and via recursion, for
1641
+ * files and directories within directories that are unlinked
1642
+ * @param directory within which the following item is located
1643
+ * @param item base path of item/directory
1644
+ */
1645
+ _remove(directory, item, isDirectory) {
1646
+ // if what is being deleted is a directory, get that directory's paths
1647
+ // for recursive deleting and cleaning of watched object
1648
+ // if it is not a directory, nestedDirectoryChildren will be empty array
1649
+ const path = external_node_path_.join(directory, item);
1650
+ const fullPath = external_node_path_.resolve(path);
1651
+ isDirectory =
1652
+ isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
1653
+ // prevent duplicate handling in case of arriving here nearly simultaneously
1654
+ // via multiple paths (such as _handleFile and _handleDir)
1655
+ if (!this._throttle('remove', path, 100))
1656
+ return;
1657
+ // if the only watched file is removed, watch for its return
1658
+ if (!isDirectory && this._watched.size === 1) {
1659
+ this.add(directory, item, true);
1660
+ }
1661
+ // This will create a new entry in the watched object in either case
1662
+ // so we got to do the directory check beforehand
1663
+ const wp = this._getWatchedDir(path);
1664
+ const nestedDirectoryChildren = wp.getChildren();
1665
+ // Recursively remove children directories / files.
1666
+ nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
1667
+ // Check if item was on the watched list and remove it
1668
+ const parent = this._getWatchedDir(directory);
1669
+ const wasTracked = parent.has(item);
1670
+ parent.remove(item);
1671
+ // Fixes issue #1042 -> Relative paths were detected and added as symlinks
1672
+ // (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
1673
+ // but never removed from the map in case the path was deleted.
1674
+ // This leads to an incorrect state if the path was recreated:
1675
+ // https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
1676
+ if (this._symlinkPaths.has(fullPath)) {
1677
+ this._symlinkPaths.delete(fullPath);
1678
+ }
1679
+ // If we wait for this file to be fully written, cancel the wait.
1680
+ let relPath = path;
1681
+ if (this.options.cwd)
1682
+ relPath = external_node_path_.relative(this.options.cwd, path);
1683
+ if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
1684
+ const event = this._pendingWrites.get(relPath).cancelWait();
1685
+ if (event === EVENTS.ADD)
1686
+ return;
1687
+ }
1688
+ // The Entry will either be a directory that just got removed
1689
+ // or a bogus entry to a file, in either case we have to remove it
1690
+ this._watched.delete(path);
1691
+ this._watched.delete(fullPath);
1692
+ const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
1693
+ if (wasTracked && !this._isIgnored(path))
1694
+ this._emit(eventName, path);
1695
+ // Avoid conflicts if we later create another file with the same name
1696
+ this._closePath(path);
1697
+ }
1698
+ /**
1699
+ * Closes all watchers for a path
1700
+ */
1701
+ _closePath(path) {
1702
+ this._closeFile(path);
1703
+ const dir = external_node_path_.dirname(path);
1704
+ this._getWatchedDir(dir).remove(external_node_path_.basename(path));
1705
+ }
1706
+ /**
1707
+ * Closes only file-specific watchers
1708
+ */
1709
+ _closeFile(path) {
1710
+ const closers = this._closers.get(path);
1711
+ if (!closers)
1712
+ return;
1713
+ closers.forEach((closer) => closer());
1714
+ this._closers.delete(path);
1715
+ }
1716
+ _addPathCloser(path, closer) {
1717
+ if (!closer)
1718
+ return;
1719
+ let list = this._closers.get(path);
1720
+ if (!list) {
1721
+ list = [];
1722
+ this._closers.set(path, list);
1723
+ }
1724
+ list.push(closer);
1725
+ }
1726
+ _readdirp(root, opts) {
1727
+ if (this.closed)
1728
+ return;
1729
+ const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
1730
+ let stream = readdirp(root, options);
1731
+ this._streams.add(stream);
1732
+ stream.once(STR_CLOSE, () => {
1733
+ stream = undefined;
1734
+ });
1735
+ stream.once(STR_END, () => {
1736
+ if (stream) {
1737
+ this._streams.delete(stream);
1738
+ stream = undefined;
1739
+ }
1740
+ });
1741
+ return stream;
1742
+ }
1743
+ }
1744
+ /**
1745
+ * Instantiates watcher with paths to be tracked.
1746
+ * @param paths file / directory paths
1747
+ * @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
1748
+ * @returns an instance of FSWatcher for chaining.
1749
+ * @example
1750
+ * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
1751
+ * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
1752
+ */
1753
+ function watch(paths, options = {}) {
1754
+ const watcher = new FSWatcher(options);
1755
+ watcher.add(paths);
1756
+ return watcher;
1757
+ }
1758
+ /* export default */ const chokidar = ({ watch: watch, FSWatcher: FSWatcher });
1759
+
1760
+
1761
+ },
1762
+
1763
+ };
1764
+
1765
+ //# sourceMappingURL=190.js.map