@rsbuild/core 2.1.7 → 2.1.8
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.
- package/compiled/cors/index.d.ts +1 -1
- package/compiled/html-rspack-plugin/index.d.ts +1 -1
- package/dist/{711.js → 626.js} +92 -69
- package/dist/build.d.ts +4 -0
- package/dist/chokidar.js +1 -1046
- package/{dist-types → dist}/cli/commands.d.ts +2 -2
- package/{dist-types → dist}/cli/init.d.ts +2 -2
- package/dist/client/hmr.js +1 -1
- package/dist/client/overlay.js +1 -1
- package/{dist-types → dist}/configChain.d.ts +2 -2
- package/dist/connect-next.js +1 -876
- package/dist/cors.js +1 -1
- package/{dist-types → dist}/createCompiler.d.ts +2 -2
- package/{dist-types → dist}/createContext.d.ts +3 -3
- package/{dist-types → dist}/createRsbuild.d.ts +1 -1
- package/{dist-types → dist}/defaultConfig.d.ts +1 -1
- package/{dist-types → dist}/helpers/compiler.d.ts +1 -1
- package/{dist-types → dist}/helpers/css.d.ts +1 -1
- package/{dist-types → dist}/helpers/format.d.ts +1 -1
- package/{dist-types → dist}/helpers/fs.d.ts +2 -2
- package/{dist-types → dist}/helpers/index.d.ts +4 -4
- package/{dist-types → dist}/helpers/overlayConfig.d.ts +1 -1
- package/{dist-types → dist}/helpers/path.d.ts +1 -1
- package/{dist-types → dist}/helpers/restartManager.d.ts +2 -2
- package/{dist-types → dist}/helpers/stats.d.ts +2 -2
- package/{dist-types → dist}/helpers/url.d.ts +2 -2
- package/{dist-types → dist}/helpers/vendors.d.ts +1 -1
- package/{dist-types → dist}/hooks.d.ts +1 -1
- package/dist/http-proxy-middleware.js +5 -3010
- package/{dist-types → dist}/index.d.ts +14 -14
- package/dist/index.js +1 -1
- package/{dist-types → dist}/initConfigs.d.ts +1 -1
- package/{dist-types → dist}/initPlugins.d.ts +2 -2
- package/{dist-types → dist}/inspectConfig.d.ts +2 -2
- package/dist/launch-editor-middleware.js +1 -544
- package/{dist-types → dist}/loadConfig.d.ts +6 -6
- package/{dist-types → dist}/loader/cssUrlLoader.d.ts +1 -1
- package/{dist-types → dist}/loader/ignoreCssLoader.d.ts +1 -1
- package/{dist-types → dist}/loader/transformLoader.d.ts +1 -1
- package/{dist-types → dist}/loader/transformRawLoader.d.ts +1 -1
- package/{dist-types → dist}/logger.d.ts +1 -1
- package/dist/manifest-plugin.js +1 -692
- package/dist/memfs.js +1 -5695
- package/{dist-types → dist}/mergeConfig.d.ts +1 -1
- package/dist/open.js +2 -439
- package/{dist-types → dist}/pluginHelper.d.ts +1 -1
- package/{dist-types → dist}/pluginManager.d.ts +2 -2
- package/{dist-types → dist}/plugins/appIcon.d.ts +1 -1
- package/{dist-types → dist}/plugins/asset.d.ts +1 -1
- package/{dist-types → dist}/plugins/basic.d.ts +1 -1
- package/dist/plugins/cache.d.ts +2 -0
- package/{dist-types → dist}/plugins/cleanOutput.d.ts +1 -1
- package/{dist-types → dist}/plugins/css.d.ts +1 -1
- package/{dist-types → dist}/plugins/define.d.ts +1 -1
- package/dist/plugins/entry.d.ts +2 -0
- package/{dist-types → dist}/plugins/externals.d.ts +2 -2
- package/{dist-types → dist}/plugins/fileSize.d.ts +1 -1
- package/{dist-types → dist}/plugins/html.d.ts +1 -1
- package/{dist-types → dist}/plugins/inlineChunk.d.ts +1 -1
- package/{dist-types → dist}/plugins/lazyCompilation.d.ts +1 -1
- package/{dist-types → dist}/plugins/manifest.d.ts +1 -1
- package/{dist-types → dist}/plugins/minimize.d.ts +2 -2
- package/{dist-types → dist}/plugins/moduleFederation.d.ts +1 -1
- package/{dist-types → dist}/plugins/nodeAddons.d.ts +1 -1
- package/dist/plugins/nonce.d.ts +2 -0
- package/{dist-types → dist}/plugins/output.d.ts +1 -1
- package/{dist-types → dist}/plugins/progress.d.ts +1 -1
- package/{dist-types → dist}/plugins/resolve.d.ts +1 -1
- package/{dist-types → dist}/plugins/resourceHints.d.ts +1 -1
- package/{dist-types → dist}/plugins/rsdoctor.d.ts +1 -1
- package/{dist-types → dist}/plugins/rspackProfile.d.ts +1 -1
- package/{dist-types → dist}/plugins/server.d.ts +1 -1
- package/{dist-types → dist}/plugins/sourceMap.d.ts +1 -1
- package/{dist-types → dist}/plugins/splitChunks.d.ts +1 -1
- package/dist/plugins/sri.d.ts +2 -0
- package/{dist-types → dist}/plugins/swc.d.ts +1 -1
- package/{dist-types → dist}/plugins/target.d.ts +1 -1
- package/dist/plugins/wasm.d.ts +2 -0
- package/{dist-types → dist}/plugins/worker.d.ts +1 -1
- package/dist/range-parser.js +1 -1
- package/dist/restart.d.ts +15 -0
- package/{dist-types → dist}/rspack-plugins/RsbuildHtmlPlugin.d.ts +1 -1
- package/{dist-types → dist}/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +1 -1
- package/{dist-types → dist}/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +1 -1
- package/{dist-types → dist}/rspack-plugins/resource-hints/extractChunks.d.ts +1 -1
- package/{dist-types → dist}/rspackConfig.d.ts +1 -1
- package/{dist-types → dist}/server/assets-middleware/getFileFromUrl.d.ts +1 -1
- package/{dist-types → dist}/server/assets-middleware/index.d.ts +2 -2
- package/{dist-types → dist}/server/assets-middleware/middleware.d.ts +1 -1
- package/{dist-types → dist}/server/assets-middleware/setupOutputFileSystem.d.ts +1 -1
- package/{dist-types → dist}/server/assets-middleware/setupWriteToDisk.d.ts +2 -2
- package/{dist-types → dist}/server/browserLogs.d.ts +1 -1
- package/{dist-types → dist}/server/buildManager.d.ts +3 -3
- package/{dist-types → dist}/server/cliShortcuts.d.ts +2 -2
- package/{dist-types → dist}/server/devMiddlewares.d.ts +4 -4
- package/{dist-types → dist}/server/devServer.d.ts +4 -4
- package/{dist-types → dist}/server/environment.d.ts +1 -1
- package/{dist-types → dist}/server/gzipMiddleware.d.ts +1 -1
- package/{dist-types → dist}/server/helper.d.ts +4 -4
- package/{dist-types → dist}/server/historyApiFallback.d.ts +2 -2
- package/{dist-types → dist}/server/httpServer.d.ts +1 -1
- package/{dist-types → dist}/server/middlewares.d.ts +2 -2
- package/{dist-types → dist}/server/open.d.ts +2 -2
- package/{dist-types → dist}/server/previewServer.d.ts +2 -2
- package/{dist-types → dist}/server/proxy.d.ts +3 -3
- package/{dist-types → dist}/server/runner/basic.d.ts +1 -1
- package/{dist-types → dist}/server/runner/cjs.d.ts +2 -2
- package/{dist-types → dist}/server/runner/esm.d.ts +2 -2
- package/{dist-types → dist}/server/runner/index.d.ts +1 -1
- package/{dist-types → dist}/server/serverSetup.d.ts +1 -1
- package/{dist-types → dist}/server/socketServer.d.ts +1 -1
- package/{dist-types → dist}/server/watchFiles.d.ts +4 -3
- package/dist/sirv.js +1 -1
- package/dist/tinyglobby.js +1 -1670
- package/{dist-types → dist}/types/config.d.ts +24 -15
- package/{dist-types → dist}/types/context.d.ts +8 -8
- package/{dist-types → dist}/types/hooks.d.ts +29 -13
- package/dist/types/index.d.ts +8 -0
- package/{dist-types → dist}/types/plugin.d.ts +7 -7
- package/{dist-types → dist}/types/rsbuild.d.ts +11 -11
- package/{dist-types → dist}/types/rspack.d.ts +2 -2
- package/{dist-types → dist}/types/thirdParty.d.ts +5 -5
- package/dist/ws.js +2 -1524
- package/package.json +7 -8
- package/dist-types/build.d.ts +0 -4
- package/dist-types/package.json +0 -1
- package/dist-types/plugins/cache.d.ts +0 -2
- package/dist-types/plugins/entry.d.ts +0 -2
- package/dist-types/plugins/nonce.d.ts +0 -2
- package/dist-types/plugins/sri.d.ts +0 -2
- package/dist-types/plugins/wasm.d.ts +0 -2
- package/dist-types/restart.d.ts +0 -14
- package/dist-types/types/index.d.ts +0 -8
- /package/dist/{711.js.LICENSE.txt → 626.js.LICENSE.txt} +0 -0
- /package/{dist-types → dist}/cli/index.d.ts +0 -0
- /package/dist/client/{307.js → 307~0.js} +0 -0
- /package/{dist-types → dist}/constants.d.ts +0 -0
- /package/{dist-types → dist}/helpers/exitHook.d.ts +0 -0
- /package/{dist-types → dist}/helpers/packageJson.d.ts +0 -0
- /package/{dist-types → dist}/helpers/version.d.ts +0 -0
- /package/{dist-types → dist}/loadEnv.d.ts +0 -0
- /package/{dist-types → dist}/loader/workerLoader.d.ts +0 -0
- /package/dist/{1~rslib-runtime.js → rslib-runtime.js} +0 -0
- /package/{dist-types → dist}/rspack-plugins/resource-hints/getResourceType.d.ts +0 -0
- /package/{dist-types → dist}/server/ansiHTML.d.ts +0 -0
- /package/{dist-types → dist}/server/assets-middleware/parseTokenList.d.ts +0 -0
- /package/{dist-types → dist}/server/compileState.d.ts +0 -0
- /package/{dist-types → dist}/server/gracefulShutdown.d.ts +0 -0
- /package/{dist-types → dist}/server/hmrFallback.d.ts +0 -0
- /package/{dist-types → dist}/server/overlay.d.ts +0 -0
- /package/{dist-types → dist}/server/publicPathnames.d.ts +0 -0
- /package/{dist-types → dist}/server/runner/asModule.d.ts +0 -0
- /package/{dist-types → dist}/server/runner/type.d.ts +0 -0
- /package/{dist-types → dist}/types/utils.d.ts +0 -0
package/dist/chokidar.js
CHANGED
|
@@ -1,1047 +1,2 @@
|
|
|
1
1
|
/*! LICENSE: chokidar.js.LICENSE.txt */
|
|
2
|
-
import { EventEmitter } from "node:events";
|
|
3
|
-
import { stat as external_node_fs_stat, unwatchFile, watch, watchFile } from "node:fs";
|
|
4
|
-
import { lstat, open as promises_open, readdir, realpath as promises_realpath, stat as promises_stat } from "node:fs/promises";
|
|
5
|
-
import { join, relative as external_node_path_relative, resolve as external_node_path_resolve, sep } from "node:path";
|
|
6
|
-
import { Readable } from "node:stream";
|
|
7
|
-
import { type as external_node_os_type } from "node:os";
|
|
8
|
-
import * as __rspack_external_node_path_806ed179 from "node:path";
|
|
9
|
-
let EntryTypes_FILE_TYPE = 'files', EntryTypes_DIR_TYPE = 'directories', EntryTypes_FILE_DIR_TYPE = 'files_directories', defaultOptions = {
|
|
10
|
-
root: '.',
|
|
11
|
-
fileFilter: (_entryInfo)=>!0,
|
|
12
|
-
directoryFilter: (_entryInfo)=>!0,
|
|
13
|
-
type: EntryTypes_FILE_TYPE,
|
|
14
|
-
lstat: !1,
|
|
15
|
-
depth: 2147483648,
|
|
16
|
-
alwaysStat: !1,
|
|
17
|
-
highWaterMark: 4096
|
|
18
|
-
};
|
|
19
|
-
Object.freeze(defaultOptions);
|
|
20
|
-
let RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR', NORMAL_FLOW_ERRORS = new Set([
|
|
21
|
-
'ENOENT',
|
|
22
|
-
'EPERM',
|
|
23
|
-
'EACCES',
|
|
24
|
-
'ELOOP',
|
|
25
|
-
RECURSIVE_ERROR_CODE
|
|
26
|
-
]), ALL_TYPES = [
|
|
27
|
-
EntryTypes_DIR_TYPE,
|
|
28
|
-
'all',
|
|
29
|
-
EntryTypes_FILE_DIR_TYPE,
|
|
30
|
-
EntryTypes_FILE_TYPE
|
|
31
|
-
], DIR_TYPES = new Set([
|
|
32
|
-
EntryTypes_DIR_TYPE,
|
|
33
|
-
'all',
|
|
34
|
-
EntryTypes_FILE_DIR_TYPE
|
|
35
|
-
]), FILE_TYPES = new Set([
|
|
36
|
-
'all',
|
|
37
|
-
EntryTypes_FILE_DIR_TYPE,
|
|
38
|
-
EntryTypes_FILE_TYPE
|
|
39
|
-
]), wantBigintFsStats = 'win32' === process.platform, emptyFn = (_entryInfo)=>!0, normalizeFilter = (filter)=>{
|
|
40
|
-
if (void 0 === filter) return emptyFn;
|
|
41
|
-
if ('function' == typeof filter) return filter;
|
|
42
|
-
if ('string' == typeof filter) {
|
|
43
|
-
let fl = filter.trim();
|
|
44
|
-
return (entry)=>entry.basename === fl;
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(filter)) {
|
|
47
|
-
let trItems = filter.map((item)=>item.trim());
|
|
48
|
-
return (entry)=>trItems.some((f)=>entry.basename === f);
|
|
49
|
-
}
|
|
50
|
-
return emptyFn;
|
|
51
|
-
};
|
|
52
|
-
class ReaddirpStream extends Readable {
|
|
53
|
-
parents;
|
|
54
|
-
reading;
|
|
55
|
-
parent;
|
|
56
|
-
_stat;
|
|
57
|
-
_maxDepth;
|
|
58
|
-
_wantsDir;
|
|
59
|
-
_wantsFile;
|
|
60
|
-
_wantsEverything;
|
|
61
|
-
_root;
|
|
62
|
-
_isDirent;
|
|
63
|
-
_statsProp;
|
|
64
|
-
_rdOptions;
|
|
65
|
-
_fileFilter;
|
|
66
|
-
_directoryFilter;
|
|
67
|
-
constructor(options = {}){
|
|
68
|
-
super({
|
|
69
|
-
objectMode: !0,
|
|
70
|
-
autoDestroy: !0,
|
|
71
|
-
highWaterMark: options.highWaterMark
|
|
72
|
-
});
|
|
73
|
-
let opts = {
|
|
74
|
-
...defaultOptions,
|
|
75
|
-
...options
|
|
76
|
-
}, { root, type } = opts;
|
|
77
|
-
this._fileFilter = normalizeFilter(opts.fileFilter), this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
78
|
-
let statMethod = opts.lstat ? lstat : promises_stat;
|
|
79
|
-
wantBigintFsStats ? this._stat = (path)=>statMethod(path, {
|
|
80
|
-
bigint: !0
|
|
81
|
-
}) : this._stat = statMethod, this._maxDepth = null != opts.depth && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth, this._wantsDir = !!type && DIR_TYPES.has(type), this._wantsFile = !!type && FILE_TYPES.has(type), this._wantsEverything = 'all' === type, this._root = external_node_path_resolve(root), this._isDirent = !opts.alwaysStat, this._statsProp = this._isDirent ? 'dirent' : 'stats', this._rdOptions = {
|
|
82
|
-
encoding: 'utf8',
|
|
83
|
-
withFileTypes: this._isDirent
|
|
84
|
-
}, this.parents = [
|
|
85
|
-
this._exploreDir(root, 1)
|
|
86
|
-
], this.reading = !1, this.parent = void 0;
|
|
87
|
-
}
|
|
88
|
-
async _read(batch) {
|
|
89
|
-
if (!this.reading) {
|
|
90
|
-
this.reading = !0;
|
|
91
|
-
try {
|
|
92
|
-
for(; !this.destroyed && batch > 0;){
|
|
93
|
-
let par = this.parent, fil = par && par.files;
|
|
94
|
-
if (fil && fil.length > 0) {
|
|
95
|
-
let { path, depth } = par, slice = fil.splice(0, batch).map((dirent)=>this._formatEntry(dirent, path));
|
|
96
|
-
for (let entry of (await Promise.all(slice))){
|
|
97
|
-
if (!entry) continue;
|
|
98
|
-
if (this.destroyed) return;
|
|
99
|
-
let entryType = await this._getEntryType(entry);
|
|
100
|
-
'directory' === entryType && this._directoryFilter(entry) ? (depth <= this._maxDepth && this.parents.push(this._exploreDir(entry.fullPath, depth + 1)), this._wantsDir && (this.push(entry), batch--)) : ('file' === entryType || this._includeAsFile(entry)) && this._fileFilter(entry) && this._wantsFile && (this.push(entry), batch--);
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
let parent = this.parents.pop();
|
|
104
|
-
if (!parent) {
|
|
105
|
-
this.push(null);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (this.parent = await parent, this.destroyed) return;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
} catch (error) {
|
|
112
|
-
this.destroy(error);
|
|
113
|
-
} finally{
|
|
114
|
-
this.reading = !1;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async _exploreDir(path, depth) {
|
|
119
|
-
let files;
|
|
120
|
-
try {
|
|
121
|
-
files = await readdir(path, this._rdOptions);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
this._onError(error);
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
files,
|
|
127
|
-
depth,
|
|
128
|
-
path
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
async _formatEntry(dirent, path) {
|
|
132
|
-
let entry, basename = this._isDirent ? dirent.name : dirent;
|
|
133
|
-
try {
|
|
134
|
-
let fullPath = external_node_path_resolve(join(path, basename));
|
|
135
|
-
(entry = {
|
|
136
|
-
path: external_node_path_relative(this._root, fullPath),
|
|
137
|
-
fullPath,
|
|
138
|
-
basename
|
|
139
|
-
})[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
140
|
-
} catch (err) {
|
|
141
|
-
this._onError(err);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
return entry;
|
|
145
|
-
}
|
|
146
|
-
_onError(err) {
|
|
147
|
-
NORMAL_FLOW_ERRORS.has(err.code) && !this.destroyed ? this.emit('warn', err) : this.destroy(err);
|
|
148
|
-
}
|
|
149
|
-
async _getEntryType(entry) {
|
|
150
|
-
if (!entry && this._statsProp in entry) return '';
|
|
151
|
-
let stats = entry[this._statsProp];
|
|
152
|
-
if (stats.isFile()) return 'file';
|
|
153
|
-
if (stats.isDirectory()) return 'directory';
|
|
154
|
-
if (stats && stats.isSymbolicLink()) {
|
|
155
|
-
let full = entry.fullPath;
|
|
156
|
-
try {
|
|
157
|
-
let entryRealPath = await promises_realpath(full), entryRealPathStats = await lstat(entryRealPath);
|
|
158
|
-
if (entryRealPathStats.isFile()) return 'file';
|
|
159
|
-
if (entryRealPathStats.isDirectory()) {
|
|
160
|
-
let len = entryRealPath.length;
|
|
161
|
-
if (full.startsWith(entryRealPath) && full.substr(len, 1) === sep) {
|
|
162
|
-
let recursiveError = Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
163
|
-
return recursiveError.code = RECURSIVE_ERROR_CODE, this._onError(recursiveError);
|
|
164
|
-
}
|
|
165
|
-
return 'directory';
|
|
166
|
-
}
|
|
167
|
-
} catch (error) {
|
|
168
|
-
return this._onError(error), '';
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
_includeAsFile(entry) {
|
|
173
|
-
let stats = entry && entry[this._statsProp];
|
|
174
|
-
return stats && this._wantsEverything && !stats.isDirectory();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function readdirp(root, options = {}) {
|
|
178
|
-
let type = options.entryType || options.type;
|
|
179
|
-
if ('both' === type && (type = EntryTypes_FILE_DIR_TYPE), type && (options.type = type), root) {
|
|
180
|
-
if ('string' != typeof root) throw TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
|
|
181
|
-
else if (type && !ALL_TYPES.includes(type)) throw Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
|
|
182
|
-
} else throw Error('readdirp: root argument is required. Usage: readdirp(root, options)');
|
|
183
|
-
return options.root = root, new ReaddirpStream(options);
|
|
184
|
-
}
|
|
185
|
-
let EMPTY_FN = ()=>{}, pl = process.platform, isWindows = 'win32' === pl, isMacos = 'darwin' === pl, isLinux = 'linux' === pl, isFreeBSD = 'freebsd' === pl, isIBMi = 'OS400' === external_node_os_type(), EVENTS_ALL = 'all', EVENTS_READY = 'ready', EVENTS_ADD = 'add', EVENTS_CHANGE = 'change', EVENTS_ADD_DIR = 'addDir', EVENTS_UNLINK = 'unlink', EVENTS_UNLINK_DIR = 'unlinkDir', EVENTS_RAW = 'raw', EVENTS_ERROR = 'error', statMethods = {
|
|
186
|
-
lstat: lstat,
|
|
187
|
-
stat: promises_stat
|
|
188
|
-
}, KEY_LISTENERS = 'listeners', KEY_ERR = 'errHandlers', KEY_RAW = 'rawEmitters', HANDLER_KEYS = [
|
|
189
|
-
KEY_LISTENERS,
|
|
190
|
-
KEY_ERR,
|
|
191
|
-
KEY_RAW
|
|
192
|
-
], binaryExtensions = new Set([
|
|
193
|
-
'3dm',
|
|
194
|
-
'3ds',
|
|
195
|
-
'3g2',
|
|
196
|
-
'3gp',
|
|
197
|
-
'7z',
|
|
198
|
-
'a',
|
|
199
|
-
'aac',
|
|
200
|
-
'adp',
|
|
201
|
-
'afdesign',
|
|
202
|
-
'afphoto',
|
|
203
|
-
'afpub',
|
|
204
|
-
'ai',
|
|
205
|
-
'aif',
|
|
206
|
-
'aiff',
|
|
207
|
-
'alz',
|
|
208
|
-
'ape',
|
|
209
|
-
'apk',
|
|
210
|
-
'appimage',
|
|
211
|
-
'ar',
|
|
212
|
-
'arj',
|
|
213
|
-
'asf',
|
|
214
|
-
'au',
|
|
215
|
-
'avi',
|
|
216
|
-
'bak',
|
|
217
|
-
'baml',
|
|
218
|
-
'bh',
|
|
219
|
-
'bin',
|
|
220
|
-
'bk',
|
|
221
|
-
'bmp',
|
|
222
|
-
'btif',
|
|
223
|
-
'bz2',
|
|
224
|
-
'bzip2',
|
|
225
|
-
'cab',
|
|
226
|
-
'caf',
|
|
227
|
-
'cgm',
|
|
228
|
-
'class',
|
|
229
|
-
'cmx',
|
|
230
|
-
'cpio',
|
|
231
|
-
'cr2',
|
|
232
|
-
'cur',
|
|
233
|
-
'dat',
|
|
234
|
-
'dcm',
|
|
235
|
-
'deb',
|
|
236
|
-
'dex',
|
|
237
|
-
'djvu',
|
|
238
|
-
'dll',
|
|
239
|
-
'dmg',
|
|
240
|
-
'dng',
|
|
241
|
-
'doc',
|
|
242
|
-
'docm',
|
|
243
|
-
'docx',
|
|
244
|
-
'dot',
|
|
245
|
-
'dotm',
|
|
246
|
-
'dra',
|
|
247
|
-
'DS_Store',
|
|
248
|
-
'dsk',
|
|
249
|
-
'dts',
|
|
250
|
-
'dtshd',
|
|
251
|
-
'dvb',
|
|
252
|
-
'dwg',
|
|
253
|
-
'dxf',
|
|
254
|
-
'ecelp4800',
|
|
255
|
-
'ecelp7470',
|
|
256
|
-
'ecelp9600',
|
|
257
|
-
'egg',
|
|
258
|
-
'eol',
|
|
259
|
-
'eot',
|
|
260
|
-
'epub',
|
|
261
|
-
'exe',
|
|
262
|
-
'f4v',
|
|
263
|
-
'fbs',
|
|
264
|
-
'fh',
|
|
265
|
-
'fla',
|
|
266
|
-
'flac',
|
|
267
|
-
'flatpak',
|
|
268
|
-
'fli',
|
|
269
|
-
'flv',
|
|
270
|
-
'fpx',
|
|
271
|
-
'fst',
|
|
272
|
-
'fvt',
|
|
273
|
-
'g3',
|
|
274
|
-
'gh',
|
|
275
|
-
'gif',
|
|
276
|
-
'graffle',
|
|
277
|
-
'gz',
|
|
278
|
-
'gzip',
|
|
279
|
-
'h261',
|
|
280
|
-
'h263',
|
|
281
|
-
'h264',
|
|
282
|
-
'icns',
|
|
283
|
-
'ico',
|
|
284
|
-
'ief',
|
|
285
|
-
'img',
|
|
286
|
-
'ipa',
|
|
287
|
-
'iso',
|
|
288
|
-
'jar',
|
|
289
|
-
'jpeg',
|
|
290
|
-
'jpg',
|
|
291
|
-
'jpgv',
|
|
292
|
-
'jpm',
|
|
293
|
-
'jxr',
|
|
294
|
-
'key',
|
|
295
|
-
'ktx',
|
|
296
|
-
'lha',
|
|
297
|
-
'lib',
|
|
298
|
-
'lvp',
|
|
299
|
-
'lz',
|
|
300
|
-
'lzh',
|
|
301
|
-
'lzma',
|
|
302
|
-
'lzo',
|
|
303
|
-
'm3u',
|
|
304
|
-
'm4a',
|
|
305
|
-
'm4v',
|
|
306
|
-
'mar',
|
|
307
|
-
'mdi',
|
|
308
|
-
'mht',
|
|
309
|
-
'mid',
|
|
310
|
-
'midi',
|
|
311
|
-
'mj2',
|
|
312
|
-
'mka',
|
|
313
|
-
'mkv',
|
|
314
|
-
'mmr',
|
|
315
|
-
'mng',
|
|
316
|
-
'mobi',
|
|
317
|
-
'mov',
|
|
318
|
-
'movie',
|
|
319
|
-
'mp3',
|
|
320
|
-
'mp4',
|
|
321
|
-
'mp4a',
|
|
322
|
-
'mpeg',
|
|
323
|
-
'mpg',
|
|
324
|
-
'mpga',
|
|
325
|
-
'mxu',
|
|
326
|
-
'nef',
|
|
327
|
-
'npx',
|
|
328
|
-
'numbers',
|
|
329
|
-
'nupkg',
|
|
330
|
-
'o',
|
|
331
|
-
'odp',
|
|
332
|
-
'ods',
|
|
333
|
-
'odt',
|
|
334
|
-
'oga',
|
|
335
|
-
'ogg',
|
|
336
|
-
'ogv',
|
|
337
|
-
'otf',
|
|
338
|
-
'ott',
|
|
339
|
-
'pages',
|
|
340
|
-
'pbm',
|
|
341
|
-
'pcx',
|
|
342
|
-
'pdb',
|
|
343
|
-
'pdf',
|
|
344
|
-
'pea',
|
|
345
|
-
'pgm',
|
|
346
|
-
'pic',
|
|
347
|
-
'png',
|
|
348
|
-
'pnm',
|
|
349
|
-
'pot',
|
|
350
|
-
'potm',
|
|
351
|
-
'potx',
|
|
352
|
-
'ppa',
|
|
353
|
-
'ppam',
|
|
354
|
-
'ppm',
|
|
355
|
-
'pps',
|
|
356
|
-
'ppsm',
|
|
357
|
-
'ppsx',
|
|
358
|
-
'ppt',
|
|
359
|
-
'pptm',
|
|
360
|
-
'pptx',
|
|
361
|
-
'psd',
|
|
362
|
-
'pya',
|
|
363
|
-
'pyc',
|
|
364
|
-
'pyo',
|
|
365
|
-
'pyv',
|
|
366
|
-
'qt',
|
|
367
|
-
'rar',
|
|
368
|
-
'ras',
|
|
369
|
-
'raw',
|
|
370
|
-
'resources',
|
|
371
|
-
'rgb',
|
|
372
|
-
'rip',
|
|
373
|
-
'rlc',
|
|
374
|
-
'rmf',
|
|
375
|
-
'rmvb',
|
|
376
|
-
'rpm',
|
|
377
|
-
'rtf',
|
|
378
|
-
'rz',
|
|
379
|
-
's3m',
|
|
380
|
-
's7z',
|
|
381
|
-
'scpt',
|
|
382
|
-
'sgi',
|
|
383
|
-
'shar',
|
|
384
|
-
'snap',
|
|
385
|
-
'sil',
|
|
386
|
-
'sketch',
|
|
387
|
-
'slk',
|
|
388
|
-
'smv',
|
|
389
|
-
'snk',
|
|
390
|
-
'so',
|
|
391
|
-
'stl',
|
|
392
|
-
'suo',
|
|
393
|
-
'sub',
|
|
394
|
-
'swf',
|
|
395
|
-
'tar',
|
|
396
|
-
'tbz',
|
|
397
|
-
'tbz2',
|
|
398
|
-
'tga',
|
|
399
|
-
'tgz',
|
|
400
|
-
'thmx',
|
|
401
|
-
'tif',
|
|
402
|
-
'tiff',
|
|
403
|
-
'tlz',
|
|
404
|
-
'ttc',
|
|
405
|
-
'ttf',
|
|
406
|
-
'txz',
|
|
407
|
-
'udf',
|
|
408
|
-
'uvh',
|
|
409
|
-
'uvi',
|
|
410
|
-
'uvm',
|
|
411
|
-
'uvp',
|
|
412
|
-
'uvs',
|
|
413
|
-
'uvu',
|
|
414
|
-
'viv',
|
|
415
|
-
'vob',
|
|
416
|
-
'war',
|
|
417
|
-
'wav',
|
|
418
|
-
'wax',
|
|
419
|
-
'wbmp',
|
|
420
|
-
'wdp',
|
|
421
|
-
'weba',
|
|
422
|
-
'webm',
|
|
423
|
-
'webp',
|
|
424
|
-
'whl',
|
|
425
|
-
'wim',
|
|
426
|
-
'wm',
|
|
427
|
-
'wma',
|
|
428
|
-
'wmv',
|
|
429
|
-
'wmx',
|
|
430
|
-
'woff',
|
|
431
|
-
'woff2',
|
|
432
|
-
'wrm',
|
|
433
|
-
'wvx',
|
|
434
|
-
'xbm',
|
|
435
|
-
'xif',
|
|
436
|
-
'xla',
|
|
437
|
-
'xlam',
|
|
438
|
-
'xls',
|
|
439
|
-
'xlsb',
|
|
440
|
-
'xlsm',
|
|
441
|
-
'xlsx',
|
|
442
|
-
'xlt',
|
|
443
|
-
'xltm',
|
|
444
|
-
'xltx',
|
|
445
|
-
'xm',
|
|
446
|
-
'xmind',
|
|
447
|
-
'xpi',
|
|
448
|
-
'xpm',
|
|
449
|
-
'xwd',
|
|
450
|
-
'xz',
|
|
451
|
-
'z',
|
|
452
|
-
'zip',
|
|
453
|
-
'zipx'
|
|
454
|
-
]), foreach = (val, fn)=>{
|
|
455
|
-
val instanceof Set ? val.forEach(fn) : fn(val);
|
|
456
|
-
}, addAndConvert = (main, prop, item)=>{
|
|
457
|
-
let container = main[prop];
|
|
458
|
-
container instanceof Set || (main[prop] = container = new Set([
|
|
459
|
-
container
|
|
460
|
-
])), container.add(item);
|
|
461
|
-
}, delFromSet = (main, prop, item)=>{
|
|
462
|
-
let container = main[prop];
|
|
463
|
-
container instanceof Set ? container.delete(item) : container === item && delete main[prop];
|
|
464
|
-
}, isEmptySet = (val)=>val instanceof Set ? 0 === val.size : !val, FsWatchInstances = new Map();
|
|
465
|
-
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
466
|
-
try {
|
|
467
|
-
return watch(path, {
|
|
468
|
-
persistent: options.persistent
|
|
469
|
-
}, (rawEvent, evPath)=>{
|
|
470
|
-
listener(path), emitRaw(rawEvent, evPath, {
|
|
471
|
-
watchedPath: path
|
|
472
|
-
}), evPath && path !== evPath && fsWatchBroadcast(__rspack_external_node_path_806ed179.resolve(path, evPath), KEY_LISTENERS, __rspack_external_node_path_806ed179.join(path, evPath));
|
|
473
|
-
});
|
|
474
|
-
} catch (error) {
|
|
475
|
-
errHandler(error);
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
let fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3)=>{
|
|
480
|
-
let cont = FsWatchInstances.get(fullPath);
|
|
481
|
-
cont && foreach(cont[listenerType], (listener)=>{
|
|
482
|
-
listener(val1, val2, val3);
|
|
483
|
-
});
|
|
484
|
-
}, FsWatchFileInstances = new Map();
|
|
485
|
-
class NodeFsHandler {
|
|
486
|
-
fsw;
|
|
487
|
-
_boundHandleError;
|
|
488
|
-
constructor(fsW){
|
|
489
|
-
this.fsw = fsW, this._boundHandleError = (error)=>fsW._handleError(error);
|
|
490
|
-
}
|
|
491
|
-
_watchWithNodeFs(path, listener) {
|
|
492
|
-
let closer, opts = this.fsw.options, directory = __rspack_external_node_path_806ed179.dirname(path), basename = __rspack_external_node_path_806ed179.basename(path);
|
|
493
|
-
this.fsw._getWatchedDir(directory).add(basename);
|
|
494
|
-
let absolutePath = __rspack_external_node_path_806ed179.resolve(path), options = {
|
|
495
|
-
persistent: opts.persistent
|
|
496
|
-
};
|
|
497
|
-
if (listener || (listener = EMPTY_FN), opts.usePolling) options.interval = opts.interval !== opts.binaryInterval && binaryExtensions.has(__rspack_external_node_path_806ed179.extname(basename).slice(1).toLowerCase()) ? opts.binaryInterval : opts.interval, closer = ((path, fullPath, options, handlers)=>{
|
|
498
|
-
let { listener, rawEmitter } = handlers, cont = FsWatchFileInstances.get(fullPath), copts = cont && cont.options;
|
|
499
|
-
return copts && (copts.persistent < options.persistent || copts.interval > options.interval) && (unwatchFile(fullPath), cont = void 0), cont ? (addAndConvert(cont, KEY_LISTENERS, listener), addAndConvert(cont, KEY_RAW, rawEmitter)) : (cont = {
|
|
500
|
-
listeners: listener,
|
|
501
|
-
rawEmitters: rawEmitter,
|
|
502
|
-
options,
|
|
503
|
-
watcher: watchFile(fullPath, options, (curr, prev)=>{
|
|
504
|
-
foreach(cont.rawEmitters, (rawEmitter)=>{
|
|
505
|
-
rawEmitter(EVENTS_CHANGE, fullPath, {
|
|
506
|
-
curr,
|
|
507
|
-
prev
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
let currmtime = curr.mtimeMs;
|
|
511
|
-
(curr.size !== prev.size || currmtime > prev.mtimeMs || 0 === currmtime) && foreach(cont.listeners, (listener)=>listener(path, curr));
|
|
512
|
-
})
|
|
513
|
-
}, FsWatchFileInstances.set(fullPath, cont)), ()=>{
|
|
514
|
-
delFromSet(cont, KEY_LISTENERS, listener), delFromSet(cont, KEY_RAW, rawEmitter), isEmptySet(cont.listeners) && (FsWatchFileInstances.delete(fullPath), unwatchFile(fullPath), cont.options = cont.watcher = void 0, Object.freeze(cont));
|
|
515
|
-
};
|
|
516
|
-
})(path, absolutePath, options, {
|
|
517
|
-
listener,
|
|
518
|
-
rawEmitter: this.fsw._emitRaw
|
|
519
|
-
});
|
|
520
|
-
else closer = ((path, fullPath, options, handlers)=>{
|
|
521
|
-
let watcher, { listener, errHandler, rawEmitter } = handlers, cont = FsWatchInstances.get(fullPath);
|
|
522
|
-
if (!options.persistent) {
|
|
523
|
-
if (!(watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter))) return;
|
|
524
|
-
return watcher.close.bind(watcher);
|
|
525
|
-
}
|
|
526
|
-
if (cont) addAndConvert(cont, KEY_LISTENERS, listener), addAndConvert(cont, KEY_ERR, errHandler), addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
527
|
-
else {
|
|
528
|
-
if (!(watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW)))) return;
|
|
529
|
-
watcher.on(EVENTS_ERROR, async (error)=>{
|
|
530
|
-
let broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
531
|
-
if (cont && (cont.watcherUnusable = !0), isWindows && 'EPERM' === error.code) try {
|
|
532
|
-
let fd = await promises_open(path, 'r');
|
|
533
|
-
await fd.close(), broadcastErr(error);
|
|
534
|
-
} catch (err) {}
|
|
535
|
-
else broadcastErr(error);
|
|
536
|
-
}), cont = {
|
|
537
|
-
listeners: listener,
|
|
538
|
-
errHandlers: errHandler,
|
|
539
|
-
rawEmitters: rawEmitter,
|
|
540
|
-
watcher
|
|
541
|
-
}, FsWatchInstances.set(fullPath, cont);
|
|
542
|
-
}
|
|
543
|
-
return ()=>{
|
|
544
|
-
if (delFromSet(cont, KEY_LISTENERS, listener), delFromSet(cont, KEY_ERR, errHandler), delFromSet(cont, KEY_RAW, rawEmitter), isEmptySet(cont.listeners)) {
|
|
545
|
-
let cont1;
|
|
546
|
-
cont.watcher.close(), FsWatchInstances.delete(fullPath), HANDLER_KEYS.forEach((cont1 = cont, (key)=>{
|
|
547
|
-
let set = cont1[key];
|
|
548
|
-
set instanceof Set ? set.clear() : delete cont1[key];
|
|
549
|
-
})), cont.watcher = void 0, Object.freeze(cont);
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
})(path, absolutePath, options, {
|
|
553
|
-
listener,
|
|
554
|
-
errHandler: this._boundHandleError,
|
|
555
|
-
rawEmitter: this.fsw._emitRaw
|
|
556
|
-
});
|
|
557
|
-
return closer;
|
|
558
|
-
}
|
|
559
|
-
_handleFile(file, stats, initialAdd) {
|
|
560
|
-
if (this.fsw.closed) return;
|
|
561
|
-
let dirname = __rspack_external_node_path_806ed179.dirname(file), basename = __rspack_external_node_path_806ed179.basename(file), parent = this.fsw._getWatchedDir(dirname), prevStats = stats;
|
|
562
|
-
if (parent.has(basename)) return;
|
|
563
|
-
let listener = async (path, newStats)=>{
|
|
564
|
-
if (this.fsw._throttle('watch', file, 5)) if (newStats && 0 !== newStats.mtimeMs) {
|
|
565
|
-
if (parent.has(basename)) {
|
|
566
|
-
let at = newStats.atimeMs, mt = newStats.mtimeMs;
|
|
567
|
-
(!at || at <= mt || mt !== prevStats.mtimeMs) && this.fsw._emit(EVENTS_CHANGE, file, newStats), prevStats = newStats;
|
|
568
|
-
}
|
|
569
|
-
} else try {
|
|
570
|
-
let newStats = await promises_stat(file);
|
|
571
|
-
if (this.fsw.closed) return;
|
|
572
|
-
let at = newStats.atimeMs, mt = newStats.mtimeMs;
|
|
573
|
-
if ((!at || at <= mt || mt !== prevStats.mtimeMs) && this.fsw._emit(EVENTS_CHANGE, file, newStats), (isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
|
574
|
-
this.fsw._closeFile(path), prevStats = newStats;
|
|
575
|
-
let closer = this._watchWithNodeFs(file, listener);
|
|
576
|
-
closer && this.fsw._addPathCloser(path, closer);
|
|
577
|
-
} else prevStats = newStats;
|
|
578
|
-
} catch (error) {
|
|
579
|
-
this.fsw._remove(dirname, basename);
|
|
580
|
-
}
|
|
581
|
-
}, closer = this._watchWithNodeFs(file, listener);
|
|
582
|
-
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
583
|
-
if (!this.fsw._throttle(EVENTS_ADD, file, 0)) return;
|
|
584
|
-
this.fsw._emit(EVENTS_ADD, file, stats);
|
|
585
|
-
}
|
|
586
|
-
return closer;
|
|
587
|
-
}
|
|
588
|
-
async _handleSymlink(entry, directory, path, item) {
|
|
589
|
-
if (this.fsw.closed) return;
|
|
590
|
-
let full = entry.fullPath, dir = this.fsw._getWatchedDir(directory);
|
|
591
|
-
if (!this.fsw.options.followSymlinks) {
|
|
592
|
-
let linkPath;
|
|
593
|
-
this.fsw._incrReadyCount();
|
|
594
|
-
try {
|
|
595
|
-
linkPath = await promises_realpath(path);
|
|
596
|
-
} catch (e) {
|
|
597
|
-
return this.fsw._emitReady(), !0;
|
|
598
|
-
}
|
|
599
|
-
if (this.fsw.closed) return;
|
|
600
|
-
return dir.has(item) ? this.fsw._symlinkPaths.get(full) !== linkPath && (this.fsw._symlinkPaths.set(full, linkPath), this.fsw._emit(EVENTS_CHANGE, path, entry.stats)) : (dir.add(item), this.fsw._symlinkPaths.set(full, linkPath), this.fsw._emit(EVENTS_ADD, path, entry.stats)), this.fsw._emitReady(), !0;
|
|
601
|
-
}
|
|
602
|
-
if (this.fsw._symlinkPaths.has(full)) return !0;
|
|
603
|
-
this.fsw._symlinkPaths.set(full, !0);
|
|
604
|
-
}
|
|
605
|
-
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
606
|
-
directory = __rspack_external_node_path_806ed179.join(directory, '');
|
|
607
|
-
let throttleKey = target ? `${directory}:${target}` : directory;
|
|
608
|
-
if (!(throttler = this.fsw._throttle('readdir', throttleKey, 1000))) return;
|
|
609
|
-
let previous = this.fsw._getWatchedDir(wh.path), current = new Set(), stream = this.fsw._readdirp(directory, {
|
|
610
|
-
fileFilter: (entry)=>wh.filterPath(entry),
|
|
611
|
-
directoryFilter: (entry)=>wh.filterDir(entry)
|
|
612
|
-
});
|
|
613
|
-
if (stream) return stream.on('data', async (entry)=>{
|
|
614
|
-
if (this.fsw.closed) {
|
|
615
|
-
stream = void 0;
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
let item = entry.path, path = __rspack_external_node_path_806ed179.join(directory, item);
|
|
619
|
-
if (current.add(item), !(entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item))) {
|
|
620
|
-
if (this.fsw.closed) {
|
|
621
|
-
stream = void 0;
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
item !== target && (target || previous.has(item)) || (this.fsw._incrReadyCount(), path = __rspack_external_node_path_806ed179.join(dir, __rspack_external_node_path_806ed179.relative(dir, path)), this._addToNodeFs(path, initialAdd, wh, depth + 1));
|
|
625
|
-
}
|
|
626
|
-
}).on(EVENTS_ERROR, this._boundHandleError), new Promise((resolve, reject)=>{
|
|
627
|
-
if (!stream) return reject();
|
|
628
|
-
stream.once('end', ()=>{
|
|
629
|
-
if (this.fsw.closed) {
|
|
630
|
-
stream = void 0;
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
let wasThrottled = !!throttler && throttler.clear();
|
|
634
|
-
resolve(void 0), previous.getChildren().filter((item)=>item !== directory && !current.has(item)).forEach((item)=>{
|
|
635
|
-
this.fsw._remove(directory, item);
|
|
636
|
-
}), stream = void 0, wasThrottled && this._handleRead(directory, !1, wh, target, dir, depth, throttler);
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
|
641
|
-
let throttler, closer, parentDir = this.fsw._getWatchedDir(__rspack_external_node_path_806ed179.dirname(dir)), tracked = parentDir.has(__rspack_external_node_path_806ed179.basename(dir));
|
|
642
|
-
initialAdd && this.fsw.options.ignoreInitial || target || tracked || this.fsw._emit(EVENTS_ADD_DIR, dir, stats), parentDir.add(__rspack_external_node_path_806ed179.basename(dir)), this.fsw._getWatchedDir(dir);
|
|
643
|
-
let oDepth = this.fsw.options.depth;
|
|
644
|
-
if ((null == oDepth || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
|
645
|
-
if (!target && (await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler), this.fsw.closed)) return;
|
|
646
|
-
closer = this._watchWithNodeFs(dir, (dirPath, stats)=>{
|
|
647
|
-
stats && 0 === stats.mtimeMs || this._handleRead(dirPath, !1, wh, target, dir, depth, throttler);
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
return closer;
|
|
651
|
-
}
|
|
652
|
-
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
653
|
-
let ready = this.fsw._emitReady;
|
|
654
|
-
if (this.fsw._isIgnored(path) || this.fsw.closed) return ready(), !1;
|
|
655
|
-
let wh = this.fsw._getWatchHelpers(path);
|
|
656
|
-
priorWh && (wh.filterPath = (entry)=>priorWh.filterPath(entry), wh.filterDir = (entry)=>priorWh.filterDir(entry));
|
|
657
|
-
try {
|
|
658
|
-
let closer, stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
659
|
-
if (this.fsw.closed) return;
|
|
660
|
-
if (this.fsw._isIgnored(wh.watchPath, stats)) return ready(), !1;
|
|
661
|
-
let follow = this.fsw.options.followSymlinks;
|
|
662
|
-
if (stats.isDirectory()) {
|
|
663
|
-
let absPath = __rspack_external_node_path_806ed179.resolve(path), targetPath = follow ? await promises_realpath(path) : path;
|
|
664
|
-
if (this.fsw.closed || (closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath), this.fsw.closed)) return;
|
|
665
|
-
absPath !== targetPath && void 0 !== targetPath && this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
666
|
-
} else if (stats.isSymbolicLink()) {
|
|
667
|
-
let targetPath = follow ? await promises_realpath(path) : path;
|
|
668
|
-
if (this.fsw.closed) return;
|
|
669
|
-
let parent = __rspack_external_node_path_806ed179.dirname(wh.watchPath);
|
|
670
|
-
if (this.fsw._getWatchedDir(parent).add(wh.watchPath), this.fsw._emit(EVENTS_ADD, wh.watchPath, stats), closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath), this.fsw.closed) return;
|
|
671
|
-
void 0 !== targetPath && this.fsw._symlinkPaths.set(__rspack_external_node_path_806ed179.resolve(path), targetPath);
|
|
672
|
-
} else closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
673
|
-
return ready(), closer && this.fsw._addPathCloser(path, closer), !1;
|
|
674
|
-
} catch (error) {
|
|
675
|
-
if (this.fsw._handleError(error)) return ready(), path;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
let BACK_SLASH_RE = /\\/g, DOUBLE_SLASH_RE = /\/\//g, DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/, REPLACER_RE = /^\.[/\\]/;
|
|
680
|
-
function arrify(item) {
|
|
681
|
-
return Array.isArray(item) ? item : [
|
|
682
|
-
item
|
|
683
|
-
];
|
|
684
|
-
}
|
|
685
|
-
let isMatcherObject = (matcher)=>'object' == typeof matcher && null !== matcher && !(matcher instanceof RegExp);
|
|
686
|
-
function createPattern(matcher) {
|
|
687
|
-
return 'function' == typeof matcher ? matcher : 'string' == typeof matcher ? (string)=>matcher === string : matcher instanceof RegExp ? (string)=>matcher.test(string) : 'object' == typeof matcher && null !== matcher ? (string)=>{
|
|
688
|
-
if (matcher.path === string) return !0;
|
|
689
|
-
if (matcher.recursive) {
|
|
690
|
-
let relative = __rspack_external_node_path_806ed179.relative(matcher.path, string);
|
|
691
|
-
return !!relative && !relative.startsWith('..') && !__rspack_external_node_path_806ed179.isAbsolute(relative);
|
|
692
|
-
}
|
|
693
|
-
return !1;
|
|
694
|
-
} : ()=>!1;
|
|
695
|
-
}
|
|
696
|
-
function normalizePath(path) {
|
|
697
|
-
if ('string' != typeof path) throw Error('string expected');
|
|
698
|
-
path = (path = __rspack_external_node_path_806ed179.normalize(path)).replace(/\\/g, '/');
|
|
699
|
-
let prepend = !1;
|
|
700
|
-
return path.startsWith('//') && (prepend = !0), path = path.replace(DOUBLE_SLASH_RE, '/'), prepend && (path = '/' + path), path;
|
|
701
|
-
}
|
|
702
|
-
function matchPatterns(patterns, testString, stats) {
|
|
703
|
-
let path = normalizePath(testString);
|
|
704
|
-
for(let index = 0; index < patterns.length; index++)if ((0, patterns[index])(path, stats)) return !0;
|
|
705
|
-
return !1;
|
|
706
|
-
}
|
|
707
|
-
function anymatch(matchers, testString) {
|
|
708
|
-
if (null == matchers) throw TypeError('anymatch: specify first argument');
|
|
709
|
-
let patterns = arrify(matchers).map((matcher)=>createPattern(matcher));
|
|
710
|
-
return null == testString ? (testString, stats)=>matchPatterns(patterns, testString, stats) : matchPatterns(patterns, testString);
|
|
711
|
-
}
|
|
712
|
-
let unifyPaths = (paths_)=>{
|
|
713
|
-
let paths = arrify(paths_).flat();
|
|
714
|
-
if (!paths.every((p)=>'string' == typeof p)) throw TypeError(`Non-string provided as watch path: ${paths}`);
|
|
715
|
-
return paths.map(normalizePathToUnix);
|
|
716
|
-
}, toUnix = (string)=>{
|
|
717
|
-
let str = string.replace(BACK_SLASH_RE, '/'), prepend = !1;
|
|
718
|
-
return str.startsWith('//') && (prepend = !0), str = str.replace(DOUBLE_SLASH_RE, '/'), prepend && (str = '/' + str), str;
|
|
719
|
-
}, normalizePathToUnix = (path)=>toUnix(__rspack_external_node_path_806ed179.normalize(toUnix(path))), normalizeIgnored = (cwd = '')=>(path)=>'string' == typeof path ? normalizePathToUnix(__rspack_external_node_path_806ed179.isAbsolute(path) ? path : __rspack_external_node_path_806ed179.join(cwd, path)) : path, EMPTY_SET = Object.freeze(new Set());
|
|
720
|
-
class DirEntry {
|
|
721
|
-
path;
|
|
722
|
-
_removeWatcher;
|
|
723
|
-
items;
|
|
724
|
-
constructor(dir, removeWatcher){
|
|
725
|
-
this.path = dir, this._removeWatcher = removeWatcher, this.items = new Set();
|
|
726
|
-
}
|
|
727
|
-
add(item) {
|
|
728
|
-
let { items } = this;
|
|
729
|
-
items && '.' !== item && '..' !== item && items.add(item);
|
|
730
|
-
}
|
|
731
|
-
async remove(item) {
|
|
732
|
-
let { items } = this;
|
|
733
|
-
if (!items || (items.delete(item), items.size > 0)) return;
|
|
734
|
-
let dir = this.path;
|
|
735
|
-
try {
|
|
736
|
-
await readdir(dir);
|
|
737
|
-
} catch (err) {
|
|
738
|
-
this._removeWatcher && this._removeWatcher(__rspack_external_node_path_806ed179.dirname(dir), __rspack_external_node_path_806ed179.basename(dir));
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
has(item) {
|
|
742
|
-
let { items } = this;
|
|
743
|
-
if (items) return items.has(item);
|
|
744
|
-
}
|
|
745
|
-
getChildren() {
|
|
746
|
-
let { items } = this;
|
|
747
|
-
return items ? [
|
|
748
|
-
...items.values()
|
|
749
|
-
] : [];
|
|
750
|
-
}
|
|
751
|
-
dispose() {
|
|
752
|
-
this.items.clear(), this.path = '', this._removeWatcher = EMPTY_FN, this.items = EMPTY_SET, Object.freeze(this);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
class WatchHelper {
|
|
756
|
-
fsw;
|
|
757
|
-
path;
|
|
758
|
-
watchPath;
|
|
759
|
-
fullWatchPath;
|
|
760
|
-
dirParts;
|
|
761
|
-
followSymlinks;
|
|
762
|
-
statMethod;
|
|
763
|
-
constructor(path, follow, fsw){
|
|
764
|
-
this.fsw = fsw;
|
|
765
|
-
let watchPath = path;
|
|
766
|
-
this.path = path = path.replace(REPLACER_RE, ''), this.watchPath = watchPath, this.fullWatchPath = __rspack_external_node_path_806ed179.resolve(watchPath), this.dirParts = [], this.dirParts.forEach((parts)=>{
|
|
767
|
-
parts.length > 1 && parts.pop();
|
|
768
|
-
}), this.followSymlinks = follow, this.statMethod = follow ? 'stat' : 'lstat';
|
|
769
|
-
}
|
|
770
|
-
entryPath(entry) {
|
|
771
|
-
return __rspack_external_node_path_806ed179.join(this.watchPath, __rspack_external_node_path_806ed179.relative(this.watchPath, entry.fullPath));
|
|
772
|
-
}
|
|
773
|
-
filterPath(entry) {
|
|
774
|
-
let { stats } = entry;
|
|
775
|
-
if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
|
|
776
|
-
let resolvedPath = this.entryPath(entry);
|
|
777
|
-
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
778
|
-
}
|
|
779
|
-
filterDir(entry) {
|
|
780
|
-
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
class FSWatcher extends EventEmitter {
|
|
784
|
-
closed;
|
|
785
|
-
options;
|
|
786
|
-
_closers;
|
|
787
|
-
_ignoredPaths;
|
|
788
|
-
_throttled;
|
|
789
|
-
_streams;
|
|
790
|
-
_symlinkPaths;
|
|
791
|
-
_watched;
|
|
792
|
-
_pendingWrites;
|
|
793
|
-
_pendingUnlinks;
|
|
794
|
-
_readyCount;
|
|
795
|
-
_emitReady;
|
|
796
|
-
_closePromise;
|
|
797
|
-
_userIgnored;
|
|
798
|
-
_readyEmitted;
|
|
799
|
-
_emitRaw;
|
|
800
|
-
_boundRemove;
|
|
801
|
-
_nodeFsHandler;
|
|
802
|
-
constructor(_opts = {}){
|
|
803
|
-
super(), this.closed = !1, this._closers = new Map(), this._ignoredPaths = new Set(), this._throttled = new Map(), this._streams = new Set(), this._symlinkPaths = new Map(), this._watched = new Map(), this._pendingWrites = new Map(), this._pendingUnlinks = new Map(), this._readyCount = 0, this._readyEmitted = !1;
|
|
804
|
-
let awf = _opts.awaitWriteFinish, DEF_AWF = {
|
|
805
|
-
stabilityThreshold: 2000,
|
|
806
|
-
pollInterval: 100
|
|
807
|
-
}, opts = {
|
|
808
|
-
persistent: !0,
|
|
809
|
-
ignoreInitial: !1,
|
|
810
|
-
ignorePermissionErrors: !1,
|
|
811
|
-
interval: 100,
|
|
812
|
-
binaryInterval: 300,
|
|
813
|
-
followSymlinks: !0,
|
|
814
|
-
usePolling: !1,
|
|
815
|
-
atomic: !0,
|
|
816
|
-
..._opts,
|
|
817
|
-
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
818
|
-
awaitWriteFinish: !0 === awf ? DEF_AWF : 'object' == typeof awf && {
|
|
819
|
-
...DEF_AWF,
|
|
820
|
-
...awf
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
isIBMi && (opts.usePolling = !0), void 0 === opts.atomic && (opts.atomic = !opts.usePolling);
|
|
824
|
-
let envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
825
|
-
if (void 0 !== envPoll) {
|
|
826
|
-
let envLower = envPoll.toLowerCase();
|
|
827
|
-
'false' === envLower || '0' === envLower ? opts.usePolling = !1 : 'true' === envLower || '1' === envLower ? opts.usePolling = !0 : opts.usePolling = !!envLower;
|
|
828
|
-
}
|
|
829
|
-
let envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
830
|
-
envInterval && (opts.interval = Number.parseInt(envInterval, 10));
|
|
831
|
-
let readyCalls = 0;
|
|
832
|
-
this._emitReady = ()=>{
|
|
833
|
-
++readyCalls >= this._readyCount && (this._emitReady = EMPTY_FN, this._readyEmitted = !0, process.nextTick(()=>this.emit(EVENTS_READY)));
|
|
834
|
-
}, this._emitRaw = (...args)=>this.emit(EVENTS_RAW, ...args), this._boundRemove = this._remove.bind(this), this.options = opts, this._nodeFsHandler = new NodeFsHandler(this), Object.freeze(opts);
|
|
835
|
-
}
|
|
836
|
-
_addIgnoredPath(matcher) {
|
|
837
|
-
if (isMatcherObject(matcher)) {
|
|
838
|
-
for (let ignored of this._ignoredPaths)if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
|
|
839
|
-
}
|
|
840
|
-
this._ignoredPaths.add(matcher);
|
|
841
|
-
}
|
|
842
|
-
_removeIgnoredPath(matcher) {
|
|
843
|
-
if (this._ignoredPaths.delete(matcher), 'string' == typeof matcher) for (let ignored of this._ignoredPaths)isMatcherObject(ignored) && ignored.path === matcher && this._ignoredPaths.delete(ignored);
|
|
844
|
-
}
|
|
845
|
-
add(paths_, _origAdd, _internal) {
|
|
846
|
-
let { cwd } = this.options;
|
|
847
|
-
this.closed = !1, this._closePromise = void 0;
|
|
848
|
-
let paths = unifyPaths(paths_);
|
|
849
|
-
return cwd && (paths = paths.map((path)=>__rspack_external_node_path_806ed179.isAbsolute(path) ? path : __rspack_external_node_path_806ed179.join(cwd, path))), paths.forEach((path)=>{
|
|
850
|
-
this._removeIgnoredPath(path);
|
|
851
|
-
}), this._userIgnored = void 0, this._readyCount || (this._readyCount = 0), this._readyCount += paths.length, Promise.all(paths.map(async (path)=>{
|
|
852
|
-
let res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
853
|
-
return res && this._emitReady(), res;
|
|
854
|
-
})).then((results)=>{
|
|
855
|
-
this.closed || results.forEach((item)=>{
|
|
856
|
-
item && this.add(__rspack_external_node_path_806ed179.dirname(item), __rspack_external_node_path_806ed179.basename(_origAdd || item));
|
|
857
|
-
});
|
|
858
|
-
}), this;
|
|
859
|
-
}
|
|
860
|
-
unwatch(paths_) {
|
|
861
|
-
if (this.closed) return this;
|
|
862
|
-
let paths = unifyPaths(paths_), { cwd } = this.options;
|
|
863
|
-
return paths.forEach((path)=>{
|
|
864
|
-
__rspack_external_node_path_806ed179.isAbsolute(path) || this._closers.has(path) || (cwd && (path = __rspack_external_node_path_806ed179.join(cwd, path)), path = __rspack_external_node_path_806ed179.resolve(path)), this._closePath(path), this._addIgnoredPath(path), this._watched.has(path) && this._addIgnoredPath({
|
|
865
|
-
path,
|
|
866
|
-
recursive: !0
|
|
867
|
-
}), this._userIgnored = void 0;
|
|
868
|
-
}), this;
|
|
869
|
-
}
|
|
870
|
-
close() {
|
|
871
|
-
if (this._closePromise) return this._closePromise;
|
|
872
|
-
this.closed = !0, this.removeAllListeners();
|
|
873
|
-
let closers = [];
|
|
874
|
-
return this._closers.forEach((closerList)=>closerList.forEach((closer)=>{
|
|
875
|
-
let promise = closer();
|
|
876
|
-
promise instanceof Promise && closers.push(promise);
|
|
877
|
-
})), this._streams.forEach((stream)=>stream.destroy()), this._userIgnored = void 0, this._readyCount = 0, this._readyEmitted = !1, this._watched.forEach((dirent)=>dirent.dispose()), this._closers.clear(), this._watched.clear(), this._streams.clear(), this._symlinkPaths.clear(), this._throttled.clear(), this._closePromise = closers.length ? Promise.all(closers).then(()=>void 0) : Promise.resolve(), this._closePromise;
|
|
878
|
-
}
|
|
879
|
-
getWatched() {
|
|
880
|
-
let watchList = {};
|
|
881
|
-
return this._watched.forEach((entry, dir)=>{
|
|
882
|
-
watchList[(this.options.cwd ? __rspack_external_node_path_806ed179.relative(this.options.cwd, dir) : dir) || '.'] = entry.getChildren().sort();
|
|
883
|
-
}), watchList;
|
|
884
|
-
}
|
|
885
|
-
emitWithAll(event, args) {
|
|
886
|
-
this.emit(event, ...args), event !== EVENTS_ERROR && this.emit(EVENTS_ALL, event, ...args);
|
|
887
|
-
}
|
|
888
|
-
async _emit(event, path, stats) {
|
|
889
|
-
let pw;
|
|
890
|
-
if (this.closed) return;
|
|
891
|
-
let opts = this.options;
|
|
892
|
-
isWindows && (path = __rspack_external_node_path_806ed179.normalize(path)), opts.cwd && (path = __rspack_external_node_path_806ed179.relative(opts.cwd, path));
|
|
893
|
-
let args = [
|
|
894
|
-
path
|
|
895
|
-
];
|
|
896
|
-
null != stats && args.push(stats);
|
|
897
|
-
let awf = opts.awaitWriteFinish;
|
|
898
|
-
if (awf && (pw = this._pendingWrites.get(path))) return pw.lastChange = new Date(), this;
|
|
899
|
-
if (opts.atomic) {
|
|
900
|
-
if (event === EVENTS_UNLINK) return this._pendingUnlinks.set(path, [
|
|
901
|
-
event,
|
|
902
|
-
...args
|
|
903
|
-
]), setTimeout(()=>{
|
|
904
|
-
this._pendingUnlinks.forEach((entry, path)=>{
|
|
905
|
-
this.emit(...entry), this.emit(EVENTS_ALL, ...entry), this._pendingUnlinks.delete(path);
|
|
906
|
-
});
|
|
907
|
-
}, 'number' == typeof opts.atomic ? opts.atomic : 100), this;
|
|
908
|
-
event === EVENTS_ADD && this._pendingUnlinks.has(path) && (event = EVENTS_CHANGE, this._pendingUnlinks.delete(path));
|
|
909
|
-
}
|
|
910
|
-
if (awf && (event === EVENTS_ADD || event === EVENTS_CHANGE) && this._readyEmitted) {
|
|
911
|
-
let awfEmit = (err, stats)=>{
|
|
912
|
-
err ? (event = EVENTS_ERROR, args[0] = err, this.emitWithAll(event, args)) : stats && (args.length > 1 ? args[1] = stats : args.push(stats), this.emitWithAll(event, args));
|
|
913
|
-
};
|
|
914
|
-
return this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit), this;
|
|
915
|
-
}
|
|
916
|
-
if (event === EVENTS_CHANGE && !this._throttle(EVENTS_CHANGE, path, 50)) return this;
|
|
917
|
-
if (opts.alwaysStat && void 0 === stats && (event === EVENTS_ADD || event === EVENTS_ADD_DIR || event === EVENTS_CHANGE)) {
|
|
918
|
-
let stats, fullPath = opts.cwd ? __rspack_external_node_path_806ed179.join(opts.cwd, path) : path;
|
|
919
|
-
try {
|
|
920
|
-
stats = await promises_stat(fullPath);
|
|
921
|
-
} catch (err) {}
|
|
922
|
-
if (!stats || this.closed) return;
|
|
923
|
-
args.push(stats);
|
|
924
|
-
}
|
|
925
|
-
return this.emitWithAll(event, args), this;
|
|
926
|
-
}
|
|
927
|
-
_handleError(error) {
|
|
928
|
-
let code = error && error.code;
|
|
929
|
-
return error && 'ENOENT' !== code && 'ENOTDIR' !== code && (!this.options.ignorePermissionErrors || 'EPERM' !== code && 'EACCES' !== code) && this.emit(EVENTS_ERROR, error), error || this.closed;
|
|
930
|
-
}
|
|
931
|
-
_throttle(actionType, path, timeout) {
|
|
932
|
-
let timeoutObject;
|
|
933
|
-
this._throttled.has(actionType) || this._throttled.set(actionType, new Map());
|
|
934
|
-
let action = this._throttled.get(actionType);
|
|
935
|
-
if (!action) throw Error('invalid throttle');
|
|
936
|
-
let actionPath = action.get(path);
|
|
937
|
-
if (actionPath) return actionPath.count++, !1;
|
|
938
|
-
let clear = ()=>{
|
|
939
|
-
let item = action.get(path), count = item ? item.count : 0;
|
|
940
|
-
return action.delete(path), clearTimeout(timeoutObject), item && clearTimeout(item.timeoutObject), count;
|
|
941
|
-
}, thr = {
|
|
942
|
-
timeoutObject: timeoutObject = setTimeout(clear, timeout),
|
|
943
|
-
clear,
|
|
944
|
-
count: 0
|
|
945
|
-
};
|
|
946
|
-
return action.set(path, thr), thr;
|
|
947
|
-
}
|
|
948
|
-
_incrReadyCount() {
|
|
949
|
-
return this._readyCount++;
|
|
950
|
-
}
|
|
951
|
-
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
952
|
-
let timeoutHandler, awf = this.options.awaitWriteFinish;
|
|
953
|
-
if ('object' != typeof awf) return;
|
|
954
|
-
let pollInterval = awf.pollInterval, fullPath = path;
|
|
955
|
-
this.options.cwd && !__rspack_external_node_path_806ed179.isAbsolute(path) && (fullPath = __rspack_external_node_path_806ed179.join(this.options.cwd, path));
|
|
956
|
-
let now = new Date(), writes = this._pendingWrites;
|
|
957
|
-
function awaitWriteFinishFn(prevStat) {
|
|
958
|
-
external_node_fs_stat(fullPath, (err, curStat)=>{
|
|
959
|
-
if (err || !writes.has(path)) {
|
|
960
|
-
err && 'ENOENT' !== err.code && awfEmit(err);
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
963
|
-
let now = Number(new Date());
|
|
964
|
-
prevStat && curStat.size !== prevStat.size && (writes.get(path).lastChange = now), now - writes.get(path).lastChange >= threshold ? (writes.delete(path), awfEmit(void 0, curStat)) : timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
writes.has(path) || (writes.set(path, {
|
|
968
|
-
lastChange: now,
|
|
969
|
-
cancelWait: ()=>(writes.delete(path), clearTimeout(timeoutHandler), event)
|
|
970
|
-
}), timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval));
|
|
971
|
-
}
|
|
972
|
-
_isIgnored(path, stats) {
|
|
973
|
-
if (this.options.atomic && DOT_RE.test(path)) return !0;
|
|
974
|
-
if (!this._userIgnored) {
|
|
975
|
-
let { cwd } = this.options, ignored = (this.options.ignored || []).map(normalizeIgnored(cwd)), list = [
|
|
976
|
-
...[
|
|
977
|
-
...this._ignoredPaths
|
|
978
|
-
].map(normalizeIgnored(cwd)),
|
|
979
|
-
...ignored
|
|
980
|
-
];
|
|
981
|
-
this._userIgnored = anymatch(list, void 0);
|
|
982
|
-
}
|
|
983
|
-
return this._userIgnored(path, stats);
|
|
984
|
-
}
|
|
985
|
-
_isntIgnored(path, stat) {
|
|
986
|
-
return !this._isIgnored(path, stat);
|
|
987
|
-
}
|
|
988
|
-
_getWatchHelpers(path) {
|
|
989
|
-
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
990
|
-
}
|
|
991
|
-
_getWatchedDir(directory) {
|
|
992
|
-
let dir = __rspack_external_node_path_806ed179.resolve(directory);
|
|
993
|
-
return this._watched.has(dir) || this._watched.set(dir, new DirEntry(dir, this._boundRemove)), this._watched.get(dir);
|
|
994
|
-
}
|
|
995
|
-
_hasReadPermissions(stats) {
|
|
996
|
-
return !!this.options.ignorePermissionErrors || !!(256 & Number(stats.mode));
|
|
997
|
-
}
|
|
998
|
-
_remove(directory, item, isDirectory) {
|
|
999
|
-
let path = __rspack_external_node_path_806ed179.join(directory, item), fullPath = __rspack_external_node_path_806ed179.resolve(path);
|
|
1000
|
-
if (isDirectory = null != isDirectory ? isDirectory : this._watched.has(path) || this._watched.has(fullPath), !this._throttle('remove', path, 100)) return;
|
|
1001
|
-
isDirectory || 1 !== this._watched.size || this.add(directory, item, !0), this._getWatchedDir(path).getChildren().forEach((nested)=>this._remove(path, nested));
|
|
1002
|
-
let parent = this._getWatchedDir(directory), wasTracked = parent.has(item);
|
|
1003
|
-
parent.remove(item), this._symlinkPaths.has(fullPath) && this._symlinkPaths.delete(fullPath);
|
|
1004
|
-
let relPath = path;
|
|
1005
|
-
if (this.options.cwd && (relPath = __rspack_external_node_path_806ed179.relative(this.options.cwd, path)), this.options.awaitWriteFinish && this._pendingWrites.has(relPath) && this._pendingWrites.get(relPath).cancelWait() === EVENTS_ADD) return;
|
|
1006
|
-
this._watched.delete(path), this._watched.delete(fullPath);
|
|
1007
|
-
let eventName = isDirectory ? EVENTS_UNLINK_DIR : EVENTS_UNLINK;
|
|
1008
|
-
wasTracked && !this._isIgnored(path) && this._emit(eventName, path), this._closePath(path);
|
|
1009
|
-
}
|
|
1010
|
-
_closePath(path) {
|
|
1011
|
-
this._closeFile(path);
|
|
1012
|
-
let dir = __rspack_external_node_path_806ed179.dirname(path);
|
|
1013
|
-
this._getWatchedDir(dir).remove(__rspack_external_node_path_806ed179.basename(path));
|
|
1014
|
-
}
|
|
1015
|
-
_closeFile(path) {
|
|
1016
|
-
let closers = this._closers.get(path);
|
|
1017
|
-
closers && (closers.forEach((closer)=>closer()), this._closers.delete(path));
|
|
1018
|
-
}
|
|
1019
|
-
_addPathCloser(path, closer) {
|
|
1020
|
-
if (!closer) return;
|
|
1021
|
-
let list = this._closers.get(path);
|
|
1022
|
-
list || (list = [], this._closers.set(path, list)), list.push(closer);
|
|
1023
|
-
}
|
|
1024
|
-
_readdirp(root, opts) {
|
|
1025
|
-
if (this.closed) return;
|
|
1026
|
-
let stream = readdirp(root, {
|
|
1027
|
-
type: EVENTS_ALL,
|
|
1028
|
-
alwaysStat: !0,
|
|
1029
|
-
lstat: !0,
|
|
1030
|
-
...opts,
|
|
1031
|
-
depth: 0
|
|
1032
|
-
});
|
|
1033
|
-
return this._streams.add(stream), stream.once("close", ()=>{
|
|
1034
|
-
stream = void 0;
|
|
1035
|
-
}), stream.once("end", ()=>{
|
|
1036
|
-
stream && (this._streams.delete(stream), stream = void 0);
|
|
1037
|
-
}), stream;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
function chokidar_watch(paths, options = {}) {
|
|
1041
|
-
let watcher = new FSWatcher(options);
|
|
1042
|
-
return watcher.add(paths), watcher;
|
|
1043
|
-
}
|
|
1044
|
-
export default {
|
|
1045
|
-
watch: chokidar_watch,
|
|
1046
|
-
FSWatcher: FSWatcher
|
|
1047
|
-
};
|
|
2
|
+
import{EventEmitter as t}from"node:events";import{stat as e,unwatchFile as i,watch as s,watchFile as r}from"node:fs";import{lstat as a,open as h,readdir as n,realpath as o,stat as l}from"node:fs/promises";import{join as d,relative as c,resolve as f,sep as m}from"node:path";import{Readable as p}from"node:stream";import{type as _}from"node:os";import*as u from"node:path";let w="files",g="directories",y="files_directories",v={root:".",fileFilter:t=>!0,directoryFilter:t=>!0,type:w,lstat:!1,depth:0x80000000,alwaysStat:!1,highWaterMark:4096};Object.freeze(v);let P="READDIRP_RECURSIVE_ERROR",b=new Set(["ENOENT","EPERM","EACCES","ELOOP",P]),E=[g,"all",y,w],x=new Set([g,"all",y]),k=new Set(["all",y,w]),W="win32"===process.platform,D=t=>!0,F=t=>{if(void 0===t)return D;if("function"==typeof t)return t;if("string"==typeof t){let e=t.trim();return t=>t.basename===e}if(Array.isArray(t)){let e=t.map(t=>t.trim());return t=>e.some(e=>t.basename===e)}return D};class S extends p{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...v,...t},{root:i,type:s}=e;this._fileFilter=F(e.fileFilter),this._directoryFilter=F(e.directoryFilter);let r=e.lstat?a:l;W?this._stat=t=>r(t,{bigint:!0}):this._stat=r,this._maxDepth=null!=e.depth&&Number.isSafeInteger(e.depth)?e.depth:v.depth,this._wantsDir=!!s&&x.has(s),this._wantsFile=!!s&&k.has(s),this._wantsEverything="all"===s,this._root=f(i),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,i=e&&e.files;if(i&&i.length>0){let{path:s,depth:r}=e,a=i.splice(0,t).map(t=>this._formatEntry(t,s));for(let e of(await Promise.all(a))){if(!e)continue;if(this.destroyed)return;let i=await this._getEntryType(e);"directory"===i&&this._directoryFilter(e)?(r<=this._maxDepth&&this.parents.push(this._exploreDir(e.fullPath,r+1)),this._wantsDir&&(this.push(e),t--)):("file"===i||this._includeAsFile(e))&&this._fileFilter(e)&&this._wantsFile&&(this.push(e),t--)}}else{let t=this.parents.pop();if(!t){this.push(null);break}if(this.parent=await t,this.destroyed)return}}}catch(t){this.destroy(t)}finally{this.reading=!1}}}async _exploreDir(t,e){let i;try{i=await n(t,this._rdOptions)}catch(t){this._onError(t)}return{files:i,depth:e,path:t}}async _formatEntry(t,e){let i,s=this._isDirent?t.name:t;try{let r=f(d(e,s));(i={path:c(this._root,r),fullPath:r,basename:s})[this._statsProp]=this._isDirent?t:await this._stat(r)}catch(t){this._onError(t);return}return i}_onError(t){b.has(t.code)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let e=t.fullPath;try{let t=await o(e),i=await a(t);if(i.isFile())return"file";if(i.isDirectory()){let i=t.length;if(e.startsWith(t)&&e.substr(i,1)===m){let i=Error(`Circular symlink detected: "${e}" points to "${t}"`);return i.code=P,this._onError(i)}return"directory"}}catch(t){return this._onError(t),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}}let I=()=>{},R=process.platform,z="win32"===R,j="darwin"===R,C="linux"===R,M="freebsd"===R,T="OS400"===_(),A="all",O="ready",N="add",H="change",U="addDir",L="unlink",$="unlinkDir",q="raw",K="error",V={lstat:a,stat:l},G="listeners",B="errHandlers",J="rawEmitters",Q=[G,B,J],X=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),Y=(t,e)=>{t instanceof Set?t.forEach(e):e(t)},Z=(t,e,i)=>{let s=t[e];s instanceof Set||(t[e]=s=new Set([s])),s.add(i)},tt=(t,e,i)=>{let s=t[e];s instanceof Set?s.delete(i):s===i&&delete t[e]},te=t=>t instanceof Set?0===t.size:!t,ti=new Map;function ts(t,e,i,r,a){try{return s(t,{persistent:e.persistent},(e,s)=>{i(t),a(e,s,{watchedPath:t}),s&&t!==s&&tr(u.resolve(t,s),G,u.join(t,s))})}catch(t){r(t);return}}let tr=(t,e,i,s,r)=>{let a=ti.get(t);a&&Y(a[e],t=>{t(i,s,r)})},ta=new Map;class th{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let s,a=this.fsw.options,n=u.dirname(t),o=u.basename(t);this.fsw._getWatchedDir(n).add(o);let l=u.resolve(t),d={persistent:a.persistent};if(e||(e=I),a.usePolling)d.interval=a.interval!==a.binaryInterval&&X.has(u.extname(o).slice(1).toLowerCase())?a.binaryInterval:a.interval,s=((t,e,s,a)=>{let{listener:h,rawEmitter:n}=a,o=ta.get(e),l=o&&o.options;return l&&(l.persistent<s.persistent||l.interval>s.interval)&&(i(e),o=void 0),o?(Z(o,G,h),Z(o,J,n)):(o={listeners:h,rawEmitters:n,options:s,watcher:r(e,s,(i,s)=>{Y(o.rawEmitters,t=>{t(H,e,{curr:i,prev:s})});let r=i.mtimeMs;(i.size!==s.size||r>s.mtimeMs||0===r)&&Y(o.listeners,e=>e(t,i))})},ta.set(e,o)),()=>{tt(o,G,h),tt(o,J,n),te(o.listeners)&&(ta.delete(e),i(e),o.options=o.watcher=void 0,Object.freeze(o))}})(t,l,d,{listener:e,rawEmitter:this.fsw._emitRaw});else s=((t,e,i,s)=>{let r,{listener:a,errHandler:n,rawEmitter:o}=s,l=ti.get(e);if(!i.persistent){if(!(r=ts(t,i,a,n,o)))return;return r.close.bind(r)}if(l)Z(l,G,a),Z(l,B,n),Z(l,J,o);else{if(!(r=ts(t,i,tr.bind(null,e,G),n,tr.bind(null,e,J))))return;r.on(K,async i=>{let s=tr.bind(null,e,B);if(l&&(l.watcherUnusable=!0),z&&"EPERM"===i.code)try{let e=await h(t,"r");await e.close(),s(i)}catch(t){}else s(i)}),l={listeners:a,errHandlers:n,rawEmitters:o,watcher:r},ti.set(e,l)}return()=>{if(tt(l,G,a),tt(l,B,n),tt(l,J,o),te(l.listeners)){let t;l.watcher.close(),ti.delete(e),Q.forEach((t=l,e=>{let i=t[e];i instanceof Set?i.clear():delete t[e]})),l.watcher=void 0,Object.freeze(l)}}})(t,l,d,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return s}_handleFile(t,e,i){if(this.fsw.closed)return;let s=u.dirname(t),r=u.basename(t),a=this.fsw._getWatchedDir(s),h=e;if(a.has(r))return;let n=async(e,i)=>{if(this.fsw._throttle("watch",t,5))if(i&&0!==i.mtimeMs){if(a.has(r)){let e=i.atimeMs,s=i.mtimeMs;(!e||e<=s||s!==h.mtimeMs)&&this.fsw._emit(H,t,i),h=i}}else try{let i=await l(t);if(this.fsw.closed)return;let s=i.atimeMs,r=i.mtimeMs;if((!s||s<=r||r!==h.mtimeMs)&&this.fsw._emit(H,t,i),(j||C||M)&&h.ino!==i.ino){this.fsw._closeFile(e),h=i;let s=this._watchWithNodeFs(t,n);s&&this.fsw._addPathCloser(e,s)}else h=i}catch(t){this.fsw._remove(s,r)}},o=this._watchWithNodeFs(t,n);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(N,t,0))return;this.fsw._emit(N,t,e)}return o}async _handleSymlink(t,e,i,s){if(this.fsw.closed)return;let r=t.fullPath,a=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){let e;this.fsw._incrReadyCount();try{e=await o(i)}catch(t){return this.fsw._emitReady(),!0}if(this.fsw.closed)return;return a.has(s)?this.fsw._symlinkPaths.get(r)!==e&&(this.fsw._symlinkPaths.set(r,e),this.fsw._emit(H,i,t.stats)):(a.add(s),this.fsw._symlinkPaths.set(r,e),this.fsw._emit(N,i,t.stats)),this.fsw._emitReady(),!0}if(this.fsw._symlinkPaths.has(r))return!0;this.fsw._symlinkPaths.set(r,!0)}_handleRead(t,e,i,s,r,a,h){t=u.join(t,"");let n=s?`${t}:${s}`:t;if(!(h=this.fsw._throttle("readdir",n,1e3)))return;let o=this.fsw._getWatchedDir(i.path),l=new Set,d=this.fsw._readdirp(t,{fileFilter:t=>i.filterPath(t),directoryFilter:t=>i.filterDir(t)});if(d)return d.on("data",async h=>{if(this.fsw.closed){d=void 0;return}let n=h.path,c=u.join(t,n);if(l.add(n),!(h.stats.isSymbolicLink()&&await this._handleSymlink(h,t,c,n))){if(this.fsw.closed){d=void 0;return}n!==s&&(s||o.has(n))||(this.fsw._incrReadyCount(),c=u.join(r,u.relative(r,c)),this._addToNodeFs(c,e,i,a+1))}}).on(K,this._boundHandleError),new Promise((e,n)=>{if(!d)return n();d.once("end",()=>{if(this.fsw.closed){d=void 0;return}let n=!!h&&h.clear();e(void 0),o.getChildren().filter(e=>e!==t&&!l.has(e)).forEach(e=>{this.fsw._remove(t,e)}),d=void 0,n&&this._handleRead(t,!1,i,s,r,a,h)})})}async _handleDir(t,e,i,s,r,a,h){let n,o,l=this.fsw._getWatchedDir(u.dirname(t)),d=l.has(u.basename(t));i&&this.fsw.options.ignoreInitial||r||d||this.fsw._emit(U,t,e),l.add(u.basename(t)),this.fsw._getWatchedDir(t);let c=this.fsw.options.depth;if((null==c||s<=c)&&!this.fsw._symlinkPaths.has(h)){if(!r&&(await this._handleRead(t,i,a,r,t,s,n),this.fsw.closed))return;o=this._watchWithNodeFs(t,(e,i)=>{i&&0===i.mtimeMs||this._handleRead(e,!1,a,r,t,s,n)})}return o}async _addToNodeFs(t,e,i,s,r){let a=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return a(),!1;let h=this.fsw._getWatchHelpers(t);i&&(h.filterPath=t=>i.filterPath(t),h.filterDir=t=>i.filterDir(t));try{let i,n=await V[h.statMethod](h.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(h.watchPath,n))return a(),!1;let l=this.fsw.options.followSymlinks;if(n.isDirectory()){let a=u.resolve(t),d=l?await o(t):t;if(this.fsw.closed||(i=await this._handleDir(h.watchPath,n,e,s,r,h,d),this.fsw.closed))return;a!==d&&void 0!==d&&this.fsw._symlinkPaths.set(a,d)}else if(n.isSymbolicLink()){let r=l?await o(t):t;if(this.fsw.closed)return;let a=u.dirname(h.watchPath);if(this.fsw._getWatchedDir(a).add(h.watchPath),this.fsw._emit(N,h.watchPath,n),i=await this._handleDir(a,n,e,s,t,h,r),this.fsw.closed)return;void 0!==r&&this.fsw._symlinkPaths.set(u.resolve(t),r)}else i=this._handleFile(h.watchPath,n,e);return a(),i&&this.fsw._addPathCloser(t,i),!1}catch(e){if(this.fsw._handleError(e))return a(),t}}}let tn=/\\/g,to=/\/\//g,tl=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,td=/^\.[/\\]/;function tc(t){return Array.isArray(t)?t:[t]}let tf=t=>"object"==typeof t&&null!==t&&!(t instanceof RegExp);function tm(t,e,i){let s=function(t){if("string"!=typeof t)throw Error("string expected");t=(t=u.normalize(t)).replace(/\\/g,"/");let e=!1;return t.startsWith("//")&&(e=!0),t=t.replace(to,"/"),e&&(t="/"+t),t}(e);for(let e=0;e<t.length;e++)if((0,t[e])(s,i))return!0;return!1}let tp=t=>{let e=tc(t).flat();if(!e.every(t=>"string"==typeof t))throw TypeError(`Non-string provided as watch path: ${e}`);return e.map(tu)},t_=t=>{let e=t.replace(tn,"/"),i=!1;return e.startsWith("//")&&(i=!0),e=e.replace(to,"/"),i&&(e="/"+e),e},tu=t=>t_(u.normalize(t_(t))),tw=(t="")=>e=>"string"==typeof e?tu(u.isAbsolute(e)?e:u.join(t,e)):e,tg=Object.freeze(new Set);class ty{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&"."!==t&&".."!==t&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let i=this.path;try{await n(i)}catch(t){this._removeWatcher&&this._removeWatcher(u.dirname(i),u.basename(i))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=I,this.items=tg,Object.freeze(this)}}class tv{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,i){this.fsw=i;let s=t;this.path=t=t.replace(td,""),this.watchPath=s,this.fullWatchPath=u.resolve(s),this.dirParts=[],this.dirParts.forEach(t=>{t.length>1&&t.pop()}),this.followSymlinks=e,this.statMethod=e?"stat":"lstat"}entryPath(t){return u.join(this.watchPath,u.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let i=this.entryPath(t);return this.fsw._isntIgnored(i,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}}class tP extends t{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tc(t.ignored):tc([]),awaitWriteFinish:!0===e?i:"object"==typeof e&&{...i,...e}};T&&(s.usePolling=!0),void 0===s.atomic&&(s.atomic=!s.usePolling);let r=process.env.CHOKIDAR_USEPOLLING;if(void 0!==r){let t=r.toLowerCase();"false"===t||"0"===t?s.usePolling=!1:"true"===t||"1"===t?s.usePolling=!0:s.usePolling=!!t}let a=process.env.CHOKIDAR_INTERVAL;a&&(s.interval=Number.parseInt(a,10));let h=0;this._emitReady=()=>{++h>=this._readyCount&&(this._emitReady=I,this._readyEmitted=!0,process.nextTick(()=>this.emit(O)))},this._emitRaw=(...t)=>this.emit(q,...t),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new th(this),Object.freeze(s)}_addIgnoredPath(t){if(tf(t)){for(let e of this._ignoredPaths)if(tf(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),"string"==typeof t)for(let e of this._ignoredPaths)tf(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,i){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let r=tp(t);return s&&(r=r.map(t=>u.isAbsolute(t)?t:u.join(s,t))),r.forEach(t=>{this._removeIgnoredPath(t)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=r.length,Promise.all(r.map(async t=>{let s=await this._nodeFsHandler._addToNodeFs(t,!i,void 0,0,e);return s&&this._emitReady(),s})).then(t=>{this.closed||t.forEach(t=>{t&&this.add(u.dirname(t),u.basename(e||t))})}),this}unwatch(t){if(this.closed)return this;let e=tp(t),{cwd:i}=this.options;return e.forEach(t=>{u.isAbsolute(t)||this._closers.has(t)||(i&&(t=u.join(i,t)),t=u.resolve(t)),this._closePath(t),this._addIgnoredPath(t),this._watched.has(t)&&this._addIgnoredPath({path:t,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(e=>{let i=e();i instanceof Promise&&t.push(i)})),this._streams.forEach(t=>t.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(t=>t.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,i)=>{t[(this.options.cwd?u.relative(this.options.cwd,i):i)||"."]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==K&&this.emit(A,t,...e)}async _emit(t,e,i){let s;if(this.closed)return;let r=this.options;z&&(e=u.normalize(e)),r.cwd&&(e=u.relative(r.cwd,e));let a=[e];null!=i&&a.push(i);let h=r.awaitWriteFinish;if(h&&(s=this._pendingWrites.get(e)))return s.lastChange=new Date,this;if(r.atomic){if(t===L)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((t,e)=>{this.emit(...t),this.emit(A,...t),this._pendingUnlinks.delete(e)})},"number"==typeof r.atomic?r.atomic:100),this;t===N&&this._pendingUnlinks.has(e)&&(t=H,this._pendingUnlinks.delete(e))}if(h&&(t===N||t===H)&&this._readyEmitted){let i=(e,i)=>{e?(t=K,a[0]=e,this.emitWithAll(t,a)):i&&(a.length>1?a[1]=i:a.push(i),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,h.stabilityThreshold,t,i),this}if(t===H&&!this._throttle(H,e,50))return this;if(r.alwaysStat&&void 0===i&&(t===N||t===U||t===H)){let t,i=r.cwd?u.join(r.cwd,e):e;try{t=await l(i)}catch(t){}if(!t||this.closed)return;a.push(t)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&"ENOENT"!==e&&"ENOTDIR"!==e&&(!this.options.ignorePermissionErrors||"EPERM"!==e&&"EACCES"!==e)&&this.emit(K,t),t||this.closed}_throttle(t,e,i){let s;this._throttled.has(t)||this._throttled.set(t,new Map);let r=this._throttled.get(t);if(!r)throw Error("invalid throttle");let a=r.get(e);if(a)return a.count++,!1;let h=()=>{let t=r.get(e),i=t?t.count:0;return r.delete(e),clearTimeout(s),t&&clearTimeout(t.timeoutObject),i},n={timeoutObject:s=setTimeout(h,i),clear:h,count:0};return r.set(e,n),n}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,i,s,r){let a,h=this.options.awaitWriteFinish;if("object"!=typeof h)return;let n=h.pollInterval,o=t;this.options.cwd&&!u.isAbsolute(t)&&(o=u.join(this.options.cwd,t));let l=new Date,d=this._pendingWrites;d.has(t)||(d.set(t,{lastChange:l,cancelWait:()=>(d.delete(t),clearTimeout(a),s)}),a=setTimeout(function s(h){e(o,(e,o)=>{if(e||!d.has(t)){e&&"ENOENT"!==e.code&&r(e);return}let l=Number(new Date);h&&o.size!==h.size&&(d.get(t).lastChange=l),l-d.get(t).lastChange>=i?(d.delete(t),r(void 0,o)):a=setTimeout(s,n,o)})},n))}_isIgnored(t,e){if(this.options.atomic&&tl.test(t))return!0;if(!this._userIgnored){let{cwd:t}=this.options,e=(this.options.ignored||[]).map(tw(t)),i=[...[...this._ignoredPaths].map(tw(t)),...e];this._userIgnored=function(t,e){if(null==t)throw TypeError("anymatch: specify first argument");let i=tc(t).map(t=>"function"==typeof t?t:"string"==typeof t?e=>t===e:t instanceof RegExp?e=>t.test(e):"object"==typeof t&&null!==t?e=>{if(t.path===e)return!0;if(t.recursive){let i=u.relative(t.path,e);return!!i&&!i.startsWith("..")&&!u.isAbsolute(i)}return!1}:()=>!1);return null==e?(t,e)=>tm(i,t,e):tm(i,e)}(i,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new tv(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=u.resolve(t);return this._watched.has(e)||this._watched.set(e,new ty(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return!!this.options.ignorePermissionErrors||!!(256&Number(t.mode))}_remove(t,e,i){let s=u.join(t,e),r=u.resolve(s);if(i=null!=i?i:this._watched.has(s)||this._watched.has(r),!this._throttle("remove",s,100))return;i||1!==this._watched.size||this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(t=>this._remove(s,t));let a=this._getWatchedDir(t),h=a.has(e);a.remove(e),this._symlinkPaths.has(r)&&this._symlinkPaths.delete(r);let n=s;if(this.options.cwd&&(n=u.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(n)&&this._pendingWrites.get(n).cancelWait()===N)return;this._watched.delete(s),this._watched.delete(r);let o=i?$:L;h&&!this._isIgnored(s)&&this._emit(o,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=u.dirname(t);this._getWatchedDir(e).remove(u.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(t=>t()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let i=this._closers.get(t);i||(i=[],this._closers.set(t,i)),i.push(e)}_readdirp(t,e){if(this.closed)return;let i=function(t,e={}){let i=e.entryType||e.type;if("both"===i&&(i=y),i&&(e.type=i),t){if("string"!=typeof t)throw TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");else if(i&&!E.includes(i))throw Error(`readdirp: Invalid type passed. Use one of ${E.join(", ")}`)}else throw Error("readdirp: root argument is required. Usage: readdirp(root, options)");return e.root=t,new S(e)}(t,{type:A,alwaysStat:!0,lstat:!0,...e,depth:0});return this._streams.add(i),i.once("close",()=>{i=void 0}),i.once("end",()=>{i&&(this._streams.delete(i),i=void 0)}),i}}export default{watch:function(t,e={}){let i=new tP(e);return i.add(t),i},FSWatcher:tP};
|