create-microact-app 1.0.1

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 (213) hide show
  1. package/index.js +95 -0
  2. package/package.json +21 -0
  3. package/templates/vanilla/.github/workflows/deploy.yml +38 -0
  4. package/templates/vanilla/index.html +13 -0
  5. package/templates/vanilla/node_modules/.package-lock.json +207 -0
  6. package/templates/vanilla/node_modules/@esbuild/darwin-x64/README.md +3 -0
  7. package/templates/vanilla/node_modules/@esbuild/darwin-x64/bin/esbuild +0 -0
  8. package/templates/vanilla/node_modules/@esbuild/darwin-x64/package.json +17 -0
  9. package/templates/vanilla/node_modules/@monygroupcorp/microact/README.md +154 -0
  10. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.cjs.js +1749 -0
  11. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.cjs.js.map +1 -0
  12. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.esm.js +1743 -0
  13. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.esm.js.map +1 -0
  14. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.umd.js +2 -0
  15. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.umd.js.map +1 -0
  16. package/templates/vanilla/node_modules/@monygroupcorp/microact/example/index.html +13 -0
  17. package/templates/vanilla/node_modules/@monygroupcorp/microact/example/index.js +63 -0
  18. package/templates/vanilla/node_modules/@monygroupcorp/microact/package.json +38 -0
  19. package/templates/vanilla/node_modules/@monygroupcorp/microact/rollup.config.cjs +30 -0
  20. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/Component.js +831 -0
  21. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/DOMUpdater.js +320 -0
  22. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/EventBus.js +123 -0
  23. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/Router.js +253 -0
  24. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/UpdateScheduler.js +218 -0
  25. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/index.js +6 -0
  26. package/templates/vanilla/node_modules/esbuild/LICENSE.md +21 -0
  27. package/templates/vanilla/node_modules/esbuild/README.md +3 -0
  28. package/templates/vanilla/node_modules/esbuild/bin/esbuild +0 -0
  29. package/templates/vanilla/node_modules/esbuild/install.js +287 -0
  30. package/templates/vanilla/node_modules/esbuild/lib/main.d.ts +660 -0
  31. package/templates/vanilla/node_modules/esbuild/lib/main.js +2393 -0
  32. package/templates/vanilla/node_modules/esbuild/package.json +42 -0
  33. package/templates/vanilla/node_modules/nanoid/LICENSE +20 -0
  34. package/templates/vanilla/node_modules/nanoid/README.md +39 -0
  35. package/templates/vanilla/node_modules/nanoid/async/index.browser.cjs +69 -0
  36. package/templates/vanilla/node_modules/nanoid/async/index.browser.js +34 -0
  37. package/templates/vanilla/node_modules/nanoid/async/index.cjs +71 -0
  38. package/templates/vanilla/node_modules/nanoid/async/index.d.ts +56 -0
  39. package/templates/vanilla/node_modules/nanoid/async/index.js +35 -0
  40. package/templates/vanilla/node_modules/nanoid/async/index.native.js +26 -0
  41. package/templates/vanilla/node_modules/nanoid/async/package.json +12 -0
  42. package/templates/vanilla/node_modules/nanoid/bin/nanoid.cjs +55 -0
  43. package/templates/vanilla/node_modules/nanoid/index.browser.cjs +72 -0
  44. package/templates/vanilla/node_modules/nanoid/index.browser.js +34 -0
  45. package/templates/vanilla/node_modules/nanoid/index.cjs +85 -0
  46. package/templates/vanilla/node_modules/nanoid/index.d.cts +91 -0
  47. package/templates/vanilla/node_modules/nanoid/index.d.ts +91 -0
  48. package/templates/vanilla/node_modules/nanoid/index.js +45 -0
  49. package/templates/vanilla/node_modules/nanoid/nanoid.js +1 -0
  50. package/templates/vanilla/node_modules/nanoid/non-secure/index.cjs +34 -0
  51. package/templates/vanilla/node_modules/nanoid/non-secure/index.d.ts +33 -0
  52. package/templates/vanilla/node_modules/nanoid/non-secure/index.js +21 -0
  53. package/templates/vanilla/node_modules/nanoid/non-secure/package.json +6 -0
  54. package/templates/vanilla/node_modules/nanoid/package.json +89 -0
  55. package/templates/vanilla/node_modules/nanoid/url-alphabet/index.cjs +7 -0
  56. package/templates/vanilla/node_modules/nanoid/url-alphabet/index.js +3 -0
  57. package/templates/vanilla/node_modules/nanoid/url-alphabet/package.json +6 -0
  58. package/templates/vanilla/node_modules/picocolors/LICENSE +15 -0
  59. package/templates/vanilla/node_modules/picocolors/README.md +21 -0
  60. package/templates/vanilla/node_modules/picocolors/package.json +25 -0
  61. package/templates/vanilla/node_modules/picocolors/picocolors.browser.js +4 -0
  62. package/templates/vanilla/node_modules/picocolors/picocolors.d.ts +5 -0
  63. package/templates/vanilla/node_modules/picocolors/picocolors.js +75 -0
  64. package/templates/vanilla/node_modules/picocolors/types.d.ts +51 -0
  65. package/templates/vanilla/node_modules/postcss/LICENSE +20 -0
  66. package/templates/vanilla/node_modules/postcss/README.md +29 -0
  67. package/templates/vanilla/node_modules/postcss/lib/at-rule.d.ts +140 -0
  68. package/templates/vanilla/node_modules/postcss/lib/at-rule.js +25 -0
  69. package/templates/vanilla/node_modules/postcss/lib/comment.d.ts +68 -0
  70. package/templates/vanilla/node_modules/postcss/lib/comment.js +13 -0
  71. package/templates/vanilla/node_modules/postcss/lib/container.d.ts +483 -0
  72. package/templates/vanilla/node_modules/postcss/lib/container.js +447 -0
  73. package/templates/vanilla/node_modules/postcss/lib/css-syntax-error.d.ts +248 -0
  74. package/templates/vanilla/node_modules/postcss/lib/css-syntax-error.js +133 -0
  75. package/templates/vanilla/node_modules/postcss/lib/declaration.d.ts +151 -0
  76. package/templates/vanilla/node_modules/postcss/lib/declaration.js +24 -0
  77. package/templates/vanilla/node_modules/postcss/lib/document.d.ts +69 -0
  78. package/templates/vanilla/node_modules/postcss/lib/document.js +33 -0
  79. package/templates/vanilla/node_modules/postcss/lib/fromJSON.d.ts +9 -0
  80. package/templates/vanilla/node_modules/postcss/lib/fromJSON.js +54 -0
  81. package/templates/vanilla/node_modules/postcss/lib/input.d.ts +227 -0
  82. package/templates/vanilla/node_modules/postcss/lib/input.js +265 -0
  83. package/templates/vanilla/node_modules/postcss/lib/lazy-result.d.ts +190 -0
  84. package/templates/vanilla/node_modules/postcss/lib/lazy-result.js +550 -0
  85. package/templates/vanilla/node_modules/postcss/lib/list.d.ts +60 -0
  86. package/templates/vanilla/node_modules/postcss/lib/list.js +58 -0
  87. package/templates/vanilla/node_modules/postcss/lib/map-generator.js +368 -0
  88. package/templates/vanilla/node_modules/postcss/lib/no-work-result.d.ts +46 -0
  89. package/templates/vanilla/node_modules/postcss/lib/no-work-result.js +138 -0
  90. package/templates/vanilla/node_modules/postcss/lib/node.d.ts +556 -0
  91. package/templates/vanilla/node_modules/postcss/lib/node.js +449 -0
  92. package/templates/vanilla/node_modules/postcss/lib/parse.d.ts +9 -0
  93. package/templates/vanilla/node_modules/postcss/lib/parse.js +42 -0
  94. package/templates/vanilla/node_modules/postcss/lib/parser.js +611 -0
  95. package/templates/vanilla/node_modules/postcss/lib/postcss.d.mts +69 -0
  96. package/templates/vanilla/node_modules/postcss/lib/postcss.d.ts +458 -0
  97. package/templates/vanilla/node_modules/postcss/lib/postcss.js +101 -0
  98. package/templates/vanilla/node_modules/postcss/lib/postcss.mjs +30 -0
  99. package/templates/vanilla/node_modules/postcss/lib/previous-map.d.ts +81 -0
  100. package/templates/vanilla/node_modules/postcss/lib/previous-map.js +144 -0
  101. package/templates/vanilla/node_modules/postcss/lib/processor.d.ts +115 -0
  102. package/templates/vanilla/node_modules/postcss/lib/processor.js +67 -0
  103. package/templates/vanilla/node_modules/postcss/lib/result.d.ts +205 -0
  104. package/templates/vanilla/node_modules/postcss/lib/result.js +42 -0
  105. package/templates/vanilla/node_modules/postcss/lib/root.d.ts +87 -0
  106. package/templates/vanilla/node_modules/postcss/lib/root.js +61 -0
  107. package/templates/vanilla/node_modules/postcss/lib/rule.d.ts +126 -0
  108. package/templates/vanilla/node_modules/postcss/lib/rule.js +27 -0
  109. package/templates/vanilla/node_modules/postcss/lib/stringifier.d.ts +46 -0
  110. package/templates/vanilla/node_modules/postcss/lib/stringifier.js +353 -0
  111. package/templates/vanilla/node_modules/postcss/lib/stringify.d.ts +9 -0
  112. package/templates/vanilla/node_modules/postcss/lib/stringify.js +11 -0
  113. package/templates/vanilla/node_modules/postcss/lib/symbols.js +5 -0
  114. package/templates/vanilla/node_modules/postcss/lib/terminal-highlight.js +70 -0
  115. package/templates/vanilla/node_modules/postcss/lib/tokenize.js +266 -0
  116. package/templates/vanilla/node_modules/postcss/lib/warn-once.js +13 -0
  117. package/templates/vanilla/node_modules/postcss/lib/warning.d.ts +147 -0
  118. package/templates/vanilla/node_modules/postcss/lib/warning.js +37 -0
  119. package/templates/vanilla/node_modules/postcss/package.json +88 -0
  120. package/templates/vanilla/node_modules/rollup/LICENSE.md +695 -0
  121. package/templates/vanilla/node_modules/rollup/README.md +125 -0
  122. package/templates/vanilla/node_modules/rollup/dist/bin/rollup +1715 -0
  123. package/templates/vanilla/node_modules/rollup/dist/es/getLogFilter.js +64 -0
  124. package/templates/vanilla/node_modules/rollup/dist/es/package.json +1 -0
  125. package/templates/vanilla/node_modules/rollup/dist/es/rollup.js +17 -0
  126. package/templates/vanilla/node_modules/rollup/dist/es/shared/node-entry.js +27273 -0
  127. package/templates/vanilla/node_modules/rollup/dist/es/shared/watch.js +4857 -0
  128. package/templates/vanilla/node_modules/rollup/dist/getLogFilter.d.ts +5 -0
  129. package/templates/vanilla/node_modules/rollup/dist/getLogFilter.js +69 -0
  130. package/templates/vanilla/node_modules/rollup/dist/loadConfigFile.d.ts +20 -0
  131. package/templates/vanilla/node_modules/rollup/dist/loadConfigFile.js +29 -0
  132. package/templates/vanilla/node_modules/rollup/dist/rollup.d.ts +1012 -0
  133. package/templates/vanilla/node_modules/rollup/dist/rollup.js +31 -0
  134. package/templates/vanilla/node_modules/rollup/dist/shared/fsevents-importer.js +37 -0
  135. package/templates/vanilla/node_modules/rollup/dist/shared/index.js +4571 -0
  136. package/templates/vanilla/node_modules/rollup/dist/shared/loadConfigFile.js +546 -0
  137. package/templates/vanilla/node_modules/rollup/dist/shared/rollup.js +27351 -0
  138. package/templates/vanilla/node_modules/rollup/dist/shared/watch-cli.js +561 -0
  139. package/templates/vanilla/node_modules/rollup/dist/shared/watch-proxy.js +87 -0
  140. package/templates/vanilla/node_modules/rollup/dist/shared/watch.js +316 -0
  141. package/templates/vanilla/node_modules/rollup/package.json +181 -0
  142. package/templates/vanilla/node_modules/source-map-js/LICENSE +28 -0
  143. package/templates/vanilla/node_modules/source-map-js/README.md +765 -0
  144. package/templates/vanilla/node_modules/source-map-js/lib/array-set.js +121 -0
  145. package/templates/vanilla/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  146. package/templates/vanilla/node_modules/source-map-js/lib/base64.js +67 -0
  147. package/templates/vanilla/node_modules/source-map-js/lib/binary-search.js +111 -0
  148. package/templates/vanilla/node_modules/source-map-js/lib/mapping-list.js +79 -0
  149. package/templates/vanilla/node_modules/source-map-js/lib/quick-sort.js +132 -0
  150. package/templates/vanilla/node_modules/source-map-js/lib/source-map-consumer.d.ts +1 -0
  151. package/templates/vanilla/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  152. package/templates/vanilla/node_modules/source-map-js/lib/source-map-generator.d.ts +1 -0
  153. package/templates/vanilla/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  154. package/templates/vanilla/node_modules/source-map-js/lib/source-node.d.ts +1 -0
  155. package/templates/vanilla/node_modules/source-map-js/lib/source-node.js +413 -0
  156. package/templates/vanilla/node_modules/source-map-js/lib/util.js +594 -0
  157. package/templates/vanilla/node_modules/source-map-js/package.json +71 -0
  158. package/templates/vanilla/node_modules/source-map-js/source-map.d.ts +104 -0
  159. package/templates/vanilla/node_modules/source-map-js/source-map.js +8 -0
  160. package/templates/vanilla/node_modules/vite/LICENSE.md +3396 -0
  161. package/templates/vanilla/node_modules/vite/README.md +20 -0
  162. package/templates/vanilla/node_modules/vite/bin/openChrome.applescript +95 -0
  163. package/templates/vanilla/node_modules/vite/bin/vite.js +61 -0
  164. package/templates/vanilla/node_modules/vite/client.d.ts +281 -0
  165. package/templates/vanilla/node_modules/vite/dist/client/client.mjs +725 -0
  166. package/templates/vanilla/node_modules/vite/dist/client/client.mjs.map +1 -0
  167. package/templates/vanilla/node_modules/vite/dist/client/env.mjs +30 -0
  168. package/templates/vanilla/node_modules/vite/dist/client/env.mjs.map +1 -0
  169. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-7ec6f216.js +914 -0
  170. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-827b23df.js +66713 -0
  171. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-c423598f.js +561 -0
  172. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-f0c7dae0.js +7930 -0
  173. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-f1e8587f.js +7646 -0
  174. package/templates/vanilla/node_modules/vite/dist/node/cli.js +929 -0
  175. package/templates/vanilla/node_modules/vite/dist/node/constants.js +130 -0
  176. package/templates/vanilla/node_modules/vite/dist/node/index.d.ts +3548 -0
  177. package/templates/vanilla/node_modules/vite/dist/node/index.js +158 -0
  178. package/templates/vanilla/node_modules/vite/dist/node-cjs/publicUtils.cjs +4555 -0
  179. package/templates/vanilla/node_modules/vite/index.cjs +34 -0
  180. package/templates/vanilla/node_modules/vite/package.json +173 -0
  181. package/templates/vanilla/node_modules/vite/types/customEvent.d.ts +35 -0
  182. package/templates/vanilla/node_modules/vite/types/hmrPayload.d.ts +61 -0
  183. package/templates/vanilla/node_modules/vite/types/hot.d.ts +32 -0
  184. package/templates/vanilla/node_modules/vite/types/importGlob.d.ts +97 -0
  185. package/templates/vanilla/node_modules/vite/types/importMeta.d.ts +26 -0
  186. package/templates/vanilla/node_modules/vite/types/metadata.d.ts +10 -0
  187. package/templates/vanilla/node_modules/vite/types/package.json +4 -0
  188. package/templates/vanilla/package-lock.json +589 -0
  189. package/templates/vanilla/package.json +17 -0
  190. package/templates/vanilla/src/components/App.js +60 -0
  191. package/templates/vanilla/src/components/Card.js +21 -0
  192. package/templates/vanilla/src/components/Hero.js +15 -0
  193. package/templates/vanilla/src/components/InteractiveDemo.js +59 -0
  194. package/templates/vanilla/src/main.js +9 -0
  195. package/templates/vanilla/src/style/main.css +172 -0
  196. package/templates/vanilla/vite.config.js +8 -0
  197. package/templates/web3/.env.example +15 -0
  198. package/templates/web3/.github/workflows/deploy.yml +38 -0
  199. package/templates/web3/README.md +33 -0
  200. package/templates/web3/contracts/foundry.toml +11 -0
  201. package/templates/web3/contracts/script/Deploy.s.sol +13 -0
  202. package/templates/web3/contracts/src/Counter.sol +21 -0
  203. package/templates/web3/index.html +13 -0
  204. package/templates/web3/package.json +25 -0
  205. package/templates/web3/scripts/chain-start.mjs +305 -0
  206. package/templates/web3/scripts/chain-stop.mjs +34 -0
  207. package/templates/web3/scripts/deploy.mjs +155 -0
  208. package/templates/web3/scripts/setup.mjs +42 -0
  209. package/templates/web3/src/components/App.js +49 -0
  210. package/templates/web3/src/components/CounterCard.js +111 -0
  211. package/templates/web3/src/main.js +54 -0
  212. package/templates/web3/src/style/main.css +345 -0
  213. package/templates/web3/vite.config.js +29 -0
