@sanurb/ringi 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1741 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/mcp.mjs +1061 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/runtime.mjs +2975 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +9 -9
- package/dist/chunk-KMYSGMD3.js +0 -3526
- package/dist/chunk-KMYSGMD3.js.map +0 -1
- package/dist/cli.js +0 -1839
- package/dist/cli.js.map +0 -1
- package/dist/mcp.js +0 -1228
- package/dist/mcp.js.map +0 -1
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,2975 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, stat, unwatchFile, watch, watchFile } from "node:fs";
|
|
3
|
+
import * as sp from "node:path";
|
|
4
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import * as HttpApiSchema from "@effect/platform/HttpApiSchema";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
import { lstat, open, readFile, readdir, realpath, stat as stat$1 } from "node:fs/promises";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
import { DatabaseSync } from "node:sqlite";
|
|
12
|
+
import * as Config from "effect/Config";
|
|
13
|
+
import * as Exit from "effect/Exit";
|
|
14
|
+
import * as Layer from "effect/Layer";
|
|
15
|
+
import "effect/ManagedRuntime";
|
|
16
|
+
import { platform, type } from "node:os";
|
|
17
|
+
import { EventEmitter } from "node:events";
|
|
18
|
+
import { Readable } from "node:stream";
|
|
19
|
+
import * as Queue from "effect/Queue";
|
|
20
|
+
import * as Runtime from "effect/Runtime";
|
|
21
|
+
import * as Stream from "effect/Stream";
|
|
22
|
+
//#region ../../packages/core/src/schemas/review.ts
|
|
23
|
+
const ReviewId = Schema.String.pipe(Schema.brand("ReviewId"));
|
|
24
|
+
const ReviewStatus = Schema.Literal("in_progress", "approved", "changes_requested");
|
|
25
|
+
const ReviewSourceType = Schema.Literal("staged", "branch", "commits");
|
|
26
|
+
Schema.Struct({
|
|
27
|
+
baseRef: Schema.NullOr(Schema.String),
|
|
28
|
+
createdAt: Schema.String,
|
|
29
|
+
id: ReviewId,
|
|
30
|
+
repositoryPath: Schema.String,
|
|
31
|
+
snapshotData: Schema.String,
|
|
32
|
+
sourceRef: Schema.NullOr(Schema.String),
|
|
33
|
+
sourceType: ReviewSourceType,
|
|
34
|
+
status: ReviewStatus,
|
|
35
|
+
updatedAt: Schema.String
|
|
36
|
+
});
|
|
37
|
+
Schema.Struct({
|
|
38
|
+
sourceRef: Schema.optionalWith(Schema.NullOr(Schema.String), { default: () => null }),
|
|
39
|
+
sourceType: Schema.optionalWith(ReviewSourceType, { default: () => "staged" })
|
|
40
|
+
});
|
|
41
|
+
Schema.Struct({ status: Schema.optionalWith(ReviewStatus, { as: "Option" }) });
|
|
42
|
+
var ReviewNotFound = class extends Schema.TaggedError()("ReviewNotFound", { id: ReviewId }, HttpApiSchema.annotations({ status: 404 })) {};
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../../packages/core/src/schemas/todo.ts
|
|
45
|
+
const TodoId = Schema.String.pipe(Schema.brand("TodoId"));
|
|
46
|
+
Schema.Struct({
|
|
47
|
+
completed: Schema.Boolean,
|
|
48
|
+
content: Schema.String,
|
|
49
|
+
createdAt: Schema.String,
|
|
50
|
+
id: TodoId,
|
|
51
|
+
position: Schema.Number,
|
|
52
|
+
reviewId: Schema.NullOr(ReviewId),
|
|
53
|
+
updatedAt: Schema.String
|
|
54
|
+
});
|
|
55
|
+
Schema.Struct({
|
|
56
|
+
content: Schema.String.pipe(Schema.minLength(1)),
|
|
57
|
+
reviewId: Schema.optionalWith(Schema.NullOr(ReviewId), { default: () => null })
|
|
58
|
+
});
|
|
59
|
+
Schema.Struct({
|
|
60
|
+
completed: Schema.optionalWith(Schema.Boolean, { as: "Option" }),
|
|
61
|
+
content: Schema.optionalWith(Schema.String.pipe(Schema.minLength(1)), { as: "Option" })
|
|
62
|
+
});
|
|
63
|
+
var TodoNotFound = class extends Schema.TaggedError()("TodoNotFound", { id: TodoId }, HttpApiSchema.annotations({ status: 404 })) {};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region ../../packages/core/src/db/migrations.ts
|
|
66
|
+
const migrations = [
|
|
67
|
+
`CREATE TABLE IF NOT EXISTS reviews (
|
|
68
|
+
id TEXT PRIMARY KEY,
|
|
69
|
+
repository_path TEXT NOT NULL,
|
|
70
|
+
base_ref TEXT,
|
|
71
|
+
snapshot_data TEXT NOT NULL,
|
|
72
|
+
status TEXT DEFAULT 'in_progress',
|
|
73
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
74
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
75
|
+
) STRICT`,
|
|
76
|
+
`CREATE TABLE IF NOT EXISTS comments (
|
|
77
|
+
id TEXT PRIMARY KEY,
|
|
78
|
+
review_id TEXT NOT NULL REFERENCES reviews(id) ON DELETE CASCADE,
|
|
79
|
+
file_path TEXT NOT NULL,
|
|
80
|
+
line_number INTEGER,
|
|
81
|
+
line_type TEXT,
|
|
82
|
+
content TEXT NOT NULL,
|
|
83
|
+
suggestion TEXT,
|
|
84
|
+
resolved INTEGER DEFAULT 0,
|
|
85
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
86
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
87
|
+
) STRICT`,
|
|
88
|
+
`ALTER TABLE reviews ADD COLUMN source_type TEXT DEFAULT 'staged';
|
|
89
|
+
ALTER TABLE reviews ADD COLUMN source_ref TEXT`,
|
|
90
|
+
`CREATE TABLE IF NOT EXISTS todos (
|
|
91
|
+
id TEXT PRIMARY KEY,
|
|
92
|
+
content TEXT NOT NULL,
|
|
93
|
+
completed INTEGER DEFAULT 0,
|
|
94
|
+
review_id TEXT REFERENCES reviews(id) ON DELETE CASCADE,
|
|
95
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
96
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
97
|
+
) STRICT`,
|
|
98
|
+
`ALTER TABLE todos ADD COLUMN position INTEGER DEFAULT 0`,
|
|
99
|
+
`CREATE TABLE IF NOT EXISTS review_files (
|
|
100
|
+
id TEXT PRIMARY KEY,
|
|
101
|
+
review_id TEXT NOT NULL REFERENCES reviews(id) ON DELETE CASCADE,
|
|
102
|
+
file_path TEXT NOT NULL,
|
|
103
|
+
old_path TEXT,
|
|
104
|
+
status TEXT NOT NULL,
|
|
105
|
+
additions INTEGER NOT NULL DEFAULT 0,
|
|
106
|
+
deletions INTEGER NOT NULL DEFAULT 0,
|
|
107
|
+
hunks_data TEXT,
|
|
108
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
109
|
+
) STRICT`
|
|
110
|
+
];
|
|
111
|
+
/** Apply pending migrations using PRAGMA user_version as the version tracker. */
|
|
112
|
+
const runMigrations = (db) => {
|
|
113
|
+
const currentVersion = db.prepare("PRAGMA user_version").get().user_version;
|
|
114
|
+
for (let i = currentVersion; i < migrations.length; i++) {
|
|
115
|
+
const statements = migrations[i].split(";").map((s) => s.trim()).filter(Boolean);
|
|
116
|
+
for (const sql of statements) db.exec(sql);
|
|
117
|
+
db.exec(`PRAGMA user_version = ${i + 1}`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region ../../packages/core/src/db/database.ts
|
|
122
|
+
/**
|
|
123
|
+
* Wraps `body` in a SQLite transaction: BEGIN before, COMMIT on success,
|
|
124
|
+
* ROLLBACK on any failure or interruption.
|
|
125
|
+
*/
|
|
126
|
+
const withTransaction = (db, body) => Effect.acquireUseRelease(Effect.sync(() => db.exec("BEGIN")), () => body, (_, exit) => Effect.sync(() => {
|
|
127
|
+
if (Exit.isSuccess(exit)) db.exec("COMMIT");
|
|
128
|
+
else db.exec("ROLLBACK");
|
|
129
|
+
}));
|
|
130
|
+
var SqliteService = class extends Effect.Service()("@ringi/SqliteService", { effect: Effect.gen(function* effect() {
|
|
131
|
+
const dbPath = yield* Config.string("DB_PATH").pipe(Config.withDefault(".ringi/reviews.db"));
|
|
132
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
133
|
+
const db = new DatabaseSync(dbPath);
|
|
134
|
+
db.exec("PRAGMA journal_mode=WAL");
|
|
135
|
+
db.exec("PRAGMA foreign_keys=ON");
|
|
136
|
+
runMigrations(db);
|
|
137
|
+
return { db };
|
|
138
|
+
}) }) {};
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region ../../packages/core/src/repos/comment.repo.ts
|
|
141
|
+
const rowToComment = (row) => ({
|
|
142
|
+
content: row.content,
|
|
143
|
+
createdAt: row.created_at,
|
|
144
|
+
filePath: row.file_path,
|
|
145
|
+
id: row.id,
|
|
146
|
+
lineNumber: row.line_number,
|
|
147
|
+
lineType: row.line_type,
|
|
148
|
+
resolved: row.resolved === 1,
|
|
149
|
+
reviewId: row.review_id,
|
|
150
|
+
suggestion: row.suggestion,
|
|
151
|
+
updatedAt: row.updated_at
|
|
152
|
+
});
|
|
153
|
+
var CommentRepo = class extends Effect.Service()("@ringi/CommentRepo", {
|
|
154
|
+
dependencies: [SqliteService.Default],
|
|
155
|
+
effect: Effect.gen(function* effect() {
|
|
156
|
+
const { db } = yield* SqliteService;
|
|
157
|
+
const stmtFindById = db.prepare("SELECT * FROM comments WHERE id = ?");
|
|
158
|
+
const stmtFindByReview = db.prepare("SELECT * FROM comments WHERE review_id = ? ORDER BY created_at ASC");
|
|
159
|
+
const stmtFindByFile = db.prepare("SELECT * FROM comments WHERE review_id = ? AND file_path = ? ORDER BY line_number ASC, created_at ASC");
|
|
160
|
+
const stmtInsert = db.prepare(`INSERT INTO comments (id, review_id, file_path, line_number, line_type, content, suggestion, resolved, created_at, updated_at)
|
|
161
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 0, datetime('now'), datetime('now'))`);
|
|
162
|
+
const stmtDelete = db.prepare("DELETE FROM comments WHERE id = ?");
|
|
163
|
+
const stmtDeleteByReview = db.prepare("DELETE FROM comments WHERE review_id = ?");
|
|
164
|
+
const stmtSetResolved = db.prepare("UPDATE comments SET resolved = ?, updated_at = datetime('now') WHERE id = ?");
|
|
165
|
+
const stmtCountByReview = db.prepare(`SELECT
|
|
166
|
+
COUNT(*) as total,
|
|
167
|
+
SUM(CASE WHEN resolved = 1 THEN 1 ELSE 0 END) as resolved,
|
|
168
|
+
SUM(CASE WHEN resolved = 0 THEN 1 ELSE 0 END) as unresolved,
|
|
169
|
+
SUM(CASE WHEN suggestion IS NOT NULL THEN 1 ELSE 0 END) as with_suggestions
|
|
170
|
+
FROM comments WHERE review_id = ?`);
|
|
171
|
+
const findById = (id) => Effect.sync(() => {
|
|
172
|
+
const row = stmtFindById.get(id);
|
|
173
|
+
return row ? rowToComment(row) : null;
|
|
174
|
+
});
|
|
175
|
+
const findByReview = (reviewId) => Effect.sync(() => {
|
|
176
|
+
return stmtFindByReview.all(reviewId).map(rowToComment);
|
|
177
|
+
});
|
|
178
|
+
const findByFile = (reviewId, filePath) => Effect.sync(() => {
|
|
179
|
+
return stmtFindByFile.all(reviewId, filePath).map(rowToComment);
|
|
180
|
+
});
|
|
181
|
+
const create = (input) => Effect.sync(() => {
|
|
182
|
+
stmtInsert.run(input.id, input.reviewId, input.filePath, input.lineNumber, input.lineType, input.content, input.suggestion);
|
|
183
|
+
return rowToComment(stmtFindById.get(input.id));
|
|
184
|
+
});
|
|
185
|
+
const update = (id, updates) => Effect.sync(() => {
|
|
186
|
+
const setClauses = [];
|
|
187
|
+
const params = [];
|
|
188
|
+
if (updates.content !== void 0) {
|
|
189
|
+
setClauses.push("content = ?");
|
|
190
|
+
params.push(updates.content);
|
|
191
|
+
}
|
|
192
|
+
if (updates.suggestion !== void 0) {
|
|
193
|
+
setClauses.push("suggestion = ?");
|
|
194
|
+
params.push(updates.suggestion);
|
|
195
|
+
}
|
|
196
|
+
if (setClauses.length === 0) {
|
|
197
|
+
const row = stmtFindById.get(id);
|
|
198
|
+
return row ? rowToComment(row) : null;
|
|
199
|
+
}
|
|
200
|
+
setClauses.push("updated_at = datetime('now')");
|
|
201
|
+
params.push(id);
|
|
202
|
+
db.prepare(`UPDATE comments SET ${setClauses.join(", ")} WHERE id = ?`).run(...params);
|
|
203
|
+
const row = stmtFindById.get(id);
|
|
204
|
+
return row ? rowToComment(row) : null;
|
|
205
|
+
});
|
|
206
|
+
const setResolved = (id, resolved) => Effect.sync(() => {
|
|
207
|
+
stmtSetResolved.run(resolved ? 1 : 0, id);
|
|
208
|
+
const row = stmtFindById.get(id);
|
|
209
|
+
return row ? rowToComment(row) : null;
|
|
210
|
+
});
|
|
211
|
+
const remove = (id) => Effect.sync(() => {
|
|
212
|
+
const result = stmtDelete.run(id);
|
|
213
|
+
return Number(result.changes) > 0;
|
|
214
|
+
});
|
|
215
|
+
const removeByReview = (reviewId) => Effect.sync(() => {
|
|
216
|
+
const result = stmtDeleteByReview.run(reviewId);
|
|
217
|
+
return Number(result.changes);
|
|
218
|
+
});
|
|
219
|
+
const countByReview = (reviewId) => Effect.sync(() => {
|
|
220
|
+
const row = stmtCountByReview.get(reviewId);
|
|
221
|
+
return {
|
|
222
|
+
resolved: row.resolved,
|
|
223
|
+
total: row.total,
|
|
224
|
+
unresolved: row.unresolved,
|
|
225
|
+
withSuggestions: row.with_suggestions
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
countByReview,
|
|
230
|
+
create,
|
|
231
|
+
findByFile,
|
|
232
|
+
findById,
|
|
233
|
+
findByReview,
|
|
234
|
+
remove,
|
|
235
|
+
removeByReview,
|
|
236
|
+
setResolved,
|
|
237
|
+
update
|
|
238
|
+
};
|
|
239
|
+
})
|
|
240
|
+
}) {};
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region ../../packages/core/src/schemas/comment.ts
|
|
243
|
+
const CommentId = Schema.String.pipe(Schema.brand("CommentId"));
|
|
244
|
+
const LineType = Schema.Literal("added", "removed", "context");
|
|
245
|
+
Schema.Struct({
|
|
246
|
+
content: Schema.String,
|
|
247
|
+
createdAt: Schema.String,
|
|
248
|
+
filePath: Schema.String,
|
|
249
|
+
id: CommentId,
|
|
250
|
+
lineNumber: Schema.NullOr(Schema.Number),
|
|
251
|
+
lineType: Schema.NullOr(LineType),
|
|
252
|
+
resolved: Schema.Boolean,
|
|
253
|
+
reviewId: ReviewId,
|
|
254
|
+
suggestion: Schema.NullOr(Schema.String),
|
|
255
|
+
updatedAt: Schema.String
|
|
256
|
+
});
|
|
257
|
+
Schema.Struct({
|
|
258
|
+
content: Schema.String.pipe(Schema.minLength(1)),
|
|
259
|
+
filePath: Schema.String.pipe(Schema.minLength(1)),
|
|
260
|
+
lineNumber: Schema.optionalWith(Schema.NullOr(Schema.Number), { default: () => null }),
|
|
261
|
+
lineType: Schema.optionalWith(Schema.NullOr(LineType), { default: () => null }),
|
|
262
|
+
suggestion: Schema.optionalWith(Schema.NullOr(Schema.String), { default: () => null })
|
|
263
|
+
});
|
|
264
|
+
Schema.Struct({
|
|
265
|
+
content: Schema.optionalWith(Schema.String.pipe(Schema.minLength(1)), { as: "Option" }),
|
|
266
|
+
suggestion: Schema.optionalWith(Schema.NullOr(Schema.String), { as: "Option" })
|
|
267
|
+
});
|
|
268
|
+
var CommentNotFound = class extends Schema.TaggedError()("CommentNotFound", { id: CommentId }, HttpApiSchema.annotations({ status: 404 })) {};
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region ../../packages/core/src/services/comment.service.ts
|
|
271
|
+
var CommentService = class extends Effect.Service()("@ringi/CommentService", {
|
|
272
|
+
dependencies: [CommentRepo.Default],
|
|
273
|
+
effect: Effect.sync(() => {
|
|
274
|
+
const create = Effect.fn("CommentService.create")(function* create(reviewId, input) {
|
|
275
|
+
const repo = yield* CommentRepo;
|
|
276
|
+
const id = randomUUID();
|
|
277
|
+
return yield* repo.create({
|
|
278
|
+
content: input.content,
|
|
279
|
+
filePath: input.filePath,
|
|
280
|
+
id,
|
|
281
|
+
lineNumber: input.lineNumber,
|
|
282
|
+
lineType: input.lineType,
|
|
283
|
+
reviewId,
|
|
284
|
+
suggestion: input.suggestion
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
const getById = Effect.fn("CommentService.getById")(function* getById(id) {
|
|
288
|
+
const comment = yield* (yield* CommentRepo).findById(id);
|
|
289
|
+
if (!comment) return yield* new CommentNotFound({ id });
|
|
290
|
+
return comment;
|
|
291
|
+
});
|
|
292
|
+
const getByReview = Effect.fn("CommentService.getByReview")(function* getByReview(reviewId) {
|
|
293
|
+
return yield* (yield* CommentRepo).findByReview(reviewId);
|
|
294
|
+
});
|
|
295
|
+
const getByFile = Effect.fn("CommentService.getByFile")(function* getByFile(reviewId, filePath) {
|
|
296
|
+
return yield* (yield* CommentRepo).findByFile(reviewId, filePath);
|
|
297
|
+
});
|
|
298
|
+
const update = Effect.fn("CommentService.update")(function* update(id, input) {
|
|
299
|
+
const repo = yield* CommentRepo;
|
|
300
|
+
const updates = {};
|
|
301
|
+
if (Option.isSome(input.content)) updates.content = input.content.value;
|
|
302
|
+
if (Option.isSome(input.suggestion)) updates.suggestion = input.suggestion.value;
|
|
303
|
+
const comment = yield* repo.update(id, updates);
|
|
304
|
+
if (!comment) return yield* new CommentNotFound({ id });
|
|
305
|
+
return comment;
|
|
306
|
+
});
|
|
307
|
+
const resolve = Effect.fn("CommentService.resolve")(function* resolve(id) {
|
|
308
|
+
const comment = yield* (yield* CommentRepo).setResolved(id, true);
|
|
309
|
+
if (!comment) return yield* new CommentNotFound({ id });
|
|
310
|
+
return comment;
|
|
311
|
+
});
|
|
312
|
+
const unresolve = Effect.fn("CommentService.unresolve")(function* unresolve(id) {
|
|
313
|
+
const comment = yield* (yield* CommentRepo).setResolved(id, false);
|
|
314
|
+
if (!comment) return yield* new CommentNotFound({ id });
|
|
315
|
+
return comment;
|
|
316
|
+
});
|
|
317
|
+
const remove = Effect.fn("CommentService.remove")(function* remove(id) {
|
|
318
|
+
if (!(yield* (yield* CommentRepo).remove(id))) return yield* new CommentNotFound({ id });
|
|
319
|
+
return { success: true };
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
create,
|
|
323
|
+
getByFile,
|
|
324
|
+
getById,
|
|
325
|
+
getByReview,
|
|
326
|
+
getStats: Effect.fn("CommentService.getStats")(function* getStats(reviewId) {
|
|
327
|
+
return yield* (yield* CommentRepo).countByReview(reviewId);
|
|
328
|
+
}),
|
|
329
|
+
remove,
|
|
330
|
+
resolve,
|
|
331
|
+
unresolve,
|
|
332
|
+
update
|
|
333
|
+
};
|
|
334
|
+
})
|
|
335
|
+
}) {};
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region ../../packages/core/src/services/diff.service.ts
|
|
338
|
+
const HUNK_HEADER = /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
339
|
+
const splitIntoFiles = (diffText) => {
|
|
340
|
+
const files = [];
|
|
341
|
+
const lines = diffText.split("\n");
|
|
342
|
+
let current = [];
|
|
343
|
+
for (const line of lines) if (line.startsWith("diff --git")) {
|
|
344
|
+
if (current.length > 0) files.push(current.join("\n"));
|
|
345
|
+
current = [line];
|
|
346
|
+
} else current.push(line);
|
|
347
|
+
if (current.length > 0) files.push(current.join("\n"));
|
|
348
|
+
return files;
|
|
349
|
+
};
|
|
350
|
+
const parseHunks$1 = (lines) => {
|
|
351
|
+
const hunks = [];
|
|
352
|
+
let currentHunk = null;
|
|
353
|
+
let oldLineNum = 0;
|
|
354
|
+
let newLineNum = 0;
|
|
355
|
+
for (const line of lines) {
|
|
356
|
+
const match = line.match(HUNK_HEADER);
|
|
357
|
+
if (match) {
|
|
358
|
+
if (currentHunk) hunks.push(currentHunk);
|
|
359
|
+
const oldStart = Number.parseInt(match[1], 10);
|
|
360
|
+
const oldLines = Number.parseInt(match[2] ?? "1", 10);
|
|
361
|
+
const newStart = Number.parseInt(match[3], 10);
|
|
362
|
+
currentHunk = {
|
|
363
|
+
lines: [],
|
|
364
|
+
newLines: Number.parseInt(match[4] ?? "1", 10),
|
|
365
|
+
newStart,
|
|
366
|
+
oldLines,
|
|
367
|
+
oldStart
|
|
368
|
+
};
|
|
369
|
+
oldLineNum = oldStart;
|
|
370
|
+
newLineNum = newStart;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (!currentHunk) continue;
|
|
374
|
+
if (line.startsWith("+") && !line.startsWith("+++")) currentHunk.lines.push({
|
|
375
|
+
content: line.slice(1),
|
|
376
|
+
newLineNumber: newLineNum++,
|
|
377
|
+
oldLineNumber: null,
|
|
378
|
+
type: "added"
|
|
379
|
+
});
|
|
380
|
+
else if (line.startsWith("-") && !line.startsWith("---")) currentHunk.lines.push({
|
|
381
|
+
content: line.slice(1),
|
|
382
|
+
newLineNumber: null,
|
|
383
|
+
oldLineNumber: oldLineNum++,
|
|
384
|
+
type: "removed"
|
|
385
|
+
});
|
|
386
|
+
else if (line.startsWith(" ")) currentHunk.lines.push({
|
|
387
|
+
content: line.slice(1),
|
|
388
|
+
newLineNumber: newLineNum++,
|
|
389
|
+
oldLineNumber: oldLineNum++,
|
|
390
|
+
type: "context"
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
if (currentHunk) hunks.push(currentHunk);
|
|
394
|
+
return hunks;
|
|
395
|
+
};
|
|
396
|
+
const parseFileDiff = (fileDiff) => {
|
|
397
|
+
const lines = fileDiff.split("\n");
|
|
398
|
+
const diffLine = lines.find((l) => l.startsWith("diff --git"));
|
|
399
|
+
if (!diffLine) return null;
|
|
400
|
+
const pathMatch = diffLine.match(/diff --git a\/(.+) b\/(.+)/);
|
|
401
|
+
if (!pathMatch) return null;
|
|
402
|
+
const oldPath = pathMatch[1];
|
|
403
|
+
const newPath = pathMatch[2];
|
|
404
|
+
let status = "modified";
|
|
405
|
+
if (lines.some((l) => l.startsWith("deleted file mode"))) status = "deleted";
|
|
406
|
+
else if (lines.some((l) => l.startsWith("new file mode"))) status = "added";
|
|
407
|
+
else if (lines.some((l) => l.startsWith("rename from")) || oldPath !== newPath) status = "renamed";
|
|
408
|
+
const hunks = parseHunks$1(lines);
|
|
409
|
+
let additions = 0;
|
|
410
|
+
let deletions = 0;
|
|
411
|
+
for (const hunk of hunks) for (const line of hunk.lines) if (line.type === "added") additions++;
|
|
412
|
+
else if (line.type === "removed") deletions++;
|
|
413
|
+
return {
|
|
414
|
+
additions,
|
|
415
|
+
deletions,
|
|
416
|
+
hunks,
|
|
417
|
+
newPath,
|
|
418
|
+
oldPath,
|
|
419
|
+
status
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
/** Parse a full multi-file unified diff into structured DiffFile objects. */
|
|
423
|
+
const parseDiff = (diffText) => {
|
|
424
|
+
if (!diffText.trim()) return [];
|
|
425
|
+
const blocks = splitIntoFiles(diffText);
|
|
426
|
+
const files = [];
|
|
427
|
+
for (const block of blocks) {
|
|
428
|
+
const parsed = parseFileDiff(block);
|
|
429
|
+
if (parsed) files.push(parsed);
|
|
430
|
+
}
|
|
431
|
+
return files;
|
|
432
|
+
};
|
|
433
|
+
/** Aggregate stats from already-parsed files. */
|
|
434
|
+
const getDiffSummary = (files) => {
|
|
435
|
+
let totalAdditions = 0;
|
|
436
|
+
let totalDeletions = 0;
|
|
437
|
+
for (const file of files) {
|
|
438
|
+
totalAdditions += file.additions;
|
|
439
|
+
totalDeletions += file.deletions;
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
filesAdded: files.filter((f) => f.status === "added").length,
|
|
443
|
+
filesDeleted: files.filter((f) => f.status === "deleted").length,
|
|
444
|
+
filesModified: files.filter((f) => f.status === "modified").length,
|
|
445
|
+
filesRenamed: files.filter((f) => f.status === "renamed").length,
|
|
446
|
+
totalAdditions,
|
|
447
|
+
totalDeletions,
|
|
448
|
+
totalFiles: files.length
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region ../../packages/core/src/repos/review-file.repo.ts
|
|
453
|
+
const parseHunks = (hunksData) => hunksData == null ? Effect.succeed([]) : Effect.try(() => JSON.parse(hunksData)).pipe(Effect.orElseSucceed(() => []));
|
|
454
|
+
const serializeHunks = (hunks) => JSON.stringify(hunks);
|
|
455
|
+
var ReviewFileRepo = class extends Effect.Service()("@ringi/ReviewFileRepo", {
|
|
456
|
+
dependencies: [SqliteService.Default],
|
|
457
|
+
effect: Effect.gen(function* effect() {
|
|
458
|
+
const { db } = yield* SqliteService;
|
|
459
|
+
const stmtFindByReview = db.prepare(`SELECT id, review_id, file_path, old_path, status, additions, deletions, created_at
|
|
460
|
+
FROM review_files WHERE review_id = ? ORDER BY file_path`);
|
|
461
|
+
const stmtFindByReviewAndPath = db.prepare("SELECT * FROM review_files WHERE review_id = ? AND file_path = ?");
|
|
462
|
+
const stmtInsert = db.prepare(`INSERT INTO review_files (id, review_id, file_path, old_path, status, additions, deletions, hunks_data, created_at)
|
|
463
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))`);
|
|
464
|
+
const stmtDeleteByReview = db.prepare("DELETE FROM review_files WHERE review_id = ?");
|
|
465
|
+
const stmtCountByReview = db.prepare("SELECT COUNT(*) as count FROM review_files WHERE review_id = ?");
|
|
466
|
+
const findByReview = (reviewId) => Effect.sync(() => stmtFindByReview.all(reviewId));
|
|
467
|
+
const findByReviewAndPath = (reviewId, filePath) => Effect.sync(() => {
|
|
468
|
+
return stmtFindByReviewAndPath.get(reviewId, filePath) ?? null;
|
|
469
|
+
});
|
|
470
|
+
const createBulk = (files) => withTransaction(db, Effect.sync(() => {
|
|
471
|
+
for (const f of files) stmtInsert.run(randomUUID(), f.reviewId, f.filePath, f.oldPath, f.status, f.additions, f.deletions, f.hunksData);
|
|
472
|
+
}));
|
|
473
|
+
const deleteByReview = (reviewId) => Effect.sync(() => {
|
|
474
|
+
const result = stmtDeleteByReview.run(reviewId);
|
|
475
|
+
return Number(result.changes);
|
|
476
|
+
});
|
|
477
|
+
const countByReview = (reviewId) => Effect.sync(() => {
|
|
478
|
+
return stmtCountByReview.get(reviewId).count;
|
|
479
|
+
});
|
|
480
|
+
return {
|
|
481
|
+
countByReview,
|
|
482
|
+
createBulk,
|
|
483
|
+
deleteByReview,
|
|
484
|
+
findByReview,
|
|
485
|
+
findByReviewAndPath
|
|
486
|
+
};
|
|
487
|
+
})
|
|
488
|
+
}) {};
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region ../../packages/core/src/repos/review.repo.ts
|
|
491
|
+
const rowToReview = (row) => ({
|
|
492
|
+
baseRef: row.base_ref,
|
|
493
|
+
createdAt: row.created_at,
|
|
494
|
+
id: row.id,
|
|
495
|
+
repositoryPath: row.repository_path,
|
|
496
|
+
snapshotData: row.snapshot_data,
|
|
497
|
+
sourceRef: row.source_ref,
|
|
498
|
+
sourceType: row.source_type,
|
|
499
|
+
status: row.status,
|
|
500
|
+
updatedAt: row.updated_at
|
|
501
|
+
});
|
|
502
|
+
var ReviewRepo = class extends Effect.Service()("@ringi/ReviewRepo", {
|
|
503
|
+
dependencies: [SqliteService.Default],
|
|
504
|
+
effect: Effect.gen(function* effect() {
|
|
505
|
+
const { db } = yield* SqliteService;
|
|
506
|
+
const stmtFindById = db.prepare("SELECT * FROM reviews WHERE id = ?");
|
|
507
|
+
const stmtInsert = db.prepare(`INSERT INTO reviews (id, repository_path, base_ref, source_type, source_ref, snapshot_data, status, created_at, updated_at)
|
|
508
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))`);
|
|
509
|
+
const stmtUpdate = db.prepare(`UPDATE reviews SET status = COALESCE(?, status), updated_at = datetime('now') WHERE id = ?`);
|
|
510
|
+
const stmtDelete = db.prepare("DELETE FROM reviews WHERE id = ?");
|
|
511
|
+
const stmtCountAll = db.prepare("SELECT COUNT(*) as count FROM reviews");
|
|
512
|
+
const stmtCountByStatus = db.prepare("SELECT COUNT(*) as count FROM reviews WHERE status = ?");
|
|
513
|
+
const findById = (id) => Effect.sync(() => {
|
|
514
|
+
const row = stmtFindById.get(id);
|
|
515
|
+
return row ? rowToReview(row) : null;
|
|
516
|
+
});
|
|
517
|
+
const findAll = (opts = {}) => Effect.sync(() => {
|
|
518
|
+
const conditions = [];
|
|
519
|
+
const params = [];
|
|
520
|
+
if (opts.status != null) {
|
|
521
|
+
conditions.push("status = ?");
|
|
522
|
+
params.push(opts.status);
|
|
523
|
+
}
|
|
524
|
+
if (opts.repositoryPath != null) {
|
|
525
|
+
conditions.push("repository_path = ?");
|
|
526
|
+
params.push(opts.repositoryPath);
|
|
527
|
+
}
|
|
528
|
+
if (opts.sourceType != null) {
|
|
529
|
+
conditions.push("source_type = ?");
|
|
530
|
+
params.push(opts.sourceType);
|
|
531
|
+
}
|
|
532
|
+
const where = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
|
|
533
|
+
const page = opts.page ?? 1;
|
|
534
|
+
const pageSize = opts.pageSize ?? 20;
|
|
535
|
+
const offset = (page - 1) * pageSize;
|
|
536
|
+
const totalRow = db.prepare(`SELECT COUNT(*) as count FROM reviews${where}`).get(...params);
|
|
537
|
+
return {
|
|
538
|
+
data: db.prepare(`SELECT * FROM reviews${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`).all(...params, pageSize, offset).map(rowToReview),
|
|
539
|
+
total: totalRow.count
|
|
540
|
+
};
|
|
541
|
+
});
|
|
542
|
+
const create = (input) => Effect.sync(() => {
|
|
543
|
+
stmtInsert.run(input.id, input.repositoryPath, input.baseRef, input.sourceType, input.sourceRef, input.snapshotData, input.status);
|
|
544
|
+
return rowToReview(stmtFindById.get(input.id));
|
|
545
|
+
});
|
|
546
|
+
const update = (id, status) => Effect.sync(() => {
|
|
547
|
+
stmtUpdate.run(status, id);
|
|
548
|
+
const row = stmtFindById.get(id);
|
|
549
|
+
return row ? rowToReview(row) : null;
|
|
550
|
+
});
|
|
551
|
+
const remove = (id) => Effect.sync(() => {
|
|
552
|
+
const result = stmtDelete.run(id);
|
|
553
|
+
return Number(result.changes) > 0;
|
|
554
|
+
});
|
|
555
|
+
const countAll = () => Effect.sync(() => {
|
|
556
|
+
return stmtCountAll.get().count;
|
|
557
|
+
});
|
|
558
|
+
const countByStatus = (status) => Effect.sync(() => {
|
|
559
|
+
return stmtCountByStatus.get(status).count;
|
|
560
|
+
});
|
|
561
|
+
return {
|
|
562
|
+
countAll,
|
|
563
|
+
countByStatus,
|
|
564
|
+
create,
|
|
565
|
+
findAll,
|
|
566
|
+
findById,
|
|
567
|
+
remove,
|
|
568
|
+
update
|
|
569
|
+
};
|
|
570
|
+
})
|
|
571
|
+
}) {};
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region ../../packages/core/src/services/git.service.ts
|
|
574
|
+
var GitError = class extends Schema.TaggedError()("GitError", { message: Schema.String }, HttpApiSchema.annotations({ status: 500 })) {};
|
|
575
|
+
/** Max bytes to collect from a git command before truncating (200 MB). */
|
|
576
|
+
const MAX_STDOUT_BYTES = 200 * 1024 * 1024;
|
|
577
|
+
const execGit = (args, repoPath) => Effect.tryPromise({
|
|
578
|
+
catch: (error) => new GitError({ message: String(error) }),
|
|
579
|
+
try: () => new Promise((resolve, reject) => {
|
|
580
|
+
const child = spawn("git", [...args], { cwd: repoPath });
|
|
581
|
+
const chunks = [];
|
|
582
|
+
let bytes = 0;
|
|
583
|
+
let truncated = false;
|
|
584
|
+
child.stdout.on("data", (chunk) => {
|
|
585
|
+
if (truncated) return;
|
|
586
|
+
bytes += chunk.length;
|
|
587
|
+
if (bytes > MAX_STDOUT_BYTES) {
|
|
588
|
+
truncated = true;
|
|
589
|
+
child.kill();
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
chunks.push(chunk);
|
|
593
|
+
});
|
|
594
|
+
let stderr = "";
|
|
595
|
+
child.stderr.on("data", (chunk) => {
|
|
596
|
+
stderr += chunk.toString();
|
|
597
|
+
});
|
|
598
|
+
child.on("error", reject);
|
|
599
|
+
child.on("close", (code) => {
|
|
600
|
+
if (truncated) {
|
|
601
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (code !== 0) reject(/* @__PURE__ */ new Error(`git ${args[0]} exited with code ${code}: ${stderr}`));
|
|
605
|
+
else resolve(Buffer.concat(chunks).toString("utf8"));
|
|
606
|
+
});
|
|
607
|
+
})
|
|
608
|
+
});
|
|
609
|
+
/** Split git output into non-empty lines. */
|
|
610
|
+
const lines = (output) => output.trim().split("\n").filter(Boolean);
|
|
611
|
+
/** Parse name-status output (e.g. `M\tfile.ts`). */
|
|
612
|
+
const parseNameStatus = (output) => lines(output).map((line) => {
|
|
613
|
+
const [status, ...rest] = line.split(" ");
|
|
614
|
+
return {
|
|
615
|
+
path: rest.join(" "),
|
|
616
|
+
status
|
|
617
|
+
};
|
|
618
|
+
});
|
|
619
|
+
var GitService = class extends Effect.Service()("@ringi/GitService", { effect: Effect.gen(function* effect() {
|
|
620
|
+
const repoPath = yield* Config.string("REPOSITORY_PATH").pipe(Config.withDefault(process.cwd()));
|
|
621
|
+
const hasCommits = execGit(["rev-parse", "HEAD"], repoPath).pipe(Effect.as(true), Effect.catchTag("GitError", () => Effect.succeed(false)), Effect.withSpan("GitService.hasCommits"));
|
|
622
|
+
const getRepositoryInfo = Effect.gen(function* getRepositoryInfo() {
|
|
623
|
+
const name = yield* execGit(["rev-parse", "--show-toplevel"], repoPath).pipe(Effect.map((s) => s.trim().split("/").pop() ?? "unknown"));
|
|
624
|
+
return {
|
|
625
|
+
branch: yield* execGit([
|
|
626
|
+
"rev-parse",
|
|
627
|
+
"--abbrev-ref",
|
|
628
|
+
"HEAD"
|
|
629
|
+
], repoPath).pipe(Effect.map((s) => s.trim())),
|
|
630
|
+
name,
|
|
631
|
+
path: repoPath,
|
|
632
|
+
remote: yield* execGit([
|
|
633
|
+
"config",
|
|
634
|
+
"--get",
|
|
635
|
+
"remote.origin.url"
|
|
636
|
+
], repoPath).pipe(Effect.map((s) => s.trim() || null), Effect.catchTag("GitError", () => Effect.succeed(null)))
|
|
637
|
+
};
|
|
638
|
+
}).pipe(Effect.withSpan("GitService.getRepositoryInfo"));
|
|
639
|
+
const getStagedDiff = execGit([
|
|
640
|
+
"diff",
|
|
641
|
+
"--cached",
|
|
642
|
+
"--no-color",
|
|
643
|
+
"--unified=3"
|
|
644
|
+
], repoPath).pipe(Effect.withSpan("GitService.getStagedDiff"));
|
|
645
|
+
const getUncommittedDiff = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
|
|
646
|
+
"diff",
|
|
647
|
+
"HEAD",
|
|
648
|
+
"--no-color",
|
|
649
|
+
"--unified=3"
|
|
650
|
+
], repoPath) : Effect.succeed("")), Effect.withSpan("GitService.getUncommittedDiff"));
|
|
651
|
+
const getUnstagedDiff = execGit([
|
|
652
|
+
"diff",
|
|
653
|
+
"--no-color",
|
|
654
|
+
"--unified=3"
|
|
655
|
+
], repoPath).pipe(Effect.withSpan("GitService.getUnstagedDiff"));
|
|
656
|
+
const getLastCommitDiff = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
|
|
657
|
+
"show",
|
|
658
|
+
"HEAD",
|
|
659
|
+
"--format=",
|
|
660
|
+
"--no-color",
|
|
661
|
+
"--unified=3"
|
|
662
|
+
], repoPath) : Effect.succeed("")), Effect.withSpan("GitService.getLastCommitDiff"));
|
|
663
|
+
const getBranchDiff = Effect.fn("GitService.getBranchDiff")(function* getBranchDiff(branch) {
|
|
664
|
+
return yield* execGit([
|
|
665
|
+
"diff",
|
|
666
|
+
`${branch}...HEAD`,
|
|
667
|
+
"--no-color",
|
|
668
|
+
"--unified=3"
|
|
669
|
+
], repoPath);
|
|
670
|
+
});
|
|
671
|
+
const getCommitDiff = Effect.fn("GitService.getCommitDiff")(function* getCommitDiff(shas) {
|
|
672
|
+
if (shas.length === 1) return yield* execGit([
|
|
673
|
+
"show",
|
|
674
|
+
shas[0],
|
|
675
|
+
"--format=",
|
|
676
|
+
"--no-color",
|
|
677
|
+
"--unified=3"
|
|
678
|
+
], repoPath);
|
|
679
|
+
const first = shas.at(-1);
|
|
680
|
+
const last = shas[0];
|
|
681
|
+
return yield* execGit([
|
|
682
|
+
"diff",
|
|
683
|
+
`${first}~1..${last}`,
|
|
684
|
+
"--no-color",
|
|
685
|
+
"--unified=3"
|
|
686
|
+
], repoPath);
|
|
687
|
+
});
|
|
688
|
+
const getStagedFiles = execGit([
|
|
689
|
+
"diff",
|
|
690
|
+
"--cached",
|
|
691
|
+
"--name-status"
|
|
692
|
+
], repoPath).pipe(Effect.map(parseNameStatus), Effect.withSpan("GitService.getStagedFiles"));
|
|
693
|
+
const getUncommittedFiles = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
|
|
694
|
+
"diff",
|
|
695
|
+
"HEAD",
|
|
696
|
+
"--name-status"
|
|
697
|
+
], repoPath).pipe(Effect.map(parseNameStatus)) : Effect.succeed([])), Effect.withSpan("GitService.getUncommittedFiles"));
|
|
698
|
+
const getUnstagedFiles = execGit(["diff", "--name-status"], repoPath).pipe(Effect.map(parseNameStatus), Effect.withSpan("GitService.getUnstagedFiles"));
|
|
699
|
+
const getLastCommitFiles = hasCommits.pipe(Effect.flatMap((has) => has ? execGit([
|
|
700
|
+
"show",
|
|
701
|
+
"HEAD",
|
|
702
|
+
"--format=",
|
|
703
|
+
"--name-status"
|
|
704
|
+
], repoPath).pipe(Effect.map(parseNameStatus)) : Effect.succeed([])), Effect.withSpan("GitService.getLastCommitFiles"));
|
|
705
|
+
const getFileContent = Effect.fn("GitService.getFileContent")(function* getFileContent(filePath, version) {
|
|
706
|
+
switch (version) {
|
|
707
|
+
case "staged": return yield* execGit(["show", `:${filePath}`], repoPath);
|
|
708
|
+
case "head": return yield* execGit(["show", `HEAD:${filePath}`], repoPath);
|
|
709
|
+
default: return yield* Effect.tryPromise({
|
|
710
|
+
catch: (error) => new GitError({ message: `Failed to read ${filePath}: ${String(error)}` }),
|
|
711
|
+
try: () => readFile(join(repoPath, filePath), "utf8")
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
const getFileTree = Effect.fn("GitService.getFileTree")(function* getFileTree(ref) {
|
|
716
|
+
return yield* execGit([
|
|
717
|
+
"ls-tree",
|
|
718
|
+
"-r",
|
|
719
|
+
"--name-only",
|
|
720
|
+
ref
|
|
721
|
+
], repoPath).pipe(Effect.map(lines));
|
|
722
|
+
});
|
|
723
|
+
const getBranches = execGit(["branch", "--format=%(refname:short) %(HEAD)"], repoPath).pipe(Effect.map((output) => lines(output).map((line) => {
|
|
724
|
+
const [name, head] = line.split(" ");
|
|
725
|
+
return {
|
|
726
|
+
current: head === "*",
|
|
727
|
+
name
|
|
728
|
+
};
|
|
729
|
+
})), Effect.withSpan("GitService.getBranches"));
|
|
730
|
+
const getCommits = Effect.fn("GitService.getCommits")(function* getCommits(opts) {
|
|
731
|
+
const limit = (opts.limit ?? 20) + 1;
|
|
732
|
+
const args = [
|
|
733
|
+
"log",
|
|
734
|
+
`--max-count=${limit}`,
|
|
735
|
+
`--skip=${opts.offset ?? 0}`,
|
|
736
|
+
"--format=%H %s %an %aI"
|
|
737
|
+
];
|
|
738
|
+
if (opts.search) args.push(`--grep=${opts.search}`, "-i");
|
|
739
|
+
const rows = lines(yield* execGit(args, repoPath));
|
|
740
|
+
const hasMore = rows.length === limit;
|
|
741
|
+
return {
|
|
742
|
+
commits: (hasMore ? rows.slice(0, -1) : rows).map((line) => {
|
|
743
|
+
const [hash, message, author, date] = line.split(" ");
|
|
744
|
+
return {
|
|
745
|
+
author,
|
|
746
|
+
date,
|
|
747
|
+
hash,
|
|
748
|
+
message
|
|
749
|
+
};
|
|
750
|
+
}),
|
|
751
|
+
hasMore
|
|
752
|
+
};
|
|
753
|
+
});
|
|
754
|
+
const stageFiles = Effect.fn("GitService.stageFiles")(function* stageFiles(files) {
|
|
755
|
+
return yield* execGit([
|
|
756
|
+
"add",
|
|
757
|
+
"--",
|
|
758
|
+
...files
|
|
759
|
+
], repoPath).pipe(Effect.as(files));
|
|
760
|
+
});
|
|
761
|
+
const stageAll = execGit(["add", "-A"], repoPath).pipe(Effect.flatMap(() => getStagedFiles), Effect.map((files) => files.map((f) => f.path)), Effect.withSpan("GitService.stageAll"));
|
|
762
|
+
const unstageFiles = Effect.fn("GitService.unstageFiles")(function* unstageFiles(files) {
|
|
763
|
+
return yield* execGit([
|
|
764
|
+
"reset",
|
|
765
|
+
"HEAD",
|
|
766
|
+
"--",
|
|
767
|
+
...files
|
|
768
|
+
], repoPath).pipe(Effect.as(files));
|
|
769
|
+
});
|
|
770
|
+
return {
|
|
771
|
+
getBranchDiff,
|
|
772
|
+
getBranches,
|
|
773
|
+
getCommitDiff,
|
|
774
|
+
getCommits,
|
|
775
|
+
getFileContent,
|
|
776
|
+
getFileTree,
|
|
777
|
+
getLastCommitDiff,
|
|
778
|
+
getLastCommitFiles,
|
|
779
|
+
getRepositoryInfo,
|
|
780
|
+
getRepositoryPath: execGit(["rev-parse", "--show-toplevel"], repoPath).pipe(Effect.map((s) => s.trim()), Effect.withSpan("GitService.getRepositoryPath")),
|
|
781
|
+
getStagedDiff,
|
|
782
|
+
getStagedFiles,
|
|
783
|
+
getUncommittedDiff,
|
|
784
|
+
getUncommittedFiles,
|
|
785
|
+
getUnstagedDiff,
|
|
786
|
+
getUnstagedFiles,
|
|
787
|
+
hasCommits,
|
|
788
|
+
stageAll,
|
|
789
|
+
stageFiles,
|
|
790
|
+
unstageFiles
|
|
791
|
+
};
|
|
792
|
+
}) }) {};
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region ../../packages/core/src/services/review.service.ts
|
|
795
|
+
var ReviewError = class extends Schema.TaggedError()("ReviewError", {
|
|
796
|
+
code: Schema.String,
|
|
797
|
+
message: Schema.String
|
|
798
|
+
}, HttpApiSchema.annotations({ status: 400 })) {};
|
|
799
|
+
/** Get HEAD SHA via git rev-parse. */
|
|
800
|
+
const getHeadSha = (repoPath) => Effect.tryPromise({
|
|
801
|
+
catch: () => new ReviewError({
|
|
802
|
+
code: "GIT_ERROR",
|
|
803
|
+
message: "Failed to get HEAD"
|
|
804
|
+
}),
|
|
805
|
+
try: () => new Promise((resolve, reject) => {
|
|
806
|
+
execFile("git", ["rev-parse", "HEAD"], { cwd: repoPath }, (err, stdout) => {
|
|
807
|
+
if (err) reject(err);
|
|
808
|
+
else resolve(stdout.trim());
|
|
809
|
+
});
|
|
810
|
+
})
|
|
811
|
+
});
|
|
812
|
+
/**
|
|
813
|
+
* Parse snapshotData JSON. Handles both v1 and v2 formats gracefully.
|
|
814
|
+
* v1: { files: DiffFile[], repository: {...} }
|
|
815
|
+
* v2: { repository: {...}, version: 2 }
|
|
816
|
+
*/
|
|
817
|
+
const parseSnapshotData = (s) => Effect.try(() => JSON.parse(s)).pipe(Effect.orElseSucceed(() => ({})));
|
|
818
|
+
var ReviewService = class extends Effect.Service()("@ringi/ReviewService", {
|
|
819
|
+
dependencies: [
|
|
820
|
+
ReviewRepo.Default,
|
|
821
|
+
ReviewFileRepo.Default,
|
|
822
|
+
GitService.Default
|
|
823
|
+
],
|
|
824
|
+
effect: Effect.sync(() => {
|
|
825
|
+
const create = Effect.fn("ReviewService.create")(function* create(input) {
|
|
826
|
+
const git = yield* GitService;
|
|
827
|
+
const repo = yield* ReviewRepo;
|
|
828
|
+
const fileRepo = yield* ReviewFileRepo;
|
|
829
|
+
const repoPath = yield* git.getRepositoryPath;
|
|
830
|
+
if (!(yield* git.hasCommits)) return yield* new ReviewError({
|
|
831
|
+
code: "NO_COMMITS",
|
|
832
|
+
message: "Repository has no commits"
|
|
833
|
+
});
|
|
834
|
+
let diffText;
|
|
835
|
+
let baseRef = null;
|
|
836
|
+
const { sourceType, sourceRef } = input;
|
|
837
|
+
switch (sourceType) {
|
|
838
|
+
case "staged":
|
|
839
|
+
diffText = yield* git.getStagedDiff;
|
|
840
|
+
if (!diffText.trim()) return yield* new ReviewError({
|
|
841
|
+
code: "NO_STAGED_CHANGES",
|
|
842
|
+
message: "No staged changes"
|
|
843
|
+
});
|
|
844
|
+
baseRef = yield* getHeadSha(repoPath);
|
|
845
|
+
break;
|
|
846
|
+
case "branch":
|
|
847
|
+
if (!sourceRef) return yield* new ReviewError({
|
|
848
|
+
code: "INVALID_SOURCE",
|
|
849
|
+
message: "Branch name required"
|
|
850
|
+
});
|
|
851
|
+
diffText = yield* git.getBranchDiff(sourceRef);
|
|
852
|
+
baseRef = sourceRef;
|
|
853
|
+
break;
|
|
854
|
+
case "commits": {
|
|
855
|
+
if (!sourceRef) return yield* new ReviewError({
|
|
856
|
+
code: "INVALID_SOURCE",
|
|
857
|
+
message: "Commit SHAs required"
|
|
858
|
+
});
|
|
859
|
+
const shas = sourceRef.split(",").map((s) => s.trim()).filter(Boolean);
|
|
860
|
+
if (shas.length === 0) return yield* new ReviewError({
|
|
861
|
+
code: "INVALID_SOURCE",
|
|
862
|
+
message: "No valid commit SHAs"
|
|
863
|
+
});
|
|
864
|
+
diffText = yield* git.getCommitDiff(shas);
|
|
865
|
+
baseRef = shas.at(-1) ?? null;
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
default: return yield* new ReviewError({
|
|
869
|
+
code: "INVALID_SOURCE",
|
|
870
|
+
message: "Unsupported review source"
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
const files = parseDiff(diffText);
|
|
874
|
+
if (files.length === 0) return yield* new ReviewError({
|
|
875
|
+
code: "NO_CHANGES",
|
|
876
|
+
message: "No changes found"
|
|
877
|
+
});
|
|
878
|
+
const repoInfo = yield* git.getRepositoryInfo;
|
|
879
|
+
const reviewId = crypto.randomUUID();
|
|
880
|
+
const storeHunks = sourceType === "staged";
|
|
881
|
+
const fileInputs = files.map((f) => ({
|
|
882
|
+
additions: f.additions,
|
|
883
|
+
deletions: f.deletions,
|
|
884
|
+
filePath: f.newPath,
|
|
885
|
+
hunksData: storeHunks ? serializeHunks(f.hunks) : null,
|
|
886
|
+
oldPath: f.oldPath !== f.newPath ? f.oldPath : null,
|
|
887
|
+
reviewId,
|
|
888
|
+
status: f.status
|
|
889
|
+
}));
|
|
890
|
+
const snapshotData = JSON.stringify({
|
|
891
|
+
repository: repoInfo,
|
|
892
|
+
version: 2
|
|
893
|
+
});
|
|
894
|
+
const review = yield* repo.create({
|
|
895
|
+
baseRef,
|
|
896
|
+
id: reviewId,
|
|
897
|
+
repositoryPath: repoPath,
|
|
898
|
+
snapshotData,
|
|
899
|
+
sourceRef: sourceRef ?? null,
|
|
900
|
+
sourceType,
|
|
901
|
+
status: "in_progress"
|
|
902
|
+
});
|
|
903
|
+
yield* fileRepo.createBulk(fileInputs);
|
|
904
|
+
return review;
|
|
905
|
+
});
|
|
906
|
+
const list = Effect.fn("ReviewService.list")(function* list(opts) {
|
|
907
|
+
const repo = yield* ReviewRepo;
|
|
908
|
+
const fileRepo = yield* ReviewFileRepo;
|
|
909
|
+
const page = opts.page ?? 1;
|
|
910
|
+
const pageSize = opts.pageSize ?? 20;
|
|
911
|
+
const result = yield* repo.findAll({
|
|
912
|
+
page,
|
|
913
|
+
pageSize,
|
|
914
|
+
repositoryPath: opts.repositoryPath,
|
|
915
|
+
sourceType: opts.sourceType,
|
|
916
|
+
status: opts.status
|
|
917
|
+
});
|
|
918
|
+
const reviews = [];
|
|
919
|
+
for (const review of result.data) {
|
|
920
|
+
const fileCount = yield* fileRepo.countByReview(review.id);
|
|
921
|
+
const snapshot = yield* parseSnapshotData(review.snapshotData);
|
|
922
|
+
reviews.push({
|
|
923
|
+
...review,
|
|
924
|
+
fileCount,
|
|
925
|
+
repository: snapshot.repository ?? null
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return {
|
|
929
|
+
hasMore: page * pageSize < result.total,
|
|
930
|
+
page,
|
|
931
|
+
pageSize,
|
|
932
|
+
reviews,
|
|
933
|
+
total: result.total
|
|
934
|
+
};
|
|
935
|
+
});
|
|
936
|
+
const getById = Effect.fn("ReviewService.getById")(function* getById(id) {
|
|
937
|
+
const repo = yield* ReviewRepo;
|
|
938
|
+
const fileRepo = yield* ReviewFileRepo;
|
|
939
|
+
const review = yield* repo.findById(id);
|
|
940
|
+
if (!review) return yield* new ReviewNotFound({ id });
|
|
941
|
+
const files = (yield* fileRepo.findByReview(id)).map((r) => ({
|
|
942
|
+
additions: r.additions,
|
|
943
|
+
deletions: r.deletions,
|
|
944
|
+
filePath: r.file_path,
|
|
945
|
+
id: r.id,
|
|
946
|
+
oldPath: r.old_path,
|
|
947
|
+
status: r.status
|
|
948
|
+
}));
|
|
949
|
+
const snapshot = yield* parseSnapshotData(review.snapshotData);
|
|
950
|
+
const summary = getDiffSummary(files.map((f) => ({
|
|
951
|
+
additions: f.additions,
|
|
952
|
+
deletions: f.deletions,
|
|
953
|
+
hunks: [],
|
|
954
|
+
newPath: f.filePath,
|
|
955
|
+
oldPath: f.oldPath ?? f.filePath,
|
|
956
|
+
status: f.status
|
|
957
|
+
})));
|
|
958
|
+
return {
|
|
959
|
+
...review,
|
|
960
|
+
files,
|
|
961
|
+
repository: snapshot.repository ?? null,
|
|
962
|
+
summary
|
|
963
|
+
};
|
|
964
|
+
});
|
|
965
|
+
const getFileHunks = Effect.fn("ReviewService.getFileHunks")(function* getFileHunks(reviewId, filePath) {
|
|
966
|
+
const repo = yield* ReviewRepo;
|
|
967
|
+
const fileRepo = yield* ReviewFileRepo;
|
|
968
|
+
const git = yield* GitService;
|
|
969
|
+
const review = yield* repo.findById(reviewId);
|
|
970
|
+
if (!review) return yield* new ReviewNotFound({ id: reviewId });
|
|
971
|
+
const fileRecord = yield* fileRepo.findByReviewAndPath(reviewId, filePath);
|
|
972
|
+
if (fileRecord?.hunks_data) return yield* parseHunks(fileRecord.hunks_data);
|
|
973
|
+
if (review.sourceType === "branch" && review.sourceRef) return parseDiff(yield* git.getBranchDiff(review.sourceRef)).find((f) => f.newPath === filePath)?.hunks ?? [];
|
|
974
|
+
if (review.sourceType === "commits" && review.sourceRef) {
|
|
975
|
+
const shas = review.sourceRef.split(",").map((s) => s.trim());
|
|
976
|
+
return parseDiff(yield* git.getCommitDiff(shas)).find((f) => f.newPath === filePath)?.hunks ?? [];
|
|
977
|
+
}
|
|
978
|
+
const snapshot = yield* parseSnapshotData(review.snapshotData);
|
|
979
|
+
if (snapshot.files) return snapshot.files.find((f) => f.newPath === filePath)?.hunks ?? [];
|
|
980
|
+
return [];
|
|
981
|
+
});
|
|
982
|
+
const update = Effect.fn("ReviewService.update")(function* update(id, input) {
|
|
983
|
+
const repo = yield* ReviewRepo;
|
|
984
|
+
if (!(yield* repo.findById(id))) return yield* new ReviewNotFound({ id });
|
|
985
|
+
const status = Option.getOrNull(input.status);
|
|
986
|
+
const review = yield* repo.update(id, status);
|
|
987
|
+
if (!review) return yield* new ReviewNotFound({ id });
|
|
988
|
+
return review;
|
|
989
|
+
});
|
|
990
|
+
const remove = Effect.fn("ReviewService.remove")(function* remove(id) {
|
|
991
|
+
const repo = yield* ReviewRepo;
|
|
992
|
+
const fileRepo = yield* ReviewFileRepo;
|
|
993
|
+
if (!(yield* repo.findById(id))) return yield* new ReviewNotFound({ id });
|
|
994
|
+
yield* fileRepo.deleteByReview(id);
|
|
995
|
+
yield* repo.remove(id);
|
|
996
|
+
return { success: true };
|
|
997
|
+
});
|
|
998
|
+
return {
|
|
999
|
+
create,
|
|
1000
|
+
getById,
|
|
1001
|
+
getFileHunks,
|
|
1002
|
+
getStats: Effect.fn("ReviewService.getStats")(function* getStats() {
|
|
1003
|
+
const repo = yield* ReviewRepo;
|
|
1004
|
+
const total = yield* repo.countAll();
|
|
1005
|
+
const inProgress = yield* repo.countByStatus("in_progress");
|
|
1006
|
+
return {
|
|
1007
|
+
approved: yield* repo.countByStatus("approved"),
|
|
1008
|
+
changesRequested: yield* repo.countByStatus("changes_requested"),
|
|
1009
|
+
inProgress,
|
|
1010
|
+
total
|
|
1011
|
+
};
|
|
1012
|
+
}),
|
|
1013
|
+
list,
|
|
1014
|
+
remove,
|
|
1015
|
+
update
|
|
1016
|
+
};
|
|
1017
|
+
})
|
|
1018
|
+
}) {};
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region ../../packages/core/src/repos/todo.repo.ts
|
|
1021
|
+
const rowToTodo = (row) => ({
|
|
1022
|
+
completed: row.completed === 1,
|
|
1023
|
+
content: row.content,
|
|
1024
|
+
createdAt: row.created_at,
|
|
1025
|
+
id: row.id,
|
|
1026
|
+
position: row.position,
|
|
1027
|
+
reviewId: row.review_id,
|
|
1028
|
+
updatedAt: row.updated_at
|
|
1029
|
+
});
|
|
1030
|
+
var TodoRepo = class extends Effect.Service()("@ringi/TodoRepo", {
|
|
1031
|
+
dependencies: [SqliteService.Default],
|
|
1032
|
+
effect: Effect.gen(function* effect() {
|
|
1033
|
+
const { db } = yield* SqliteService;
|
|
1034
|
+
const stmtFindById = db.prepare("SELECT * FROM todos WHERE id = ?");
|
|
1035
|
+
const stmtInsert = db.prepare(`INSERT INTO todos (id, content, completed, review_id, position, created_at, updated_at)
|
|
1036
|
+
VALUES (?, ?, 0, ?, ?, datetime('now'), datetime('now'))`);
|
|
1037
|
+
const stmtDelete = db.prepare("DELETE FROM todos WHERE id = ?");
|
|
1038
|
+
const stmtDeleteCompleted = db.prepare("DELETE FROM todos WHERE completed = 1");
|
|
1039
|
+
const stmtNextPosition = db.prepare("SELECT COALESCE(MAX(position), -1) + 1 AS next_pos FROM todos");
|
|
1040
|
+
const stmtCountAll = db.prepare("SELECT COUNT(*) as count FROM todos");
|
|
1041
|
+
const stmtCountCompleted = db.prepare("SELECT COUNT(*) as count FROM todos WHERE completed = 1");
|
|
1042
|
+
const stmtCountPending = db.prepare("SELECT COUNT(*) as count FROM todos WHERE completed = 0");
|
|
1043
|
+
const findById = (id) => Effect.sync(() => {
|
|
1044
|
+
const row = stmtFindById.get(id);
|
|
1045
|
+
return row ? rowToTodo(row) : null;
|
|
1046
|
+
});
|
|
1047
|
+
const findAll = (opts = {}) => Effect.sync(() => {
|
|
1048
|
+
const conditions = [];
|
|
1049
|
+
const params = [];
|
|
1050
|
+
if (opts.reviewId != null) {
|
|
1051
|
+
conditions.push("review_id = ?");
|
|
1052
|
+
params.push(opts.reviewId);
|
|
1053
|
+
}
|
|
1054
|
+
if (opts.completed != null) {
|
|
1055
|
+
conditions.push("completed = ?");
|
|
1056
|
+
params.push(opts.completed ? 1 : 0);
|
|
1057
|
+
}
|
|
1058
|
+
const where = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
|
|
1059
|
+
const totalRow = db.prepare(`SELECT COUNT(*) as count FROM todos${where}`).get(...params);
|
|
1060
|
+
const limitClause = opts.limit != null ? ` LIMIT ? OFFSET ?` : "";
|
|
1061
|
+
const queryParams = opts.limit != null ? [
|
|
1062
|
+
...params,
|
|
1063
|
+
opts.limit,
|
|
1064
|
+
opts.offset ?? 0
|
|
1065
|
+
] : params;
|
|
1066
|
+
return {
|
|
1067
|
+
data: db.prepare(`SELECT * FROM todos${where} ORDER BY position ASC${limitClause}`).all(...queryParams).map(rowToTodo),
|
|
1068
|
+
total: totalRow.count
|
|
1069
|
+
};
|
|
1070
|
+
});
|
|
1071
|
+
const create = (input) => Effect.sync(() => {
|
|
1072
|
+
const { next_pos } = stmtNextPosition.get();
|
|
1073
|
+
stmtInsert.run(input.id, input.content, input.reviewId, next_pos);
|
|
1074
|
+
return rowToTodo(stmtFindById.get(input.id));
|
|
1075
|
+
});
|
|
1076
|
+
const update = (id, updates) => Effect.sync(() => {
|
|
1077
|
+
const sets = [];
|
|
1078
|
+
const params = [];
|
|
1079
|
+
if (updates.content != null) {
|
|
1080
|
+
sets.push("content = ?");
|
|
1081
|
+
params.push(updates.content);
|
|
1082
|
+
}
|
|
1083
|
+
if (updates.completed != null) {
|
|
1084
|
+
sets.push("completed = ?");
|
|
1085
|
+
params.push(updates.completed ? 1 : 0);
|
|
1086
|
+
}
|
|
1087
|
+
if (sets.length === 0) {
|
|
1088
|
+
const row = stmtFindById.get(id);
|
|
1089
|
+
return row ? rowToTodo(row) : null;
|
|
1090
|
+
}
|
|
1091
|
+
sets.push("updated_at = datetime('now')");
|
|
1092
|
+
params.push(id);
|
|
1093
|
+
db.prepare(`UPDATE todos SET ${sets.join(", ")} WHERE id = ?`).run(...params);
|
|
1094
|
+
const row = stmtFindById.get(id);
|
|
1095
|
+
return row ? rowToTodo(row) : null;
|
|
1096
|
+
});
|
|
1097
|
+
const toggle = (id) => Effect.sync(() => {
|
|
1098
|
+
const row = stmtFindById.get(id);
|
|
1099
|
+
if (!row) return null;
|
|
1100
|
+
const newCompleted = row.completed === 1 ? 0 : 1;
|
|
1101
|
+
db.prepare("UPDATE todos SET completed = ?, updated_at = datetime('now') WHERE id = ?").run(newCompleted, id);
|
|
1102
|
+
return rowToTodo(stmtFindById.get(id));
|
|
1103
|
+
});
|
|
1104
|
+
const remove = (id) => Effect.sync(() => {
|
|
1105
|
+
const result = stmtDelete.run(id);
|
|
1106
|
+
return Number(result.changes) > 0;
|
|
1107
|
+
});
|
|
1108
|
+
const removeCompleted = () => Effect.sync(() => {
|
|
1109
|
+
const result = stmtDeleteCompleted.run();
|
|
1110
|
+
return Number(result.changes);
|
|
1111
|
+
});
|
|
1112
|
+
const reorder = (orderedIds) => withTransaction(db, Effect.sync(() => {
|
|
1113
|
+
const stmt = db.prepare("UPDATE todos SET position = ?, updated_at = datetime('now') WHERE id = ?");
|
|
1114
|
+
let updated = 0;
|
|
1115
|
+
for (let i = 0; i < orderedIds.length; i++) {
|
|
1116
|
+
const result = stmt.run(i, orderedIds[i]);
|
|
1117
|
+
updated += Number(result.changes);
|
|
1118
|
+
}
|
|
1119
|
+
return updated;
|
|
1120
|
+
}));
|
|
1121
|
+
const move = (id, newPosition) => Effect.gen(function* move() {
|
|
1122
|
+
const row = stmtFindById.get(id);
|
|
1123
|
+
if (!row) return null;
|
|
1124
|
+
const oldPosition = row.position;
|
|
1125
|
+
yield* withTransaction(db, Effect.sync(() => {
|
|
1126
|
+
if (newPosition < oldPosition) db.prepare("UPDATE todos SET position = position + 1, updated_at = datetime('now') WHERE position >= ? AND position < ? AND id != ?").run(newPosition, oldPosition, id);
|
|
1127
|
+
else if (newPosition > oldPosition) db.prepare("UPDATE todos SET position = position - 1, updated_at = datetime('now') WHERE position > ? AND position <= ? AND id != ?").run(oldPosition, newPosition, id);
|
|
1128
|
+
db.prepare("UPDATE todos SET position = ?, updated_at = datetime('now') WHERE id = ?").run(newPosition, id);
|
|
1129
|
+
}));
|
|
1130
|
+
return rowToTodo(stmtFindById.get(id));
|
|
1131
|
+
});
|
|
1132
|
+
const countAll = () => Effect.sync(() => {
|
|
1133
|
+
return stmtCountAll.get().count;
|
|
1134
|
+
});
|
|
1135
|
+
const countCompleted = () => Effect.sync(() => {
|
|
1136
|
+
return stmtCountCompleted.get().count;
|
|
1137
|
+
});
|
|
1138
|
+
const countPending = () => Effect.sync(() => {
|
|
1139
|
+
return stmtCountPending.get().count;
|
|
1140
|
+
});
|
|
1141
|
+
return {
|
|
1142
|
+
countAll,
|
|
1143
|
+
countCompleted,
|
|
1144
|
+
countPending,
|
|
1145
|
+
create,
|
|
1146
|
+
findAll,
|
|
1147
|
+
findById,
|
|
1148
|
+
move,
|
|
1149
|
+
remove,
|
|
1150
|
+
removeCompleted,
|
|
1151
|
+
reorder,
|
|
1152
|
+
toggle,
|
|
1153
|
+
update
|
|
1154
|
+
};
|
|
1155
|
+
})
|
|
1156
|
+
}) {};
|
|
1157
|
+
//#endregion
|
|
1158
|
+
//#region ../../packages/core/src/services/todo.service.ts
|
|
1159
|
+
var TodoService = class extends Effect.Service()("@ringi/TodoService", {
|
|
1160
|
+
dependencies: [TodoRepo.Default],
|
|
1161
|
+
effect: Effect.sync(() => {
|
|
1162
|
+
const create = Effect.fn("TodoService.create")(function* create(input) {
|
|
1163
|
+
const repo = yield* TodoRepo;
|
|
1164
|
+
const id = randomUUID();
|
|
1165
|
+
return yield* repo.create({
|
|
1166
|
+
content: input.content,
|
|
1167
|
+
id,
|
|
1168
|
+
reviewId: input.reviewId
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
const getById = Effect.fn("TodoService.getById")(function* getById(id) {
|
|
1172
|
+
const todo = yield* (yield* TodoRepo).findById(id);
|
|
1173
|
+
if (!todo) return yield* new TodoNotFound({ id });
|
|
1174
|
+
return todo;
|
|
1175
|
+
});
|
|
1176
|
+
const list = Effect.fn("TodoService.list")(function* list(opts = {}) {
|
|
1177
|
+
const result = yield* (yield* TodoRepo).findAll(opts);
|
|
1178
|
+
return {
|
|
1179
|
+
data: result.data,
|
|
1180
|
+
limit: opts.limit ?? null,
|
|
1181
|
+
offset: opts.offset ?? 0,
|
|
1182
|
+
total: result.total
|
|
1183
|
+
};
|
|
1184
|
+
});
|
|
1185
|
+
const update = Effect.fn("TodoService.update")(function* update(id, input) {
|
|
1186
|
+
const repo = yield* TodoRepo;
|
|
1187
|
+
if (!(yield* repo.findById(id))) return yield* new TodoNotFound({ id });
|
|
1188
|
+
const updates = {};
|
|
1189
|
+
if (Option.isSome(input.content)) updates.content = input.content.value;
|
|
1190
|
+
if (Option.isSome(input.completed)) updates.completed = input.completed.value;
|
|
1191
|
+
const todo = yield* repo.update(id, updates);
|
|
1192
|
+
if (!todo) return yield* new TodoNotFound({ id });
|
|
1193
|
+
return todo;
|
|
1194
|
+
});
|
|
1195
|
+
const toggle = Effect.fn("TodoService.toggle")(function* toggle(id) {
|
|
1196
|
+
const todo = yield* (yield* TodoRepo).toggle(id);
|
|
1197
|
+
if (!todo) return yield* new TodoNotFound({ id });
|
|
1198
|
+
return todo;
|
|
1199
|
+
});
|
|
1200
|
+
const remove = Effect.fn("TodoService.remove")(function* remove(id) {
|
|
1201
|
+
const repo = yield* TodoRepo;
|
|
1202
|
+
if (!(yield* repo.findById(id))) return yield* new TodoNotFound({ id });
|
|
1203
|
+
yield* repo.remove(id);
|
|
1204
|
+
return { success: true };
|
|
1205
|
+
});
|
|
1206
|
+
const removeCompleted = Effect.fn("TodoService.removeCompleted")(function* removeCompleted() {
|
|
1207
|
+
return { deleted: yield* (yield* TodoRepo).removeCompleted() };
|
|
1208
|
+
});
|
|
1209
|
+
const reorder = Effect.fn("TodoService.reorder")(function* reorder(orderedIds) {
|
|
1210
|
+
return { updated: yield* (yield* TodoRepo).reorder(orderedIds) };
|
|
1211
|
+
});
|
|
1212
|
+
const move = Effect.fn("TodoService.move")(function* move(id, position) {
|
|
1213
|
+
const todo = yield* (yield* TodoRepo).move(id, position);
|
|
1214
|
+
if (!todo) return yield* new TodoNotFound({ id });
|
|
1215
|
+
return todo;
|
|
1216
|
+
});
|
|
1217
|
+
return {
|
|
1218
|
+
create,
|
|
1219
|
+
getById,
|
|
1220
|
+
getStats: Effect.fn("TodoService.getStats")(function* getStats() {
|
|
1221
|
+
const repo = yield* TodoRepo;
|
|
1222
|
+
const total = yield* repo.countAll();
|
|
1223
|
+
return {
|
|
1224
|
+
completed: yield* repo.countCompleted(),
|
|
1225
|
+
pending: yield* repo.countPending(),
|
|
1226
|
+
total
|
|
1227
|
+
};
|
|
1228
|
+
}),
|
|
1229
|
+
list,
|
|
1230
|
+
move,
|
|
1231
|
+
remove,
|
|
1232
|
+
removeCompleted,
|
|
1233
|
+
reorder,
|
|
1234
|
+
toggle,
|
|
1235
|
+
update
|
|
1236
|
+
};
|
|
1237
|
+
})
|
|
1238
|
+
}) {};
|
|
1239
|
+
//#endregion
|
|
1240
|
+
//#region ../../packages/core/src/services/export.service.ts
|
|
1241
|
+
var ExportService = class extends Effect.Service()("@ringi/ExportService", {
|
|
1242
|
+
dependencies: [
|
|
1243
|
+
ReviewService.Default,
|
|
1244
|
+
CommentService.Default,
|
|
1245
|
+
TodoService.Default
|
|
1246
|
+
],
|
|
1247
|
+
effect: Effect.sync(() => {
|
|
1248
|
+
return { exportReview: Effect.fn("ExportService.exportReview")(function* exportReview(reviewId) {
|
|
1249
|
+
const reviewSvc = yield* ReviewService;
|
|
1250
|
+
const commentSvc = yield* CommentService;
|
|
1251
|
+
const todoSvc = yield* TodoService;
|
|
1252
|
+
const review = yield* reviewSvc.getById(reviewId);
|
|
1253
|
+
const repo = review.repository;
|
|
1254
|
+
const repoName = repo?.name ?? "Unknown";
|
|
1255
|
+
const branch = repo?.branch ?? "unknown";
|
|
1256
|
+
const comments = yield* commentSvc.getByReview(reviewId);
|
|
1257
|
+
const commentStats = yield* commentSvc.getStats(reviewId);
|
|
1258
|
+
const todos = yield* todoSvc.list({ reviewId });
|
|
1259
|
+
const lines = [];
|
|
1260
|
+
lines.push(`# Code Review: ${repoName}`);
|
|
1261
|
+
lines.push("");
|
|
1262
|
+
lines.push(`**Status:** ${review.status}`);
|
|
1263
|
+
lines.push(`**Branch:** ${branch}`);
|
|
1264
|
+
lines.push(`**Created:** ${review.createdAt}`);
|
|
1265
|
+
if (review.files && review.files.length > 0) {
|
|
1266
|
+
lines.push("");
|
|
1267
|
+
lines.push("## Files Changed");
|
|
1268
|
+
lines.push("");
|
|
1269
|
+
lines.push("| File | Status | Additions | Deletions |");
|
|
1270
|
+
lines.push("|------|--------|-----------|-----------|");
|
|
1271
|
+
for (const f of review.files) {
|
|
1272
|
+
const statusLabel = f.status === "modified" ? "M" : f.status === "added" ? "A" : f.status === "deleted" ? "D" : f.status;
|
|
1273
|
+
lines.push(`| ${f.filePath} | ${statusLabel} | +${f.additions} | -${f.deletions} |`);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
if (comments.length > 0) {
|
|
1277
|
+
lines.push("");
|
|
1278
|
+
lines.push(`## Comments (${commentStats.total} total, ${commentStats.resolved} resolved)`);
|
|
1279
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
1280
|
+
for (const c of comments) {
|
|
1281
|
+
const key = c.filePath ?? "(general)";
|
|
1282
|
+
const arr = byFile.get(key) ?? [];
|
|
1283
|
+
arr.push(c);
|
|
1284
|
+
byFile.set(key, arr);
|
|
1285
|
+
}
|
|
1286
|
+
for (const [filePath, fileComments] of byFile) {
|
|
1287
|
+
lines.push("");
|
|
1288
|
+
lines.push(`### ${filePath}`);
|
|
1289
|
+
for (const c of fileComments) {
|
|
1290
|
+
lines.push("");
|
|
1291
|
+
lines.push(`**Line ${c.lineNumber ?? "–"}** (${c.lineType ?? "context"})`);
|
|
1292
|
+
lines.push(`> ${c.content}`);
|
|
1293
|
+
if (c.suggestion) {
|
|
1294
|
+
lines.push("");
|
|
1295
|
+
lines.push("```suggestion");
|
|
1296
|
+
lines.push(c.suggestion);
|
|
1297
|
+
lines.push("```");
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
if (todos.data.length > 0) {
|
|
1303
|
+
const completed = todos.data.filter((t) => t.completed).length;
|
|
1304
|
+
lines.push("");
|
|
1305
|
+
lines.push("---");
|
|
1306
|
+
lines.push("");
|
|
1307
|
+
lines.push(`## Todos (${todos.total} total, ${completed} completed)`);
|
|
1308
|
+
lines.push("");
|
|
1309
|
+
for (const t of todos.data) {
|
|
1310
|
+
const check = t.completed ? "x" : " ";
|
|
1311
|
+
lines.push(`- [${check}] ${t.content}`);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
lines.push("");
|
|
1315
|
+
return lines.join("\n");
|
|
1316
|
+
}) };
|
|
1317
|
+
})
|
|
1318
|
+
}) {};
|
|
1319
|
+
//#endregion
|
|
1320
|
+
//#region ../../node_modules/.pnpm/readdirp@5.0.0/node_modules/readdirp/index.js
|
|
1321
|
+
const EntryTypes = {
|
|
1322
|
+
FILE_TYPE: "files",
|
|
1323
|
+
DIR_TYPE: "directories",
|
|
1324
|
+
FILE_DIR_TYPE: "files_directories",
|
|
1325
|
+
EVERYTHING_TYPE: "all"
|
|
1326
|
+
};
|
|
1327
|
+
const defaultOptions = {
|
|
1328
|
+
root: ".",
|
|
1329
|
+
fileFilter: (_entryInfo) => true,
|
|
1330
|
+
directoryFilter: (_entryInfo) => true,
|
|
1331
|
+
type: EntryTypes.FILE_TYPE,
|
|
1332
|
+
lstat: false,
|
|
1333
|
+
depth: 2147483648,
|
|
1334
|
+
alwaysStat: false,
|
|
1335
|
+
highWaterMark: 4096
|
|
1336
|
+
};
|
|
1337
|
+
Object.freeze(defaultOptions);
|
|
1338
|
+
const RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
|
|
1339
|
+
const NORMAL_FLOW_ERRORS = new Set([
|
|
1340
|
+
"ENOENT",
|
|
1341
|
+
"EPERM",
|
|
1342
|
+
"EACCES",
|
|
1343
|
+
"ELOOP",
|
|
1344
|
+
RECURSIVE_ERROR_CODE
|
|
1345
|
+
]);
|
|
1346
|
+
const ALL_TYPES = [
|
|
1347
|
+
EntryTypes.DIR_TYPE,
|
|
1348
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1349
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
1350
|
+
EntryTypes.FILE_TYPE
|
|
1351
|
+
];
|
|
1352
|
+
const DIR_TYPES = new Set([
|
|
1353
|
+
EntryTypes.DIR_TYPE,
|
|
1354
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1355
|
+
EntryTypes.FILE_DIR_TYPE
|
|
1356
|
+
]);
|
|
1357
|
+
const FILE_TYPES = new Set([
|
|
1358
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1359
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
1360
|
+
EntryTypes.FILE_TYPE
|
|
1361
|
+
]);
|
|
1362
|
+
const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
|
1363
|
+
const wantBigintFsStats = process.platform === "win32";
|
|
1364
|
+
const emptyFn = (_entryInfo) => true;
|
|
1365
|
+
const normalizeFilter = (filter) => {
|
|
1366
|
+
if (filter === void 0) return emptyFn;
|
|
1367
|
+
if (typeof filter === "function") return filter;
|
|
1368
|
+
if (typeof filter === "string") {
|
|
1369
|
+
const fl = filter.trim();
|
|
1370
|
+
return (entry) => entry.basename === fl;
|
|
1371
|
+
}
|
|
1372
|
+
if (Array.isArray(filter)) {
|
|
1373
|
+
const trItems = filter.map((item) => item.trim());
|
|
1374
|
+
return (entry) => trItems.some((f) => entry.basename === f);
|
|
1375
|
+
}
|
|
1376
|
+
return emptyFn;
|
|
1377
|
+
};
|
|
1378
|
+
/** Readable readdir stream, emitting new files as they're being listed. */
|
|
1379
|
+
var ReaddirpStream = class extends Readable {
|
|
1380
|
+
parents;
|
|
1381
|
+
reading;
|
|
1382
|
+
parent;
|
|
1383
|
+
_stat;
|
|
1384
|
+
_maxDepth;
|
|
1385
|
+
_wantsDir;
|
|
1386
|
+
_wantsFile;
|
|
1387
|
+
_wantsEverything;
|
|
1388
|
+
_root;
|
|
1389
|
+
_isDirent;
|
|
1390
|
+
_statsProp;
|
|
1391
|
+
_rdOptions;
|
|
1392
|
+
_fileFilter;
|
|
1393
|
+
_directoryFilter;
|
|
1394
|
+
constructor(options = {}) {
|
|
1395
|
+
super({
|
|
1396
|
+
objectMode: true,
|
|
1397
|
+
autoDestroy: true,
|
|
1398
|
+
highWaterMark: options.highWaterMark
|
|
1399
|
+
});
|
|
1400
|
+
const opts = {
|
|
1401
|
+
...defaultOptions,
|
|
1402
|
+
...options
|
|
1403
|
+
};
|
|
1404
|
+
const { root, type } = opts;
|
|
1405
|
+
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
1406
|
+
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
1407
|
+
const statMethod = opts.lstat ? lstat : stat$1;
|
|
1408
|
+
if (wantBigintFsStats) this._stat = (path) => statMethod(path, { bigint: true });
|
|
1409
|
+
else this._stat = statMethod;
|
|
1410
|
+
this._maxDepth = opts.depth != null && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth;
|
|
1411
|
+
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
|
1412
|
+
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
|
1413
|
+
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
|
1414
|
+
this._root = resolve(root);
|
|
1415
|
+
this._isDirent = !opts.alwaysStat;
|
|
1416
|
+
this._statsProp = this._isDirent ? "dirent" : "stats";
|
|
1417
|
+
this._rdOptions = {
|
|
1418
|
+
encoding: "utf8",
|
|
1419
|
+
withFileTypes: this._isDirent
|
|
1420
|
+
};
|
|
1421
|
+
this.parents = [this._exploreDir(root, 1)];
|
|
1422
|
+
this.reading = false;
|
|
1423
|
+
this.parent = void 0;
|
|
1424
|
+
}
|
|
1425
|
+
async _read(batch) {
|
|
1426
|
+
if (this.reading) return;
|
|
1427
|
+
this.reading = true;
|
|
1428
|
+
try {
|
|
1429
|
+
while (!this.destroyed && batch > 0) {
|
|
1430
|
+
const par = this.parent;
|
|
1431
|
+
const fil = par && par.files;
|
|
1432
|
+
if (fil && fil.length > 0) {
|
|
1433
|
+
const { path, depth } = par;
|
|
1434
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
|
1435
|
+
const awaited = await Promise.all(slice);
|
|
1436
|
+
for (const entry of awaited) {
|
|
1437
|
+
if (!entry) continue;
|
|
1438
|
+
if (this.destroyed) return;
|
|
1439
|
+
const entryType = await this._getEntryType(entry);
|
|
1440
|
+
if (entryType === "directory" && this._directoryFilter(entry)) {
|
|
1441
|
+
if (depth <= this._maxDepth) this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
|
1442
|
+
if (this._wantsDir) {
|
|
1443
|
+
this.push(entry);
|
|
1444
|
+
batch--;
|
|
1445
|
+
}
|
|
1446
|
+
} else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
|
|
1447
|
+
if (this._wantsFile) {
|
|
1448
|
+
this.push(entry);
|
|
1449
|
+
batch--;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
} else {
|
|
1454
|
+
const parent = this.parents.pop();
|
|
1455
|
+
if (!parent) {
|
|
1456
|
+
this.push(null);
|
|
1457
|
+
break;
|
|
1458
|
+
}
|
|
1459
|
+
this.parent = await parent;
|
|
1460
|
+
if (this.destroyed) return;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
} catch (error) {
|
|
1464
|
+
this.destroy(error);
|
|
1465
|
+
} finally {
|
|
1466
|
+
this.reading = false;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
async _exploreDir(path, depth) {
|
|
1470
|
+
let files;
|
|
1471
|
+
try {
|
|
1472
|
+
files = await readdir(path, this._rdOptions);
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
this._onError(error);
|
|
1475
|
+
}
|
|
1476
|
+
return {
|
|
1477
|
+
files,
|
|
1478
|
+
depth,
|
|
1479
|
+
path
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
async _formatEntry(dirent, path) {
|
|
1483
|
+
let entry;
|
|
1484
|
+
const basename = this._isDirent ? dirent.name : dirent;
|
|
1485
|
+
try {
|
|
1486
|
+
const fullPath = resolve(join(path, basename));
|
|
1487
|
+
entry = {
|
|
1488
|
+
path: relative(this._root, fullPath),
|
|
1489
|
+
fullPath,
|
|
1490
|
+
basename
|
|
1491
|
+
};
|
|
1492
|
+
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
1493
|
+
} catch (err) {
|
|
1494
|
+
this._onError(err);
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
return entry;
|
|
1498
|
+
}
|
|
1499
|
+
_onError(err) {
|
|
1500
|
+
if (isNormalFlowError(err) && !this.destroyed) this.emit("warn", err);
|
|
1501
|
+
else this.destroy(err);
|
|
1502
|
+
}
|
|
1503
|
+
async _getEntryType(entry) {
|
|
1504
|
+
if (!entry && this._statsProp in entry) return "";
|
|
1505
|
+
const stats = entry[this._statsProp];
|
|
1506
|
+
if (stats.isFile()) return "file";
|
|
1507
|
+
if (stats.isDirectory()) return "directory";
|
|
1508
|
+
if (stats && stats.isSymbolicLink()) {
|
|
1509
|
+
const full = entry.fullPath;
|
|
1510
|
+
try {
|
|
1511
|
+
const entryRealPath = await realpath(full);
|
|
1512
|
+
const entryRealPathStats = await lstat(entryRealPath);
|
|
1513
|
+
if (entryRealPathStats.isFile()) return "file";
|
|
1514
|
+
if (entryRealPathStats.isDirectory()) {
|
|
1515
|
+
const len = entryRealPath.length;
|
|
1516
|
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === sep) {
|
|
1517
|
+
const recursiveError = /* @__PURE__ */ new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
1518
|
+
recursiveError.code = RECURSIVE_ERROR_CODE;
|
|
1519
|
+
return this._onError(recursiveError);
|
|
1520
|
+
}
|
|
1521
|
+
return "directory";
|
|
1522
|
+
}
|
|
1523
|
+
} catch (error) {
|
|
1524
|
+
this._onError(error);
|
|
1525
|
+
return "";
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
_includeAsFile(entry) {
|
|
1530
|
+
const stats = entry && entry[this._statsProp];
|
|
1531
|
+
return stats && this._wantsEverything && !stats.isDirectory();
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
/**
|
|
1535
|
+
* Streaming version: Reads all files and directories in given root recursively.
|
|
1536
|
+
* Consumes ~constant small amount of RAM.
|
|
1537
|
+
* @param root Root directory
|
|
1538
|
+
* @param options Options to specify root (start directory), filters and recursion depth
|
|
1539
|
+
*/
|
|
1540
|
+
function readdirp(root, options = {}) {
|
|
1541
|
+
let type = options.entryType || options.type;
|
|
1542
|
+
if (type === "both") type = EntryTypes.FILE_DIR_TYPE;
|
|
1543
|
+
if (type) options.type = type;
|
|
1544
|
+
if (!root) throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
|
|
1545
|
+
else if (typeof root !== "string") throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
|
|
1546
|
+
else if (type && !ALL_TYPES.includes(type)) throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
|
|
1547
|
+
options.root = root;
|
|
1548
|
+
return new ReaddirpStream(options);
|
|
1549
|
+
}
|
|
1550
|
+
//#endregion
|
|
1551
|
+
//#region ../../node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/handler.js
|
|
1552
|
+
const STR_DATA = "data";
|
|
1553
|
+
const STR_CLOSE = "close";
|
|
1554
|
+
const EMPTY_FN = () => {};
|
|
1555
|
+
const pl = process.platform;
|
|
1556
|
+
const isWindows = pl === "win32";
|
|
1557
|
+
const isMacos = pl === "darwin";
|
|
1558
|
+
const isLinux = pl === "linux";
|
|
1559
|
+
const isFreeBSD = pl === "freebsd";
|
|
1560
|
+
const isIBMi = type() === "OS400";
|
|
1561
|
+
const EVENTS = {
|
|
1562
|
+
ALL: "all",
|
|
1563
|
+
READY: "ready",
|
|
1564
|
+
ADD: "add",
|
|
1565
|
+
CHANGE: "change",
|
|
1566
|
+
ADD_DIR: "addDir",
|
|
1567
|
+
UNLINK: "unlink",
|
|
1568
|
+
UNLINK_DIR: "unlinkDir",
|
|
1569
|
+
RAW: "raw",
|
|
1570
|
+
ERROR: "error"
|
|
1571
|
+
};
|
|
1572
|
+
const EV = EVENTS;
|
|
1573
|
+
const THROTTLE_MODE_WATCH = "watch";
|
|
1574
|
+
const statMethods = {
|
|
1575
|
+
lstat,
|
|
1576
|
+
stat: stat$1
|
|
1577
|
+
};
|
|
1578
|
+
const KEY_LISTENERS = "listeners";
|
|
1579
|
+
const KEY_ERR = "errHandlers";
|
|
1580
|
+
const KEY_RAW = "rawEmitters";
|
|
1581
|
+
const HANDLER_KEYS = [
|
|
1582
|
+
KEY_LISTENERS,
|
|
1583
|
+
KEY_ERR,
|
|
1584
|
+
KEY_RAW
|
|
1585
|
+
];
|
|
1586
|
+
const binaryExtensions = new Set([
|
|
1587
|
+
"3dm",
|
|
1588
|
+
"3ds",
|
|
1589
|
+
"3g2",
|
|
1590
|
+
"3gp",
|
|
1591
|
+
"7z",
|
|
1592
|
+
"a",
|
|
1593
|
+
"aac",
|
|
1594
|
+
"adp",
|
|
1595
|
+
"afdesign",
|
|
1596
|
+
"afphoto",
|
|
1597
|
+
"afpub",
|
|
1598
|
+
"ai",
|
|
1599
|
+
"aif",
|
|
1600
|
+
"aiff",
|
|
1601
|
+
"alz",
|
|
1602
|
+
"ape",
|
|
1603
|
+
"apk",
|
|
1604
|
+
"appimage",
|
|
1605
|
+
"ar",
|
|
1606
|
+
"arj",
|
|
1607
|
+
"asf",
|
|
1608
|
+
"au",
|
|
1609
|
+
"avi",
|
|
1610
|
+
"bak",
|
|
1611
|
+
"baml",
|
|
1612
|
+
"bh",
|
|
1613
|
+
"bin",
|
|
1614
|
+
"bk",
|
|
1615
|
+
"bmp",
|
|
1616
|
+
"btif",
|
|
1617
|
+
"bz2",
|
|
1618
|
+
"bzip2",
|
|
1619
|
+
"cab",
|
|
1620
|
+
"caf",
|
|
1621
|
+
"cgm",
|
|
1622
|
+
"class",
|
|
1623
|
+
"cmx",
|
|
1624
|
+
"cpio",
|
|
1625
|
+
"cr2",
|
|
1626
|
+
"cur",
|
|
1627
|
+
"dat",
|
|
1628
|
+
"dcm",
|
|
1629
|
+
"deb",
|
|
1630
|
+
"dex",
|
|
1631
|
+
"djvu",
|
|
1632
|
+
"dll",
|
|
1633
|
+
"dmg",
|
|
1634
|
+
"dng",
|
|
1635
|
+
"doc",
|
|
1636
|
+
"docm",
|
|
1637
|
+
"docx",
|
|
1638
|
+
"dot",
|
|
1639
|
+
"dotm",
|
|
1640
|
+
"dra",
|
|
1641
|
+
"DS_Store",
|
|
1642
|
+
"dsk",
|
|
1643
|
+
"dts",
|
|
1644
|
+
"dtshd",
|
|
1645
|
+
"dvb",
|
|
1646
|
+
"dwg",
|
|
1647
|
+
"dxf",
|
|
1648
|
+
"ecelp4800",
|
|
1649
|
+
"ecelp7470",
|
|
1650
|
+
"ecelp9600",
|
|
1651
|
+
"egg",
|
|
1652
|
+
"eol",
|
|
1653
|
+
"eot",
|
|
1654
|
+
"epub",
|
|
1655
|
+
"exe",
|
|
1656
|
+
"f4v",
|
|
1657
|
+
"fbs",
|
|
1658
|
+
"fh",
|
|
1659
|
+
"fla",
|
|
1660
|
+
"flac",
|
|
1661
|
+
"flatpak",
|
|
1662
|
+
"fli",
|
|
1663
|
+
"flv",
|
|
1664
|
+
"fpx",
|
|
1665
|
+
"fst",
|
|
1666
|
+
"fvt",
|
|
1667
|
+
"g3",
|
|
1668
|
+
"gh",
|
|
1669
|
+
"gif",
|
|
1670
|
+
"graffle",
|
|
1671
|
+
"gz",
|
|
1672
|
+
"gzip",
|
|
1673
|
+
"h261",
|
|
1674
|
+
"h263",
|
|
1675
|
+
"h264",
|
|
1676
|
+
"icns",
|
|
1677
|
+
"ico",
|
|
1678
|
+
"ief",
|
|
1679
|
+
"img",
|
|
1680
|
+
"ipa",
|
|
1681
|
+
"iso",
|
|
1682
|
+
"jar",
|
|
1683
|
+
"jpeg",
|
|
1684
|
+
"jpg",
|
|
1685
|
+
"jpgv",
|
|
1686
|
+
"jpm",
|
|
1687
|
+
"jxr",
|
|
1688
|
+
"key",
|
|
1689
|
+
"ktx",
|
|
1690
|
+
"lha",
|
|
1691
|
+
"lib",
|
|
1692
|
+
"lvp",
|
|
1693
|
+
"lz",
|
|
1694
|
+
"lzh",
|
|
1695
|
+
"lzma",
|
|
1696
|
+
"lzo",
|
|
1697
|
+
"m3u",
|
|
1698
|
+
"m4a",
|
|
1699
|
+
"m4v",
|
|
1700
|
+
"mar",
|
|
1701
|
+
"mdi",
|
|
1702
|
+
"mht",
|
|
1703
|
+
"mid",
|
|
1704
|
+
"midi",
|
|
1705
|
+
"mj2",
|
|
1706
|
+
"mka",
|
|
1707
|
+
"mkv",
|
|
1708
|
+
"mmr",
|
|
1709
|
+
"mng",
|
|
1710
|
+
"mobi",
|
|
1711
|
+
"mov",
|
|
1712
|
+
"movie",
|
|
1713
|
+
"mp3",
|
|
1714
|
+
"mp4",
|
|
1715
|
+
"mp4a",
|
|
1716
|
+
"mpeg",
|
|
1717
|
+
"mpg",
|
|
1718
|
+
"mpga",
|
|
1719
|
+
"mxu",
|
|
1720
|
+
"nef",
|
|
1721
|
+
"npx",
|
|
1722
|
+
"numbers",
|
|
1723
|
+
"nupkg",
|
|
1724
|
+
"o",
|
|
1725
|
+
"odp",
|
|
1726
|
+
"ods",
|
|
1727
|
+
"odt",
|
|
1728
|
+
"oga",
|
|
1729
|
+
"ogg",
|
|
1730
|
+
"ogv",
|
|
1731
|
+
"otf",
|
|
1732
|
+
"ott",
|
|
1733
|
+
"pages",
|
|
1734
|
+
"pbm",
|
|
1735
|
+
"pcx",
|
|
1736
|
+
"pdb",
|
|
1737
|
+
"pdf",
|
|
1738
|
+
"pea",
|
|
1739
|
+
"pgm",
|
|
1740
|
+
"pic",
|
|
1741
|
+
"png",
|
|
1742
|
+
"pnm",
|
|
1743
|
+
"pot",
|
|
1744
|
+
"potm",
|
|
1745
|
+
"potx",
|
|
1746
|
+
"ppa",
|
|
1747
|
+
"ppam",
|
|
1748
|
+
"ppm",
|
|
1749
|
+
"pps",
|
|
1750
|
+
"ppsm",
|
|
1751
|
+
"ppsx",
|
|
1752
|
+
"ppt",
|
|
1753
|
+
"pptm",
|
|
1754
|
+
"pptx",
|
|
1755
|
+
"psd",
|
|
1756
|
+
"pya",
|
|
1757
|
+
"pyc",
|
|
1758
|
+
"pyo",
|
|
1759
|
+
"pyv",
|
|
1760
|
+
"qt",
|
|
1761
|
+
"rar",
|
|
1762
|
+
"ras",
|
|
1763
|
+
"raw",
|
|
1764
|
+
"resources",
|
|
1765
|
+
"rgb",
|
|
1766
|
+
"rip",
|
|
1767
|
+
"rlc",
|
|
1768
|
+
"rmf",
|
|
1769
|
+
"rmvb",
|
|
1770
|
+
"rpm",
|
|
1771
|
+
"rtf",
|
|
1772
|
+
"rz",
|
|
1773
|
+
"s3m",
|
|
1774
|
+
"s7z",
|
|
1775
|
+
"scpt",
|
|
1776
|
+
"sgi",
|
|
1777
|
+
"shar",
|
|
1778
|
+
"snap",
|
|
1779
|
+
"sil",
|
|
1780
|
+
"sketch",
|
|
1781
|
+
"slk",
|
|
1782
|
+
"smv",
|
|
1783
|
+
"snk",
|
|
1784
|
+
"so",
|
|
1785
|
+
"stl",
|
|
1786
|
+
"suo",
|
|
1787
|
+
"sub",
|
|
1788
|
+
"swf",
|
|
1789
|
+
"tar",
|
|
1790
|
+
"tbz",
|
|
1791
|
+
"tbz2",
|
|
1792
|
+
"tga",
|
|
1793
|
+
"tgz",
|
|
1794
|
+
"thmx",
|
|
1795
|
+
"tif",
|
|
1796
|
+
"tiff",
|
|
1797
|
+
"tlz",
|
|
1798
|
+
"ttc",
|
|
1799
|
+
"ttf",
|
|
1800
|
+
"txz",
|
|
1801
|
+
"udf",
|
|
1802
|
+
"uvh",
|
|
1803
|
+
"uvi",
|
|
1804
|
+
"uvm",
|
|
1805
|
+
"uvp",
|
|
1806
|
+
"uvs",
|
|
1807
|
+
"uvu",
|
|
1808
|
+
"viv",
|
|
1809
|
+
"vob",
|
|
1810
|
+
"war",
|
|
1811
|
+
"wav",
|
|
1812
|
+
"wax",
|
|
1813
|
+
"wbmp",
|
|
1814
|
+
"wdp",
|
|
1815
|
+
"weba",
|
|
1816
|
+
"webm",
|
|
1817
|
+
"webp",
|
|
1818
|
+
"whl",
|
|
1819
|
+
"wim",
|
|
1820
|
+
"wm",
|
|
1821
|
+
"wma",
|
|
1822
|
+
"wmv",
|
|
1823
|
+
"wmx",
|
|
1824
|
+
"woff",
|
|
1825
|
+
"woff2",
|
|
1826
|
+
"wrm",
|
|
1827
|
+
"wvx",
|
|
1828
|
+
"xbm",
|
|
1829
|
+
"xif",
|
|
1830
|
+
"xla",
|
|
1831
|
+
"xlam",
|
|
1832
|
+
"xls",
|
|
1833
|
+
"xlsb",
|
|
1834
|
+
"xlsm",
|
|
1835
|
+
"xlsx",
|
|
1836
|
+
"xlt",
|
|
1837
|
+
"xltm",
|
|
1838
|
+
"xltx",
|
|
1839
|
+
"xm",
|
|
1840
|
+
"xmind",
|
|
1841
|
+
"xpi",
|
|
1842
|
+
"xpm",
|
|
1843
|
+
"xwd",
|
|
1844
|
+
"xz",
|
|
1845
|
+
"z",
|
|
1846
|
+
"zip",
|
|
1847
|
+
"zipx"
|
|
1848
|
+
]);
|
|
1849
|
+
const isBinaryPath = (filePath) => binaryExtensions.has(sp.extname(filePath).slice(1).toLowerCase());
|
|
1850
|
+
const foreach = (val, fn) => {
|
|
1851
|
+
if (val instanceof Set) val.forEach(fn);
|
|
1852
|
+
else fn(val);
|
|
1853
|
+
};
|
|
1854
|
+
const addAndConvert = (main, prop, item) => {
|
|
1855
|
+
let container = main[prop];
|
|
1856
|
+
if (!(container instanceof Set)) main[prop] = container = new Set([container]);
|
|
1857
|
+
container.add(item);
|
|
1858
|
+
};
|
|
1859
|
+
const clearItem = (cont) => (key) => {
|
|
1860
|
+
const set = cont[key];
|
|
1861
|
+
if (set instanceof Set) set.clear();
|
|
1862
|
+
else delete cont[key];
|
|
1863
|
+
};
|
|
1864
|
+
const delFromSet = (main, prop, item) => {
|
|
1865
|
+
const container = main[prop];
|
|
1866
|
+
if (container instanceof Set) container.delete(item);
|
|
1867
|
+
else if (container === item) delete main[prop];
|
|
1868
|
+
};
|
|
1869
|
+
const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
1870
|
+
const FsWatchInstances = /* @__PURE__ */ new Map();
|
|
1871
|
+
/**
|
|
1872
|
+
* Instantiates the fs_watch interface
|
|
1873
|
+
* @param path to be watched
|
|
1874
|
+
* @param options to be passed to fs_watch
|
|
1875
|
+
* @param listener main event handler
|
|
1876
|
+
* @param errHandler emits info about errors
|
|
1877
|
+
* @param emitRaw emits raw event data
|
|
1878
|
+
* @returns {NativeFsWatcher}
|
|
1879
|
+
*/
|
|
1880
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
1881
|
+
const handleEvent = (rawEvent, evPath) => {
|
|
1882
|
+
listener(path);
|
|
1883
|
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
1884
|
+
if (evPath && path !== evPath) fsWatchBroadcast(sp.resolve(path, evPath), KEY_LISTENERS, sp.join(path, evPath));
|
|
1885
|
+
};
|
|
1886
|
+
try {
|
|
1887
|
+
return watch(path, { persistent: options.persistent }, handleEvent);
|
|
1888
|
+
} catch (error) {
|
|
1889
|
+
errHandler(error);
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Helper for passing fs_watch event data to a collection of listeners
|
|
1895
|
+
* @param fullPath absolute path bound to fs_watch instance
|
|
1896
|
+
*/
|
|
1897
|
+
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
1898
|
+
const cont = FsWatchInstances.get(fullPath);
|
|
1899
|
+
if (!cont) return;
|
|
1900
|
+
foreach(cont[listenerType], (listener) => {
|
|
1901
|
+
listener(val1, val2, val3);
|
|
1902
|
+
});
|
|
1903
|
+
};
|
|
1904
|
+
/**
|
|
1905
|
+
* Instantiates the fs_watch interface or binds listeners
|
|
1906
|
+
* to an existing one covering the same file system entry
|
|
1907
|
+
* @param path
|
|
1908
|
+
* @param fullPath absolute path
|
|
1909
|
+
* @param options to be passed to fs_watch
|
|
1910
|
+
* @param handlers container for event listener functions
|
|
1911
|
+
*/
|
|
1912
|
+
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
1913
|
+
const { listener, errHandler, rawEmitter } = handlers;
|
|
1914
|
+
let cont = FsWatchInstances.get(fullPath);
|
|
1915
|
+
let watcher;
|
|
1916
|
+
if (!options.persistent) {
|
|
1917
|
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
1918
|
+
if (!watcher) return;
|
|
1919
|
+
return watcher.close.bind(watcher);
|
|
1920
|
+
}
|
|
1921
|
+
if (cont) {
|
|
1922
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
1923
|
+
addAndConvert(cont, KEY_ERR, errHandler);
|
|
1924
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
1925
|
+
} else {
|
|
1926
|
+
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
|
1927
|
+
if (!watcher) return;
|
|
1928
|
+
watcher.on(EV.ERROR, async (error) => {
|
|
1929
|
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
1930
|
+
if (cont) cont.watcherUnusable = true;
|
|
1931
|
+
if (isWindows && error.code === "EPERM") try {
|
|
1932
|
+
await (await open(path, "r")).close();
|
|
1933
|
+
broadcastErr(error);
|
|
1934
|
+
} catch (err) {}
|
|
1935
|
+
else broadcastErr(error);
|
|
1936
|
+
});
|
|
1937
|
+
cont = {
|
|
1938
|
+
listeners: listener,
|
|
1939
|
+
errHandlers: errHandler,
|
|
1940
|
+
rawEmitters: rawEmitter,
|
|
1941
|
+
watcher
|
|
1942
|
+
};
|
|
1943
|
+
FsWatchInstances.set(fullPath, cont);
|
|
1944
|
+
}
|
|
1945
|
+
return () => {
|
|
1946
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
1947
|
+
delFromSet(cont, KEY_ERR, errHandler);
|
|
1948
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
1949
|
+
if (isEmptySet(cont.listeners)) {
|
|
1950
|
+
cont.watcher.close();
|
|
1951
|
+
FsWatchInstances.delete(fullPath);
|
|
1952
|
+
HANDLER_KEYS.forEach(clearItem(cont));
|
|
1953
|
+
cont.watcher = void 0;
|
|
1954
|
+
Object.freeze(cont);
|
|
1955
|
+
}
|
|
1956
|
+
};
|
|
1957
|
+
};
|
|
1958
|
+
const FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
1959
|
+
/**
|
|
1960
|
+
* Instantiates the fs_watchFile interface or binds listeners
|
|
1961
|
+
* to an existing one covering the same file system entry
|
|
1962
|
+
* @param path to be watched
|
|
1963
|
+
* @param fullPath absolute path
|
|
1964
|
+
* @param options options to be passed to fs_watchFile
|
|
1965
|
+
* @param handlers container for event listener functions
|
|
1966
|
+
* @returns closer
|
|
1967
|
+
*/
|
|
1968
|
+
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
1969
|
+
const { listener, rawEmitter } = handlers;
|
|
1970
|
+
let cont = FsWatchFileInstances.get(fullPath);
|
|
1971
|
+
const copts = cont && cont.options;
|
|
1972
|
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
1973
|
+
unwatchFile(fullPath);
|
|
1974
|
+
cont = void 0;
|
|
1975
|
+
}
|
|
1976
|
+
if (cont) {
|
|
1977
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
1978
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
1979
|
+
} else {
|
|
1980
|
+
cont = {
|
|
1981
|
+
listeners: listener,
|
|
1982
|
+
rawEmitters: rawEmitter,
|
|
1983
|
+
options,
|
|
1984
|
+
watcher: watchFile(fullPath, options, (curr, prev) => {
|
|
1985
|
+
foreach(cont.rawEmitters, (rawEmitter) => {
|
|
1986
|
+
rawEmitter(EV.CHANGE, fullPath, {
|
|
1987
|
+
curr,
|
|
1988
|
+
prev
|
|
1989
|
+
});
|
|
1990
|
+
});
|
|
1991
|
+
const currmtime = curr.mtimeMs;
|
|
1992
|
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener) => listener(path, curr));
|
|
1993
|
+
})
|
|
1994
|
+
};
|
|
1995
|
+
FsWatchFileInstances.set(fullPath, cont);
|
|
1996
|
+
}
|
|
1997
|
+
return () => {
|
|
1998
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
1999
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2000
|
+
if (isEmptySet(cont.listeners)) {
|
|
2001
|
+
FsWatchFileInstances.delete(fullPath);
|
|
2002
|
+
unwatchFile(fullPath);
|
|
2003
|
+
cont.options = cont.watcher = void 0;
|
|
2004
|
+
Object.freeze(cont);
|
|
2005
|
+
}
|
|
2006
|
+
};
|
|
2007
|
+
};
|
|
2008
|
+
/**
|
|
2009
|
+
* @mixin
|
|
2010
|
+
*/
|
|
2011
|
+
var NodeFsHandler = class {
|
|
2012
|
+
fsw;
|
|
2013
|
+
_boundHandleError;
|
|
2014
|
+
constructor(fsW) {
|
|
2015
|
+
this.fsw = fsW;
|
|
2016
|
+
this._boundHandleError = (error) => fsW._handleError(error);
|
|
2017
|
+
}
|
|
2018
|
+
/**
|
|
2019
|
+
* Watch file for changes with fs_watchFile or fs_watch.
|
|
2020
|
+
* @param path to file or dir
|
|
2021
|
+
* @param listener on fs change
|
|
2022
|
+
* @returns closer for the watcher instance
|
|
2023
|
+
*/
|
|
2024
|
+
_watchWithNodeFs(path, listener) {
|
|
2025
|
+
const opts = this.fsw.options;
|
|
2026
|
+
const directory = sp.dirname(path);
|
|
2027
|
+
const basename = sp.basename(path);
|
|
2028
|
+
this.fsw._getWatchedDir(directory).add(basename);
|
|
2029
|
+
const absolutePath = sp.resolve(path);
|
|
2030
|
+
const options = { persistent: opts.persistent };
|
|
2031
|
+
if (!listener) listener = EMPTY_FN;
|
|
2032
|
+
let closer;
|
|
2033
|
+
if (opts.usePolling) {
|
|
2034
|
+
options.interval = opts.interval !== opts.binaryInterval && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
|
2035
|
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
2036
|
+
listener,
|
|
2037
|
+
rawEmitter: this.fsw._emitRaw
|
|
2038
|
+
});
|
|
2039
|
+
} else closer = setFsWatchListener(path, absolutePath, options, {
|
|
2040
|
+
listener,
|
|
2041
|
+
errHandler: this._boundHandleError,
|
|
2042
|
+
rawEmitter: this.fsw._emitRaw
|
|
2043
|
+
});
|
|
2044
|
+
return closer;
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Watch a file and emit add event if warranted.
|
|
2048
|
+
* @returns closer for the watcher instance
|
|
2049
|
+
*/
|
|
2050
|
+
_handleFile(file, stats, initialAdd) {
|
|
2051
|
+
if (this.fsw.closed) return;
|
|
2052
|
+
const dirname = sp.dirname(file);
|
|
2053
|
+
const basename = sp.basename(file);
|
|
2054
|
+
const parent = this.fsw._getWatchedDir(dirname);
|
|
2055
|
+
let prevStats = stats;
|
|
2056
|
+
if (parent.has(basename)) return;
|
|
2057
|
+
const listener = async (path, newStats) => {
|
|
2058
|
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
|
|
2059
|
+
if (!newStats || newStats.mtimeMs === 0) try {
|
|
2060
|
+
const newStats = await stat$1(file);
|
|
2061
|
+
if (this.fsw.closed) return;
|
|
2062
|
+
const at = newStats.atimeMs;
|
|
2063
|
+
const mt = newStats.mtimeMs;
|
|
2064
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
|
|
2065
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
|
2066
|
+
this.fsw._closeFile(path);
|
|
2067
|
+
prevStats = newStats;
|
|
2068
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
2069
|
+
if (closer) this.fsw._addPathCloser(path, closer);
|
|
2070
|
+
} else prevStats = newStats;
|
|
2071
|
+
} catch (error) {
|
|
2072
|
+
this.fsw._remove(dirname, basename);
|
|
2073
|
+
}
|
|
2074
|
+
else if (parent.has(basename)) {
|
|
2075
|
+
const at = newStats.atimeMs;
|
|
2076
|
+
const mt = newStats.mtimeMs;
|
|
2077
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
|
|
2078
|
+
prevStats = newStats;
|
|
2079
|
+
}
|
|
2080
|
+
};
|
|
2081
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
2082
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
2083
|
+
if (!this.fsw._throttle(EV.ADD, file, 0)) return;
|
|
2084
|
+
this.fsw._emit(EV.ADD, file, stats);
|
|
2085
|
+
}
|
|
2086
|
+
return closer;
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Handle symlinks encountered while reading a dir.
|
|
2090
|
+
* @param entry returned by readdirp
|
|
2091
|
+
* @param directory path of dir being read
|
|
2092
|
+
* @param path of this item
|
|
2093
|
+
* @param item basename of this item
|
|
2094
|
+
* @returns true if no more processing is needed for this entry.
|
|
2095
|
+
*/
|
|
2096
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
2097
|
+
if (this.fsw.closed) return;
|
|
2098
|
+
const full = entry.fullPath;
|
|
2099
|
+
const dir = this.fsw._getWatchedDir(directory);
|
|
2100
|
+
if (!this.fsw.options.followSymlinks) {
|
|
2101
|
+
this.fsw._incrReadyCount();
|
|
2102
|
+
let linkPath;
|
|
2103
|
+
try {
|
|
2104
|
+
linkPath = await realpath(path);
|
|
2105
|
+
} catch (e) {
|
|
2106
|
+
this.fsw._emitReady();
|
|
2107
|
+
return true;
|
|
2108
|
+
}
|
|
2109
|
+
if (this.fsw.closed) return;
|
|
2110
|
+
if (dir.has(item)) {
|
|
2111
|
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
2112
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
2113
|
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
2114
|
+
}
|
|
2115
|
+
} else {
|
|
2116
|
+
dir.add(item);
|
|
2117
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
2118
|
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
2119
|
+
}
|
|
2120
|
+
this.fsw._emitReady();
|
|
2121
|
+
return true;
|
|
2122
|
+
}
|
|
2123
|
+
if (this.fsw._symlinkPaths.has(full)) return true;
|
|
2124
|
+
this.fsw._symlinkPaths.set(full, true);
|
|
2125
|
+
}
|
|
2126
|
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
2127
|
+
directory = sp.join(directory, "");
|
|
2128
|
+
const throttleKey = target ? `${directory}:${target}` : directory;
|
|
2129
|
+
throttler = this.fsw._throttle("readdir", throttleKey, 1e3);
|
|
2130
|
+
if (!throttler) return;
|
|
2131
|
+
const previous = this.fsw._getWatchedDir(wh.path);
|
|
2132
|
+
const current = /* @__PURE__ */ new Set();
|
|
2133
|
+
let stream = this.fsw._readdirp(directory, {
|
|
2134
|
+
fileFilter: (entry) => wh.filterPath(entry),
|
|
2135
|
+
directoryFilter: (entry) => wh.filterDir(entry)
|
|
2136
|
+
});
|
|
2137
|
+
if (!stream) return;
|
|
2138
|
+
stream.on(STR_DATA, async (entry) => {
|
|
2139
|
+
if (this.fsw.closed) {
|
|
2140
|
+
stream = void 0;
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
const item = entry.path;
|
|
2144
|
+
let path = sp.join(directory, item);
|
|
2145
|
+
current.add(item);
|
|
2146
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) return;
|
|
2147
|
+
if (this.fsw.closed) {
|
|
2148
|
+
stream = void 0;
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
if (item === target || !target && !previous.has(item)) {
|
|
2152
|
+
this.fsw._incrReadyCount();
|
|
2153
|
+
path = sp.join(dir, sp.relative(dir, path));
|
|
2154
|
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
2155
|
+
}
|
|
2156
|
+
}).on(EV.ERROR, this._boundHandleError);
|
|
2157
|
+
return new Promise((resolve, reject) => {
|
|
2158
|
+
if (!stream) return reject();
|
|
2159
|
+
stream.once("end", () => {
|
|
2160
|
+
if (this.fsw.closed) {
|
|
2161
|
+
stream = void 0;
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
const wasThrottled = throttler ? throttler.clear() : false;
|
|
2165
|
+
resolve(void 0);
|
|
2166
|
+
previous.getChildren().filter((item) => {
|
|
2167
|
+
return item !== directory && !current.has(item);
|
|
2168
|
+
}).forEach((item) => {
|
|
2169
|
+
this.fsw._remove(directory, item);
|
|
2170
|
+
});
|
|
2171
|
+
stream = void 0;
|
|
2172
|
+
if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
2173
|
+
});
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
2178
|
+
* @param dir fs path
|
|
2179
|
+
* @param stats
|
|
2180
|
+
* @param initialAdd
|
|
2181
|
+
* @param depth relative to user-supplied path
|
|
2182
|
+
* @param target child path targeted for watch
|
|
2183
|
+
* @param wh Common watch helpers for this path
|
|
2184
|
+
* @param realpath
|
|
2185
|
+
* @returns closer for the watcher instance.
|
|
2186
|
+
*/
|
|
2187
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
|
2188
|
+
const parentDir = this.fsw._getWatchedDir(sp.dirname(dir));
|
|
2189
|
+
const tracked = parentDir.has(sp.basename(dir));
|
|
2190
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
2191
|
+
parentDir.add(sp.basename(dir));
|
|
2192
|
+
this.fsw._getWatchedDir(dir);
|
|
2193
|
+
let throttler;
|
|
2194
|
+
let closer;
|
|
2195
|
+
const oDepth = this.fsw.options.depth;
|
|
2196
|
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
|
2197
|
+
if (!target) {
|
|
2198
|
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
2199
|
+
if (this.fsw.closed) return;
|
|
2200
|
+
}
|
|
2201
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
|
2202
|
+
if (stats && stats.mtimeMs === 0) return;
|
|
2203
|
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
return closer;
|
|
2207
|
+
}
|
|
2208
|
+
/**
|
|
2209
|
+
* Handle added file, directory, or glob pattern.
|
|
2210
|
+
* Delegates call to _handleFile / _handleDir after checks.
|
|
2211
|
+
* @param path to file or ir
|
|
2212
|
+
* @param initialAdd was the file added at watch instantiation?
|
|
2213
|
+
* @param priorWh depth relative to user-supplied path
|
|
2214
|
+
* @param depth Child path actually targeted for watch
|
|
2215
|
+
* @param target Child path actually targeted for watch
|
|
2216
|
+
*/
|
|
2217
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
2218
|
+
const ready = this.fsw._emitReady;
|
|
2219
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
2220
|
+
ready();
|
|
2221
|
+
return false;
|
|
2222
|
+
}
|
|
2223
|
+
const wh = this.fsw._getWatchHelpers(path);
|
|
2224
|
+
if (priorWh) {
|
|
2225
|
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
2226
|
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
2227
|
+
}
|
|
2228
|
+
try {
|
|
2229
|
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
2230
|
+
if (this.fsw.closed) return;
|
|
2231
|
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
2232
|
+
ready();
|
|
2233
|
+
return false;
|
|
2234
|
+
}
|
|
2235
|
+
const follow = this.fsw.options.followSymlinks;
|
|
2236
|
+
let closer;
|
|
2237
|
+
if (stats.isDirectory()) {
|
|
2238
|
+
const absPath = sp.resolve(path);
|
|
2239
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
2240
|
+
if (this.fsw.closed) return;
|
|
2241
|
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
2242
|
+
if (this.fsw.closed) return;
|
|
2243
|
+
if (absPath !== targetPath && targetPath !== void 0) this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
2244
|
+
} else if (stats.isSymbolicLink()) {
|
|
2245
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
2246
|
+
if (this.fsw.closed) return;
|
|
2247
|
+
const parent = sp.dirname(wh.watchPath);
|
|
2248
|
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
2249
|
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
2250
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
2251
|
+
if (this.fsw.closed) return;
|
|
2252
|
+
if (targetPath !== void 0) this.fsw._symlinkPaths.set(sp.resolve(path), targetPath);
|
|
2253
|
+
} else closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
2254
|
+
ready();
|
|
2255
|
+
if (closer) this.fsw._addPathCloser(path, closer);
|
|
2256
|
+
return false;
|
|
2257
|
+
} catch (error) {
|
|
2258
|
+
if (this.fsw._handleError(error)) {
|
|
2259
|
+
ready();
|
|
2260
|
+
return path;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
};
|
|
2265
|
+
//#endregion
|
|
2266
|
+
//#region ../../node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.js
|
|
2267
|
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
|
2268
|
+
const SLASH = "/";
|
|
2269
|
+
const SLASH_SLASH = "//";
|
|
2270
|
+
const ONE_DOT = ".";
|
|
2271
|
+
const TWO_DOTS = "..";
|
|
2272
|
+
const STRING_TYPE = "string";
|
|
2273
|
+
const BACK_SLASH_RE = /\\/g;
|
|
2274
|
+
const DOUBLE_SLASH_RE = /\/\//g;
|
|
2275
|
+
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
2276
|
+
const REPLACER_RE = /^\.[/\\]/;
|
|
2277
|
+
function arrify(item) {
|
|
2278
|
+
return Array.isArray(item) ? item : [item];
|
|
2279
|
+
}
|
|
2280
|
+
const isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
|
|
2281
|
+
function createPattern(matcher) {
|
|
2282
|
+
if (typeof matcher === "function") return matcher;
|
|
2283
|
+
if (typeof matcher === "string") return (string) => matcher === string;
|
|
2284
|
+
if (matcher instanceof RegExp) return (string) => matcher.test(string);
|
|
2285
|
+
if (typeof matcher === "object" && matcher !== null) return (string) => {
|
|
2286
|
+
if (matcher.path === string) return true;
|
|
2287
|
+
if (matcher.recursive) {
|
|
2288
|
+
const relative = sp.relative(matcher.path, string);
|
|
2289
|
+
if (!relative) return false;
|
|
2290
|
+
return !relative.startsWith("..") && !sp.isAbsolute(relative);
|
|
2291
|
+
}
|
|
2292
|
+
return false;
|
|
2293
|
+
};
|
|
2294
|
+
return () => false;
|
|
2295
|
+
}
|
|
2296
|
+
function normalizePath(path) {
|
|
2297
|
+
if (typeof path !== "string") throw new Error("string expected");
|
|
2298
|
+
path = sp.normalize(path);
|
|
2299
|
+
path = path.replace(/\\/g, "/");
|
|
2300
|
+
let prepend = false;
|
|
2301
|
+
if (path.startsWith("//")) prepend = true;
|
|
2302
|
+
path = path.replace(DOUBLE_SLASH_RE, "/");
|
|
2303
|
+
if (prepend) path = "/" + path;
|
|
2304
|
+
return path;
|
|
2305
|
+
}
|
|
2306
|
+
function matchPatterns(patterns, testString, stats) {
|
|
2307
|
+
const path = normalizePath(testString);
|
|
2308
|
+
for (let index = 0; index < patterns.length; index++) {
|
|
2309
|
+
const pattern = patterns[index];
|
|
2310
|
+
if (pattern(path, stats)) return true;
|
|
2311
|
+
}
|
|
2312
|
+
return false;
|
|
2313
|
+
}
|
|
2314
|
+
function anymatch(matchers, testString) {
|
|
2315
|
+
if (matchers == null) throw new TypeError("anymatch: specify first argument");
|
|
2316
|
+
const patterns = arrify(matchers).map((matcher) => createPattern(matcher));
|
|
2317
|
+
if (testString == null) return (testString, stats) => {
|
|
2318
|
+
return matchPatterns(patterns, testString, stats);
|
|
2319
|
+
};
|
|
2320
|
+
return matchPatterns(patterns, testString);
|
|
2321
|
+
}
|
|
2322
|
+
const unifyPaths = (paths_) => {
|
|
2323
|
+
const paths = arrify(paths_).flat();
|
|
2324
|
+
if (!paths.every((p) => typeof p === STRING_TYPE)) throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
2325
|
+
return paths.map(normalizePathToUnix);
|
|
2326
|
+
};
|
|
2327
|
+
const toUnix = (string) => {
|
|
2328
|
+
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
2329
|
+
let prepend = false;
|
|
2330
|
+
if (str.startsWith(SLASH_SLASH)) prepend = true;
|
|
2331
|
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
2332
|
+
if (prepend) str = SLASH + str;
|
|
2333
|
+
return str;
|
|
2334
|
+
};
|
|
2335
|
+
const normalizePathToUnix = (path) => toUnix(sp.normalize(toUnix(path)));
|
|
2336
|
+
const normalizeIgnored = (cwd = "") => (path) => {
|
|
2337
|
+
if (typeof path === "string") return normalizePathToUnix(sp.isAbsolute(path) ? path : sp.join(cwd, path));
|
|
2338
|
+
else return path;
|
|
2339
|
+
};
|
|
2340
|
+
const getAbsolutePath = (path, cwd) => {
|
|
2341
|
+
if (sp.isAbsolute(path)) return path;
|
|
2342
|
+
return sp.join(cwd, path);
|
|
2343
|
+
};
|
|
2344
|
+
const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
2345
|
+
/**
|
|
2346
|
+
* Directory entry.
|
|
2347
|
+
*/
|
|
2348
|
+
var DirEntry = class {
|
|
2349
|
+
path;
|
|
2350
|
+
_removeWatcher;
|
|
2351
|
+
items;
|
|
2352
|
+
constructor(dir, removeWatcher) {
|
|
2353
|
+
this.path = dir;
|
|
2354
|
+
this._removeWatcher = removeWatcher;
|
|
2355
|
+
this.items = /* @__PURE__ */ new Set();
|
|
2356
|
+
}
|
|
2357
|
+
add(item) {
|
|
2358
|
+
const { items } = this;
|
|
2359
|
+
if (!items) return;
|
|
2360
|
+
if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
|
|
2361
|
+
}
|
|
2362
|
+
async remove(item) {
|
|
2363
|
+
const { items } = this;
|
|
2364
|
+
if (!items) return;
|
|
2365
|
+
items.delete(item);
|
|
2366
|
+
if (items.size > 0) return;
|
|
2367
|
+
const dir = this.path;
|
|
2368
|
+
try {
|
|
2369
|
+
await readdir(dir);
|
|
2370
|
+
} catch (err) {
|
|
2371
|
+
if (this._removeWatcher) this._removeWatcher(sp.dirname(dir), sp.basename(dir));
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
has(item) {
|
|
2375
|
+
const { items } = this;
|
|
2376
|
+
if (!items) return;
|
|
2377
|
+
return items.has(item);
|
|
2378
|
+
}
|
|
2379
|
+
getChildren() {
|
|
2380
|
+
const { items } = this;
|
|
2381
|
+
if (!items) return [];
|
|
2382
|
+
return [...items.values()];
|
|
2383
|
+
}
|
|
2384
|
+
dispose() {
|
|
2385
|
+
this.items.clear();
|
|
2386
|
+
this.path = "";
|
|
2387
|
+
this._removeWatcher = EMPTY_FN;
|
|
2388
|
+
this.items = EMPTY_SET;
|
|
2389
|
+
Object.freeze(this);
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
const STAT_METHOD_F = "stat";
|
|
2393
|
+
const STAT_METHOD_L = "lstat";
|
|
2394
|
+
var WatchHelper = class {
|
|
2395
|
+
fsw;
|
|
2396
|
+
path;
|
|
2397
|
+
watchPath;
|
|
2398
|
+
fullWatchPath;
|
|
2399
|
+
dirParts;
|
|
2400
|
+
followSymlinks;
|
|
2401
|
+
statMethod;
|
|
2402
|
+
constructor(path, follow, fsw) {
|
|
2403
|
+
this.fsw = fsw;
|
|
2404
|
+
const watchPath = path;
|
|
2405
|
+
this.path = path = path.replace(REPLACER_RE, "");
|
|
2406
|
+
this.watchPath = watchPath;
|
|
2407
|
+
this.fullWatchPath = sp.resolve(watchPath);
|
|
2408
|
+
this.dirParts = [];
|
|
2409
|
+
this.dirParts.forEach((parts) => {
|
|
2410
|
+
if (parts.length > 1) parts.pop();
|
|
2411
|
+
});
|
|
2412
|
+
this.followSymlinks = follow;
|
|
2413
|
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
2414
|
+
}
|
|
2415
|
+
entryPath(entry) {
|
|
2416
|
+
return sp.join(this.watchPath, sp.relative(this.watchPath, entry.fullPath));
|
|
2417
|
+
}
|
|
2418
|
+
filterPath(entry) {
|
|
2419
|
+
const { stats } = entry;
|
|
2420
|
+
if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
|
|
2421
|
+
const resolvedPath = this.entryPath(entry);
|
|
2422
|
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
2423
|
+
}
|
|
2424
|
+
filterDir(entry) {
|
|
2425
|
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
2426
|
+
}
|
|
2427
|
+
};
|
|
2428
|
+
/**
|
|
2429
|
+
* Watches files & directories for changes. Emitted events:
|
|
2430
|
+
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
|
2431
|
+
*
|
|
2432
|
+
* new FSWatcher()
|
|
2433
|
+
* .add(directories)
|
|
2434
|
+
* .on('add', path => log('File', path, 'was added'))
|
|
2435
|
+
*/
|
|
2436
|
+
var FSWatcher = class extends EventEmitter {
|
|
2437
|
+
closed;
|
|
2438
|
+
options;
|
|
2439
|
+
_closers;
|
|
2440
|
+
_ignoredPaths;
|
|
2441
|
+
_throttled;
|
|
2442
|
+
_streams;
|
|
2443
|
+
_symlinkPaths;
|
|
2444
|
+
_watched;
|
|
2445
|
+
_pendingWrites;
|
|
2446
|
+
_pendingUnlinks;
|
|
2447
|
+
_readyCount;
|
|
2448
|
+
_emitReady;
|
|
2449
|
+
_closePromise;
|
|
2450
|
+
_userIgnored;
|
|
2451
|
+
_readyEmitted;
|
|
2452
|
+
_emitRaw;
|
|
2453
|
+
_boundRemove;
|
|
2454
|
+
_nodeFsHandler;
|
|
2455
|
+
constructor(_opts = {}) {
|
|
2456
|
+
super();
|
|
2457
|
+
this.closed = false;
|
|
2458
|
+
this._closers = /* @__PURE__ */ new Map();
|
|
2459
|
+
this._ignoredPaths = /* @__PURE__ */ new Set();
|
|
2460
|
+
this._throttled = /* @__PURE__ */ new Map();
|
|
2461
|
+
this._streams = /* @__PURE__ */ new Set();
|
|
2462
|
+
this._symlinkPaths = /* @__PURE__ */ new Map();
|
|
2463
|
+
this._watched = /* @__PURE__ */ new Map();
|
|
2464
|
+
this._pendingWrites = /* @__PURE__ */ new Map();
|
|
2465
|
+
this._pendingUnlinks = /* @__PURE__ */ new Map();
|
|
2466
|
+
this._readyCount = 0;
|
|
2467
|
+
this._readyEmitted = false;
|
|
2468
|
+
const awf = _opts.awaitWriteFinish;
|
|
2469
|
+
const DEF_AWF = {
|
|
2470
|
+
stabilityThreshold: 2e3,
|
|
2471
|
+
pollInterval: 100
|
|
2472
|
+
};
|
|
2473
|
+
const opts = {
|
|
2474
|
+
persistent: true,
|
|
2475
|
+
ignoreInitial: false,
|
|
2476
|
+
ignorePermissionErrors: false,
|
|
2477
|
+
interval: 100,
|
|
2478
|
+
binaryInterval: 300,
|
|
2479
|
+
followSymlinks: true,
|
|
2480
|
+
usePolling: false,
|
|
2481
|
+
atomic: true,
|
|
2482
|
+
..._opts,
|
|
2483
|
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
2484
|
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? {
|
|
2485
|
+
...DEF_AWF,
|
|
2486
|
+
...awf
|
|
2487
|
+
} : false
|
|
2488
|
+
};
|
|
2489
|
+
if (isIBMi) opts.usePolling = true;
|
|
2490
|
+
if (opts.atomic === void 0) opts.atomic = !opts.usePolling;
|
|
2491
|
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
2492
|
+
if (envPoll !== void 0) {
|
|
2493
|
+
const envLower = envPoll.toLowerCase();
|
|
2494
|
+
if (envLower === "false" || envLower === "0") opts.usePolling = false;
|
|
2495
|
+
else if (envLower === "true" || envLower === "1") opts.usePolling = true;
|
|
2496
|
+
else opts.usePolling = !!envLower;
|
|
2497
|
+
}
|
|
2498
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
2499
|
+
if (envInterval) opts.interval = Number.parseInt(envInterval, 10);
|
|
2500
|
+
let readyCalls = 0;
|
|
2501
|
+
this._emitReady = () => {
|
|
2502
|
+
readyCalls++;
|
|
2503
|
+
if (readyCalls >= this._readyCount) {
|
|
2504
|
+
this._emitReady = EMPTY_FN;
|
|
2505
|
+
this._readyEmitted = true;
|
|
2506
|
+
process.nextTick(() => this.emit(EVENTS.READY));
|
|
2507
|
+
}
|
|
2508
|
+
};
|
|
2509
|
+
this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
|
|
2510
|
+
this._boundRemove = this._remove.bind(this);
|
|
2511
|
+
this.options = opts;
|
|
2512
|
+
this._nodeFsHandler = new NodeFsHandler(this);
|
|
2513
|
+
Object.freeze(opts);
|
|
2514
|
+
}
|
|
2515
|
+
_addIgnoredPath(matcher) {
|
|
2516
|
+
if (isMatcherObject(matcher)) {
|
|
2517
|
+
for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
|
|
2518
|
+
}
|
|
2519
|
+
this._ignoredPaths.add(matcher);
|
|
2520
|
+
}
|
|
2521
|
+
_removeIgnoredPath(matcher) {
|
|
2522
|
+
this._ignoredPaths.delete(matcher);
|
|
2523
|
+
if (typeof matcher === "string") {
|
|
2524
|
+
for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher) this._ignoredPaths.delete(ignored);
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* Adds paths to be watched on an existing FSWatcher instance.
|
|
2529
|
+
* @param paths_ file or file list. Other arguments are unused
|
|
2530
|
+
*/
|
|
2531
|
+
add(paths_, _origAdd, _internal) {
|
|
2532
|
+
const { cwd } = this.options;
|
|
2533
|
+
this.closed = false;
|
|
2534
|
+
this._closePromise = void 0;
|
|
2535
|
+
let paths = unifyPaths(paths_);
|
|
2536
|
+
if (cwd) paths = paths.map((path) => {
|
|
2537
|
+
return getAbsolutePath(path, cwd);
|
|
2538
|
+
});
|
|
2539
|
+
paths.forEach((path) => {
|
|
2540
|
+
this._removeIgnoredPath(path);
|
|
2541
|
+
});
|
|
2542
|
+
this._userIgnored = void 0;
|
|
2543
|
+
if (!this._readyCount) this._readyCount = 0;
|
|
2544
|
+
this._readyCount += paths.length;
|
|
2545
|
+
Promise.all(paths.map(async (path) => {
|
|
2546
|
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
2547
|
+
if (res) this._emitReady();
|
|
2548
|
+
return res;
|
|
2549
|
+
})).then((results) => {
|
|
2550
|
+
if (this.closed) return;
|
|
2551
|
+
results.forEach((item) => {
|
|
2552
|
+
if (item) this.add(sp.dirname(item), sp.basename(_origAdd || item));
|
|
2553
|
+
});
|
|
2554
|
+
});
|
|
2555
|
+
return this;
|
|
2556
|
+
}
|
|
2557
|
+
/**
|
|
2558
|
+
* Close watchers or start ignoring events from specified paths.
|
|
2559
|
+
*/
|
|
2560
|
+
unwatch(paths_) {
|
|
2561
|
+
if (this.closed) return this;
|
|
2562
|
+
const paths = unifyPaths(paths_);
|
|
2563
|
+
const { cwd } = this.options;
|
|
2564
|
+
paths.forEach((path) => {
|
|
2565
|
+
if (!sp.isAbsolute(path) && !this._closers.has(path)) {
|
|
2566
|
+
if (cwd) path = sp.join(cwd, path);
|
|
2567
|
+
path = sp.resolve(path);
|
|
2568
|
+
}
|
|
2569
|
+
this._closePath(path);
|
|
2570
|
+
this._addIgnoredPath(path);
|
|
2571
|
+
if (this._watched.has(path)) this._addIgnoredPath({
|
|
2572
|
+
path,
|
|
2573
|
+
recursive: true
|
|
2574
|
+
});
|
|
2575
|
+
this._userIgnored = void 0;
|
|
2576
|
+
});
|
|
2577
|
+
return this;
|
|
2578
|
+
}
|
|
2579
|
+
/**
|
|
2580
|
+
* Close watchers and remove all listeners from watched paths.
|
|
2581
|
+
*/
|
|
2582
|
+
close() {
|
|
2583
|
+
if (this._closePromise) return this._closePromise;
|
|
2584
|
+
this.closed = true;
|
|
2585
|
+
this.removeAllListeners();
|
|
2586
|
+
const closers = [];
|
|
2587
|
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
|
2588
|
+
const promise = closer();
|
|
2589
|
+
if (promise instanceof Promise) closers.push(promise);
|
|
2590
|
+
}));
|
|
2591
|
+
this._streams.forEach((stream) => stream.destroy());
|
|
2592
|
+
this._userIgnored = void 0;
|
|
2593
|
+
this._readyCount = 0;
|
|
2594
|
+
this._readyEmitted = false;
|
|
2595
|
+
this._watched.forEach((dirent) => dirent.dispose());
|
|
2596
|
+
this._closers.clear();
|
|
2597
|
+
this._watched.clear();
|
|
2598
|
+
this._streams.clear();
|
|
2599
|
+
this._symlinkPaths.clear();
|
|
2600
|
+
this._throttled.clear();
|
|
2601
|
+
this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
|
|
2602
|
+
return this._closePromise;
|
|
2603
|
+
}
|
|
2604
|
+
/**
|
|
2605
|
+
* Expose list of watched paths
|
|
2606
|
+
* @returns for chaining
|
|
2607
|
+
*/
|
|
2608
|
+
getWatched() {
|
|
2609
|
+
const watchList = {};
|
|
2610
|
+
this._watched.forEach((entry, dir) => {
|
|
2611
|
+
const index = (this.options.cwd ? sp.relative(this.options.cwd, dir) : dir) || ONE_DOT;
|
|
2612
|
+
watchList[index] = entry.getChildren().sort();
|
|
2613
|
+
});
|
|
2614
|
+
return watchList;
|
|
2615
|
+
}
|
|
2616
|
+
emitWithAll(event, args) {
|
|
2617
|
+
this.emit(event, ...args);
|
|
2618
|
+
if (event !== EVENTS.ERROR) this.emit(EVENTS.ALL, event, ...args);
|
|
2619
|
+
}
|
|
2620
|
+
/**
|
|
2621
|
+
* Normalize and emit events.
|
|
2622
|
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
2623
|
+
* @param event Type of event
|
|
2624
|
+
* @param path File or directory path
|
|
2625
|
+
* @param stats arguments to be passed with event
|
|
2626
|
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
2627
|
+
*/
|
|
2628
|
+
async _emit(event, path, stats) {
|
|
2629
|
+
if (this.closed) return;
|
|
2630
|
+
const opts = this.options;
|
|
2631
|
+
if (isWindows) path = sp.normalize(path);
|
|
2632
|
+
if (opts.cwd) path = sp.relative(opts.cwd, path);
|
|
2633
|
+
const args = [path];
|
|
2634
|
+
if (stats != null) args.push(stats);
|
|
2635
|
+
const awf = opts.awaitWriteFinish;
|
|
2636
|
+
let pw;
|
|
2637
|
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
2638
|
+
pw.lastChange = /* @__PURE__ */ new Date();
|
|
2639
|
+
return this;
|
|
2640
|
+
}
|
|
2641
|
+
if (opts.atomic) {
|
|
2642
|
+
if (event === EVENTS.UNLINK) {
|
|
2643
|
+
this._pendingUnlinks.set(path, [event, ...args]);
|
|
2644
|
+
setTimeout(() => {
|
|
2645
|
+
this._pendingUnlinks.forEach((entry, path) => {
|
|
2646
|
+
this.emit(...entry);
|
|
2647
|
+
this.emit(EVENTS.ALL, ...entry);
|
|
2648
|
+
this._pendingUnlinks.delete(path);
|
|
2649
|
+
});
|
|
2650
|
+
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
2651
|
+
return this;
|
|
2652
|
+
}
|
|
2653
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
2654
|
+
event = EVENTS.CHANGE;
|
|
2655
|
+
this._pendingUnlinks.delete(path);
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
2659
|
+
const awfEmit = (err, stats) => {
|
|
2660
|
+
if (err) {
|
|
2661
|
+
event = EVENTS.ERROR;
|
|
2662
|
+
args[0] = err;
|
|
2663
|
+
this.emitWithAll(event, args);
|
|
2664
|
+
} else if (stats) {
|
|
2665
|
+
if (args.length > 1) args[1] = stats;
|
|
2666
|
+
else args.push(stats);
|
|
2667
|
+
this.emitWithAll(event, args);
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
2671
|
+
return this;
|
|
2672
|
+
}
|
|
2673
|
+
if (event === EVENTS.CHANGE) {
|
|
2674
|
+
if (!this._throttle(EVENTS.CHANGE, path, 50)) return this;
|
|
2675
|
+
}
|
|
2676
|
+
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
2677
|
+
const fullPath = opts.cwd ? sp.join(opts.cwd, path) : path;
|
|
2678
|
+
let stats;
|
|
2679
|
+
try {
|
|
2680
|
+
stats = await stat$1(fullPath);
|
|
2681
|
+
} catch (err) {}
|
|
2682
|
+
if (!stats || this.closed) return;
|
|
2683
|
+
args.push(stats);
|
|
2684
|
+
}
|
|
2685
|
+
this.emitWithAll(event, args);
|
|
2686
|
+
return this;
|
|
2687
|
+
}
|
|
2688
|
+
/**
|
|
2689
|
+
* Common handler for errors
|
|
2690
|
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
2691
|
+
*/
|
|
2692
|
+
_handleError(error) {
|
|
2693
|
+
const code = error && error.code;
|
|
2694
|
+
if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) this.emit(EVENTS.ERROR, error);
|
|
2695
|
+
return error || this.closed;
|
|
2696
|
+
}
|
|
2697
|
+
/**
|
|
2698
|
+
* Helper utility for throttling
|
|
2699
|
+
* @param actionType type being throttled
|
|
2700
|
+
* @param path being acted upon
|
|
2701
|
+
* @param timeout duration of time to suppress duplicate actions
|
|
2702
|
+
* @returns tracking object or false if action should be suppressed
|
|
2703
|
+
*/
|
|
2704
|
+
_throttle(actionType, path, timeout) {
|
|
2705
|
+
if (!this._throttled.has(actionType)) this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
2706
|
+
const action = this._throttled.get(actionType);
|
|
2707
|
+
if (!action) throw new Error("invalid throttle");
|
|
2708
|
+
const actionPath = action.get(path);
|
|
2709
|
+
if (actionPath) {
|
|
2710
|
+
actionPath.count++;
|
|
2711
|
+
return false;
|
|
2712
|
+
}
|
|
2713
|
+
let timeoutObject;
|
|
2714
|
+
const clear = () => {
|
|
2715
|
+
const item = action.get(path);
|
|
2716
|
+
const count = item ? item.count : 0;
|
|
2717
|
+
action.delete(path);
|
|
2718
|
+
clearTimeout(timeoutObject);
|
|
2719
|
+
if (item) clearTimeout(item.timeoutObject);
|
|
2720
|
+
return count;
|
|
2721
|
+
};
|
|
2722
|
+
timeoutObject = setTimeout(clear, timeout);
|
|
2723
|
+
const thr = {
|
|
2724
|
+
timeoutObject,
|
|
2725
|
+
clear,
|
|
2726
|
+
count: 0
|
|
2727
|
+
};
|
|
2728
|
+
action.set(path, thr);
|
|
2729
|
+
return thr;
|
|
2730
|
+
}
|
|
2731
|
+
_incrReadyCount() {
|
|
2732
|
+
return this._readyCount++;
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Awaits write operation to finish.
|
|
2736
|
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
2737
|
+
* @param path being acted upon
|
|
2738
|
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
2739
|
+
* @param event
|
|
2740
|
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
2741
|
+
*/
|
|
2742
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
2743
|
+
const awf = this.options.awaitWriteFinish;
|
|
2744
|
+
if (typeof awf !== "object") return;
|
|
2745
|
+
const pollInterval = awf.pollInterval;
|
|
2746
|
+
let timeoutHandler;
|
|
2747
|
+
let fullPath = path;
|
|
2748
|
+
if (this.options.cwd && !sp.isAbsolute(path)) fullPath = sp.join(this.options.cwd, path);
|
|
2749
|
+
const now = /* @__PURE__ */ new Date();
|
|
2750
|
+
const writes = this._pendingWrites;
|
|
2751
|
+
function awaitWriteFinishFn(prevStat) {
|
|
2752
|
+
stat(fullPath, (err, curStat) => {
|
|
2753
|
+
if (err || !writes.has(path)) {
|
|
2754
|
+
if (err && err.code !== "ENOENT") awfEmit(err);
|
|
2755
|
+
return;
|
|
2756
|
+
}
|
|
2757
|
+
const now = Number(/* @__PURE__ */ new Date());
|
|
2758
|
+
if (prevStat && curStat.size !== prevStat.size) writes.get(path).lastChange = now;
|
|
2759
|
+
if (now - writes.get(path).lastChange >= threshold) {
|
|
2760
|
+
writes.delete(path);
|
|
2761
|
+
awfEmit(void 0, curStat);
|
|
2762
|
+
} else timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
if (!writes.has(path)) {
|
|
2766
|
+
writes.set(path, {
|
|
2767
|
+
lastChange: now,
|
|
2768
|
+
cancelWait: () => {
|
|
2769
|
+
writes.delete(path);
|
|
2770
|
+
clearTimeout(timeoutHandler);
|
|
2771
|
+
return event;
|
|
2772
|
+
}
|
|
2773
|
+
});
|
|
2774
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* Determines whether user has asked to ignore this path.
|
|
2779
|
+
*/
|
|
2780
|
+
_isIgnored(path, stats) {
|
|
2781
|
+
if (this.options.atomic && DOT_RE.test(path)) return true;
|
|
2782
|
+
if (!this._userIgnored) {
|
|
2783
|
+
const { cwd } = this.options;
|
|
2784
|
+
const ignored = (this.options.ignored || []).map(normalizeIgnored(cwd));
|
|
2785
|
+
this._userIgnored = anymatch([...[...this._ignoredPaths].map(normalizeIgnored(cwd)), ...ignored], void 0);
|
|
2786
|
+
}
|
|
2787
|
+
return this._userIgnored(path, stats);
|
|
2788
|
+
}
|
|
2789
|
+
_isntIgnored(path, stat) {
|
|
2790
|
+
return !this._isIgnored(path, stat);
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Provides a set of common helpers and properties relating to symlink handling.
|
|
2794
|
+
* @param path file or directory pattern being watched
|
|
2795
|
+
*/
|
|
2796
|
+
_getWatchHelpers(path) {
|
|
2797
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
2798
|
+
}
|
|
2799
|
+
/**
|
|
2800
|
+
* Provides directory tracking objects
|
|
2801
|
+
* @param directory path of the directory
|
|
2802
|
+
*/
|
|
2803
|
+
_getWatchedDir(directory) {
|
|
2804
|
+
const dir = sp.resolve(directory);
|
|
2805
|
+
if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
2806
|
+
return this._watched.get(dir);
|
|
2807
|
+
}
|
|
2808
|
+
/**
|
|
2809
|
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
|
2810
|
+
*/
|
|
2811
|
+
_hasReadPermissions(stats) {
|
|
2812
|
+
if (this.options.ignorePermissionErrors) return true;
|
|
2813
|
+
return Boolean(Number(stats.mode) & 256);
|
|
2814
|
+
}
|
|
2815
|
+
/**
|
|
2816
|
+
* Handles emitting unlink events for
|
|
2817
|
+
* files and directories, and via recursion, for
|
|
2818
|
+
* files and directories within directories that are unlinked
|
|
2819
|
+
* @param directory within which the following item is located
|
|
2820
|
+
* @param item base path of item/directory
|
|
2821
|
+
*/
|
|
2822
|
+
_remove(directory, item, isDirectory) {
|
|
2823
|
+
const path = sp.join(directory, item);
|
|
2824
|
+
const fullPath = sp.resolve(path);
|
|
2825
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
2826
|
+
if (!this._throttle("remove", path, 100)) return;
|
|
2827
|
+
if (!isDirectory && this._watched.size === 1) this.add(directory, item, true);
|
|
2828
|
+
this._getWatchedDir(path).getChildren().forEach((nested) => this._remove(path, nested));
|
|
2829
|
+
const parent = this._getWatchedDir(directory);
|
|
2830
|
+
const wasTracked = parent.has(item);
|
|
2831
|
+
parent.remove(item);
|
|
2832
|
+
if (this._symlinkPaths.has(fullPath)) this._symlinkPaths.delete(fullPath);
|
|
2833
|
+
let relPath = path;
|
|
2834
|
+
if (this.options.cwd) relPath = sp.relative(this.options.cwd, path);
|
|
2835
|
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
2836
|
+
if (this._pendingWrites.get(relPath).cancelWait() === EVENTS.ADD) return;
|
|
2837
|
+
}
|
|
2838
|
+
this._watched.delete(path);
|
|
2839
|
+
this._watched.delete(fullPath);
|
|
2840
|
+
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
2841
|
+
if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
|
|
2842
|
+
this._closePath(path);
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* Closes all watchers for a path
|
|
2846
|
+
*/
|
|
2847
|
+
_closePath(path) {
|
|
2848
|
+
this._closeFile(path);
|
|
2849
|
+
const dir = sp.dirname(path);
|
|
2850
|
+
this._getWatchedDir(dir).remove(sp.basename(path));
|
|
2851
|
+
}
|
|
2852
|
+
/**
|
|
2853
|
+
* Closes only file-specific watchers
|
|
2854
|
+
*/
|
|
2855
|
+
_closeFile(path) {
|
|
2856
|
+
const closers = this._closers.get(path);
|
|
2857
|
+
if (!closers) return;
|
|
2858
|
+
closers.forEach((closer) => closer());
|
|
2859
|
+
this._closers.delete(path);
|
|
2860
|
+
}
|
|
2861
|
+
_addPathCloser(path, closer) {
|
|
2862
|
+
if (!closer) return;
|
|
2863
|
+
let list = this._closers.get(path);
|
|
2864
|
+
if (!list) {
|
|
2865
|
+
list = [];
|
|
2866
|
+
this._closers.set(path, list);
|
|
2867
|
+
}
|
|
2868
|
+
list.push(closer);
|
|
2869
|
+
}
|
|
2870
|
+
_readdirp(root, opts) {
|
|
2871
|
+
if (this.closed) return;
|
|
2872
|
+
let stream = readdirp(root, {
|
|
2873
|
+
type: EVENTS.ALL,
|
|
2874
|
+
alwaysStat: true,
|
|
2875
|
+
lstat: true,
|
|
2876
|
+
...opts,
|
|
2877
|
+
depth: 0
|
|
2878
|
+
});
|
|
2879
|
+
this._streams.add(stream);
|
|
2880
|
+
stream.once(STR_CLOSE, () => {
|
|
2881
|
+
stream = void 0;
|
|
2882
|
+
});
|
|
2883
|
+
stream.once("end", () => {
|
|
2884
|
+
if (stream) {
|
|
2885
|
+
this._streams.delete(stream);
|
|
2886
|
+
stream = void 0;
|
|
2887
|
+
}
|
|
2888
|
+
});
|
|
2889
|
+
return stream;
|
|
2890
|
+
}
|
|
2891
|
+
};
|
|
2892
|
+
/**
|
|
2893
|
+
* Instantiates watcher with paths to be tracked.
|
|
2894
|
+
* @param paths file / directory paths
|
|
2895
|
+
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
|
2896
|
+
* @returns an instance of FSWatcher for chaining.
|
|
2897
|
+
* @example
|
|
2898
|
+
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
|
2899
|
+
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
|
2900
|
+
*/
|
|
2901
|
+
function watch$1(paths, options = {}) {
|
|
2902
|
+
const watcher = new FSWatcher(options);
|
|
2903
|
+
watcher.add(paths);
|
|
2904
|
+
return watcher;
|
|
2905
|
+
}
|
|
2906
|
+
var chokidar_default = {
|
|
2907
|
+
watch: watch$1,
|
|
2908
|
+
FSWatcher
|
|
2909
|
+
};
|
|
2910
|
+
//#endregion
|
|
2911
|
+
//#region ../../packages/core/src/services/event.service.ts
|
|
2912
|
+
var EventService = class extends Effect.Service()("@ringi/EventService", { effect: Effect.gen(function* effect() {
|
|
2913
|
+
const rt = yield* Effect.runtime();
|
|
2914
|
+
const runFork = Runtime.runFork(rt);
|
|
2915
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
2916
|
+
const broadcast = Effect.fn("EventService.broadcast")(function* broadcast(type, data) {
|
|
2917
|
+
const event = {
|
|
2918
|
+
data,
|
|
2919
|
+
timestamp: Date.now(),
|
|
2920
|
+
type
|
|
2921
|
+
};
|
|
2922
|
+
for (const queue of subscribers) yield* Queue.offer(queue, event);
|
|
2923
|
+
});
|
|
2924
|
+
const subscribe = Effect.fn("EventService.subscribe")(function* subscribe() {
|
|
2925
|
+
const queue = yield* Queue.sliding(100);
|
|
2926
|
+
subscribers.add(queue);
|
|
2927
|
+
return {
|
|
2928
|
+
stream: Stream.fromQueue(queue),
|
|
2929
|
+
unsubscribe: Effect.sync(() => {
|
|
2930
|
+
subscribers.delete(queue);
|
|
2931
|
+
}).pipe(Effect.andThen(Queue.shutdown(queue)))
|
|
2932
|
+
};
|
|
2933
|
+
});
|
|
2934
|
+
const startFileWatcher = (repoPath) => Effect.acquireRelease(Effect.sync(() => {
|
|
2935
|
+
let debounceTimer = null;
|
|
2936
|
+
const watcher = chokidar_default.watch(repoPath, {
|
|
2937
|
+
ignoreInitial: true,
|
|
2938
|
+
ignored: [
|
|
2939
|
+
"**/node_modules/**",
|
|
2940
|
+
"**/.git/**",
|
|
2941
|
+
"**/.ringi/**",
|
|
2942
|
+
"**/dist/**"
|
|
2943
|
+
],
|
|
2944
|
+
persistent: true,
|
|
2945
|
+
...platform() === "darwin" ? {
|
|
2946
|
+
interval: 1e3,
|
|
2947
|
+
usePolling: true
|
|
2948
|
+
} : {}
|
|
2949
|
+
});
|
|
2950
|
+
const debouncedBroadcast = (filePath) => {
|
|
2951
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
2952
|
+
debounceTimer = setTimeout(() => {
|
|
2953
|
+
runFork(broadcast("files", { path: relative(repoPath, filePath) }));
|
|
2954
|
+
}, 300);
|
|
2955
|
+
};
|
|
2956
|
+
watcher.on("add", debouncedBroadcast);
|
|
2957
|
+
watcher.on("change", debouncedBroadcast);
|
|
2958
|
+
watcher.on("unlink", debouncedBroadcast);
|
|
2959
|
+
return watcher;
|
|
2960
|
+
}), (watcher) => Effect.promise(() => watcher.close()));
|
|
2961
|
+
const getClientCount = () => Effect.sync(() => subscribers.size);
|
|
2962
|
+
return {
|
|
2963
|
+
broadcast,
|
|
2964
|
+
getClientCount,
|
|
2965
|
+
startFileWatcher,
|
|
2966
|
+
subscribe
|
|
2967
|
+
};
|
|
2968
|
+
}) }) {};
|
|
2969
|
+
//#endregion
|
|
2970
|
+
//#region ../../packages/core/src/runtime.ts
|
|
2971
|
+
const CoreLive = Layer.mergeAll(ReviewService.Default, ReviewRepo.Default, ReviewFileRepo.Default, CommentService.Default, CommentRepo.Default, TodoService.Default, TodoRepo.Default, GitService.Default, EventService.Default, ExportService.Default, SqliteService.Default);
|
|
2972
|
+
//#endregion
|
|
2973
|
+
export { GitService as a, CommentService as c, ReviewId as d, ReviewNotFound as f, ReviewService as i, TodoId as l, ExportService as n, getDiffSummary as o, ReviewSourceType as p, TodoService as r, parseDiff as s, CoreLive as t, TodoNotFound as u };
|
|
2974
|
+
|
|
2975
|
+
//# sourceMappingURL=runtime.mjs.map
|