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