@@ -0,0 +1,4857 @@
1
+ /*
2
+ @license
3
+ Rollup.js v3.29.4
4
+ Sat, 21 Sep 2024 06:29:06 GMT - commit 2ef77c00ec2635d42697cff2c0567ccc8db34fb4
5
+
6
+ https://github.com/rollup/rollup
7
+
8
+ Released under the MIT License.
9
+ */
10
+ import { resolve } from 'node:path';
11
+ import process$1 from 'node:process';
12
+ import { picomatch as picomatch$2, getAugmentedNamespace, fseventsImporter, createFilter, rollupInternal } from './node-entry.js';
13
+ import { platform } from 'node:os';
14
+ import require$$0$1 from 'fs';
15
+ import require$$2 from 'util';
16
+ import require$$1 from 'stream';
17
+ import require$$0$2 from 'path';
18
+ import require$$2$1 from 'os';
19
+ import require$$0$3 from 'events';
20
+ import 'node:perf_hooks';
21
+ import 'node:crypto';
22
+ import 'node:fs/promises';
23
+ import 'tty';
24
+
25
+ var chokidar = {};
26
+
27
+ const fs$3 = require$$0$1;
28
+ const { Readable } = require$$1;
29
+ const sysPath$3 = require$$0$2;
30
+ const { promisify: promisify$3 } = require$$2;
31
+ const picomatch$1 = picomatch$2;
32
+
33
+ const readdir$1 = promisify$3(fs$3.readdir);
34
+ const stat$3 = promisify$3(fs$3.stat);
35
+ const lstat$2 = promisify$3(fs$3.lstat);
36
+ const realpath$1 = promisify$3(fs$3.realpath);
37
+
38
+ /**
39
+ * @typedef {Object} EntryInfo
40
+ * @property {String} path
41
+ * @property {String} fullPath
42
+ * @property {fs.Stats=} stats
43
+ * @property {fs.Dirent=} dirent
44
+ * @property {String} basename
45
+ */
46
+
47
+ const BANG$2 = '!';
48
+ const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
49
+ const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
50
+ const FILE_TYPE = 'files';
51
+ const DIR_TYPE = 'directories';
52
+ const FILE_DIR_TYPE = 'files_directories';
53
+ const EVERYTHING_TYPE = 'all';
54
+ const ALL_TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE];
55
+
56
+ const isNormalFlowError = error => NORMAL_FLOW_ERRORS.has(error.code);
57
+ const [maj, min] = process.versions.node.split('.').slice(0, 2).map(n => Number.parseInt(n, 10));
58
+ const wantBigintFsStats = process.platform === 'win32' && (maj > 10 || (maj === 10 && min >= 5));
59
+
60
+ const normalizeFilter = filter => {
61
+ if (filter === undefined) return;
62
+ if (typeof filter === 'function') return filter;
63
+
64
+ if (typeof filter === 'string') {
65
+ const glob = picomatch$1(filter.trim());
66
+ return entry => glob(entry.basename);
67
+ }
68
+
69
+ if (Array.isArray(filter)) {
70
+ const positive = [];
71
+ const negative = [];
72
+ for (const item of filter) {
73
+ const trimmed = item.trim();
74
+ if (trimmed.charAt(0) === BANG$2) {
75
+ negative.push(picomatch$1(trimmed.slice(1)));
76
+ } else {
77
+ positive.push(picomatch$1(trimmed));
78
+ }
79
+ }
80
+
81
+ if (negative.length > 0) {
82
+ if (positive.length > 0) {
83
+ return entry =>
84
+ positive.some(f => f(entry.basename)) && !negative.some(f => f(entry.basename));
85
+ }
86
+ return entry => !negative.some(f => f(entry.basename));
87
+ }
88
+ return entry => positive.some(f => f(entry.basename));
89
+ }
90
+ };
91
+
92
+ class ReaddirpStream extends Readable {
93
+ static get defaultOptions() {
94
+ return {
95
+ root: '.',
96
+ /* eslint-disable no-unused-vars */
97
+ fileFilter: (path) => true,
98
+ directoryFilter: (path) => true,
99
+ /* eslint-enable no-unused-vars */
100
+ type: FILE_TYPE,
101
+ lstat: false,
102
+ depth: 2147483648,
103
+ alwaysStat: false
104
+ };
105
+ }
106
+
107
+ constructor(options = {}) {
108
+ super({
109
+ objectMode: true,
110
+ autoDestroy: true,
111
+ highWaterMark: options.highWaterMark || 4096
112
+ });
113
+ const opts = { ...ReaddirpStream.defaultOptions, ...options };
114
+ const { root, type } = opts;
115
+
116
+ this._fileFilter = normalizeFilter(opts.fileFilter);
117
+ this._directoryFilter = normalizeFilter(opts.directoryFilter);
118
+
119
+ const statMethod = opts.lstat ? lstat$2 : stat$3;
120
+ // Use bigint stats if it's windows and stat() supports options (node 10+).
121
+ if (wantBigintFsStats) {
122
+ this._stat = path => statMethod(path, { bigint: true });
123
+ } else {
124
+ this._stat = statMethod;
125
+ }
126
+
127
+ this._maxDepth = opts.depth;
128
+ this._wantsDir = [DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE].includes(type);
129
+ this._wantsFile = [FILE_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE].includes(type);
130
+ this._wantsEverything = type === EVERYTHING_TYPE;
131
+ this._root = sysPath$3.resolve(root);
132
+ this._isDirent = ('Dirent' in fs$3) && !opts.alwaysStat;
133
+ this._statsProp = this._isDirent ? 'dirent' : 'stats';
134
+ this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
135
+
136
+ // Launch stream with one parent, the root dir.
137
+ this.parents = [this._exploreDir(root, 1)];
138
+ this.reading = false;
139
+ this.parent = undefined;
140
+ }
141
+
142
+ async _read(batch) {
143
+ if (this.reading) return;
144
+ this.reading = true;
145
+
146
+ try {
147
+ while (!this.destroyed && batch > 0) {
148
+ const { path, depth, files = [] } = this.parent || {};
149
+
150
+ if (files.length > 0) {
151
+ const slice = files.splice(0, batch).map(dirent => this._formatEntry(dirent, path));
152
+ for (const entry of await Promise.all(slice)) {
153
+ if (this.destroyed) return;
154
+
155
+ const entryType = await this._getEntryType(entry);
156
+ if (entryType === 'directory' && this._directoryFilter(entry)) {
157
+ if (depth <= this._maxDepth) {
158
+ this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
159
+ }
160
+
161
+ if (this._wantsDir) {
162
+ this.push(entry);
163
+ batch--;
164
+ }
165
+ } else if ((entryType === 'file' || this._includeAsFile(entry)) && this._fileFilter(entry)) {
166
+ if (this._wantsFile) {
167
+ this.push(entry);
168
+ batch--;
169
+ }
170
+ }
171
+ }
172
+ } else {
173
+ const parent = this.parents.pop();
174
+ if (!parent) {
175
+ this.push(null);
176
+ break;
177
+ }
178
+ this.parent = await parent;
179
+ if (this.destroyed) return;
180
+ }
181
+ }
182
+ } catch (error) {
183
+ this.destroy(error);
184
+ } finally {
185
+ this.reading = false;
186
+ }
187
+ }
188
+
189
+ async _exploreDir(path, depth) {
190
+ let files;
191
+ try {
192
+ files = await readdir$1(path, this._rdOptions);
193
+ } catch (error) {
194
+ this._onError(error);
195
+ }
196
+ return { files, depth, path };
197
+ }
198
+
199
+ async _formatEntry(dirent, path) {
200
+ let entry;
201
+ try {
202
+ const basename = this._isDirent ? dirent.name : dirent;
203
+ const fullPath = sysPath$3.resolve(sysPath$3.join(path, basename));
204
+ entry = { path: sysPath$3.relative(this._root, fullPath), fullPath, basename };
205
+ entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
206
+ } catch (err) {
207
+ this._onError(err);
208
+ }
209
+ return entry;
210
+ }
211
+
212
+ _onError(err) {
213
+ if (isNormalFlowError(err) && !this.destroyed) {
214
+ this.emit('warn', err);
215
+ } else {
216
+ this.destroy(err);
217
+ }
218
+ }
219
+
220
+ async _getEntryType(entry) {
221
+ // entry may be undefined, because a warning or an error were emitted
222
+ // and the statsProp is undefined
223
+ const stats = entry && entry[this._statsProp];
224
+ if (!stats) {
225
+ return;
226
+ }
227
+ if (stats.isFile()) {
228
+ return 'file';
229
+ }
230
+ if (stats.isDirectory()) {
231
+ return 'directory';
232
+ }
233
+ if (stats && stats.isSymbolicLink()) {
234
+ const full = entry.fullPath;
235
+ try {
236
+ const entryRealPath = await realpath$1(full);
237
+ const entryRealPathStats = await lstat$2(entryRealPath);
238
+ if (entryRealPathStats.isFile()) {
239
+ return 'file';
240
+ }
241
+ if (entryRealPathStats.isDirectory()) {
242
+ const len = entryRealPath.length;
243
+ if (full.startsWith(entryRealPath) && full.substr(len, 1) === sysPath$3.sep) {
244
+ const recursiveError = new Error(
245
+ `Circular symlink detected: "${full}" points to "${entryRealPath}"`
246
+ );
247
+ recursiveError.code = RECURSIVE_ERROR_CODE;
248
+ return this._onError(recursiveError);
249
+ }
250
+ return 'directory';
251
+ }
252
+ } catch (error) {
253
+ this._onError(error);
254
+ }
255
+ }
256
+ }
257
+
258
+ _includeAsFile(entry) {
259
+ const stats = entry && entry[this._statsProp];
260
+
261
+ return stats && this._wantsEverything && !stats.isDirectory();
262
+ }
263
+ }
264
+
265
+ /**
266
+ * @typedef {Object} ReaddirpArguments
267
+ * @property {Function=} fileFilter
268
+ * @property {Function=} directoryFilter
269
+ * @property {String=} type
270
+ * @property {Number=} depth
271
+ * @property {String=} root
272
+ * @property {Boolean=} lstat
273
+ * @property {Boolean=} bigint
274
+ */
275
+
276
+ /**
277
+ * Main function which ends up calling readdirRec and reads all files and directories in given root recursively.
278
+ * @param {String} root Root directory
279
+ * @param {ReaddirpArguments=} options Options to specify root (start directory), filters and recursion depth
280
+ */
281
+ const readdirp$1 = (root, options = {}) => {
282
+ let type = options.entryType || options.type;
283
+ if (type === 'both') type = FILE_DIR_TYPE; // backwards-compatibility
284
+ if (type) options.type = type;
285
+ if (!root) {
286
+ throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
287
+ } else if (typeof root !== 'string') {
288
+ throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
289
+ } else if (type && !ALL_TYPES.includes(type)) {
290
+ throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
291
+ }
292
+
293
+ options.root = root;
294
+ return new ReaddirpStream(options);
295
+ };
296
+
297
+ const readdirpPromise = (root, options = {}) => {
298
+ return new Promise((resolve, reject) => {
299
+ const files = [];
300
+ readdirp$1(root, options)
301
+ .on('data', entry => files.push(entry))
302
+ .on('end', () => resolve(files))
303
+ .on('error', error => reject(error));
304
+ });
305
+ };
306
+
307
+ readdirp$1.promise = readdirpPromise;
308
+ readdirp$1.ReaddirpStream = ReaddirpStream;
309
+ readdirp$1.default = readdirp$1;
310
+
311
+ var readdirp_1 = readdirp$1;
312
+
313
+ var anymatch$2 = {exports: {}};
314
+
315
+ /*!
316
+ * normalize-path <https://github.com/jonschlinkert/normalize-path>
317
+ *
318
+ * Copyright (c) 2014-2018, Jon Schlinkert.
319
+ * Released under the MIT License.
320
+ */
321
+
322
+ var normalizePath$2 = function(path, stripTrailing) {
323
+ if (typeof path !== 'string') {
324
+ throw new TypeError('expected path to be a string');
325
+ }
326
+
327
+ if (path === '\\' || path === '/') return '/';
328
+
329
+ var len = path.length;
330
+ if (len <= 1) return path;
331
+
332
+ // ensure that win32 namespaces has two leading slashes, so that the path is
333
+ // handled properly by the win32 version of path.parse() after being normalized
334
+ // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
335
+ var prefix = '';
336
+ if (len > 4 && path[3] === '\\') {
337
+ var ch = path[2];
338
+ if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
339
+ path = path.slice(2);
340
+ prefix = '//';
341
+ }
342
+ }
343
+
344
+ var segs = path.split(/[/\\]+/);
345
+ if (stripTrailing !== false && segs[segs.length - 1] === '') {
346
+ segs.pop();
347
+ }
348
+ return prefix + segs.join('/');
349
+ };
350
+
351
+ var anymatch_1 = anymatch$2.exports;
352
+
353
+ Object.defineProperty(anymatch_1, "__esModule", { value: true });
354
+
355
+ const picomatch = picomatch$2;
356
+ const normalizePath$1 = normalizePath$2;
357
+
358
+ /**
359
+ * @typedef {(testString: string) => boolean} AnymatchFn
360
+ * @typedef {string|RegExp|AnymatchFn} AnymatchPattern
361
+ * @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
362
+ */
363
+ const BANG$1 = '!';
364
+ const DEFAULT_OPTIONS = {returnIndex: false};
365
+ const arrify$1 = (item) => Array.isArray(item) ? item : [item];
366
+
367
+ /**
368
+ * @param {AnymatchPattern} matcher
369
+ * @param {object} options
370
+ * @returns {AnymatchFn}
371
+ */
372
+ const createPattern = (matcher, options) => {
373
+ if (typeof matcher === 'function') {
374
+ return matcher;
375
+ }
376
+ if (typeof matcher === 'string') {
377
+ const glob = picomatch(matcher, options);
378
+ return (string) => matcher === string || glob(string);
379
+ }
380
+ if (matcher instanceof RegExp) {
381
+ return (string) => matcher.test(string);
382
+ }
383
+ return (string) => false;
384
+ };
385
+
386
+ /**
387
+ * @param {Array<Function>} patterns
388
+ * @param {Array<Function>} negPatterns
389
+ * @param {String|Array} args
390
+ * @param {Boolean} returnIndex
391
+ * @returns {boolean|number}
392
+ */
393
+ const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
394
+ const isList = Array.isArray(args);
395
+ const _path = isList ? args[0] : args;
396
+ if (!isList && typeof _path !== 'string') {
397
+ throw new TypeError('anymatch: second argument must be a string: got ' +
398
+ Object.prototype.toString.call(_path))
399
+ }
400
+ const path = normalizePath$1(_path, false);
401
+
402
+ for (let index = 0; index < negPatterns.length; index++) {
403
+ const nglob = negPatterns[index];
404
+ if (nglob(path)) {
405
+ return returnIndex ? -1 : false;
406
+ }
407
+ }
408
+
409
+ const applied = isList && [path].concat(args.slice(1));
410
+ for (let index = 0; index < patterns.length; index++) {
411
+ const pattern = patterns[index];
412
+ if (isList ? pattern(...applied) : pattern(path)) {
413
+ return returnIndex ? index : true;
414
+ }
415
+ }
416
+
417
+ return returnIndex ? -1 : false;
418
+ };
419
+
420
+ /**
421
+ * @param {AnymatchMatcher} matchers
422
+ * @param {Array|string} testString
423
+ * @param {object} options
424
+ * @returns {boolean|number|Function}
425
+ */
426
+ const anymatch$1 = (matchers, testString, options = DEFAULT_OPTIONS) => {
427
+ if (matchers == null) {
428
+ throw new TypeError('anymatch: specify first argument');
429
+ }
430
+ const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
431
+ const returnIndex = opts.returnIndex || false;
432
+
433
+ // Early cache for matchers.
434
+ const mtchers = arrify$1(matchers);
435
+ const negatedGlobs = mtchers
436
+ .filter(item => typeof item === 'string' && item.charAt(0) === BANG$1)
437
+ .map(item => item.slice(1))
438
+ .map(item => picomatch(item, opts));
439
+ const patterns = mtchers
440
+ .filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG$1))
441
+ .map(matcher => createPattern(matcher, opts));
442
+
443
+ if (testString == null) {
444
+ return (testString, ri = false) => {
445
+ const returnIndex = typeof ri === 'boolean' ? ri : false;
446
+ return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
447
+ }
448
+ }
449
+
450
+ return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
451
+ };
452
+
453
+ anymatch$1.default = anymatch$1;
454
+ anymatch$2.exports = anymatch$1;
455
+
456
+ var anymatchExports = anymatch$2.exports;
457
+
458
+ /*!
459
+ * is-extglob <https://github.com/jonschlinkert/is-extglob>
460
+ *
461
+ * Copyright (c) 2014-2016, Jon Schlinkert.
462
+ * Licensed under the MIT License.
463
+ */
464
+
465
+ var isExtglob$1 = function isExtglob(str) {
466
+ if (typeof str !== 'string' || str === '') {
467
+ return false;
468
+ }
469
+
470
+ var match;
471
+ while ((match = /(\\).|([@?!+*]\(.*\))/g.exec(str))) {
472
+ if (match[2]) return true;
473
+ str = str.slice(match.index + match[0].length);
474
+ }
475
+
476
+ return false;
477
+ };
478
+
479
+ /*!
480
+ * is-glob <https://github.com/jonschlinkert/is-glob>
481
+ *
482
+ * Copyright (c) 2014-2017, Jon Schlinkert.
483
+ * Released under the MIT License.
484
+ */
485
+
486
+ var isExtglob = isExtglob$1;
487
+ var chars = { '{': '}', '(': ')', '[': ']'};
488
+ var strictCheck = function(str) {
489
+ if (str[0] === '!') {
490
+ return true;
491
+ }
492
+ var index = 0;
493
+ var pipeIndex = -2;
494
+ var closeSquareIndex = -2;
495
+ var closeCurlyIndex = -2;
496
+ var closeParenIndex = -2;
497
+ var backSlashIndex = -2;
498
+ while (index < str.length) {
499
+ if (str[index] === '*') {
500
+ return true;
501
+ }
502
+
503
+ if (str[index + 1] === '?' && /[\].+)]/.test(str[index])) {
504
+ return true;
505
+ }
506
+
507
+ if (closeSquareIndex !== -1 && str[index] === '[' && str[index + 1] !== ']') {
508
+ if (closeSquareIndex < index) {
509
+ closeSquareIndex = str.indexOf(']', index);
510
+ }
511
+ if (closeSquareIndex > index) {
512
+ if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
513
+ return true;
514
+ }
515
+ backSlashIndex = str.indexOf('\\', index);
516
+ if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
517
+ return true;
518
+ }
519
+ }
520
+ }
521
+
522
+ if (closeCurlyIndex !== -1 && str[index] === '{' && str[index + 1] !== '}') {
523
+ closeCurlyIndex = str.indexOf('}', index);
524
+ if (closeCurlyIndex > index) {
525
+ backSlashIndex = str.indexOf('\\', index);
526
+ if (backSlashIndex === -1 || backSlashIndex > closeCurlyIndex) {
527
+ return true;
528
+ }
529
+ }
530
+ }
531
+
532
+ if (closeParenIndex !== -1 && str[index] === '(' && str[index + 1] === '?' && /[:!=]/.test(str[index + 2]) && str[index + 3] !== ')') {
533
+ closeParenIndex = str.indexOf(')', index);
534
+ if (closeParenIndex > index) {
535
+ backSlashIndex = str.indexOf('\\', index);
536
+ if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
537
+ return true;
538
+ }
539
+ }
540
+ }
541
+
542
+ if (pipeIndex !== -1 && str[index] === '(' && str[index + 1] !== '|') {
543
+ if (pipeIndex < index) {
544
+ pipeIndex = str.indexOf('|', index);
545
+ }
546
+ if (pipeIndex !== -1 && str[pipeIndex + 1] !== ')') {
547
+ closeParenIndex = str.indexOf(')', pipeIndex);
548
+ if (closeParenIndex > pipeIndex) {
549
+ backSlashIndex = str.indexOf('\\', pipeIndex);
550
+ if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
551
+ return true;
552
+ }
553
+ }
554
+ }
555
+ }
556
+
557
+ if (str[index] === '\\') {
558
+ var open = str[index + 1];
559
+ index += 2;
560
+ var close = chars[open];
561
+
562
+ if (close) {
563
+ var n = str.indexOf(close, index);
564
+ if (n !== -1) {
565
+ index = n + 1;
566
+ }
567
+ }
568
+
569
+ if (str[index] === '!') {
570
+ return true;
571
+ }
572
+ } else {
573
+ index++;
574
+ }
575
+ }
576
+ return false;
577
+ };
578
+
579
+ var relaxedCheck = function(str) {
580
+ if (str[0] === '!') {
581
+ return true;
582
+ }
583
+ var index = 0;
584
+ while (index < str.length) {
585
+ if (/[*?{}()[\]]/.test(str[index])) {
586
+ return true;
587
+ }
588
+
589
+ if (str[index] === '\\') {
590
+ var open = str[index + 1];
591
+ index += 2;
592
+ var close = chars[open];
593
+
594
+ if (close) {
595
+ var n = str.indexOf(close, index);
596
+ if (n !== -1) {
597
+ index = n + 1;
598
+ }
599
+ }
600
+
601
+ if (str[index] === '!') {
602
+ return true;
603
+ }
604
+ } else {
605
+ index++;
606
+ }
607
+ }
608
+ return false;
609
+ };
610
+
611
+ var isGlob$2 = function isGlob(str, options) {
612
+ if (typeof str !== 'string' || str === '') {
613
+ return false;
614
+ }
615
+
616
+ if (isExtglob(str)) {
617
+ return true;
618
+ }
619
+
620
+ var check = strictCheck;
621
+
622
+ // optionally relax check
623
+ if (options && options.strict === false) {
624
+ check = relaxedCheck;
625
+ }
626
+
627
+ return check(str);
628
+ };
629
+
630
+ var isGlob$1 = isGlob$2;
631
+ var pathPosixDirname = require$$0$2.posix.dirname;
632
+ var isWin32 = require$$2$1.platform() === 'win32';
633
+
634
+ var slash = '/';
635
+ var backslash = /\\/g;
636
+ var enclosure = /[\{\[].*[\}\]]$/;
637
+ var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
638
+ var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
639
+
640
+ /**
641
+ * @param {string} str
642
+ * @param {Object} opts
643
+ * @param {boolean} [opts.flipBackslashes=true]
644
+ * @returns {string}
645
+ */
646
+ var globParent$1 = function globParent(str, opts) {
647
+ var options = Object.assign({ flipBackslashes: true }, opts);
648
+
649
+ // flip windows path separators
650
+ if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
651
+ str = str.replace(backslash, slash);
652
+ }
653
+
654
+ // special case for strings ending in enclosure containing path separator
655
+ if (enclosure.test(str)) {
656
+ str += slash;
657
+ }
658
+
659
+ // preserves full path in case of trailing path separator
660
+ str += 'a';
661
+
662
+ // remove path parts that are globby
663
+ do {
664
+ str = pathPosixDirname(str);
665
+ } while (isGlob$1(str) || globby.test(str));
666
+
667
+ // remove escape chars and return result
668
+ return str.replace(escaped, '$1');
669
+ };
670
+
671
+ var utils$3 = {};
672
+
673
+ (function (exports) {
674
+
675
+ exports.isInteger = num => {
676
+ if (typeof num === 'number') {
677
+ return Number.isInteger(num);
678
+ }
679
+ if (typeof num === 'string' && num.trim() !== '') {
680
+ return Number.isInteger(Number(num));
681
+ }
682
+ return false;
683
+ };
684
+
685
+ /**
686
+ * Find a node of the given type
687
+ */
688
+
689
+ exports.find = (node, type) => node.nodes.find(node => node.type === type);
690
+
691
+ /**
692
+ * Find a node of the given type
693
+ */
694
+
695
+ exports.exceedsLimit = (min, max, step = 1, limit) => {
696
+ if (limit === false) return false;
697
+ if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
698
+ return ((Number(max) - Number(min)) / Number(step)) >= limit;
699
+ };
700
+
701
+ /**
702
+ * Escape the given node with '\\' before node.value
703
+ */
704
+
705
+ exports.escapeNode = (block, n = 0, type) => {
706
+ let node = block.nodes[n];
707
+ if (!node) return;
708
+
709
+ if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
710
+ if (node.escaped !== true) {
711
+ node.value = '\\' + node.value;
712
+ node.escaped = true;
713
+ }
714
+ }
715
+ };
716
+
717
+ /**
718
+ * Returns true if the given brace node should be enclosed in literal braces
719
+ */
720
+
721
+ exports.encloseBrace = node => {
722
+ if (node.type !== 'brace') return false;
723
+ if ((node.commas >> 0 + node.ranges >> 0) === 0) {
724
+ node.invalid = true;
725
+ return true;
726
+ }
727
+ return false;
728
+ };
729
+
730
+ /**
731
+ * Returns true if a brace node is invalid.
732
+ */
733
+
734
+ exports.isInvalidBrace = block => {
735
+ if (block.type !== 'brace') return false;
736
+ if (block.invalid === true || block.dollar) return true;
737
+ if ((block.commas >> 0 + block.ranges >> 0) === 0) {
738
+ block.invalid = true;
739
+ return true;
740
+ }
741
+ if (block.open !== true || block.close !== true) {
742
+ block.invalid = true;
743
+ return true;
744
+ }
745
+ return false;
746
+ };
747
+
748
+ /**
749
+ * Returns true if a node is an open or close node
750
+ */
751
+
752
+ exports.isOpenOrClose = node => {
753
+ if (node.type === 'open' || node.type === 'close') {
754
+ return true;
755
+ }
756
+ return node.open === true || node.close === true;
757
+ };
758
+
759
+ /**
760
+ * Reduce an array of text nodes.
761
+ */
762
+
763
+ exports.reduce = nodes => nodes.reduce((acc, node) => {
764
+ if (node.type === 'text') acc.push(node.value);
765
+ if (node.type === 'range') node.type = 'text';
766
+ return acc;
767
+ }, []);
768
+
769
+ /**
770
+ * Flatten an array
771
+ */
772
+
773
+ exports.flatten = (...args) => {
774
+ const result = [];
775
+ const flat = arr => {
776
+ for (let i = 0; i < arr.length; i++) {
777
+ let ele = arr[i];
778
+ Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
779
+ }
780
+ return result;
781
+ };
782
+ flat(args);
783
+ return result;
784
+ };
785
+ } (utils$3));
786
+
787
+ const utils$2 = utils$3;
788
+
789
+ var stringify$4 = (ast, options = {}) => {
790
+ let stringify = (node, parent = {}) => {
791
+ let invalidBlock = options.escapeInvalid && utils$2.isInvalidBrace(parent);
792
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
793
+ let output = '';
794
+
795
+ if (node.value) {
796
+ if ((invalidBlock || invalidNode) && utils$2.isOpenOrClose(node)) {
797
+ return '\\' + node.value;
798
+ }
799
+ return node.value;
800
+ }
801
+
802
+ if (node.value) {
803
+ return node.value;
804
+ }
805
+
806
+ if (node.nodes) {
807
+ for (let child of node.nodes) {
808
+ output += stringify(child);
809
+ }
810
+ }
811
+ return output;
812
+ };
813
+
814
+ return stringify(ast);
815
+ };
816
+
817
+ /*!
818
+ * is-number <https://github.com/jonschlinkert/is-number>
819
+ *
820
+ * Copyright (c) 2014-present, Jon Schlinkert.
821
+ * Released under the MIT License.
822
+ */
823
+
824
+ var isNumber$2 = function(num) {
825
+ if (typeof num === 'number') {
826
+ return num - num === 0;
827
+ }
828
+ if (typeof num === 'string' && num.trim() !== '') {
829
+ return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
830
+ }
831
+ return false;
832
+ };
833
+
834
+ /*!
835
+ * to-regex-range <https://github.com/micromatch/to-regex-range>
836
+ *
837
+ * Copyright (c) 2015-present, Jon Schlinkert.
838
+ * Released under the MIT License.
839
+ */
840
+
841
+ const isNumber$1 = isNumber$2;
842
+
843
+ const toRegexRange$1 = (min, max, options) => {
844
+ if (isNumber$1(min) === false) {
845
+ throw new TypeError('toRegexRange: expected the first argument to be a number');
846
+ }
847
+
848
+ if (max === void 0 || min === max) {
849
+ return String(min);
850
+ }
851
+
852
+ if (isNumber$1(max) === false) {
853
+ throw new TypeError('toRegexRange: expected the second argument to be a number.');
854
+ }
855
+
856
+ let opts = { relaxZeros: true, ...options };
857
+ if (typeof opts.strictZeros === 'boolean') {
858
+ opts.relaxZeros = opts.strictZeros === false;
859
+ }
860
+
861
+ let relax = String(opts.relaxZeros);
862
+ let shorthand = String(opts.shorthand);
863
+ let capture = String(opts.capture);
864
+ let wrap = String(opts.wrap);
865
+ let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
866
+
867
+ if (toRegexRange$1.cache.hasOwnProperty(cacheKey)) {
868
+ return toRegexRange$1.cache[cacheKey].result;
869
+ }
870
+
871
+ let a = Math.min(min, max);
872
+ let b = Math.max(min, max);
873
+
874
+ if (Math.abs(a - b) === 1) {
875
+ let result = min + '|' + max;
876
+ if (opts.capture) {
877
+ return `(${result})`;
878
+ }
879
+ if (opts.wrap === false) {
880
+ return result;
881
+ }
882
+ return `(?:${result})`;
883
+ }
884
+
885
+ let isPadded = hasPadding(min) || hasPadding(max);
886
+ let state = { min, max, a, b };
887
+ let positives = [];
888
+ let negatives = [];
889
+
890
+ if (isPadded) {
891
+ state.isPadded = isPadded;
892
+ state.maxLen = String(state.max).length;
893
+ }
894
+
895
+ if (a < 0) {
896
+ let newMin = b < 0 ? Math.abs(b) : 1;
897
+ negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
898
+ a = state.a = 0;
899
+ }
900
+
901
+ if (b >= 0) {
902
+ positives = splitToPatterns(a, b, state, opts);
903
+ }
904
+
905
+ state.negatives = negatives;
906
+ state.positives = positives;
907
+ state.result = collatePatterns(negatives, positives);
908
+
909
+ if (opts.capture === true) {
910
+ state.result = `(${state.result})`;
911
+ } else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
912
+ state.result = `(?:${state.result})`;
913
+ }
914
+
915
+ toRegexRange$1.cache[cacheKey] = state;
916
+ return state.result;
917
+ };
918
+
919
+ function collatePatterns(neg, pos, options) {
920
+ let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
921
+ let onlyPositive = filterPatterns(pos, neg, '', false) || [];
922
+ let intersected = filterPatterns(neg, pos, '-?', true) || [];
923
+ let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
924
+ return subpatterns.join('|');
925
+ }
926
+
927
+ function splitToRanges(min, max) {
928
+ let nines = 1;
929
+ let zeros = 1;
930
+
931
+ let stop = countNines(min, nines);
932
+ let stops = new Set([max]);
933
+
934
+ while (min <= stop && stop <= max) {
935
+ stops.add(stop);
936
+ nines += 1;
937
+ stop = countNines(min, nines);
938
+ }
939
+
940
+ stop = countZeros(max + 1, zeros) - 1;
941
+
942
+ while (min < stop && stop <= max) {
943
+ stops.add(stop);
944
+ zeros += 1;
945
+ stop = countZeros(max + 1, zeros) - 1;
946
+ }
947
+
948
+ stops = [...stops];
949
+ stops.sort(compare);
950
+ return stops;
951
+ }
952
+
953
+ /**
954
+ * Convert a range to a regex pattern
955
+ * @param {Number} `start`
956
+ * @param {Number} `stop`
957
+ * @return {String}
958
+ */
959
+
960
+ function rangeToPattern(start, stop, options) {
961
+ if (start === stop) {
962
+ return { pattern: start, count: [], digits: 0 };
963
+ }
964
+
965
+ let zipped = zip(start, stop);
966
+ let digits = zipped.length;
967
+ let pattern = '';
968
+ let count = 0;
969
+
970
+ for (let i = 0; i < digits; i++) {
971
+ let [startDigit, stopDigit] = zipped[i];
972
+
973
+ if (startDigit === stopDigit) {
974
+ pattern += startDigit;
975
+
976
+ } else if (startDigit !== '0' || stopDigit !== '9') {
977
+ pattern += toCharacterClass(startDigit, stopDigit);
978
+
979
+ } else {
980
+ count++;
981
+ }
982
+ }
983
+
984
+ if (count) {
985
+ pattern += options.shorthand === true ? '\\d' : '[0-9]';
986
+ }
987
+
988
+ return { pattern, count: [count], digits };
989
+ }
990
+
991
+ function splitToPatterns(min, max, tok, options) {
992
+ let ranges = splitToRanges(min, max);
993
+ let tokens = [];
994
+ let start = min;
995
+ let prev;
996
+
997
+ for (let i = 0; i < ranges.length; i++) {
998
+ let max = ranges[i];
999
+ let obj = rangeToPattern(String(start), String(max), options);
1000
+ let zeros = '';
1001
+
1002
+ if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
1003
+ if (prev.count.length > 1) {
1004
+ prev.count.pop();
1005
+ }
1006
+
1007
+ prev.count.push(obj.count[0]);
1008
+ prev.string = prev.pattern + toQuantifier(prev.count);
1009
+ start = max + 1;
1010
+ continue;
1011
+ }
1012
+
1013
+ if (tok.isPadded) {
1014
+ zeros = padZeros(max, tok, options);
1015
+ }
1016
+
1017
+ obj.string = zeros + obj.pattern + toQuantifier(obj.count);
1018
+ tokens.push(obj);
1019
+ start = max + 1;
1020
+ prev = obj;
1021
+ }
1022
+
1023
+ return tokens;
1024
+ }
1025
+
1026
+ function filterPatterns(arr, comparison, prefix, intersection, options) {
1027
+ let result = [];
1028
+
1029
+ for (let ele of arr) {
1030
+ let { string } = ele;
1031
+
1032
+ // only push if _both_ are negative...
1033
+ if (!intersection && !contains(comparison, 'string', string)) {
1034
+ result.push(prefix + string);
1035
+ }
1036
+
1037
+ // or _both_ are positive
1038
+ if (intersection && contains(comparison, 'string', string)) {
1039
+ result.push(prefix + string);
1040
+ }
1041
+ }
1042
+ return result;
1043
+ }
1044
+
1045
+ /**
1046
+ * Zip strings
1047
+ */
1048
+
1049
+ function zip(a, b) {
1050
+ let arr = [];
1051
+ for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
1052
+ return arr;
1053
+ }
1054
+
1055
+ function compare(a, b) {
1056
+ return a > b ? 1 : b > a ? -1 : 0;
1057
+ }
1058
+
1059
+ function contains(arr, key, val) {
1060
+ return arr.some(ele => ele[key] === val);
1061
+ }
1062
+
1063
+ function countNines(min, len) {
1064
+ return Number(String(min).slice(0, -len) + '9'.repeat(len));
1065
+ }
1066
+
1067
+ function countZeros(integer, zeros) {
1068
+ return integer - (integer % Math.pow(10, zeros));
1069
+ }
1070
+
1071
+ function toQuantifier(digits) {
1072
+ let [start = 0, stop = ''] = digits;
1073
+ if (stop || start > 1) {
1074
+ return `{${start + (stop ? ',' + stop : '')}}`;
1075
+ }
1076
+ return '';
1077
+ }
1078
+
1079
+ function toCharacterClass(a, b, options) {
1080
+ return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
1081
+ }
1082
+
1083
+ function hasPadding(str) {
1084
+ return /^-?(0+)\d/.test(str);
1085
+ }
1086
+
1087
+ function padZeros(value, tok, options) {
1088
+ if (!tok.isPadded) {
1089
+ return value;
1090
+ }
1091
+
1092
+ let diff = Math.abs(tok.maxLen - String(value).length);
1093
+ let relax = options.relaxZeros !== false;
1094
+
1095
+ switch (diff) {
1096
+ case 0:
1097
+ return '';
1098
+ case 1:
1099
+ return relax ? '0?' : '0';
1100
+ case 2:
1101
+ return relax ? '0{0,2}' : '00';
1102
+ default: {
1103
+ return relax ? `0{0,${diff}}` : `0{${diff}}`;
1104
+ }
1105
+ }
1106
+ }
1107
+
1108
+ /**
1109
+ * Cache
1110
+ */
1111
+
1112
+ toRegexRange$1.cache = {};
1113
+ toRegexRange$1.clearCache = () => (toRegexRange$1.cache = {});
1114
+
1115
+ /**
1116
+ * Expose `toRegexRange`
1117
+ */
1118
+
1119
+ var toRegexRange_1 = toRegexRange$1;
1120
+
1121
+ /*!
1122
+ * fill-range <https://github.com/jonschlinkert/fill-range>
1123
+ *
1124
+ * Copyright (c) 2014-present, Jon Schlinkert.
1125
+ * Licensed under the MIT License.
1126
+ */
1127
+
1128
+ const util = require$$2;
1129
+ const toRegexRange = toRegexRange_1;
1130
+
1131
+ const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
1132
+
1133
+ const transform = toNumber => {
1134
+ return value => toNumber === true ? Number(value) : String(value);
1135
+ };
1136
+
1137
+ const isValidValue = value => {
1138
+ return typeof value === 'number' || (typeof value === 'string' && value !== '');
1139
+ };
1140
+
1141
+ const isNumber = num => Number.isInteger(+num);
1142
+
1143
+ const zeros = input => {
1144
+ let value = `${input}`;
1145
+ let index = -1;
1146
+ if (value[0] === '-') value = value.slice(1);
1147
+ if (value === '0') return false;
1148
+ while (value[++index] === '0');
1149
+ return index > 0;
1150
+ };
1151
+
1152
+ const stringify$3 = (start, end, options) => {
1153
+ if (typeof start === 'string' || typeof end === 'string') {
1154
+ return true;
1155
+ }
1156
+ return options.stringify === true;
1157
+ };
1158
+
1159
+ const pad = (input, maxLength, toNumber) => {
1160
+ if (maxLength > 0) {
1161
+ let dash = input[0] === '-' ? '-' : '';
1162
+ if (dash) input = input.slice(1);
1163
+ input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
1164
+ }
1165
+ if (toNumber === false) {
1166
+ return String(input);
1167
+ }
1168
+ return input;
1169
+ };
1170
+
1171
+ const toMaxLen = (input, maxLength) => {
1172
+ let negative = input[0] === '-' ? '-' : '';
1173
+ if (negative) {
1174
+ input = input.slice(1);
1175
+ maxLength--;
1176
+ }
1177
+ while (input.length < maxLength) input = '0' + input;
1178
+ return negative ? ('-' + input) : input;
1179
+ };
1180
+
1181
+ const toSequence = (parts, options) => {
1182
+ parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1183
+ parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1184
+
1185
+ let prefix = options.capture ? '' : '?:';
1186
+ let positives = '';
1187
+ let negatives = '';
1188
+ let result;
1189
+
1190
+ if (parts.positives.length) {
1191
+ positives = parts.positives.join('|');
1192
+ }
1193
+
1194
+ if (parts.negatives.length) {
1195
+ negatives = `-(${prefix}${parts.negatives.join('|')})`;
1196
+ }
1197
+
1198
+ if (positives && negatives) {
1199
+ result = `${positives}|${negatives}`;
1200
+ } else {
1201
+ result = positives || negatives;
1202
+ }
1203
+
1204
+ if (options.wrap) {
1205
+ return `(${prefix}${result})`;
1206
+ }
1207
+
1208
+ return result;
1209
+ };
1210
+
1211
+ const toRange = (a, b, isNumbers, options) => {
1212
+ if (isNumbers) {
1213
+ return toRegexRange(a, b, { wrap: false, ...options });
1214
+ }
1215
+
1216
+ let start = String.fromCharCode(a);
1217
+ if (a === b) return start;
1218
+
1219
+ let stop = String.fromCharCode(b);
1220
+ return `[${start}-${stop}]`;
1221
+ };
1222
+
1223
+ const toRegex = (start, end, options) => {
1224
+ if (Array.isArray(start)) {
1225
+ let wrap = options.wrap === true;
1226
+ let prefix = options.capture ? '' : '?:';
1227
+ return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
1228
+ }
1229
+ return toRegexRange(start, end, options);
1230
+ };
1231
+
1232
+ const rangeError = (...args) => {
1233
+ return new RangeError('Invalid range arguments: ' + util.inspect(...args));
1234
+ };
1235
+
1236
+ const invalidRange = (start, end, options) => {
1237
+ if (options.strictRanges === true) throw rangeError([start, end]);
1238
+ return [];
1239
+ };
1240
+
1241
+ const invalidStep = (step, options) => {
1242
+ if (options.strictRanges === true) {
1243
+ throw new TypeError(`Expected step "${step}" to be a number`);
1244
+ }
1245
+ return [];
1246
+ };
1247
+
1248
+ const fillNumbers = (start, end, step = 1, options = {}) => {
1249
+ let a = Number(start);
1250
+ let b = Number(end);
1251
+
1252
+ if (!Number.isInteger(a) || !Number.isInteger(b)) {
1253
+ if (options.strictRanges === true) throw rangeError([start, end]);
1254
+ return [];
1255
+ }
1256
+
1257
+ // fix negative zero
1258
+ if (a === 0) a = 0;
1259
+ if (b === 0) b = 0;
1260
+
1261
+ let descending = a > b;
1262
+ let startString = String(start);
1263
+ let endString = String(end);
1264
+ let stepString = String(step);
1265
+ step = Math.max(Math.abs(step), 1);
1266
+
1267
+ let padded = zeros(startString) || zeros(endString) || zeros(stepString);
1268
+ let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
1269
+ let toNumber = padded === false && stringify$3(start, end, options) === false;
1270
+ let format = options.transform || transform(toNumber);
1271
+
1272
+ if (options.toRegex && step === 1) {
1273
+ return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
1274
+ }
1275
+
1276
+ let parts = { negatives: [], positives: [] };
1277
+ let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
1278
+ let range = [];
1279
+ let index = 0;
1280
+
1281
+ while (descending ? a >= b : a <= b) {
1282
+ if (options.toRegex === true && step > 1) {
1283
+ push(a);
1284
+ } else {
1285
+ range.push(pad(format(a, index), maxLen, toNumber));
1286
+ }
1287
+ a = descending ? a - step : a + step;
1288
+ index++;
1289
+ }
1290
+
1291
+ if (options.toRegex === true) {
1292
+ return step > 1
1293
+ ? toSequence(parts, options)
1294
+ : toRegex(range, null, { wrap: false, ...options });
1295
+ }
1296
+
1297
+ return range;
1298
+ };
1299
+
1300
+ const fillLetters = (start, end, step = 1, options = {}) => {
1301
+ if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
1302
+ return invalidRange(start, end, options);
1303
+ }
1304
+
1305
+
1306
+ let format = options.transform || (val => String.fromCharCode(val));
1307
+ let a = `${start}`.charCodeAt(0);
1308
+ let b = `${end}`.charCodeAt(0);
1309
+
1310
+ let descending = a > b;
1311
+ let min = Math.min(a, b);
1312
+ let max = Math.max(a, b);
1313
+
1314
+ if (options.toRegex && step === 1) {
1315
+ return toRange(min, max, false, options);
1316
+ }
1317
+
1318
+ let range = [];
1319
+ let index = 0;
1320
+
1321
+ while (descending ? a >= b : a <= b) {
1322
+ range.push(format(a, index));
1323
+ a = descending ? a - step : a + step;
1324
+ index++;
1325
+ }
1326
+
1327
+ if (options.toRegex === true) {
1328
+ return toRegex(range, null, { wrap: false, options });
1329
+ }
1330
+
1331
+ return range;
1332
+ };
1333
+
1334
+ const fill$2 = (start, end, step, options = {}) => {
1335
+ if (end == null && isValidValue(start)) {
1336
+ return [start];
1337
+ }
1338
+
1339
+ if (!isValidValue(start) || !isValidValue(end)) {
1340
+ return invalidRange(start, end, options);
1341
+ }
1342
+
1343
+ if (typeof step === 'function') {
1344
+ return fill$2(start, end, 1, { transform: step });
1345
+ }
1346
+
1347
+ if (isObject(step)) {
1348
+ return fill$2(start, end, 0, step);
1349
+ }
1350
+
1351
+ let opts = { ...options };
1352
+ if (opts.capture === true) opts.wrap = true;
1353
+ step = step || opts.step || 1;
1354
+
1355
+ if (!isNumber(step)) {
1356
+ if (step != null && !isObject(step)) return invalidStep(step, opts);
1357
+ return fill$2(start, end, 1, step);
1358
+ }
1359
+
1360
+ if (isNumber(start) && isNumber(end)) {
1361
+ return fillNumbers(start, end, step, opts);
1362
+ }
1363
+
1364
+ return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
1365
+ };
1366
+
1367
+ var fillRange = fill$2;
1368
+
1369
+ const fill$1 = fillRange;
1370
+ const utils$1 = utils$3;
1371
+
1372
+ const compile$1 = (ast, options = {}) => {
1373
+ let walk = (node, parent = {}) => {
1374
+ let invalidBlock = utils$1.isInvalidBrace(parent);
1375
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
1376
+ let invalid = invalidBlock === true || invalidNode === true;
1377
+ let prefix = options.escapeInvalid === true ? '\\' : '';
1378
+ let output = '';
1379
+
1380
+ if (node.isOpen === true) {
1381
+ return prefix + node.value;
1382
+ }
1383
+ if (node.isClose === true) {
1384
+ return prefix + node.value;
1385
+ }
1386
+
1387
+ if (node.type === 'open') {
1388
+ return invalid ? (prefix + node.value) : '(';
1389
+ }
1390
+
1391
+ if (node.type === 'close') {
1392
+ return invalid ? (prefix + node.value) : ')';
1393
+ }
1394
+
1395
+ if (node.type === 'comma') {
1396
+ return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
1397
+ }
1398
+
1399
+ if (node.value) {
1400
+ return node.value;
1401
+ }
1402
+
1403
+ if (node.nodes && node.ranges > 0) {
1404
+ let args = utils$1.reduce(node.nodes);
1405
+ let range = fill$1(...args, { ...options, wrap: false, toRegex: true });
1406
+
1407
+ if (range.length !== 0) {
1408
+ return args.length > 1 && range.length > 1 ? `(${range})` : range;
1409
+ }
1410
+ }
1411
+
1412
+ if (node.nodes) {
1413
+ for (let child of node.nodes) {
1414
+ output += walk(child, node);
1415
+ }
1416
+ }
1417
+ return output;
1418
+ };
1419
+
1420
+ return walk(ast);
1421
+ };
1422
+
1423
+ var compile_1 = compile$1;
1424
+
1425
+ const fill = fillRange;
1426
+ const stringify$2 = stringify$4;
1427
+ const utils = utils$3;
1428
+
1429
+ const append = (queue = '', stash = '', enclose = false) => {
1430
+ let result = [];
1431
+
1432
+ queue = [].concat(queue);
1433
+ stash = [].concat(stash);
1434
+
1435
+ if (!stash.length) return queue;
1436
+ if (!queue.length) {
1437
+ return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
1438
+ }
1439
+
1440
+ for (let item of queue) {
1441
+ if (Array.isArray(item)) {
1442
+ for (let value of item) {
1443
+ result.push(append(value, stash, enclose));
1444
+ }
1445
+ } else {
1446
+ for (let ele of stash) {
1447
+ if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
1448
+ result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
1449
+ }
1450
+ }
1451
+ }
1452
+ return utils.flatten(result);
1453
+ };
1454
+
1455
+ const expand$1 = (ast, options = {}) => {
1456
+ let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
1457
+
1458
+ let walk = (node, parent = {}) => {
1459
+ node.queue = [];
1460
+
1461
+ let p = parent;
1462
+ let q = parent.queue;
1463
+
1464
+ while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
1465
+ p = p.parent;
1466
+ q = p.queue;
1467
+ }
1468
+
1469
+ if (node.invalid || node.dollar) {
1470
+ q.push(append(q.pop(), stringify$2(node, options)));
1471
+ return;
1472
+ }
1473
+
1474
+ if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
1475
+ q.push(append(q.pop(), ['{}']));
1476
+ return;
1477
+ }
1478
+
1479
+ if (node.nodes && node.ranges > 0) {
1480
+ let args = utils.reduce(node.nodes);
1481
+
1482
+ if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
1483
+ throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
1484
+ }
1485
+
1486
+ let range = fill(...args, options);
1487
+ if (range.length === 0) {
1488
+ range = stringify$2(node, options);
1489
+ }
1490
+
1491
+ q.push(append(q.pop(), range));
1492
+ node.nodes = [];
1493
+ return;
1494
+ }
1495
+
1496
+ let enclose = utils.encloseBrace(node);
1497
+ let queue = node.queue;
1498
+ let block = node;
1499
+
1500
+ while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
1501
+ block = block.parent;
1502
+ queue = block.queue;
1503
+ }
1504
+
1505
+ for (let i = 0; i < node.nodes.length; i++) {
1506
+ let child = node.nodes[i];
1507
+
1508
+ if (child.type === 'comma' && node.type === 'brace') {
1509
+ if (i === 1) queue.push('');
1510
+ queue.push('');
1511
+ continue;
1512
+ }
1513
+
1514
+ if (child.type === 'close') {
1515
+ q.push(append(q.pop(), queue, enclose));
1516
+ continue;
1517
+ }
1518
+
1519
+ if (child.value && child.type !== 'open') {
1520
+ queue.push(append(queue.pop(), child.value));
1521
+ continue;
1522
+ }
1523
+
1524
+ if (child.nodes) {
1525
+ walk(child, node);
1526
+ }
1527
+ }
1528
+
1529
+ return queue;
1530
+ };
1531
+
1532
+ return utils.flatten(walk(ast));
1533
+ };
1534
+
1535
+ var expand_1 = expand$1;
1536
+
1537
+ var constants$1 = {
1538
+ MAX_LENGTH: 1024 * 64,
1539
+
1540
+ // Digits
1541
+ CHAR_0: '0', /* 0 */
1542
+ CHAR_9: '9', /* 9 */
1543
+
1544
+ // Alphabet chars.
1545
+ CHAR_UPPERCASE_A: 'A', /* A */
1546
+ CHAR_LOWERCASE_A: 'a', /* a */
1547
+ CHAR_UPPERCASE_Z: 'Z', /* Z */
1548
+ CHAR_LOWERCASE_Z: 'z', /* z */
1549
+
1550
+ CHAR_LEFT_PARENTHESES: '(', /* ( */
1551
+ CHAR_RIGHT_PARENTHESES: ')', /* ) */
1552
+
1553
+ CHAR_ASTERISK: '*', /* * */
1554
+
1555
+ // Non-alphabetic chars.
1556
+ CHAR_AMPERSAND: '&', /* & */
1557
+ CHAR_AT: '@', /* @ */
1558
+ CHAR_BACKSLASH: '\\', /* \ */
1559
+ CHAR_BACKTICK: '`', /* ` */
1560
+ CHAR_CARRIAGE_RETURN: '\r', /* \r */
1561
+ CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
1562
+ CHAR_COLON: ':', /* : */
1563
+ CHAR_COMMA: ',', /* , */
1564
+ CHAR_DOLLAR: '$', /* . */
1565
+ CHAR_DOT: '.', /* . */
1566
+ CHAR_DOUBLE_QUOTE: '"', /* " */
1567
+ CHAR_EQUAL: '=', /* = */
1568
+ CHAR_EXCLAMATION_MARK: '!', /* ! */
1569
+ CHAR_FORM_FEED: '\f', /* \f */
1570
+ CHAR_FORWARD_SLASH: '/', /* / */
1571
+ CHAR_HASH: '#', /* # */
1572
+ CHAR_HYPHEN_MINUS: '-', /* - */
1573
+ CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
1574
+ CHAR_LEFT_CURLY_BRACE: '{', /* { */
1575
+ CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
1576
+ CHAR_LINE_FEED: '\n', /* \n */
1577
+ CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
1578
+ CHAR_PERCENT: '%', /* % */
1579
+ CHAR_PLUS: '+', /* + */
1580
+ CHAR_QUESTION_MARK: '?', /* ? */
1581
+ CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
1582
+ CHAR_RIGHT_CURLY_BRACE: '}', /* } */
1583
+ CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
1584
+ CHAR_SEMICOLON: ';', /* ; */
1585
+ CHAR_SINGLE_QUOTE: '\'', /* ' */
1586
+ CHAR_SPACE: ' ', /* */
1587
+ CHAR_TAB: '\t', /* \t */
1588
+ CHAR_UNDERSCORE: '_', /* _ */
1589
+ CHAR_VERTICAL_LINE: '|', /* | */
1590
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
1591
+ };
1592
+
1593
+ const stringify$1 = stringify$4;
1594
+
1595
+ /**
1596
+ * Constants
1597
+ */
1598
+
1599
+ const {
1600
+ MAX_LENGTH,
1601
+ CHAR_BACKSLASH, /* \ */
1602
+ CHAR_BACKTICK, /* ` */
1603
+ CHAR_COMMA, /* , */
1604
+ CHAR_DOT, /* . */
1605
+ CHAR_LEFT_PARENTHESES, /* ( */
1606
+ CHAR_RIGHT_PARENTHESES, /* ) */
1607
+ CHAR_LEFT_CURLY_BRACE, /* { */
1608
+ CHAR_RIGHT_CURLY_BRACE, /* } */
1609
+ CHAR_LEFT_SQUARE_BRACKET, /* [ */
1610
+ CHAR_RIGHT_SQUARE_BRACKET, /* ] */
1611
+ CHAR_DOUBLE_QUOTE, /* " */
1612
+ CHAR_SINGLE_QUOTE, /* ' */
1613
+ CHAR_NO_BREAK_SPACE,
1614
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE
1615
+ } = constants$1;
1616
+
1617
+ /**
1618
+ * parse
1619
+ */
1620
+
1621
+ const parse$1 = (input, options = {}) => {
1622
+ if (typeof input !== 'string') {
1623
+ throw new TypeError('Expected a string');
1624
+ }
1625
+
1626
+ let opts = options || {};
1627
+ let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1628
+ if (input.length > max) {
1629
+ throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
1630
+ }
1631
+
1632
+ let ast = { type: 'root', input, nodes: [] };
1633
+ let stack = [ast];
1634
+ let block = ast;
1635
+ let prev = ast;
1636
+ let brackets = 0;
1637
+ let length = input.length;
1638
+ let index = 0;
1639
+ let depth = 0;
1640
+ let value;
1641
+
1642
+ /**
1643
+ * Helpers
1644
+ */
1645
+
1646
+ const advance = () => input[index++];
1647
+ const push = node => {
1648
+ if (node.type === 'text' && prev.type === 'dot') {
1649
+ prev.type = 'text';
1650
+ }
1651
+
1652
+ if (prev && prev.type === 'text' && node.type === 'text') {
1653
+ prev.value += node.value;
1654
+ return;
1655
+ }
1656
+
1657
+ block.nodes.push(node);
1658
+ node.parent = block;
1659
+ node.prev = prev;
1660
+ prev = node;
1661
+ return node;
1662
+ };
1663
+
1664
+ push({ type: 'bos' });
1665
+
1666
+ while (index < length) {
1667
+ block = stack[stack.length - 1];
1668
+ value = advance();
1669
+
1670
+ /**
1671
+ * Invalid chars
1672
+ */
1673
+
1674
+ if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
1675
+ continue;
1676
+ }
1677
+
1678
+ /**
1679
+ * Escaped chars
1680
+ */
1681
+
1682
+ if (value === CHAR_BACKSLASH) {
1683
+ push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
1684
+ continue;
1685
+ }
1686
+
1687
+ /**
1688
+ * Right square bracket (literal): ']'
1689
+ */
1690
+
1691
+ if (value === CHAR_RIGHT_SQUARE_BRACKET) {
1692
+ push({ type: 'text', value: '\\' + value });
1693
+ continue;
1694
+ }
1695
+
1696
+ /**
1697
+ * Left square bracket: '['
1698
+ */
1699
+
1700
+ if (value === CHAR_LEFT_SQUARE_BRACKET) {
1701
+ brackets++;
1702
+ let next;
1703
+
1704
+ while (index < length && (next = advance())) {
1705
+ value += next;
1706
+
1707
+ if (next === CHAR_LEFT_SQUARE_BRACKET) {
1708
+ brackets++;
1709
+ continue;
1710
+ }
1711
+
1712
+ if (next === CHAR_BACKSLASH) {
1713
+ value += advance();
1714
+ continue;
1715
+ }
1716
+
1717
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
1718
+ brackets--;
1719
+
1720
+ if (brackets === 0) {
1721
+ break;
1722
+ }
1723
+ }
1724
+ }
1725
+
1726
+ push({ type: 'text', value });
1727
+ continue;
1728
+ }
1729
+
1730
+ /**
1731
+ * Parentheses
1732
+ */
1733
+
1734
+ if (value === CHAR_LEFT_PARENTHESES) {
1735
+ block = push({ type: 'paren', nodes: [] });
1736
+ stack.push(block);
1737
+ push({ type: 'text', value });
1738
+ continue;
1739
+ }
1740
+
1741
+ if (value === CHAR_RIGHT_PARENTHESES) {
1742
+ if (block.type !== 'paren') {
1743
+ push({ type: 'text', value });
1744
+ continue;
1745
+ }
1746
+ block = stack.pop();
1747
+ push({ type: 'text', value });
1748
+ block = stack[stack.length - 1];
1749
+ continue;
1750
+ }
1751
+
1752
+ /**
1753
+ * Quotes: '|"|`
1754
+ */
1755
+
1756
+ if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
1757
+ let open = value;
1758
+ let next;
1759
+
1760
+ if (options.keepQuotes !== true) {
1761
+ value = '';
1762
+ }
1763
+
1764
+ while (index < length && (next = advance())) {
1765
+ if (next === CHAR_BACKSLASH) {
1766
+ value += next + advance();
1767
+ continue;
1768
+ }
1769
+
1770
+ if (next === open) {
1771
+ if (options.keepQuotes === true) value += next;
1772
+ break;
1773
+ }
1774
+
1775
+ value += next;
1776
+ }
1777
+
1778
+ push({ type: 'text', value });
1779
+ continue;
1780
+ }
1781
+
1782
+ /**
1783
+ * Left curly brace: '{'
1784
+ */
1785
+
1786
+ if (value === CHAR_LEFT_CURLY_BRACE) {
1787
+ depth++;
1788
+
1789
+ let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
1790
+ let brace = {
1791
+ type: 'brace',
1792
+ open: true,
1793
+ close: false,
1794
+ dollar,
1795
+ depth,
1796
+ commas: 0,
1797
+ ranges: 0,
1798
+ nodes: []
1799
+ };
1800
+
1801
+ block = push(brace);
1802
+ stack.push(block);
1803
+ push({ type: 'open', value });
1804
+ continue;
1805
+ }
1806
+
1807
+ /**
1808
+ * Right curly brace: '}'
1809
+ */
1810
+
1811
+ if (value === CHAR_RIGHT_CURLY_BRACE) {
1812
+ if (block.type !== 'brace') {
1813
+ push({ type: 'text', value });
1814
+ continue;
1815
+ }
1816
+
1817
+ let type = 'close';
1818
+ block = stack.pop();
1819
+ block.close = true;
1820
+
1821
+ push({ type, value });
1822
+ depth--;
1823
+
1824
+ block = stack[stack.length - 1];
1825
+ continue;
1826
+ }
1827
+
1828
+ /**
1829
+ * Comma: ','
1830
+ */
1831
+
1832
+ if (value === CHAR_COMMA && depth > 0) {
1833
+ if (block.ranges > 0) {
1834
+ block.ranges = 0;
1835
+ let open = block.nodes.shift();
1836
+ block.nodes = [open, { type: 'text', value: stringify$1(block) }];
1837
+ }
1838
+
1839
+ push({ type: 'comma', value });
1840
+ block.commas++;
1841
+ continue;
1842
+ }
1843
+
1844
+ /**
1845
+ * Dot: '.'
1846
+ */
1847
+
1848
+ if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
1849
+ let siblings = block.nodes;
1850
+
1851
+ if (depth === 0 || siblings.length === 0) {
1852
+ push({ type: 'text', value });
1853
+ continue;
1854
+ }
1855
+
1856
+ if (prev.type === 'dot') {
1857
+ block.range = [];
1858
+ prev.value += value;
1859
+ prev.type = 'range';
1860
+
1861
+ if (block.nodes.length !== 3 && block.nodes.length !== 5) {
1862
+ block.invalid = true;
1863
+ block.ranges = 0;
1864
+ prev.type = 'text';
1865
+ continue;
1866
+ }
1867
+
1868
+ block.ranges++;
1869
+ block.args = [];
1870
+ continue;
1871
+ }
1872
+
1873
+ if (prev.type === 'range') {
1874
+ siblings.pop();
1875
+
1876
+ let before = siblings[siblings.length - 1];
1877
+ before.value += prev.value + value;
1878
+ prev = before;
1879
+ block.ranges--;
1880
+ continue;
1881
+ }
1882
+
1883
+ push({ type: 'dot', value });
1884
+ continue;
1885
+ }
1886
+
1887
+ /**
1888
+ * Text
1889
+ */
1890
+
1891
+ push({ type: 'text', value });
1892
+ }
1893
+
1894
+ // Mark imbalanced braces and brackets as invalid
1895
+ do {
1896
+ block = stack.pop();
1897
+
1898
+ if (block.type !== 'root') {
1899
+ block.nodes.forEach(node => {
1900
+ if (!node.nodes) {
1901
+ if (node.type === 'open') node.isOpen = true;
1902
+ if (node.type === 'close') node.isClose = true;
1903
+ if (!node.nodes) node.type = 'text';
1904
+ node.invalid = true;
1905
+ }
1906
+ });
1907
+
1908
+ // get the location of the block on parent.nodes (block's siblings)
1909
+ let parent = stack[stack.length - 1];
1910
+ let index = parent.nodes.indexOf(block);
1911
+ // replace the (invalid) block with it's nodes
1912
+ parent.nodes.splice(index, 1, ...block.nodes);
1913
+ }
1914
+ } while (stack.length > 0);
1915
+
1916
+ push({ type: 'eos' });
1917
+ return ast;
1918
+ };
1919
+
1920
+ var parse_1 = parse$1;
1921
+
1922
+ const stringify = stringify$4;
1923
+ const compile = compile_1;
1924
+ const expand = expand_1;
1925
+ const parse = parse_1;
1926
+
1927
+ /**
1928
+ * Expand the given pattern or create a regex-compatible string.
1929
+ *
1930
+ * ```js
1931
+ * const braces = require('braces');
1932
+ * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
1933
+ * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
1934
+ * ```
1935
+ * @param {String} `str`
1936
+ * @param {Object} `options`
1937
+ * @return {String}
1938
+ * @api public
1939
+ */
1940
+
1941
+ const braces$1 = (input, options = {}) => {
1942
+ let output = [];
1943
+
1944
+ if (Array.isArray(input)) {
1945
+ for (let pattern of input) {
1946
+ let result = braces$1.create(pattern, options);
1947
+ if (Array.isArray(result)) {
1948
+ output.push(...result);
1949
+ } else {
1950
+ output.push(result);
1951
+ }
1952
+ }
1953
+ } else {
1954
+ output = [].concat(braces$1.create(input, options));
1955
+ }
1956
+
1957
+ if (options && options.expand === true && options.nodupes === true) {
1958
+ output = [...new Set(output)];
1959
+ }
1960
+ return output;
1961
+ };
1962
+
1963
+ /**
1964
+ * Parse the given `str` with the given `options`.
1965
+ *
1966
+ * ```js
1967
+ * // braces.parse(pattern, [, options]);
1968
+ * const ast = braces.parse('a/{b,c}/d');
1969
+ * console.log(ast);
1970
+ * ```
1971
+ * @param {String} pattern Brace pattern to parse
1972
+ * @param {Object} options
1973
+ * @return {Object} Returns an AST
1974
+ * @api public
1975
+ */
1976
+
1977
+ braces$1.parse = (input, options = {}) => parse(input, options);
1978
+
1979
+ /**
1980
+ * Creates a braces string from an AST, or an AST node.
1981
+ *
1982
+ * ```js
1983
+ * const braces = require('braces');
1984
+ * let ast = braces.parse('foo/{a,b}/bar');
1985
+ * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
1986
+ * ```
1987
+ * @param {String} `input` Brace pattern or AST.
1988
+ * @param {Object} `options`
1989
+ * @return {Array} Returns an array of expanded values.
1990
+ * @api public
1991
+ */
1992
+
1993
+ braces$1.stringify = (input, options = {}) => {
1994
+ if (typeof input === 'string') {
1995
+ return stringify(braces$1.parse(input, options), options);
1996
+ }
1997
+ return stringify(input, options);
1998
+ };
1999
+
2000
+ /**
2001
+ * Compiles a brace pattern into a regex-compatible, optimized string.
2002
+ * This method is called by the main [braces](#braces) function by default.
2003
+ *
2004
+ * ```js
2005
+ * const braces = require('braces');
2006
+ * console.log(braces.compile('a/{b,c}/d'));
2007
+ * //=> ['a/(b|c)/d']
2008
+ * ```
2009
+ * @param {String} `input` Brace pattern or AST.
2010
+ * @param {Object} `options`
2011
+ * @return {Array} Returns an array of expanded values.
2012
+ * @api public
2013
+ */
2014
+
2015
+ braces$1.compile = (input, options = {}) => {
2016
+ if (typeof input === 'string') {
2017
+ input = braces$1.parse(input, options);
2018
+ }
2019
+ return compile(input, options);
2020
+ };
2021
+
2022
+ /**
2023
+ * Expands a brace pattern into an array. This method is called by the
2024
+ * main [braces](#braces) function when `options.expand` is true. Before
2025
+ * using this method it's recommended that you read the [performance notes](#performance))
2026
+ * and advantages of using [.compile](#compile) instead.
2027
+ *
2028
+ * ```js
2029
+ * const braces = require('braces');
2030
+ * console.log(braces.expand('a/{b,c}/d'));
2031
+ * //=> ['a/b/d', 'a/c/d'];
2032
+ * ```
2033
+ * @param {String} `pattern` Brace pattern
2034
+ * @param {Object} `options`
2035
+ * @return {Array} Returns an array of expanded values.
2036
+ * @api public
2037
+ */
2038
+
2039
+ braces$1.expand = (input, options = {}) => {
2040
+ if (typeof input === 'string') {
2041
+ input = braces$1.parse(input, options);
2042
+ }
2043
+
2044
+ let result = expand(input, options);
2045
+
2046
+ // filter out empty strings if specified
2047
+ if (options.noempty === true) {
2048
+ result = result.filter(Boolean);
2049
+ }
2050
+
2051
+ // filter out duplicates if specified
2052
+ if (options.nodupes === true) {
2053
+ result = [...new Set(result)];
2054
+ }
2055
+
2056
+ return result;
2057
+ };
2058
+
2059
+ /**
2060
+ * Processes a brace pattern and returns either an expanded array
2061
+ * (if `options.expand` is true), a highly optimized regex-compatible string.
2062
+ * This method is called by the main [braces](#braces) function.
2063
+ *
2064
+ * ```js
2065
+ * const braces = require('braces');
2066
+ * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
2067
+ * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
2068
+ * ```
2069
+ * @param {String} `pattern` Brace pattern
2070
+ * @param {Object} `options`
2071
+ * @return {Array} Returns an array of expanded values.
2072
+ * @api public
2073
+ */
2074
+
2075
+ braces$1.create = (input, options = {}) => {
2076
+ if (input === '' || input.length < 3) {
2077
+ return [input];
2078
+ }
2079
+
2080
+ return options.expand !== true
2081
+ ? braces$1.compile(input, options)
2082
+ : braces$1.expand(input, options);
2083
+ };
2084
+
2085
+ /**
2086
+ * Expose "braces"
2087
+ */
2088
+
2089
+ var braces_1 = braces$1;
2090
+
2091
+ const require$$0 = [
2092
+ "3dm",
2093
+ "3ds",
2094
+ "3g2",
2095
+ "3gp",
2096
+ "7z",
2097
+ "a",
2098
+ "aac",
2099
+ "adp",
2100
+ "ai",
2101
+ "aif",
2102
+ "aiff",
2103
+ "alz",
2104
+ "ape",
2105
+ "apk",
2106
+ "appimage",
2107
+ "ar",
2108
+ "arj",
2109
+ "asf",
2110
+ "au",
2111
+ "avi",
2112
+ "bak",
2113
+ "baml",
2114
+ "bh",
2115
+ "bin",
2116
+ "bk",
2117
+ "bmp",
2118
+ "btif",
2119
+ "bz2",
2120
+ "bzip2",
2121
+ "cab",
2122
+ "caf",
2123
+ "cgm",
2124
+ "class",
2125
+ "cmx",
2126
+ "cpio",
2127
+ "cr2",
2128
+ "cur",
2129
+ "dat",
2130
+ "dcm",
2131
+ "deb",
2132
+ "dex",
2133
+ "djvu",
2134
+ "dll",
2135
+ "dmg",
2136
+ "dng",
2137
+ "doc",
2138
+ "docm",
2139
+ "docx",
2140
+ "dot",
2141
+ "dotm",
2142
+ "dra",
2143
+ "DS_Store",
2144
+ "dsk",
2145
+ "dts",
2146
+ "dtshd",
2147
+ "dvb",
2148
+ "dwg",
2149
+ "dxf",
2150
+ "ecelp4800",
2151
+ "ecelp7470",
2152
+ "ecelp9600",
2153
+ "egg",
2154
+ "eol",
2155
+ "eot",
2156
+ "epub",
2157
+ "exe",
2158
+ "f4v",
2159
+ "fbs",
2160
+ "fh",
2161
+ "fla",
2162
+ "flac",
2163
+ "flatpak",
2164
+ "fli",
2165
+ "flv",
2166
+ "fpx",
2167
+ "fst",
2168
+ "fvt",
2169
+ "g3",
2170
+ "gh",
2171
+ "gif",
2172
+ "graffle",
2173
+ "gz",
2174
+ "gzip",
2175
+ "h261",
2176
+ "h263",
2177
+ "h264",
2178
+ "icns",
2179
+ "ico",
2180
+ "ief",
2181
+ "img",
2182
+ "ipa",
2183
+ "iso",
2184
+ "jar",
2185
+ "jpeg",
2186
+ "jpg",
2187
+ "jpgv",
2188
+ "jpm",
2189
+ "jxr",
2190
+ "key",
2191
+ "ktx",
2192
+ "lha",
2193
+ "lib",
2194
+ "lvp",
2195
+ "lz",
2196
+ "lzh",
2197
+ "lzma",
2198
+ "lzo",
2199
+ "m3u",
2200
+ "m4a",
2201
+ "m4v",
2202
+ "mar",
2203
+ "mdi",
2204
+ "mht",
2205
+ "mid",
2206
+ "midi",
2207
+ "mj2",
2208
+ "mka",
2209
+ "mkv",
2210
+ "mmr",
2211
+ "mng",
2212
+ "mobi",
2213
+ "mov",
2214
+ "movie",
2215
+ "mp3",
2216
+ "mp4",
2217
+ "mp4a",
2218
+ "mpeg",
2219
+ "mpg",
2220
+ "mpga",
2221
+ "mxu",
2222
+ "nef",
2223
+ "npx",
2224
+ "numbers",
2225
+ "nupkg",
2226
+ "o",
2227
+ "odp",
2228
+ "ods",
2229
+ "odt",
2230
+ "oga",
2231
+ "ogg",
2232
+ "ogv",
2233
+ "otf",
2234
+ "ott",
2235
+ "pages",
2236
+ "pbm",
2237
+ "pcx",
2238
+ "pdb",
2239
+ "pdf",
2240
+ "pea",
2241
+ "pgm",
2242
+ "pic",
2243
+ "png",
2244
+ "pnm",
2245
+ "pot",
2246
+ "potm",
2247
+ "potx",
2248
+ "ppa",
2249
+ "ppam",
2250
+ "ppm",
2251
+ "pps",
2252
+ "ppsm",
2253
+ "ppsx",
2254
+ "ppt",
2255
+ "pptm",
2256
+ "pptx",
2257
+ "psd",
2258
+ "pya",
2259
+ "pyc",
2260
+ "pyo",
2261
+ "pyv",
2262
+ "qt",
2263
+ "rar",
2264
+ "ras",
2265
+ "raw",
2266
+ "resources",
2267
+ "rgb",
2268
+ "rip",
2269
+ "rlc",
2270
+ "rmf",
2271
+ "rmvb",
2272
+ "rpm",
2273
+ "rtf",
2274
+ "rz",
2275
+ "s3m",
2276
+ "s7z",
2277
+ "scpt",
2278
+ "sgi",
2279
+ "shar",
2280
+ "snap",
2281
+ "sil",
2282
+ "sketch",
2283
+ "slk",
2284
+ "smv",
2285
+ "snk",
2286
+ "so",
2287
+ "stl",
2288
+ "suo",
2289
+ "sub",
2290
+ "swf",
2291
+ "tar",
2292
+ "tbz",
2293
+ "tbz2",
2294
+ "tga",
2295
+ "tgz",
2296
+ "thmx",
2297
+ "tif",
2298
+ "tiff",
2299
+ "tlz",
2300
+ "ttc",
2301
+ "ttf",
2302
+ "txz",
2303
+ "udf",
2304
+ "uvh",
2305
+ "uvi",
2306
+ "uvm",
2307
+ "uvp",
2308
+ "uvs",
2309
+ "uvu",
2310
+ "viv",
2311
+ "vob",
2312
+ "war",
2313
+ "wav",
2314
+ "wax",
2315
+ "wbmp",
2316
+ "wdp",
2317
+ "weba",
2318
+ "webm",
2319
+ "webp",
2320
+ "whl",
2321
+ "wim",
2322
+ "wm",
2323
+ "wma",
2324
+ "wmv",
2325
+ "wmx",
2326
+ "woff",
2327
+ "woff2",
2328
+ "wrm",
2329
+ "wvx",
2330
+ "xbm",
2331
+ "xif",
2332
+ "xla",
2333
+ "xlam",
2334
+ "xls",
2335
+ "xlsb",
2336
+ "xlsm",
2337
+ "xlsx",
2338
+ "xlt",
2339
+ "xltm",
2340
+ "xltx",
2341
+ "xm",
2342
+ "xmind",
2343
+ "xpi",
2344
+ "xpm",
2345
+ "xwd",
2346
+ "xz",
2347
+ "z",
2348
+ "zip",
2349
+ "zipx"
2350
+ ];
2351
+
2352
+ var binaryExtensions$1 = require$$0;
2353
+
2354
+ const path = require$$0$2;
2355
+ const binaryExtensions = binaryExtensions$1;
2356
+
2357
+ const extensions = new Set(binaryExtensions);
2358
+
2359
+ var isBinaryPath$1 = filePath => extensions.has(path.extname(filePath).slice(1).toLowerCase());
2360
+
2361
+ var constants = {};
2362
+
2363
+ (function (exports) {
2364
+
2365
+ const {sep} = require$$0$2;
2366
+ const {platform} = process;
2367
+ const os = require$$2$1;
2368
+
2369
+ exports.EV_ALL = 'all';
2370
+ exports.EV_READY = 'ready';
2371
+ exports.EV_ADD = 'add';
2372
+ exports.EV_CHANGE = 'change';
2373
+ exports.EV_ADD_DIR = 'addDir';
2374
+ exports.EV_UNLINK = 'unlink';
2375
+ exports.EV_UNLINK_DIR = 'unlinkDir';
2376
+ exports.EV_RAW = 'raw';
2377
+ exports.EV_ERROR = 'error';
2378
+
2379
+ exports.STR_DATA = 'data';
2380
+ exports.STR_END = 'end';
2381
+ exports.STR_CLOSE = 'close';
2382
+
2383
+ exports.FSEVENT_CREATED = 'created';
2384
+ exports.FSEVENT_MODIFIED = 'modified';
2385
+ exports.FSEVENT_DELETED = 'deleted';
2386
+ exports.FSEVENT_MOVED = 'moved';
2387
+ exports.FSEVENT_CLONED = 'cloned';
2388
+ exports.FSEVENT_UNKNOWN = 'unknown';
2389
+ exports.FSEVENT_TYPE_FILE = 'file';
2390
+ exports.FSEVENT_TYPE_DIRECTORY = 'directory';
2391
+ exports.FSEVENT_TYPE_SYMLINK = 'symlink';
2392
+
2393
+ exports.KEY_LISTENERS = 'listeners';
2394
+ exports.KEY_ERR = 'errHandlers';
2395
+ exports.KEY_RAW = 'rawEmitters';
2396
+ exports.HANDLER_KEYS = [exports.KEY_LISTENERS, exports.KEY_ERR, exports.KEY_RAW];
2397
+
2398
+ exports.DOT_SLASH = `.${sep}`;
2399
+
2400
+ exports.BACK_SLASH_RE = /\\/g;
2401
+ exports.DOUBLE_SLASH_RE = /\/\//;
2402
+ exports.SLASH_OR_BACK_SLASH_RE = /[/\\]/;
2403
+ exports.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
2404
+ exports.REPLACER_RE = /^\.[/\\]/;
2405
+
2406
+ exports.SLASH = '/';
2407
+ exports.SLASH_SLASH = '//';
2408
+ exports.BRACE_START = '{';
2409
+ exports.BANG = '!';
2410
+ exports.ONE_DOT = '.';
2411
+ exports.TWO_DOTS = '..';
2412
+ exports.STAR = '*';
2413
+ exports.GLOBSTAR = '**';
2414
+ exports.ROOT_GLOBSTAR = '/**/*';
2415
+ exports.SLASH_GLOBSTAR = '/**';
2416
+ exports.DIR_SUFFIX = 'Dir';
2417
+ exports.ANYMATCH_OPTS = {dot: true};
2418
+ exports.STRING_TYPE = 'string';
2419
+ exports.FUNCTION_TYPE = 'function';
2420
+ exports.EMPTY_STR = '';
2421
+ exports.EMPTY_FN = () => {};
2422
+ exports.IDENTITY_FN = val => val;
2423
+
2424
+ exports.isWindows = platform === 'win32';
2425
+ exports.isMacos = platform === 'darwin';
2426
+ exports.isLinux = platform === 'linux';
2427
+ exports.isIBMi = os.type() === 'OS400';
2428
+ } (constants));
2429
+
2430
+ const fs$2 = require$$0$1;
2431
+ const sysPath$2 = require$$0$2;
2432
+ const { promisify: promisify$2 } = require$$2;
2433
+ const isBinaryPath = isBinaryPath$1;
2434
+ const {
2435
+ isWindows: isWindows$1,
2436
+ isLinux,
2437
+ EMPTY_FN: EMPTY_FN$2,
2438
+ EMPTY_STR: EMPTY_STR$1,
2439
+ KEY_LISTENERS,
2440
+ KEY_ERR,
2441
+ KEY_RAW,
2442
+ HANDLER_KEYS,
2443
+ EV_CHANGE: EV_CHANGE$2,
2444
+ EV_ADD: EV_ADD$2,
2445
+ EV_ADD_DIR: EV_ADD_DIR$2,
2446
+ EV_ERROR: EV_ERROR$2,
2447
+ STR_DATA: STR_DATA$1,
2448
+ STR_END: STR_END$2,
2449
+ BRACE_START: BRACE_START$1,
2450
+ STAR
2451
+ } = constants;
2452
+
2453
+ const THROTTLE_MODE_WATCH = 'watch';
2454
+
2455
+ const open = promisify$2(fs$2.open);
2456
+ const stat$2 = promisify$2(fs$2.stat);
2457
+ const lstat$1 = promisify$2(fs$2.lstat);
2458
+ const close = promisify$2(fs$2.close);
2459
+ const fsrealpath = promisify$2(fs$2.realpath);
2460
+
2461
+ const statMethods$1 = { lstat: lstat$1, stat: stat$2 };
2462
+
2463
+ // TODO: emit errors properly. Example: EMFILE on Macos.
2464
+ const foreach = (val, fn) => {
2465
+ if (val instanceof Set) {
2466
+ val.forEach(fn);
2467
+ } else {
2468
+ fn(val);
2469
+ }
2470
+ };
2471
+
2472
+ const addAndConvert = (main, prop, item) => {
2473
+ let container = main[prop];
2474
+ if (!(container instanceof Set)) {
2475
+ main[prop] = container = new Set([container]);
2476
+ }
2477
+ container.add(item);
2478
+ };
2479
+
2480
+ const clearItem = cont => key => {
2481
+ const set = cont[key];
2482
+ if (set instanceof Set) {
2483
+ set.clear();
2484
+ } else {
2485
+ delete cont[key];
2486
+ }
2487
+ };
2488
+
2489
+ const delFromSet = (main, prop, item) => {
2490
+ const container = main[prop];
2491
+ if (container instanceof Set) {
2492
+ container.delete(item);
2493
+ } else if (container === item) {
2494
+ delete main[prop];
2495
+ }
2496
+ };
2497
+
2498
+ const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
2499
+
2500
+ /**
2501
+ * @typedef {String} Path
2502
+ */
2503
+
2504
+ // fs_watch helpers
2505
+
2506
+ // object to hold per-process fs_watch instances
2507
+ // (may be shared across chokidar FSWatcher instances)
2508
+
2509
+ /**
2510
+ * @typedef {Object} FsWatchContainer
2511
+ * @property {Set} listeners
2512
+ * @property {Set} errHandlers
2513
+ * @property {Set} rawEmitters
2514
+ * @property {fs.FSWatcher=} watcher
2515
+ * @property {Boolean=} watcherUnusable
2516
+ */
2517
+
2518
+ /**
2519
+ * @type {Map<String,FsWatchContainer>}
2520
+ */
2521
+ const FsWatchInstances = new Map();
2522
+
2523
+ /**
2524
+ * Instantiates the fs_watch interface
2525
+ * @param {String} path to be watched
2526
+ * @param {Object} options to be passed to fs_watch
2527
+ * @param {Function} listener main event handler
2528
+ * @param {Function} errHandler emits info about errors
2529
+ * @param {Function} emitRaw emits raw event data
2530
+ * @returns {fs.FSWatcher} new fsevents instance
2531
+ */
2532
+ function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
2533
+ const handleEvent = (rawEvent, evPath) => {
2534
+ listener(path);
2535
+ emitRaw(rawEvent, evPath, {watchedPath: path});
2536
+
2537
+ // emit based on events occurring for files from a directory's watcher in
2538
+ // case the file's watcher misses it (and rely on throttling to de-dupe)
2539
+ if (evPath && path !== evPath) {
2540
+ fsWatchBroadcast(
2541
+ sysPath$2.resolve(path, evPath), KEY_LISTENERS, sysPath$2.join(path, evPath)
2542
+ );
2543
+ }
2544
+ };
2545
+ try {
2546
+ return fs$2.watch(path, options, handleEvent);
2547
+ } catch (error) {
2548
+ errHandler(error);
2549
+ }
2550
+ }
2551
+
2552
+ /**
2553
+ * Helper for passing fs_watch event data to a collection of listeners
2554
+ * @param {Path} fullPath absolute path bound to fs_watch instance
2555
+ * @param {String} type listener type
2556
+ * @param {*=} val1 arguments to be passed to listeners
2557
+ * @param {*=} val2
2558
+ * @param {*=} val3
2559
+ */
2560
+ const fsWatchBroadcast = (fullPath, type, val1, val2, val3) => {
2561
+ const cont = FsWatchInstances.get(fullPath);
2562
+ if (!cont) return;
2563
+ foreach(cont[type], (listener) => {
2564
+ listener(val1, val2, val3);
2565
+ });
2566
+ };
2567
+
2568
+ /**
2569
+ * Instantiates the fs_watch interface or binds listeners
2570
+ * to an existing one covering the same file system entry
2571
+ * @param {String} path
2572
+ * @param {String} fullPath absolute path
2573
+ * @param {Object} options to be passed to fs_watch
2574
+ * @param {Object} handlers container for event listener functions
2575
+ */
2576
+ const setFsWatchListener = (path, fullPath, options, handlers) => {
2577
+ const {listener, errHandler, rawEmitter} = handlers;
2578
+ let cont = FsWatchInstances.get(fullPath);
2579
+
2580
+ /** @type {fs.FSWatcher=} */
2581
+ let watcher;
2582
+ if (!options.persistent) {
2583
+ watcher = createFsWatchInstance(
2584
+ path, options, listener, errHandler, rawEmitter
2585
+ );
2586
+ return watcher.close.bind(watcher);
2587
+ }
2588
+ if (cont) {
2589
+ addAndConvert(cont, KEY_LISTENERS, listener);
2590
+ addAndConvert(cont, KEY_ERR, errHandler);
2591
+ addAndConvert(cont, KEY_RAW, rawEmitter);
2592
+ } else {
2593
+ watcher = createFsWatchInstance(
2594
+ path,
2595
+ options,
2596
+ fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
2597
+ errHandler, // no need to use broadcast here
2598
+ fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
2599
+ );
2600
+ if (!watcher) return;
2601
+ watcher.on(EV_ERROR$2, async (error) => {
2602
+ const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
2603
+ cont.watcherUnusable = true; // documented since Node 10.4.1
2604
+ // Workaround for https://github.com/joyent/node/issues/4337
2605
+ if (isWindows$1 && error.code === 'EPERM') {
2606
+ try {
2607
+ const fd = await open(path, 'r');
2608
+ await close(fd);
2609
+ broadcastErr(error);
2610
+ } catch (err) {}
2611
+ } else {
2612
+ broadcastErr(error);
2613
+ }
2614
+ });
2615
+ cont = {
2616
+ listeners: listener,
2617
+ errHandlers: errHandler,
2618
+ rawEmitters: rawEmitter,
2619
+ watcher
2620
+ };
2621
+ FsWatchInstances.set(fullPath, cont);
2622
+ }
2623
+ // const index = cont.listeners.indexOf(listener);
2624
+
2625
+ // removes this instance's listeners and closes the underlying fs_watch
2626
+ // instance if there are no more listeners left
2627
+ return () => {
2628
+ delFromSet(cont, KEY_LISTENERS, listener);
2629
+ delFromSet(cont, KEY_ERR, errHandler);
2630
+ delFromSet(cont, KEY_RAW, rawEmitter);
2631
+ if (isEmptySet(cont.listeners)) {
2632
+ // Check to protect against issue gh-730.
2633
+ // if (cont.watcherUnusable) {
2634
+ cont.watcher.close();
2635
+ // }
2636
+ FsWatchInstances.delete(fullPath);
2637
+ HANDLER_KEYS.forEach(clearItem(cont));
2638
+ cont.watcher = undefined;
2639
+ Object.freeze(cont);
2640
+ }
2641
+ };
2642
+ };
2643
+
2644
+ // fs_watchFile helpers
2645
+
2646
+ // object to hold per-process fs_watchFile instances
2647
+ // (may be shared across chokidar FSWatcher instances)
2648
+ const FsWatchFileInstances = new Map();
2649
+
2650
+ /**
2651
+ * Instantiates the fs_watchFile interface or binds listeners
2652
+ * to an existing one covering the same file system entry
2653
+ * @param {String} path to be watched
2654
+ * @param {String} fullPath absolute path
2655
+ * @param {Object} options options to be passed to fs_watchFile
2656
+ * @param {Object} handlers container for event listener functions
2657
+ * @returns {Function} closer
2658
+ */
2659
+ const setFsWatchFileListener = (path, fullPath, options, handlers) => {
2660
+ const {listener, rawEmitter} = handlers;
2661
+ let cont = FsWatchFileInstances.get(fullPath);
2662
+
2663
+ const copts = cont && cont.options;
2664
+ if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
2665
+ fs$2.unwatchFile(fullPath);
2666
+ cont = undefined;
2667
+ }
2668
+
2669
+ /* eslint-enable no-unused-vars, prefer-destructuring */
2670
+
2671
+ if (cont) {
2672
+ addAndConvert(cont, KEY_LISTENERS, listener);
2673
+ addAndConvert(cont, KEY_RAW, rawEmitter);
2674
+ } else {
2675
+ // TODO
2676
+ // listeners.add(listener);
2677
+ // rawEmitters.add(rawEmitter);
2678
+ cont = {
2679
+ listeners: listener,
2680
+ rawEmitters: rawEmitter,
2681
+ options,
2682
+ watcher: fs$2.watchFile(fullPath, options, (curr, prev) => {
2683
+ foreach(cont.rawEmitters, (rawEmitter) => {
2684
+ rawEmitter(EV_CHANGE$2, fullPath, {curr, prev});
2685
+ });
2686
+ const currmtime = curr.mtimeMs;
2687
+ if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
2688
+ foreach(cont.listeners, (listener) => listener(path, curr));
2689
+ }
2690
+ })
2691
+ };
2692
+ FsWatchFileInstances.set(fullPath, cont);
2693
+ }
2694
+ // const index = cont.listeners.indexOf(listener);
2695
+
2696
+ // Removes this instance's listeners and closes the underlying fs_watchFile
2697
+ // instance if there are no more listeners left.
2698
+ return () => {
2699
+ delFromSet(cont, KEY_LISTENERS, listener);
2700
+ delFromSet(cont, KEY_RAW, rawEmitter);
2701
+ if (isEmptySet(cont.listeners)) {
2702
+ FsWatchFileInstances.delete(fullPath);
2703
+ fs$2.unwatchFile(fullPath);
2704
+ cont.options = cont.watcher = undefined;
2705
+ Object.freeze(cont);
2706
+ }
2707
+ };
2708
+ };
2709
+
2710
+ /**
2711
+ * @mixin
2712
+ */
2713
+ let NodeFsHandler$1 = class NodeFsHandler {
2714
+
2715
+ /**
2716
+ * @param {import("../index").FSWatcher} fsW
2717
+ */
2718
+ constructor(fsW) {
2719
+ this.fsw = fsW;
2720
+ this._boundHandleError = (error) => fsW._handleError(error);
2721
+ }
2722
+
2723
+ /**
2724
+ * Watch file for changes with fs_watchFile or fs_watch.
2725
+ * @param {String} path to file or dir
2726
+ * @param {Function} listener on fs change
2727
+ * @returns {Function} closer for the watcher instance
2728
+ */
2729
+ _watchWithNodeFs(path, listener) {
2730
+ const opts = this.fsw.options;
2731
+ const directory = sysPath$2.dirname(path);
2732
+ const basename = sysPath$2.basename(path);
2733
+ const parent = this.fsw._getWatchedDir(directory);
2734
+ parent.add(basename);
2735
+ const absolutePath = sysPath$2.resolve(path);
2736
+ const options = {persistent: opts.persistent};
2737
+ if (!listener) listener = EMPTY_FN$2;
2738
+
2739
+ let closer;
2740
+ if (opts.usePolling) {
2741
+ options.interval = opts.enableBinaryInterval && isBinaryPath(basename) ?
2742
+ opts.binaryInterval : opts.interval;
2743
+ closer = setFsWatchFileListener(path, absolutePath, options, {
2744
+ listener,
2745
+ rawEmitter: this.fsw._emitRaw
2746
+ });
2747
+ } else {
2748
+ closer = setFsWatchListener(path, absolutePath, options, {
2749
+ listener,
2750
+ errHandler: this._boundHandleError,
2751
+ rawEmitter: this.fsw._emitRaw
2752
+ });
2753
+ }
2754
+ return closer;
2755
+ }
2756
+
2757
+ /**
2758
+ * Watch a file and emit add event if warranted.
2759
+ * @param {Path} file Path
2760
+ * @param {fs.Stats} stats result of fs_stat
2761
+ * @param {Boolean} initialAdd was the file added at watch instantiation?
2762
+ * @returns {Function} closer for the watcher instance
2763
+ */
2764
+ _handleFile(file, stats, initialAdd) {
2765
+ if (this.fsw.closed) {
2766
+ return;
2767
+ }
2768
+ const dirname = sysPath$2.dirname(file);
2769
+ const basename = sysPath$2.basename(file);
2770
+ const parent = this.fsw._getWatchedDir(dirname);
2771
+ // stats is always present
2772
+ let prevStats = stats;
2773
+
2774
+ // if the file is already being watched, do nothing
2775
+ if (parent.has(basename)) return;
2776
+
2777
+ const listener = async (path, newStats) => {
2778
+ if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
2779
+ if (!newStats || newStats.mtimeMs === 0) {
2780
+ try {
2781
+ const newStats = await stat$2(file);
2782
+ if (this.fsw.closed) return;
2783
+ // Check that change event was not fired because of changed only accessTime.
2784
+ const at = newStats.atimeMs;
2785
+ const mt = newStats.mtimeMs;
2786
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) {
2787
+ this.fsw._emit(EV_CHANGE$2, file, newStats);
2788
+ }
2789
+ if (isLinux && prevStats.ino !== newStats.ino) {
2790
+ this.fsw._closeFile(path);
2791
+ prevStats = newStats;
2792
+ this.fsw._addPathCloser(path, this._watchWithNodeFs(file, listener));
2793
+ } else {
2794
+ prevStats = newStats;
2795
+ }
2796
+ } catch (error) {
2797
+ // Fix issues where mtime is null but file is still present
2798
+ this.fsw._remove(dirname, basename);
2799
+ }
2800
+ // add is about to be emitted if file not already tracked in parent
2801
+ } else if (parent.has(basename)) {
2802
+ // Check that change event was not fired because of changed only accessTime.
2803
+ const at = newStats.atimeMs;
2804
+ const mt = newStats.mtimeMs;
2805
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) {
2806
+ this.fsw._emit(EV_CHANGE$2, file, newStats);
2807
+ }
2808
+ prevStats = newStats;
2809
+ }
2810
+ };
2811
+ // kick off the watcher
2812
+ const closer = this._watchWithNodeFs(file, listener);
2813
+
2814
+ // emit an add event if we're supposed to
2815
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
2816
+ if (!this.fsw._throttle(EV_ADD$2, file, 0)) return;
2817
+ this.fsw._emit(EV_ADD$2, file, stats);
2818
+ }
2819
+
2820
+ return closer;
2821
+ }
2822
+
2823
+ /**
2824
+ * Handle symlinks encountered while reading a dir.
2825
+ * @param {Object} entry returned by readdirp
2826
+ * @param {String} directory path of dir being read
2827
+ * @param {String} path of this item
2828
+ * @param {String} item basename of this item
2829
+ * @returns {Promise<Boolean>} true if no more processing is needed for this entry.
2830
+ */
2831
+ async _handleSymlink(entry, directory, path, item) {
2832
+ if (this.fsw.closed) {
2833
+ return;
2834
+ }
2835
+ const full = entry.fullPath;
2836
+ const dir = this.fsw._getWatchedDir(directory);
2837
+
2838
+ if (!this.fsw.options.followSymlinks) {
2839
+ // watch symlink directly (don't follow) and detect changes
2840
+ this.fsw._incrReadyCount();
2841
+
2842
+ let linkPath;
2843
+ try {
2844
+ linkPath = await fsrealpath(path);
2845
+ } catch (e) {
2846
+ this.fsw._emitReady();
2847
+ return true;
2848
+ }
2849
+
2850
+ if (this.fsw.closed) return;
2851
+ if (dir.has(item)) {
2852
+ if (this.fsw._symlinkPaths.get(full) !== linkPath) {
2853
+ this.fsw._symlinkPaths.set(full, linkPath);
2854
+ this.fsw._emit(EV_CHANGE$2, path, entry.stats);
2855
+ }
2856
+ } else {
2857
+ dir.add(item);
2858
+ this.fsw._symlinkPaths.set(full, linkPath);
2859
+ this.fsw._emit(EV_ADD$2, path, entry.stats);
2860
+ }
2861
+ this.fsw._emitReady();
2862
+ return true;
2863
+ }
2864
+
2865
+ // don't follow the same symlink more than once
2866
+ if (this.fsw._symlinkPaths.has(full)) {
2867
+ return true;
2868
+ }
2869
+
2870
+ this.fsw._symlinkPaths.set(full, true);
2871
+ }
2872
+
2873
+ _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
2874
+ // Normalize the directory name on Windows
2875
+ directory = sysPath$2.join(directory, EMPTY_STR$1);
2876
+
2877
+ if (!wh.hasGlob) {
2878
+ throttler = this.fsw._throttle('readdir', directory, 1000);
2879
+ if (!throttler) return;
2880
+ }
2881
+
2882
+ const previous = this.fsw._getWatchedDir(wh.path);
2883
+ const current = new Set();
2884
+
2885
+ let stream = this.fsw._readdirp(directory, {
2886
+ fileFilter: entry => wh.filterPath(entry),
2887
+ directoryFilter: entry => wh.filterDir(entry),
2888
+ depth: 0
2889
+ }).on(STR_DATA$1, async (entry) => {
2890
+ if (this.fsw.closed) {
2891
+ stream = undefined;
2892
+ return;
2893
+ }
2894
+ const item = entry.path;
2895
+ let path = sysPath$2.join(directory, item);
2896
+ current.add(item);
2897
+
2898
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
2899
+ return;
2900
+ }
2901
+
2902
+ if (this.fsw.closed) {
2903
+ stream = undefined;
2904
+ return;
2905
+ }
2906
+ // Files that present in current directory snapshot
2907
+ // but absent in previous are added to watch list and
2908
+ // emit `add` event.
2909
+ if (item === target || !target && !previous.has(item)) {
2910
+ this.fsw._incrReadyCount();
2911
+
2912
+ // ensure relativeness of path is preserved in case of watcher reuse
2913
+ path = sysPath$2.join(dir, sysPath$2.relative(dir, path));
2914
+
2915
+ this._addToNodeFs(path, initialAdd, wh, depth + 1);
2916
+ }
2917
+ }).on(EV_ERROR$2, this._boundHandleError);
2918
+
2919
+ return new Promise(resolve =>
2920
+ stream.once(STR_END$2, () => {
2921
+ if (this.fsw.closed) {
2922
+ stream = undefined;
2923
+ return;
2924
+ }
2925
+ const wasThrottled = throttler ? throttler.clear() : false;
2926
+
2927
+ resolve();
2928
+
2929
+ // Files that absent in current directory snapshot
2930
+ // but present in previous emit `remove` event
2931
+ // and are removed from @watched[directory].
2932
+ previous.getChildren().filter((item) => {
2933
+ return item !== directory &&
2934
+ !current.has(item) &&
2935
+ // in case of intersecting globs;
2936
+ // a path may have been filtered out of this readdir, but
2937
+ // shouldn't be removed because it matches a different glob
2938
+ (!wh.hasGlob || wh.filterPath({
2939
+ fullPath: sysPath$2.resolve(directory, item)
2940
+ }));
2941
+ }).forEach((item) => {
2942
+ this.fsw._remove(directory, item);
2943
+ });
2944
+
2945
+ stream = undefined;
2946
+
2947
+ // one more time for any missed in case changes came in extremely quickly
2948
+ if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
2949
+ })
2950
+ );
2951
+ }
2952
+
2953
+ /**
2954
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
2955
+ * @param {String} dir fs path
2956
+ * @param {fs.Stats} stats
2957
+ * @param {Boolean} initialAdd
2958
+ * @param {Number} depth relative to user-supplied path
2959
+ * @param {String} target child path targeted for watch
2960
+ * @param {Object} wh Common watch helpers for this path
2961
+ * @param {String} realpath
2962
+ * @returns {Promise<Function>} closer for the watcher instance.
2963
+ */
2964
+ async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
2965
+ const parentDir = this.fsw._getWatchedDir(sysPath$2.dirname(dir));
2966
+ const tracked = parentDir.has(sysPath$2.basename(dir));
2967
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
2968
+ if (!wh.hasGlob || wh.globFilter(dir)) this.fsw._emit(EV_ADD_DIR$2, dir, stats);
2969
+ }
2970
+
2971
+ // ensure dir is tracked (harmless if redundant)
2972
+ parentDir.add(sysPath$2.basename(dir));
2973
+ this.fsw._getWatchedDir(dir);
2974
+ let throttler;
2975
+ let closer;
2976
+
2977
+ const oDepth = this.fsw.options.depth;
2978
+ if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
2979
+ if (!target) {
2980
+ await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
2981
+ if (this.fsw.closed) return;
2982
+ }
2983
+
2984
+ closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
2985
+ // if current directory is removed, do nothing
2986
+ if (stats && stats.mtimeMs === 0) return;
2987
+
2988
+ this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
2989
+ });
2990
+ }
2991
+ return closer;
2992
+ }
2993
+
2994
+ /**
2995
+ * Handle added file, directory, or glob pattern.
2996
+ * Delegates call to _handleFile / _handleDir after checks.
2997
+ * @param {String} path to file or ir
2998
+ * @param {Boolean} initialAdd was the file added at watch instantiation?
2999
+ * @param {Object} priorWh depth relative to user-supplied path
3000
+ * @param {Number} depth Child path actually targeted for watch
3001
+ * @param {String=} target Child path actually targeted for watch
3002
+ * @returns {Promise}
3003
+ */
3004
+ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
3005
+ const ready = this.fsw._emitReady;
3006
+ if (this.fsw._isIgnored(path) || this.fsw.closed) {
3007
+ ready();
3008
+ return false;
3009
+ }
3010
+
3011
+ const wh = this.fsw._getWatchHelpers(path, depth);
3012
+ if (!wh.hasGlob && priorWh) {
3013
+ wh.hasGlob = priorWh.hasGlob;
3014
+ wh.globFilter = priorWh.globFilter;
3015
+ wh.filterPath = entry => priorWh.filterPath(entry);
3016
+ wh.filterDir = entry => priorWh.filterDir(entry);
3017
+ }
3018
+
3019
+ // evaluate what is at the path we're being asked to watch
3020
+ try {
3021
+ const stats = await statMethods$1[wh.statMethod](wh.watchPath);
3022
+ if (this.fsw.closed) return;
3023
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
3024
+ ready();
3025
+ return false;
3026
+ }
3027
+
3028
+ const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START$1);
3029
+ let closer;
3030
+ if (stats.isDirectory()) {
3031
+ const absPath = sysPath$2.resolve(path);
3032
+ const targetPath = follow ? await fsrealpath(path) : path;
3033
+ if (this.fsw.closed) return;
3034
+ closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
3035
+ if (this.fsw.closed) return;
3036
+ // preserve this symlink's target path
3037
+ if (absPath !== targetPath && targetPath !== undefined) {
3038
+ this.fsw._symlinkPaths.set(absPath, targetPath);
3039
+ }
3040
+ } else if (stats.isSymbolicLink()) {
3041
+ const targetPath = follow ? await fsrealpath(path) : path;
3042
+ if (this.fsw.closed) return;
3043
+ const parent = sysPath$2.dirname(wh.watchPath);
3044
+ this.fsw._getWatchedDir(parent).add(wh.watchPath);
3045
+ this.fsw._emit(EV_ADD$2, wh.watchPath, stats);
3046
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
3047
+ if (this.fsw.closed) return;
3048
+
3049
+ // preserve this symlink's target path
3050
+ if (targetPath !== undefined) {
3051
+ this.fsw._symlinkPaths.set(sysPath$2.resolve(path), targetPath);
3052
+ }
3053
+ } else {
3054
+ closer = this._handleFile(wh.watchPath, stats, initialAdd);
3055
+ }
3056
+ ready();
3057
+
3058
+ this.fsw._addPathCloser(path, closer);
3059
+ return false;
3060
+
3061
+ } catch (error) {
3062
+ if (this.fsw._handleError(error)) {
3063
+ ready();
3064
+ return path;
3065
+ }
3066
+ }
3067
+ }
3068
+
3069
+ };
3070
+
3071
+ var nodefsHandler = NodeFsHandler$1;
3072
+
3073
+ var fseventsHandler = {exports: {}};
3074
+
3075
+ const require$$3 = /*@__PURE__*/getAugmentedNamespace(fseventsImporter);
3076
+
3077
+ const fs$1 = require$$0$1;
3078
+ const sysPath$1 = require$$0$2;
3079
+ const { promisify: promisify$1 } = require$$2;
3080
+
3081
+ let fsevents;
3082
+ try {
3083
+ fsevents = require$$3.getFsEvents();
3084
+ } catch (error) {
3085
+ if (process.env.CHOKIDAR_PRINT_FSEVENTS_REQUIRE_ERROR) console.error(error);
3086
+ }
3087
+
3088
+ if (fsevents) {
3089
+ // TODO: real check
3090
+ const mtch = process.version.match(/v(\d+)\.(\d+)/);
3091
+ if (mtch && mtch[1] && mtch[2]) {
3092
+ const maj = Number.parseInt(mtch[1], 10);
3093
+ const min = Number.parseInt(mtch[2], 10);
3094
+ if (maj === 8 && min < 16) {
3095
+ fsevents = undefined;
3096
+ }
3097
+ }
3098
+ }
3099
+
3100
+ const {
3101
+ EV_ADD: EV_ADD$1,
3102
+ EV_CHANGE: EV_CHANGE$1,
3103
+ EV_ADD_DIR: EV_ADD_DIR$1,
3104
+ EV_UNLINK: EV_UNLINK$1,
3105
+ EV_ERROR: EV_ERROR$1,
3106
+ STR_DATA,
3107
+ STR_END: STR_END$1,
3108
+ FSEVENT_CREATED,
3109
+ FSEVENT_MODIFIED,
3110
+ FSEVENT_DELETED,
3111
+ FSEVENT_MOVED,
3112
+ // FSEVENT_CLONED,
3113
+ FSEVENT_UNKNOWN,
3114
+ FSEVENT_TYPE_FILE,
3115
+ FSEVENT_TYPE_DIRECTORY,
3116
+ FSEVENT_TYPE_SYMLINK,
3117
+
3118
+ ROOT_GLOBSTAR,
3119
+ DIR_SUFFIX,
3120
+ DOT_SLASH,
3121
+ FUNCTION_TYPE: FUNCTION_TYPE$1,
3122
+ EMPTY_FN: EMPTY_FN$1,
3123
+ IDENTITY_FN
3124
+ } = constants;
3125
+
3126
+ const Depth = (value) => isNaN(value) ? {} : {depth: value};
3127
+
3128
+ const stat$1 = promisify$1(fs$1.stat);
3129
+ const lstat = promisify$1(fs$1.lstat);
3130
+ const realpath = promisify$1(fs$1.realpath);
3131
+
3132
+ const statMethods = { stat: stat$1, lstat };
3133
+
3134
+ /**
3135
+ * @typedef {String} Path
3136
+ */
3137
+
3138
+ /**
3139
+ * @typedef {Object} FsEventsWatchContainer
3140
+ * @property {Set<Function>} listeners
3141
+ * @property {Function} rawEmitter
3142
+ * @property {{stop: Function}} watcher
3143
+ */
3144
+
3145
+ // fsevents instance helper functions
3146
+ /**
3147
+ * Object to hold per-process fsevents instances (may be shared across chokidar FSWatcher instances)
3148
+ * @type {Map<Path,FsEventsWatchContainer>}
3149
+ */
3150
+ const FSEventsWatchers = new Map();
3151
+
3152
+ // Threshold of duplicate path prefixes at which to start
3153
+ // consolidating going forward
3154
+ const consolidateThreshhold = 10;
3155
+
3156
+ const wrongEventFlags = new Set([
3157
+ 69888, 70400, 71424, 72704, 73472, 131328, 131840, 262912
3158
+ ]);
3159
+
3160
+ /**
3161
+ * Instantiates the fsevents interface
3162
+ * @param {Path} path path to be watched
3163
+ * @param {Function} callback called when fsevents is bound and ready
3164
+ * @returns {{stop: Function}} new fsevents instance
3165
+ */
3166
+ const createFSEventsInstance = (path, callback) => {
3167
+ const stop = fsevents.watch(path, callback);
3168
+ return {stop};
3169
+ };
3170
+
3171
+ /**
3172
+ * Instantiates the fsevents interface or binds listeners to an existing one covering
3173
+ * the same file tree.
3174
+ * @param {Path} path - to be watched
3175
+ * @param {Path} realPath - real path for symlinks
3176
+ * @param {Function} listener - called when fsevents emits events
3177
+ * @param {Function} rawEmitter - passes data to listeners of the 'raw' event
3178
+ * @returns {Function} closer
3179
+ */
3180
+ function setFSEventsListener(path, realPath, listener, rawEmitter) {
3181
+ let watchPath = sysPath$1.extname(realPath) ? sysPath$1.dirname(realPath) : realPath;
3182
+
3183
+ const parentPath = sysPath$1.dirname(watchPath);
3184
+ let cont = FSEventsWatchers.get(watchPath);
3185
+
3186
+ // If we've accumulated a substantial number of paths that
3187
+ // could have been consolidated by watching one directory
3188
+ // above the current one, create a watcher on the parent
3189
+ // path instead, so that we do consolidate going forward.
3190
+ if (couldConsolidate(parentPath)) {
3191
+ watchPath = parentPath;
3192
+ }
3193
+
3194
+ const resolvedPath = sysPath$1.resolve(path);
3195
+ const hasSymlink = resolvedPath !== realPath;
3196
+
3197
+ const filteredListener = (fullPath, flags, info) => {
3198
+ if (hasSymlink) fullPath = fullPath.replace(realPath, resolvedPath);
3199
+ if (
3200
+ fullPath === resolvedPath ||
3201
+ !fullPath.indexOf(resolvedPath + sysPath$1.sep)
3202
+ ) listener(fullPath, flags, info);
3203
+ };
3204
+
3205
+ // check if there is already a watcher on a parent path
3206
+ // modifies `watchPath` to the parent path when it finds a match
3207
+ let watchedParent = false;
3208
+ for (const watchedPath of FSEventsWatchers.keys()) {
3209
+ if (realPath.indexOf(sysPath$1.resolve(watchedPath) + sysPath$1.sep) === 0) {
3210
+ watchPath = watchedPath;
3211
+ cont = FSEventsWatchers.get(watchPath);
3212
+ watchedParent = true;
3213
+ break;
3214
+ }
3215
+ }
3216
+
3217
+ if (cont || watchedParent) {
3218
+ cont.listeners.add(filteredListener);
3219
+ } else {
3220
+ cont = {
3221
+ listeners: new Set([filteredListener]),
3222
+ rawEmitter,
3223
+ watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
3224
+ if (!cont.listeners.size) return;
3225
+ const info = fsevents.getInfo(fullPath, flags);
3226
+ cont.listeners.forEach(list => {
3227
+ list(fullPath, flags, info);
3228
+ });
3229
+
3230
+ cont.rawEmitter(info.event, fullPath, info);
3231
+ })
3232
+ };
3233
+ FSEventsWatchers.set(watchPath, cont);
3234
+ }
3235
+
3236
+ // removes this instance's listeners and closes the underlying fsevents
3237
+ // instance if there are no more listeners left
3238
+ return () => {
3239
+ const lst = cont.listeners;
3240
+
3241
+ lst.delete(filteredListener);
3242
+ if (!lst.size) {
3243
+ FSEventsWatchers.delete(watchPath);
3244
+ if (cont.watcher) return cont.watcher.stop().then(() => {
3245
+ cont.rawEmitter = cont.watcher = undefined;
3246
+ Object.freeze(cont);
3247
+ });
3248
+ }
3249
+ };
3250
+ }
3251
+
3252
+ // Decide whether or not we should start a new higher-level
3253
+ // parent watcher
3254
+ const couldConsolidate = (path) => {
3255
+ let count = 0;
3256
+ for (const watchPath of FSEventsWatchers.keys()) {
3257
+ if (watchPath.indexOf(path) === 0) {
3258
+ count++;
3259
+ if (count >= consolidateThreshhold) {
3260
+ return true;
3261
+ }
3262
+ }
3263
+ }
3264
+
3265
+ return false;
3266
+ };
3267
+
3268
+ // returns boolean indicating whether fsevents can be used
3269
+ const canUse = () => fsevents && FSEventsWatchers.size < 128;
3270
+
3271
+ // determines subdirectory traversal levels from root to path
3272
+ const calcDepth = (path, root) => {
3273
+ let i = 0;
3274
+ while (!path.indexOf(root) && (path = sysPath$1.dirname(path)) !== root) i++;
3275
+ return i;
3276
+ };
3277
+
3278
+ // returns boolean indicating whether the fsevents' event info has the same type
3279
+ // as the one returned by fs.stat
3280
+ const sameTypes = (info, stats) => (
3281
+ info.type === FSEVENT_TYPE_DIRECTORY && stats.isDirectory() ||
3282
+ info.type === FSEVENT_TYPE_SYMLINK && stats.isSymbolicLink() ||
3283
+ info.type === FSEVENT_TYPE_FILE && stats.isFile()
3284
+ );
3285
+
3286
+ /**
3287
+ * @mixin
3288
+ */
3289
+ let FsEventsHandler$1 = class FsEventsHandler {
3290
+
3291
+ /**
3292
+ * @param {import('../index').FSWatcher} fsw
3293
+ */
3294
+ constructor(fsw) {
3295
+ this.fsw = fsw;
3296
+ }
3297
+ checkIgnored(path, stats) {
3298
+ const ipaths = this.fsw._ignoredPaths;
3299
+ if (this.fsw._isIgnored(path, stats)) {
3300
+ ipaths.add(path);
3301
+ if (stats && stats.isDirectory()) {
3302
+ ipaths.add(path + ROOT_GLOBSTAR);
3303
+ }
3304
+ return true;
3305
+ }
3306
+
3307
+ ipaths.delete(path);
3308
+ ipaths.delete(path + ROOT_GLOBSTAR);
3309
+ }
3310
+
3311
+ addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
3312
+ const event = watchedDir.has(item) ? EV_CHANGE$1 : EV_ADD$1;
3313
+ this.handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3314
+ }
3315
+
3316
+ async checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
3317
+ try {
3318
+ const stats = await stat$1(path);
3319
+ if (this.fsw.closed) return;
3320
+ if (sameTypes(info, stats)) {
3321
+ this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3322
+ } else {
3323
+ this.handleEvent(EV_UNLINK$1, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3324
+ }
3325
+ } catch (error) {
3326
+ if (error.code === 'EACCES') {
3327
+ this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3328
+ } else {
3329
+ this.handleEvent(EV_UNLINK$1, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3330
+ }
3331
+ }
3332
+ }
3333
+
3334
+ handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts) {
3335
+ if (this.fsw.closed || this.checkIgnored(path)) return;
3336
+
3337
+ if (event === EV_UNLINK$1) {
3338
+ const isDirectory = info.type === FSEVENT_TYPE_DIRECTORY;
3339
+ // suppress unlink events on never before seen files
3340
+ if (isDirectory || watchedDir.has(item)) {
3341
+ this.fsw._remove(parent, item, isDirectory);
3342
+ }
3343
+ } else {
3344
+ if (event === EV_ADD$1) {
3345
+ // track new directories
3346
+ if (info.type === FSEVENT_TYPE_DIRECTORY) this.fsw._getWatchedDir(path);
3347
+
3348
+ if (info.type === FSEVENT_TYPE_SYMLINK && opts.followSymlinks) {
3349
+ // push symlinks back to the top of the stack to get handled
3350
+ const curDepth = opts.depth === undefined ?
3351
+ undefined : calcDepth(fullPath, realPath) + 1;
3352
+ return this._addToFsEvents(path, false, true, curDepth);
3353
+ }
3354
+
3355
+ // track new paths
3356
+ // (other than symlinks being followed, which will be tracked soon)
3357
+ this.fsw._getWatchedDir(parent).add(item);
3358
+ }
3359
+ /**
3360
+ * @type {'add'|'addDir'|'unlink'|'unlinkDir'}
3361
+ */
3362
+ const eventName = info.type === FSEVENT_TYPE_DIRECTORY ? event + DIR_SUFFIX : event;
3363
+ this.fsw._emit(eventName, path);
3364
+ if (eventName === EV_ADD_DIR$1) this._addToFsEvents(path, false, true);
3365
+ }
3366
+ }
3367
+
3368
+ /**
3369
+ * Handle symlinks encountered during directory scan
3370
+ * @param {String} watchPath - file/dir path to be watched with fsevents
3371
+ * @param {String} realPath - real path (in case of symlinks)
3372
+ * @param {Function} transform - path transformer
3373
+ * @param {Function} globFilter - path filter in case a glob pattern was provided
3374
+ * @returns {Function} closer for the watcher instance
3375
+ */
3376
+ _watchWithFsEvents(watchPath, realPath, transform, globFilter) {
3377
+ if (this.fsw.closed || this.fsw._isIgnored(watchPath)) return;
3378
+ const opts = this.fsw.options;
3379
+ const watchCallback = async (fullPath, flags, info) => {
3380
+ if (this.fsw.closed) return;
3381
+ if (
3382
+ opts.depth !== undefined &&
3383
+ calcDepth(fullPath, realPath) > opts.depth
3384
+ ) return;
3385
+ const path = transform(sysPath$1.join(
3386
+ watchPath, sysPath$1.relative(watchPath, fullPath)
3387
+ ));
3388
+ if (globFilter && !globFilter(path)) return;
3389
+ // ensure directories are tracked
3390
+ const parent = sysPath$1.dirname(path);
3391
+ const item = sysPath$1.basename(path);
3392
+ const watchedDir = this.fsw._getWatchedDir(
3393
+ info.type === FSEVENT_TYPE_DIRECTORY ? path : parent
3394
+ );
3395
+
3396
+ // correct for wrong events emitted
3397
+ if (wrongEventFlags.has(flags) || info.event === FSEVENT_UNKNOWN) {
3398
+ if (typeof opts.ignored === FUNCTION_TYPE$1) {
3399
+ let stats;
3400
+ try {
3401
+ stats = await stat$1(path);
3402
+ } catch (error) {}
3403
+ if (this.fsw.closed) return;
3404
+ if (this.checkIgnored(path, stats)) return;
3405
+ if (sameTypes(info, stats)) {
3406
+ this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3407
+ } else {
3408
+ this.handleEvent(EV_UNLINK$1, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3409
+ }
3410
+ } else {
3411
+ this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3412
+ }
3413
+ } else {
3414
+ switch (info.event) {
3415
+ case FSEVENT_CREATED:
3416
+ case FSEVENT_MODIFIED:
3417
+ return this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3418
+ case FSEVENT_DELETED:
3419
+ case FSEVENT_MOVED:
3420
+ return this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3421
+ }
3422
+ }
3423
+ };
3424
+
3425
+ const closer = setFSEventsListener(
3426
+ watchPath,
3427
+ realPath,
3428
+ watchCallback,
3429
+ this.fsw._emitRaw
3430
+ );
3431
+
3432
+ this.fsw._emitReady();
3433
+ return closer;
3434
+ }
3435
+
3436
+ /**
3437
+ * Handle symlinks encountered during directory scan
3438
+ * @param {String} linkPath path to symlink
3439
+ * @param {String} fullPath absolute path to the symlink
3440
+ * @param {Function} transform pre-existing path transformer
3441
+ * @param {Number} curDepth level of subdirectories traversed to where symlink is
3442
+ * @returns {Promise<void>}
3443
+ */
3444
+ async _handleFsEventsSymlink(linkPath, fullPath, transform, curDepth) {
3445
+ // don't follow the same symlink more than once
3446
+ if (this.fsw.closed || this.fsw._symlinkPaths.has(fullPath)) return;
3447
+
3448
+ this.fsw._symlinkPaths.set(fullPath, true);
3449
+ this.fsw._incrReadyCount();
3450
+
3451
+ try {
3452
+ const linkTarget = await realpath(linkPath);
3453
+ if (this.fsw.closed) return;
3454
+ if (this.fsw._isIgnored(linkTarget)) {
3455
+ return this.fsw._emitReady();
3456
+ }
3457
+
3458
+ this.fsw._incrReadyCount();
3459
+
3460
+ // add the linkTarget for watching with a wrapper for transform
3461
+ // that causes emitted paths to incorporate the link's path
3462
+ this._addToFsEvents(linkTarget || linkPath, (path) => {
3463
+ let aliasedPath = linkPath;
3464
+ if (linkTarget && linkTarget !== DOT_SLASH) {
3465
+ aliasedPath = path.replace(linkTarget, linkPath);
3466
+ } else if (path !== DOT_SLASH) {
3467
+ aliasedPath = sysPath$1.join(linkPath, path);
3468
+ }
3469
+ return transform(aliasedPath);
3470
+ }, false, curDepth);
3471
+ } catch(error) {
3472
+ if (this.fsw._handleError(error)) {
3473
+ return this.fsw._emitReady();
3474
+ }
3475
+ }
3476
+ }
3477
+
3478
+ /**
3479
+ *
3480
+ * @param {Path} newPath
3481
+ * @param {fs.Stats} stats
3482
+ */
3483
+ emitAdd(newPath, stats, processPath, opts, forceAdd) {
3484
+ const pp = processPath(newPath);
3485
+ const isDir = stats.isDirectory();
3486
+ const dirObj = this.fsw._getWatchedDir(sysPath$1.dirname(pp));
3487
+ const base = sysPath$1.basename(pp);
3488
+
3489
+ // ensure empty dirs get tracked
3490
+ if (isDir) this.fsw._getWatchedDir(pp);
3491
+ if (dirObj.has(base)) return;
3492
+ dirObj.add(base);
3493
+
3494
+ if (!opts.ignoreInitial || forceAdd === true) {
3495
+ this.fsw._emit(isDir ? EV_ADD_DIR$1 : EV_ADD$1, pp, stats);
3496
+ }
3497
+ }
3498
+
3499
+ initWatch(realPath, path, wh, processPath) {
3500
+ if (this.fsw.closed) return;
3501
+ const closer = this._watchWithFsEvents(
3502
+ wh.watchPath,
3503
+ sysPath$1.resolve(realPath || wh.watchPath),
3504
+ processPath,
3505
+ wh.globFilter
3506
+ );
3507
+ this.fsw._addPathCloser(path, closer);
3508
+ }
3509
+
3510
+ /**
3511
+ * Handle added path with fsevents
3512
+ * @param {String} path file/dir path or glob pattern
3513
+ * @param {Function|Boolean=} transform converts working path to what the user expects
3514
+ * @param {Boolean=} forceAdd ensure add is emitted
3515
+ * @param {Number=} priorDepth Level of subdirectories already traversed.
3516
+ * @returns {Promise<void>}
3517
+ */
3518
+ async _addToFsEvents(path, transform, forceAdd, priorDepth) {
3519
+ if (this.fsw.closed) {
3520
+ return;
3521
+ }
3522
+ const opts = this.fsw.options;
3523
+ const processPath = typeof transform === FUNCTION_TYPE$1 ? transform : IDENTITY_FN;
3524
+
3525
+ const wh = this.fsw._getWatchHelpers(path);
3526
+
3527
+ // evaluate what is at the path we're being asked to watch
3528
+ try {
3529
+ const stats = await statMethods[wh.statMethod](wh.watchPath);
3530
+ if (this.fsw.closed) return;
3531
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
3532
+ throw null;
3533
+ }
3534
+ if (stats.isDirectory()) {
3535
+ // emit addDir unless this is a glob parent
3536
+ if (!wh.globFilter) this.emitAdd(processPath(path), stats, processPath, opts, forceAdd);
3537
+
3538
+ // don't recurse further if it would exceed depth setting
3539
+ if (priorDepth && priorDepth > opts.depth) return;
3540
+
3541
+ // scan the contents of the dir
3542
+ this.fsw._readdirp(wh.watchPath, {
3543
+ fileFilter: entry => wh.filterPath(entry),
3544
+ directoryFilter: entry => wh.filterDir(entry),
3545
+ ...Depth(opts.depth - (priorDepth || 0))
3546
+ }).on(STR_DATA, (entry) => {
3547
+ // need to check filterPath on dirs b/c filterDir is less restrictive
3548
+ if (this.fsw.closed) {
3549
+ return;
3550
+ }
3551
+ if (entry.stats.isDirectory() && !wh.filterPath(entry)) return;
3552
+
3553
+ const joinedPath = sysPath$1.join(wh.watchPath, entry.path);
3554
+ const {fullPath} = entry;
3555
+
3556
+ if (wh.followSymlinks && entry.stats.isSymbolicLink()) {
3557
+ // preserve the current depth here since it can't be derived from
3558
+ // real paths past the symlink
3559
+ const curDepth = opts.depth === undefined ?
3560
+ undefined : calcDepth(joinedPath, sysPath$1.resolve(wh.watchPath)) + 1;
3561
+
3562
+ this._handleFsEventsSymlink(joinedPath, fullPath, processPath, curDepth);
3563
+ } else {
3564
+ this.emitAdd(joinedPath, entry.stats, processPath, opts, forceAdd);
3565
+ }
3566
+ }).on(EV_ERROR$1, EMPTY_FN$1).on(STR_END$1, () => {
3567
+ this.fsw._emitReady();
3568
+ });
3569
+ } else {
3570
+ this.emitAdd(wh.watchPath, stats, processPath, opts, forceAdd);
3571
+ this.fsw._emitReady();
3572
+ }
3573
+ } catch (error) {
3574
+ if (!error || this.fsw._handleError(error)) {
3575
+ // TODO: Strange thing: "should not choke on an ignored watch path" will be failed without 2 ready calls -__-
3576
+ this.fsw._emitReady();
3577
+ this.fsw._emitReady();
3578
+ }
3579
+ }
3580
+
3581
+ if (opts.persistent && forceAdd !== true) {
3582
+ if (typeof transform === FUNCTION_TYPE$1) {
3583
+ // realpath has already been resolved
3584
+ this.initWatch(undefined, path, wh, processPath);
3585
+ } else {
3586
+ let realPath;
3587
+ try {
3588
+ realPath = await realpath(wh.watchPath);
3589
+ } catch (e) {}
3590
+ this.initWatch(realPath, path, wh, processPath);
3591
+ }
3592
+ }
3593
+ }
3594
+
3595
+ };
3596
+
3597
+ fseventsHandler.exports = FsEventsHandler$1;
3598
+ fseventsHandler.exports.canUse = canUse;
3599
+
3600
+ var fseventsHandlerExports = fseventsHandler.exports;
3601
+
3602
+ const { EventEmitter } = require$$0$3;
3603
+ const fs = require$$0$1;
3604
+ const sysPath = require$$0$2;
3605
+ const { promisify } = require$$2;
3606
+ const readdirp = readdirp_1;
3607
+ const anymatch = anymatchExports.default;
3608
+ const globParent = globParent$1;
3609
+ const isGlob = isGlob$2;
3610
+ const braces = braces_1;
3611
+ const normalizePath = normalizePath$2;
3612
+
3613
+ const NodeFsHandler = nodefsHandler;
3614
+ const FsEventsHandler = fseventsHandlerExports;
3615
+ const {
3616
+ EV_ALL,
3617
+ EV_READY,
3618
+ EV_ADD,
3619
+ EV_CHANGE,
3620
+ EV_UNLINK,
3621
+ EV_ADD_DIR,
3622
+ EV_UNLINK_DIR,
3623
+ EV_RAW,
3624
+ EV_ERROR,
3625
+
3626
+ STR_CLOSE,
3627
+ STR_END,
3628
+
3629
+ BACK_SLASH_RE,
3630
+ DOUBLE_SLASH_RE,
3631
+ SLASH_OR_BACK_SLASH_RE,
3632
+ DOT_RE,
3633
+ REPLACER_RE,
3634
+
3635
+ SLASH,
3636
+ SLASH_SLASH,
3637
+ BRACE_START,
3638
+ BANG,
3639
+ ONE_DOT,
3640
+ TWO_DOTS,
3641
+ GLOBSTAR,
3642
+ SLASH_GLOBSTAR,
3643
+ ANYMATCH_OPTS,
3644
+ STRING_TYPE,
3645
+ FUNCTION_TYPE,
3646
+ EMPTY_STR,
3647
+ EMPTY_FN,
3648
+
3649
+ isWindows,
3650
+ isMacos,
3651
+ isIBMi
3652
+ } = constants;
3653
+
3654
+ const stat = promisify(fs.stat);
3655
+ const readdir = promisify(fs.readdir);
3656
+
3657
+ /**
3658
+ * @typedef {String} Path
3659
+ * @typedef {'all'|'add'|'addDir'|'change'|'unlink'|'unlinkDir'|'raw'|'error'|'ready'} EventName
3660
+ * @typedef {'readdir'|'watch'|'add'|'remove'|'change'} ThrottleType
3661
+ */
3662
+
3663
+ /**
3664
+ *
3665
+ * @typedef {Object} WatchHelpers
3666
+ * @property {Boolean} followSymlinks
3667
+ * @property {'stat'|'lstat'} statMethod
3668
+ * @property {Path} path
3669
+ * @property {Path} watchPath
3670
+ * @property {Function} entryPath
3671
+ * @property {Boolean} hasGlob
3672
+ * @property {Object} globFilter
3673
+ * @property {Function} filterPath
3674
+ * @property {Function} filterDir
3675
+ */
3676
+
3677
+ const arrify = (value = []) => Array.isArray(value) ? value : [value];
3678
+ const flatten = (list, result = []) => {
3679
+ list.forEach(item => {
3680
+ if (Array.isArray(item)) {
3681
+ flatten(item, result);
3682
+ } else {
3683
+ result.push(item);
3684
+ }
3685
+ });
3686
+ return result;
3687
+ };
3688
+
3689
+ const unifyPaths = (paths_) => {
3690
+ /**
3691
+ * @type {Array<String>}
3692
+ */
3693
+ const paths = flatten(arrify(paths_));
3694
+ if (!paths.every(p => typeof p === STRING_TYPE)) {
3695
+ throw new TypeError(`Non-string provided as watch path: ${paths}`);
3696
+ }
3697
+ return paths.map(normalizePathToUnix);
3698
+ };
3699
+
3700
+ // If SLASH_SLASH occurs at the beginning of path, it is not replaced
3701
+ // because "//StoragePC/DrivePool/Movies" is a valid network path
3702
+ const toUnix = (string) => {
3703
+ let str = string.replace(BACK_SLASH_RE, SLASH);
3704
+ let prepend = false;
3705
+ if (str.startsWith(SLASH_SLASH)) {
3706
+ prepend = true;
3707
+ }
3708
+ while (str.match(DOUBLE_SLASH_RE)) {
3709
+ str = str.replace(DOUBLE_SLASH_RE, SLASH);
3710
+ }
3711
+ if (prepend) {
3712
+ str = SLASH + str;
3713
+ }
3714
+ return str;
3715
+ };
3716
+
3717
+ // Our version of upath.normalize
3718
+ // TODO: this is not equal to path-normalize module - investigate why
3719
+ const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
3720
+
3721
+ const normalizeIgnored = (cwd = EMPTY_STR) => (path) => {
3722
+ if (typeof path !== STRING_TYPE) return path;
3723
+ return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
3724
+ };
3725
+
3726
+ const getAbsolutePath = (path, cwd) => {
3727
+ if (sysPath.isAbsolute(path)) {
3728
+ return path;
3729
+ }
3730
+ if (path.startsWith(BANG)) {
3731
+ return BANG + sysPath.join(cwd, path.slice(1));
3732
+ }
3733
+ return sysPath.join(cwd, path);
3734
+ };
3735
+
3736
+ const undef = (opts, key) => opts[key] === undefined;
3737
+
3738
+ /**
3739
+ * Directory entry.
3740
+ * @property {Path} path
3741
+ * @property {Set<Path>} items
3742
+ */
3743
+ class DirEntry {
3744
+ /**
3745
+ * @param {Path} dir
3746
+ * @param {Function} removeWatcher
3747
+ */
3748
+ constructor(dir, removeWatcher) {
3749
+ this.path = dir;
3750
+ this._removeWatcher = removeWatcher;
3751
+ /** @type {Set<Path>} */
3752
+ this.items = new Set();
3753
+ }
3754
+
3755
+ add(item) {
3756
+ const {items} = this;
3757
+ if (!items) return;
3758
+ if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
3759
+ }
3760
+
3761
+ async remove(item) {
3762
+ const {items} = this;
3763
+ if (!items) return;
3764
+ items.delete(item);
3765
+ if (items.size > 0) return;
3766
+
3767
+ const dir = this.path;
3768
+ try {
3769
+ await readdir(dir);
3770
+ } catch (err) {
3771
+ if (this._removeWatcher) {
3772
+ this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
3773
+ }
3774
+ }
3775
+ }
3776
+
3777
+ has(item) {
3778
+ const {items} = this;
3779
+ if (!items) return;
3780
+ return items.has(item);
3781
+ }
3782
+
3783
+ /**
3784
+ * @returns {Array<String>}
3785
+ */
3786
+ getChildren() {
3787
+ const {items} = this;
3788
+ if (!items) return;
3789
+ return [...items.values()];
3790
+ }
3791
+
3792
+ dispose() {
3793
+ this.items.clear();
3794
+ delete this.path;
3795
+ delete this._removeWatcher;
3796
+ delete this.items;
3797
+ Object.freeze(this);
3798
+ }
3799
+ }
3800
+
3801
+ const STAT_METHOD_F = 'stat';
3802
+ const STAT_METHOD_L = 'lstat';
3803
+ class WatchHelper {
3804
+ constructor(path, watchPath, follow, fsw) {
3805
+ this.fsw = fsw;
3806
+ this.path = path = path.replace(REPLACER_RE, EMPTY_STR);
3807
+ this.watchPath = watchPath;
3808
+ this.fullWatchPath = sysPath.resolve(watchPath);
3809
+ this.hasGlob = watchPath !== path;
3810
+ /** @type {object|boolean} */
3811
+ if (path === EMPTY_STR) this.hasGlob = false;
3812
+ this.globSymlink = this.hasGlob && follow ? undefined : false;
3813
+ this.globFilter = this.hasGlob ? anymatch(path, undefined, ANYMATCH_OPTS) : false;
3814
+ this.dirParts = this.getDirParts(path);
3815
+ this.dirParts.forEach((parts) => {
3816
+ if (parts.length > 1) parts.pop();
3817
+ });
3818
+ this.followSymlinks = follow;
3819
+ this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
3820
+ }
3821
+
3822
+ checkGlobSymlink(entry) {
3823
+ // only need to resolve once
3824
+ // first entry should always have entry.parentDir === EMPTY_STR
3825
+ if (this.globSymlink === undefined) {
3826
+ this.globSymlink = entry.fullParentDir === this.fullWatchPath ?
3827
+ false : {realPath: entry.fullParentDir, linkPath: this.fullWatchPath};
3828
+ }
3829
+
3830
+ if (this.globSymlink) {
3831
+ return entry.fullPath.replace(this.globSymlink.realPath, this.globSymlink.linkPath);
3832
+ }
3833
+
3834
+ return entry.fullPath;
3835
+ }
3836
+
3837
+ entryPath(entry) {
3838
+ return sysPath.join(this.watchPath,
3839
+ sysPath.relative(this.watchPath, this.checkGlobSymlink(entry))
3840
+ );
3841
+ }
3842
+
3843
+ filterPath(entry) {
3844
+ const {stats} = entry;
3845
+ if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
3846
+ const resolvedPath = this.entryPath(entry);
3847
+ const matchesGlob = this.hasGlob && typeof this.globFilter === FUNCTION_TYPE ?
3848
+ this.globFilter(resolvedPath) : true;
3849
+ return matchesGlob &&
3850
+ this.fsw._isntIgnored(resolvedPath, stats) &&
3851
+ this.fsw._hasReadPermissions(stats);
3852
+ }
3853
+
3854
+ getDirParts(path) {
3855
+ if (!this.hasGlob) return [];
3856
+ const parts = [];
3857
+ const expandedPath = path.includes(BRACE_START) ? braces.expand(path) : [path];
3858
+ expandedPath.forEach((path) => {
3859
+ parts.push(sysPath.relative(this.watchPath, path).split(SLASH_OR_BACK_SLASH_RE));
3860
+ });
3861
+ return parts;
3862
+ }
3863
+
3864
+ filterDir(entry) {
3865
+ if (this.hasGlob) {
3866
+ const entryParts = this.getDirParts(this.checkGlobSymlink(entry));
3867
+ let globstar = false;
3868
+ this.unmatchedGlob = !this.dirParts.some((parts) => {
3869
+ return parts.every((part, i) => {
3870
+ if (part === GLOBSTAR) globstar = true;
3871
+ return globstar || !entryParts[0][i] || anymatch(part, entryParts[0][i], ANYMATCH_OPTS);
3872
+ });
3873
+ });
3874
+ }
3875
+ return !this.unmatchedGlob && this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
3876
+ }
3877
+ }
3878
+
3879
+ /**
3880
+ * Watches files & directories for changes. Emitted events:
3881
+ * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
3882
+ *
3883
+ * new FSWatcher()
3884
+ * .add(directories)
3885
+ * .on('add', path => log('File', path, 'was added'))
3886
+ */
3887
+ class FSWatcher extends EventEmitter {
3888
+ // Not indenting methods for history sake; for now.
3889
+ constructor(_opts) {
3890
+ super();
3891
+
3892
+ const opts = {};
3893
+ if (_opts) Object.assign(opts, _opts); // for frozen objects
3894
+
3895
+ /** @type {Map<String, DirEntry>} */
3896
+ this._watched = new Map();
3897
+ /** @type {Map<String, Array>} */
3898
+ this._closers = new Map();
3899
+ /** @type {Set<String>} */
3900
+ this._ignoredPaths = new Set();
3901
+
3902
+ /** @type {Map<ThrottleType, Map>} */
3903
+ this._throttled = new Map();
3904
+
3905
+ /** @type {Map<Path, String|Boolean>} */
3906
+ this._symlinkPaths = new Map();
3907
+
3908
+ this._streams = new Set();
3909
+ this.closed = false;
3910
+
3911
+ // Set up default options.
3912
+ if (undef(opts, 'persistent')) opts.persistent = true;
3913
+ if (undef(opts, 'ignoreInitial')) opts.ignoreInitial = false;
3914
+ if (undef(opts, 'ignorePermissionErrors')) opts.ignorePermissionErrors = false;
3915
+ if (undef(opts, 'interval')) opts.interval = 100;
3916
+ if (undef(opts, 'binaryInterval')) opts.binaryInterval = 300;
3917
+ if (undef(opts, 'disableGlobbing')) opts.disableGlobbing = false;
3918
+ opts.enableBinaryInterval = opts.binaryInterval !== opts.interval;
3919
+
3920
+ // Enable fsevents on OS X when polling isn't explicitly enabled.
3921
+ if (undef(opts, 'useFsEvents')) opts.useFsEvents = !opts.usePolling;
3922
+
3923
+ // If we can't use fsevents, ensure the options reflect it's disabled.
3924
+ const canUseFsEvents = FsEventsHandler.canUse();
3925
+ if (!canUseFsEvents) opts.useFsEvents = false;
3926
+
3927
+ // Use polling on Mac if not using fsevents.
3928
+ // Other platforms use non-polling fs_watch.
3929
+ if (undef(opts, 'usePolling') && !opts.useFsEvents) {
3930
+ opts.usePolling = isMacos;
3931
+ }
3932
+
3933
+ // Always default to polling on IBM i because fs.watch() is not available on IBM i.
3934
+ if(isIBMi) {
3935
+ opts.usePolling = true;
3936
+ }
3937
+
3938
+ // Global override (useful for end-developers that need to force polling for all
3939
+ // instances of chokidar, regardless of usage/dependency depth)
3940
+ const envPoll = process.env.CHOKIDAR_USEPOLLING;
3941
+ if (envPoll !== undefined) {
3942
+ const envLower = envPoll.toLowerCase();
3943
+
3944
+ if (envLower === 'false' || envLower === '0') {
3945
+ opts.usePolling = false;
3946
+ } else if (envLower === 'true' || envLower === '1') {
3947
+ opts.usePolling = true;
3948
+ } else {
3949
+ opts.usePolling = !!envLower;
3950
+ }
3951
+ }
3952
+ const envInterval = process.env.CHOKIDAR_INTERVAL;
3953
+ if (envInterval) {
3954
+ opts.interval = Number.parseInt(envInterval, 10);
3955
+ }
3956
+
3957
+ // Editor atomic write normalization enabled by default with fs.watch
3958
+ if (undef(opts, 'atomic')) opts.atomic = !opts.usePolling && !opts.useFsEvents;
3959
+ if (opts.atomic) this._pendingUnlinks = new Map();
3960
+
3961
+ if (undef(opts, 'followSymlinks')) opts.followSymlinks = true;
3962
+
3963
+ if (undef(opts, 'awaitWriteFinish')) opts.awaitWriteFinish = false;
3964
+ if (opts.awaitWriteFinish === true) opts.awaitWriteFinish = {};
3965
+ const awf = opts.awaitWriteFinish;
3966
+ if (awf) {
3967
+ if (!awf.stabilityThreshold) awf.stabilityThreshold = 2000;
3968
+ if (!awf.pollInterval) awf.pollInterval = 100;
3969
+ this._pendingWrites = new Map();
3970
+ }
3971
+ if (opts.ignored) opts.ignored = arrify(opts.ignored);
3972
+
3973
+ let readyCalls = 0;
3974
+ this._emitReady = () => {
3975
+ readyCalls++;
3976
+ if (readyCalls >= this._readyCount) {
3977
+ this._emitReady = EMPTY_FN;
3978
+ this._readyEmitted = true;
3979
+ // use process.nextTick to allow time for listener to be bound
3980
+ process.nextTick(() => this.emit(EV_READY));
3981
+ }
3982
+ };
3983
+ this._emitRaw = (...args) => this.emit(EV_RAW, ...args);
3984
+ this._readyEmitted = false;
3985
+ this.options = opts;
3986
+
3987
+ // Initialize with proper watcher.
3988
+ if (opts.useFsEvents) {
3989
+ this._fsEventsHandler = new FsEventsHandler(this);
3990
+ } else {
3991
+ this._nodeFsHandler = new NodeFsHandler(this);
3992
+ }
3993
+
3994
+ // You’re frozen when your heart’s not open.
3995
+ Object.freeze(opts);
3996
+ }
3997
+
3998
+ // Public methods
3999
+
4000
+ /**
4001
+ * Adds paths to be watched on an existing FSWatcher instance
4002
+ * @param {Path|Array<Path>} paths_
4003
+ * @param {String=} _origAdd private; for handling non-existent paths to be watched
4004
+ * @param {Boolean=} _internal private; indicates a non-user add
4005
+ * @returns {FSWatcher} for chaining
4006
+ */
4007
+ add(paths_, _origAdd, _internal) {
4008
+ const {cwd, disableGlobbing} = this.options;
4009
+ this.closed = false;
4010
+ let paths = unifyPaths(paths_);
4011
+ if (cwd) {
4012
+ paths = paths.map((path) => {
4013
+ const absPath = getAbsolutePath(path, cwd);
4014
+
4015
+ // Check `path` instead of `absPath` because the cwd portion can't be a glob
4016
+ if (disableGlobbing || !isGlob(path)) {
4017
+ return absPath;
4018
+ }
4019
+ return normalizePath(absPath);
4020
+ });
4021
+ }
4022
+
4023
+ // set aside negated glob strings
4024
+ paths = paths.filter((path) => {
4025
+ if (path.startsWith(BANG)) {
4026
+ this._ignoredPaths.add(path.slice(1));
4027
+ return false;
4028
+ }
4029
+
4030
+ // if a path is being added that was previously ignored, stop ignoring it
4031
+ this._ignoredPaths.delete(path);
4032
+ this._ignoredPaths.delete(path + SLASH_GLOBSTAR);
4033
+
4034
+ // reset the cached userIgnored anymatch fn
4035
+ // to make ignoredPaths changes effective
4036
+ this._userIgnored = undefined;
4037
+
4038
+ return true;
4039
+ });
4040
+
4041
+ if (this.options.useFsEvents && this._fsEventsHandler) {
4042
+ if (!this._readyCount) this._readyCount = paths.length;
4043
+ if (this.options.persistent) this._readyCount *= 2;
4044
+ paths.forEach((path) => this._fsEventsHandler._addToFsEvents(path));
4045
+ } else {
4046
+ if (!this._readyCount) this._readyCount = 0;
4047
+ this._readyCount += paths.length;
4048
+ Promise.all(
4049
+ paths.map(async path => {
4050
+ const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, 0, 0, _origAdd);
4051
+ if (res) this._emitReady();
4052
+ return res;
4053
+ })
4054
+ ).then(results => {
4055
+ if (this.closed) return;
4056
+ results.filter(item => item).forEach(item => {
4057
+ this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
4058
+ });
4059
+ });
4060
+ }
4061
+
4062
+ return this;
4063
+ }
4064
+
4065
+ /**
4066
+ * Close watchers or start ignoring events from specified paths.
4067
+ * @param {Path|Array<Path>} paths_ - string or array of strings, file/directory paths and/or globs
4068
+ * @returns {FSWatcher} for chaining
4069
+ */
4070
+ unwatch(paths_) {
4071
+ if (this.closed) return this;
4072
+ const paths = unifyPaths(paths_);
4073
+ const {cwd} = this.options;
4074
+
4075
+ paths.forEach((path) => {
4076
+ // convert to absolute path unless relative path already matches
4077
+ if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
4078
+ if (cwd) path = sysPath.join(cwd, path);
4079
+ path = sysPath.resolve(path);
4080
+ }
4081
+
4082
+ this._closePath(path);
4083
+
4084
+ this._ignoredPaths.add(path);
4085
+ if (this._watched.has(path)) {
4086
+ this._ignoredPaths.add(path + SLASH_GLOBSTAR);
4087
+ }
4088
+
4089
+ // reset the cached userIgnored anymatch fn
4090
+ // to make ignoredPaths changes effective
4091
+ this._userIgnored = undefined;
4092
+ });
4093
+
4094
+ return this;
4095
+ }
4096
+
4097
+ /**
4098
+ * Close watchers and remove all listeners from watched paths.
4099
+ * @returns {Promise<void>}.
4100
+ */
4101
+ close() {
4102
+ if (this.closed) return this._closePromise;
4103
+ this.closed = true;
4104
+
4105
+ // Memory management.
4106
+ this.removeAllListeners();
4107
+ const closers = [];
4108
+ this._closers.forEach(closerList => closerList.forEach(closer => {
4109
+ const promise = closer();
4110
+ if (promise instanceof Promise) closers.push(promise);
4111
+ }));
4112
+ this._streams.forEach(stream => stream.destroy());
4113
+ this._userIgnored = undefined;
4114
+ this._readyCount = 0;
4115
+ this._readyEmitted = false;
4116
+ this._watched.forEach(dirent => dirent.dispose());
4117
+ ['closers', 'watched', 'streams', 'symlinkPaths', 'throttled'].forEach(key => {
4118
+ this[`_${key}`].clear();
4119
+ });
4120
+
4121
+ this._closePromise = closers.length ? Promise.all(closers).then(() => undefined) : Promise.resolve();
4122
+ return this._closePromise;
4123
+ }
4124
+
4125
+ /**
4126
+ * Expose list of watched paths
4127
+ * @returns {Object} for chaining
4128
+ */
4129
+ getWatched() {
4130
+ const watchList = {};
4131
+ this._watched.forEach((entry, dir) => {
4132
+ const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
4133
+ watchList[key || ONE_DOT] = entry.getChildren().sort();
4134
+ });
4135
+ return watchList;
4136
+ }
4137
+
4138
+ emitWithAll(event, args) {
4139
+ this.emit(...args);
4140
+ if (event !== EV_ERROR) this.emit(EV_ALL, ...args);
4141
+ }
4142
+
4143
+ // Common helpers
4144
+ // --------------
4145
+
4146
+ /**
4147
+ * Normalize and emit events.
4148
+ * Calling _emit DOES NOT MEAN emit() would be called!
4149
+ * @param {EventName} event Type of event
4150
+ * @param {Path} path File or directory path
4151
+ * @param {*=} val1 arguments to be passed with event
4152
+ * @param {*=} val2
4153
+ * @param {*=} val3
4154
+ * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
4155
+ */
4156
+ async _emit(event, path, val1, val2, val3) {
4157
+ if (this.closed) return;
4158
+
4159
+ const opts = this.options;
4160
+ if (isWindows) path = sysPath.normalize(path);
4161
+ if (opts.cwd) path = sysPath.relative(opts.cwd, path);
4162
+ /** @type Array<any> */
4163
+ const args = [event, path];
4164
+ if (val3 !== undefined) args.push(val1, val2, val3);
4165
+ else if (val2 !== undefined) args.push(val1, val2);
4166
+ else if (val1 !== undefined) args.push(val1);
4167
+
4168
+ const awf = opts.awaitWriteFinish;
4169
+ let pw;
4170
+ if (awf && (pw = this._pendingWrites.get(path))) {
4171
+ pw.lastChange = new Date();
4172
+ return this;
4173
+ }
4174
+
4175
+ if (opts.atomic) {
4176
+ if (event === EV_UNLINK) {
4177
+ this._pendingUnlinks.set(path, args);
4178
+ setTimeout(() => {
4179
+ this._pendingUnlinks.forEach((entry, path) => {
4180
+ this.emit(...entry);
4181
+ this.emit(EV_ALL, ...entry);
4182
+ this._pendingUnlinks.delete(path);
4183
+ });
4184
+ }, typeof opts.atomic === 'number' ? opts.atomic : 100);
4185
+ return this;
4186
+ }
4187
+ if (event === EV_ADD && this._pendingUnlinks.has(path)) {
4188
+ event = args[0] = EV_CHANGE;
4189
+ this._pendingUnlinks.delete(path);
4190
+ }
4191
+ }
4192
+
4193
+ if (awf && (event === EV_ADD || event === EV_CHANGE) && this._readyEmitted) {
4194
+ const awfEmit = (err, stats) => {
4195
+ if (err) {
4196
+ event = args[0] = EV_ERROR;
4197
+ args[1] = err;
4198
+ this.emitWithAll(event, args);
4199
+ } else if (stats) {
4200
+ // if stats doesn't exist the file must have been deleted
4201
+ if (args.length > 2) {
4202
+ args[2] = stats;
4203
+ } else {
4204
+ args.push(stats);
4205
+ }
4206
+ this.emitWithAll(event, args);
4207
+ }
4208
+ };
4209
+
4210
+ this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
4211
+ return this;
4212
+ }
4213
+
4214
+ if (event === EV_CHANGE) {
4215
+ const isThrottled = !this._throttle(EV_CHANGE, path, 50);
4216
+ if (isThrottled) return this;
4217
+ }
4218
+
4219
+ if (opts.alwaysStat && val1 === undefined &&
4220
+ (event === EV_ADD || event === EV_ADD_DIR || event === EV_CHANGE)
4221
+ ) {
4222
+ const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
4223
+ let stats;
4224
+ try {
4225
+ stats = await stat(fullPath);
4226
+ } catch (err) {}
4227
+ // Suppress event when fs_stat fails, to avoid sending undefined 'stat'
4228
+ if (!stats || this.closed) return;
4229
+ args.push(stats);
4230
+ }
4231
+ this.emitWithAll(event, args);
4232
+
4233
+ return this;
4234
+ }
4235
+
4236
+ /**
4237
+ * Common handler for errors
4238
+ * @param {Error} error
4239
+ * @returns {Error|Boolean} The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
4240
+ */
4241
+ _handleError(error) {
4242
+ const code = error && error.code;
4243
+ if (error && code !== 'ENOENT' && code !== 'ENOTDIR' &&
4244
+ (!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))
4245
+ ) {
4246
+ this.emit(EV_ERROR, error);
4247
+ }
4248
+ return error || this.closed;
4249
+ }
4250
+
4251
+ /**
4252
+ * Helper utility for throttling
4253
+ * @param {ThrottleType} actionType type being throttled
4254
+ * @param {Path} path being acted upon
4255
+ * @param {Number} timeout duration of time to suppress duplicate actions
4256
+ * @returns {Object|false} tracking object or false if action should be suppressed
4257
+ */
4258
+ _throttle(actionType, path, timeout) {
4259
+ if (!this._throttled.has(actionType)) {
4260
+ this._throttled.set(actionType, new Map());
4261
+ }
4262
+
4263
+ /** @type {Map<Path, Object>} */
4264
+ const action = this._throttled.get(actionType);
4265
+ /** @type {Object} */
4266
+ const actionPath = action.get(path);
4267
+
4268
+ if (actionPath) {
4269
+ actionPath.count++;
4270
+ return false;
4271
+ }
4272
+
4273
+ let timeoutObject;
4274
+ const clear = () => {
4275
+ const item = action.get(path);
4276
+ const count = item ? item.count : 0;
4277
+ action.delete(path);
4278
+ clearTimeout(timeoutObject);
4279
+ if (item) clearTimeout(item.timeoutObject);
4280
+ return count;
4281
+ };
4282
+ timeoutObject = setTimeout(clear, timeout);
4283
+ const thr = {timeoutObject, clear, count: 0};
4284
+ action.set(path, thr);
4285
+ return thr;
4286
+ }
4287
+
4288
+ _incrReadyCount() {
4289
+ return this._readyCount++;
4290
+ }
4291
+
4292
+ /**
4293
+ * Awaits write operation to finish.
4294
+ * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
4295
+ * @param {Path} path being acted upon
4296
+ * @param {Number} threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
4297
+ * @param {EventName} event
4298
+ * @param {Function} awfEmit Callback to be called when ready for event to be emitted.
4299
+ */
4300
+ _awaitWriteFinish(path, threshold, event, awfEmit) {
4301
+ let timeoutHandler;
4302
+
4303
+ let fullPath = path;
4304
+ if (this.options.cwd && !sysPath.isAbsolute(path)) {
4305
+ fullPath = sysPath.join(this.options.cwd, path);
4306
+ }
4307
+
4308
+ const now = new Date();
4309
+
4310
+ const awaitWriteFinish = (prevStat) => {
4311
+ fs.stat(fullPath, (err, curStat) => {
4312
+ if (err || !this._pendingWrites.has(path)) {
4313
+ if (err && err.code !== 'ENOENT') awfEmit(err);
4314
+ return;
4315
+ }
4316
+
4317
+ const now = Number(new Date());
4318
+
4319
+ if (prevStat && curStat.size !== prevStat.size) {
4320
+ this._pendingWrites.get(path).lastChange = now;
4321
+ }
4322
+ const pw = this._pendingWrites.get(path);
4323
+ const df = now - pw.lastChange;
4324
+
4325
+ if (df >= threshold) {
4326
+ this._pendingWrites.delete(path);
4327
+ awfEmit(undefined, curStat);
4328
+ } else {
4329
+ timeoutHandler = setTimeout(
4330
+ awaitWriteFinish,
4331
+ this.options.awaitWriteFinish.pollInterval,
4332
+ curStat
4333
+ );
4334
+ }
4335
+ });
4336
+ };
4337
+
4338
+ if (!this._pendingWrites.has(path)) {
4339
+ this._pendingWrites.set(path, {
4340
+ lastChange: now,
4341
+ cancelWait: () => {
4342
+ this._pendingWrites.delete(path);
4343
+ clearTimeout(timeoutHandler);
4344
+ return event;
4345
+ }
4346
+ });
4347
+ timeoutHandler = setTimeout(
4348
+ awaitWriteFinish,
4349
+ this.options.awaitWriteFinish.pollInterval
4350
+ );
4351
+ }
4352
+ }
4353
+
4354
+ _getGlobIgnored() {
4355
+ return [...this._ignoredPaths.values()];
4356
+ }
4357
+
4358
+ /**
4359
+ * Determines whether user has asked to ignore this path.
4360
+ * @param {Path} path filepath or dir
4361
+ * @param {fs.Stats=} stats result of fs.stat
4362
+ * @returns {Boolean}
4363
+ */
4364
+ _isIgnored(path, stats) {
4365
+ if (this.options.atomic && DOT_RE.test(path)) return true;
4366
+ if (!this._userIgnored) {
4367
+ const {cwd} = this.options;
4368
+ const ign = this.options.ignored;
4369
+
4370
+ const ignored = ign && ign.map(normalizeIgnored(cwd));
4371
+ const paths = arrify(ignored)
4372
+ .filter((path) => typeof path === STRING_TYPE && !isGlob(path))
4373
+ .map((path) => path + SLASH_GLOBSTAR);
4374
+ const list = this._getGlobIgnored().map(normalizeIgnored(cwd)).concat(ignored, paths);
4375
+ this._userIgnored = anymatch(list, undefined, ANYMATCH_OPTS);
4376
+ }
4377
+
4378
+ return this._userIgnored([path, stats]);
4379
+ }
4380
+
4381
+ _isntIgnored(path, stat) {
4382
+ return !this._isIgnored(path, stat);
4383
+ }
4384
+
4385
+ /**
4386
+ * Provides a set of common helpers and properties relating to symlink and glob handling.
4387
+ * @param {Path} path file, directory, or glob pattern being watched
4388
+ * @param {Number=} depth at any depth > 0, this isn't a glob
4389
+ * @returns {WatchHelper} object containing helpers for this path
4390
+ */
4391
+ _getWatchHelpers(path, depth) {
4392
+ const watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : globParent(path);
4393
+ const follow = this.options.followSymlinks;
4394
+
4395
+ return new WatchHelper(path, watchPath, follow, this);
4396
+ }
4397
+
4398
+ // Directory helpers
4399
+ // -----------------
4400
+
4401
+ /**
4402
+ * Provides directory tracking objects
4403
+ * @param {String} directory path of the directory
4404
+ * @returns {DirEntry} the directory's tracking object
4405
+ */
4406
+ _getWatchedDir(directory) {
4407
+ if (!this._boundRemove) this._boundRemove = this._remove.bind(this);
4408
+ const dir = sysPath.resolve(directory);
4409
+ if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
4410
+ return this._watched.get(dir);
4411
+ }
4412
+
4413
+ // File helpers
4414
+ // ------------
4415
+
4416
+ /**
4417
+ * Check for read permissions.
4418
+ * Based on this answer on SO: https://stackoverflow.com/a/11781404/1358405
4419
+ * @param {fs.Stats} stats - object, result of fs_stat
4420
+ * @returns {Boolean} indicates whether the file can be read
4421
+ */
4422
+ _hasReadPermissions(stats) {
4423
+ if (this.options.ignorePermissionErrors) return true;
4424
+
4425
+ // stats.mode may be bigint
4426
+ const md = stats && Number.parseInt(stats.mode, 10);
4427
+ const st = md & 0o777;
4428
+ const it = Number.parseInt(st.toString(8)[0], 10);
4429
+ return Boolean(4 & it);
4430
+ }
4431
+
4432
+ /**
4433
+ * Handles emitting unlink events for
4434
+ * files and directories, and via recursion, for
4435
+ * files and directories within directories that are unlinked
4436
+ * @param {String} directory within which the following item is located
4437
+ * @param {String} item base path of item/directory
4438
+ * @returns {void}
4439
+ */
4440
+ _remove(directory, item, isDirectory) {
4441
+ // if what is being deleted is a directory, get that directory's paths
4442
+ // for recursive deleting and cleaning of watched object
4443
+ // if it is not a directory, nestedDirectoryChildren will be empty array
4444
+ const path = sysPath.join(directory, item);
4445
+ const fullPath = sysPath.resolve(path);
4446
+ isDirectory = isDirectory != null
4447
+ ? isDirectory
4448
+ : this._watched.has(path) || this._watched.has(fullPath);
4449
+
4450
+ // prevent duplicate handling in case of arriving here nearly simultaneously
4451
+ // via multiple paths (such as _handleFile and _handleDir)
4452
+ if (!this._throttle('remove', path, 100)) return;
4453
+
4454
+ // if the only watched file is removed, watch for its return
4455
+ if (!isDirectory && !this.options.useFsEvents && this._watched.size === 1) {
4456
+ this.add(directory, item, true);
4457
+ }
4458
+
4459
+ // This will create a new entry in the watched object in either case
4460
+ // so we got to do the directory check beforehand
4461
+ const wp = this._getWatchedDir(path);
4462
+ const nestedDirectoryChildren = wp.getChildren();
4463
+
4464
+ // Recursively remove children directories / files.
4465
+ nestedDirectoryChildren.forEach(nested => this._remove(path, nested));
4466
+
4467
+ // Check if item was on the watched list and remove it
4468
+ const parent = this._getWatchedDir(directory);
4469
+ const wasTracked = parent.has(item);
4470
+ parent.remove(item);
4471
+
4472
+ // Fixes issue #1042 -> Relative paths were detected and added as symlinks
4473
+ // (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
4474
+ // but never removed from the map in case the path was deleted.
4475
+ // This leads to an incorrect state if the path was recreated:
4476
+ // https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
4477
+ if (this._symlinkPaths.has(fullPath)) {
4478
+ this._symlinkPaths.delete(fullPath);
4479
+ }
4480
+
4481
+ // If we wait for this file to be fully written, cancel the wait.
4482
+ let relPath = path;
4483
+ if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
4484
+ if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
4485
+ const event = this._pendingWrites.get(relPath).cancelWait();
4486
+ if (event === EV_ADD) return;
4487
+ }
4488
+
4489
+ // The Entry will either be a directory that just got removed
4490
+ // or a bogus entry to a file, in either case we have to remove it
4491
+ this._watched.delete(path);
4492
+ this._watched.delete(fullPath);
4493
+ const eventName = isDirectory ? EV_UNLINK_DIR : EV_UNLINK;
4494
+ if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
4495
+
4496
+ // Avoid conflicts if we later create another file with the same name
4497
+ if (!this.options.useFsEvents) {
4498
+ this._closePath(path);
4499
+ }
4500
+ }
4501
+
4502
+ /**
4503
+ * Closes all watchers for a path
4504
+ * @param {Path} path
4505
+ */
4506
+ _closePath(path) {
4507
+ this._closeFile(path);
4508
+ const dir = sysPath.dirname(path);
4509
+ this._getWatchedDir(dir).remove(sysPath.basename(path));
4510
+ }
4511
+
4512
+ /**
4513
+ * Closes only file-specific watchers
4514
+ * @param {Path} path
4515
+ */
4516
+ _closeFile(path) {
4517
+ const closers = this._closers.get(path);
4518
+ if (!closers) return;
4519
+ closers.forEach(closer => closer());
4520
+ this._closers.delete(path);
4521
+ }
4522
+
4523
+ /**
4524
+ *
4525
+ * @param {Path} path
4526
+ * @param {Function} closer
4527
+ */
4528
+ _addPathCloser(path, closer) {
4529
+ if (!closer) return;
4530
+ let list = this._closers.get(path);
4531
+ if (!list) {
4532
+ list = [];
4533
+ this._closers.set(path, list);
4534
+ }
4535
+ list.push(closer);
4536
+ }
4537
+
4538
+ _readdirp(root, opts) {
4539
+ if (this.closed) return;
4540
+ const options = {type: EV_ALL, alwaysStat: true, lstat: true, ...opts};
4541
+ let stream = readdirp(root, options);
4542
+ this._streams.add(stream);
4543
+ stream.once(STR_CLOSE, () => {
4544
+ stream = undefined;
4545
+ });
4546
+ stream.once(STR_END, () => {
4547
+ if (stream) {
4548
+ this._streams.delete(stream);
4549
+ stream = undefined;
4550
+ }
4551
+ });
4552
+ return stream;
4553
+ }
4554
+
4555
+ }
4556
+
4557
+ // Export FSWatcher class
4558
+ chokidar.FSWatcher = FSWatcher;
4559
+
4560
+ /**
4561
+ * Instantiates watcher with paths to be tracked.
4562
+ * @param {String|Array<String>} paths file/directory paths and/or globs
4563
+ * @param {Object=} options chokidar opts
4564
+ * @returns an instance of FSWatcher for chaining.
4565
+ */
4566
+ const watch = (paths, options) => {
4567
+ const watcher = new FSWatcher(options);
4568
+ watcher.add(paths);
4569
+ return watcher;
4570
+ };
4571
+
4572
+ chokidar.watch = watch;
4573
+
4574
+ class FileWatcher {
4575
+ constructor(task, chokidarOptions) {
4576
+ this.transformWatchers = new Map();
4577
+ this.chokidarOptions = chokidarOptions;
4578
+ this.task = task;
4579
+ this.watcher = this.createWatcher(null);
4580
+ }
4581
+ close() {
4582
+ this.watcher.close();
4583
+ for (const watcher of this.transformWatchers.values()) {
4584
+ watcher.close();
4585
+ }
4586
+ }
4587
+ unwatch(id) {
4588
+ this.watcher.unwatch(id);
4589
+ const transformWatcher = this.transformWatchers.get(id);
4590
+ if (transformWatcher) {
4591
+ this.transformWatchers.delete(id);
4592
+ transformWatcher.close();
4593
+ }
4594
+ }
4595
+ watch(id, isTransformDependency) {
4596
+ if (isTransformDependency) {
4597
+ const watcher = this.transformWatchers.get(id) ?? this.createWatcher(id);
4598
+ watcher.add(id);
4599
+ this.transformWatchers.set(id, watcher);
4600
+ }
4601
+ else {
4602
+ this.watcher.add(id);
4603
+ }
4604
+ }
4605
+ createWatcher(transformWatcherId) {
4606
+ const task = this.task;
4607
+ const isLinux = platform() === 'linux';
4608
+ const isTransformDependency = transformWatcherId !== null;
4609
+ const handleChange = (id, event) => {
4610
+ const changedId = transformWatcherId || id;
4611
+ if (isLinux) {
4612
+ // unwatching and watching fixes an issue with chokidar where on certain systems,
4613
+ // a file that was unlinked and immediately recreated would create a change event
4614
+ // but then no longer any further events
4615
+ watcher.unwatch(changedId);
4616
+ watcher.add(changedId);
4617
+ }
4618
+ task.invalidate(changedId, { event, isTransformDependency });
4619
+ };
4620
+ const watcher = chokidar
4621
+ .watch([], this.chokidarOptions)
4622
+ .on('add', id => handleChange(id, 'create'))
4623
+ .on('change', id => handleChange(id, 'update'))
4624
+ .on('unlink', id => handleChange(id, 'delete'));
4625
+ return watcher;
4626
+ }
4627
+ }
4628
+
4629
+ const eventsRewrites = {
4630
+ create: {
4631
+ create: 'buggy',
4632
+ delete: null,
4633
+ update: 'create'
4634
+ },
4635
+ delete: {
4636
+ create: 'update',
4637
+ delete: 'buggy',
4638
+ update: 'buggy'
4639
+ },
4640
+ update: {
4641
+ create: 'buggy',
4642
+ delete: 'delete',
4643
+ update: 'update'
4644
+ }
4645
+ };
4646
+ class Watcher {
4647
+ constructor(optionsList, emitter) {
4648
+ this.buildDelay = 0;
4649
+ this.buildTimeout = null;
4650
+ this.closed = false;
4651
+ this.invalidatedIds = new Map();
4652
+ this.rerun = false;
4653
+ this.running = true;
4654
+ this.emitter = emitter;
4655
+ emitter.close = this.close.bind(this);
4656
+ this.tasks = optionsList.map(options => new Task(this, options));
4657
+ for (const { watch } of optionsList) {
4658
+ if (watch && typeof watch.buildDelay === 'number') {
4659
+ this.buildDelay = Math.max(this.buildDelay, watch.buildDelay);
4660
+ }
4661
+ }
4662
+ process$1.nextTick(() => this.run());
4663
+ }
4664
+ async close() {
4665
+ if (this.closed)
4666
+ return;
4667
+ this.closed = true;
4668
+ if (this.buildTimeout)
4669
+ clearTimeout(this.buildTimeout);
4670
+ for (const task of this.tasks) {
4671
+ task.close();
4672
+ }
4673
+ await this.emitter.emit('close');
4674
+ this.emitter.removeAllListeners();
4675
+ }
4676
+ invalidate(file) {
4677
+ if (file) {
4678
+ const previousEvent = this.invalidatedIds.get(file.id);
4679
+ const event = previousEvent ? eventsRewrites[previousEvent][file.event] : file.event;
4680
+ if (event === 'buggy') {
4681
+ //TODO: throws or warn? Currently just ignore, uses new event
4682
+ this.invalidatedIds.set(file.id, file.event);
4683
+ }
4684
+ else if (event === null) {
4685
+ this.invalidatedIds.delete(file.id);
4686
+ }
4687
+ else {
4688
+ this.invalidatedIds.set(file.id, event);
4689
+ }
4690
+ }
4691
+ if (this.running) {
4692
+ this.rerun = true;
4693
+ return;
4694
+ }
4695
+ if (this.buildTimeout)
4696
+ clearTimeout(this.buildTimeout);
4697
+ this.buildTimeout = setTimeout(async () => {
4698
+ this.buildTimeout = null;
4699
+ try {
4700
+ await Promise.all([...this.invalidatedIds].map(([id, event]) => this.emitter.emit('change', id, { event })));
4701
+ this.invalidatedIds.clear();
4702
+ await this.emitter.emit('restart');
4703
+ this.emitter.removeListenersForCurrentRun();
4704
+ this.run();
4705
+ }
4706
+ catch (error) {
4707
+ this.invalidatedIds.clear();
4708
+ await this.emitter.emit('event', {
4709
+ code: 'ERROR',
4710
+ error,
4711
+ result: null
4712
+ });
4713
+ await this.emitter.emit('event', {
4714
+ code: 'END'
4715
+ });
4716
+ }
4717
+ }, this.buildDelay);
4718
+ }
4719
+ async run() {
4720
+ this.running = true;
4721
+ await this.emitter.emit('event', {
4722
+ code: 'START'
4723
+ });
4724
+ for (const task of this.tasks) {
4725
+ await task.run();
4726
+ }
4727
+ this.running = false;
4728
+ await this.emitter.emit('event', {
4729
+ code: 'END'
4730
+ });
4731
+ if (this.rerun) {
4732
+ this.rerun = false;
4733
+ this.invalidate();
4734
+ }
4735
+ }
4736
+ }
4737
+ class Task {
4738
+ constructor(watcher, options) {
4739
+ this.cache = { modules: [] };
4740
+ this.watchFiles = [];
4741
+ this.closed = false;
4742
+ this.invalidated = true;
4743
+ this.watched = new Set();
4744
+ this.watcher = watcher;
4745
+ this.options = options;
4746
+ this.skipWrite = Boolean(options.watch && options.watch.skipWrite);
4747
+ this.outputs = this.options.output;
4748
+ this.outputFiles = this.outputs.map(output => {
4749
+ if (output.file || output.dir)
4750
+ return resolve(output.file || output.dir);
4751
+ return undefined;
4752
+ });
4753
+ const watchOptions = this.options.watch || {};
4754
+ this.filter = createFilter(watchOptions.include, watchOptions.exclude);
4755
+ this.fileWatcher = new FileWatcher(this, {
4756
+ ...watchOptions.chokidar,
4757
+ disableGlobbing: true,
4758
+ ignoreInitial: true
4759
+ });
4760
+ }
4761
+ close() {
4762
+ this.closed = true;
4763
+ this.fileWatcher.close();
4764
+ }
4765
+ invalidate(id, details) {
4766
+ this.invalidated = true;
4767
+ if (details.isTransformDependency) {
4768
+ for (const module of this.cache.modules) {
4769
+ if (!module.transformDependencies.includes(id))
4770
+ continue;
4771
+ // effective invalidation
4772
+ module.originalCode = null;
4773
+ }
4774
+ }
4775
+ this.watcher.invalidate({ event: details.event, id });
4776
+ }
4777
+ async run() {
4778
+ if (!this.invalidated)
4779
+ return;
4780
+ this.invalidated = false;
4781
+ const options = {
4782
+ ...this.options,
4783
+ cache: this.cache
4784
+ };
4785
+ const start = Date.now();
4786
+ await this.watcher.emitter.emit('event', {
4787
+ code: 'BUNDLE_START',
4788
+ input: this.options.input,
4789
+ output: this.outputFiles
4790
+ });
4791
+ let result = null;
4792
+ try {
4793
+ result = await rollupInternal(options, this.watcher.emitter);
4794
+ if (this.closed) {
4795
+ return;
4796
+ }
4797
+ this.updateWatchedFiles(result);
4798
+ this.skipWrite || (await Promise.all(this.outputs.map(output => result.write(output))));
4799
+ await this.watcher.emitter.emit('event', {
4800
+ code: 'BUNDLE_END',
4801
+ duration: Date.now() - start,
4802
+ input: this.options.input,
4803
+ output: this.outputFiles,
4804
+ result
4805
+ });
4806
+ }
4807
+ catch (error) {
4808
+ if (!this.closed) {
4809
+ if (Array.isArray(error.watchFiles)) {
4810
+ for (const id of error.watchFiles) {
4811
+ this.watchFile(id);
4812
+ }
4813
+ }
4814
+ if (error.id) {
4815
+ this.cache.modules = this.cache.modules.filter(module => module.id !== error.id);
4816
+ }
4817
+ }
4818
+ await this.watcher.emitter.emit('event', {
4819
+ code: 'ERROR',
4820
+ error,
4821
+ result
4822
+ });
4823
+ }
4824
+ }
4825
+ updateWatchedFiles(result) {
4826
+ const previouslyWatched = this.watched;
4827
+ this.watched = new Set();
4828
+ this.watchFiles = result.watchFiles;
4829
+ this.cache = result.cache;
4830
+ for (const id of this.watchFiles) {
4831
+ this.watchFile(id);
4832
+ }
4833
+ for (const module of this.cache.modules) {
4834
+ for (const depId of module.transformDependencies) {
4835
+ this.watchFile(depId, true);
4836
+ }
4837
+ }
4838
+ for (const id of previouslyWatched) {
4839
+ if (!this.watched.has(id)) {
4840
+ this.fileWatcher.unwatch(id);
4841
+ }
4842
+ }
4843
+ }
4844
+ watchFile(id, isTransformDependency = false) {
4845
+ if (!this.filter(id))
4846
+ return;
4847
+ this.watched.add(id);
4848
+ if (this.outputFiles.includes(id)) {
4849
+ throw new Error('Cannot import the generated bundle');
4850
+ }
4851
+ // this is necessary to ensure that any 'renamed' files
4852
+ // continue to be watched following an error
4853
+ this.fileWatcher.watch(id, isTransformDependency);
4854
+ }
4855
+ }
4856
+
4857
+ export { Task, Watcher };