nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-122334-09c1a7a8
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/dist/_build/common.mjs +763 -0
- package/dist/_build/rolldown.mjs +216 -0
- package/dist/_build/rollup.mjs +359 -0
- package/dist/_build/vite.build.mjs +67 -0
- package/dist/_build/vite.plugin.mjs +762 -0
- package/dist/_chunks/B-7HiF0V.mjs +1303 -0
- package/dist/_chunks/B3asVbT4.mjs +151 -0
- package/dist/_chunks/B5ooyfLk.mjs +372 -0
- package/dist/_chunks/DXMHy5ca.mjs +43 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +675 -0
- package/dist/_libs/acorn.mjs +5034 -0
- package/dist/_libs/c12.mjs +2798 -0
- package/dist/_libs/chokidar.mjs +1560 -0
- package/dist/_libs/citty.mjs +333 -0
- package/dist/_libs/commondir.mjs +22 -0
- package/dist/_libs/compatx.mjs +46 -0
- package/dist/_libs/confbox.mjs +2920 -0
- package/dist/_libs/debug.mjs +848 -0
- package/dist/_libs/deepmerge.mjs +86 -0
- package/dist/_libs/depd.mjs +314 -0
- package/dist/_libs/dot-prop.mjs +138 -0
- package/dist/_libs/duplexer.mjs +71 -0
- package/dist/_libs/ee-first.mjs +68 -0
- package/dist/_libs/encodeurl.mjs +49 -0
- package/dist/_libs/escape-html.mjs +58 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +330 -0
- package/dist/_libs/etag.mjs +75 -0
- package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
- package/dist/_libs/fresh.mjs +85 -0
- package/dist/_libs/function-bind.mjs +63 -0
- package/dist/_libs/gen-mapping.mjs +612 -0
- package/dist/_libs/giget.mjs +19076 -0
- package/dist/_libs/gzip-size.mjs +21 -0
- package/dist/_libs/hasown.mjs +14 -0
- package/dist/_libs/http-errors.mjs +436 -0
- package/dist/_libs/httpxy.mjs +410 -0
- package/dist/_libs/is-core-module.mjs +220 -0
- package/dist/_libs/is-module.mjs +13 -0
- package/dist/_libs/is-reference.mjs +32 -0
- package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
- package/dist/_libs/klona.mjs +90 -0
- package/dist/_libs/knitwork.mjs +124 -0
- package/dist/_libs/local-pkg.mjs +1686 -0
- package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
- package/dist/_libs/mime-db.mjs +7642 -0
- package/dist/_libs/mime-types.mjs +162 -0
- package/dist/_libs/mime.mjs +1391 -0
- package/dist/_libs/node-fetch-native.mjs +173 -0
- package/dist/_libs/on-finished.mjs +170 -0
- package/dist/_libs/parseurl.mjs +103 -0
- package/dist/_libs/path-parse.mjs +47 -0
- package/dist/_libs/pathe.mjs +41 -0
- package/dist/_libs/picomatch.mjs +1673 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-commonjs.mjs +1489 -0
- package/dist/_libs/plugin-inject.mjs +135 -0
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/plugin-node-resolve.mjs +1553 -0
- package/dist/_libs/plugin-replace.mjs +104 -0
- package/dist/_libs/pretty-bytes.mjs +116 -0
- package/dist/_libs/range-parser.mjs +102 -0
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
- package/dist/_libs/send.mjs +857 -0
- package/dist/_libs/serve-static.mjs +124 -0
- package/dist/_libs/std-env.mjs +158 -0
- package/dist/_libs/strip-literal.mjs +51 -0
- package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/unimport.mjs +3520 -0
- package/dist/_libs/untyped.mjs +271 -0
- package/dist/_libs/unwasm.mjs +5825 -0
- package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
- package/dist/_presets.mjs +1723 -0
- package/dist/builder.d.mts +37 -35
- package/dist/builder.mjs +45 -117
- package/dist/cli/_chunks/build.mjs +43 -0
- package/dist/cli/_chunks/common.mjs +15 -0
- package/dist/cli/_chunks/detect-acorn.mjs +12 -0
- package/dist/cli/_chunks/dev.mjs +79 -0
- package/dist/cli/_chunks/dist.mjs +3 -0
- package/dist/cli/_chunks/dist2.mjs +4 -0
- package/dist/cli/_chunks/esm.mjs +3 -0
- package/dist/cli/_chunks/json5.mjs +4 -0
- package/dist/cli/_chunks/jsonc.mjs +4 -0
- package/dist/cli/_chunks/list.mjs +27 -0
- package/dist/cli/_chunks/multipart-parser.mjs +6 -0
- package/dist/cli/_chunks/prepare.mjs +19 -0
- package/dist/cli/_chunks/run.mjs +55 -0
- package/dist/cli/_chunks/task.mjs +16 -0
- package/dist/cli/_chunks/toml.mjs +4 -0
- package/dist/cli/_chunks/yaml.mjs +4 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +19 -18
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
- package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
- package/dist/presets/azure/runtime/_utils.mjs +43 -43
- package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
- package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
- package/dist/presets/bun/runtime/bun.d.mts +1 -0
- package/dist/presets/bun/runtime/bun.mjs +18 -17
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
- package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
- package/dist/presets/deno/runtime/deno-server.mjs +31 -39
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
- package/dist/presets/netlify/runtime/netlify.mjs +11 -17
- package/dist/presets/node/runtime/node-cluster.mjs +49 -48
- package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
- package/dist/presets/node/runtime/node-middleware.mjs +7 -6
- package/dist/presets/node/runtime/node-server.mjs +33 -23
- package/dist/presets/standard/runtime/server.d.mts +1 -3
- package/dist/presets/standard/runtime/server.mjs +1 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
- package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
- package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
- package/dist/presets/vercel/runtime/vercel.mjs +15 -14
- package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/runtime/index.d.mts +12 -1
- package/dist/runtime/index.mjs +12 -7
- package/dist/runtime/internal/app.mjs +175 -162
- package/dist/runtime/internal/cache.d.mts +10 -4
- package/dist/runtime/internal/cache.mjs +247 -216
- package/dist/runtime/internal/context.d.mts +9 -9
- package/dist/runtime/internal/context.mjs +17 -10
- package/dist/runtime/internal/database.mjs +8 -10
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +106 -105
- package/dist/runtime/internal/error/prod.d.mts +2 -2
- package/dist/runtime/internal/error/prod.mjs +48 -52
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/error/utils.mjs +1 -1
- package/dist/runtime/internal/index.d.mts +2 -0
- package/dist/runtime/internal/index.mjs +2 -0
- package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
- package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/meta.mjs +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/plugin.mjs +1 -1
- package/dist/runtime/internal/renderer.mjs +39 -31
- package/dist/runtime/internal/route-rules.d.mts +8 -8
- package/dist/runtime/internal/route-rules.mjs +53 -51
- package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
- package/dist/runtime/internal/routes/openapi.d.mts +1 -0
- package/dist/runtime/internal/routes/openapi.mjs +81 -87
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +1 -0
- package/dist/runtime/internal/routes/scalar.mjs +22 -23
- package/dist/runtime/internal/routes/swagger.d.mts +1 -0
- package/dist/runtime/internal/routes/swagger.mjs +9 -11
- package/dist/runtime/internal/runtime-config.d.mts +4 -4
- package/dist/runtime/internal/runtime-config.mjs +40 -35
- package/dist/runtime/internal/shutdown.d.mts +2 -7
- package/dist/runtime/internal/shutdown.mjs +30 -29
- package/dist/runtime/internal/static.mjs +63 -74
- package/dist/runtime/internal/storage.mjs +2 -2
- package/dist/runtime/internal/task.d.mts +6 -6
- package/dist/runtime/internal/task.mjs +56 -59
- package/dist/runtime/internal/utils.d.mts +1 -1
- package/dist/runtime/internal/utils.mjs +4 -10
- package/dist/types/index.d.mts +2566 -3851
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +61 -51
- package/dist/vite.mjs +55 -132
- package/package.json +10 -10
- package/dist/_build/build.mjs +0 -368
- package/dist/_build/build2.mjs +0 -556
- package/dist/_build/info.mjs +0 -1002
- package/dist/_build/prepare.mjs +0 -1511
- package/dist/_build/snapshot.mjs +0 -185
- package/dist/_build/vite.mjs +0 -959
- package/dist/_build/vite2.mjs +0 -149
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
- package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
- package/dist/_chunks/_deps/acorn.mjs +0 -6225
- package/dist/_chunks/_deps/c12.mjs +0 -510
- package/dist/_chunks/_deps/chokidar.mjs +0 -1428
- package/dist/_chunks/_deps/citty.mjs +0 -460
- package/dist/_chunks/_deps/commondir.mjs +0 -77
- package/dist/_chunks/_deps/compatx.mjs +0 -76
- package/dist/_chunks/_deps/confbox.mjs +0 -300
- package/dist/_chunks/_deps/debug.mjs +0 -885
- package/dist/_chunks/_deps/deepmerge.mjs +0 -147
- package/dist/_chunks/_deps/depd.mjs +0 -550
- package/dist/_chunks/_deps/dot-prop.mjs +0 -282
- package/dist/_chunks/_deps/dotenv.mjs +0 -555
- package/dist/_chunks/_deps/duplexer.mjs +0 -1
- package/dist/_chunks/_deps/ee-first.mjs +0 -104
- package/dist/_chunks/_deps/encodeurl.mjs +0 -69
- package/dist/_chunks/_deps/escape-html.mjs +0 -87
- package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
- package/dist/_chunks/_deps/estree-walker.mjs +0 -433
- package/dist/_chunks/_deps/etag.mjs +0 -147
- package/dist/_chunks/_deps/exsolve.mjs +0 -1416
- package/dist/_chunks/_deps/fresh.mjs +0 -145
- package/dist/_chunks/_deps/function-bind.mjs +0 -106
- package/dist/_chunks/_deps/giget.mjs +0 -451
- package/dist/_chunks/_deps/gzip-size.mjs +0 -19
- package/dist/_chunks/_deps/hasown.mjs +0 -19
- package/dist/_chunks/_deps/http-errors.mjs +0 -307
- package/dist/_chunks/_deps/httpxy.mjs +0 -580
- package/dist/_chunks/_deps/inherits.mjs +0 -57
- package/dist/_chunks/_deps/is-core-module.mjs +0 -596
- package/dist/_chunks/_deps/is-module.mjs +0 -25
- package/dist/_chunks/_deps/is-reference.mjs +0 -31
- package/dist/_chunks/_deps/klona.mjs +0 -137
- package/dist/_chunks/_deps/knitwork.mjs +0 -172
- package/dist/_chunks/_deps/local-pkg.mjs +0 -163
- package/dist/_chunks/_deps/mime-db.mjs +0 -11685
- package/dist/_chunks/_deps/mime-types.mjs +0 -287
- package/dist/_chunks/_deps/mime.mjs +0 -1172
- package/dist/_chunks/_deps/mlly.mjs +0 -2413
- package/dist/_chunks/_deps/ms.mjs +0 -172
- package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
- package/dist/_chunks/_deps/nypm.mjs +0 -219
- package/dist/_chunks/_deps/on-finished.mjs +0 -246
- package/dist/_chunks/_deps/parseurl.mjs +0 -168
- package/dist/_chunks/_deps/path-parse.mjs +0 -85
- package/dist/_chunks/_deps/pathe.mjs +0 -251
- package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
- package/dist/_chunks/_deps/picomatch.mjs +0 -2144
- package/dist/_chunks/_deps/pkg-types.mjs +0 -247
- package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
- package/dist/_chunks/_deps/quansync.mjs +0 -99
- package/dist/_chunks/_deps/range-parser.mjs +0 -171
- package/dist/_chunks/_deps/rc9.mjs +0 -219
- package/dist/_chunks/_deps/readdirp.mjs +0 -245
- package/dist/_chunks/_deps/resolve.mjs +0 -1260
- package/dist/_chunks/_deps/send.mjs +0 -1022
- package/dist/_chunks/_deps/serve-static.mjs +0 -228
- package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
- package/dist/_chunks/_deps/statuses.mjs +0 -457
- package/dist/_chunks/_deps/std-env.mjs +0 -3
- package/dist/_chunks/_deps/strip-literal.mjs +0 -67
- package/dist/_chunks/_deps/supports-color.mjs +0 -44
- package/dist/_chunks/_deps/tinyexec.mjs +0 -552
- package/dist/_chunks/_deps/toidentifier.mjs +0 -41
- package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
- package/dist/_chunks/_deps/unimport.mjs +0 -2267
- package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
- package/dist/_chunks/_deps/unplugin.mjs +0 -1294
- package/dist/_chunks/_deps/untyped.mjs +0 -375
- package/dist/_chunks/_deps/unwasm.mjs +0 -6959
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
- package/dist/_chunks/_presets/_all.mjs +0 -59
- package/dist/_chunks/_presets/_nitro.mjs +0 -74
- package/dist/_chunks/_presets/_resolve.mjs +0 -64
- package/dist/_chunks/_presets/_static.mjs +0 -69
- package/dist/_chunks/_presets/_types.mjs +0 -3
- package/dist/_chunks/_presets/_utils.mjs +0 -31
- package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
- package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
- package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
- package/dist/_chunks/_presets/azure.mjs +0 -162
- package/dist/_chunks/_presets/bun.mjs +0 -19
- package/dist/_chunks/_presets/cleavr.mjs +0 -15
- package/dist/_chunks/_presets/cloudflare.mjs +0 -608
- package/dist/_chunks/_presets/deno.mjs +0 -196
- package/dist/_chunks/_presets/digitalocean.mjs +0 -14
- package/dist/_chunks/_presets/firebase.mjs +0 -47
- package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
- package/dist/_chunks/_presets/genezio.mjs +0 -13
- package/dist/_chunks/_presets/heroku.mjs +0 -14
- package/dist/_chunks/_presets/iis.mjs +0 -194
- package/dist/_chunks/_presets/index.mjs +0 -62
- package/dist/_chunks/_presets/koyeb.mjs +0 -14
- package/dist/_chunks/_presets/netlify.mjs +0 -241
- package/dist/_chunks/_presets/node.mjs +0 -54
- package/dist/_chunks/_presets/platform.mjs +0 -14
- package/dist/_chunks/_presets/render.mjs +0 -14
- package/dist/_chunks/_presets/standard.mjs +0 -23
- package/dist/_chunks/_presets/stormkit.mjs +0 -18
- package/dist/_chunks/_presets/vercel.mjs +0 -375
- package/dist/_chunks/_presets/winterjs.mjs +0 -22
- package/dist/_chunks/_presets/zeabur.mjs +0 -69
- package/dist/_chunks/_presets/zerops.mjs +0 -27
- package/dist/_chunks/app.mjs +0 -600
- package/dist/_chunks/builder.mjs +0 -648
- package/dist/_chunks/server.mjs +0 -256
- package/dist/_cli/build.mjs +0 -49
- package/dist/_cli/common.mjs +0 -13
- package/dist/_cli/dev.mjs +0 -121
- package/dist/_cli/index.mjs +0 -16
- package/dist/_cli/list.mjs +0 -33
- package/dist/_cli/prepare.mjs +0 -23
- package/dist/_cli/run.mjs +0 -59
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
- package/dist/runtime/internal/empty.d.mts +0 -0
- package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
- package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
- package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
- /package/lib/{indexd.mts → index.d.mts} +0 -0
|
@@ -1,1428 +0,0 @@
|
|
|
1
|
-
import { unwatchFile, watchFile, watch as watch$1, stat as stat$1 } from 'fs';
|
|
2
|
-
import { realpath, stat, lstat, open, readdir } from 'fs/promises';
|
|
3
|
-
import { EventEmitter } from 'events';
|
|
4
|
-
import * as sysPath from 'path';
|
|
5
|
-
import { r as readdirp } from './readdirp.mjs';
|
|
6
|
-
import { type } from 'os';
|
|
7
|
-
import 'node:fs/promises';
|
|
8
|
-
import 'node:stream';
|
|
9
|
-
import 'node:path';
|
|
10
|
-
|
|
11
|
-
const STR_DATA = 'data';
|
|
12
|
-
const STR_END = 'end';
|
|
13
|
-
const STR_CLOSE = 'close';
|
|
14
|
-
const EMPTY_FN = () => { };
|
|
15
|
-
const pl = process.platform;
|
|
16
|
-
const isWindows = pl === 'win32';
|
|
17
|
-
const isMacos = pl === 'darwin';
|
|
18
|
-
const isLinux = pl === 'linux';
|
|
19
|
-
const isFreeBSD = pl === 'freebsd';
|
|
20
|
-
const isIBMi = type() === 'OS400';
|
|
21
|
-
const EVENTS = {
|
|
22
|
-
ALL: 'all',
|
|
23
|
-
READY: 'ready',
|
|
24
|
-
ADD: 'add',
|
|
25
|
-
CHANGE: 'change',
|
|
26
|
-
ADD_DIR: 'addDir',
|
|
27
|
-
UNLINK: 'unlink',
|
|
28
|
-
UNLINK_DIR: 'unlinkDir',
|
|
29
|
-
RAW: 'raw',
|
|
30
|
-
ERROR: 'error',
|
|
31
|
-
};
|
|
32
|
-
const EV = EVENTS;
|
|
33
|
-
const THROTTLE_MODE_WATCH = 'watch';
|
|
34
|
-
const statMethods = { lstat, stat };
|
|
35
|
-
const KEY_LISTENERS = 'listeners';
|
|
36
|
-
const KEY_ERR = 'errHandlers';
|
|
37
|
-
const KEY_RAW = 'rawEmitters';
|
|
38
|
-
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
39
|
-
// prettier-ignore
|
|
40
|
-
const binaryExtensions = new Set([
|
|
41
|
-
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
|
42
|
-
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
|
43
|
-
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
|
44
|
-
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
|
45
|
-
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
|
46
|
-
'dtshd', 'dvb', 'dwg', 'dxf',
|
|
47
|
-
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
|
48
|
-
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
|
49
|
-
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
|
50
|
-
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
|
51
|
-
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
|
52
|
-
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
|
53
|
-
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
|
54
|
-
'mobi', 'mov', 'movie', 'mp3',
|
|
55
|
-
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
|
56
|
-
'nef', 'npx', 'numbers', 'nupkg',
|
|
57
|
-
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
|
58
|
-
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
|
59
|
-
'potx', 'ppa', 'ppam',
|
|
60
|
-
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
|
61
|
-
'qt',
|
|
62
|
-
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
|
63
|
-
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
|
64
|
-
'stl', 'suo', 'sub', 'swf',
|
|
65
|
-
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
|
66
|
-
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
|
67
|
-
'viv', 'vob',
|
|
68
|
-
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
|
69
|
-
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
|
70
|
-
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
|
71
|
-
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
|
72
|
-
'z', 'zip', 'zipx',
|
|
73
|
-
]);
|
|
74
|
-
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
|
75
|
-
// TODO: emit errors properly. Example: EMFILE on Macos.
|
|
76
|
-
const foreach = (val, fn) => {
|
|
77
|
-
if (val instanceof Set) {
|
|
78
|
-
val.forEach(fn);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
fn(val);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const addAndConvert = (main, prop, item) => {
|
|
85
|
-
let container = main[prop];
|
|
86
|
-
if (!(container instanceof Set)) {
|
|
87
|
-
main[prop] = container = new Set([container]);
|
|
88
|
-
}
|
|
89
|
-
container.add(item);
|
|
90
|
-
};
|
|
91
|
-
const clearItem = (cont) => (key) => {
|
|
92
|
-
const set = cont[key];
|
|
93
|
-
if (set instanceof Set) {
|
|
94
|
-
set.clear();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
delete cont[key];
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const delFromSet = (main, prop, item) => {
|
|
101
|
-
const container = main[prop];
|
|
102
|
-
if (container instanceof Set) {
|
|
103
|
-
container.delete(item);
|
|
104
|
-
}
|
|
105
|
-
else if (container === item) {
|
|
106
|
-
delete main[prop];
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
|
110
|
-
const FsWatchInstances = new Map();
|
|
111
|
-
/**
|
|
112
|
-
* Instantiates the fs_watch interface
|
|
113
|
-
* @param path to be watched
|
|
114
|
-
* @param options to be passed to fs_watch
|
|
115
|
-
* @param listener main event handler
|
|
116
|
-
* @param errHandler emits info about errors
|
|
117
|
-
* @param emitRaw emits raw event data
|
|
118
|
-
* @returns {NativeFsWatcher}
|
|
119
|
-
*/
|
|
120
|
-
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
121
|
-
const handleEvent = (rawEvent, evPath) => {
|
|
122
|
-
listener(path);
|
|
123
|
-
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
124
|
-
// emit based on events occurring for files from a directory's watcher in
|
|
125
|
-
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
|
126
|
-
if (evPath && path !== evPath) {
|
|
127
|
-
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
try {
|
|
131
|
-
return watch$1(path, {
|
|
132
|
-
persistent: options.persistent,
|
|
133
|
-
}, handleEvent);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
errHandler(error);
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Helper for passing fs_watch event data to a collection of listeners
|
|
142
|
-
* @param fullPath absolute path bound to fs_watch instance
|
|
143
|
-
*/
|
|
144
|
-
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
145
|
-
const cont = FsWatchInstances.get(fullPath);
|
|
146
|
-
if (!cont)
|
|
147
|
-
return;
|
|
148
|
-
foreach(cont[listenerType], (listener) => {
|
|
149
|
-
listener(val1, val2, val3);
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Instantiates the fs_watch interface or binds listeners
|
|
154
|
-
* to an existing one covering the same file system entry
|
|
155
|
-
* @param path
|
|
156
|
-
* @param fullPath absolute path
|
|
157
|
-
* @param options to be passed to fs_watch
|
|
158
|
-
* @param handlers container for event listener functions
|
|
159
|
-
*/
|
|
160
|
-
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
161
|
-
const { listener, errHandler, rawEmitter } = handlers;
|
|
162
|
-
let cont = FsWatchInstances.get(fullPath);
|
|
163
|
-
let watcher;
|
|
164
|
-
if (!options.persistent) {
|
|
165
|
-
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
166
|
-
if (!watcher)
|
|
167
|
-
return;
|
|
168
|
-
return watcher.close.bind(watcher);
|
|
169
|
-
}
|
|
170
|
-
if (cont) {
|
|
171
|
-
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
172
|
-
addAndConvert(cont, KEY_ERR, errHandler);
|
|
173
|
-
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
|
177
|
-
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
|
178
|
-
if (!watcher)
|
|
179
|
-
return;
|
|
180
|
-
watcher.on(EV.ERROR, async (error) => {
|
|
181
|
-
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
182
|
-
if (cont)
|
|
183
|
-
cont.watcherUnusable = true; // documented since Node 10.4.1
|
|
184
|
-
// Workaround for https://github.com/joyent/node/issues/4337
|
|
185
|
-
if (isWindows && error.code === 'EPERM') {
|
|
186
|
-
try {
|
|
187
|
-
const fd = await open(path, 'r');
|
|
188
|
-
await fd.close();
|
|
189
|
-
broadcastErr(error);
|
|
190
|
-
}
|
|
191
|
-
catch (err) {
|
|
192
|
-
// do nothing
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
broadcastErr(error);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
cont = {
|
|
200
|
-
listeners: listener,
|
|
201
|
-
errHandlers: errHandler,
|
|
202
|
-
rawEmitters: rawEmitter,
|
|
203
|
-
watcher,
|
|
204
|
-
};
|
|
205
|
-
FsWatchInstances.set(fullPath, cont);
|
|
206
|
-
}
|
|
207
|
-
// const index = cont.listeners.indexOf(listener);
|
|
208
|
-
// removes this instance's listeners and closes the underlying fs_watch
|
|
209
|
-
// instance if there are no more listeners left
|
|
210
|
-
return () => {
|
|
211
|
-
delFromSet(cont, KEY_LISTENERS, listener);
|
|
212
|
-
delFromSet(cont, KEY_ERR, errHandler);
|
|
213
|
-
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
214
|
-
if (isEmptySet(cont.listeners)) {
|
|
215
|
-
// Check to protect against issue gh-730.
|
|
216
|
-
// if (cont.watcherUnusable) {
|
|
217
|
-
cont.watcher.close();
|
|
218
|
-
// }
|
|
219
|
-
FsWatchInstances.delete(fullPath);
|
|
220
|
-
HANDLER_KEYS.forEach(clearItem(cont));
|
|
221
|
-
// @ts-ignore
|
|
222
|
-
cont.watcher = undefined;
|
|
223
|
-
Object.freeze(cont);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
// fs_watchFile helpers
|
|
228
|
-
// object to hold per-process fs_watchFile instances
|
|
229
|
-
// (may be shared across chokidar FSWatcher instances)
|
|
230
|
-
const FsWatchFileInstances = new Map();
|
|
231
|
-
/**
|
|
232
|
-
* Instantiates the fs_watchFile interface or binds listeners
|
|
233
|
-
* to an existing one covering the same file system entry
|
|
234
|
-
* @param path to be watched
|
|
235
|
-
* @param fullPath absolute path
|
|
236
|
-
* @param options options to be passed to fs_watchFile
|
|
237
|
-
* @param handlers container for event listener functions
|
|
238
|
-
* @returns closer
|
|
239
|
-
*/
|
|
240
|
-
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
241
|
-
const { listener, rawEmitter } = handlers;
|
|
242
|
-
let cont = FsWatchFileInstances.get(fullPath);
|
|
243
|
-
// let listeners = new Set();
|
|
244
|
-
// let rawEmitters = new Set();
|
|
245
|
-
const copts = cont && cont.options;
|
|
246
|
-
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
247
|
-
// "Upgrade" the watcher to persistence or a quicker interval.
|
|
248
|
-
// This creates some unlikely edge case issues if the user mixes
|
|
249
|
-
// settings in a very weird way, but solving for those cases
|
|
250
|
-
// doesn't seem worthwhile for the added complexity.
|
|
251
|
-
// listeners = cont.listeners;
|
|
252
|
-
// rawEmitters = cont.rawEmitters;
|
|
253
|
-
unwatchFile(fullPath);
|
|
254
|
-
cont = undefined;
|
|
255
|
-
}
|
|
256
|
-
if (cont) {
|
|
257
|
-
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
258
|
-
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
// TODO
|
|
262
|
-
// listeners.add(listener);
|
|
263
|
-
// rawEmitters.add(rawEmitter);
|
|
264
|
-
cont = {
|
|
265
|
-
listeners: listener,
|
|
266
|
-
rawEmitters: rawEmitter,
|
|
267
|
-
options,
|
|
268
|
-
watcher: watchFile(fullPath, options, (curr, prev) => {
|
|
269
|
-
foreach(cont.rawEmitters, (rawEmitter) => {
|
|
270
|
-
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
|
271
|
-
});
|
|
272
|
-
const currmtime = curr.mtimeMs;
|
|
273
|
-
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
274
|
-
foreach(cont.listeners, (listener) => listener(path, curr));
|
|
275
|
-
}
|
|
276
|
-
}),
|
|
277
|
-
};
|
|
278
|
-
FsWatchFileInstances.set(fullPath, cont);
|
|
279
|
-
}
|
|
280
|
-
// const index = cont.listeners.indexOf(listener);
|
|
281
|
-
// Removes this instance's listeners and closes the underlying fs_watchFile
|
|
282
|
-
// instance if there are no more listeners left.
|
|
283
|
-
return () => {
|
|
284
|
-
delFromSet(cont, KEY_LISTENERS, listener);
|
|
285
|
-
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
286
|
-
if (isEmptySet(cont.listeners)) {
|
|
287
|
-
FsWatchFileInstances.delete(fullPath);
|
|
288
|
-
unwatchFile(fullPath);
|
|
289
|
-
cont.options = cont.watcher = undefined;
|
|
290
|
-
Object.freeze(cont);
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
/**
|
|
295
|
-
* @mixin
|
|
296
|
-
*/
|
|
297
|
-
class NodeFsHandler {
|
|
298
|
-
constructor(fsW) {
|
|
299
|
-
this.fsw = fsW;
|
|
300
|
-
this._boundHandleError = (error) => fsW._handleError(error);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Watch file for changes with fs_watchFile or fs_watch.
|
|
304
|
-
* @param path to file or dir
|
|
305
|
-
* @param listener on fs change
|
|
306
|
-
* @returns closer for the watcher instance
|
|
307
|
-
*/
|
|
308
|
-
_watchWithNodeFs(path, listener) {
|
|
309
|
-
const opts = this.fsw.options;
|
|
310
|
-
const directory = sysPath.dirname(path);
|
|
311
|
-
const basename = sysPath.basename(path);
|
|
312
|
-
const parent = this.fsw._getWatchedDir(directory);
|
|
313
|
-
parent.add(basename);
|
|
314
|
-
const absolutePath = sysPath.resolve(path);
|
|
315
|
-
const options = {
|
|
316
|
-
persistent: opts.persistent,
|
|
317
|
-
};
|
|
318
|
-
if (!listener)
|
|
319
|
-
listener = EMPTY_FN;
|
|
320
|
-
let closer;
|
|
321
|
-
if (opts.usePolling) {
|
|
322
|
-
const enableBin = opts.interval !== opts.binaryInterval;
|
|
323
|
-
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
|
324
|
-
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
325
|
-
listener,
|
|
326
|
-
rawEmitter: this.fsw._emitRaw,
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
closer = setFsWatchListener(path, absolutePath, options, {
|
|
331
|
-
listener,
|
|
332
|
-
errHandler: this._boundHandleError,
|
|
333
|
-
rawEmitter: this.fsw._emitRaw,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
return closer;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Watch a file and emit add event if warranted.
|
|
340
|
-
* @returns closer for the watcher instance
|
|
341
|
-
*/
|
|
342
|
-
_handleFile(file, stats, initialAdd) {
|
|
343
|
-
if (this.fsw.closed) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
const dirname = sysPath.dirname(file);
|
|
347
|
-
const basename = sysPath.basename(file);
|
|
348
|
-
const parent = this.fsw._getWatchedDir(dirname);
|
|
349
|
-
// stats is always present
|
|
350
|
-
let prevStats = stats;
|
|
351
|
-
// if the file is already being watched, do nothing
|
|
352
|
-
if (parent.has(basename))
|
|
353
|
-
return;
|
|
354
|
-
const listener = async (path, newStats) => {
|
|
355
|
-
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
356
|
-
return;
|
|
357
|
-
if (!newStats || newStats.mtimeMs === 0) {
|
|
358
|
-
try {
|
|
359
|
-
const newStats = await stat(file);
|
|
360
|
-
if (this.fsw.closed)
|
|
361
|
-
return;
|
|
362
|
-
// Check that change event was not fired because of changed only accessTime.
|
|
363
|
-
const at = newStats.atimeMs;
|
|
364
|
-
const mt = newStats.mtimeMs;
|
|
365
|
-
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
366
|
-
this.fsw._emit(EV.CHANGE, file, newStats);
|
|
367
|
-
}
|
|
368
|
-
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
|
369
|
-
this.fsw._closeFile(path);
|
|
370
|
-
prevStats = newStats;
|
|
371
|
-
const closer = this._watchWithNodeFs(file, listener);
|
|
372
|
-
if (closer)
|
|
373
|
-
this.fsw._addPathCloser(path, closer);
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
prevStats = newStats;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
catch (error) {
|
|
380
|
-
// Fix issues where mtime is null but file is still present
|
|
381
|
-
this.fsw._remove(dirname, basename);
|
|
382
|
-
}
|
|
383
|
-
// add is about to be emitted if file not already tracked in parent
|
|
384
|
-
}
|
|
385
|
-
else if (parent.has(basename)) {
|
|
386
|
-
// Check that change event was not fired because of changed only accessTime.
|
|
387
|
-
const at = newStats.atimeMs;
|
|
388
|
-
const mt = newStats.mtimeMs;
|
|
389
|
-
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
390
|
-
this.fsw._emit(EV.CHANGE, file, newStats);
|
|
391
|
-
}
|
|
392
|
-
prevStats = newStats;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
// kick off the watcher
|
|
396
|
-
const closer = this._watchWithNodeFs(file, listener);
|
|
397
|
-
// emit an add event if we're supposed to
|
|
398
|
-
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
399
|
-
if (!this.fsw._throttle(EV.ADD, file, 0))
|
|
400
|
-
return;
|
|
401
|
-
this.fsw._emit(EV.ADD, file, stats);
|
|
402
|
-
}
|
|
403
|
-
return closer;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Handle symlinks encountered while reading a dir.
|
|
407
|
-
* @param entry returned by readdirp
|
|
408
|
-
* @param directory path of dir being read
|
|
409
|
-
* @param path of this item
|
|
410
|
-
* @param item basename of this item
|
|
411
|
-
* @returns true if no more processing is needed for this entry.
|
|
412
|
-
*/
|
|
413
|
-
async _handleSymlink(entry, directory, path, item) {
|
|
414
|
-
if (this.fsw.closed) {
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
const full = entry.fullPath;
|
|
418
|
-
const dir = this.fsw._getWatchedDir(directory);
|
|
419
|
-
if (!this.fsw.options.followSymlinks) {
|
|
420
|
-
// watch symlink directly (don't follow) and detect changes
|
|
421
|
-
this.fsw._incrReadyCount();
|
|
422
|
-
let linkPath;
|
|
423
|
-
try {
|
|
424
|
-
linkPath = await realpath(path);
|
|
425
|
-
}
|
|
426
|
-
catch (e) {
|
|
427
|
-
this.fsw._emitReady();
|
|
428
|
-
return true;
|
|
429
|
-
}
|
|
430
|
-
if (this.fsw.closed)
|
|
431
|
-
return;
|
|
432
|
-
if (dir.has(item)) {
|
|
433
|
-
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
434
|
-
this.fsw._symlinkPaths.set(full, linkPath);
|
|
435
|
-
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
dir.add(item);
|
|
440
|
-
this.fsw._symlinkPaths.set(full, linkPath);
|
|
441
|
-
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
442
|
-
}
|
|
443
|
-
this.fsw._emitReady();
|
|
444
|
-
return true;
|
|
445
|
-
}
|
|
446
|
-
// don't follow the same symlink more than once
|
|
447
|
-
if (this.fsw._symlinkPaths.has(full)) {
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
this.fsw._symlinkPaths.set(full, true);
|
|
451
|
-
}
|
|
452
|
-
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
453
|
-
// Normalize the directory name on Windows
|
|
454
|
-
directory = sysPath.join(directory, '');
|
|
455
|
-
throttler = this.fsw._throttle('readdir', directory, 1000);
|
|
456
|
-
if (!throttler)
|
|
457
|
-
return;
|
|
458
|
-
const previous = this.fsw._getWatchedDir(wh.path);
|
|
459
|
-
const current = new Set();
|
|
460
|
-
let stream = this.fsw._readdirp(directory, {
|
|
461
|
-
fileFilter: (entry) => wh.filterPath(entry),
|
|
462
|
-
directoryFilter: (entry) => wh.filterDir(entry),
|
|
463
|
-
});
|
|
464
|
-
if (!stream)
|
|
465
|
-
return;
|
|
466
|
-
stream
|
|
467
|
-
.on(STR_DATA, async (entry) => {
|
|
468
|
-
if (this.fsw.closed) {
|
|
469
|
-
stream = undefined;
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
const item = entry.path;
|
|
473
|
-
let path = sysPath.join(directory, item);
|
|
474
|
-
current.add(item);
|
|
475
|
-
if (entry.stats.isSymbolicLink() &&
|
|
476
|
-
(await this._handleSymlink(entry, directory, path, item))) {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
if (this.fsw.closed) {
|
|
480
|
-
stream = undefined;
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
// Files that present in current directory snapshot
|
|
484
|
-
// but absent in previous are added to watch list and
|
|
485
|
-
// emit `add` event.
|
|
486
|
-
if (item === target || (!target && !previous.has(item))) {
|
|
487
|
-
this.fsw._incrReadyCount();
|
|
488
|
-
// ensure relativeness of path is preserved in case of watcher reuse
|
|
489
|
-
path = sysPath.join(dir, sysPath.relative(dir, path));
|
|
490
|
-
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
491
|
-
}
|
|
492
|
-
})
|
|
493
|
-
.on(EV.ERROR, this._boundHandleError);
|
|
494
|
-
return new Promise((resolve, reject) => {
|
|
495
|
-
if (!stream)
|
|
496
|
-
return reject();
|
|
497
|
-
stream.once(STR_END, () => {
|
|
498
|
-
if (this.fsw.closed) {
|
|
499
|
-
stream = undefined;
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
const wasThrottled = throttler ? throttler.clear() : false;
|
|
503
|
-
resolve(undefined);
|
|
504
|
-
// Files that absent in current directory snapshot
|
|
505
|
-
// but present in previous emit `remove` event
|
|
506
|
-
// and are removed from @watched[directory].
|
|
507
|
-
previous
|
|
508
|
-
.getChildren()
|
|
509
|
-
.filter((item) => {
|
|
510
|
-
return item !== directory && !current.has(item);
|
|
511
|
-
})
|
|
512
|
-
.forEach((item) => {
|
|
513
|
-
this.fsw._remove(directory, item);
|
|
514
|
-
});
|
|
515
|
-
stream = undefined;
|
|
516
|
-
// one more time for any missed in case changes came in extremely quickly
|
|
517
|
-
if (wasThrottled)
|
|
518
|
-
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
524
|
-
* @param dir fs path
|
|
525
|
-
* @param stats
|
|
526
|
-
* @param initialAdd
|
|
527
|
-
* @param depth relative to user-supplied path
|
|
528
|
-
* @param target child path targeted for watch
|
|
529
|
-
* @param wh Common watch helpers for this path
|
|
530
|
-
* @param realpath
|
|
531
|
-
* @returns closer for the watcher instance.
|
|
532
|
-
*/
|
|
533
|
-
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
|
534
|
-
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
|
535
|
-
const tracked = parentDir.has(sysPath.basename(dir));
|
|
536
|
-
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
|
537
|
-
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
538
|
-
}
|
|
539
|
-
// ensure dir is tracked (harmless if redundant)
|
|
540
|
-
parentDir.add(sysPath.basename(dir));
|
|
541
|
-
this.fsw._getWatchedDir(dir);
|
|
542
|
-
let throttler;
|
|
543
|
-
let closer;
|
|
544
|
-
const oDepth = this.fsw.options.depth;
|
|
545
|
-
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
|
546
|
-
if (!target) {
|
|
547
|
-
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
548
|
-
if (this.fsw.closed)
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
|
552
|
-
// if current directory is removed, do nothing
|
|
553
|
-
if (stats && stats.mtimeMs === 0)
|
|
554
|
-
return;
|
|
555
|
-
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
return closer;
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Handle added file, directory, or glob pattern.
|
|
562
|
-
* Delegates call to _handleFile / _handleDir after checks.
|
|
563
|
-
* @param path to file or ir
|
|
564
|
-
* @param initialAdd was the file added at watch instantiation?
|
|
565
|
-
* @param priorWh depth relative to user-supplied path
|
|
566
|
-
* @param depth Child path actually targeted for watch
|
|
567
|
-
* @param target Child path actually targeted for watch
|
|
568
|
-
*/
|
|
569
|
-
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
570
|
-
const ready = this.fsw._emitReady;
|
|
571
|
-
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
572
|
-
ready();
|
|
573
|
-
return false;
|
|
574
|
-
}
|
|
575
|
-
const wh = this.fsw._getWatchHelpers(path);
|
|
576
|
-
if (priorWh) {
|
|
577
|
-
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
578
|
-
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
579
|
-
}
|
|
580
|
-
// evaluate what is at the path we're being asked to watch
|
|
581
|
-
try {
|
|
582
|
-
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
583
|
-
if (this.fsw.closed)
|
|
584
|
-
return;
|
|
585
|
-
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
586
|
-
ready();
|
|
587
|
-
return false;
|
|
588
|
-
}
|
|
589
|
-
const follow = this.fsw.options.followSymlinks;
|
|
590
|
-
let closer;
|
|
591
|
-
if (stats.isDirectory()) {
|
|
592
|
-
const absPath = sysPath.resolve(path);
|
|
593
|
-
const targetPath = follow ? await realpath(path) : path;
|
|
594
|
-
if (this.fsw.closed)
|
|
595
|
-
return;
|
|
596
|
-
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
597
|
-
if (this.fsw.closed)
|
|
598
|
-
return;
|
|
599
|
-
// preserve this symlink's target path
|
|
600
|
-
if (absPath !== targetPath && targetPath !== undefined) {
|
|
601
|
-
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
else if (stats.isSymbolicLink()) {
|
|
605
|
-
const targetPath = follow ? await realpath(path) : path;
|
|
606
|
-
if (this.fsw.closed)
|
|
607
|
-
return;
|
|
608
|
-
const parent = sysPath.dirname(wh.watchPath);
|
|
609
|
-
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
610
|
-
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
611
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
612
|
-
if (this.fsw.closed)
|
|
613
|
-
return;
|
|
614
|
-
// preserve this symlink's target path
|
|
615
|
-
if (targetPath !== undefined) {
|
|
616
|
-
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
else {
|
|
620
|
-
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
621
|
-
}
|
|
622
|
-
ready();
|
|
623
|
-
if (closer)
|
|
624
|
-
this.fsw._addPathCloser(path, closer);
|
|
625
|
-
return false;
|
|
626
|
-
}
|
|
627
|
-
catch (error) {
|
|
628
|
-
if (this.fsw._handleError(error)) {
|
|
629
|
-
ready();
|
|
630
|
-
return path;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
|
637
|
-
const SLASH = '/';
|
|
638
|
-
const SLASH_SLASH = '//';
|
|
639
|
-
const ONE_DOT = '.';
|
|
640
|
-
const TWO_DOTS = '..';
|
|
641
|
-
const STRING_TYPE = 'string';
|
|
642
|
-
const BACK_SLASH_RE = /\\/g;
|
|
643
|
-
const DOUBLE_SLASH_RE = /\/\//;
|
|
644
|
-
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
645
|
-
const REPLACER_RE = /^\.[/\\]/;
|
|
646
|
-
function arrify(item) {
|
|
647
|
-
return Array.isArray(item) ? item : [item];
|
|
648
|
-
}
|
|
649
|
-
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
|
650
|
-
function createPattern(matcher) {
|
|
651
|
-
if (typeof matcher === 'function')
|
|
652
|
-
return matcher;
|
|
653
|
-
if (typeof matcher === 'string')
|
|
654
|
-
return (string) => matcher === string;
|
|
655
|
-
if (matcher instanceof RegExp)
|
|
656
|
-
return (string) => matcher.test(string);
|
|
657
|
-
if (typeof matcher === 'object' && matcher !== null) {
|
|
658
|
-
return (string) => {
|
|
659
|
-
if (matcher.path === string)
|
|
660
|
-
return true;
|
|
661
|
-
if (matcher.recursive) {
|
|
662
|
-
const relative = sysPath.relative(matcher.path, string);
|
|
663
|
-
if (!relative) {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
|
667
|
-
}
|
|
668
|
-
return false;
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
return () => false;
|
|
672
|
-
}
|
|
673
|
-
function normalizePath(path) {
|
|
674
|
-
if (typeof path !== 'string')
|
|
675
|
-
throw new Error('string expected');
|
|
676
|
-
path = sysPath.normalize(path);
|
|
677
|
-
path = path.replace(/\\/g, '/');
|
|
678
|
-
let prepend = false;
|
|
679
|
-
if (path.startsWith('//'))
|
|
680
|
-
prepend = true;
|
|
681
|
-
const DOUBLE_SLASH_RE = /\/\//;
|
|
682
|
-
while (path.match(DOUBLE_SLASH_RE))
|
|
683
|
-
path = path.replace(DOUBLE_SLASH_RE, '/');
|
|
684
|
-
if (prepend)
|
|
685
|
-
path = '/' + path;
|
|
686
|
-
return path;
|
|
687
|
-
}
|
|
688
|
-
function matchPatterns(patterns, testString, stats) {
|
|
689
|
-
const path = normalizePath(testString);
|
|
690
|
-
for (let index = 0; index < patterns.length; index++) {
|
|
691
|
-
const pattern = patterns[index];
|
|
692
|
-
if (pattern(path, stats)) {
|
|
693
|
-
return true;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
return false;
|
|
697
|
-
}
|
|
698
|
-
function anymatch(matchers, testString) {
|
|
699
|
-
if (matchers == null) {
|
|
700
|
-
throw new TypeError('anymatch: specify first argument');
|
|
701
|
-
}
|
|
702
|
-
// Early cache for matchers.
|
|
703
|
-
const matchersArray = arrify(matchers);
|
|
704
|
-
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
|
705
|
-
{
|
|
706
|
-
return (testString, stats) => {
|
|
707
|
-
return matchPatterns(patterns, testString, stats);
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
const unifyPaths = (paths_) => {
|
|
712
|
-
const paths = arrify(paths_).flat();
|
|
713
|
-
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
|
714
|
-
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
715
|
-
}
|
|
716
|
-
return paths.map(normalizePathToUnix);
|
|
717
|
-
};
|
|
718
|
-
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
|
719
|
-
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
|
720
|
-
const toUnix = (string) => {
|
|
721
|
-
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
722
|
-
let prepend = false;
|
|
723
|
-
if (str.startsWith(SLASH_SLASH)) {
|
|
724
|
-
prepend = true;
|
|
725
|
-
}
|
|
726
|
-
while (str.match(DOUBLE_SLASH_RE)) {
|
|
727
|
-
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
728
|
-
}
|
|
729
|
-
if (prepend) {
|
|
730
|
-
str = SLASH + str;
|
|
731
|
-
}
|
|
732
|
-
return str;
|
|
733
|
-
};
|
|
734
|
-
// Our version of upath.normalize
|
|
735
|
-
// TODO: this is not equal to path-normalize module - investigate why
|
|
736
|
-
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
|
737
|
-
// TODO: refactor
|
|
738
|
-
const normalizeIgnored = (cwd = '') => (path) => {
|
|
739
|
-
if (typeof path === 'string') {
|
|
740
|
-
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
|
741
|
-
}
|
|
742
|
-
else {
|
|
743
|
-
return path;
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
const getAbsolutePath = (path, cwd) => {
|
|
747
|
-
if (sysPath.isAbsolute(path)) {
|
|
748
|
-
return path;
|
|
749
|
-
}
|
|
750
|
-
return sysPath.join(cwd, path);
|
|
751
|
-
};
|
|
752
|
-
const EMPTY_SET = Object.freeze(new Set());
|
|
753
|
-
/**
|
|
754
|
-
* Directory entry.
|
|
755
|
-
*/
|
|
756
|
-
class DirEntry {
|
|
757
|
-
constructor(dir, removeWatcher) {
|
|
758
|
-
this.path = dir;
|
|
759
|
-
this._removeWatcher = removeWatcher;
|
|
760
|
-
this.items = new Set();
|
|
761
|
-
}
|
|
762
|
-
add(item) {
|
|
763
|
-
const { items } = this;
|
|
764
|
-
if (!items)
|
|
765
|
-
return;
|
|
766
|
-
if (item !== ONE_DOT && item !== TWO_DOTS)
|
|
767
|
-
items.add(item);
|
|
768
|
-
}
|
|
769
|
-
async remove(item) {
|
|
770
|
-
const { items } = this;
|
|
771
|
-
if (!items)
|
|
772
|
-
return;
|
|
773
|
-
items.delete(item);
|
|
774
|
-
if (items.size > 0)
|
|
775
|
-
return;
|
|
776
|
-
const dir = this.path;
|
|
777
|
-
try {
|
|
778
|
-
await readdir(dir);
|
|
779
|
-
}
|
|
780
|
-
catch (err) {
|
|
781
|
-
if (this._removeWatcher) {
|
|
782
|
-
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
has(item) {
|
|
787
|
-
const { items } = this;
|
|
788
|
-
if (!items)
|
|
789
|
-
return;
|
|
790
|
-
return items.has(item);
|
|
791
|
-
}
|
|
792
|
-
getChildren() {
|
|
793
|
-
const { items } = this;
|
|
794
|
-
if (!items)
|
|
795
|
-
return [];
|
|
796
|
-
return [...items.values()];
|
|
797
|
-
}
|
|
798
|
-
dispose() {
|
|
799
|
-
this.items.clear();
|
|
800
|
-
this.path = '';
|
|
801
|
-
this._removeWatcher = EMPTY_FN;
|
|
802
|
-
this.items = EMPTY_SET;
|
|
803
|
-
Object.freeze(this);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
const STAT_METHOD_F = 'stat';
|
|
807
|
-
const STAT_METHOD_L = 'lstat';
|
|
808
|
-
class WatchHelper {
|
|
809
|
-
constructor(path, follow, fsw) {
|
|
810
|
-
this.fsw = fsw;
|
|
811
|
-
const watchPath = path;
|
|
812
|
-
this.path = path = path.replace(REPLACER_RE, '');
|
|
813
|
-
this.watchPath = watchPath;
|
|
814
|
-
this.fullWatchPath = sysPath.resolve(watchPath);
|
|
815
|
-
this.dirParts = [];
|
|
816
|
-
this.dirParts.forEach((parts) => {
|
|
817
|
-
if (parts.length > 1)
|
|
818
|
-
parts.pop();
|
|
819
|
-
});
|
|
820
|
-
this.followSymlinks = follow;
|
|
821
|
-
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
822
|
-
}
|
|
823
|
-
entryPath(entry) {
|
|
824
|
-
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
|
825
|
-
}
|
|
826
|
-
filterPath(entry) {
|
|
827
|
-
const { stats } = entry;
|
|
828
|
-
if (stats && stats.isSymbolicLink())
|
|
829
|
-
return this.filterDir(entry);
|
|
830
|
-
const resolvedPath = this.entryPath(entry);
|
|
831
|
-
// TODO: what if stats is undefined? remove !
|
|
832
|
-
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
833
|
-
}
|
|
834
|
-
filterDir(entry) {
|
|
835
|
-
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
/**
|
|
839
|
-
* Watches files & directories for changes. Emitted events:
|
|
840
|
-
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
|
841
|
-
*
|
|
842
|
-
* new FSWatcher()
|
|
843
|
-
* .add(directories)
|
|
844
|
-
* .on('add', path => log('File', path, 'was added'))
|
|
845
|
-
*/
|
|
846
|
-
class FSWatcher extends EventEmitter {
|
|
847
|
-
// Not indenting methods for history sake; for now.
|
|
848
|
-
constructor(_opts = {}) {
|
|
849
|
-
super();
|
|
850
|
-
this.closed = false;
|
|
851
|
-
this._closers = new Map();
|
|
852
|
-
this._ignoredPaths = new Set();
|
|
853
|
-
this._throttled = new Map();
|
|
854
|
-
this._streams = new Set();
|
|
855
|
-
this._symlinkPaths = new Map();
|
|
856
|
-
this._watched = new Map();
|
|
857
|
-
this._pendingWrites = new Map();
|
|
858
|
-
this._pendingUnlinks = new Map();
|
|
859
|
-
this._readyCount = 0;
|
|
860
|
-
this._readyEmitted = false;
|
|
861
|
-
const awf = _opts.awaitWriteFinish;
|
|
862
|
-
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
|
863
|
-
const opts = {
|
|
864
|
-
// Defaults
|
|
865
|
-
persistent: true,
|
|
866
|
-
ignoreInitial: false,
|
|
867
|
-
ignorePermissionErrors: false,
|
|
868
|
-
interval: 100,
|
|
869
|
-
binaryInterval: 300,
|
|
870
|
-
followSymlinks: true,
|
|
871
|
-
usePolling: false,
|
|
872
|
-
// useAsync: false,
|
|
873
|
-
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
|
874
|
-
..._opts,
|
|
875
|
-
// Change format
|
|
876
|
-
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
877
|
-
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
|
878
|
-
};
|
|
879
|
-
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
|
880
|
-
if (isIBMi)
|
|
881
|
-
opts.usePolling = true;
|
|
882
|
-
// Editor atomic write normalization enabled by default with fs.watch
|
|
883
|
-
if (opts.atomic === undefined)
|
|
884
|
-
opts.atomic = !opts.usePolling;
|
|
885
|
-
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
|
886
|
-
// Global override. Useful for developers, who need to force polling for all
|
|
887
|
-
// instances of chokidar, regardless of usage / dependency depth
|
|
888
|
-
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
889
|
-
if (envPoll !== undefined) {
|
|
890
|
-
const envLower = envPoll.toLowerCase();
|
|
891
|
-
if (envLower === 'false' || envLower === '0')
|
|
892
|
-
opts.usePolling = false;
|
|
893
|
-
else if (envLower === 'true' || envLower === '1')
|
|
894
|
-
opts.usePolling = true;
|
|
895
|
-
else
|
|
896
|
-
opts.usePolling = !!envLower;
|
|
897
|
-
}
|
|
898
|
-
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
899
|
-
if (envInterval)
|
|
900
|
-
opts.interval = Number.parseInt(envInterval, 10);
|
|
901
|
-
// This is done to emit ready only once, but each 'add' will increase that?
|
|
902
|
-
let readyCalls = 0;
|
|
903
|
-
this._emitReady = () => {
|
|
904
|
-
readyCalls++;
|
|
905
|
-
if (readyCalls >= this._readyCount) {
|
|
906
|
-
this._emitReady = EMPTY_FN;
|
|
907
|
-
this._readyEmitted = true;
|
|
908
|
-
// use process.nextTick to allow time for listener to be bound
|
|
909
|
-
process.nextTick(() => this.emit(EVENTS.READY));
|
|
910
|
-
}
|
|
911
|
-
};
|
|
912
|
-
this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
|
|
913
|
-
this._boundRemove = this._remove.bind(this);
|
|
914
|
-
this.options = opts;
|
|
915
|
-
this._nodeFsHandler = new NodeFsHandler(this);
|
|
916
|
-
// You’re frozen when your heart’s not open.
|
|
917
|
-
Object.freeze(opts);
|
|
918
|
-
}
|
|
919
|
-
_addIgnoredPath(matcher) {
|
|
920
|
-
if (isMatcherObject(matcher)) {
|
|
921
|
-
// return early if we already have a deeply equal matcher object
|
|
922
|
-
for (const ignored of this._ignoredPaths) {
|
|
923
|
-
if (isMatcherObject(ignored) &&
|
|
924
|
-
ignored.path === matcher.path &&
|
|
925
|
-
ignored.recursive === matcher.recursive) {
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
this._ignoredPaths.add(matcher);
|
|
931
|
-
}
|
|
932
|
-
_removeIgnoredPath(matcher) {
|
|
933
|
-
this._ignoredPaths.delete(matcher);
|
|
934
|
-
// now find any matcher objects with the matcher as path
|
|
935
|
-
if (typeof matcher === 'string') {
|
|
936
|
-
for (const ignored of this._ignoredPaths) {
|
|
937
|
-
// TODO (43081j): make this more efficient.
|
|
938
|
-
// probably just make a `this._ignoredDirectories` or some
|
|
939
|
-
// such thing.
|
|
940
|
-
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
|
941
|
-
this._ignoredPaths.delete(ignored);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
// Public methods
|
|
947
|
-
/**
|
|
948
|
-
* Adds paths to be watched on an existing FSWatcher instance.
|
|
949
|
-
* @param paths_ file or file list. Other arguments are unused
|
|
950
|
-
*/
|
|
951
|
-
add(paths_, _origAdd, _internal) {
|
|
952
|
-
const { cwd } = this.options;
|
|
953
|
-
this.closed = false;
|
|
954
|
-
this._closePromise = undefined;
|
|
955
|
-
let paths = unifyPaths(paths_);
|
|
956
|
-
if (cwd) {
|
|
957
|
-
paths = paths.map((path) => {
|
|
958
|
-
const absPath = getAbsolutePath(path, cwd);
|
|
959
|
-
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
|
960
|
-
return absPath;
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
paths.forEach((path) => {
|
|
964
|
-
this._removeIgnoredPath(path);
|
|
965
|
-
});
|
|
966
|
-
this._userIgnored = undefined;
|
|
967
|
-
if (!this._readyCount)
|
|
968
|
-
this._readyCount = 0;
|
|
969
|
-
this._readyCount += paths.length;
|
|
970
|
-
Promise.all(paths.map(async (path) => {
|
|
971
|
-
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
|
972
|
-
if (res)
|
|
973
|
-
this._emitReady();
|
|
974
|
-
return res;
|
|
975
|
-
})).then((results) => {
|
|
976
|
-
if (this.closed)
|
|
977
|
-
return;
|
|
978
|
-
results.forEach((item) => {
|
|
979
|
-
if (item)
|
|
980
|
-
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
|
981
|
-
});
|
|
982
|
-
});
|
|
983
|
-
return this;
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Close watchers or start ignoring events from specified paths.
|
|
987
|
-
*/
|
|
988
|
-
unwatch(paths_) {
|
|
989
|
-
if (this.closed)
|
|
990
|
-
return this;
|
|
991
|
-
const paths = unifyPaths(paths_);
|
|
992
|
-
const { cwd } = this.options;
|
|
993
|
-
paths.forEach((path) => {
|
|
994
|
-
// convert to absolute path unless relative path already matches
|
|
995
|
-
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
|
996
|
-
if (cwd)
|
|
997
|
-
path = sysPath.join(cwd, path);
|
|
998
|
-
path = sysPath.resolve(path);
|
|
999
|
-
}
|
|
1000
|
-
this._closePath(path);
|
|
1001
|
-
this._addIgnoredPath(path);
|
|
1002
|
-
if (this._watched.has(path)) {
|
|
1003
|
-
this._addIgnoredPath({
|
|
1004
|
-
path,
|
|
1005
|
-
recursive: true,
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
// reset the cached userIgnored anymatch fn
|
|
1009
|
-
// to make ignoredPaths changes effective
|
|
1010
|
-
this._userIgnored = undefined;
|
|
1011
|
-
});
|
|
1012
|
-
return this;
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Close watchers and remove all listeners from watched paths.
|
|
1016
|
-
*/
|
|
1017
|
-
close() {
|
|
1018
|
-
if (this._closePromise) {
|
|
1019
|
-
return this._closePromise;
|
|
1020
|
-
}
|
|
1021
|
-
this.closed = true;
|
|
1022
|
-
// Memory management.
|
|
1023
|
-
this.removeAllListeners();
|
|
1024
|
-
const closers = [];
|
|
1025
|
-
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
|
1026
|
-
const promise = closer();
|
|
1027
|
-
if (promise instanceof Promise)
|
|
1028
|
-
closers.push(promise);
|
|
1029
|
-
}));
|
|
1030
|
-
this._streams.forEach((stream) => stream.destroy());
|
|
1031
|
-
this._userIgnored = undefined;
|
|
1032
|
-
this._readyCount = 0;
|
|
1033
|
-
this._readyEmitted = false;
|
|
1034
|
-
this._watched.forEach((dirent) => dirent.dispose());
|
|
1035
|
-
this._closers.clear();
|
|
1036
|
-
this._watched.clear();
|
|
1037
|
-
this._streams.clear();
|
|
1038
|
-
this._symlinkPaths.clear();
|
|
1039
|
-
this._throttled.clear();
|
|
1040
|
-
this._closePromise = closers.length
|
|
1041
|
-
? Promise.all(closers).then(() => undefined)
|
|
1042
|
-
: Promise.resolve();
|
|
1043
|
-
return this._closePromise;
|
|
1044
|
-
}
|
|
1045
|
-
/**
|
|
1046
|
-
* Expose list of watched paths
|
|
1047
|
-
* @returns for chaining
|
|
1048
|
-
*/
|
|
1049
|
-
getWatched() {
|
|
1050
|
-
const watchList = {};
|
|
1051
|
-
this._watched.forEach((entry, dir) => {
|
|
1052
|
-
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
|
1053
|
-
const index = key || ONE_DOT;
|
|
1054
|
-
watchList[index] = entry.getChildren().sort();
|
|
1055
|
-
});
|
|
1056
|
-
return watchList;
|
|
1057
|
-
}
|
|
1058
|
-
emitWithAll(event, args) {
|
|
1059
|
-
this.emit(event, ...args);
|
|
1060
|
-
if (event !== EVENTS.ERROR)
|
|
1061
|
-
this.emit(EVENTS.ALL, event, ...args);
|
|
1062
|
-
}
|
|
1063
|
-
// Common helpers
|
|
1064
|
-
// --------------
|
|
1065
|
-
/**
|
|
1066
|
-
* Normalize and emit events.
|
|
1067
|
-
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
1068
|
-
* @param event Type of event
|
|
1069
|
-
* @param path File or directory path
|
|
1070
|
-
* @param stats arguments to be passed with event
|
|
1071
|
-
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
1072
|
-
*/
|
|
1073
|
-
async _emit(event, path, stats) {
|
|
1074
|
-
if (this.closed)
|
|
1075
|
-
return;
|
|
1076
|
-
const opts = this.options;
|
|
1077
|
-
if (isWindows)
|
|
1078
|
-
path = sysPath.normalize(path);
|
|
1079
|
-
if (opts.cwd)
|
|
1080
|
-
path = sysPath.relative(opts.cwd, path);
|
|
1081
|
-
const args = [path];
|
|
1082
|
-
if (stats != null)
|
|
1083
|
-
args.push(stats);
|
|
1084
|
-
const awf = opts.awaitWriteFinish;
|
|
1085
|
-
let pw;
|
|
1086
|
-
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
1087
|
-
pw.lastChange = new Date();
|
|
1088
|
-
return this;
|
|
1089
|
-
}
|
|
1090
|
-
if (opts.atomic) {
|
|
1091
|
-
if (event === EVENTS.UNLINK) {
|
|
1092
|
-
this._pendingUnlinks.set(path, [event, ...args]);
|
|
1093
|
-
setTimeout(() => {
|
|
1094
|
-
this._pendingUnlinks.forEach((entry, path) => {
|
|
1095
|
-
this.emit(...entry);
|
|
1096
|
-
this.emit(EVENTS.ALL, ...entry);
|
|
1097
|
-
this._pendingUnlinks.delete(path);
|
|
1098
|
-
});
|
|
1099
|
-
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
|
1100
|
-
return this;
|
|
1101
|
-
}
|
|
1102
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
1103
|
-
event = EVENTS.CHANGE;
|
|
1104
|
-
this._pendingUnlinks.delete(path);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
1108
|
-
const awfEmit = (err, stats) => {
|
|
1109
|
-
if (err) {
|
|
1110
|
-
event = EVENTS.ERROR;
|
|
1111
|
-
args[0] = err;
|
|
1112
|
-
this.emitWithAll(event, args);
|
|
1113
|
-
}
|
|
1114
|
-
else if (stats) {
|
|
1115
|
-
// if stats doesn't exist the file must have been deleted
|
|
1116
|
-
if (args.length > 1) {
|
|
1117
|
-
args[1] = stats;
|
|
1118
|
-
}
|
|
1119
|
-
else {
|
|
1120
|
-
args.push(stats);
|
|
1121
|
-
}
|
|
1122
|
-
this.emitWithAll(event, args);
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
1126
|
-
return this;
|
|
1127
|
-
}
|
|
1128
|
-
if (event === EVENTS.CHANGE) {
|
|
1129
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
|
|
1130
|
-
if (isThrottled)
|
|
1131
|
-
return this;
|
|
1132
|
-
}
|
|
1133
|
-
if (opts.alwaysStat &&
|
|
1134
|
-
stats === undefined &&
|
|
1135
|
-
(event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
1136
|
-
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
|
1137
|
-
let stats;
|
|
1138
|
-
try {
|
|
1139
|
-
stats = await stat(fullPath);
|
|
1140
|
-
}
|
|
1141
|
-
catch (err) {
|
|
1142
|
-
// do nothing
|
|
1143
|
-
}
|
|
1144
|
-
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
|
1145
|
-
if (!stats || this.closed)
|
|
1146
|
-
return;
|
|
1147
|
-
args.push(stats);
|
|
1148
|
-
}
|
|
1149
|
-
this.emitWithAll(event, args);
|
|
1150
|
-
return this;
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Common handler for errors
|
|
1154
|
-
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
1155
|
-
*/
|
|
1156
|
-
_handleError(error) {
|
|
1157
|
-
const code = error && error.code;
|
|
1158
|
-
if (error &&
|
|
1159
|
-
code !== 'ENOENT' &&
|
|
1160
|
-
code !== 'ENOTDIR' &&
|
|
1161
|
-
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
|
1162
|
-
this.emit(EVENTS.ERROR, error);
|
|
1163
|
-
}
|
|
1164
|
-
return error || this.closed;
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Helper utility for throttling
|
|
1168
|
-
* @param actionType type being throttled
|
|
1169
|
-
* @param path being acted upon
|
|
1170
|
-
* @param timeout duration of time to suppress duplicate actions
|
|
1171
|
-
* @returns tracking object or false if action should be suppressed
|
|
1172
|
-
*/
|
|
1173
|
-
_throttle(actionType, path, timeout) {
|
|
1174
|
-
if (!this._throttled.has(actionType)) {
|
|
1175
|
-
this._throttled.set(actionType, new Map());
|
|
1176
|
-
}
|
|
1177
|
-
const action = this._throttled.get(actionType);
|
|
1178
|
-
if (!action)
|
|
1179
|
-
throw new Error('invalid throttle');
|
|
1180
|
-
const actionPath = action.get(path);
|
|
1181
|
-
if (actionPath) {
|
|
1182
|
-
actionPath.count++;
|
|
1183
|
-
return false;
|
|
1184
|
-
}
|
|
1185
|
-
// eslint-disable-next-line prefer-const
|
|
1186
|
-
let timeoutObject;
|
|
1187
|
-
const clear = () => {
|
|
1188
|
-
const item = action.get(path);
|
|
1189
|
-
const count = item ? item.count : 0;
|
|
1190
|
-
action.delete(path);
|
|
1191
|
-
clearTimeout(timeoutObject);
|
|
1192
|
-
if (item)
|
|
1193
|
-
clearTimeout(item.timeoutObject);
|
|
1194
|
-
return count;
|
|
1195
|
-
};
|
|
1196
|
-
timeoutObject = setTimeout(clear, timeout);
|
|
1197
|
-
const thr = { timeoutObject, clear, count: 0 };
|
|
1198
|
-
action.set(path, thr);
|
|
1199
|
-
return thr;
|
|
1200
|
-
}
|
|
1201
|
-
_incrReadyCount() {
|
|
1202
|
-
return this._readyCount++;
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Awaits write operation to finish.
|
|
1206
|
-
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
1207
|
-
* @param path being acted upon
|
|
1208
|
-
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
1209
|
-
* @param event
|
|
1210
|
-
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
1211
|
-
*/
|
|
1212
|
-
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
1213
|
-
const awf = this.options.awaitWriteFinish;
|
|
1214
|
-
if (typeof awf !== 'object')
|
|
1215
|
-
return;
|
|
1216
|
-
const pollInterval = awf.pollInterval;
|
|
1217
|
-
let timeoutHandler;
|
|
1218
|
-
let fullPath = path;
|
|
1219
|
-
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
|
1220
|
-
fullPath = sysPath.join(this.options.cwd, path);
|
|
1221
|
-
}
|
|
1222
|
-
const now = new Date();
|
|
1223
|
-
const writes = this._pendingWrites;
|
|
1224
|
-
function awaitWriteFinishFn(prevStat) {
|
|
1225
|
-
stat$1(fullPath, (err, curStat) => {
|
|
1226
|
-
if (err || !writes.has(path)) {
|
|
1227
|
-
if (err && err.code !== 'ENOENT')
|
|
1228
|
-
awfEmit(err);
|
|
1229
|
-
return;
|
|
1230
|
-
}
|
|
1231
|
-
const now = Number(new Date());
|
|
1232
|
-
if (prevStat && curStat.size !== prevStat.size) {
|
|
1233
|
-
writes.get(path).lastChange = now;
|
|
1234
|
-
}
|
|
1235
|
-
const pw = writes.get(path);
|
|
1236
|
-
const df = now - pw.lastChange;
|
|
1237
|
-
if (df >= threshold) {
|
|
1238
|
-
writes.delete(path);
|
|
1239
|
-
awfEmit(undefined, curStat);
|
|
1240
|
-
}
|
|
1241
|
-
else {
|
|
1242
|
-
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
if (!writes.has(path)) {
|
|
1247
|
-
writes.set(path, {
|
|
1248
|
-
lastChange: now,
|
|
1249
|
-
cancelWait: () => {
|
|
1250
|
-
writes.delete(path);
|
|
1251
|
-
clearTimeout(timeoutHandler);
|
|
1252
|
-
return event;
|
|
1253
|
-
},
|
|
1254
|
-
});
|
|
1255
|
-
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Determines whether user has asked to ignore this path.
|
|
1260
|
-
*/
|
|
1261
|
-
_isIgnored(path, stats) {
|
|
1262
|
-
if (this.options.atomic && DOT_RE.test(path))
|
|
1263
|
-
return true;
|
|
1264
|
-
if (!this._userIgnored) {
|
|
1265
|
-
const { cwd } = this.options;
|
|
1266
|
-
const ign = this.options.ignored;
|
|
1267
|
-
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
|
1268
|
-
const ignoredPaths = [...this._ignoredPaths];
|
|
1269
|
-
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
1270
|
-
this._userIgnored = anymatch(list);
|
|
1271
|
-
}
|
|
1272
|
-
return this._userIgnored(path, stats);
|
|
1273
|
-
}
|
|
1274
|
-
_isntIgnored(path, stat) {
|
|
1275
|
-
return !this._isIgnored(path, stat);
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* Provides a set of common helpers and properties relating to symlink handling.
|
|
1279
|
-
* @param path file or directory pattern being watched
|
|
1280
|
-
*/
|
|
1281
|
-
_getWatchHelpers(path) {
|
|
1282
|
-
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
1283
|
-
}
|
|
1284
|
-
// Directory helpers
|
|
1285
|
-
// -----------------
|
|
1286
|
-
/**
|
|
1287
|
-
* Provides directory tracking objects
|
|
1288
|
-
* @param directory path of the directory
|
|
1289
|
-
*/
|
|
1290
|
-
_getWatchedDir(directory) {
|
|
1291
|
-
const dir = sysPath.resolve(directory);
|
|
1292
|
-
if (!this._watched.has(dir))
|
|
1293
|
-
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
1294
|
-
return this._watched.get(dir);
|
|
1295
|
-
}
|
|
1296
|
-
// File helpers
|
|
1297
|
-
// ------------
|
|
1298
|
-
/**
|
|
1299
|
-
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
|
1300
|
-
*/
|
|
1301
|
-
_hasReadPermissions(stats) {
|
|
1302
|
-
if (this.options.ignorePermissionErrors)
|
|
1303
|
-
return true;
|
|
1304
|
-
return Boolean(Number(stats.mode) & 0o400);
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Handles emitting unlink events for
|
|
1308
|
-
* files and directories, and via recursion, for
|
|
1309
|
-
* files and directories within directories that are unlinked
|
|
1310
|
-
* @param directory within which the following item is located
|
|
1311
|
-
* @param item base path of item/directory
|
|
1312
|
-
*/
|
|
1313
|
-
_remove(directory, item, isDirectory) {
|
|
1314
|
-
// if what is being deleted is a directory, get that directory's paths
|
|
1315
|
-
// for recursive deleting and cleaning of watched object
|
|
1316
|
-
// if it is not a directory, nestedDirectoryChildren will be empty array
|
|
1317
|
-
const path = sysPath.join(directory, item);
|
|
1318
|
-
const fullPath = sysPath.resolve(path);
|
|
1319
|
-
isDirectory =
|
|
1320
|
-
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
1321
|
-
// prevent duplicate handling in case of arriving here nearly simultaneously
|
|
1322
|
-
// via multiple paths (such as _handleFile and _handleDir)
|
|
1323
|
-
if (!this._throttle('remove', path, 100))
|
|
1324
|
-
return;
|
|
1325
|
-
// if the only watched file is removed, watch for its return
|
|
1326
|
-
if (!isDirectory && this._watched.size === 1) {
|
|
1327
|
-
this.add(directory, item, true);
|
|
1328
|
-
}
|
|
1329
|
-
// This will create a new entry in the watched object in either case
|
|
1330
|
-
// so we got to do the directory check beforehand
|
|
1331
|
-
const wp = this._getWatchedDir(path);
|
|
1332
|
-
const nestedDirectoryChildren = wp.getChildren();
|
|
1333
|
-
// Recursively remove children directories / files.
|
|
1334
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
|
1335
|
-
// Check if item was on the watched list and remove it
|
|
1336
|
-
const parent = this._getWatchedDir(directory);
|
|
1337
|
-
const wasTracked = parent.has(item);
|
|
1338
|
-
parent.remove(item);
|
|
1339
|
-
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
|
1340
|
-
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
|
1341
|
-
// but never removed from the map in case the path was deleted.
|
|
1342
|
-
// This leads to an incorrect state if the path was recreated:
|
|
1343
|
-
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
|
1344
|
-
if (this._symlinkPaths.has(fullPath)) {
|
|
1345
|
-
this._symlinkPaths.delete(fullPath);
|
|
1346
|
-
}
|
|
1347
|
-
// If we wait for this file to be fully written, cancel the wait.
|
|
1348
|
-
let relPath = path;
|
|
1349
|
-
if (this.options.cwd)
|
|
1350
|
-
relPath = sysPath.relative(this.options.cwd, path);
|
|
1351
|
-
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
1352
|
-
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
1353
|
-
if (event === EVENTS.ADD)
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
// The Entry will either be a directory that just got removed
|
|
1357
|
-
// or a bogus entry to a file, in either case we have to remove it
|
|
1358
|
-
this._watched.delete(path);
|
|
1359
|
-
this._watched.delete(fullPath);
|
|
1360
|
-
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
1361
|
-
if (wasTracked && !this._isIgnored(path))
|
|
1362
|
-
this._emit(eventName, path);
|
|
1363
|
-
// Avoid conflicts if we later create another file with the same name
|
|
1364
|
-
this._closePath(path);
|
|
1365
|
-
}
|
|
1366
|
-
/**
|
|
1367
|
-
* Closes all watchers for a path
|
|
1368
|
-
*/
|
|
1369
|
-
_closePath(path) {
|
|
1370
|
-
this._closeFile(path);
|
|
1371
|
-
const dir = sysPath.dirname(path);
|
|
1372
|
-
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Closes only file-specific watchers
|
|
1376
|
-
*/
|
|
1377
|
-
_closeFile(path) {
|
|
1378
|
-
const closers = this._closers.get(path);
|
|
1379
|
-
if (!closers)
|
|
1380
|
-
return;
|
|
1381
|
-
closers.forEach((closer) => closer());
|
|
1382
|
-
this._closers.delete(path);
|
|
1383
|
-
}
|
|
1384
|
-
_addPathCloser(path, closer) {
|
|
1385
|
-
if (!closer)
|
|
1386
|
-
return;
|
|
1387
|
-
let list = this._closers.get(path);
|
|
1388
|
-
if (!list) {
|
|
1389
|
-
list = [];
|
|
1390
|
-
this._closers.set(path, list);
|
|
1391
|
-
}
|
|
1392
|
-
list.push(closer);
|
|
1393
|
-
}
|
|
1394
|
-
_readdirp(root, opts) {
|
|
1395
|
-
if (this.closed)
|
|
1396
|
-
return;
|
|
1397
|
-
const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
|
1398
|
-
let stream = readdirp(root, options);
|
|
1399
|
-
this._streams.add(stream);
|
|
1400
|
-
stream.once(STR_CLOSE, () => {
|
|
1401
|
-
stream = undefined;
|
|
1402
|
-
});
|
|
1403
|
-
stream.once(STR_END, () => {
|
|
1404
|
-
if (stream) {
|
|
1405
|
-
this._streams.delete(stream);
|
|
1406
|
-
stream = undefined;
|
|
1407
|
-
}
|
|
1408
|
-
});
|
|
1409
|
-
return stream;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Instantiates watcher with paths to be tracked.
|
|
1414
|
-
* @param paths file / directory paths
|
|
1415
|
-
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
|
1416
|
-
* @returns an instance of FSWatcher for chaining.
|
|
1417
|
-
* @example
|
|
1418
|
-
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
|
1419
|
-
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
|
1420
|
-
*/
|
|
1421
|
-
function watch(paths, options = {}) {
|
|
1422
|
-
const watcher = new FSWatcher(options);
|
|
1423
|
-
watcher.add(paths);
|
|
1424
|
-
return watcher;
|
|
1425
|
-
}
|
|
1426
|
-
const index = { watch, FSWatcher };
|
|
1427
|
-
|
|
1428
|
-
export { FSWatcher, WatchHelper, index as default, watch };
|