@buildautomaton/cli 0.1.3 → 0.1.4

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.js CHANGED
@@ -971,7 +971,7 @@ var require_suggestSimilar = __commonJS({
971
971
  // ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js
972
972
  var require_command = __commonJS({
973
973
  "../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js"(exports) {
974
- var EventEmitter3 = __require("node:events").EventEmitter;
974
+ var EventEmitter2 = __require("node:events").EventEmitter;
975
975
  var childProcess = __require("node:child_process");
976
976
  var path25 = __require("node:path");
977
977
  var fs21 = __require("node:fs");
@@ -981,7 +981,7 @@ var require_command = __commonJS({
981
981
  var { Help: Help2 } = require_help();
982
982
  var { Option: Option2, DualOptions } = require_option();
983
983
  var { suggestSimilar } = require_suggestSimilar();
984
- var Command2 = class _Command extends EventEmitter3 {
984
+ var Command2 = class _Command extends EventEmitter2 {
985
985
  /**
986
986
  * Initialize a new `Command`.
987
987
  *
@@ -5231,13 +5231,13 @@ var require_extension = __commonJS({
5231
5231
  var require_websocket = __commonJS({
5232
5232
  "../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js"(exports, module) {
5233
5233
  "use strict";
5234
- var EventEmitter3 = __require("events");
5234
+ var EventEmitter2 = __require("events");
5235
5235
  var https3 = __require("https");
5236
5236
  var http = __require("http");
5237
5237
  var net = __require("net");
5238
5238
  var tls = __require("tls");
5239
5239
  var { randomBytes, createHash: createHash2 } = __require("crypto");
5240
- var { Duplex, Readable: Readable3 } = __require("stream");
5240
+ var { Duplex, Readable: Readable2 } = __require("stream");
5241
5241
  var { URL: URL2 } = __require("url");
5242
5242
  var PerMessageDeflate = require_permessage_deflate();
5243
5243
  var Receiver2 = require_receiver();
@@ -5263,7 +5263,7 @@ var require_websocket = __commonJS({
5263
5263
  var protocolVersions = [8, 13];
5264
5264
  var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
5265
5265
  var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
5266
- var WebSocket2 = class _WebSocket extends EventEmitter3 {
5266
+ var WebSocket2 = class _WebSocket extends EventEmitter2 {
5267
5267
  /**
5268
5268
  * Create a new `WebSocket`.
5269
5269
  *
@@ -6175,7 +6175,7 @@ var require_stream = __commonJS({
6175
6175
  };
6176
6176
  duplex._final = function(callback) {
6177
6177
  if (ws.readyState === ws.CONNECTING) {
6178
- ws.once("open", function open2() {
6178
+ ws.once("open", function open() {
6179
6179
  duplex._final(callback);
6180
6180
  });
6181
6181
  return;
@@ -6196,7 +6196,7 @@ var require_stream = __commonJS({
6196
6196
  };
6197
6197
  duplex._write = function(chunk, encoding, callback) {
6198
6198
  if (ws.readyState === ws.CONNECTING) {
6199
- ws.once("open", function open2() {
6199
+ ws.once("open", function open() {
6200
6200
  duplex._write(chunk, encoding, callback);
6201
6201
  });
6202
6202
  return;
@@ -6260,7 +6260,7 @@ var require_subprotocol = __commonJS({
6260
6260
  var require_websocket_server = __commonJS({
6261
6261
  "../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js"(exports, module) {
6262
6262
  "use strict";
6263
- var EventEmitter3 = __require("events");
6263
+ var EventEmitter2 = __require("events");
6264
6264
  var http = __require("http");
6265
6265
  var { Duplex } = __require("stream");
6266
6266
  var { createHash: createHash2 } = __require("crypto");
@@ -6273,7 +6273,7 @@ var require_websocket_server = __commonJS({
6273
6273
  var RUNNING = 0;
6274
6274
  var CLOSING = 1;
6275
6275
  var CLOSED = 2;
6276
- var WebSocketServer2 = class extends EventEmitter3 {
6276
+ var WebSocketServer2 = class extends EventEmitter2 {
6277
6277
  /**
6278
6278
  * Create a `WebSocketServer` instance.
6279
6279
  *
@@ -7426,12 +7426,12 @@ var require_src2 = __commonJS({
7426
7426
  function check2(path25, isFile, isDirectory) {
7427
7427
  log2(`checking %s`, path25);
7428
7428
  try {
7429
- const stat4 = fs_1.statSync(path25);
7430
- if (stat4.isFile() && isFile) {
7429
+ const stat = fs_1.statSync(path25);
7430
+ if (stat.isFile() && isFile) {
7431
7431
  log2(`[OK] path represents a file`);
7432
7432
  return true;
7433
7433
  }
7434
- if (stat4.isDirectory() && isDirectory) {
7434
+ if (stat.isDirectory() && isDirectory) {
7435
7435
  log2(`[OK] path represents a directory`);
7436
7436
  return true;
7437
7437
  }
@@ -24800,8 +24800,8 @@ var init_acp = __esm({
24800
24800
  this.#requestHandler = requestHandler;
24801
24801
  this.#notificationHandler = notificationHandler;
24802
24802
  this.#stream = stream;
24803
- this.#closedPromise = new Promise((resolve17) => {
24804
- this.#abortController.signal.addEventListener("abort", () => resolve17());
24803
+ this.#closedPromise = new Promise((resolve15) => {
24804
+ this.#abortController.signal.addEventListener("abort", () => resolve15());
24805
24805
  });
24806
24806
  this.#receive();
24807
24807
  }
@@ -24950,8 +24950,8 @@ var init_acp = __esm({
24950
24950
  }
24951
24951
  async sendRequest(method, params) {
24952
24952
  const id = this.#nextRequestId++;
24953
- const responsePromise = new Promise((resolve17, reject) => {
24954
- this.#pendingResponses.set(id, { resolve: resolve17, reject });
24953
+ const responsePromise = new Promise((resolve15, reject) => {
24954
+ this.#pendingResponses.set(id, { resolve: resolve15, reject });
24955
24955
  });
24956
24956
  await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
24957
24957
  return responsePromise;
@@ -25304,8 +25304,8 @@ function runPendingAuth(options) {
25304
25304
  let hasOpenedBrowser = false;
25305
25305
  let resolved = false;
25306
25306
  let resolveAuth;
25307
- const authPromise = new Promise((resolve17) => {
25308
- resolveAuth = resolve17;
25307
+ const authPromise = new Promise((resolve15) => {
25308
+ resolveAuth = resolve15;
25309
25309
  });
25310
25310
  function cleanup() {
25311
25311
  if (reconnectTimeout) {
@@ -30076,7 +30076,7 @@ function scheduleReconnect(state, connect, log2) {
30076
30076
  // src/bridge/connection/close-bridge-connection.ts
30077
30077
  async function closeBridgeConnection(state, acpManager, devServerManager, log2) {
30078
30078
  log2?.("Shutting down\u2026");
30079
- await new Promise((resolve17) => setImmediate(resolve17));
30079
+ await new Promise((resolve15) => setImmediate(resolve15));
30080
30080
  if (devServerManager) {
30081
30081
  log2?.("Requesting dev server processes to stop\u2026");
30082
30082
  await devServerManager.shutdownAllGraceful();
@@ -30274,14 +30274,14 @@ function toErrorMessage(err) {
30274
30274
  async function createAcpClient(options) {
30275
30275
  const { ClientSideConnection: ClientSideConnection2, ndJsonStream: ndJsonStream2 } = await Promise.resolve().then(() => (init_acp(), acp_exports));
30276
30276
  const { command, cwd: cwd3 = process.cwd(), onSessionUpdate } = options;
30277
- const isWindows2 = process.platform === "win32";
30277
+ const isWindows = process.platform === "win32";
30278
30278
  const child = spawn2(command[0], command.slice(1), {
30279
30279
  cwd: cwd3,
30280
30280
  stdio: ["pipe", "pipe", "inherit"],
30281
30281
  env: process.env,
30282
- shell: isWindows2
30282
+ shell: isWindows
30283
30283
  });
30284
- return new Promise((resolve17, reject) => {
30284
+ return new Promise((resolve15, reject) => {
30285
30285
  child.on("error", (err) => {
30286
30286
  child.kill();
30287
30287
  reject(new Error(formatSpawnError(err, command[0])));
@@ -30310,7 +30310,7 @@ async function createAcpClient(options) {
30310
30310
  });
30311
30311
  const newSessionRes = await connection.newSession({ workingDirectory: cwd3 });
30312
30312
  const sessionId = newSessionRes.sessionId;
30313
- resolve17({
30313
+ resolve15({
30314
30314
  sessionId,
30315
30315
  async sendPrompt(prompt, _options) {
30316
30316
  try {
@@ -30461,14 +30461,14 @@ function sliceLinesByRange(content, line, limit) {
30461
30461
  async function createCursorAcpClient(options) {
30462
30462
  const { command, cwd: cwd3 = process.cwd(), onSessionUpdate, onRequest, onFileChange } = options;
30463
30463
  const dbgFs = process.env.BUILDAMATON_DEBUG_ACP_FS === "1";
30464
- const isWindows2 = process.platform === "win32";
30464
+ const isWindows = process.platform === "win32";
30465
30465
  const child = spawn3(command[0], command.slice(1), {
30466
30466
  cwd: cwd3,
30467
30467
  stdio: ["pipe", "pipe", "inherit"],
30468
30468
  env: process.env,
30469
- shell: isWindows2
30469
+ shell: isWindows
30470
30470
  });
30471
- return new Promise((resolve17, reject) => {
30471
+ return new Promise((resolve15, reject) => {
30472
30472
  child.on("error", (err) => {
30473
30473
  child.kill();
30474
30474
  reject(new Error(formatSpawnError2(err, command[0])));
@@ -30639,7 +30639,7 @@ async function createCursorAcpClient(options) {
30639
30639
  const newResult = await send("session/new", { cwd: cwd3, mcpServers: [] });
30640
30640
  const sessionId = newResult?.sessionId ?? "";
30641
30641
  if (!sessionId) throw new Error("Cursor ACP session/new did not return sessionId");
30642
- resolve17({
30642
+ resolve15({
30643
30643
  sessionId,
30644
30644
  async sendPrompt(prompt, _options) {
30645
30645
  promptOutputBuffer = "";
@@ -31959,11 +31959,11 @@ var previewSkill = {
31959
31959
  const port = params.port ?? (Number(process.env[PREVIEW_PORT_ENV]) || DEFAULT_PORT);
31960
31960
  previewPort = port;
31961
31961
  previewSecret = randomSecret();
31962
- const isWindows2 = process.platform === "win32";
31962
+ const isWindows = process.platform === "win32";
31963
31963
  const parts = command.split(/\s+/);
31964
31964
  const exe = parts[0];
31965
31965
  const args = parts.slice(1);
31966
- previewProcess = spawn4(isWindows2 && exe === "npm" ? "npm.cmd" : exe, args, {
31966
+ previewProcess = spawn4(isWindows && exe === "npm" ? "npm.cmd" : exe, args, {
31967
31967
  cwd: process.cwd(),
31968
31968
  stdio: ["ignore", "pipe", "pipe"],
31969
31969
  env: {
@@ -32145,8 +32145,8 @@ function resolveFilePath(relativePath) {
32145
32145
  } catch {
32146
32146
  real = resolved;
32147
32147
  }
32148
- const stat4 = fs6.statSync(real);
32149
- if (!stat4.isFile()) return { error: "Not a file" };
32148
+ const stat = fs6.statSync(real);
32149
+ if (!stat.isFile()) return { error: "Not a file" };
32150
32150
  return real;
32151
32151
  }
32152
32152
  var LINE_CHUNK_SIZE = 64 * 1024;
@@ -32311,10 +32311,10 @@ function readFile(relativePath, startLine, endLine, lineOffset, lineChunkSize =
32311
32311
  if (hasRange) {
32312
32312
  return readFileRange(result, startLine, endLine, lineOffset, lineChunkSize);
32313
32313
  }
32314
- const stat4 = fs6.statSync(result);
32314
+ const stat = fs6.statSync(result);
32315
32315
  const raw = fs6.readFileSync(result, "utf8");
32316
32316
  const lines = raw.split(/\r?\n/);
32317
- return { content: raw, totalLines: lines.length, size: stat4.size };
32317
+ return { content: raw, totalLines: lines.length, size: stat.size };
32318
32318
  } catch (err) {
32319
32319
  return { error: err instanceof Error ? err.message : String(err) };
32320
32320
  }
@@ -32375,17 +32375,17 @@ function walkDir(dir, baseDir, out) {
32375
32375
  for (const name of names) {
32376
32376
  if (name.startsWith(".")) continue;
32377
32377
  const full = path13.join(dir, name);
32378
- let stat4;
32378
+ let stat;
32379
32379
  try {
32380
- stat4 = fs7.statSync(full);
32380
+ stat = fs7.statSync(full);
32381
32381
  } catch {
32382
32382
  continue;
32383
32383
  }
32384
- const relative6 = path13.relative(baseDir, full).replace(/\\/g, "/");
32385
- if (stat4.isDirectory()) {
32384
+ const relative4 = path13.relative(baseDir, full).replace(/\\/g, "/");
32385
+ if (stat.isDirectory()) {
32386
32386
  walkDir(full, baseDir, out);
32387
- } else if (stat4.isFile()) {
32388
- out.push(relative6);
32387
+ } else if (stat.isFile()) {
32388
+ out.push(relative4);
32389
32389
  }
32390
32390
  }
32391
32391
  }
@@ -33195,1700 +33195,8 @@ async function refreshBridgeTokens(params) {
33195
33195
  }
33196
33196
 
33197
33197
  // src/files/watch-file-index.ts
33198
+ import { watch } from "node:fs";
33198
33199
  import path21 from "node:path";
33199
-
33200
- // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
33201
- import { stat as statcb } from "fs";
33202
- import { stat as stat3, readdir as readdir2 } from "fs/promises";
33203
- import { EventEmitter as EventEmitter2 } from "events";
33204
- import * as sysPath2 from "path";
33205
-
33206
- // ../../node_modules/.pnpm/readdirp@4.1.2/node_modules/readdirp/esm/index.js
33207
- import { stat, lstat, readdir, realpath } from "node:fs/promises";
33208
- import { Readable as Readable2 } from "node:stream";
33209
- import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "node:path";
33210
- var EntryTypes = {
33211
- FILE_TYPE: "files",
33212
- DIR_TYPE: "directories",
33213
- FILE_DIR_TYPE: "files_directories",
33214
- EVERYTHING_TYPE: "all"
33215
- };
33216
- var defaultOptions2 = {
33217
- root: ".",
33218
- fileFilter: (_entryInfo) => true,
33219
- directoryFilter: (_entryInfo) => true,
33220
- type: EntryTypes.FILE_TYPE,
33221
- lstat: false,
33222
- depth: 2147483648,
33223
- alwaysStat: false,
33224
- highWaterMark: 4096
33225
- };
33226
- Object.freeze(defaultOptions2);
33227
- var RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
33228
- var NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EPERM", "EACCES", "ELOOP", RECURSIVE_ERROR_CODE]);
33229
- var ALL_TYPES = [
33230
- EntryTypes.DIR_TYPE,
33231
- EntryTypes.EVERYTHING_TYPE,
33232
- EntryTypes.FILE_DIR_TYPE,
33233
- EntryTypes.FILE_TYPE
33234
- ];
33235
- var DIR_TYPES = /* @__PURE__ */ new Set([
33236
- EntryTypes.DIR_TYPE,
33237
- EntryTypes.EVERYTHING_TYPE,
33238
- EntryTypes.FILE_DIR_TYPE
33239
- ]);
33240
- var FILE_TYPES = /* @__PURE__ */ new Set([
33241
- EntryTypes.EVERYTHING_TYPE,
33242
- EntryTypes.FILE_DIR_TYPE,
33243
- EntryTypes.FILE_TYPE
33244
- ]);
33245
- var isNormalFlowError = (error40) => NORMAL_FLOW_ERRORS.has(error40.code);
33246
- var wantBigintFsStats = process.platform === "win32";
33247
- var emptyFn = (_entryInfo) => true;
33248
- var normalizeFilter = (filter) => {
33249
- if (filter === void 0)
33250
- return emptyFn;
33251
- if (typeof filter === "function")
33252
- return filter;
33253
- if (typeof filter === "string") {
33254
- const fl = filter.trim();
33255
- return (entry) => entry.basename === fl;
33256
- }
33257
- if (Array.isArray(filter)) {
33258
- const trItems = filter.map((item) => item.trim());
33259
- return (entry) => trItems.some((f) => entry.basename === f);
33260
- }
33261
- return emptyFn;
33262
- };
33263
- var ReaddirpStream = class extends Readable2 {
33264
- constructor(options = {}) {
33265
- super({
33266
- objectMode: true,
33267
- autoDestroy: true,
33268
- highWaterMark: options.highWaterMark
33269
- });
33270
- const opts = { ...defaultOptions2, ...options };
33271
- const { root, type } = opts;
33272
- this._fileFilter = normalizeFilter(opts.fileFilter);
33273
- this._directoryFilter = normalizeFilter(opts.directoryFilter);
33274
- const statMethod = opts.lstat ? lstat : stat;
33275
- if (wantBigintFsStats) {
33276
- this._stat = (path25) => statMethod(path25, { bigint: true });
33277
- } else {
33278
- this._stat = statMethod;
33279
- }
33280
- this._maxDepth = opts.depth ?? defaultOptions2.depth;
33281
- this._wantsDir = type ? DIR_TYPES.has(type) : false;
33282
- this._wantsFile = type ? FILE_TYPES.has(type) : false;
33283
- this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
33284
- this._root = presolve(root);
33285
- this._isDirent = !opts.alwaysStat;
33286
- this._statsProp = this._isDirent ? "dirent" : "stats";
33287
- this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
33288
- this.parents = [this._exploreDir(root, 1)];
33289
- this.reading = false;
33290
- this.parent = void 0;
33291
- }
33292
- async _read(batch) {
33293
- if (this.reading)
33294
- return;
33295
- this.reading = true;
33296
- try {
33297
- while (!this.destroyed && batch > 0) {
33298
- const par = this.parent;
33299
- const fil = par && par.files;
33300
- if (fil && fil.length > 0) {
33301
- const { path: path25, depth } = par;
33302
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path25));
33303
- const awaited = await Promise.all(slice);
33304
- for (const entry of awaited) {
33305
- if (!entry)
33306
- continue;
33307
- if (this.destroyed)
33308
- return;
33309
- const entryType = await this._getEntryType(entry);
33310
- if (entryType === "directory" && this._directoryFilter(entry)) {
33311
- if (depth <= this._maxDepth) {
33312
- this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
33313
- }
33314
- if (this._wantsDir) {
33315
- this.push(entry);
33316
- batch--;
33317
- }
33318
- } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
33319
- if (this._wantsFile) {
33320
- this.push(entry);
33321
- batch--;
33322
- }
33323
- }
33324
- }
33325
- } else {
33326
- const parent = this.parents.pop();
33327
- if (!parent) {
33328
- this.push(null);
33329
- break;
33330
- }
33331
- this.parent = await parent;
33332
- if (this.destroyed)
33333
- return;
33334
- }
33335
- }
33336
- } catch (error40) {
33337
- this.destroy(error40);
33338
- } finally {
33339
- this.reading = false;
33340
- }
33341
- }
33342
- async _exploreDir(path25, depth) {
33343
- let files;
33344
- try {
33345
- files = await readdir(path25, this._rdOptions);
33346
- } catch (error40) {
33347
- this._onError(error40);
33348
- }
33349
- return { files, depth, path: path25 };
33350
- }
33351
- async _formatEntry(dirent, path25) {
33352
- let entry;
33353
- const basename6 = this._isDirent ? dirent.name : dirent;
33354
- try {
33355
- const fullPath = presolve(pjoin(path25, basename6));
33356
- entry = { path: prelative(this._root, fullPath), fullPath, basename: basename6 };
33357
- entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
33358
- } catch (err) {
33359
- this._onError(err);
33360
- return;
33361
- }
33362
- return entry;
33363
- }
33364
- _onError(err) {
33365
- if (isNormalFlowError(err) && !this.destroyed) {
33366
- this.emit("warn", err);
33367
- } else {
33368
- this.destroy(err);
33369
- }
33370
- }
33371
- async _getEntryType(entry) {
33372
- if (!entry && this._statsProp in entry) {
33373
- return "";
33374
- }
33375
- const stats = entry[this._statsProp];
33376
- if (stats.isFile())
33377
- return "file";
33378
- if (stats.isDirectory())
33379
- return "directory";
33380
- if (stats && stats.isSymbolicLink()) {
33381
- const full = entry.fullPath;
33382
- try {
33383
- const entryRealPath = await realpath(full);
33384
- const entryRealPathStats = await lstat(entryRealPath);
33385
- if (entryRealPathStats.isFile()) {
33386
- return "file";
33387
- }
33388
- if (entryRealPathStats.isDirectory()) {
33389
- const len = entryRealPath.length;
33390
- if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
33391
- const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
33392
- recursiveError.code = RECURSIVE_ERROR_CODE;
33393
- return this._onError(recursiveError);
33394
- }
33395
- return "directory";
33396
- }
33397
- } catch (error40) {
33398
- this._onError(error40);
33399
- return "";
33400
- }
33401
- }
33402
- }
33403
- _includeAsFile(entry) {
33404
- const stats = entry && entry[this._statsProp];
33405
- return stats && this._wantsEverything && !stats.isDirectory();
33406
- }
33407
- };
33408
- function readdirp(root, options = {}) {
33409
- let type = options.entryType || options.type;
33410
- if (type === "both")
33411
- type = EntryTypes.FILE_DIR_TYPE;
33412
- if (type)
33413
- options.type = type;
33414
- if (!root) {
33415
- throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
33416
- } else if (typeof root !== "string") {
33417
- throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
33418
- } else if (type && !ALL_TYPES.includes(type)) {
33419
- throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
33420
- }
33421
- options.root = root;
33422
- return new ReaddirpStream(options);
33423
- }
33424
-
33425
- // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/handler.js
33426
- import { watchFile, unwatchFile, watch as fs_watch } from "fs";
33427
- import { open, stat as stat2, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
33428
- import * as sysPath from "path";
33429
- import { type as osType } from "os";
33430
- var STR_DATA = "data";
33431
- var STR_END = "end";
33432
- var STR_CLOSE = "close";
33433
- var EMPTY_FN = () => {
33434
- };
33435
- var pl = process.platform;
33436
- var isWindows = pl === "win32";
33437
- var isMacos = pl === "darwin";
33438
- var isLinux = pl === "linux";
33439
- var isFreeBSD = pl === "freebsd";
33440
- var isIBMi = osType() === "OS400";
33441
- var EVENTS = {
33442
- ALL: "all",
33443
- READY: "ready",
33444
- ADD: "add",
33445
- CHANGE: "change",
33446
- ADD_DIR: "addDir",
33447
- UNLINK: "unlink",
33448
- UNLINK_DIR: "unlinkDir",
33449
- RAW: "raw",
33450
- ERROR: "error"
33451
- };
33452
- var EV = EVENTS;
33453
- var THROTTLE_MODE_WATCH = "watch";
33454
- var statMethods = { lstat: lstat2, stat: stat2 };
33455
- var KEY_LISTENERS = "listeners";
33456
- var KEY_ERR = "errHandlers";
33457
- var KEY_RAW = "rawEmitters";
33458
- var HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
33459
- var binaryExtensions = /* @__PURE__ */ new Set([
33460
- "3dm",
33461
- "3ds",
33462
- "3g2",
33463
- "3gp",
33464
- "7z",
33465
- "a",
33466
- "aac",
33467
- "adp",
33468
- "afdesign",
33469
- "afphoto",
33470
- "afpub",
33471
- "ai",
33472
- "aif",
33473
- "aiff",
33474
- "alz",
33475
- "ape",
33476
- "apk",
33477
- "appimage",
33478
- "ar",
33479
- "arj",
33480
- "asf",
33481
- "au",
33482
- "avi",
33483
- "bak",
33484
- "baml",
33485
- "bh",
33486
- "bin",
33487
- "bk",
33488
- "bmp",
33489
- "btif",
33490
- "bz2",
33491
- "bzip2",
33492
- "cab",
33493
- "caf",
33494
- "cgm",
33495
- "class",
33496
- "cmx",
33497
- "cpio",
33498
- "cr2",
33499
- "cur",
33500
- "dat",
33501
- "dcm",
33502
- "deb",
33503
- "dex",
33504
- "djvu",
33505
- "dll",
33506
- "dmg",
33507
- "dng",
33508
- "doc",
33509
- "docm",
33510
- "docx",
33511
- "dot",
33512
- "dotm",
33513
- "dra",
33514
- "DS_Store",
33515
- "dsk",
33516
- "dts",
33517
- "dtshd",
33518
- "dvb",
33519
- "dwg",
33520
- "dxf",
33521
- "ecelp4800",
33522
- "ecelp7470",
33523
- "ecelp9600",
33524
- "egg",
33525
- "eol",
33526
- "eot",
33527
- "epub",
33528
- "exe",
33529
- "f4v",
33530
- "fbs",
33531
- "fh",
33532
- "fla",
33533
- "flac",
33534
- "flatpak",
33535
- "fli",
33536
- "flv",
33537
- "fpx",
33538
- "fst",
33539
- "fvt",
33540
- "g3",
33541
- "gh",
33542
- "gif",
33543
- "graffle",
33544
- "gz",
33545
- "gzip",
33546
- "h261",
33547
- "h263",
33548
- "h264",
33549
- "icns",
33550
- "ico",
33551
- "ief",
33552
- "img",
33553
- "ipa",
33554
- "iso",
33555
- "jar",
33556
- "jpeg",
33557
- "jpg",
33558
- "jpgv",
33559
- "jpm",
33560
- "jxr",
33561
- "key",
33562
- "ktx",
33563
- "lha",
33564
- "lib",
33565
- "lvp",
33566
- "lz",
33567
- "lzh",
33568
- "lzma",
33569
- "lzo",
33570
- "m3u",
33571
- "m4a",
33572
- "m4v",
33573
- "mar",
33574
- "mdi",
33575
- "mht",
33576
- "mid",
33577
- "midi",
33578
- "mj2",
33579
- "mka",
33580
- "mkv",
33581
- "mmr",
33582
- "mng",
33583
- "mobi",
33584
- "mov",
33585
- "movie",
33586
- "mp3",
33587
- "mp4",
33588
- "mp4a",
33589
- "mpeg",
33590
- "mpg",
33591
- "mpga",
33592
- "mxu",
33593
- "nef",
33594
- "npx",
33595
- "numbers",
33596
- "nupkg",
33597
- "o",
33598
- "odp",
33599
- "ods",
33600
- "odt",
33601
- "oga",
33602
- "ogg",
33603
- "ogv",
33604
- "otf",
33605
- "ott",
33606
- "pages",
33607
- "pbm",
33608
- "pcx",
33609
- "pdb",
33610
- "pdf",
33611
- "pea",
33612
- "pgm",
33613
- "pic",
33614
- "png",
33615
- "pnm",
33616
- "pot",
33617
- "potm",
33618
- "potx",
33619
- "ppa",
33620
- "ppam",
33621
- "ppm",
33622
- "pps",
33623
- "ppsm",
33624
- "ppsx",
33625
- "ppt",
33626
- "pptm",
33627
- "pptx",
33628
- "psd",
33629
- "pya",
33630
- "pyc",
33631
- "pyo",
33632
- "pyv",
33633
- "qt",
33634
- "rar",
33635
- "ras",
33636
- "raw",
33637
- "resources",
33638
- "rgb",
33639
- "rip",
33640
- "rlc",
33641
- "rmf",
33642
- "rmvb",
33643
- "rpm",
33644
- "rtf",
33645
- "rz",
33646
- "s3m",
33647
- "s7z",
33648
- "scpt",
33649
- "sgi",
33650
- "shar",
33651
- "snap",
33652
- "sil",
33653
- "sketch",
33654
- "slk",
33655
- "smv",
33656
- "snk",
33657
- "so",
33658
- "stl",
33659
- "suo",
33660
- "sub",
33661
- "swf",
33662
- "tar",
33663
- "tbz",
33664
- "tbz2",
33665
- "tga",
33666
- "tgz",
33667
- "thmx",
33668
- "tif",
33669
- "tiff",
33670
- "tlz",
33671
- "ttc",
33672
- "ttf",
33673
- "txz",
33674
- "udf",
33675
- "uvh",
33676
- "uvi",
33677
- "uvm",
33678
- "uvp",
33679
- "uvs",
33680
- "uvu",
33681
- "viv",
33682
- "vob",
33683
- "war",
33684
- "wav",
33685
- "wax",
33686
- "wbmp",
33687
- "wdp",
33688
- "weba",
33689
- "webm",
33690
- "webp",
33691
- "whl",
33692
- "wim",
33693
- "wm",
33694
- "wma",
33695
- "wmv",
33696
- "wmx",
33697
- "woff",
33698
- "woff2",
33699
- "wrm",
33700
- "wvx",
33701
- "xbm",
33702
- "xif",
33703
- "xla",
33704
- "xlam",
33705
- "xls",
33706
- "xlsb",
33707
- "xlsm",
33708
- "xlsx",
33709
- "xlt",
33710
- "xltm",
33711
- "xltx",
33712
- "xm",
33713
- "xmind",
33714
- "xpi",
33715
- "xpm",
33716
- "xwd",
33717
- "xz",
33718
- "z",
33719
- "zip",
33720
- "zipx"
33721
- ]);
33722
- var isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
33723
- var foreach = (val, fn) => {
33724
- if (val instanceof Set) {
33725
- val.forEach(fn);
33726
- } else {
33727
- fn(val);
33728
- }
33729
- };
33730
- var addAndConvert = (main2, prop, item) => {
33731
- let container = main2[prop];
33732
- if (!(container instanceof Set)) {
33733
- main2[prop] = container = /* @__PURE__ */ new Set([container]);
33734
- }
33735
- container.add(item);
33736
- };
33737
- var clearItem = (cont) => (key) => {
33738
- const set2 = cont[key];
33739
- if (set2 instanceof Set) {
33740
- set2.clear();
33741
- } else {
33742
- delete cont[key];
33743
- }
33744
- };
33745
- var delFromSet = (main2, prop, item) => {
33746
- const container = main2[prop];
33747
- if (container instanceof Set) {
33748
- container.delete(item);
33749
- } else if (container === item) {
33750
- delete main2[prop];
33751
- }
33752
- };
33753
- var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
33754
- var FsWatchInstances = /* @__PURE__ */ new Map();
33755
- function createFsWatchInstance(path25, options, listener, errHandler, emitRaw) {
33756
- const handleEvent = (rawEvent, evPath) => {
33757
- listener(path25);
33758
- emitRaw(rawEvent, evPath, { watchedPath: path25 });
33759
- if (evPath && path25 !== evPath) {
33760
- fsWatchBroadcast(sysPath.resolve(path25, evPath), KEY_LISTENERS, sysPath.join(path25, evPath));
33761
- }
33762
- };
33763
- try {
33764
- return fs_watch(path25, {
33765
- persistent: options.persistent
33766
- }, handleEvent);
33767
- } catch (error40) {
33768
- errHandler(error40);
33769
- return void 0;
33770
- }
33771
- }
33772
- var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
33773
- const cont = FsWatchInstances.get(fullPath);
33774
- if (!cont)
33775
- return;
33776
- foreach(cont[listenerType], (listener) => {
33777
- listener(val1, val2, val3);
33778
- });
33779
- };
33780
- var setFsWatchListener = (path25, fullPath, options, handlers) => {
33781
- const { listener, errHandler, rawEmitter } = handlers;
33782
- let cont = FsWatchInstances.get(fullPath);
33783
- let watcher;
33784
- if (!options.persistent) {
33785
- watcher = createFsWatchInstance(path25, options, listener, errHandler, rawEmitter);
33786
- if (!watcher)
33787
- return;
33788
- return watcher.close.bind(watcher);
33789
- }
33790
- if (cont) {
33791
- addAndConvert(cont, KEY_LISTENERS, listener);
33792
- addAndConvert(cont, KEY_ERR, errHandler);
33793
- addAndConvert(cont, KEY_RAW, rawEmitter);
33794
- } else {
33795
- watcher = createFsWatchInstance(
33796
- path25,
33797
- options,
33798
- fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
33799
- errHandler,
33800
- // no need to use broadcast here
33801
- fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
33802
- );
33803
- if (!watcher)
33804
- return;
33805
- watcher.on(EV.ERROR, async (error40) => {
33806
- const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
33807
- if (cont)
33808
- cont.watcherUnusable = true;
33809
- if (isWindows && error40.code === "EPERM") {
33810
- try {
33811
- const fd = await open(path25, "r");
33812
- await fd.close();
33813
- broadcastErr(error40);
33814
- } catch (err) {
33815
- }
33816
- } else {
33817
- broadcastErr(error40);
33818
- }
33819
- });
33820
- cont = {
33821
- listeners: listener,
33822
- errHandlers: errHandler,
33823
- rawEmitters: rawEmitter,
33824
- watcher
33825
- };
33826
- FsWatchInstances.set(fullPath, cont);
33827
- }
33828
- return () => {
33829
- delFromSet(cont, KEY_LISTENERS, listener);
33830
- delFromSet(cont, KEY_ERR, errHandler);
33831
- delFromSet(cont, KEY_RAW, rawEmitter);
33832
- if (isEmptySet(cont.listeners)) {
33833
- cont.watcher.close();
33834
- FsWatchInstances.delete(fullPath);
33835
- HANDLER_KEYS.forEach(clearItem(cont));
33836
- cont.watcher = void 0;
33837
- Object.freeze(cont);
33838
- }
33839
- };
33840
- };
33841
- var FsWatchFileInstances = /* @__PURE__ */ new Map();
33842
- var setFsWatchFileListener = (path25, fullPath, options, handlers) => {
33843
- const { listener, rawEmitter } = handlers;
33844
- let cont = FsWatchFileInstances.get(fullPath);
33845
- const copts = cont && cont.options;
33846
- if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
33847
- unwatchFile(fullPath);
33848
- cont = void 0;
33849
- }
33850
- if (cont) {
33851
- addAndConvert(cont, KEY_LISTENERS, listener);
33852
- addAndConvert(cont, KEY_RAW, rawEmitter);
33853
- } else {
33854
- cont = {
33855
- listeners: listener,
33856
- rawEmitters: rawEmitter,
33857
- options,
33858
- watcher: watchFile(fullPath, options, (curr, prev) => {
33859
- foreach(cont.rawEmitters, (rawEmitter2) => {
33860
- rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
33861
- });
33862
- const currmtime = curr.mtimeMs;
33863
- if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
33864
- foreach(cont.listeners, (listener2) => listener2(path25, curr));
33865
- }
33866
- })
33867
- };
33868
- FsWatchFileInstances.set(fullPath, cont);
33869
- }
33870
- return () => {
33871
- delFromSet(cont, KEY_LISTENERS, listener);
33872
- delFromSet(cont, KEY_RAW, rawEmitter);
33873
- if (isEmptySet(cont.listeners)) {
33874
- FsWatchFileInstances.delete(fullPath);
33875
- unwatchFile(fullPath);
33876
- cont.options = cont.watcher = void 0;
33877
- Object.freeze(cont);
33878
- }
33879
- };
33880
- };
33881
- var NodeFsHandler = class {
33882
- constructor(fsW) {
33883
- this.fsw = fsW;
33884
- this._boundHandleError = (error40) => fsW._handleError(error40);
33885
- }
33886
- /**
33887
- * Watch file for changes with fs_watchFile or fs_watch.
33888
- * @param path to file or dir
33889
- * @param listener on fs change
33890
- * @returns closer for the watcher instance
33891
- */
33892
- _watchWithNodeFs(path25, listener) {
33893
- const opts = this.fsw.options;
33894
- const directory = sysPath.dirname(path25);
33895
- const basename6 = sysPath.basename(path25);
33896
- const parent = this.fsw._getWatchedDir(directory);
33897
- parent.add(basename6);
33898
- const absolutePath = sysPath.resolve(path25);
33899
- const options = {
33900
- persistent: opts.persistent
33901
- };
33902
- if (!listener)
33903
- listener = EMPTY_FN;
33904
- let closer;
33905
- if (opts.usePolling) {
33906
- const enableBin = opts.interval !== opts.binaryInterval;
33907
- options.interval = enableBin && isBinaryPath(basename6) ? opts.binaryInterval : opts.interval;
33908
- closer = setFsWatchFileListener(path25, absolutePath, options, {
33909
- listener,
33910
- rawEmitter: this.fsw._emitRaw
33911
- });
33912
- } else {
33913
- closer = setFsWatchListener(path25, absolutePath, options, {
33914
- listener,
33915
- errHandler: this._boundHandleError,
33916
- rawEmitter: this.fsw._emitRaw
33917
- });
33918
- }
33919
- return closer;
33920
- }
33921
- /**
33922
- * Watch a file and emit add event if warranted.
33923
- * @returns closer for the watcher instance
33924
- */
33925
- _handleFile(file2, stats, initialAdd) {
33926
- if (this.fsw.closed) {
33927
- return;
33928
- }
33929
- const dirname7 = sysPath.dirname(file2);
33930
- const basename6 = sysPath.basename(file2);
33931
- const parent = this.fsw._getWatchedDir(dirname7);
33932
- let prevStats = stats;
33933
- if (parent.has(basename6))
33934
- return;
33935
- const listener = async (path25, newStats) => {
33936
- if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file2, 5))
33937
- return;
33938
- if (!newStats || newStats.mtimeMs === 0) {
33939
- try {
33940
- const newStats2 = await stat2(file2);
33941
- if (this.fsw.closed)
33942
- return;
33943
- const at = newStats2.atimeMs;
33944
- const mt = newStats2.mtimeMs;
33945
- if (!at || at <= mt || mt !== prevStats.mtimeMs) {
33946
- this.fsw._emit(EV.CHANGE, file2, newStats2);
33947
- }
33948
- if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
33949
- this.fsw._closeFile(path25);
33950
- prevStats = newStats2;
33951
- const closer2 = this._watchWithNodeFs(file2, listener);
33952
- if (closer2)
33953
- this.fsw._addPathCloser(path25, closer2);
33954
- } else {
33955
- prevStats = newStats2;
33956
- }
33957
- } catch (error40) {
33958
- this.fsw._remove(dirname7, basename6);
33959
- }
33960
- } else if (parent.has(basename6)) {
33961
- const at = newStats.atimeMs;
33962
- const mt = newStats.mtimeMs;
33963
- if (!at || at <= mt || mt !== prevStats.mtimeMs) {
33964
- this.fsw._emit(EV.CHANGE, file2, newStats);
33965
- }
33966
- prevStats = newStats;
33967
- }
33968
- };
33969
- const closer = this._watchWithNodeFs(file2, listener);
33970
- if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file2)) {
33971
- if (!this.fsw._throttle(EV.ADD, file2, 0))
33972
- return;
33973
- this.fsw._emit(EV.ADD, file2, stats);
33974
- }
33975
- return closer;
33976
- }
33977
- /**
33978
- * Handle symlinks encountered while reading a dir.
33979
- * @param entry returned by readdirp
33980
- * @param directory path of dir being read
33981
- * @param path of this item
33982
- * @param item basename of this item
33983
- * @returns true if no more processing is needed for this entry.
33984
- */
33985
- async _handleSymlink(entry, directory, path25, item) {
33986
- if (this.fsw.closed) {
33987
- return;
33988
- }
33989
- const full = entry.fullPath;
33990
- const dir = this.fsw._getWatchedDir(directory);
33991
- if (!this.fsw.options.followSymlinks) {
33992
- this.fsw._incrReadyCount();
33993
- let linkPath;
33994
- try {
33995
- linkPath = await fsrealpath(path25);
33996
- } catch (e) {
33997
- this.fsw._emitReady();
33998
- return true;
33999
- }
34000
- if (this.fsw.closed)
34001
- return;
34002
- if (dir.has(item)) {
34003
- if (this.fsw._symlinkPaths.get(full) !== linkPath) {
34004
- this.fsw._symlinkPaths.set(full, linkPath);
34005
- this.fsw._emit(EV.CHANGE, path25, entry.stats);
34006
- }
34007
- } else {
34008
- dir.add(item);
34009
- this.fsw._symlinkPaths.set(full, linkPath);
34010
- this.fsw._emit(EV.ADD, path25, entry.stats);
34011
- }
34012
- this.fsw._emitReady();
34013
- return true;
34014
- }
34015
- if (this.fsw._symlinkPaths.has(full)) {
34016
- return true;
34017
- }
34018
- this.fsw._symlinkPaths.set(full, true);
34019
- }
34020
- _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
34021
- directory = sysPath.join(directory, "");
34022
- throttler = this.fsw._throttle("readdir", directory, 1e3);
34023
- if (!throttler)
34024
- return;
34025
- const previous = this.fsw._getWatchedDir(wh.path);
34026
- const current = /* @__PURE__ */ new Set();
34027
- let stream = this.fsw._readdirp(directory, {
34028
- fileFilter: (entry) => wh.filterPath(entry),
34029
- directoryFilter: (entry) => wh.filterDir(entry)
34030
- });
34031
- if (!stream)
34032
- return;
34033
- stream.on(STR_DATA, async (entry) => {
34034
- if (this.fsw.closed) {
34035
- stream = void 0;
34036
- return;
34037
- }
34038
- const item = entry.path;
34039
- let path25 = sysPath.join(directory, item);
34040
- current.add(item);
34041
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path25, item)) {
34042
- return;
34043
- }
34044
- if (this.fsw.closed) {
34045
- stream = void 0;
34046
- return;
34047
- }
34048
- if (item === target || !target && !previous.has(item)) {
34049
- this.fsw._incrReadyCount();
34050
- path25 = sysPath.join(dir, sysPath.relative(dir, path25));
34051
- this._addToNodeFs(path25, initialAdd, wh, depth + 1);
34052
- }
34053
- }).on(EV.ERROR, this._boundHandleError);
34054
- return new Promise((resolve17, reject) => {
34055
- if (!stream)
34056
- return reject();
34057
- stream.once(STR_END, () => {
34058
- if (this.fsw.closed) {
34059
- stream = void 0;
34060
- return;
34061
- }
34062
- const wasThrottled = throttler ? throttler.clear() : false;
34063
- resolve17(void 0);
34064
- previous.getChildren().filter((item) => {
34065
- return item !== directory && !current.has(item);
34066
- }).forEach((item) => {
34067
- this.fsw._remove(directory, item);
34068
- });
34069
- stream = void 0;
34070
- if (wasThrottled)
34071
- this._handleRead(directory, false, wh, target, dir, depth, throttler);
34072
- });
34073
- });
34074
- }
34075
- /**
34076
- * Read directory to add / remove files from `@watched` list and re-read it on change.
34077
- * @param dir fs path
34078
- * @param stats
34079
- * @param initialAdd
34080
- * @param depth relative to user-supplied path
34081
- * @param target child path targeted for watch
34082
- * @param wh Common watch helpers for this path
34083
- * @param realpath
34084
- * @returns closer for the watcher instance.
34085
- */
34086
- async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath2) {
34087
- const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
34088
- const tracked = parentDir.has(sysPath.basename(dir));
34089
- if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
34090
- this.fsw._emit(EV.ADD_DIR, dir, stats);
34091
- }
34092
- parentDir.add(sysPath.basename(dir));
34093
- this.fsw._getWatchedDir(dir);
34094
- let throttler;
34095
- let closer;
34096
- const oDepth = this.fsw.options.depth;
34097
- if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath2)) {
34098
- if (!target) {
34099
- await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
34100
- if (this.fsw.closed)
34101
- return;
34102
- }
34103
- closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
34104
- if (stats2 && stats2.mtimeMs === 0)
34105
- return;
34106
- this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
34107
- });
34108
- }
34109
- return closer;
34110
- }
34111
- /**
34112
- * Handle added file, directory, or glob pattern.
34113
- * Delegates call to _handleFile / _handleDir after checks.
34114
- * @param path to file or ir
34115
- * @param initialAdd was the file added at watch instantiation?
34116
- * @param priorWh depth relative to user-supplied path
34117
- * @param depth Child path actually targeted for watch
34118
- * @param target Child path actually targeted for watch
34119
- */
34120
- async _addToNodeFs(path25, initialAdd, priorWh, depth, target) {
34121
- const ready = this.fsw._emitReady;
34122
- if (this.fsw._isIgnored(path25) || this.fsw.closed) {
34123
- ready();
34124
- return false;
34125
- }
34126
- const wh = this.fsw._getWatchHelpers(path25);
34127
- if (priorWh) {
34128
- wh.filterPath = (entry) => priorWh.filterPath(entry);
34129
- wh.filterDir = (entry) => priorWh.filterDir(entry);
34130
- }
34131
- try {
34132
- const stats = await statMethods[wh.statMethod](wh.watchPath);
34133
- if (this.fsw.closed)
34134
- return;
34135
- if (this.fsw._isIgnored(wh.watchPath, stats)) {
34136
- ready();
34137
- return false;
34138
- }
34139
- const follow = this.fsw.options.followSymlinks;
34140
- let closer;
34141
- if (stats.isDirectory()) {
34142
- const absPath = sysPath.resolve(path25);
34143
- const targetPath = follow ? await fsrealpath(path25) : path25;
34144
- if (this.fsw.closed)
34145
- return;
34146
- closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
34147
- if (this.fsw.closed)
34148
- return;
34149
- if (absPath !== targetPath && targetPath !== void 0) {
34150
- this.fsw._symlinkPaths.set(absPath, targetPath);
34151
- }
34152
- } else if (stats.isSymbolicLink()) {
34153
- const targetPath = follow ? await fsrealpath(path25) : path25;
34154
- if (this.fsw.closed)
34155
- return;
34156
- const parent = sysPath.dirname(wh.watchPath);
34157
- this.fsw._getWatchedDir(parent).add(wh.watchPath);
34158
- this.fsw._emit(EV.ADD, wh.watchPath, stats);
34159
- closer = await this._handleDir(parent, stats, initialAdd, depth, path25, wh, targetPath);
34160
- if (this.fsw.closed)
34161
- return;
34162
- if (targetPath !== void 0) {
34163
- this.fsw._symlinkPaths.set(sysPath.resolve(path25), targetPath);
34164
- }
34165
- } else {
34166
- closer = this._handleFile(wh.watchPath, stats, initialAdd);
34167
- }
34168
- ready();
34169
- if (closer)
34170
- this.fsw._addPathCloser(path25, closer);
34171
- return false;
34172
- } catch (error40) {
34173
- if (this.fsw._handleError(error40)) {
34174
- ready();
34175
- return path25;
34176
- }
34177
- }
34178
- }
34179
- };
34180
-
34181
- // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
34182
- var SLASH = "/";
34183
- var SLASH_SLASH = "//";
34184
- var ONE_DOT = ".";
34185
- var TWO_DOTS = "..";
34186
- var STRING_TYPE = "string";
34187
- var BACK_SLASH_RE = /\\/g;
34188
- var DOUBLE_SLASH_RE = /\/\//;
34189
- var DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
34190
- var REPLACER_RE = /^\.[/\\]/;
34191
- function arrify(item) {
34192
- return Array.isArray(item) ? item : [item];
34193
- }
34194
- var isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
34195
- function createPattern(matcher) {
34196
- if (typeof matcher === "function")
34197
- return matcher;
34198
- if (typeof matcher === "string")
34199
- return (string4) => matcher === string4;
34200
- if (matcher instanceof RegExp)
34201
- return (string4) => matcher.test(string4);
34202
- if (typeof matcher === "object" && matcher !== null) {
34203
- return (string4) => {
34204
- if (matcher.path === string4)
34205
- return true;
34206
- if (matcher.recursive) {
34207
- const relative6 = sysPath2.relative(matcher.path, string4);
34208
- if (!relative6) {
34209
- return false;
34210
- }
34211
- return !relative6.startsWith("..") && !sysPath2.isAbsolute(relative6);
34212
- }
34213
- return false;
34214
- };
34215
- }
34216
- return () => false;
34217
- }
34218
- function normalizePath(path25) {
34219
- if (typeof path25 !== "string")
34220
- throw new Error("string expected");
34221
- path25 = sysPath2.normalize(path25);
34222
- path25 = path25.replace(/\\/g, "/");
34223
- let prepend = false;
34224
- if (path25.startsWith("//"))
34225
- prepend = true;
34226
- const DOUBLE_SLASH_RE2 = /\/\//;
34227
- while (path25.match(DOUBLE_SLASH_RE2))
34228
- path25 = path25.replace(DOUBLE_SLASH_RE2, "/");
34229
- if (prepend)
34230
- path25 = "/" + path25;
34231
- return path25;
34232
- }
34233
- function matchPatterns(patterns, testString, stats) {
34234
- const path25 = normalizePath(testString);
34235
- for (let index = 0; index < patterns.length; index++) {
34236
- const pattern = patterns[index];
34237
- if (pattern(path25, stats)) {
34238
- return true;
34239
- }
34240
- }
34241
- return false;
34242
- }
34243
- function anymatch(matchers, testString) {
34244
- if (matchers == null) {
34245
- throw new TypeError("anymatch: specify first argument");
34246
- }
34247
- const matchersArray = arrify(matchers);
34248
- const patterns = matchersArray.map((matcher) => createPattern(matcher));
34249
- if (testString == null) {
34250
- return (testString2, stats) => {
34251
- return matchPatterns(patterns, testString2, stats);
34252
- };
34253
- }
34254
- return matchPatterns(patterns, testString);
34255
- }
34256
- var unifyPaths = (paths_) => {
34257
- const paths = arrify(paths_).flat();
34258
- if (!paths.every((p) => typeof p === STRING_TYPE)) {
34259
- throw new TypeError(`Non-string provided as watch path: ${paths}`);
34260
- }
34261
- return paths.map(normalizePathToUnix);
34262
- };
34263
- var toUnix = (string4) => {
34264
- let str = string4.replace(BACK_SLASH_RE, SLASH);
34265
- let prepend = false;
34266
- if (str.startsWith(SLASH_SLASH)) {
34267
- prepend = true;
34268
- }
34269
- while (str.match(DOUBLE_SLASH_RE)) {
34270
- str = str.replace(DOUBLE_SLASH_RE, SLASH);
34271
- }
34272
- if (prepend) {
34273
- str = SLASH + str;
34274
- }
34275
- return str;
34276
- };
34277
- var normalizePathToUnix = (path25) => toUnix(sysPath2.normalize(toUnix(path25)));
34278
- var normalizeIgnored = (cwd3 = "") => (path25) => {
34279
- if (typeof path25 === "string") {
34280
- return normalizePathToUnix(sysPath2.isAbsolute(path25) ? path25 : sysPath2.join(cwd3, path25));
34281
- } else {
34282
- return path25;
34283
- }
34284
- };
34285
- var getAbsolutePath = (path25, cwd3) => {
34286
- if (sysPath2.isAbsolute(path25)) {
34287
- return path25;
34288
- }
34289
- return sysPath2.join(cwd3, path25);
34290
- };
34291
- var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
34292
- var DirEntry = class {
34293
- constructor(dir, removeWatcher) {
34294
- this.path = dir;
34295
- this._removeWatcher = removeWatcher;
34296
- this.items = /* @__PURE__ */ new Set();
34297
- }
34298
- add(item) {
34299
- const { items } = this;
34300
- if (!items)
34301
- return;
34302
- if (item !== ONE_DOT && item !== TWO_DOTS)
34303
- items.add(item);
34304
- }
34305
- async remove(item) {
34306
- const { items } = this;
34307
- if (!items)
34308
- return;
34309
- items.delete(item);
34310
- if (items.size > 0)
34311
- return;
34312
- const dir = this.path;
34313
- try {
34314
- await readdir2(dir);
34315
- } catch (err) {
34316
- if (this._removeWatcher) {
34317
- this._removeWatcher(sysPath2.dirname(dir), sysPath2.basename(dir));
34318
- }
34319
- }
34320
- }
34321
- has(item) {
34322
- const { items } = this;
34323
- if (!items)
34324
- return;
34325
- return items.has(item);
34326
- }
34327
- getChildren() {
34328
- const { items } = this;
34329
- if (!items)
34330
- return [];
34331
- return [...items.values()];
34332
- }
34333
- dispose() {
34334
- this.items.clear();
34335
- this.path = "";
34336
- this._removeWatcher = EMPTY_FN;
34337
- this.items = EMPTY_SET;
34338
- Object.freeze(this);
34339
- }
34340
- };
34341
- var STAT_METHOD_F = "stat";
34342
- var STAT_METHOD_L = "lstat";
34343
- var WatchHelper = class {
34344
- constructor(path25, follow, fsw) {
34345
- this.fsw = fsw;
34346
- const watchPath = path25;
34347
- this.path = path25 = path25.replace(REPLACER_RE, "");
34348
- this.watchPath = watchPath;
34349
- this.fullWatchPath = sysPath2.resolve(watchPath);
34350
- this.dirParts = [];
34351
- this.dirParts.forEach((parts) => {
34352
- if (parts.length > 1)
34353
- parts.pop();
34354
- });
34355
- this.followSymlinks = follow;
34356
- this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
34357
- }
34358
- entryPath(entry) {
34359
- return sysPath2.join(this.watchPath, sysPath2.relative(this.watchPath, entry.fullPath));
34360
- }
34361
- filterPath(entry) {
34362
- const { stats } = entry;
34363
- if (stats && stats.isSymbolicLink())
34364
- return this.filterDir(entry);
34365
- const resolvedPath = this.entryPath(entry);
34366
- return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
34367
- }
34368
- filterDir(entry) {
34369
- return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
34370
- }
34371
- };
34372
- var FSWatcher = class extends EventEmitter2 {
34373
- // Not indenting methods for history sake; for now.
34374
- constructor(_opts = {}) {
34375
- super();
34376
- this.closed = false;
34377
- this._closers = /* @__PURE__ */ new Map();
34378
- this._ignoredPaths = /* @__PURE__ */ new Set();
34379
- this._throttled = /* @__PURE__ */ new Map();
34380
- this._streams = /* @__PURE__ */ new Set();
34381
- this._symlinkPaths = /* @__PURE__ */ new Map();
34382
- this._watched = /* @__PURE__ */ new Map();
34383
- this._pendingWrites = /* @__PURE__ */ new Map();
34384
- this._pendingUnlinks = /* @__PURE__ */ new Map();
34385
- this._readyCount = 0;
34386
- this._readyEmitted = false;
34387
- const awf = _opts.awaitWriteFinish;
34388
- const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
34389
- const opts = {
34390
- // Defaults
34391
- persistent: true,
34392
- ignoreInitial: false,
34393
- ignorePermissionErrors: false,
34394
- interval: 100,
34395
- binaryInterval: 300,
34396
- followSymlinks: true,
34397
- usePolling: false,
34398
- // useAsync: false,
34399
- atomic: true,
34400
- // NOTE: overwritten later (depends on usePolling)
34401
- ..._opts,
34402
- // Change format
34403
- ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
34404
- awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
34405
- };
34406
- if (isIBMi)
34407
- opts.usePolling = true;
34408
- if (opts.atomic === void 0)
34409
- opts.atomic = !opts.usePolling;
34410
- const envPoll = process.env.CHOKIDAR_USEPOLLING;
34411
- if (envPoll !== void 0) {
34412
- const envLower = envPoll.toLowerCase();
34413
- if (envLower === "false" || envLower === "0")
34414
- opts.usePolling = false;
34415
- else if (envLower === "true" || envLower === "1")
34416
- opts.usePolling = true;
34417
- else
34418
- opts.usePolling = !!envLower;
34419
- }
34420
- const envInterval = process.env.CHOKIDAR_INTERVAL;
34421
- if (envInterval)
34422
- opts.interval = Number.parseInt(envInterval, 10);
34423
- let readyCalls = 0;
34424
- this._emitReady = () => {
34425
- readyCalls++;
34426
- if (readyCalls >= this._readyCount) {
34427
- this._emitReady = EMPTY_FN;
34428
- this._readyEmitted = true;
34429
- process.nextTick(() => this.emit(EVENTS.READY));
34430
- }
34431
- };
34432
- this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
34433
- this._boundRemove = this._remove.bind(this);
34434
- this.options = opts;
34435
- this._nodeFsHandler = new NodeFsHandler(this);
34436
- Object.freeze(opts);
34437
- }
34438
- _addIgnoredPath(matcher) {
34439
- if (isMatcherObject(matcher)) {
34440
- for (const ignored of this._ignoredPaths) {
34441
- if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
34442
- return;
34443
- }
34444
- }
34445
- }
34446
- this._ignoredPaths.add(matcher);
34447
- }
34448
- _removeIgnoredPath(matcher) {
34449
- this._ignoredPaths.delete(matcher);
34450
- if (typeof matcher === "string") {
34451
- for (const ignored of this._ignoredPaths) {
34452
- if (isMatcherObject(ignored) && ignored.path === matcher) {
34453
- this._ignoredPaths.delete(ignored);
34454
- }
34455
- }
34456
- }
34457
- }
34458
- // Public methods
34459
- /**
34460
- * Adds paths to be watched on an existing FSWatcher instance.
34461
- * @param paths_ file or file list. Other arguments are unused
34462
- */
34463
- add(paths_, _origAdd, _internal) {
34464
- const { cwd: cwd3 } = this.options;
34465
- this.closed = false;
34466
- this._closePromise = void 0;
34467
- let paths = unifyPaths(paths_);
34468
- if (cwd3) {
34469
- paths = paths.map((path25) => {
34470
- const absPath = getAbsolutePath(path25, cwd3);
34471
- return absPath;
34472
- });
34473
- }
34474
- paths.forEach((path25) => {
34475
- this._removeIgnoredPath(path25);
34476
- });
34477
- this._userIgnored = void 0;
34478
- if (!this._readyCount)
34479
- this._readyCount = 0;
34480
- this._readyCount += paths.length;
34481
- Promise.all(paths.map(async (path25) => {
34482
- const res = await this._nodeFsHandler._addToNodeFs(path25, !_internal, void 0, 0, _origAdd);
34483
- if (res)
34484
- this._emitReady();
34485
- return res;
34486
- })).then((results) => {
34487
- if (this.closed)
34488
- return;
34489
- results.forEach((item) => {
34490
- if (item)
34491
- this.add(sysPath2.dirname(item), sysPath2.basename(_origAdd || item));
34492
- });
34493
- });
34494
- return this;
34495
- }
34496
- /**
34497
- * Close watchers or start ignoring events from specified paths.
34498
- */
34499
- unwatch(paths_) {
34500
- if (this.closed)
34501
- return this;
34502
- const paths = unifyPaths(paths_);
34503
- const { cwd: cwd3 } = this.options;
34504
- paths.forEach((path25) => {
34505
- if (!sysPath2.isAbsolute(path25) && !this._closers.has(path25)) {
34506
- if (cwd3)
34507
- path25 = sysPath2.join(cwd3, path25);
34508
- path25 = sysPath2.resolve(path25);
34509
- }
34510
- this._closePath(path25);
34511
- this._addIgnoredPath(path25);
34512
- if (this._watched.has(path25)) {
34513
- this._addIgnoredPath({
34514
- path: path25,
34515
- recursive: true
34516
- });
34517
- }
34518
- this._userIgnored = void 0;
34519
- });
34520
- return this;
34521
- }
34522
- /**
34523
- * Close watchers and remove all listeners from watched paths.
34524
- */
34525
- close() {
34526
- if (this._closePromise) {
34527
- return this._closePromise;
34528
- }
34529
- this.closed = true;
34530
- this.removeAllListeners();
34531
- const closers = [];
34532
- this._closers.forEach((closerList) => closerList.forEach((closer) => {
34533
- const promise2 = closer();
34534
- if (promise2 instanceof Promise)
34535
- closers.push(promise2);
34536
- }));
34537
- this._streams.forEach((stream) => stream.destroy());
34538
- this._userIgnored = void 0;
34539
- this._readyCount = 0;
34540
- this._readyEmitted = false;
34541
- this._watched.forEach((dirent) => dirent.dispose());
34542
- this._closers.clear();
34543
- this._watched.clear();
34544
- this._streams.clear();
34545
- this._symlinkPaths.clear();
34546
- this._throttled.clear();
34547
- this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
34548
- return this._closePromise;
34549
- }
34550
- /**
34551
- * Expose list of watched paths
34552
- * @returns for chaining
34553
- */
34554
- getWatched() {
34555
- const watchList = {};
34556
- this._watched.forEach((entry, dir) => {
34557
- const key = this.options.cwd ? sysPath2.relative(this.options.cwd, dir) : dir;
34558
- const index = key || ONE_DOT;
34559
- watchList[index] = entry.getChildren().sort();
34560
- });
34561
- return watchList;
34562
- }
34563
- emitWithAll(event, args) {
34564
- this.emit(event, ...args);
34565
- if (event !== EVENTS.ERROR)
34566
- this.emit(EVENTS.ALL, event, ...args);
34567
- }
34568
- // Common helpers
34569
- // --------------
34570
- /**
34571
- * Normalize and emit events.
34572
- * Calling _emit DOES NOT MEAN emit() would be called!
34573
- * @param event Type of event
34574
- * @param path File or directory path
34575
- * @param stats arguments to be passed with event
34576
- * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
34577
- */
34578
- async _emit(event, path25, stats) {
34579
- if (this.closed)
34580
- return;
34581
- const opts = this.options;
34582
- if (isWindows)
34583
- path25 = sysPath2.normalize(path25);
34584
- if (opts.cwd)
34585
- path25 = sysPath2.relative(opts.cwd, path25);
34586
- const args = [path25];
34587
- if (stats != null)
34588
- args.push(stats);
34589
- const awf = opts.awaitWriteFinish;
34590
- let pw;
34591
- if (awf && (pw = this._pendingWrites.get(path25))) {
34592
- pw.lastChange = /* @__PURE__ */ new Date();
34593
- return this;
34594
- }
34595
- if (opts.atomic) {
34596
- if (event === EVENTS.UNLINK) {
34597
- this._pendingUnlinks.set(path25, [event, ...args]);
34598
- setTimeout(() => {
34599
- this._pendingUnlinks.forEach((entry, path26) => {
34600
- this.emit(...entry);
34601
- this.emit(EVENTS.ALL, ...entry);
34602
- this._pendingUnlinks.delete(path26);
34603
- });
34604
- }, typeof opts.atomic === "number" ? opts.atomic : 100);
34605
- return this;
34606
- }
34607
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path25)) {
34608
- event = EVENTS.CHANGE;
34609
- this._pendingUnlinks.delete(path25);
34610
- }
34611
- }
34612
- if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
34613
- const awfEmit = (err, stats2) => {
34614
- if (err) {
34615
- event = EVENTS.ERROR;
34616
- args[0] = err;
34617
- this.emitWithAll(event, args);
34618
- } else if (stats2) {
34619
- if (args.length > 1) {
34620
- args[1] = stats2;
34621
- } else {
34622
- args.push(stats2);
34623
- }
34624
- this.emitWithAll(event, args);
34625
- }
34626
- };
34627
- this._awaitWriteFinish(path25, awf.stabilityThreshold, event, awfEmit);
34628
- return this;
34629
- }
34630
- if (event === EVENTS.CHANGE) {
34631
- const isThrottled = !this._throttle(EVENTS.CHANGE, path25, 50);
34632
- if (isThrottled)
34633
- return this;
34634
- }
34635
- if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
34636
- const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path25) : path25;
34637
- let stats2;
34638
- try {
34639
- stats2 = await stat3(fullPath);
34640
- } catch (err) {
34641
- }
34642
- if (!stats2 || this.closed)
34643
- return;
34644
- args.push(stats2);
34645
- }
34646
- this.emitWithAll(event, args);
34647
- return this;
34648
- }
34649
- /**
34650
- * Common handler for errors
34651
- * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
34652
- */
34653
- _handleError(error40) {
34654
- const code = error40 && error40.code;
34655
- if (error40 && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
34656
- this.emit(EVENTS.ERROR, error40);
34657
- }
34658
- return error40 || this.closed;
34659
- }
34660
- /**
34661
- * Helper utility for throttling
34662
- * @param actionType type being throttled
34663
- * @param path being acted upon
34664
- * @param timeout duration of time to suppress duplicate actions
34665
- * @returns tracking object or false if action should be suppressed
34666
- */
34667
- _throttle(actionType, path25, timeout) {
34668
- if (!this._throttled.has(actionType)) {
34669
- this._throttled.set(actionType, /* @__PURE__ */ new Map());
34670
- }
34671
- const action = this._throttled.get(actionType);
34672
- if (!action)
34673
- throw new Error("invalid throttle");
34674
- const actionPath = action.get(path25);
34675
- if (actionPath) {
34676
- actionPath.count++;
34677
- return false;
34678
- }
34679
- let timeoutObject;
34680
- const clear = () => {
34681
- const item = action.get(path25);
34682
- const count = item ? item.count : 0;
34683
- action.delete(path25);
34684
- clearTimeout(timeoutObject);
34685
- if (item)
34686
- clearTimeout(item.timeoutObject);
34687
- return count;
34688
- };
34689
- timeoutObject = setTimeout(clear, timeout);
34690
- const thr = { timeoutObject, clear, count: 0 };
34691
- action.set(path25, thr);
34692
- return thr;
34693
- }
34694
- _incrReadyCount() {
34695
- return this._readyCount++;
34696
- }
34697
- /**
34698
- * Awaits write operation to finish.
34699
- * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
34700
- * @param path being acted upon
34701
- * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
34702
- * @param event
34703
- * @param awfEmit Callback to be called when ready for event to be emitted.
34704
- */
34705
- _awaitWriteFinish(path25, threshold, event, awfEmit) {
34706
- const awf = this.options.awaitWriteFinish;
34707
- if (typeof awf !== "object")
34708
- return;
34709
- const pollInterval = awf.pollInterval;
34710
- let timeoutHandler;
34711
- let fullPath = path25;
34712
- if (this.options.cwd && !sysPath2.isAbsolute(path25)) {
34713
- fullPath = sysPath2.join(this.options.cwd, path25);
34714
- }
34715
- const now = /* @__PURE__ */ new Date();
34716
- const writes = this._pendingWrites;
34717
- function awaitWriteFinishFn(prevStat) {
34718
- statcb(fullPath, (err, curStat) => {
34719
- if (err || !writes.has(path25)) {
34720
- if (err && err.code !== "ENOENT")
34721
- awfEmit(err);
34722
- return;
34723
- }
34724
- const now2 = Number(/* @__PURE__ */ new Date());
34725
- if (prevStat && curStat.size !== prevStat.size) {
34726
- writes.get(path25).lastChange = now2;
34727
- }
34728
- const pw = writes.get(path25);
34729
- const df = now2 - pw.lastChange;
34730
- if (df >= threshold) {
34731
- writes.delete(path25);
34732
- awfEmit(void 0, curStat);
34733
- } else {
34734
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
34735
- }
34736
- });
34737
- }
34738
- if (!writes.has(path25)) {
34739
- writes.set(path25, {
34740
- lastChange: now,
34741
- cancelWait: () => {
34742
- writes.delete(path25);
34743
- clearTimeout(timeoutHandler);
34744
- return event;
34745
- }
34746
- });
34747
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
34748
- }
34749
- }
34750
- /**
34751
- * Determines whether user has asked to ignore this path.
34752
- */
34753
- _isIgnored(path25, stats) {
34754
- if (this.options.atomic && DOT_RE.test(path25))
34755
- return true;
34756
- if (!this._userIgnored) {
34757
- const { cwd: cwd3 } = this.options;
34758
- const ign = this.options.ignored;
34759
- const ignored = (ign || []).map(normalizeIgnored(cwd3));
34760
- const ignoredPaths = [...this._ignoredPaths];
34761
- const list = [...ignoredPaths.map(normalizeIgnored(cwd3)), ...ignored];
34762
- this._userIgnored = anymatch(list, void 0);
34763
- }
34764
- return this._userIgnored(path25, stats);
34765
- }
34766
- _isntIgnored(path25, stat4) {
34767
- return !this._isIgnored(path25, stat4);
34768
- }
34769
- /**
34770
- * Provides a set of common helpers and properties relating to symlink handling.
34771
- * @param path file or directory pattern being watched
34772
- */
34773
- _getWatchHelpers(path25) {
34774
- return new WatchHelper(path25, this.options.followSymlinks, this);
34775
- }
34776
- // Directory helpers
34777
- // -----------------
34778
- /**
34779
- * Provides directory tracking objects
34780
- * @param directory path of the directory
34781
- */
34782
- _getWatchedDir(directory) {
34783
- const dir = sysPath2.resolve(directory);
34784
- if (!this._watched.has(dir))
34785
- this._watched.set(dir, new DirEntry(dir, this._boundRemove));
34786
- return this._watched.get(dir);
34787
- }
34788
- // File helpers
34789
- // ------------
34790
- /**
34791
- * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
34792
- */
34793
- _hasReadPermissions(stats) {
34794
- if (this.options.ignorePermissionErrors)
34795
- return true;
34796
- return Boolean(Number(stats.mode) & 256);
34797
- }
34798
- /**
34799
- * Handles emitting unlink events for
34800
- * files and directories, and via recursion, for
34801
- * files and directories within directories that are unlinked
34802
- * @param directory within which the following item is located
34803
- * @param item base path of item/directory
34804
- */
34805
- _remove(directory, item, isDirectory) {
34806
- const path25 = sysPath2.join(directory, item);
34807
- const fullPath = sysPath2.resolve(path25);
34808
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path25) || this._watched.has(fullPath);
34809
- if (!this._throttle("remove", path25, 100))
34810
- return;
34811
- if (!isDirectory && this._watched.size === 1) {
34812
- this.add(directory, item, true);
34813
- }
34814
- const wp = this._getWatchedDir(path25);
34815
- const nestedDirectoryChildren = wp.getChildren();
34816
- nestedDirectoryChildren.forEach((nested) => this._remove(path25, nested));
34817
- const parent = this._getWatchedDir(directory);
34818
- const wasTracked = parent.has(item);
34819
- parent.remove(item);
34820
- if (this._symlinkPaths.has(fullPath)) {
34821
- this._symlinkPaths.delete(fullPath);
34822
- }
34823
- let relPath = path25;
34824
- if (this.options.cwd)
34825
- relPath = sysPath2.relative(this.options.cwd, path25);
34826
- if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
34827
- const event = this._pendingWrites.get(relPath).cancelWait();
34828
- if (event === EVENTS.ADD)
34829
- return;
34830
- }
34831
- this._watched.delete(path25);
34832
- this._watched.delete(fullPath);
34833
- const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
34834
- if (wasTracked && !this._isIgnored(path25))
34835
- this._emit(eventName, path25);
34836
- this._closePath(path25);
34837
- }
34838
- /**
34839
- * Closes all watchers for a path
34840
- */
34841
- _closePath(path25) {
34842
- this._closeFile(path25);
34843
- const dir = sysPath2.dirname(path25);
34844
- this._getWatchedDir(dir).remove(sysPath2.basename(path25));
34845
- }
34846
- /**
34847
- * Closes only file-specific watchers
34848
- */
34849
- _closeFile(path25) {
34850
- const closers = this._closers.get(path25);
34851
- if (!closers)
34852
- return;
34853
- closers.forEach((closer) => closer());
34854
- this._closers.delete(path25);
34855
- }
34856
- _addPathCloser(path25, closer) {
34857
- if (!closer)
34858
- return;
34859
- let list = this._closers.get(path25);
34860
- if (!list) {
34861
- list = [];
34862
- this._closers.set(path25, list);
34863
- }
34864
- list.push(closer);
34865
- }
34866
- _readdirp(root, opts) {
34867
- if (this.closed)
34868
- return;
34869
- const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
34870
- let stream = readdirp(root, options);
34871
- this._streams.add(stream);
34872
- stream.once(STR_CLOSE, () => {
34873
- stream = void 0;
34874
- });
34875
- stream.once(STR_END, () => {
34876
- if (stream) {
34877
- this._streams.delete(stream);
34878
- stream = void 0;
34879
- }
34880
- });
34881
- return stream;
34882
- }
34883
- };
34884
- function watch(paths, options = {}) {
34885
- const watcher = new FSWatcher(options);
34886
- watcher.add(paths);
34887
- return watcher;
34888
- }
34889
- var esm_default = { watch, FSWatcher };
34890
-
34891
- // src/files/watch-file-index.ts
34892
33200
  var DEBOUNCE_MS = 900;
