@sanurb/ringi 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3JLVANJR.js → chunk-KMYSGMD3.js} +1819 -75
- package/dist/chunk-KMYSGMD3.js.map +1 -0
- package/dist/cli.js +108 -39
- package/dist/cli.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +1 -1
- package/package.json +10 -83
- package/LICENSE +0 -674
- package/README.md +0 -378
- package/dist/chunk-3JLVANJR.js.map +0 -1
|
@@ -3,22 +3,24 @@ import * as Schema3 from 'effect/Schema';
|
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import * as Effect4 from 'effect/Effect';
|
|
5
5
|
import * as Option from 'effect/Option';
|
|
6
|
-
import { mkdirSync } from 'node:fs';
|
|
7
|
-
import
|
|
6
|
+
import { mkdirSync, stat as stat$1, unwatchFile, watchFile, watch as watch$1 } from 'node:fs';
|
|
7
|
+
import * as sp2 from 'node:path';
|
|
8
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
8
9
|
import { DatabaseSync } from 'node:sqlite';
|
|
9
10
|
import * as Config from 'effect/Config';
|
|
10
11
|
import * as Exit from 'effect/Exit';
|
|
11
|
-
import { execFile } from 'node:child_process';
|
|
12
|
-
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { spawn, execFile } from 'node:child_process';
|
|
13
|
+
import { readFile, stat, realpath, lstat, readdir, open } from 'node:fs/promises';
|
|
13
14
|
import * as Layer from 'effect/Layer';
|
|
14
15
|
import 'effect/ManagedRuntime';
|
|
15
|
-
import { platform } from 'node:os';
|
|
16
|
-
import
|
|
16
|
+
import { type, platform } from 'node:os';
|
|
17
|
+
import { EventEmitter } from 'node:events';
|
|
18
|
+
import { Readable } from 'node:stream';
|
|
17
19
|
import * as Queue from 'effect/Queue';
|
|
18
20
|
import * as Runtime from 'effect/Runtime';
|
|
19
21
|
import * as Stream from 'effect/Stream';
|
|
20
22
|
|
|
21
|
-
// src/
|
|
23
|
+
// ../../packages/core/src/schemas/review.ts
|
|
22
24
|
var ReviewId = Schema3.String.pipe(Schema3.brand("ReviewId"));
|
|
23
25
|
var ReviewStatus = Schema3.Literal(
|
|
24
26
|
"in_progress",
|
|
@@ -82,49 +84,8 @@ var TodoNotFound = class extends Schema3.TaggedError()(
|
|
|
82
84
|
HttpApiSchema.annotations({ status: 404 })
|
|
83
85
|
) {
|
|
84
86
|
};
|
|
85
|
-
var CommentId = Schema3.String.pipe(Schema3.brand("CommentId"));
|
|
86
|
-
var LineType = Schema3.Literal("added", "removed", "context");
|
|
87
|
-
Schema3.Struct({
|
|
88
|
-
content: Schema3.String,
|
|
89
|
-
createdAt: Schema3.String,
|
|
90
|
-
filePath: Schema3.String,
|
|
91
|
-
id: CommentId,
|
|
92
|
-
lineNumber: Schema3.NullOr(Schema3.Number),
|
|
93
|
-
lineType: Schema3.NullOr(LineType),
|
|
94
|
-
resolved: Schema3.Boolean,
|
|
95
|
-
reviewId: ReviewId,
|
|
96
|
-
suggestion: Schema3.NullOr(Schema3.String),
|
|
97
|
-
updatedAt: Schema3.String
|
|
98
|
-
});
|
|
99
|
-
Schema3.Struct({
|
|
100
|
-
content: Schema3.String.pipe(Schema3.minLength(1)),
|
|
101
|
-
filePath: Schema3.String.pipe(Schema3.minLength(1)),
|
|
102
|
-
lineNumber: Schema3.optionalWith(Schema3.NullOr(Schema3.Number), {
|
|
103
|
-
default: () => null
|
|
104
|
-
}),
|
|
105
|
-
lineType: Schema3.optionalWith(Schema3.NullOr(LineType), {
|
|
106
|
-
default: () => null
|
|
107
|
-
}),
|
|
108
|
-
suggestion: Schema3.optionalWith(Schema3.NullOr(Schema3.String), {
|
|
109
|
-
default: () => null
|
|
110
|
-
})
|
|
111
|
-
});
|
|
112
|
-
Schema3.Struct({
|
|
113
|
-
content: Schema3.optionalWith(Schema3.String.pipe(Schema3.minLength(1)), {
|
|
114
|
-
as: "Option"
|
|
115
|
-
}),
|
|
116
|
-
suggestion: Schema3.optionalWith(Schema3.NullOr(Schema3.String), {
|
|
117
|
-
as: "Option"
|
|
118
|
-
})
|
|
119
|
-
});
|
|
120
|
-
var CommentNotFound = class extends Schema3.TaggedError()(
|
|
121
|
-
"CommentNotFound",
|
|
122
|
-
{ id: CommentId },
|
|
123
|
-
HttpApiSchema.annotations({ status: 404 })
|
|
124
|
-
) {
|
|
125
|
-
};
|
|
126
87
|
|
|
127
|
-
//
|
|
88
|
+
// ../../packages/core/src/db/migrations.ts
|
|
128
89
|
var migrations = [
|
|
129
90
|
// v1: reviews table
|
|
130
91
|
`CREATE TABLE IF NOT EXISTS reviews (
|
|
@@ -187,7 +148,7 @@ var runMigrations = (db) => {
|
|
|
187
148
|
}
|
|
188
149
|
};
|
|
189
150
|
|
|
190
|
-
//
|
|
151
|
+
// ../../packages/core/src/db/database.ts
|
|
191
152
|
var withTransaction = (db, body) => Effect4.acquireUseRelease(
|
|
192
153
|
Effect4.sync(() => db.exec("BEGIN")),
|
|
193
154
|
() => body,
|
|
@@ -217,7 +178,7 @@ var SqliteService = class extends Effect4.Service()(
|
|
|
217
178
|
) {
|
|
218
179
|
};
|
|
219
180
|
|
|
220
|
-
//
|
|
181
|
+
// ../../packages/core/src/repos/comment.repo.ts
|
|
221
182
|
var rowToComment = (row) => ({
|
|
222
183
|
content: row.content,
|
|
223
184
|
createdAt: row.created_at,
|
|
@@ -353,8 +314,49 @@ var CommentRepo = class extends Effect4.Service()(
|
|
|
353
314
|
}
|
|
354
315
|
) {
|
|
355
316
|
};
|
|
317
|
+
var CommentId = Schema3.String.pipe(Schema3.brand("CommentId"));
|
|
318
|
+
var LineType = Schema3.Literal("added", "removed", "context");
|
|
319
|
+
Schema3.Struct({
|
|
320
|
+
content: Schema3.String,
|
|
321
|
+
createdAt: Schema3.String,
|
|
322
|
+
filePath: Schema3.String,
|
|
323
|
+
id: CommentId,
|
|
324
|
+
lineNumber: Schema3.NullOr(Schema3.Number),
|
|
325
|
+
lineType: Schema3.NullOr(LineType),
|
|
326
|
+
resolved: Schema3.Boolean,
|
|
327
|
+
reviewId: ReviewId,
|
|
328
|
+
suggestion: Schema3.NullOr(Schema3.String),
|
|
329
|
+
updatedAt: Schema3.String
|
|
330
|
+
});
|
|
331
|
+
Schema3.Struct({
|
|
332
|
+
content: Schema3.String.pipe(Schema3.minLength(1)),
|
|
333
|
+
filePath: Schema3.String.pipe(Schema3.minLength(1)),
|
|
334
|
+
lineNumber: Schema3.optionalWith(Schema3.NullOr(Schema3.Number), {
|
|
335
|
+
default: () => null
|
|
336
|
+
}),
|
|
337
|
+
lineType: Schema3.optionalWith(Schema3.NullOr(LineType), {
|
|
338
|
+
default: () => null
|
|
339
|
+
}),
|
|
340
|
+
suggestion: Schema3.optionalWith(Schema3.NullOr(Schema3.String), {
|
|
341
|
+
default: () => null
|
|
342
|
+
})
|
|
343
|
+
});
|
|
344
|
+
Schema3.Struct({
|
|
345
|
+
content: Schema3.optionalWith(Schema3.String.pipe(Schema3.minLength(1)), {
|
|
346
|
+
as: "Option"
|
|
347
|
+
}),
|
|
348
|
+
suggestion: Schema3.optionalWith(Schema3.NullOr(Schema3.String), {
|
|
349
|
+
as: "Option"
|
|
350
|
+
})
|
|
351
|
+
});
|
|
352
|
+
var CommentNotFound = class extends Schema3.TaggedError()(
|
|
353
|
+
"CommentNotFound",
|
|
354
|
+
{ id: CommentId },
|
|
355
|
+
HttpApiSchema.annotations({ status: 404 })
|
|
356
|
+
) {
|
|
357
|
+
};
|
|
356
358
|
|
|
357
|
-
//
|
|
359
|
+
// ../../packages/core/src/services/comment.service.ts
|
|
358
360
|
var CommentService = class extends Effect4.Service()(
|
|
359
361
|
"@ringi/CommentService",
|
|
360
362
|
{
|
|
@@ -408,7 +410,7 @@ var CommentService = class extends Effect4.Service()(
|
|
|
408
410
|
}
|
|
409
411
|
return comment;
|
|
410
412
|
});
|
|
411
|
-
const
|
|
413
|
+
const resolve3 = Effect4.fn("CommentService.resolve")(function* resolve4(id) {
|
|
412
414
|
const repo = yield* CommentRepo;
|
|
413
415
|
const comment = yield* repo.setResolved(id, true);
|
|
414
416
|
if (!comment) {
|
|
@@ -445,7 +447,7 @@ var CommentService = class extends Effect4.Service()(
|
|
|
445
447
|
getByReview,
|
|
446
448
|
getStats,
|
|
447
449
|
remove,
|
|
448
|
-
resolve,
|
|
450
|
+
resolve: resolve3,
|
|
449
451
|
unresolve,
|
|
450
452
|
update
|
|
451
453
|
};
|
|
@@ -454,7 +456,7 @@ var CommentService = class extends Effect4.Service()(
|
|
|
454
456
|
) {
|
|
455
457
|
};
|
|
456
458
|
|
|
457
|
-
//
|
|
459
|
+
// ../../packages/core/src/services/diff.service.ts
|
|
458
460
|
var HUNK_HEADER = /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
459
461
|
var splitIntoFiles = (diffText) => {
|
|
460
462
|
const files = [];
|
|
@@ -597,21 +599,44 @@ var GitError = class extends Schema3.TaggedError()(
|
|
|
597
599
|
HttpApiSchema.annotations({ status: 500 })
|
|
598
600
|
) {
|
|
599
601
|
};
|
|
602
|
+
var MAX_STDOUT_BYTES = 200 * 1024 * 1024;
|
|
600
603
|
var execGit = (args, repoPath) => Effect4.tryPromise({
|
|
601
604
|
catch: (error) => new GitError({ message: String(error) }),
|
|
602
|
-
try: () => new Promise((
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
} else {
|
|
611
|
-
resolve(stdout);
|
|
612
|
-
}
|
|
605
|
+
try: () => new Promise((resolve3, reject) => {
|
|
606
|
+
const child = spawn("git", [...args], { cwd: repoPath });
|
|
607
|
+
const chunks = [];
|
|
608
|
+
let bytes = 0;
|
|
609
|
+
let truncated = false;
|
|
610
|
+
child.stdout.on("data", (chunk) => {
|
|
611
|
+
if (truncated) {
|
|
612
|
+
return;
|
|
613
613
|
}
|
|
614
|
-
|
|
614
|
+
bytes += chunk.length;
|
|
615
|
+
if (bytes > MAX_STDOUT_BYTES) {
|
|
616
|
+
truncated = true;
|
|
617
|
+
child.kill();
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
chunks.push(chunk);
|
|
621
|
+
});
|
|
622
|
+
let stderr = "";
|
|
623
|
+
child.stderr.on("data", (chunk) => {
|
|
624
|
+
stderr += chunk.toString();
|
|
625
|
+
});
|
|
626
|
+
child.on("error", reject);
|
|
627
|
+
child.on("close", (code) => {
|
|
628
|
+
if (truncated) {
|
|
629
|
+
resolve3(Buffer.concat(chunks).toString("utf8"));
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (code !== 0) {
|
|
633
|
+
reject(
|
|
634
|
+
new Error(`git ${args[0]} exited with code ${code}: ${stderr}`)
|
|
635
|
+
);
|
|
636
|
+
} else {
|
|
637
|
+
resolve3(Buffer.concat(chunks).toString("utf8"));
|
|
638
|
+
}
|
|
639
|
+
});
|
|
615
640
|
})
|
|
616
641
|
});
|
|
617
642
|
var lines = (output) => output.trim().split("\n").filter(Boolean);
|
|
@@ -1031,7 +1056,7 @@ var ReviewRepo = class extends Effect4.Service()(
|
|
|
1031
1056
|
) {
|
|
1032
1057
|
};
|
|
1033
1058
|
|
|
1034
|
-
//
|
|
1059
|
+
// ../../packages/core/src/services/review.service.ts
|
|
1035
1060
|
var ReviewError = class extends Schema3.TaggedError()(
|
|
1036
1061
|
"ReviewError",
|
|
1037
1062
|
{ code: Schema3.String, message: Schema3.String },
|
|
@@ -1040,7 +1065,7 @@ var ReviewError = class extends Schema3.TaggedError()(
|
|
|
1040
1065
|
};
|
|
1041
1066
|
var getHeadSha = (repoPath) => Effect4.tryPromise({
|
|
1042
1067
|
catch: () => new ReviewError({ code: "GIT_ERROR", message: "Failed to get HEAD" }),
|
|
1043
|
-
try: () => new Promise((
|
|
1068
|
+
try: () => new Promise((resolve3, reject) => {
|
|
1044
1069
|
execFile(
|
|
1045
1070
|
"git",
|
|
1046
1071
|
["rev-parse", "HEAD"],
|
|
@@ -1049,7 +1074,7 @@ var getHeadSha = (repoPath) => Effect4.tryPromise({
|
|
|
1049
1074
|
if (err) {
|
|
1050
1075
|
reject(err);
|
|
1051
1076
|
} else {
|
|
1052
|
-
|
|
1077
|
+
resolve3(stdout.trim());
|
|
1053
1078
|
}
|
|
1054
1079
|
}
|
|
1055
1080
|
);
|
|
@@ -1491,7 +1516,7 @@ var TodoRepo = class extends Effect4.Service()("@ringi/TodoRepo", {
|
|
|
1491
1516
|
}) {
|
|
1492
1517
|
};
|
|
1493
1518
|
|
|
1494
|
-
//
|
|
1519
|
+
// ../../packages/core/src/services/todo.service.ts
|
|
1495
1520
|
var TodoService = class extends Effect4.Service()(
|
|
1496
1521
|
"@ringi/TodoService",
|
|
1497
1522
|
{
|
|
@@ -1696,6 +1721,1720 @@ var ExportService = class extends Effect4.Service()(
|
|
|
1696
1721
|
}
|
|
1697
1722
|
) {
|
|
1698
1723
|
};
|
|
1724
|
+
var EntryTypes = {
|
|
1725
|
+
FILE_TYPE: "files",
|
|
1726
|
+
DIR_TYPE: "directories",
|
|
1727
|
+
FILE_DIR_TYPE: "files_directories",
|
|
1728
|
+
EVERYTHING_TYPE: "all"
|
|
1729
|
+
};
|
|
1730
|
+
var defaultOptions = {
|
|
1731
|
+
root: ".",
|
|
1732
|
+
fileFilter: (_entryInfo) => true,
|
|
1733
|
+
directoryFilter: (_entryInfo) => true,
|
|
1734
|
+
type: EntryTypes.FILE_TYPE,
|
|
1735
|
+
lstat: false,
|
|
1736
|
+
depth: 2147483648,
|
|
1737
|
+
alwaysStat: false,
|
|
1738
|
+
highWaterMark: 4096
|
|
1739
|
+
};
|
|
1740
|
+
Object.freeze(defaultOptions);
|
|
1741
|
+
var RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
|
|
1742
|
+
var NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EPERM", "EACCES", "ELOOP", RECURSIVE_ERROR_CODE]);
|
|
1743
|
+
var ALL_TYPES = [
|
|
1744
|
+
EntryTypes.DIR_TYPE,
|
|
1745
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1746
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
1747
|
+
EntryTypes.FILE_TYPE
|
|
1748
|
+
];
|
|
1749
|
+
var DIR_TYPES = /* @__PURE__ */ new Set([
|
|
1750
|
+
EntryTypes.DIR_TYPE,
|
|
1751
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1752
|
+
EntryTypes.FILE_DIR_TYPE
|
|
1753
|
+
]);
|
|
1754
|
+
var FILE_TYPES = /* @__PURE__ */ new Set([
|
|
1755
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1756
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
1757
|
+
EntryTypes.FILE_TYPE
|
|
1758
|
+
]);
|
|
1759
|
+
var isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
|
1760
|
+
var wantBigintFsStats = process.platform === "win32";
|
|
1761
|
+
var emptyFn = (_entryInfo) => true;
|
|
1762
|
+
var normalizeFilter = (filter) => {
|
|
1763
|
+
if (filter === void 0)
|
|
1764
|
+
return emptyFn;
|
|
1765
|
+
if (typeof filter === "function")
|
|
1766
|
+
return filter;
|
|
1767
|
+
if (typeof filter === "string") {
|
|
1768
|
+
const fl = filter.trim();
|
|
1769
|
+
return (entry) => entry.basename === fl;
|
|
1770
|
+
}
|
|
1771
|
+
if (Array.isArray(filter)) {
|
|
1772
|
+
const trItems = filter.map((item) => item.trim());
|
|
1773
|
+
return (entry) => trItems.some((f) => entry.basename === f);
|
|
1774
|
+
}
|
|
1775
|
+
return emptyFn;
|
|
1776
|
+
};
|
|
1777
|
+
var ReaddirpStream = class extends Readable {
|
|
1778
|
+
parents;
|
|
1779
|
+
reading;
|
|
1780
|
+
parent;
|
|
1781
|
+
_stat;
|
|
1782
|
+
_maxDepth;
|
|
1783
|
+
_wantsDir;
|
|
1784
|
+
_wantsFile;
|
|
1785
|
+
_wantsEverything;
|
|
1786
|
+
_root;
|
|
1787
|
+
_isDirent;
|
|
1788
|
+
_statsProp;
|
|
1789
|
+
_rdOptions;
|
|
1790
|
+
_fileFilter;
|
|
1791
|
+
_directoryFilter;
|
|
1792
|
+
constructor(options = {}) {
|
|
1793
|
+
super({
|
|
1794
|
+
objectMode: true,
|
|
1795
|
+
autoDestroy: true,
|
|
1796
|
+
highWaterMark: options.highWaterMark
|
|
1797
|
+
});
|
|
1798
|
+
const opts = { ...defaultOptions, ...options };
|
|
1799
|
+
const { root, type } = opts;
|
|
1800
|
+
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
1801
|
+
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
1802
|
+
const statMethod = opts.lstat ? lstat : stat;
|
|
1803
|
+
if (wantBigintFsStats) {
|
|
1804
|
+
this._stat = (path) => statMethod(path, { bigint: true });
|
|
1805
|
+
} else {
|
|
1806
|
+
this._stat = statMethod;
|
|
1807
|
+
}
|
|
1808
|
+
this._maxDepth = opts.depth != null && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth;
|
|
1809
|
+
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
|
1810
|
+
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
|
1811
|
+
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
|
1812
|
+
this._root = resolve(root);
|
|
1813
|
+
this._isDirent = !opts.alwaysStat;
|
|
1814
|
+
this._statsProp = this._isDirent ? "dirent" : "stats";
|
|
1815
|
+
this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
|
|
1816
|
+
this.parents = [this._exploreDir(root, 1)];
|
|
1817
|
+
this.reading = false;
|
|
1818
|
+
this.parent = void 0;
|
|
1819
|
+
}
|
|
1820
|
+
async _read(batch) {
|
|
1821
|
+
if (this.reading)
|
|
1822
|
+
return;
|
|
1823
|
+
this.reading = true;
|
|
1824
|
+
try {
|
|
1825
|
+
while (!this.destroyed && batch > 0) {
|
|
1826
|
+
const par = this.parent;
|
|
1827
|
+
const fil = par && par.files;
|
|
1828
|
+
if (fil && fil.length > 0) {
|
|
1829
|
+
const { path, depth } = par;
|
|
1830
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
|
1831
|
+
const awaited = await Promise.all(slice);
|
|
1832
|
+
for (const entry of awaited) {
|
|
1833
|
+
if (!entry)
|
|
1834
|
+
continue;
|
|
1835
|
+
if (this.destroyed)
|
|
1836
|
+
return;
|
|
1837
|
+
const entryType = await this._getEntryType(entry);
|
|
1838
|
+
if (entryType === "directory" && this._directoryFilter(entry)) {
|
|
1839
|
+
if (depth <= this._maxDepth) {
|
|
1840
|
+
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
|
1841
|
+
}
|
|
1842
|
+
if (this._wantsDir) {
|
|
1843
|
+
this.push(entry);
|
|
1844
|
+
batch--;
|
|
1845
|
+
}
|
|
1846
|
+
} else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
|
|
1847
|
+
if (this._wantsFile) {
|
|
1848
|
+
this.push(entry);
|
|
1849
|
+
batch--;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
} else {
|
|
1854
|
+
const parent = this.parents.pop();
|
|
1855
|
+
if (!parent) {
|
|
1856
|
+
this.push(null);
|
|
1857
|
+
break;
|
|
1858
|
+
}
|
|
1859
|
+
this.parent = await parent;
|
|
1860
|
+
if (this.destroyed)
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
} catch (error) {
|
|
1865
|
+
this.destroy(error);
|
|
1866
|
+
} finally {
|
|
1867
|
+
this.reading = false;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
async _exploreDir(path, depth) {
|
|
1871
|
+
let files;
|
|
1872
|
+
try {
|
|
1873
|
+
files = await readdir(path, this._rdOptions);
|
|
1874
|
+
} catch (error) {
|
|
1875
|
+
this._onError(error);
|
|
1876
|
+
}
|
|
1877
|
+
return { files, depth, path };
|
|
1878
|
+
}
|
|
1879
|
+
async _formatEntry(dirent, path) {
|
|
1880
|
+
let entry;
|
|
1881
|
+
const basename3 = this._isDirent ? dirent.name : dirent;
|
|
1882
|
+
try {
|
|
1883
|
+
const fullPath = resolve(join(path, basename3));
|
|
1884
|
+
entry = { path: relative(this._root, fullPath), fullPath, basename: basename3 };
|
|
1885
|
+
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
1886
|
+
} catch (err) {
|
|
1887
|
+
this._onError(err);
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
return entry;
|
|
1891
|
+
}
|
|
1892
|
+
_onError(err) {
|
|
1893
|
+
if (isNormalFlowError(err) && !this.destroyed) {
|
|
1894
|
+
this.emit("warn", err);
|
|
1895
|
+
} else {
|
|
1896
|
+
this.destroy(err);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
async _getEntryType(entry) {
|
|
1900
|
+
if (!entry && this._statsProp in entry) {
|
|
1901
|
+
return "";
|
|
1902
|
+
}
|
|
1903
|
+
const stats = entry[this._statsProp];
|
|
1904
|
+
if (stats.isFile())
|
|
1905
|
+
return "file";
|
|
1906
|
+
if (stats.isDirectory())
|
|
1907
|
+
return "directory";
|
|
1908
|
+
if (stats && stats.isSymbolicLink()) {
|
|
1909
|
+
const full = entry.fullPath;
|
|
1910
|
+
try {
|
|
1911
|
+
const entryRealPath = await realpath(full);
|
|
1912
|
+
const entryRealPathStats = await lstat(entryRealPath);
|
|
1913
|
+
if (entryRealPathStats.isFile()) {
|
|
1914
|
+
return "file";
|
|
1915
|
+
}
|
|
1916
|
+
if (entryRealPathStats.isDirectory()) {
|
|
1917
|
+
const len = entryRealPath.length;
|
|
1918
|
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === sep) {
|
|
1919
|
+
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
1920
|
+
recursiveError.code = RECURSIVE_ERROR_CODE;
|
|
1921
|
+
return this._onError(recursiveError);
|
|
1922
|
+
}
|
|
1923
|
+
return "directory";
|
|
1924
|
+
}
|
|
1925
|
+
} catch (error) {
|
|
1926
|
+
this._onError(error);
|
|
1927
|
+
return "";
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
_includeAsFile(entry) {
|
|
1932
|
+
const stats = entry && entry[this._statsProp];
|
|
1933
|
+
return stats && this._wantsEverything && !stats.isDirectory();
|
|
1934
|
+
}
|
|
1935
|
+
};
|
|
1936
|
+
function readdirp(root, options = {}) {
|
|
1937
|
+
let type = options.entryType || options.type;
|
|
1938
|
+
if (type === "both")
|
|
1939
|
+
type = EntryTypes.FILE_DIR_TYPE;
|
|
1940
|
+
if (type)
|
|
1941
|
+
options.type = type;
|
|
1942
|
+
if (!root) {
|
|
1943
|
+
throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
|
|
1944
|
+
} else if (typeof root !== "string") {
|
|
1945
|
+
throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
|
|
1946
|
+
} else if (type && !ALL_TYPES.includes(type)) {
|
|
1947
|
+
throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
|
|
1948
|
+
}
|
|
1949
|
+
options.root = root;
|
|
1950
|
+
return new ReaddirpStream(options);
|
|
1951
|
+
}
|
|
1952
|
+
var STR_DATA = "data";
|
|
1953
|
+
var STR_END = "end";
|
|
1954
|
+
var STR_CLOSE = "close";
|
|
1955
|
+
var EMPTY_FN = () => {
|
|
1956
|
+
};
|
|
1957
|
+
var pl = process.platform;
|
|
1958
|
+
var isWindows = pl === "win32";
|
|
1959
|
+
var isMacos = pl === "darwin";
|
|
1960
|
+
var isLinux = pl === "linux";
|
|
1961
|
+
var isFreeBSD = pl === "freebsd";
|
|
1962
|
+
var isIBMi = type() === "OS400";
|
|
1963
|
+
var EVENTS = {
|
|
1964
|
+
ALL: "all",
|
|
1965
|
+
READY: "ready",
|
|
1966
|
+
ADD: "add",
|
|
1967
|
+
CHANGE: "change",
|
|
1968
|
+
ADD_DIR: "addDir",
|
|
1969
|
+
UNLINK: "unlink",
|
|
1970
|
+
UNLINK_DIR: "unlinkDir",
|
|
1971
|
+
RAW: "raw",
|
|
1972
|
+
ERROR: "error"
|
|
1973
|
+
};
|
|
1974
|
+
var EV = EVENTS;
|
|
1975
|
+
var THROTTLE_MODE_WATCH = "watch";
|
|
1976
|
+
var statMethods = { lstat: lstat, stat: stat };
|
|
1977
|
+
var KEY_LISTENERS = "listeners";
|
|
1978
|
+
var KEY_ERR = "errHandlers";
|
|
1979
|
+
var KEY_RAW = "rawEmitters";
|
|
1980
|
+
var HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
1981
|
+
var binaryExtensions = /* @__PURE__ */ new Set([
|
|
1982
|
+
"3dm",
|
|
1983
|
+
"3ds",
|
|
1984
|
+
"3g2",
|
|
1985
|
+
"3gp",
|
|
1986
|
+
"7z",
|
|
1987
|
+
"a",
|
|
1988
|
+
"aac",
|
|
1989
|
+
"adp",
|
|
1990
|
+
"afdesign",
|
|
1991
|
+
"afphoto",
|
|
1992
|
+
"afpub",
|
|
1993
|
+
"ai",
|
|
1994
|
+
"aif",
|
|
1995
|
+
"aiff",
|
|
1996
|
+
"alz",
|
|
1997
|
+
"ape",
|
|
1998
|
+
"apk",
|
|
1999
|
+
"appimage",
|
|
2000
|
+
"ar",
|
|
2001
|
+
"arj",
|
|
2002
|
+
"asf",
|
|
2003
|
+
"au",
|
|
2004
|
+
"avi",
|
|
2005
|
+
"bak",
|
|
2006
|
+
"baml",
|
|
2007
|
+
"bh",
|
|
2008
|
+
"bin",
|
|
2009
|
+
"bk",
|
|
2010
|
+
"bmp",
|
|
2011
|
+
"btif",
|
|
2012
|
+
"bz2",
|
|
2013
|
+
"bzip2",
|
|
2014
|
+
"cab",
|
|
2015
|
+
"caf",
|
|
2016
|
+
"cgm",
|
|
2017
|
+
"class",
|
|
2018
|
+
"cmx",
|
|
2019
|
+
"cpio",
|
|
2020
|
+
"cr2",
|
|
2021
|
+
"cur",
|
|
2022
|
+
"dat",
|
|
2023
|
+
"dcm",
|
|
2024
|
+
"deb",
|
|
2025
|
+
"dex",
|
|
2026
|
+
"djvu",
|
|
2027
|
+
"dll",
|
|
2028
|
+
"dmg",
|
|
2029
|
+
"dng",
|
|
2030
|
+
"doc",
|
|
2031
|
+
"docm",
|
|
2032
|
+
"docx",
|
|
2033
|
+
"dot",
|
|
2034
|
+
"dotm",
|
|
2035
|
+
"dra",
|
|
2036
|
+
"DS_Store",
|
|
2037
|
+
"dsk",
|
|
2038
|
+
"dts",
|
|
2039
|
+
"dtshd",
|
|
2040
|
+
"dvb",
|
|
2041
|
+
"dwg",
|
|
2042
|
+
"dxf",
|
|
2043
|
+
"ecelp4800",
|
|
2044
|
+
"ecelp7470",
|
|
2045
|
+
"ecelp9600",
|
|
2046
|
+
"egg",
|
|
2047
|
+
"eol",
|
|
2048
|
+
"eot",
|
|
2049
|
+
"epub",
|
|
2050
|
+
"exe",
|
|
2051
|
+
"f4v",
|
|
2052
|
+
"fbs",
|
|
2053
|
+
"fh",
|
|
2054
|
+
"fla",
|
|
2055
|
+
"flac",
|
|
2056
|
+
"flatpak",
|
|
2057
|
+
"fli",
|
|
2058
|
+
"flv",
|
|
2059
|
+
"fpx",
|
|
2060
|
+
"fst",
|
|
2061
|
+
"fvt",
|
|
2062
|
+
"g3",
|
|
2063
|
+
"gh",
|
|
2064
|
+
"gif",
|
|
2065
|
+
"graffle",
|
|
2066
|
+
"gz",
|
|
2067
|
+
"gzip",
|
|
2068
|
+
"h261",
|
|
2069
|
+
"h263",
|
|
2070
|
+
"h264",
|
|
2071
|
+
"icns",
|
|
2072
|
+
"ico",
|
|
2073
|
+
"ief",
|
|
2074
|
+
"img",
|
|
2075
|
+
"ipa",
|
|
2076
|
+
"iso",
|
|
2077
|
+
"jar",
|
|
2078
|
+
"jpeg",
|
|
2079
|
+
"jpg",
|
|
2080
|
+
"jpgv",
|
|
2081
|
+
"jpm",
|
|
2082
|
+
"jxr",
|
|
2083
|
+
"key",
|
|
2084
|
+
"ktx",
|
|
2085
|
+
"lha",
|
|
2086
|
+
"lib",
|
|
2087
|
+
"lvp",
|
|
2088
|
+
"lz",
|
|
2089
|
+
"lzh",
|
|
2090
|
+
"lzma",
|
|
2091
|
+
"lzo",
|
|
2092
|
+
"m3u",
|
|
2093
|
+
"m4a",
|
|
2094
|
+
"m4v",
|
|
2095
|
+
"mar",
|
|
2096
|
+
"mdi",
|
|
2097
|
+
"mht",
|
|
2098
|
+
"mid",
|
|
2099
|
+
"midi",
|
|
2100
|
+
"mj2",
|
|
2101
|
+
"mka",
|
|
2102
|
+
"mkv",
|
|
2103
|
+
"mmr",
|
|
2104
|
+
"mng",
|
|
2105
|
+
"mobi",
|
|
2106
|
+
"mov",
|
|
2107
|
+
"movie",
|
|
2108
|
+
"mp3",
|
|
2109
|
+
"mp4",
|
|
2110
|
+
"mp4a",
|
|
2111
|
+
"mpeg",
|
|
2112
|
+
"mpg",
|
|
2113
|
+
"mpga",
|
|
2114
|
+
"mxu",
|
|
2115
|
+
"nef",
|
|
2116
|
+
"npx",
|
|
2117
|
+
"numbers",
|
|
2118
|
+
"nupkg",
|
|
2119
|
+
"o",
|
|
2120
|
+
"odp",
|
|
2121
|
+
"ods",
|
|
2122
|
+
"odt",
|
|
2123
|
+
"oga",
|
|
2124
|
+
"ogg",
|
|
2125
|
+
"ogv",
|
|
2126
|
+
"otf",
|
|
2127
|
+
"ott",
|
|
2128
|
+
"pages",
|
|
2129
|
+
"pbm",
|
|
2130
|
+
"pcx",
|
|
2131
|
+
"pdb",
|
|
2132
|
+
"pdf",
|
|
2133
|
+
"pea",
|
|
2134
|
+
"pgm",
|
|
2135
|
+
"pic",
|
|
2136
|
+
"png",
|
|
2137
|
+
"pnm",
|
|
2138
|
+
"pot",
|
|
2139
|
+
"potm",
|
|
2140
|
+
"potx",
|
|
2141
|
+
"ppa",
|
|
2142
|
+
"ppam",
|
|
2143
|
+
"ppm",
|
|
2144
|
+
"pps",
|
|
2145
|
+
"ppsm",
|
|
2146
|
+
"ppsx",
|
|
2147
|
+
"ppt",
|
|
2148
|
+
"pptm",
|
|
2149
|
+
"pptx",
|
|
2150
|
+
"psd",
|
|
2151
|
+
"pya",
|
|
2152
|
+
"pyc",
|
|
2153
|
+
"pyo",
|
|
2154
|
+
"pyv",
|
|
2155
|
+
"qt",
|
|
2156
|
+
"rar",
|
|
2157
|
+
"ras",
|
|
2158
|
+
"raw",
|
|
2159
|
+
"resources",
|
|
2160
|
+
"rgb",
|
|
2161
|
+
"rip",
|
|
2162
|
+
"rlc",
|
|
2163
|
+
"rmf",
|
|
2164
|
+
"rmvb",
|
|
2165
|
+
"rpm",
|
|
2166
|
+
"rtf",
|
|
2167
|
+
"rz",
|
|
2168
|
+
"s3m",
|
|
2169
|
+
"s7z",
|
|
2170
|
+
"scpt",
|
|
2171
|
+
"sgi",
|
|
2172
|
+
"shar",
|
|
2173
|
+
"snap",
|
|
2174
|
+
"sil",
|
|
2175
|
+
"sketch",
|
|
2176
|
+
"slk",
|
|
2177
|
+
"smv",
|
|
2178
|
+
"snk",
|
|
2179
|
+
"so",
|
|
2180
|
+
"stl",
|
|
2181
|
+
"suo",
|
|
2182
|
+
"sub",
|
|
2183
|
+
"swf",
|
|
2184
|
+
"tar",
|
|
2185
|
+
"tbz",
|
|
2186
|
+
"tbz2",
|
|
2187
|
+
"tga",
|
|
2188
|
+
"tgz",
|
|
2189
|
+
"thmx",
|
|
2190
|
+
"tif",
|
|
2191
|
+
"tiff",
|
|
2192
|
+
"tlz",
|
|
2193
|
+
"ttc",
|
|
2194
|
+
"ttf",
|
|
2195
|
+
"txz",
|
|
2196
|
+
"udf",
|
|
2197
|
+
"uvh",
|
|
2198
|
+
"uvi",
|
|
2199
|
+
"uvm",
|
|
2200
|
+
"uvp",
|
|
2201
|
+
"uvs",
|
|
2202
|
+
"uvu",
|
|
2203
|
+
"viv",
|
|
2204
|
+
"vob",
|
|
2205
|
+
"war",
|
|
2206
|
+
"wav",
|
|
2207
|
+
"wax",
|
|
2208
|
+
"wbmp",
|
|
2209
|
+
"wdp",
|
|
2210
|
+
"weba",
|
|
2211
|
+
"webm",
|
|
2212
|
+
"webp",
|
|
2213
|
+
"whl",
|
|
2214
|
+
"wim",
|
|
2215
|
+
"wm",
|
|
2216
|
+
"wma",
|
|
2217
|
+
"wmv",
|
|
2218
|
+
"wmx",
|
|
2219
|
+
"woff",
|
|
2220
|
+
"woff2",
|
|
2221
|
+
"wrm",
|
|
2222
|
+
"wvx",
|
|
2223
|
+
"xbm",
|
|
2224
|
+
"xif",
|
|
2225
|
+
"xla",
|
|
2226
|
+
"xlam",
|
|
2227
|
+
"xls",
|
|
2228
|
+
"xlsb",
|
|
2229
|
+
"xlsm",
|
|
2230
|
+
"xlsx",
|
|
2231
|
+
"xlt",
|
|
2232
|
+
"xltm",
|
|
2233
|
+
"xltx",
|
|
2234
|
+
"xm",
|
|
2235
|
+
"xmind",
|
|
2236
|
+
"xpi",
|
|
2237
|
+
"xpm",
|
|
2238
|
+
"xwd",
|
|
2239
|
+
"xz",
|
|
2240
|
+
"z",
|
|
2241
|
+
"zip",
|
|
2242
|
+
"zipx"
|
|
2243
|
+
]);
|
|
2244
|
+
var isBinaryPath = (filePath) => binaryExtensions.has(sp2.extname(filePath).slice(1).toLowerCase());
|
|
2245
|
+
var foreach = (val, fn7) => {
|
|
2246
|
+
if (val instanceof Set) {
|
|
2247
|
+
val.forEach(fn7);
|
|
2248
|
+
} else {
|
|
2249
|
+
fn7(val);
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
var addAndConvert = (main, prop, item) => {
|
|
2253
|
+
let container = main[prop];
|
|
2254
|
+
if (!(container instanceof Set)) {
|
|
2255
|
+
main[prop] = container = /* @__PURE__ */ new Set([container]);
|
|
2256
|
+
}
|
|
2257
|
+
container.add(item);
|
|
2258
|
+
};
|
|
2259
|
+
var clearItem = (cont) => (key) => {
|
|
2260
|
+
const set = cont[key];
|
|
2261
|
+
if (set instanceof Set) {
|
|
2262
|
+
set.clear();
|
|
2263
|
+
} else {
|
|
2264
|
+
delete cont[key];
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
var delFromSet = (main, prop, item) => {
|
|
2268
|
+
const container = main[prop];
|
|
2269
|
+
if (container instanceof Set) {
|
|
2270
|
+
container.delete(item);
|
|
2271
|
+
} else if (container === item) {
|
|
2272
|
+
delete main[prop];
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
2276
|
+
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
2277
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
2278
|
+
const handleEvent = (rawEvent, evPath) => {
|
|
2279
|
+
listener(path);
|
|
2280
|
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
2281
|
+
if (evPath && path !== evPath) {
|
|
2282
|
+
fsWatchBroadcast(sp2.resolve(path, evPath), KEY_LISTENERS, sp2.join(path, evPath));
|
|
2283
|
+
}
|
|
2284
|
+
};
|
|
2285
|
+
try {
|
|
2286
|
+
return watch$1(path, {
|
|
2287
|
+
persistent: options.persistent
|
|
2288
|
+
}, handleEvent);
|
|
2289
|
+
} catch (error) {
|
|
2290
|
+
errHandler(error);
|
|
2291
|
+
return void 0;
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
2295
|
+
const cont = FsWatchInstances.get(fullPath);
|
|
2296
|
+
if (!cont)
|
|
2297
|
+
return;
|
|
2298
|
+
foreach(cont[listenerType], (listener) => {
|
|
2299
|
+
listener(val1, val2, val3);
|
|
2300
|
+
});
|
|
2301
|
+
};
|
|
2302
|
+
var setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
2303
|
+
const { listener, errHandler, rawEmitter } = handlers;
|
|
2304
|
+
let cont = FsWatchInstances.get(fullPath);
|
|
2305
|
+
let watcher;
|
|
2306
|
+
if (!options.persistent) {
|
|
2307
|
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
2308
|
+
if (!watcher)
|
|
2309
|
+
return;
|
|
2310
|
+
return watcher.close.bind(watcher);
|
|
2311
|
+
}
|
|
2312
|
+
if (cont) {
|
|
2313
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
2314
|
+
addAndConvert(cont, KEY_ERR, errHandler);
|
|
2315
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
2316
|
+
} else {
|
|
2317
|
+
watcher = createFsWatchInstance(
|
|
2318
|
+
path,
|
|
2319
|
+
options,
|
|
2320
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
2321
|
+
errHandler,
|
|
2322
|
+
// no need to use broadcast here
|
|
2323
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
|
|
2324
|
+
);
|
|
2325
|
+
if (!watcher)
|
|
2326
|
+
return;
|
|
2327
|
+
watcher.on(EV.ERROR, async (error) => {
|
|
2328
|
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
2329
|
+
if (cont)
|
|
2330
|
+
cont.watcherUnusable = true;
|
|
2331
|
+
if (isWindows && error.code === "EPERM") {
|
|
2332
|
+
try {
|
|
2333
|
+
const fd = await open(path, "r");
|
|
2334
|
+
await fd.close();
|
|
2335
|
+
broadcastErr(error);
|
|
2336
|
+
} catch (err) {
|
|
2337
|
+
}
|
|
2338
|
+
} else {
|
|
2339
|
+
broadcastErr(error);
|
|
2340
|
+
}
|
|
2341
|
+
});
|
|
2342
|
+
cont = {
|
|
2343
|
+
listeners: listener,
|
|
2344
|
+
errHandlers: errHandler,
|
|
2345
|
+
rawEmitters: rawEmitter,
|
|
2346
|
+
watcher
|
|
2347
|
+
};
|
|
2348
|
+
FsWatchInstances.set(fullPath, cont);
|
|
2349
|
+
}
|
|
2350
|
+
return () => {
|
|
2351
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
2352
|
+
delFromSet(cont, KEY_ERR, errHandler);
|
|
2353
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2354
|
+
if (isEmptySet(cont.listeners)) {
|
|
2355
|
+
cont.watcher.close();
|
|
2356
|
+
FsWatchInstances.delete(fullPath);
|
|
2357
|
+
HANDLER_KEYS.forEach(clearItem(cont));
|
|
2358
|
+
cont.watcher = void 0;
|
|
2359
|
+
Object.freeze(cont);
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2362
|
+
};
|
|
2363
|
+
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
2364
|
+
var setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
2365
|
+
const { listener, rawEmitter } = handlers;
|
|
2366
|
+
let cont = FsWatchFileInstances.get(fullPath);
|
|
2367
|
+
const copts = cont && cont.options;
|
|
2368
|
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
2369
|
+
unwatchFile(fullPath);
|
|
2370
|
+
cont = void 0;
|
|
2371
|
+
}
|
|
2372
|
+
if (cont) {
|
|
2373
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
2374
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
2375
|
+
} else {
|
|
2376
|
+
cont = {
|
|
2377
|
+
listeners: listener,
|
|
2378
|
+
rawEmitters: rawEmitter,
|
|
2379
|
+
options,
|
|
2380
|
+
watcher: watchFile(fullPath, options, (curr, prev) => {
|
|
2381
|
+
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
2382
|
+
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
2383
|
+
});
|
|
2384
|
+
const currmtime = curr.mtimeMs;
|
|
2385
|
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
2386
|
+
foreach(cont.listeners, (listener2) => listener2(path, curr));
|
|
2387
|
+
}
|
|
2388
|
+
})
|
|
2389
|
+
};
|
|
2390
|
+
FsWatchFileInstances.set(fullPath, cont);
|
|
2391
|
+
}
|
|
2392
|
+
return () => {
|
|
2393
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
2394
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2395
|
+
if (isEmptySet(cont.listeners)) {
|
|
2396
|
+
FsWatchFileInstances.delete(fullPath);
|
|
2397
|
+
unwatchFile(fullPath);
|
|
2398
|
+
cont.options = cont.watcher = void 0;
|
|
2399
|
+
Object.freeze(cont);
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
};
|
|
2403
|
+
var NodeFsHandler = class {
|
|
2404
|
+
fsw;
|
|
2405
|
+
_boundHandleError;
|
|
2406
|
+
constructor(fsW) {
|
|
2407
|
+
this.fsw = fsW;
|
|
2408
|
+
this._boundHandleError = (error) => fsW._handleError(error);
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Watch file for changes with fs_watchFile or fs_watch.
|
|
2412
|
+
* @param path to file or dir
|
|
2413
|
+
* @param listener on fs change
|
|
2414
|
+
* @returns closer for the watcher instance
|
|
2415
|
+
*/
|
|
2416
|
+
_watchWithNodeFs(path, listener) {
|
|
2417
|
+
const opts = this.fsw.options;
|
|
2418
|
+
const directory = sp2.dirname(path);
|
|
2419
|
+
const basename3 = sp2.basename(path);
|
|
2420
|
+
const parent = this.fsw._getWatchedDir(directory);
|
|
2421
|
+
parent.add(basename3);
|
|
2422
|
+
const absolutePath = sp2.resolve(path);
|
|
2423
|
+
const options = {
|
|
2424
|
+
persistent: opts.persistent
|
|
2425
|
+
};
|
|
2426
|
+
if (!listener)
|
|
2427
|
+
listener = EMPTY_FN;
|
|
2428
|
+
let closer;
|
|
2429
|
+
if (opts.usePolling) {
|
|
2430
|
+
const enableBin = opts.interval !== opts.binaryInterval;
|
|
2431
|
+
options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
|
|
2432
|
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
2433
|
+
listener,
|
|
2434
|
+
rawEmitter: this.fsw._emitRaw
|
|
2435
|
+
});
|
|
2436
|
+
} else {
|
|
2437
|
+
closer = setFsWatchListener(path, absolutePath, options, {
|
|
2438
|
+
listener,
|
|
2439
|
+
errHandler: this._boundHandleError,
|
|
2440
|
+
rawEmitter: this.fsw._emitRaw
|
|
2441
|
+
});
|
|
2442
|
+
}
|
|
2443
|
+
return closer;
|
|
2444
|
+
}
|
|
2445
|
+
/**
|
|
2446
|
+
* Watch a file and emit add event if warranted.
|
|
2447
|
+
* @returns closer for the watcher instance
|
|
2448
|
+
*/
|
|
2449
|
+
_handleFile(file, stats, initialAdd) {
|
|
2450
|
+
if (this.fsw.closed) {
|
|
2451
|
+
return;
|
|
2452
|
+
}
|
|
2453
|
+
const dirname4 = sp2.dirname(file);
|
|
2454
|
+
const basename3 = sp2.basename(file);
|
|
2455
|
+
const parent = this.fsw._getWatchedDir(dirname4);
|
|
2456
|
+
let prevStats = stats;
|
|
2457
|
+
if (parent.has(basename3))
|
|
2458
|
+
return;
|
|
2459
|
+
const listener = async (path, newStats) => {
|
|
2460
|
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
2461
|
+
return;
|
|
2462
|
+
if (!newStats || newStats.mtimeMs === 0) {
|
|
2463
|
+
try {
|
|
2464
|
+
const newStats2 = await stat(file);
|
|
2465
|
+
if (this.fsw.closed)
|
|
2466
|
+
return;
|
|
2467
|
+
const at = newStats2.atimeMs;
|
|
2468
|
+
const mt = newStats2.mtimeMs;
|
|
2469
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
2470
|
+
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
2471
|
+
}
|
|
2472
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
2473
|
+
this.fsw._closeFile(path);
|
|
2474
|
+
prevStats = newStats2;
|
|
2475
|
+
const closer2 = this._watchWithNodeFs(file, listener);
|
|
2476
|
+
if (closer2)
|
|
2477
|
+
this.fsw._addPathCloser(path, closer2);
|
|
2478
|
+
} else {
|
|
2479
|
+
prevStats = newStats2;
|
|
2480
|
+
}
|
|
2481
|
+
} catch (error) {
|
|
2482
|
+
this.fsw._remove(dirname4, basename3);
|
|
2483
|
+
}
|
|
2484
|
+
} else if (parent.has(basename3)) {
|
|
2485
|
+
const at = newStats.atimeMs;
|
|
2486
|
+
const mt = newStats.mtimeMs;
|
|
2487
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
2488
|
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
|
2489
|
+
}
|
|
2490
|
+
prevStats = newStats;
|
|
2491
|
+
}
|
|
2492
|
+
};
|
|
2493
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
2494
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
2495
|
+
if (!this.fsw._throttle(EV.ADD, file, 0))
|
|
2496
|
+
return;
|
|
2497
|
+
this.fsw._emit(EV.ADD, file, stats);
|
|
2498
|
+
}
|
|
2499
|
+
return closer;
|
|
2500
|
+
}
|
|
2501
|
+
/**
|
|
2502
|
+
* Handle symlinks encountered while reading a dir.
|
|
2503
|
+
* @param entry returned by readdirp
|
|
2504
|
+
* @param directory path of dir being read
|
|
2505
|
+
* @param path of this item
|
|
2506
|
+
* @param item basename of this item
|
|
2507
|
+
* @returns true if no more processing is needed for this entry.
|
|
2508
|
+
*/
|
|
2509
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
2510
|
+
if (this.fsw.closed) {
|
|
2511
|
+
return;
|
|
2512
|
+
}
|
|
2513
|
+
const full = entry.fullPath;
|
|
2514
|
+
const dir = this.fsw._getWatchedDir(directory);
|
|
2515
|
+
if (!this.fsw.options.followSymlinks) {
|
|
2516
|
+
this.fsw._incrReadyCount();
|
|
2517
|
+
let linkPath;
|
|
2518
|
+
try {
|
|
2519
|
+
linkPath = await realpath(path);
|
|
2520
|
+
} catch (e) {
|
|
2521
|
+
this.fsw._emitReady();
|
|
2522
|
+
return true;
|
|
2523
|
+
}
|
|
2524
|
+
if (this.fsw.closed)
|
|
2525
|
+
return;
|
|
2526
|
+
if (dir.has(item)) {
|
|
2527
|
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
2528
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
2529
|
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
2530
|
+
}
|
|
2531
|
+
} else {
|
|
2532
|
+
dir.add(item);
|
|
2533
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
2534
|
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
2535
|
+
}
|
|
2536
|
+
this.fsw._emitReady();
|
|
2537
|
+
return true;
|
|
2538
|
+
}
|
|
2539
|
+
if (this.fsw._symlinkPaths.has(full)) {
|
|
2540
|
+
return true;
|
|
2541
|
+
}
|
|
2542
|
+
this.fsw._symlinkPaths.set(full, true);
|
|
2543
|
+
}
|
|
2544
|
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
2545
|
+
directory = sp2.join(directory, "");
|
|
2546
|
+
const throttleKey = target ? `${directory}:${target}` : directory;
|
|
2547
|
+
throttler = this.fsw._throttle("readdir", throttleKey, 1e3);
|
|
2548
|
+
if (!throttler)
|
|
2549
|
+
return;
|
|
2550
|
+
const previous = this.fsw._getWatchedDir(wh.path);
|
|
2551
|
+
const current = /* @__PURE__ */ new Set();
|
|
2552
|
+
let stream = this.fsw._readdirp(directory, {
|
|
2553
|
+
fileFilter: (entry) => wh.filterPath(entry),
|
|
2554
|
+
directoryFilter: (entry) => wh.filterDir(entry)
|
|
2555
|
+
});
|
|
2556
|
+
if (!stream)
|
|
2557
|
+
return;
|
|
2558
|
+
stream.on(STR_DATA, async (entry) => {
|
|
2559
|
+
if (this.fsw.closed) {
|
|
2560
|
+
stream = void 0;
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
const item = entry.path;
|
|
2564
|
+
let path = sp2.join(directory, item);
|
|
2565
|
+
current.add(item);
|
|
2566
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2569
|
+
if (this.fsw.closed) {
|
|
2570
|
+
stream = void 0;
|
|
2571
|
+
return;
|
|
2572
|
+
}
|
|
2573
|
+
if (item === target || !target && !previous.has(item)) {
|
|
2574
|
+
this.fsw._incrReadyCount();
|
|
2575
|
+
path = sp2.join(dir, sp2.relative(dir, path));
|
|
2576
|
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
2577
|
+
}
|
|
2578
|
+
}).on(EV.ERROR, this._boundHandleError);
|
|
2579
|
+
return new Promise((resolve3, reject) => {
|
|
2580
|
+
if (!stream)
|
|
2581
|
+
return reject();
|
|
2582
|
+
stream.once(STR_END, () => {
|
|
2583
|
+
if (this.fsw.closed) {
|
|
2584
|
+
stream = void 0;
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
const wasThrottled = throttler ? throttler.clear() : false;
|
|
2588
|
+
resolve3(void 0);
|
|
2589
|
+
previous.getChildren().filter((item) => {
|
|
2590
|
+
return item !== directory && !current.has(item);
|
|
2591
|
+
}).forEach((item) => {
|
|
2592
|
+
this.fsw._remove(directory, item);
|
|
2593
|
+
});
|
|
2594
|
+
stream = void 0;
|
|
2595
|
+
if (wasThrottled)
|
|
2596
|
+
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
2597
|
+
});
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
2602
|
+
* @param dir fs path
|
|
2603
|
+
* @param stats
|
|
2604
|
+
* @param initialAdd
|
|
2605
|
+
* @param depth relative to user-supplied path
|
|
2606
|
+
* @param target child path targeted for watch
|
|
2607
|
+
* @param wh Common watch helpers for this path
|
|
2608
|
+
* @param realpath
|
|
2609
|
+
* @returns closer for the watcher instance.
|
|
2610
|
+
*/
|
|
2611
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath2) {
|
|
2612
|
+
const parentDir = this.fsw._getWatchedDir(sp2.dirname(dir));
|
|
2613
|
+
const tracked = parentDir.has(sp2.basename(dir));
|
|
2614
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
|
2615
|
+
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
2616
|
+
}
|
|
2617
|
+
parentDir.add(sp2.basename(dir));
|
|
2618
|
+
this.fsw._getWatchedDir(dir);
|
|
2619
|
+
let throttler;
|
|
2620
|
+
let closer;
|
|
2621
|
+
const oDepth = this.fsw.options.depth;
|
|
2622
|
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath2)) {
|
|
2623
|
+
if (!target) {
|
|
2624
|
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
2625
|
+
if (this.fsw.closed)
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
|
|
2629
|
+
if (stats2 && stats2.mtimeMs === 0)
|
|
2630
|
+
return;
|
|
2631
|
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
2632
|
+
});
|
|
2633
|
+
}
|
|
2634
|
+
return closer;
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2637
|
+
* Handle added file, directory, or glob pattern.
|
|
2638
|
+
* Delegates call to _handleFile / _handleDir after checks.
|
|
2639
|
+
* @param path to file or ir
|
|
2640
|
+
* @param initialAdd was the file added at watch instantiation?
|
|
2641
|
+
* @param priorWh depth relative to user-supplied path
|
|
2642
|
+
* @param depth Child path actually targeted for watch
|
|
2643
|
+
* @param target Child path actually targeted for watch
|
|
2644
|
+
*/
|
|
2645
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
2646
|
+
const ready = this.fsw._emitReady;
|
|
2647
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
2648
|
+
ready();
|
|
2649
|
+
return false;
|
|
2650
|
+
}
|
|
2651
|
+
const wh = this.fsw._getWatchHelpers(path);
|
|
2652
|
+
if (priorWh) {
|
|
2653
|
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
2654
|
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
2655
|
+
}
|
|
2656
|
+
try {
|
|
2657
|
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
2658
|
+
if (this.fsw.closed)
|
|
2659
|
+
return;
|
|
2660
|
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
2661
|
+
ready();
|
|
2662
|
+
return false;
|
|
2663
|
+
}
|
|
2664
|
+
const follow = this.fsw.options.followSymlinks;
|
|
2665
|
+
let closer;
|
|
2666
|
+
if (stats.isDirectory()) {
|
|
2667
|
+
const absPath = sp2.resolve(path);
|
|
2668
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
2669
|
+
if (this.fsw.closed)
|
|
2670
|
+
return;
|
|
2671
|
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
2672
|
+
if (this.fsw.closed)
|
|
2673
|
+
return;
|
|
2674
|
+
if (absPath !== targetPath && targetPath !== void 0) {
|
|
2675
|
+
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
2676
|
+
}
|
|
2677
|
+
} else if (stats.isSymbolicLink()) {
|
|
2678
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
2679
|
+
if (this.fsw.closed)
|
|
2680
|
+
return;
|
|
2681
|
+
const parent = sp2.dirname(wh.watchPath);
|
|
2682
|
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
2683
|
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
2684
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
2685
|
+
if (this.fsw.closed)
|
|
2686
|
+
return;
|
|
2687
|
+
if (targetPath !== void 0) {
|
|
2688
|
+
this.fsw._symlinkPaths.set(sp2.resolve(path), targetPath);
|
|
2689
|
+
}
|
|
2690
|
+
} else {
|
|
2691
|
+
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
2692
|
+
}
|
|
2693
|
+
ready();
|
|
2694
|
+
if (closer)
|
|
2695
|
+
this.fsw._addPathCloser(path, closer);
|
|
2696
|
+
return false;
|
|
2697
|
+
} catch (error) {
|
|
2698
|
+
if (this.fsw._handleError(error)) {
|
|
2699
|
+
ready();
|
|
2700
|
+
return path;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
};
|
|
2705
|
+
|
|
2706
|
+
// ../../node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.js
|
|
2707
|
+
var SLASH = "/";
|
|
2708
|
+
var SLASH_SLASH = "//";
|
|
2709
|
+
var ONE_DOT = ".";
|
|
2710
|
+
var TWO_DOTS = "..";
|
|
2711
|
+
var STRING_TYPE = "string";
|
|
2712
|
+
var BACK_SLASH_RE = /\\/g;
|
|
2713
|
+
var DOUBLE_SLASH_RE = /\/\//g;
|
|
2714
|
+
var DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
2715
|
+
var REPLACER_RE = /^\.[/\\]/;
|
|
2716
|
+
function arrify(item) {
|
|
2717
|
+
return Array.isArray(item) ? item : [item];
|
|
2718
|
+
}
|
|
2719
|
+
var isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
|
|
2720
|
+
function createPattern(matcher) {
|
|
2721
|
+
if (typeof matcher === "function")
|
|
2722
|
+
return matcher;
|
|
2723
|
+
if (typeof matcher === "string")
|
|
2724
|
+
return (string3) => matcher === string3;
|
|
2725
|
+
if (matcher instanceof RegExp)
|
|
2726
|
+
return (string3) => matcher.test(string3);
|
|
2727
|
+
if (typeof matcher === "object" && matcher !== null) {
|
|
2728
|
+
return (string3) => {
|
|
2729
|
+
if (matcher.path === string3)
|
|
2730
|
+
return true;
|
|
2731
|
+
if (matcher.recursive) {
|
|
2732
|
+
const relative4 = sp2.relative(matcher.path, string3);
|
|
2733
|
+
if (!relative4) {
|
|
2734
|
+
return false;
|
|
2735
|
+
}
|
|
2736
|
+
return !relative4.startsWith("..") && !sp2.isAbsolute(relative4);
|
|
2737
|
+
}
|
|
2738
|
+
return false;
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
return () => false;
|
|
2742
|
+
}
|
|
2743
|
+
function normalizePath(path) {
|
|
2744
|
+
if (typeof path !== "string")
|
|
2745
|
+
throw new Error("string expected");
|
|
2746
|
+
path = sp2.normalize(path);
|
|
2747
|
+
path = path.replace(/\\/g, "/");
|
|
2748
|
+
let prepend = false;
|
|
2749
|
+
if (path.startsWith("//"))
|
|
2750
|
+
prepend = true;
|
|
2751
|
+
path = path.replace(DOUBLE_SLASH_RE, "/");
|
|
2752
|
+
if (prepend)
|
|
2753
|
+
path = "/" + path;
|
|
2754
|
+
return path;
|
|
2755
|
+
}
|
|
2756
|
+
function matchPatterns(patterns, testString, stats) {
|
|
2757
|
+
const path = normalizePath(testString);
|
|
2758
|
+
for (let index = 0; index < patterns.length; index++) {
|
|
2759
|
+
const pattern = patterns[index];
|
|
2760
|
+
if (pattern(path, stats)) {
|
|
2761
|
+
return true;
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
return false;
|
|
2765
|
+
}
|
|
2766
|
+
function anymatch(matchers, testString) {
|
|
2767
|
+
if (matchers == null) {
|
|
2768
|
+
throw new TypeError("anymatch: specify first argument");
|
|
2769
|
+
}
|
|
2770
|
+
const matchersArray = arrify(matchers);
|
|
2771
|
+
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
|
2772
|
+
{
|
|
2773
|
+
return (testString2, stats) => {
|
|
2774
|
+
return matchPatterns(patterns, testString2, stats);
|
|
2775
|
+
};
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
var unifyPaths = (paths_) => {
|
|
2779
|
+
const paths = arrify(paths_).flat();
|
|
2780
|
+
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
|
2781
|
+
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
2782
|
+
}
|
|
2783
|
+
return paths.map(normalizePathToUnix);
|
|
2784
|
+
};
|
|
2785
|
+
var toUnix = (string3) => {
|
|
2786
|
+
let str = string3.replace(BACK_SLASH_RE, SLASH);
|
|
2787
|
+
let prepend = false;
|
|
2788
|
+
if (str.startsWith(SLASH_SLASH)) {
|
|
2789
|
+
prepend = true;
|
|
2790
|
+
}
|
|
2791
|
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
2792
|
+
if (prepend) {
|
|
2793
|
+
str = SLASH + str;
|
|
2794
|
+
}
|
|
2795
|
+
return str;
|
|
2796
|
+
};
|
|
2797
|
+
var normalizePathToUnix = (path) => toUnix(sp2.normalize(toUnix(path)));
|
|
2798
|
+
var normalizeIgnored = (cwd = "") => (path) => {
|
|
2799
|
+
if (typeof path === "string") {
|
|
2800
|
+
return normalizePathToUnix(sp2.isAbsolute(path) ? path : sp2.join(cwd, path));
|
|
2801
|
+
} else {
|
|
2802
|
+
return path;
|
|
2803
|
+
}
|
|
2804
|
+
};
|
|
2805
|
+
var getAbsolutePath = (path, cwd) => {
|
|
2806
|
+
if (sp2.isAbsolute(path)) {
|
|
2807
|
+
return path;
|
|
2808
|
+
}
|
|
2809
|
+
return sp2.join(cwd, path);
|
|
2810
|
+
};
|
|
2811
|
+
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
2812
|
+
var DirEntry = class {
|
|
2813
|
+
path;
|
|
2814
|
+
_removeWatcher;
|
|
2815
|
+
items;
|
|
2816
|
+
constructor(dir, removeWatcher) {
|
|
2817
|
+
this.path = dir;
|
|
2818
|
+
this._removeWatcher = removeWatcher;
|
|
2819
|
+
this.items = /* @__PURE__ */ new Set();
|
|
2820
|
+
}
|
|
2821
|
+
add(item) {
|
|
2822
|
+
const { items } = this;
|
|
2823
|
+
if (!items)
|
|
2824
|
+
return;
|
|
2825
|
+
if (item !== ONE_DOT && item !== TWO_DOTS)
|
|
2826
|
+
items.add(item);
|
|
2827
|
+
}
|
|
2828
|
+
async remove(item) {
|
|
2829
|
+
const { items } = this;
|
|
2830
|
+
if (!items)
|
|
2831
|
+
return;
|
|
2832
|
+
items.delete(item);
|
|
2833
|
+
if (items.size > 0)
|
|
2834
|
+
return;
|
|
2835
|
+
const dir = this.path;
|
|
2836
|
+
try {
|
|
2837
|
+
await readdir(dir);
|
|
2838
|
+
} catch (err) {
|
|
2839
|
+
if (this._removeWatcher) {
|
|
2840
|
+
this._removeWatcher(sp2.dirname(dir), sp2.basename(dir));
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
has(item) {
|
|
2845
|
+
const { items } = this;
|
|
2846
|
+
if (!items)
|
|
2847
|
+
return;
|
|
2848
|
+
return items.has(item);
|
|
2849
|
+
}
|
|
2850
|
+
getChildren() {
|
|
2851
|
+
const { items } = this;
|
|
2852
|
+
if (!items)
|
|
2853
|
+
return [];
|
|
2854
|
+
return [...items.values()];
|
|
2855
|
+
}
|
|
2856
|
+
dispose() {
|
|
2857
|
+
this.items.clear();
|
|
2858
|
+
this.path = "";
|
|
2859
|
+
this._removeWatcher = EMPTY_FN;
|
|
2860
|
+
this.items = EMPTY_SET;
|
|
2861
|
+
Object.freeze(this);
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
var STAT_METHOD_F = "stat";
|
|
2865
|
+
var STAT_METHOD_L = "lstat";
|
|
2866
|
+
var WatchHelper = class {
|
|
2867
|
+
fsw;
|
|
2868
|
+
path;
|
|
2869
|
+
watchPath;
|
|
2870
|
+
fullWatchPath;
|
|
2871
|
+
dirParts;
|
|
2872
|
+
followSymlinks;
|
|
2873
|
+
statMethod;
|
|
2874
|
+
constructor(path, follow, fsw) {
|
|
2875
|
+
this.fsw = fsw;
|
|
2876
|
+
const watchPath = path;
|
|
2877
|
+
this.path = path = path.replace(REPLACER_RE, "");
|
|
2878
|
+
this.watchPath = watchPath;
|
|
2879
|
+
this.fullWatchPath = sp2.resolve(watchPath);
|
|
2880
|
+
this.dirParts = [];
|
|
2881
|
+
this.dirParts.forEach((parts) => {
|
|
2882
|
+
if (parts.length > 1)
|
|
2883
|
+
parts.pop();
|
|
2884
|
+
});
|
|
2885
|
+
this.followSymlinks = follow;
|
|
2886
|
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
2887
|
+
}
|
|
2888
|
+
entryPath(entry) {
|
|
2889
|
+
return sp2.join(this.watchPath, sp2.relative(this.watchPath, entry.fullPath));
|
|
2890
|
+
}
|
|
2891
|
+
filterPath(entry) {
|
|
2892
|
+
const { stats } = entry;
|
|
2893
|
+
if (stats && stats.isSymbolicLink())
|
|
2894
|
+
return this.filterDir(entry);
|
|
2895
|
+
const resolvedPath = this.entryPath(entry);
|
|
2896
|
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
2897
|
+
}
|
|
2898
|
+
filterDir(entry) {
|
|
2899
|
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
2900
|
+
}
|
|
2901
|
+
};
|
|
2902
|
+
var FSWatcher = class extends EventEmitter {
|
|
2903
|
+
closed;
|
|
2904
|
+
options;
|
|
2905
|
+
_closers;
|
|
2906
|
+
_ignoredPaths;
|
|
2907
|
+
_throttled;
|
|
2908
|
+
_streams;
|
|
2909
|
+
_symlinkPaths;
|
|
2910
|
+
_watched;
|
|
2911
|
+
_pendingWrites;
|
|
2912
|
+
_pendingUnlinks;
|
|
2913
|
+
_readyCount;
|
|
2914
|
+
_emitReady;
|
|
2915
|
+
_closePromise;
|
|
2916
|
+
_userIgnored;
|
|
2917
|
+
_readyEmitted;
|
|
2918
|
+
_emitRaw;
|
|
2919
|
+
_boundRemove;
|
|
2920
|
+
_nodeFsHandler;
|
|
2921
|
+
// Not indenting methods for history sake; for now.
|
|
2922
|
+
constructor(_opts = {}) {
|
|
2923
|
+
super();
|
|
2924
|
+
this.closed = false;
|
|
2925
|
+
this._closers = /* @__PURE__ */ new Map();
|
|
2926
|
+
this._ignoredPaths = /* @__PURE__ */ new Set();
|
|
2927
|
+
this._throttled = /* @__PURE__ */ new Map();
|
|
2928
|
+
this._streams = /* @__PURE__ */ new Set();
|
|
2929
|
+
this._symlinkPaths = /* @__PURE__ */ new Map();
|
|
2930
|
+
this._watched = /* @__PURE__ */ new Map();
|
|
2931
|
+
this._pendingWrites = /* @__PURE__ */ new Map();
|
|
2932
|
+
this._pendingUnlinks = /* @__PURE__ */ new Map();
|
|
2933
|
+
this._readyCount = 0;
|
|
2934
|
+
this._readyEmitted = false;
|
|
2935
|
+
const awf = _opts.awaitWriteFinish;
|
|
2936
|
+
const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
|
|
2937
|
+
const opts = {
|
|
2938
|
+
// Defaults
|
|
2939
|
+
persistent: true,
|
|
2940
|
+
ignoreInitial: false,
|
|
2941
|
+
ignorePermissionErrors: false,
|
|
2942
|
+
interval: 100,
|
|
2943
|
+
binaryInterval: 300,
|
|
2944
|
+
followSymlinks: true,
|
|
2945
|
+
usePolling: false,
|
|
2946
|
+
// useAsync: false,
|
|
2947
|
+
atomic: true,
|
|
2948
|
+
// NOTE: overwritten later (depends on usePolling)
|
|
2949
|
+
..._opts,
|
|
2950
|
+
// Change format
|
|
2951
|
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
2952
|
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
|
|
2953
|
+
};
|
|
2954
|
+
if (isIBMi)
|
|
2955
|
+
opts.usePolling = true;
|
|
2956
|
+
if (opts.atomic === void 0)
|
|
2957
|
+
opts.atomic = !opts.usePolling;
|
|
2958
|
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
2959
|
+
if (envPoll !== void 0) {
|
|
2960
|
+
const envLower = envPoll.toLowerCase();
|
|
2961
|
+
if (envLower === "false" || envLower === "0")
|
|
2962
|
+
opts.usePolling = false;
|
|
2963
|
+
else if (envLower === "true" || envLower === "1")
|
|
2964
|
+
opts.usePolling = true;
|
|
2965
|
+
else
|
|
2966
|
+
opts.usePolling = !!envLower;
|
|
2967
|
+
}
|
|
2968
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
2969
|
+
if (envInterval)
|
|
2970
|
+
opts.interval = Number.parseInt(envInterval, 10);
|
|
2971
|
+
let readyCalls = 0;
|
|
2972
|
+
this._emitReady = () => {
|
|
2973
|
+
readyCalls++;
|
|
2974
|
+
if (readyCalls >= this._readyCount) {
|
|
2975
|
+
this._emitReady = EMPTY_FN;
|
|
2976
|
+
this._readyEmitted = true;
|
|
2977
|
+
process.nextTick(() => this.emit(EVENTS.READY));
|
|
2978
|
+
}
|
|
2979
|
+
};
|
|
2980
|
+
this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
|
|
2981
|
+
this._boundRemove = this._remove.bind(this);
|
|
2982
|
+
this.options = opts;
|
|
2983
|
+
this._nodeFsHandler = new NodeFsHandler(this);
|
|
2984
|
+
Object.freeze(opts);
|
|
2985
|
+
}
|
|
2986
|
+
_addIgnoredPath(matcher) {
|
|
2987
|
+
if (isMatcherObject(matcher)) {
|
|
2988
|
+
for (const ignored of this._ignoredPaths) {
|
|
2989
|
+
if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
|
|
2990
|
+
return;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
this._ignoredPaths.add(matcher);
|
|
2995
|
+
}
|
|
2996
|
+
_removeIgnoredPath(matcher) {
|
|
2997
|
+
this._ignoredPaths.delete(matcher);
|
|
2998
|
+
if (typeof matcher === "string") {
|
|
2999
|
+
for (const ignored of this._ignoredPaths) {
|
|
3000
|
+
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
|
3001
|
+
this._ignoredPaths.delete(ignored);
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
// Public methods
|
|
3007
|
+
/**
|
|
3008
|
+
* Adds paths to be watched on an existing FSWatcher instance.
|
|
3009
|
+
* @param paths_ file or file list. Other arguments are unused
|
|
3010
|
+
*/
|
|
3011
|
+
add(paths_, _origAdd, _internal) {
|
|
3012
|
+
const { cwd } = this.options;
|
|
3013
|
+
this.closed = false;
|
|
3014
|
+
this._closePromise = void 0;
|
|
3015
|
+
let paths = unifyPaths(paths_);
|
|
3016
|
+
if (cwd) {
|
|
3017
|
+
paths = paths.map((path) => {
|
|
3018
|
+
const absPath = getAbsolutePath(path, cwd);
|
|
3019
|
+
return absPath;
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
paths.forEach((path) => {
|
|
3023
|
+
this._removeIgnoredPath(path);
|
|
3024
|
+
});
|
|
3025
|
+
this._userIgnored = void 0;
|
|
3026
|
+
if (!this._readyCount)
|
|
3027
|
+
this._readyCount = 0;
|
|
3028
|
+
this._readyCount += paths.length;
|
|
3029
|
+
Promise.all(paths.map(async (path) => {
|
|
3030
|
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
3031
|
+
if (res)
|
|
3032
|
+
this._emitReady();
|
|
3033
|
+
return res;
|
|
3034
|
+
})).then((results) => {
|
|
3035
|
+
if (this.closed)
|
|
3036
|
+
return;
|
|
3037
|
+
results.forEach((item) => {
|
|
3038
|
+
if (item)
|
|
3039
|
+
this.add(sp2.dirname(item), sp2.basename(_origAdd || item));
|
|
3040
|
+
});
|
|
3041
|
+
});
|
|
3042
|
+
return this;
|
|
3043
|
+
}
|
|
3044
|
+
/**
|
|
3045
|
+
* Close watchers or start ignoring events from specified paths.
|
|
3046
|
+
*/
|
|
3047
|
+
unwatch(paths_) {
|
|
3048
|
+
if (this.closed)
|
|
3049
|
+
return this;
|
|
3050
|
+
const paths = unifyPaths(paths_);
|
|
3051
|
+
const { cwd } = this.options;
|
|
3052
|
+
paths.forEach((path) => {
|
|
3053
|
+
if (!sp2.isAbsolute(path) && !this._closers.has(path)) {
|
|
3054
|
+
if (cwd)
|
|
3055
|
+
path = sp2.join(cwd, path);
|
|
3056
|
+
path = sp2.resolve(path);
|
|
3057
|
+
}
|
|
3058
|
+
this._closePath(path);
|
|
3059
|
+
this._addIgnoredPath(path);
|
|
3060
|
+
if (this._watched.has(path)) {
|
|
3061
|
+
this._addIgnoredPath({
|
|
3062
|
+
path,
|
|
3063
|
+
recursive: true
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
this._userIgnored = void 0;
|
|
3067
|
+
});
|
|
3068
|
+
return this;
|
|
3069
|
+
}
|
|
3070
|
+
/**
|
|
3071
|
+
* Close watchers and remove all listeners from watched paths.
|
|
3072
|
+
*/
|
|
3073
|
+
close() {
|
|
3074
|
+
if (this._closePromise) {
|
|
3075
|
+
return this._closePromise;
|
|
3076
|
+
}
|
|
3077
|
+
this.closed = true;
|
|
3078
|
+
this.removeAllListeners();
|
|
3079
|
+
const closers = [];
|
|
3080
|
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
|
3081
|
+
const promise2 = closer();
|
|
3082
|
+
if (promise2 instanceof Promise)
|
|
3083
|
+
closers.push(promise2);
|
|
3084
|
+
}));
|
|
3085
|
+
this._streams.forEach((stream) => stream.destroy());
|
|
3086
|
+
this._userIgnored = void 0;
|
|
3087
|
+
this._readyCount = 0;
|
|
3088
|
+
this._readyEmitted = false;
|
|
3089
|
+
this._watched.forEach((dirent) => dirent.dispose());
|
|
3090
|
+
this._closers.clear();
|
|
3091
|
+
this._watched.clear();
|
|
3092
|
+
this._streams.clear();
|
|
3093
|
+
this._symlinkPaths.clear();
|
|
3094
|
+
this._throttled.clear();
|
|
3095
|
+
this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
|
|
3096
|
+
return this._closePromise;
|
|
3097
|
+
}
|
|
3098
|
+
/**
|
|
3099
|
+
* Expose list of watched paths
|
|
3100
|
+
* @returns for chaining
|
|
3101
|
+
*/
|
|
3102
|
+
getWatched() {
|
|
3103
|
+
const watchList = {};
|
|
3104
|
+
this._watched.forEach((entry, dir) => {
|
|
3105
|
+
const key = this.options.cwd ? sp2.relative(this.options.cwd, dir) : dir;
|
|
3106
|
+
const index = key || ONE_DOT;
|
|
3107
|
+
watchList[index] = entry.getChildren().sort();
|
|
3108
|
+
});
|
|
3109
|
+
return watchList;
|
|
3110
|
+
}
|
|
3111
|
+
emitWithAll(event, args) {
|
|
3112
|
+
this.emit(event, ...args);
|
|
3113
|
+
if (event !== EVENTS.ERROR)
|
|
3114
|
+
this.emit(EVENTS.ALL, event, ...args);
|
|
3115
|
+
}
|
|
3116
|
+
// Common helpers
|
|
3117
|
+
// --------------
|
|
3118
|
+
/**
|
|
3119
|
+
* Normalize and emit events.
|
|
3120
|
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
3121
|
+
* @param event Type of event
|
|
3122
|
+
* @param path File or directory path
|
|
3123
|
+
* @param stats arguments to be passed with event
|
|
3124
|
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
3125
|
+
*/
|
|
3126
|
+
async _emit(event, path, stats) {
|
|
3127
|
+
if (this.closed)
|
|
3128
|
+
return;
|
|
3129
|
+
const opts = this.options;
|
|
3130
|
+
if (isWindows)
|
|
3131
|
+
path = sp2.normalize(path);
|
|
3132
|
+
if (opts.cwd)
|
|
3133
|
+
path = sp2.relative(opts.cwd, path);
|
|
3134
|
+
const args = [path];
|
|
3135
|
+
if (stats != null)
|
|
3136
|
+
args.push(stats);
|
|
3137
|
+
const awf = opts.awaitWriteFinish;
|
|
3138
|
+
let pw;
|
|
3139
|
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
3140
|
+
pw.lastChange = /* @__PURE__ */ new Date();
|
|
3141
|
+
return this;
|
|
3142
|
+
}
|
|
3143
|
+
if (opts.atomic) {
|
|
3144
|
+
if (event === EVENTS.UNLINK) {
|
|
3145
|
+
this._pendingUnlinks.set(path, [event, ...args]);
|
|
3146
|
+
setTimeout(() => {
|
|
3147
|
+
this._pendingUnlinks.forEach((entry, path2) => {
|
|
3148
|
+
this.emit(...entry);
|
|
3149
|
+
this.emit(EVENTS.ALL, ...entry);
|
|
3150
|
+
this._pendingUnlinks.delete(path2);
|
|
3151
|
+
});
|
|
3152
|
+
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
3153
|
+
return this;
|
|
3154
|
+
}
|
|
3155
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
3156
|
+
event = EVENTS.CHANGE;
|
|
3157
|
+
this._pendingUnlinks.delete(path);
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
3161
|
+
const awfEmit = (err, stats2) => {
|
|
3162
|
+
if (err) {
|
|
3163
|
+
event = EVENTS.ERROR;
|
|
3164
|
+
args[0] = err;
|
|
3165
|
+
this.emitWithAll(event, args);
|
|
3166
|
+
} else if (stats2) {
|
|
3167
|
+
if (args.length > 1) {
|
|
3168
|
+
args[1] = stats2;
|
|
3169
|
+
} else {
|
|
3170
|
+
args.push(stats2);
|
|
3171
|
+
}
|
|
3172
|
+
this.emitWithAll(event, args);
|
|
3173
|
+
}
|
|
3174
|
+
};
|
|
3175
|
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
3176
|
+
return this;
|
|
3177
|
+
}
|
|
3178
|
+
if (event === EVENTS.CHANGE) {
|
|
3179
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
|
|
3180
|
+
if (isThrottled)
|
|
3181
|
+
return this;
|
|
3182
|
+
}
|
|
3183
|
+
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
3184
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path) : path;
|
|
3185
|
+
let stats2;
|
|
3186
|
+
try {
|
|
3187
|
+
stats2 = await stat(fullPath);
|
|
3188
|
+
} catch (err) {
|
|
3189
|
+
}
|
|
3190
|
+
if (!stats2 || this.closed)
|
|
3191
|
+
return;
|
|
3192
|
+
args.push(stats2);
|
|
3193
|
+
}
|
|
3194
|
+
this.emitWithAll(event, args);
|
|
3195
|
+
return this;
|
|
3196
|
+
}
|
|
3197
|
+
/**
|
|
3198
|
+
* Common handler for errors
|
|
3199
|
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
3200
|
+
*/
|
|
3201
|
+
_handleError(error) {
|
|
3202
|
+
const code = error && error.code;
|
|
3203
|
+
if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
|
|
3204
|
+
this.emit(EVENTS.ERROR, error);
|
|
3205
|
+
}
|
|
3206
|
+
return error || this.closed;
|
|
3207
|
+
}
|
|
3208
|
+
/**
|
|
3209
|
+
* Helper utility for throttling
|
|
3210
|
+
* @param actionType type being throttled
|
|
3211
|
+
* @param path being acted upon
|
|
3212
|
+
* @param timeout duration of time to suppress duplicate actions
|
|
3213
|
+
* @returns tracking object or false if action should be suppressed
|
|
3214
|
+
*/
|
|
3215
|
+
_throttle(actionType, path, timeout) {
|
|
3216
|
+
if (!this._throttled.has(actionType)) {
|
|
3217
|
+
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
3218
|
+
}
|
|
3219
|
+
const action = this._throttled.get(actionType);
|
|
3220
|
+
if (!action)
|
|
3221
|
+
throw new Error("invalid throttle");
|
|
3222
|
+
const actionPath = action.get(path);
|
|
3223
|
+
if (actionPath) {
|
|
3224
|
+
actionPath.count++;
|
|
3225
|
+
return false;
|
|
3226
|
+
}
|
|
3227
|
+
let timeoutObject;
|
|
3228
|
+
const clear = () => {
|
|
3229
|
+
const item = action.get(path);
|
|
3230
|
+
const count = item ? item.count : 0;
|
|
3231
|
+
action.delete(path);
|
|
3232
|
+
clearTimeout(timeoutObject);
|
|
3233
|
+
if (item)
|
|
3234
|
+
clearTimeout(item.timeoutObject);
|
|
3235
|
+
return count;
|
|
3236
|
+
};
|
|
3237
|
+
timeoutObject = setTimeout(clear, timeout);
|
|
3238
|
+
const thr = { timeoutObject, clear, count: 0 };
|
|
3239
|
+
action.set(path, thr);
|
|
3240
|
+
return thr;
|
|
3241
|
+
}
|
|
3242
|
+
_incrReadyCount() {
|
|
3243
|
+
return this._readyCount++;
|
|
3244
|
+
}
|
|
3245
|
+
/**
|
|
3246
|
+
* Awaits write operation to finish.
|
|
3247
|
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
3248
|
+
* @param path being acted upon
|
|
3249
|
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
3250
|
+
* @param event
|
|
3251
|
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
3252
|
+
*/
|
|
3253
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
3254
|
+
const awf = this.options.awaitWriteFinish;
|
|
3255
|
+
if (typeof awf !== "object")
|
|
3256
|
+
return;
|
|
3257
|
+
const pollInterval = awf.pollInterval;
|
|
3258
|
+
let timeoutHandler;
|
|
3259
|
+
let fullPath = path;
|
|
3260
|
+
if (this.options.cwd && !sp2.isAbsolute(path)) {
|
|
3261
|
+
fullPath = sp2.join(this.options.cwd, path);
|
|
3262
|
+
}
|
|
3263
|
+
const now = /* @__PURE__ */ new Date();
|
|
3264
|
+
const writes = this._pendingWrites;
|
|
3265
|
+
function awaitWriteFinishFn(prevStat) {
|
|
3266
|
+
stat$1(fullPath, (err, curStat) => {
|
|
3267
|
+
if (err || !writes.has(path)) {
|
|
3268
|
+
if (err && err.code !== "ENOENT")
|
|
3269
|
+
awfEmit(err);
|
|
3270
|
+
return;
|
|
3271
|
+
}
|
|
3272
|
+
const now2 = Number(/* @__PURE__ */ new Date());
|
|
3273
|
+
if (prevStat && curStat.size !== prevStat.size) {
|
|
3274
|
+
writes.get(path).lastChange = now2;
|
|
3275
|
+
}
|
|
3276
|
+
const pw = writes.get(path);
|
|
3277
|
+
const df = now2 - pw.lastChange;
|
|
3278
|
+
if (df >= threshold) {
|
|
3279
|
+
writes.delete(path);
|
|
3280
|
+
awfEmit(void 0, curStat);
|
|
3281
|
+
} else {
|
|
3282
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
3283
|
+
}
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
if (!writes.has(path)) {
|
|
3287
|
+
writes.set(path, {
|
|
3288
|
+
lastChange: now,
|
|
3289
|
+
cancelWait: () => {
|
|
3290
|
+
writes.delete(path);
|
|
3291
|
+
clearTimeout(timeoutHandler);
|
|
3292
|
+
return event;
|
|
3293
|
+
}
|
|
3294
|
+
});
|
|
3295
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
/**
|
|
3299
|
+
* Determines whether user has asked to ignore this path.
|
|
3300
|
+
*/
|
|
3301
|
+
_isIgnored(path, stats) {
|
|
3302
|
+
if (this.options.atomic && DOT_RE.test(path))
|
|
3303
|
+
return true;
|
|
3304
|
+
if (!this._userIgnored) {
|
|
3305
|
+
const { cwd } = this.options;
|
|
3306
|
+
const ign = this.options.ignored;
|
|
3307
|
+
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
|
3308
|
+
const ignoredPaths = [...this._ignoredPaths];
|
|
3309
|
+
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
3310
|
+
this._userIgnored = anymatch(list);
|
|
3311
|
+
}
|
|
3312
|
+
return this._userIgnored(path, stats);
|
|
3313
|
+
}
|
|
3314
|
+
_isntIgnored(path, stat4) {
|
|
3315
|
+
return !this._isIgnored(path, stat4);
|
|
3316
|
+
}
|
|
3317
|
+
/**
|
|
3318
|
+
* Provides a set of common helpers and properties relating to symlink handling.
|
|
3319
|
+
* @param path file or directory pattern being watched
|
|
3320
|
+
*/
|
|
3321
|
+
_getWatchHelpers(path) {
|
|
3322
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
3323
|
+
}
|
|
3324
|
+
// Directory helpers
|
|
3325
|
+
// -----------------
|
|
3326
|
+
/**
|
|
3327
|
+
* Provides directory tracking objects
|
|
3328
|
+
* @param directory path of the directory
|
|
3329
|
+
*/
|
|
3330
|
+
_getWatchedDir(directory) {
|
|
3331
|
+
const dir = sp2.resolve(directory);
|
|
3332
|
+
if (!this._watched.has(dir))
|
|
3333
|
+
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
3334
|
+
return this._watched.get(dir);
|
|
3335
|
+
}
|
|
3336
|
+
// File helpers
|
|
3337
|
+
// ------------
|
|
3338
|
+
/**
|
|
3339
|
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
|
3340
|
+
*/
|
|
3341
|
+
_hasReadPermissions(stats) {
|
|
3342
|
+
if (this.options.ignorePermissionErrors)
|
|
3343
|
+
return true;
|
|
3344
|
+
return Boolean(Number(stats.mode) & 256);
|
|
3345
|
+
}
|
|
3346
|
+
/**
|
|
3347
|
+
* Handles emitting unlink events for
|
|
3348
|
+
* files and directories, and via recursion, for
|
|
3349
|
+
* files and directories within directories that are unlinked
|
|
3350
|
+
* @param directory within which the following item is located
|
|
3351
|
+
* @param item base path of item/directory
|
|
3352
|
+
*/
|
|
3353
|
+
_remove(directory, item, isDirectory) {
|
|
3354
|
+
const path = sp2.join(directory, item);
|
|
3355
|
+
const fullPath = sp2.resolve(path);
|
|
3356
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
3357
|
+
if (!this._throttle("remove", path, 100))
|
|
3358
|
+
return;
|
|
3359
|
+
if (!isDirectory && this._watched.size === 1) {
|
|
3360
|
+
this.add(directory, item, true);
|
|
3361
|
+
}
|
|
3362
|
+
const wp = this._getWatchedDir(path);
|
|
3363
|
+
const nestedDirectoryChildren = wp.getChildren();
|
|
3364
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
|
3365
|
+
const parent = this._getWatchedDir(directory);
|
|
3366
|
+
const wasTracked = parent.has(item);
|
|
3367
|
+
parent.remove(item);
|
|
3368
|
+
if (this._symlinkPaths.has(fullPath)) {
|
|
3369
|
+
this._symlinkPaths.delete(fullPath);
|
|
3370
|
+
}
|
|
3371
|
+
let relPath = path;
|
|
3372
|
+
if (this.options.cwd)
|
|
3373
|
+
relPath = sp2.relative(this.options.cwd, path);
|
|
3374
|
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
3375
|
+
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
3376
|
+
if (event === EVENTS.ADD)
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3379
|
+
this._watched.delete(path);
|
|
3380
|
+
this._watched.delete(fullPath);
|
|
3381
|
+
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
3382
|
+
if (wasTracked && !this._isIgnored(path))
|
|
3383
|
+
this._emit(eventName, path);
|
|
3384
|
+
this._closePath(path);
|
|
3385
|
+
}
|
|
3386
|
+
/**
|
|
3387
|
+
* Closes all watchers for a path
|
|
3388
|
+
*/
|
|
3389
|
+
_closePath(path) {
|
|
3390
|
+
this._closeFile(path);
|
|
3391
|
+
const dir = sp2.dirname(path);
|
|
3392
|
+
this._getWatchedDir(dir).remove(sp2.basename(path));
|
|
3393
|
+
}
|
|
3394
|
+
/**
|
|
3395
|
+
* Closes only file-specific watchers
|
|
3396
|
+
*/
|
|
3397
|
+
_closeFile(path) {
|
|
3398
|
+
const closers = this._closers.get(path);
|
|
3399
|
+
if (!closers)
|
|
3400
|
+
return;
|
|
3401
|
+
closers.forEach((closer) => closer());
|
|
3402
|
+
this._closers.delete(path);
|
|
3403
|
+
}
|
|
3404
|
+
_addPathCloser(path, closer) {
|
|
3405
|
+
if (!closer)
|
|
3406
|
+
return;
|
|
3407
|
+
let list = this._closers.get(path);
|
|
3408
|
+
if (!list) {
|
|
3409
|
+
list = [];
|
|
3410
|
+
this._closers.set(path, list);
|
|
3411
|
+
}
|
|
3412
|
+
list.push(closer);
|
|
3413
|
+
}
|
|
3414
|
+
_readdirp(root, opts) {
|
|
3415
|
+
if (this.closed)
|
|
3416
|
+
return;
|
|
3417
|
+
const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
|
3418
|
+
let stream = readdirp(root, options);
|
|
3419
|
+
this._streams.add(stream);
|
|
3420
|
+
stream.once(STR_CLOSE, () => {
|
|
3421
|
+
stream = void 0;
|
|
3422
|
+
});
|
|
3423
|
+
stream.once(STR_END, () => {
|
|
3424
|
+
if (stream) {
|
|
3425
|
+
this._streams.delete(stream);
|
|
3426
|
+
stream = void 0;
|
|
3427
|
+
}
|
|
3428
|
+
});
|
|
3429
|
+
return stream;
|
|
3430
|
+
}
|
|
3431
|
+
};
|
|
3432
|
+
function watch(paths, options = {}) {
|
|
3433
|
+
const watcher = new FSWatcher(options);
|
|
3434
|
+
watcher.add(paths);
|
|
3435
|
+
return watcher;
|
|
3436
|
+
}
|
|
3437
|
+
var chokidar_default = { watch, FSWatcher };
|
|
1699
3438
|
var EventService = class extends Effect4.Service()(
|
|
1700
3439
|
"@ringi/EventService",
|
|
1701
3440
|
{
|
|
@@ -1723,7 +3462,7 @@ var EventService = class extends Effect4.Service()(
|
|
|
1723
3462
|
const startFileWatcher = (repoPath) => Effect4.acquireRelease(
|
|
1724
3463
|
Effect4.sync(() => {
|
|
1725
3464
|
let debounceTimer = null;
|
|
1726
|
-
const watcher =
|
|
3465
|
+
const watcher = chokidar_default.watch(repoPath, {
|
|
1727
3466
|
ignoreInitial: true,
|
|
1728
3467
|
ignored: [
|
|
1729
3468
|
"**/node_modules/**",
|
|
@@ -1762,7 +3501,7 @@ var EventService = class extends Effect4.Service()(
|
|
|
1762
3501
|
) {
|
|
1763
3502
|
};
|
|
1764
3503
|
|
|
1765
|
-
//
|
|
3504
|
+
// ../../packages/core/src/runtime.ts
|
|
1766
3505
|
var CoreLive = Layer.mergeAll(
|
|
1767
3506
|
ReviewService.Default,
|
|
1768
3507
|
ReviewRepo.Default,
|
|
@@ -1776,7 +3515,12 @@ var CoreLive = Layer.mergeAll(
|
|
|
1776
3515
|
ExportService.Default,
|
|
1777
3516
|
SqliteService.Default
|
|
1778
3517
|
);
|
|
3518
|
+
/*! Bundled license information:
|
|
3519
|
+
|
|
3520
|
+
chokidar/index.js:
|
|
3521
|
+
(*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
|
|
3522
|
+
*/
|
|
1779
3523
|
|
|
1780
3524
|
export { CommentService, CoreLive, ExportService, GitService, ReviewId, ReviewNotFound, ReviewService, ReviewSourceType, TodoId, TodoNotFound, TodoService, getDiffSummary, parseDiff };
|
|
1781
|
-
//# sourceMappingURL=chunk-
|
|
1782
|
-
//# sourceMappingURL=chunk-
|
|
3525
|
+
//# sourceMappingURL=chunk-KMYSGMD3.js.map
|
|
3526
|
+
//# sourceMappingURL=chunk-KMYSGMD3.js.map
|