34893
33201
  function shouldIgnoreRelative(rel) {
34894
33202
  const n = rel.replace(/\\/g, "/");
@@ -34897,8 +33205,43 @@ function shouldIgnoreRelative(rel) {
34897
33205
  if (n.includes("/.buildautomaton/") || n.startsWith(".buildautomaton/")) return true;
34898
33206
  return false;
34899
33207
  }
33208
+ function attachWatchErrorLog(w) {
33209
+ w.on("error", (err) => {
33210
+ console.error("[file-index] fs.watch error:", err);
33211
+ });
33212
+ }
33213
+ function createFsWatcher(resolved, schedule) {
33214
+ const onEvent = (_event, filename) => {
33215
+ if (filename != null) {
33216
+ const rel = typeof filename === "string" ? filename.replace(/\\/g, "/") : filename.toString("utf8").replace(/\\/g, "/");
33217
+ if (shouldIgnoreRelative(rel)) return;
33218
+ }
33219
+ schedule();
33220
+ };
33221
+ try {
33222
+ const w = watch(resolved, { recursive: true }, onEvent);
33223
+ attachWatchErrorLog(w);
33224
+ return w;
33225
+ } catch (e) {
33226
+ const code = typeof e === "object" && e !== null && "code" in e ? e.code : void 0;
33227
+ if (code === "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM") {
33228
+ console.warn(
33229
+ "[file-index] fs.watch recursive unavailable here; using non-recursive watch (Node 20+ on Linux enables recursive). Nested file changes may be missed until upgrade."
33230
+ );
33231
+ const w = watch(resolved, { recursive: false }, onEvent);
33232
+ attachWatchErrorLog(w);
33233
+ return w;
33234
+ }
33235
+ throw e;
33236
+ }
33237
+ }
34900
33238
  function startFileIndexWatcher(cwd3 = process.cwd()) {
34901
33239
  const resolved = path21.resolve(cwd3);
33240
+ try {
33241
+ buildFileIndex(resolved);
33242
+ } catch (e) {
33243
+ console.error("[file-index] Initial index build failed:", e);
33244
+ }
34902
33245
  let timer = null;
34903
33246
  const runRebuild = () => {
34904
33247
  try {
@@ -34914,27 +33257,13 @@ function startFileIndexWatcher(cwd3 = process.cwd()) {
34914
33257
  runRebuild();
34915
33258
  }, DEBOUNCE_MS);
34916
33259
  };
34917
- const watcher = esm_default.watch(".", {
34918
- cwd: resolved,
34919
- ignoreInitial: true,
34920
- persistent: true,
34921
- ignored: (p) => {
34922
- const rel = path21.isAbsolute(p) ? path21.relative(resolved, p).replace(/\\/g, "/") : p.replace(/\\/g, "/");
34923
- return shouldIgnoreRelative(rel || ".");
34924
- },
34925
- awaitWriteFinish: { stabilityThreshold: 250, pollInterval: 100 }
34926
- });
34927
- watcher.on("add", schedule);
34928
- watcher.on("change", schedule);
34929
- watcher.on("unlink", schedule);
34930
- watcher.on("addDir", schedule);
34931
- watcher.on("unlinkDir", schedule);
33260
+ const watcher = createFsWatcher(resolved, schedule);
34932
33261
  return () => {
34933
33262
  if (timer) {
34934
33263
  clearTimeout(timer);
34935
33264
  timer = null;
34936
33265
  }
34937
- void watcher.close();
33266
+ watcher.close();
34938
33267
  };
34939
33268
  }
34940
33269
 
@@ -34958,15 +33287,15 @@ function sendDevServerStatus(getWs, serverId, status, options) {
34958
33287
 
34959
33288
  // src/dev-servers/process/terminate-child-process.ts
34960
33289
  async function sigtermAndWaitForExit(proc, graceMs, log2, shortId) {
34961
- const exited = new Promise((resolve17) => {
34962
- proc.once("exit", () => resolve17());
33290
+ const exited = new Promise((resolve15) => {
33291
+ proc.once("exit", () => resolve15());
34963
33292
  });
34964
33293
  log2(`[dev-server] Sending SIGTERM to ${shortId} (pid=${proc.pid ?? "?"})\u2026`);
34965
33294
  try {
34966
33295
  proc.kill("SIGTERM");
34967
33296
  } catch {
34968
33297
  }
34969
- await Promise.race([exited, new Promise((resolve17) => setTimeout(resolve17, graceMs))]);
33298
+ await Promise.race([exited, new Promise((resolve15) => setTimeout(resolve15, graceMs))]);
34970
33299
  }
34971
33300
  function forceKillChild(proc, log2, shortId, graceMs) {
34972
33301
  log2(`[dev-server] ${shortId} did not exit within ${graceMs}ms; sending SIGKILL (pid=${proc.pid ?? "?"})\u2026`);
@@ -35750,7 +34079,7 @@ async function proxyToLocal(request) {
35750
34079
  path: url2.pathname + url2.search,
35751
34080
  headers: request.headers
35752
34081
  };
35753
- return new Promise((resolve17) => {
34082
+ return new Promise((resolve15) => {
35754
34083
  const req = mod.request(opts, (res) => {
35755
34084
  const chunks = [];
35756
34085
  res.on("data", (c) => chunks.push(c));
@@ -35761,7 +34090,7 @@ async function proxyToLocal(request) {
35761
34090
  if (typeof v === "string") headers[k] = v;
35762
34091
  else if (Array.isArray(v) && v[0]) headers[k] = v[0];
35763
34092
  }
35764
- resolve17({
34093
+ resolve15({
35765
34094
  id: request.id,
35766
34095
  statusCode: res.statusCode ?? 0,
35767
34096
  headers,
@@ -35770,7 +34099,7 @@ async function proxyToLocal(request) {
35770
34099
  });
35771
34100
  });
35772
34101
  req.on("error", (err) => {
35773
- resolve17({
34102
+ resolve15({
35774
34103
  id: request.id,
35775
34104
  statusCode: 0,
35776
34105
  headers: {},
@@ -36468,9 +34797,4 @@ main().catch((err) => {
36468
34797
  console.error(err);
36469
34798
  process.exit(1);
36470
34799
  });
36471
- /*! Bundled license information:
36472
-
36473
- chokidar/esm/index.js:
36474
- (*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
36475
- */
36476
34800
  //# sourceMappingURL=cli.js.map