@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/index.js CHANGED
@@ -2235,13 +2235,13 @@ var require_extension = __commonJS({
2235
2235
  var require_websocket = __commonJS({
2236
2236
  "../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js"(exports, module) {
2237
2237
  "use strict";
2238
- var EventEmitter3 = __require("events");
2238
+ var EventEmitter2 = __require("events");
2239
2239
  var https3 = __require("https");
2240
2240
  var http = __require("http");
2241
2241
  var net = __require("net");
2242
2242
  var tls = __require("tls");
2243
2243
  var { randomBytes, createHash: createHash2 } = __require("crypto");
2244
- var { Duplex, Readable: Readable3 } = __require("stream");
2244
+ var { Duplex, Readable: Readable2 } = __require("stream");
2245
2245
  var { URL: URL2 } = __require("url");
2246
2246
  var PerMessageDeflate = require_permessage_deflate();
2247
2247
  var Receiver2 = require_receiver();
@@ -2267,7 +2267,7 @@ var require_websocket = __commonJS({
2267
2267
  var protocolVersions = [8, 13];
2268
2268
  var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2269
2269
  var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2270
- var WebSocket2 = class _WebSocket extends EventEmitter3 {
2270
+ var WebSocket2 = class _WebSocket extends EventEmitter2 {
2271
2271
  /**
2272
2272
  * Create a new `WebSocket`.
2273
2273
  *
@@ -3179,7 +3179,7 @@ var require_stream = __commonJS({
3179
3179
  };
3180
3180
  duplex._final = function(callback) {
3181
3181
  if (ws.readyState === ws.CONNECTING) {
3182
- ws.once("open", function open2() {
3182
+ ws.once("open", function open() {
3183
3183
  duplex._final(callback);
3184
3184
  });
3185
3185
  return;
@@ -3200,7 +3200,7 @@ var require_stream = __commonJS({
3200
3200
  };
3201
3201
  duplex._write = function(chunk, encoding, callback) {
3202
3202
  if (ws.readyState === ws.CONNECTING) {
3203
- ws.once("open", function open2() {
3203
+ ws.once("open", function open() {
3204
3204
  duplex._write(chunk, encoding, callback);
3205
3205
  });
3206
3206
  return;
@@ -3264,7 +3264,7 @@ var require_subprotocol = __commonJS({
3264
3264
  var require_websocket_server = __commonJS({
3265
3265
  "../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js"(exports, module) {
3266
3266
  "use strict";
3267
- var EventEmitter3 = __require("events");
3267
+ var EventEmitter2 = __require("events");
3268
3268
  var http = __require("http");
3269
3269
  var { Duplex } = __require("stream");
3270
3270
  var { createHash: createHash2 } = __require("crypto");
@@ -3277,7 +3277,7 @@ var require_websocket_server = __commonJS({
3277
3277
  var RUNNING = 0;
3278
3278
  var CLOSING = 1;
3279
3279
  var CLOSED = 2;
3280
- var WebSocketServer2 = class extends EventEmitter3 {
3280
+ var WebSocketServer2 = class extends EventEmitter2 {
3281
3281
  /**
3282
3282
  * Create a `WebSocketServer` instance.
3283
3283
  *
@@ -20943,8 +20943,8 @@ var init_acp = __esm({
20943
20943
  this.#requestHandler = requestHandler;
20944
20944
  this.#notificationHandler = notificationHandler;
20945
20945
  this.#stream = stream;
20946
- this.#closedPromise = new Promise((resolve16) => {
20947
- this.#abortController.signal.addEventListener("abort", () => resolve16());
20946
+ this.#closedPromise = new Promise((resolve14) => {
20947
+ this.#abortController.signal.addEventListener("abort", () => resolve14());
20948
20948
  });
20949
20949
  this.#receive();
20950
20950
  }
@@ -21093,8 +21093,8 @@ var init_acp = __esm({
21093
21093
  }
21094
21094
  async sendRequest(method, params) {
21095
21095
  const id = this.#nextRequestId++;
21096
- const responsePromise = new Promise((resolve16, reject) => {
21097
- this.#pendingResponses.set(id, { resolve: resolve16, reject });
21096
+ const responsePromise = new Promise((resolve14, reject) => {
21097
+ this.#pendingResponses.set(id, { resolve: resolve14, reject });
21098
21098
  });
21099
21099
  await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
21100
21100
  return responsePromise;
@@ -21966,12 +21966,12 @@ var require_src2 = __commonJS({
21966
21966
  function check2(path24, isFile, isDirectory) {
21967
21967
  log2(`checking %s`, path24);
21968
21968
  try {
21969
- const stat4 = fs_1.statSync(path24);
21970
- if (stat4.isFile() && isFile) {
21969
+ const stat = fs_1.statSync(path24);
21970
+ if (stat.isFile() && isFile) {
21971
21971
  log2(`[OK] path represents a file`);
21972
21972
  return true;
21973
21973
  }
21974
- if (stat4.isDirectory() && isDirectory) {
21974
+ if (stat.isDirectory() && isDirectory) {
21975
21975
  log2(`[OK] path represents a directory`);
21976
21976
  return true;
21977
21977
  }
@@ -22132,14 +22132,14 @@ function toErrorMessage(err) {
22132
22132
  async function createAcpClient(options) {
22133
22133
  const { ClientSideConnection: ClientSideConnection2, ndJsonStream: ndJsonStream2 } = await Promise.resolve().then(() => (init_acp(), acp_exports));
22134
22134
  const { command, cwd: cwd3 = process.cwd(), onSessionUpdate } = options;
22135
- const isWindows2 = process.platform === "win32";
22135
+ const isWindows = process.platform === "win32";
22136
22136
  const child = spawn(command[0], command.slice(1), {
22137
22137
  cwd: cwd3,
22138
22138
  stdio: ["pipe", "pipe", "inherit"],
22139
22139
  env: process.env,
22140
- shell: isWindows2
22140
+ shell: isWindows
22141
22141
  });
22142
- return new Promise((resolve16, reject) => {
22142
+ return new Promise((resolve14, reject) => {
22143
22143
  child.on("error", (err) => {
22144
22144
  child.kill();
22145
22145
  reject(new Error(formatSpawnError(err, command[0])));
@@ -22168,7 +22168,7 @@ async function createAcpClient(options) {
22168
22168
  });
22169
22169
  const newSessionRes = await connection.newSession({ workingDirectory: cwd3 });
22170
22170
  const sessionId = newSessionRes.sessionId;
22171
- resolve16({
22171
+ resolve14({
22172
22172
  sessionId,
22173
22173
  async sendPrompt(prompt, _options) {
22174
22174
  try {
@@ -22244,7 +22244,7 @@ async function proxyToLocal(request) {
22244
22244
  path: url2.pathname + url2.search,
22245
22245
  headers: request.headers
22246
22246
  };
22247
- return new Promise((resolve16) => {
22247
+ return new Promise((resolve14) => {
22248
22248
  const req = mod.request(opts, (res) => {
22249
22249
  const chunks = [];
22250
22250
  res.on("data", (c) => chunks.push(c));
@@ -22255,7 +22255,7 @@ async function proxyToLocal(request) {
22255
22255
  if (typeof v === "string") headers[k] = v;
22256
22256
  else if (Array.isArray(v) && v[0]) headers[k] = v[0];
22257
22257
  }
22258
- resolve16({
22258
+ resolve14({
22259
22259
  id: request.id,
22260
22260
  statusCode: res.statusCode ?? 0,
22261
22261
  headers,
@@ -22264,7 +22264,7 @@ async function proxyToLocal(request) {
22264
22264
  });
22265
22265
  });
22266
22266
  req.on("error", (err) => {
22267
- resolve16({
22267
+ resolve14({
22268
22268
  id: request.id,
22269
22269
  statusCode: 0,
22270
22270
  headers: {},
@@ -22394,11 +22394,11 @@ var previewSkill = {
22394
22394
  const port = params.port ?? (Number(process.env[PREVIEW_PORT_ENV]) || DEFAULT_PORT);
22395
22395
  previewPort = port;
22396
22396
  previewSecret = randomSecret();
22397
- const isWindows2 = process.platform === "win32";
22397
+ const isWindows = process.platform === "win32";
22398
22398
  const parts = command.split(/\s+/);
22399
22399
  const exe = parts[0];
22400
22400
  const args = parts.slice(1);
22401
- previewProcess = spawn2(isWindows2 && exe === "npm" ? "npm.cmd" : exe, args, {
22401
+ previewProcess = spawn2(isWindows && exe === "npm" ? "npm.cmd" : exe, args, {
22402
22402
  cwd: process.cwd(),
22403
22403
  stdio: ["ignore", "pipe", "pipe"],
22404
22404
  env: {
@@ -22650,8 +22650,8 @@ function runPendingAuth(options) {
22650
22650
  let hasOpenedBrowser = false;
22651
22651
  let resolved = false;
22652
22652
  let resolveAuth;
22653
- const authPromise = new Promise((resolve16) => {
22654
- resolveAuth = resolve16;
22653
+ const authPromise = new Promise((resolve14) => {
22654
+ resolveAuth = resolve14;
22655
22655
  });
22656
22656
  function cleanup() {
22657
22657
  if (reconnectTimeout) {
@@ -27422,7 +27422,7 @@ function scheduleReconnect(state, connect, log2) {
27422
27422
  // src/bridge/connection/close-bridge-connection.ts
27423
27423
  async function closeBridgeConnection(state, acpManager, devServerManager, log2) {
27424
27424
  log2?.("Shutting down\u2026");
27425
- await new Promise((resolve16) => setImmediate(resolve16));
27425
+ await new Promise((resolve14) => setImmediate(resolve14));
27426
27426
  if (devServerManager) {
27427
27427
  log2?.("Requesting dev server processes to stop\u2026");
27428
27428
  await devServerManager.shutdownAllGraceful();
@@ -27708,14 +27708,14 @@ function sliceLinesByRange(content, line, limit) {
27708
27708
  async function createCursorAcpClient(options) {
27709
27709
  const { command, cwd: cwd3 = process.cwd(), onSessionUpdate, onRequest, onFileChange } = options;
27710
27710
  const dbgFs = process.env.BUILDAMATON_DEBUG_ACP_FS === "1";
27711
- const isWindows2 = process.platform === "win32";
27711
+ const isWindows = process.platform === "win32";
27712
27712
  const child = spawn4(command[0], command.slice(1), {
27713
27713
  cwd: cwd3,
27714
27714
  stdio: ["pipe", "pipe", "inherit"],
27715
27715
  env: process.env,
27716
- shell: isWindows2
27716
+ shell: isWindows
27717
27717
  });
27718
- return new Promise((resolve16, reject) => {
27718
+ return new Promise((resolve14, reject) => {
27719
27719
  child.on("error", (err) => {
27720
27720
  child.kill();
27721
27721
  reject(new Error(formatSpawnError2(err, command[0])));
@@ -27886,7 +27886,7 @@ async function createCursorAcpClient(options) {
27886
27886
  const newResult = await send("session/new", { cwd: cwd3, mcpServers: [] });
27887
27887
  const sessionId = newResult?.sessionId ?? "";
27888
27888
  if (!sessionId) throw new Error("Cursor ACP session/new did not return sessionId");
27889
- resolve16({
27889
+ resolve14({
27890
27890
  sessionId,
27891
27891
  async sendPrompt(prompt, _options) {
27892
27892
  promptOutputBuffer = "";
@@ -29218,8 +29218,8 @@ function resolveFilePath(relativePath) {
29218
29218
  } catch {
29219
29219
  real = resolved;
29220
29220
  }
29221
- const stat4 = fs6.statSync(real);
29222
- if (!stat4.isFile()) return { error: "Not a file" };
29221
+ const stat = fs6.statSync(real);
29222
+ if (!stat.isFile()) return { error: "Not a file" };
29223
29223
  return real;
29224
29224
  }
29225
29225
  var LINE_CHUNK_SIZE = 64 * 1024;
@@ -29384,10 +29384,10 @@ function readFile(relativePath, startLine, endLine, lineOffset, lineChunkSize =
29384
29384
  if (hasRange) {
29385
29385
  return readFileRange(result, startLine, endLine, lineOffset, lineChunkSize);
29386
29386
  }
29387
- const stat4 = fs6.statSync(result);
29387
+ const stat = fs6.statSync(result);
29388
29388
  const raw = fs6.readFileSync(result, "utf8");
29389
29389
  const lines = raw.split(/\r?\n/);
29390
- return { content: raw, totalLines: lines.length, size: stat4.size };
29390
+ return { content: raw, totalLines: lines.length, size: stat.size };
29391
29391
  } catch (err) {
29392
29392
  return { error: err instanceof Error ? err.message : String(err) };
29393
29393
  }
@@ -29448,17 +29448,17 @@ function walkDir(dir, baseDir, out) {
29448
29448
  for (const name of names) {
29449
29449
  if (name.startsWith(".")) continue;
29450
29450
  const full = path13.join(dir, name);
29451
- let stat4;
29451
+ let stat;
29452
29452
  try {
29453
- stat4 = fs7.statSync(full);
29453
+ stat = fs7.statSync(full);
29454
29454
  } catch {
29455
29455
  continue;
29456
29456
  }
29457
- const relative6 = path13.relative(baseDir, full).replace(/\\/g, "/");
29458
- if (stat4.isDirectory()) {
29457
+ const relative4 = path13.relative(baseDir, full).replace(/\\/g, "/");
29458
+ if (stat.isDirectory()) {
29459
29459
  walkDir(full, baseDir, out);
29460
- } else if (stat4.isFile()) {
29461
- out.push(relative6);
29460
+ } else if (stat.isFile()) {
29461
+ out.push(relative4);
29462
29462
  }
29463
29463
  }
29464
29464
  }
@@ -30268,1700 +30268,8 @@ async function refreshBridgeTokens(params) {
30268
30268
  }
30269
30269
 
30270
30270
  // src/files/watch-file-index.ts
30271
+ import { watch } from "node:fs";
30271
30272
  import path21 from "node:path";
30272
-
30273
- // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
30274
- import { stat as statcb } from "fs";
30275
- import { stat as stat3, readdir as readdir2 } from "fs/promises";
30276
- import { EventEmitter as EventEmitter2 } from "events";
30277
- import * as sysPath2 from "path";
30278
-
30279
- // ../../node_modules/.pnpm/readdirp@4.1.2/node_modules/readdirp/esm/index.js
30280
- import { stat, lstat, readdir, realpath } from "node:fs/promises";
30281
- import { Readable as Readable2 } from "node:stream";
30282
- import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "node:path";
30283
- var EntryTypes = {
30284
- FILE_TYPE: "files",
30285
- DIR_TYPE: "directories",
30286
- FILE_DIR_TYPE: "files_directories",
30287
- EVERYTHING_TYPE: "all"
30288
- };
30289
- var defaultOptions2 = {
30290
- root: ".",
30291
- fileFilter: (_entryInfo) => true,
30292
- directoryFilter: (_entryInfo) => true,
30293
- type: EntryTypes.FILE_TYPE,
30294
- lstat: false,
30295
- depth: 2147483648,
30296
- alwaysStat: false,
30297
- highWaterMark: 4096
30298
- };
30299
- Object.freeze(defaultOptions2);
30300
- var RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
30301
- var NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EPERM", "EACCES", "ELOOP", RECURSIVE_ERROR_CODE]);
30302
- var ALL_TYPES = [
30303
- EntryTypes.DIR_TYPE,
30304
- EntryTypes.EVERYTHING_TYPE,
30305
- EntryTypes.FILE_DIR_TYPE,
30306
- EntryTypes.FILE_TYPE
30307
- ];
30308
- var DIR_TYPES = /* @__PURE__ */ new Set([
30309
- EntryTypes.DIR_TYPE,
30310
- EntryTypes.EVERYTHING_TYPE,
30311
- EntryTypes.FILE_DIR_TYPE
30312
- ]);
30313
- var FILE_TYPES = /* @__PURE__ */ new Set([
30314
- EntryTypes.EVERYTHING_TYPE,
30315
- EntryTypes.FILE_DIR_TYPE,
30316
- EntryTypes.FILE_TYPE
30317
- ]);
30318
- var isNormalFlowError = (error40) => NORMAL_FLOW_ERRORS.has(error40.code);
30319
- var wantBigintFsStats = process.platform === "win32";
30320
- var emptyFn = (_entryInfo) => true;
30321
- var normalizeFilter = (filter) => {
30322
- if (filter === void 0)
30323
- return emptyFn;
30324
- if (typeof filter === "function")
30325
- return filter;
30326
- if (typeof filter === "string") {
30327
- const fl = filter.trim();
30328
- return (entry) => entry.basename === fl;
30329
- }
30330
- if (Array.isArray(filter)) {
30331
- const trItems = filter.map((item) => item.trim());
30332
- return (entry) => trItems.some((f) => entry.basename === f);
30333
- }
30334
- return emptyFn;
30335
- };
30336
- var ReaddirpStream = class extends Readable2 {
30337
- constructor(options = {}) {
30338
- super({
30339
- objectMode: true,
30340
- autoDestroy: true,
30341
- highWaterMark: options.highWaterMark
30342
- });
30343
- const opts = { ...defaultOptions2, ...options };
30344
- const { root, type } = opts;
30345
- this._fileFilter = normalizeFilter(opts.fileFilter);
30346
- this._directoryFilter = normalizeFilter(opts.directoryFilter);
30347
- const statMethod = opts.lstat ? lstat : stat;
30348
- if (wantBigintFsStats) {
30349
- this._stat = (path24) => statMethod(path24, { bigint: true });
30350
- } else {
30351
- this._stat = statMethod;
30352
- }
30353
- this._maxDepth = opts.depth ?? defaultOptions2.depth;
30354
- this._wantsDir = type ? DIR_TYPES.has(type) : false;
30355
- this._wantsFile = type ? FILE_TYPES.has(type) : false;
30356
- this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
30357
- this._root = presolve(root);
30358
- this._isDirent = !opts.alwaysStat;
30359
- this._statsProp = this._isDirent ? "dirent" : "stats";
30360
- this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
30361
- this.parents = [this._exploreDir(root, 1)];
30362
- this.reading = false;
30363
- this.parent = void 0;
30364
- }
30365
- async _read(batch) {
30366
- if (this.reading)
30367
- return;
30368
- this.reading = true;
30369
- try {
30370
- while (!this.destroyed && batch > 0) {
30371
- const par = this.parent;
30372
- const fil = par && par.files;
30373
- if (fil && fil.length > 0) {
30374
- const { path: path24, depth } = par;
30375
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path24));
30376
- const awaited = await Promise.all(slice);
30377
- for (const entry of awaited) {
30378
- if (!entry)
30379
- continue;
30380
- if (this.destroyed)
30381
- return;
30382
- const entryType = await this._getEntryType(entry);
30383
- if (entryType === "directory" && this._directoryFilter(entry)) {
30384
- if (depth <= this._maxDepth) {
30385
- this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
30386
- }
30387
- if (this._wantsDir) {
30388
- this.push(entry);
30389
- batch--;
30390
- }
30391
- } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
30392
- if (this._wantsFile) {
30393
- this.push(entry);
30394
- batch--;
30395
- }
30396
- }
30397
- }
30398
- } else {
30399
- const parent = this.parents.pop();
30400
- if (!parent) {
30401
- this.push(null);
30402
- break;
30403
- }
30404
- this.parent = await parent;
30405
- if (this.destroyed)
30406
- return;
30407
- }
30408
- }
30409
- } catch (error40) {
30410
- this.destroy(error40);
30411
- } finally {
30412
- this.reading = false;
30413
- }
30414
- }
30415
- async _exploreDir(path24, depth) {
30416
- let files;
30417
- try {
30418
- files = await readdir(path24, this._rdOptions);
30419
- } catch (error40) {
30420
- this._onError(error40);
30421
- }
30422
- return { files, depth, path: path24 };
30423
- }
30424
- async _formatEntry(dirent, path24) {
30425
- let entry;
30426
- const basename6 = this._isDirent ? dirent.name : dirent;
30427
- try {
30428
- const fullPath = presolve(pjoin(path24, basename6));
30429
- entry = { path: prelative(this._root, fullPath), fullPath, basename: basename6 };
30430
- entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
30431
- } catch (err) {
30432
- this._onError(err);
30433
- return;
30434
- }
30435
- return entry;
30436
- }
30437
- _onError(err) {
30438
- if (isNormalFlowError(err) && !this.destroyed) {
30439
- this.emit("warn", err);
30440
- } else {
30441
- this.destroy(err);
30442
- }
30443
- }
30444
- async _getEntryType(entry) {
30445
- if (!entry && this._statsProp in entry) {
30446
- return "";
30447
- }
30448
- const stats = entry[this._statsProp];
30449
- if (stats.isFile())
30450
- return "file";
30451
- if (stats.isDirectory())
30452
- return "directory";
30453
- if (stats && stats.isSymbolicLink()) {
30454
- const full = entry.fullPath;
30455
- try {
30456
- const entryRealPath = await realpath(full);
30457
- const entryRealPathStats = await lstat(entryRealPath);
30458
- if (entryRealPathStats.isFile()) {
30459
- return "file";
30460
- }
30461
- if (entryRealPathStats.isDirectory()) {
30462
- const len = entryRealPath.length;
30463
- if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
30464
- const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
30465
- recursiveError.code = RECURSIVE_ERROR_CODE;
30466
- return this._onError(recursiveError);
30467
- }
30468
- return "directory";
30469
- }
30470
- } catch (error40) {
30471
- this._onError(error40);
30472
- return "";
30473
- }
30474
- }
30475
- }
30476
- _includeAsFile(entry) {
30477
- const stats = entry && entry[this._statsProp];
30478
- return stats && this._wantsEverything && !stats.isDirectory();
30479
- }
30480
- };
30481
- function readdirp(root, options = {}) {
30482
- let type = options.entryType || options.type;
30483
- if (type === "both")
30484
- type = EntryTypes.FILE_DIR_TYPE;
30485
- if (type)
30486
- options.type = type;
30487
- if (!root) {
30488
- throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
30489
- } else if (typeof root !== "string") {
30490
- throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
30491
- } else if (type && !ALL_TYPES.includes(type)) {
30492
- throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
30493
- }
30494
- options.root = root;
30495
- return new ReaddirpStream(options);
30496
- }
30497
-
30498
- // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/handler.js
30499
- import { watchFile, unwatchFile, watch as fs_watch } from "fs";
30500
- import { open, stat as stat2, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
30501
- import * as sysPath from "path";
30502
- import { type as osType } from "os";
30503
- var STR_DATA = "data";
30504
- var STR_END = "end";
30505
- var STR_CLOSE = "close";
30506
- var EMPTY_FN = () => {
30507
- };
30508
- var pl = process.platform;
30509
- var isWindows = pl === "win32";
30510
- var isMacos = pl === "darwin";
30511
- var isLinux = pl === "linux";
30512
- var isFreeBSD = pl === "freebsd";
30513
- var isIBMi = osType() === "OS400";
30514
- var EVENTS = {
30515
- ALL: "all",
30516
- READY: "ready",
30517
- ADD: "add",
30518
- CHANGE: "change",
30519
- ADD_DIR: "addDir",
30520
- UNLINK: "unlink",
30521
- UNLINK_DIR: "unlinkDir",
30522
- RAW: "raw",
30523
- ERROR: "error"
30524
- };
30525
- var EV = EVENTS;
30526
- var THROTTLE_MODE_WATCH = "watch";
30527
- var statMethods = { lstat: lstat2, stat: stat2 };
30528
- var KEY_LISTENERS = "listeners";
30529
- var KEY_ERR = "errHandlers";
30530
- var KEY_RAW = "rawEmitters";
30531
- var HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
30532
- var binaryExtensions = /* @__PURE__ */ new Set([
30533
- "3dm",
30534
- "3ds",
30535
- "3g2",
30536
- "3gp",
30537
- "7z",
30538
- "a",
30539
- "aac",
30540
- "adp",
30541
- "afdesign",
30542
- "afphoto",
30543
- "afpub",
30544
- "ai",
30545
- "aif",
30546
- "aiff",
30547
- "alz",
30548
- "ape",
30549
- "apk",
30550
- "appimage",
30551
- "ar",
30552
- "arj",
30553
- "asf",
30554
- "au",
30555
- "avi",
30556
- "bak",
30557
- "baml",
30558
- "bh",
30559
- "bin",
30560
- "bk",
30561
- "bmp",
30562
- "btif",
30563
- "bz2",
30564
- "bzip2",
30565
- "cab",
30566
- "caf",
30567
- "cgm",
30568
- "class",
30569
- "cmx",
30570
- "cpio",
30571
- "cr2",
30572
- "cur",
30573
- "dat",
30574
- "dcm",
30575
- "deb",
30576
- "dex",
30577
- "djvu",
30578
- "dll",
30579
- "dmg",
30580
- "dng",
30581
- "doc",
30582
- "docm",
30583
- "docx",
30584
- "dot",
30585
- "dotm",
30586
- "dra",
30587
- "DS_Store",
30588
- "dsk",
30589
- "dts",
30590
- "dtshd",
30591
- "dvb",
30592
- "dwg",
30593
- "dxf",
30594
- "ecelp4800",
30595
- "ecelp7470",
30596
- "ecelp9600",
30597
- "egg",
30598
- "eol",
30599
- "eot",
30600
- "epub",
30601
- "exe",
30602
- "f4v",
30603
- "fbs",
30604
- "fh",
30605
- "fla",
30606
- "flac",
30607
- "flatpak",
30608
- "fli",
30609
- "flv",
30610
- "fpx",
30611
- "fst",
30612
- "fvt",
30613
- "g3",
30614
- "gh",
30615
- "gif",
30616
- "graffle",
30617
- "gz",
30618
- "gzip",
30619
- "h261",
30620
- "h263",
30621
- "h264",
30622
- "icns",
30623
- "ico",
30624
- "ief",
30625
- "img",
30626
- "ipa",
30627
- "iso",
30628
- "jar",
30629
- "jpeg",
30630
- "jpg",
30631
- "jpgv",
30632
- "jpm",
30633
- "jxr",
30634
- "key",
30635
- "ktx",
30636
- "lha",
30637
- "lib",
30638
- "lvp",
30639
- "lz",
30640
- "lzh",
30641
- "lzma",
30642
- "lzo",
30643
- "m3u",
30644
- "m4a",
30645
- "m4v",
30646
- "mar",
30647
- "mdi",
30648
- "mht",
30649
- "mid",
30650
- "midi",
30651
- "mj2",
30652
- "mka",
30653
- "mkv",
30654
- "mmr",
30655
- "mng",
30656
- "mobi",
30657
- "mov",
30658
- "movie",
30659
- "mp3",
30660
- "mp4",
30661
- "mp4a",
30662
- "mpeg",
30663
- "mpg",
30664
- "mpga",
30665
- "mxu",
30666
- "nef",
30667
- "npx",
30668
- "numbers",
30669
- "nupkg",
30670
- "o",
30671
- "odp",
30672
- "ods",
30673
- "odt",
30674
- "oga",
30675
- "ogg",
30676
- "ogv",
30677
- "otf",
30678
- "ott",
30679
- "pages",
30680
- "pbm",
30681
- "pcx",
30682
- "pdb",
30683
- "pdf",
30684
- "pea",
30685
- "pgm",
30686
- "pic",
30687
- "png",
30688
- "pnm",
30689
- "pot",
30690
- "potm",
30691
- "potx",
30692
- "ppa",
30693
- "ppam",
30694
- "ppm",
30695
- "pps",
30696
- "ppsm",
30697
- "ppsx",
30698
- "ppt",
30699
- "pptm",
30700
- "pptx",
30701
- "psd",
30702
- "pya",
30703
- "pyc",
30704
- "pyo",
30705
- "pyv",
30706
- "qt",
30707
- "rar",
30708
- "ras",
30709
- "raw",
30710
- "resources",
30711
- "rgb",
30712
- "rip",
30713
- "rlc",
30714
- "rmf",
30715
- "rmvb",
30716
- "rpm",
30717
- "rtf",
30718
- "rz",
30719
- "s3m",
30720
- "s7z",
30721
- "scpt",
30722
- "sgi",
30723
- "shar",
30724
- "snap",
30725
- "sil",
30726
- "sketch",
30727
- "slk",
30728
- "smv",
30729
- "snk",
30730
- "so",
30731
- "stl",
30732
- "suo",
30733
- "sub",
30734
- "swf",
30735
- "tar",
30736
- "tbz",
30737
- "tbz2",
30738
- "tga",
30739
- "tgz",
30740
- "thmx",
30741
- "tif",
30742
- "tiff",
30743
- "tlz",
30744
- "ttc",
30745
- "ttf",
30746
- "txz",
30747
- "udf",
30748
- "uvh",
30749
- "uvi",
30750
- "uvm",
30751
- "uvp",
30752
- "uvs",
30753
- "uvu",
30754
- "viv",
30755
- "vob",
30756
- "war",
30757
- "wav",
30758
- "wax",
30759
- "wbmp",
30760
- "wdp",
30761
- "weba",
30762
- "webm",
30763
- "webp",
30764
- "whl",
30765
- "wim",
30766
- "wm",
30767
- "wma",
30768
- "wmv",
30769
- "wmx",
30770
- "woff",
30771
- "woff2",
30772
- "wrm",
30773
- "wvx",
30774
- "xbm",
30775
- "xif",
30776
- "xla",
30777
- "xlam",
30778
- "xls",
30779
- "xlsb",
30780
- "xlsm",
30781
- "xlsx",
30782
- "xlt",
30783
- "xltm",
30784
- "xltx",
30785
- "xm",
30786
- "xmind",
30787
- "xpi",
30788
- "xpm",
30789
- "xwd",
30790
- "xz",
30791
- "z",
30792
- "zip",
30793
- "zipx"
30794
- ]);
30795
- var isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
30796
- var foreach = (val, fn) => {
30797
- if (val instanceof Set) {
30798
- val.forEach(fn);
30799
- } else {
30800
- fn(val);
30801
- }
30802
- };
30803
- var addAndConvert = (main, prop, item) => {
30804
- let container = main[prop];
30805
- if (!(container instanceof Set)) {
30806
- main[prop] = container = /* @__PURE__ */ new Set([container]);
30807
- }
30808
- container.add(item);
30809
- };
30810
- var clearItem = (cont) => (key) => {
30811
- const set2 = cont[key];
30812
- if (set2 instanceof Set) {
30813
- set2.clear();
30814
- } else {
30815
- delete cont[key];
30816
- }
30817
- };
30818
- var delFromSet = (main, prop, item) => {
30819
- const container = main[prop];
30820
- if (container instanceof Set) {
30821
- container.delete(item);
30822
- } else if (container === item) {
30823
- delete main[prop];
30824
- }
30825
- };
30826
- var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
30827
- var FsWatchInstances = /* @__PURE__ */ new Map();
30828
- function createFsWatchInstance(path24, options, listener, errHandler, emitRaw) {
30829
- const handleEvent = (rawEvent, evPath) => {
30830
- listener(path24);
30831
- emitRaw(rawEvent, evPath, { watchedPath: path24 });
30832
- if (evPath && path24 !== evPath) {
30833
- fsWatchBroadcast(sysPath.resolve(path24, evPath), KEY_LISTENERS, sysPath.join(path24, evPath));
30834
- }
30835
- };
30836
- try {
30837
- return fs_watch(path24, {
30838
- persistent: options.persistent
30839
- }, handleEvent);
30840
- } catch (error40) {
30841
- errHandler(error40);
30842
- return void 0;
30843
- }
30844
- }
30845
- var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
30846
- const cont = FsWatchInstances.get(fullPath);
30847
- if (!cont)
30848
- return;
30849
- foreach(cont[listenerType], (listener) => {
30850
- listener(val1, val2, val3);
30851
- });
30852
- };
30853
- var setFsWatchListener = (path24, fullPath, options, handlers) => {
30854
- const { listener, errHandler, rawEmitter } = handlers;
30855
- let cont = FsWatchInstances.get(fullPath);
30856
- let watcher;
30857
- if (!options.persistent) {
30858
- watcher = createFsWatchInstance(path24, options, listener, errHandler, rawEmitter);
30859
- if (!watcher)
30860
- return;
30861
- return watcher.close.bind(watcher);
30862
- }
30863
- if (cont) {
30864
- addAndConvert(cont, KEY_LISTENERS, listener);
30865
- addAndConvert(cont, KEY_ERR, errHandler);
30866
- addAndConvert(cont, KEY_RAW, rawEmitter);
30867
- } else {
30868
- watcher = createFsWatchInstance(
30869
- path24,
30870
- options,
30871
- fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
30872
- errHandler,
30873
- // no need to use broadcast here
30874
- fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
30875
- );
30876
- if (!watcher)
30877
- return;
30878
- watcher.on(EV.ERROR, async (error40) => {
30879
- const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
30880
- if (cont)
30881
- cont.watcherUnusable = true;
30882
- if (isWindows && error40.code === "EPERM") {
30883
- try {
30884
- const fd = await open(path24, "r");
30885
- await fd.close();
30886
- broadcastErr(error40);
30887
- } catch (err) {
30888
- }
30889
- } else {
30890
- broadcastErr(error40);
30891
- }
30892
- });
30893
- cont = {
30894
- listeners: listener,
30895
- errHandlers: errHandler,
30896
- rawEmitters: rawEmitter,
30897
- watcher
30898
- };
30899
- FsWatchInstances.set(fullPath, cont);
30900
- }
30901
- return () => {
30902
- delFromSet(cont, KEY_LISTENERS, listener);
30903
- delFromSet(cont, KEY_ERR, errHandler);
30904
- delFromSet(cont, KEY_RAW, rawEmitter);
30905
- if (isEmptySet(cont.listeners)) {
30906
- cont.watcher.close();
30907
- FsWatchInstances.delete(fullPath);
30908
- HANDLER_KEYS.forEach(clearItem(cont));
30909
- cont.watcher = void 0;
30910
- Object.freeze(cont);
30911
- }
30912
- };
30913
- };
30914
- var FsWatchFileInstances = /* @__PURE__ */ new Map();
30915
- var setFsWatchFileListener = (path24, fullPath, options, handlers) => {
30916
- const { listener, rawEmitter } = handlers;
30917
- let cont = FsWatchFileInstances.get(fullPath);
30918
- const copts = cont && cont.options;
30919
- if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
30920
- unwatchFile(fullPath);
30921
- cont = void 0;
30922
- }
30923
- if (cont) {
30924
- addAndConvert(cont, KEY_LISTENERS, listener);
30925
- addAndConvert(cont, KEY_RAW, rawEmitter);
30926
- } else {
30927
- cont = {
30928
- listeners: listener,
30929
- rawEmitters: rawEmitter,
30930
- options,
30931
- watcher: watchFile(fullPath, options, (curr, prev) => {
30932
- foreach(cont.rawEmitters, (rawEmitter2) => {
30933
- rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
30934
- });
30935
- const currmtime = curr.mtimeMs;
30936
- if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
30937
- foreach(cont.listeners, (listener2) => listener2(path24, curr));
30938
- }
30939
- })
30940
- };
30941
- FsWatchFileInstances.set(fullPath, cont);
30942
- }
30943
- return () => {
30944
- delFromSet(cont, KEY_LISTENERS, listener);
30945
- delFromSet(cont, KEY_RAW, rawEmitter);
30946
- if (isEmptySet(cont.listeners)) {
30947
- FsWatchFileInstances.delete(fullPath);
30948
- unwatchFile(fullPath);
30949
- cont.options = cont.watcher = void 0;
30950
- Object.freeze(cont);
30951
- }
30952
- };
30953
- };
30954
- var NodeFsHandler = class {
30955
- constructor(fsW) {
30956
- this.fsw = fsW;
30957
- this._boundHandleError = (error40) => fsW._handleError(error40);
30958
- }
30959
- /**
30960
- * Watch file for changes with fs_watchFile or fs_watch.
30961
- * @param path to file or dir
30962
- * @param listener on fs change
30963
- * @returns closer for the watcher instance
30964
- */
30965
- _watchWithNodeFs(path24, listener) {
30966
- const opts = this.fsw.options;
30967
- const directory = sysPath.dirname(path24);
30968
- const basename6 = sysPath.basename(path24);
30969
- const parent = this.fsw._getWatchedDir(directory);
30970
- parent.add(basename6);
30971
- const absolutePath = sysPath.resolve(path24);
30972
- const options = {
30973
- persistent: opts.persistent
30974
- };
30975
- if (!listener)
30976
- listener = EMPTY_FN;
30977
- let closer;
30978
- if (opts.usePolling) {
30979
- const enableBin = opts.interval !== opts.binaryInterval;
30980
- options.interval = enableBin && isBinaryPath(basename6) ? opts.binaryInterval : opts.interval;
30981
- closer = setFsWatchFileListener(path24, absolutePath, options, {
30982
- listener,
30983
- rawEmitter: this.fsw._emitRaw
30984
- });
30985
- } else {
30986
- closer = setFsWatchListener(path24, absolutePath, options, {
30987
- listener,
30988
- errHandler: this._boundHandleError,
30989
- rawEmitter: this.fsw._emitRaw
30990
- });
30991
- }
30992
- return closer;
30993
- }
30994
- /**
30995
- * Watch a file and emit add event if warranted.
30996
- * @returns closer for the watcher instance
30997
- */
30998
- _handleFile(file2, stats, initialAdd) {
30999
- if (this.fsw.closed) {
31000
- return;
31001
- }
31002
- const dirname7 = sysPath.dirname(file2);
31003
- const basename6 = sysPath.basename(file2);
31004
- const parent = this.fsw._getWatchedDir(dirname7);
31005
- let prevStats = stats;
31006
- if (parent.has(basename6))
31007
- return;
31008
- const listener = async (path24, newStats) => {
31009
- if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file2, 5))
31010
- return;
31011
- if (!newStats || newStats.mtimeMs === 0) {
31012
- try {
31013
- const newStats2 = await stat2(file2);
31014
- if (this.fsw.closed)
31015
- return;
31016
- const at = newStats2.atimeMs;
31017
- const mt = newStats2.mtimeMs;
31018
- if (!at || at <= mt || mt !== prevStats.mtimeMs) {
31019
- this.fsw._emit(EV.CHANGE, file2, newStats2);
31020
- }
31021
- if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
31022
- this.fsw._closeFile(path24);
31023
- prevStats = newStats2;
31024
- const closer2 = this._watchWithNodeFs(file2, listener);
31025
- if (closer2)
31026
- this.fsw._addPathCloser(path24, closer2);
31027
- } else {
31028
- prevStats = newStats2;
31029
- }
31030
- } catch (error40) {
31031
- this.fsw._remove(dirname7, basename6);
31032
- }
31033
- } else if (parent.has(basename6)) {
31034
- const at = newStats.atimeMs;
31035
- const mt = newStats.mtimeMs;
31036
- if (!at || at <= mt || mt !== prevStats.mtimeMs) {
31037
- this.fsw._emit(EV.CHANGE, file2, newStats);
31038
- }
31039
- prevStats = newStats;
31040
- }
31041
- };
31042
- const closer = this._watchWithNodeFs(file2, listener);
31043
- if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file2)) {
31044
- if (!this.fsw._throttle(EV.ADD, file2, 0))
31045
- return;
31046
- this.fsw._emit(EV.ADD, file2, stats);
31047
- }
31048
- return closer;
31049
- }
31050
- /**
31051
- * Handle symlinks encountered while reading a dir.
31052
- * @param entry returned by readdirp
31053
- * @param directory path of dir being read
31054
- * @param path of this item
31055
- * @param item basename of this item
31056
- * @returns true if no more processing is needed for this entry.
31057
- */
31058
- async _handleSymlink(entry, directory, path24, item) {
31059
- if (this.fsw.closed) {
31060
- return;
31061
- }
31062
- const full = entry.fullPath;
31063
- const dir = this.fsw._getWatchedDir(directory);
31064
- if (!this.fsw.options.followSymlinks) {
31065
- this.fsw._incrReadyCount();
31066
- let linkPath;
31067
- try {
31068
- linkPath = await fsrealpath(path24);
31069
- } catch (e) {
31070
- this.fsw._emitReady();
31071
- return true;
31072
- }
31073
- if (this.fsw.closed)
31074
- return;
31075
- if (dir.has(item)) {
31076
- if (this.fsw._symlinkPaths.get(full) !== linkPath) {
31077
- this.fsw._symlinkPaths.set(full, linkPath);
31078
- this.fsw._emit(EV.CHANGE, path24, entry.stats);
31079
- }
31080
- } else {
31081
- dir.add(item);
31082
- this.fsw._symlinkPaths.set(full, linkPath);
31083
- this.fsw._emit(EV.ADD, path24, entry.stats);
31084
- }
31085
- this.fsw._emitReady();
31086
- return true;
31087
- }
31088
- if (this.fsw._symlinkPaths.has(full)) {
31089
- return true;
31090
- }
31091
- this.fsw._symlinkPaths.set(full, true);
31092
- }
31093
- _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
31094
- directory = sysPath.join(directory, "");
31095
- throttler = this.fsw._throttle("readdir", directory, 1e3);
31096
- if (!throttler)
31097
- return;
31098
- const previous = this.fsw._getWatchedDir(wh.path);
31099
- const current = /* @__PURE__ */ new Set();
31100
- let stream = this.fsw._readdirp(directory, {
31101
- fileFilter: (entry) => wh.filterPath(entry),
31102
- directoryFilter: (entry) => wh.filterDir(entry)
31103
- });
31104
- if (!stream)
31105
- return;
31106
- stream.on(STR_DATA, async (entry) => {
31107
- if (this.fsw.closed) {
31108
- stream = void 0;
31109
- return;
31110
- }
31111
- const item = entry.path;
31112
- let path24 = sysPath.join(directory, item);
31113
- current.add(item);
31114
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path24, item)) {
31115
- return;
31116
- }
31117
- if (this.fsw.closed) {
31118
- stream = void 0;
31119
- return;
31120
- }
31121
- if (item === target || !target && !previous.has(item)) {
31122
- this.fsw._incrReadyCount();
31123
- path24 = sysPath.join(dir, sysPath.relative(dir, path24));
31124
- this._addToNodeFs(path24, initialAdd, wh, depth + 1);
31125
- }
31126
- }).on(EV.ERROR, this._boundHandleError);
31127
- return new Promise((resolve16, reject) => {
31128
- if (!stream)
31129
- return reject();
31130
- stream.once(STR_END, () => {
31131
- if (this.fsw.closed) {
31132
- stream = void 0;
31133
- return;
31134
- }
31135
- const wasThrottled = throttler ? throttler.clear() : false;
31136
- resolve16(void 0);
31137
- previous.getChildren().filter((item) => {
31138
- return item !== directory && !current.has(item);
31139
- }).forEach((item) => {
31140
- this.fsw._remove(directory, item);
31141
- });
31142
- stream = void 0;
31143
- if (wasThrottled)
31144
- this._handleRead(directory, false, wh, target, dir, depth, throttler);
31145
- });
31146
- });
31147
- }
31148
- /**
31149
- * Read directory to add / remove files from `@watched` list and re-read it on change.
31150
- * @param dir fs path
31151
- * @param stats
31152
- * @param initialAdd
31153
- * @param depth relative to user-supplied path
31154
- * @param target child path targeted for watch
31155
- * @param wh Common watch helpers for this path
31156
- * @param realpath
31157
- * @returns closer for the watcher instance.
31158
- */
31159
- async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath2) {
31160
- const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
31161
- const tracked = parentDir.has(sysPath.basename(dir));
31162
- if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
31163
- this.fsw._emit(EV.ADD_DIR, dir, stats);
31164
- }
31165
- parentDir.add(sysPath.basename(dir));
31166
- this.fsw._getWatchedDir(dir);
31167
- let throttler;
31168
- let closer;
31169
- const oDepth = this.fsw.options.depth;
31170
- if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath2)) {
31171
- if (!target) {
31172
- await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
31173
- if (this.fsw.closed)
31174
- return;
31175
- }
31176
- closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
31177
- if (stats2 && stats2.mtimeMs === 0)
31178
- return;
31179
- this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
31180
- });
31181
- }
31182
- return closer;
31183
- }
31184
- /**
31185
- * Handle added file, directory, or glob pattern.
31186
- * Delegates call to _handleFile / _handleDir after checks.
31187
- * @param path to file or ir
31188
- * @param initialAdd was the file added at watch instantiation?
31189
- * @param priorWh depth relative to user-supplied path
31190
- * @param depth Child path actually targeted for watch
31191
- * @param target Child path actually targeted for watch
31192
- */
31193
- async _addToNodeFs(path24, initialAdd, priorWh, depth, target) {
31194
- const ready = this.fsw._emitReady;
31195
- if (this.fsw._isIgnored(path24) || this.fsw.closed) {
31196
- ready();
31197
- return false;
31198
- }
31199
- const wh = this.fsw._getWatchHelpers(path24);
31200
- if (priorWh) {
31201
- wh.filterPath = (entry) => priorWh.filterPath(entry);
31202
- wh.filterDir = (entry) => priorWh.filterDir(entry);
31203
- }
31204
- try {
31205
- const stats = await statMethods[wh.statMethod](wh.watchPath);
31206
- if (this.fsw.closed)
31207
- return;
31208
- if (this.fsw._isIgnored(wh.watchPath, stats)) {
31209
- ready();
31210
- return false;
31211
- }
31212
- const follow = this.fsw.options.followSymlinks;
31213
- let closer;
31214
- if (stats.isDirectory()) {
31215
- const absPath = sysPath.resolve(path24);
31216
- const targetPath = follow ? await fsrealpath(path24) : path24;
31217
- if (this.fsw.closed)
31218
- return;
31219
- closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
31220
- if (this.fsw.closed)
31221
- return;
31222
- if (absPath !== targetPath && targetPath !== void 0) {
31223
- this.fsw._symlinkPaths.set(absPath, targetPath);
31224
- }
31225
- } else if (stats.isSymbolicLink()) {
31226
- const targetPath = follow ? await fsrealpath(path24) : path24;
31227
- if (this.fsw.closed)
31228
- return;
31229
- const parent = sysPath.dirname(wh.watchPath);
31230
- this.fsw._getWatchedDir(parent).add(wh.watchPath);
31231
- this.fsw._emit(EV.ADD, wh.watchPath, stats);
31232
- closer = await this._handleDir(parent, stats, initialAdd, depth, path24, wh, targetPath);
31233
- if (this.fsw.closed)
31234
- return;
31235
- if (targetPath !== void 0) {
31236
- this.fsw._symlinkPaths.set(sysPath.resolve(path24), targetPath);
31237
- }
31238
- } else {
31239
- closer = this._handleFile(wh.watchPath, stats, initialAdd);
31240
- }
31241
- ready();
31242
- if (closer)
31243
- this.fsw._addPathCloser(path24, closer);
31244
- return false;
31245
- } catch (error40) {
31246
- if (this.fsw._handleError(error40)) {
31247
- ready();
31248
- return path24;
31249
- }
31250
- }
31251
- }
31252
- };
31253
-
31254
- // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
31255
- var SLASH = "/";
31256
- var SLASH_SLASH = "//";
31257
- var ONE_DOT = ".";
31258
- var TWO_DOTS = "..";
31259
- var STRING_TYPE = "string";
31260
- var BACK_SLASH_RE = /\\/g;
31261
- var DOUBLE_SLASH_RE = /\/\//;
31262
- var DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
31263
- var REPLACER_RE = /^\.[/\\]/;
31264
- function arrify(item) {
31265
- return Array.isArray(item) ? item : [item];
31266
- }
31267
- var isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
31268
- function createPattern(matcher) {
31269
- if (typeof matcher === "function")
31270
- return matcher;
31271
- if (typeof matcher === "string")
31272
- return (string4) => matcher === string4;
31273
- if (matcher instanceof RegExp)
31274
- return (string4) => matcher.test(string4);
31275
- if (typeof matcher === "object" && matcher !== null) {
31276
- return (string4) => {
31277
- if (matcher.path === string4)
31278
- return true;
31279
- if (matcher.recursive) {
31280
- const relative6 = sysPath2.relative(matcher.path, string4);
31281
- if (!relative6) {
31282
- return false;
31283
- }
31284
- return !relative6.startsWith("..") && !sysPath2.isAbsolute(relative6);
31285
- }
31286
- return false;
31287
- };
31288
- }
31289
- return () => false;
31290
- }
31291
- function normalizePath(path24) {
31292
- if (typeof path24 !== "string")
31293
- throw new Error("string expected");
31294
- path24 = sysPath2.normalize(path24);
31295
- path24 = path24.replace(/\\/g, "/");
31296
- let prepend = false;
31297
- if (path24.startsWith("//"))
31298
- prepend = true;
31299
- const DOUBLE_SLASH_RE2 = /\/\//;
31300
- while (path24.match(DOUBLE_SLASH_RE2))
31301
- path24 = path24.replace(DOUBLE_SLASH_RE2, "/");
31302
- if (prepend)
31303
- path24 = "/" + path24;
31304
- return path24;
31305
- }
31306
- function matchPatterns(patterns, testString, stats) {
31307
- const path24 = normalizePath(testString);
31308
- for (let index = 0; index < patterns.length; index++) {
31309
- const pattern = patterns[index];
31310
- if (pattern(path24, stats)) {
31311
- return true;
31312
- }
31313
- }
31314
- return false;
31315
- }
31316
- function anymatch(matchers, testString) {
31317
- if (matchers == null) {
31318
- throw new TypeError("anymatch: specify first argument");
31319
- }
31320
- const matchersArray = arrify(matchers);
31321
- const patterns = matchersArray.map((matcher) => createPattern(matcher));
31322
- if (testString == null) {
31323
- return (testString2, stats) => {
31324
- return matchPatterns(patterns, testString2, stats);
31325
- };
31326
- }
31327
- return matchPatterns(patterns, testString);
31328
- }
31329
- var unifyPaths = (paths_) => {
31330
- const paths = arrify(paths_).flat();
31331
- if (!paths.every((p) => typeof p === STRING_TYPE)) {
31332
- throw new TypeError(`Non-string provided as watch path: ${paths}`);
31333
- }
31334
- return paths.map(normalizePathToUnix);
31335
- };
31336
- var toUnix = (string4) => {
31337
- let str = string4.replace(BACK_SLASH_RE, SLASH);
31338
- let prepend = false;
31339
- if (str.startsWith(SLASH_SLASH)) {
31340
- prepend = true;
31341
- }
31342
- while (str.match(DOUBLE_SLASH_RE)) {
31343
- str = str.replace(DOUBLE_SLASH_RE, SLASH);
31344
- }
31345
- if (prepend) {
31346
- str = SLASH + str;
31347
- }
31348
- return str;
31349
- };
31350
- var normalizePathToUnix = (path24) => toUnix(sysPath2.normalize(toUnix(path24)));
31351
- var normalizeIgnored = (cwd3 = "") => (path24) => {
31352
- if (typeof path24 === "string") {
31353
- return normalizePathToUnix(sysPath2.isAbsolute(path24) ? path24 : sysPath2.join(cwd3, path24));
31354
- } else {
31355
- return path24;
31356
- }
31357
- };
31358
- var getAbsolutePath = (path24, cwd3) => {
31359
- if (sysPath2.isAbsolute(path24)) {
31360
- return path24;
31361
- }
31362
- return sysPath2.join(cwd3, path24);
31363
- };
31364
- var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
31365
- var DirEntry = class {
31366
- constructor(dir, removeWatcher) {
31367
- this.path = dir;
31368
- this._removeWatcher = removeWatcher;
31369
- this.items = /* @__PURE__ */ new Set();
31370
- }
31371
- add(item) {
31372
- const { items } = this;
31373
- if (!items)
31374
- return;
31375
- if (item !== ONE_DOT && item !== TWO_DOTS)
31376
- items.add(item);
31377
- }
31378
- async remove(item) {
31379
- const { items } = this;
31380
- if (!items)
31381
- return;
31382
- items.delete(item);
31383
- if (items.size > 0)
31384
- return;
31385
- const dir = this.path;
31386
- try {
31387
- await readdir2(dir);
31388
- } catch (err) {
31389
- if (this._removeWatcher) {
31390
- this._removeWatcher(sysPath2.dirname(dir), sysPath2.basename(dir));
31391
- }
31392
- }
31393
- }
31394
- has(item) {
31395
- const { items } = this;
31396
- if (!items)
31397
- return;
31398
- return items.has(item);
31399
- }
31400
- getChildren() {
31401
- const { items } = this;
31402
- if (!items)
31403
- return [];
31404
- return [...items.values()];
31405
- }
31406
- dispose() {
31407
- this.items.clear();
31408
- this.path = "";
31409
- this._removeWatcher = EMPTY_FN;
31410
- this.items = EMPTY_SET;
31411
- Object.freeze(this);
31412
- }
31413
- };
31414
- var STAT_METHOD_F = "stat";
31415
- var STAT_METHOD_L = "lstat";
31416
- var WatchHelper = class {
31417
- constructor(path24, follow, fsw) {
31418
- this.fsw = fsw;
31419
- const watchPath = path24;
31420
- this.path = path24 = path24.replace(REPLACER_RE, "");
31421
- this.watchPath = watchPath;
31422
- this.fullWatchPath = sysPath2.resolve(watchPath);
31423
- this.dirParts = [];
31424
- this.dirParts.forEach((parts) => {
31425
- if (parts.length > 1)
31426
- parts.pop();
31427
- });
31428
- this.followSymlinks = follow;
31429
- this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
31430
- }
31431
- entryPath(entry) {
31432
- return sysPath2.join(this.watchPath, sysPath2.relative(this.watchPath, entry.fullPath));
31433
- }
31434
- filterPath(entry) {
31435
- const { stats } = entry;
31436
- if (stats && stats.isSymbolicLink())
31437
- return this.filterDir(entry);
31438
- const resolvedPath = this.entryPath(entry);
31439
- return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
31440
- }
31441
- filterDir(entry) {
31442
- return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
31443
- }
31444
- };
31445
- var FSWatcher = class extends EventEmitter2 {
31446
- // Not indenting methods for history sake; for now.
31447
- constructor(_opts = {}) {
31448
- super();
31449
- this.closed = false;
31450
- this._closers = /* @__PURE__ */ new Map();
31451
- this._ignoredPaths = /* @__PURE__ */ new Set();
31452
- this._throttled = /* @__PURE__ */ new Map();
31453
- this._streams = /* @__PURE__ */ new Set();
31454
- this._symlinkPaths = /* @__PURE__ */ new Map();
31455
- this._watched = /* @__PURE__ */ new Map();
31456
- this._pendingWrites = /* @__PURE__ */ new Map();
31457
- this._pendingUnlinks = /* @__PURE__ */ new Map();
31458
- this._readyCount = 0;
31459
- this._readyEmitted = false;
31460
- const awf = _opts.awaitWriteFinish;
31461
- const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
31462
- const opts = {
31463
- // Defaults
31464
- persistent: true,
31465
- ignoreInitial: false,
31466
- ignorePermissionErrors: false,
31467
- interval: 100,
31468
- binaryInterval: 300,
31469
- followSymlinks: true,
31470
- usePolling: false,
31471
- // useAsync: false,
31472
- atomic: true,
31473
- // NOTE: overwritten later (depends on usePolling)
31474
- ..._opts,
31475
- // Change format
31476
- ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
31477
- awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
31478
- };
31479
- if (isIBMi)
31480
- opts.usePolling = true;
31481
- if (opts.atomic === void 0)
31482
- opts.atomic = !opts.usePolling;
31483
- const envPoll = process.env.CHOKIDAR_USEPOLLING;
31484
- if (envPoll !== void 0) {
31485
- const envLower = envPoll.toLowerCase();
31486
- if (envLower === "false" || envLower === "0")
31487
- opts.usePolling = false;
31488
- else if (envLower === "true" || envLower === "1")
31489
- opts.usePolling = true;
31490
- else
31491
- opts.usePolling = !!envLower;
31492
- }
31493
- const envInterval = process.env.CHOKIDAR_INTERVAL;
31494
- if (envInterval)
31495
- opts.interval = Number.parseInt(envInterval, 10);
31496
- let readyCalls = 0;
31497
- this._emitReady = () => {
31498
- readyCalls++;
31499
- if (readyCalls >= this._readyCount) {
31500
- this._emitReady = EMPTY_FN;
31501
- this._readyEmitted = true;
31502
- process.nextTick(() => this.emit(EVENTS.READY));
31503
- }
31504
- };
31505
- this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
31506
- this._boundRemove = this._remove.bind(this);
31507
- this.options = opts;
31508
- this._nodeFsHandler = new NodeFsHandler(this);
31509
- Object.freeze(opts);
31510
- }
31511
- _addIgnoredPath(matcher) {
31512
- if (isMatcherObject(matcher)) {
31513
- for (const ignored of this._ignoredPaths) {
31514
- if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
31515
- return;
31516
- }
31517
- }
31518
- }
31519
- this._ignoredPaths.add(matcher);
31520
- }
31521
- _removeIgnoredPath(matcher) {
31522
- this._ignoredPaths.delete(matcher);
31523
- if (typeof matcher === "string") {
31524
- for (const ignored of this._ignoredPaths) {
31525
- if (isMatcherObject(ignored) && ignored.path === matcher) {
31526
- this._ignoredPaths.delete(ignored);
31527
- }
31528
- }
31529
- }
31530
- }
31531
- // Public methods
31532
- /**
31533
- * Adds paths to be watched on an existing FSWatcher instance.
31534
- * @param paths_ file or file list. Other arguments are unused
31535
- */
31536
- add(paths_, _origAdd, _internal) {
31537
- const { cwd: cwd3 } = this.options;
31538
- this.closed = false;
31539
- this._closePromise = void 0;
31540
- let paths = unifyPaths(paths_);
31541
- if (cwd3) {
31542
- paths = paths.map((path24) => {
31543
- const absPath = getAbsolutePath(path24, cwd3);
31544
- return absPath;
31545
- });
31546
- }
31547
- paths.forEach((path24) => {
31548
- this._removeIgnoredPath(path24);
31549
- });
31550
- this._userIgnored = void 0;
31551
- if (!this._readyCount)
31552
- this._readyCount = 0;
31553
- this._readyCount += paths.length;
31554
- Promise.all(paths.map(async (path24) => {
31555
- const res = await this._nodeFsHandler._addToNodeFs(path24, !_internal, void 0, 0, _origAdd);
31556
- if (res)
31557
- this._emitReady();
31558
- return res;
31559
- })).then((results) => {
31560
- if (this.closed)
31561
- return;
31562
- results.forEach((item) => {
31563
- if (item)
31564
- this.add(sysPath2.dirname(item), sysPath2.basename(_origAdd || item));
31565
- });
31566
- });
31567
- return this;
31568
- }
31569
- /**
31570
- * Close watchers or start ignoring events from specified paths.
31571
- */
31572
- unwatch(paths_) {
31573
- if (this.closed)
31574
- return this;
31575
- const paths = unifyPaths(paths_);
31576
- const { cwd: cwd3 } = this.options;
31577
- paths.forEach((path24) => {
31578
- if (!sysPath2.isAbsolute(path24) && !this._closers.has(path24)) {
31579
- if (cwd3)
31580
- path24 = sysPath2.join(cwd3, path24);
31581
- path24 = sysPath2.resolve(path24);
31582
- }
31583
- this._closePath(path24);
31584
- this._addIgnoredPath(path24);
31585
- if (this._watched.has(path24)) {
31586
- this._addIgnoredPath({
31587
- path: path24,
31588
- recursive: true
31589
- });
31590
- }
31591
- this._userIgnored = void 0;
31592
- });
31593
- return this;
31594
- }
31595
- /**
31596
- * Close watchers and remove all listeners from watched paths.
31597
- */
31598
- close() {
31599
- if (this._closePromise) {
31600
- return this._closePromise;
31601
- }
31602
- this.closed = true;
31603
- this.removeAllListeners();
31604
- const closers = [];
31605
- this._closers.forEach((closerList) => closerList.forEach((closer) => {
31606
- const promise2 = closer();
31607
- if (promise2 instanceof Promise)
31608
- closers.push(promise2);
31609
- }));
31610
- this._streams.forEach((stream) => stream.destroy());
31611
- this._userIgnored = void 0;
31612
- this._readyCount = 0;
31613
- this._readyEmitted = false;
31614
- this._watched.forEach((dirent) => dirent.dispose());
31615
- this._closers.clear();
31616
- this._watched.clear();
31617
- this._streams.clear();
31618
- this._symlinkPaths.clear();
31619
- this._throttled.clear();
31620
- this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
31621
- return this._closePromise;
31622
- }
31623
- /**
31624
- * Expose list of watched paths
31625
- * @returns for chaining
31626
- */
31627
- getWatched() {
31628
- const watchList = {};
31629
- this._watched.forEach((entry, dir) => {
31630
- const key = this.options.cwd ? sysPath2.relative(this.options.cwd, dir) : dir;
31631
- const index = key || ONE_DOT;
31632
- watchList[index] = entry.getChildren().sort();
31633
- });
31634
- return watchList;
31635
- }
31636
- emitWithAll(event, args) {
31637
- this.emit(event, ...args);
31638
- if (event !== EVENTS.ERROR)
31639
- this.emit(EVENTS.ALL, event, ...args);
31640
- }
31641
- // Common helpers
31642
- // --------------
31643
- /**
31644
- * Normalize and emit events.
31645
- * Calling _emit DOES NOT MEAN emit() would be called!
31646
- * @param event Type of event
31647
- * @param path File or directory path
31648
- * @param stats arguments to be passed with event
31649
- * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
31650
- */
31651
- async _emit(event, path24, stats) {
31652
- if (this.closed)
31653
- return;
31654
- const opts = this.options;
31655
- if (isWindows)
31656
- path24 = sysPath2.normalize(path24);
31657
- if (opts.cwd)
31658
- path24 = sysPath2.relative(opts.cwd, path24);
31659
- const args = [path24];
31660
- if (stats != null)
31661
- args.push(stats);
31662
- const awf = opts.awaitWriteFinish;
31663
- let pw;
31664
- if (awf && (pw = this._pendingWrites.get(path24))) {
31665
- pw.lastChange = /* @__PURE__ */ new Date();
31666
- return this;
31667
- }
31668
- if (opts.atomic) {
31669
- if (event === EVENTS.UNLINK) {
31670
- this._pendingUnlinks.set(path24, [event, ...args]);
31671
- setTimeout(() => {
31672
- this._pendingUnlinks.forEach((entry, path25) => {
31673
- this.emit(...entry);
31674
- this.emit(EVENTS.ALL, ...entry);
31675
- this._pendingUnlinks.delete(path25);
31676
- });
31677
- }, typeof opts.atomic === "number" ? opts.atomic : 100);
31678
- return this;
31679
- }
31680
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path24)) {
31681
- event = EVENTS.CHANGE;
31682
- this._pendingUnlinks.delete(path24);
31683
- }
31684
- }
31685
- if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
31686
- const awfEmit = (err, stats2) => {
31687
- if (err) {
31688
- event = EVENTS.ERROR;
31689
- args[0] = err;
31690
- this.emitWithAll(event, args);
31691
- } else if (stats2) {
31692
- if (args.length > 1) {
31693
- args[1] = stats2;
31694
- } else {
31695
- args.push(stats2);
31696
- }
31697
- this.emitWithAll(event, args);
31698
- }
31699
- };
31700
- this._awaitWriteFinish(path24, awf.stabilityThreshold, event, awfEmit);
31701
- return this;
31702
- }
31703
- if (event === EVENTS.CHANGE) {
31704
- const isThrottled = !this._throttle(EVENTS.CHANGE, path24, 50);
31705
- if (isThrottled)
31706
- return this;
31707
- }
31708
- if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
31709
- const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path24) : path24;
31710
- let stats2;
31711
- try {
31712
- stats2 = await stat3(fullPath);
31713
- } catch (err) {
31714
- }
31715
- if (!stats2 || this.closed)
31716
- return;
31717
- args.push(stats2);
31718
- }
31719
- this.emitWithAll(event, args);
31720
- return this;
31721
- }
31722
- /**
31723
- * Common handler for errors
31724
- * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
31725
- */
31726
- _handleError(error40) {
31727
- const code = error40 && error40.code;
31728
- if (error40 && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
31729
- this.emit(EVENTS.ERROR, error40);
31730
- }
31731
- return error40 || this.closed;
31732
- }
31733
- /**
31734
- * Helper utility for throttling
31735
- * @param actionType type being throttled
31736
- * @param path being acted upon
31737
- * @param timeout duration of time to suppress duplicate actions
31738
- * @returns tracking object or false if action should be suppressed
31739
- */
31740
- _throttle(actionType, path24, timeout) {
31741
- if (!this._throttled.has(actionType)) {
31742
- this._throttled.set(actionType, /* @__PURE__ */ new Map());
31743
- }
31744
- const action = this._throttled.get(actionType);
31745
- if (!action)
31746
- throw new Error("invalid throttle");
31747
- const actionPath = action.get(path24);
31748
- if (actionPath) {
31749
- actionPath.count++;
31750
- return false;
31751
- }
31752
- let timeoutObject;
31753
- const clear = () => {
31754
- const item = action.get(path24);
31755
- const count = item ? item.count : 0;
31756
- action.delete(path24);
31757
- clearTimeout(timeoutObject);
31758
- if (item)
31759
- clearTimeout(item.timeoutObject);
31760
- return count;
31761
- };
31762
- timeoutObject = setTimeout(clear, timeout);
31763
- const thr = { timeoutObject, clear, count: 0 };
31764
- action.set(path24, thr);
31765
- return thr;
31766
- }
31767
- _incrReadyCount() {
31768
- return this._readyCount++;
31769
- }
31770
- /**
31771
- * Awaits write operation to finish.
31772
- * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
31773
- * @param path being acted upon
31774
- * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
31775
- * @param event
31776
- * @param awfEmit Callback to be called when ready for event to be emitted.
31777
- */
31778
- _awaitWriteFinish(path24, threshold, event, awfEmit) {
31779
- const awf = this.options.awaitWriteFinish;
31780
- if (typeof awf !== "object")
31781
- return;
31782
- const pollInterval = awf.pollInterval;
31783
- let timeoutHandler;
31784
- let fullPath = path24;
31785
- if (this.options.cwd && !sysPath2.isAbsolute(path24)) {
31786
- fullPath = sysPath2.join(this.options.cwd, path24);
31787
- }
31788
- const now = /* @__PURE__ */ new Date();
31789
- const writes = this._pendingWrites;
31790
- function awaitWriteFinishFn(prevStat) {
31791
- statcb(fullPath, (err, curStat) => {
31792
- if (err || !writes.has(path24)) {
31793
- if (err && err.code !== "ENOENT")
31794
- awfEmit(err);
31795
- return;
31796
- }
31797
- const now2 = Number(/* @__PURE__ */ new Date());
31798
- if (prevStat && curStat.size !== prevStat.size) {
31799
- writes.get(path24).lastChange = now2;
31800
- }
31801
- const pw = writes.get(path24);
31802
- const df = now2 - pw.lastChange;
31803
- if (df >= threshold) {
31804
- writes.delete(path24);
31805
- awfEmit(void 0, curStat);
31806
- } else {
31807
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
31808
- }
31809
- });
31810
- }
31811
- if (!writes.has(path24)) {
31812
- writes.set(path24, {
31813
- lastChange: now,
31814
- cancelWait: () => {
31815
- writes.delete(path24);
31816
- clearTimeout(timeoutHandler);
31817
- return event;
31818
- }
31819
- });
31820
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
31821
- }
31822
- }
31823
- /**
31824
- * Determines whether user has asked to ignore this path.
31825
- */
31826
- _isIgnored(path24, stats) {
31827
- if (this.options.atomic && DOT_RE.test(path24))
31828
- return true;
31829
- if (!this._userIgnored) {
31830
- const { cwd: cwd3 } = this.options;
31831
- const ign = this.options.ignored;
31832
- const ignored = (ign || []).map(normalizeIgnored(cwd3));
31833
- const ignoredPaths = [...this._ignoredPaths];
31834
- const list = [...ignoredPaths.map(normalizeIgnored(cwd3)), ...ignored];
31835
- this._userIgnored = anymatch(list, void 0);
31836
- }
31837
- return this._userIgnored(path24, stats);
31838
- }
31839
- _isntIgnored(path24, stat4) {
31840
- return !this._isIgnored(path24, stat4);
31841
- }
31842
- /**
31843
- * Provides a set of common helpers and properties relating to symlink handling.
31844
- * @param path file or directory pattern being watched
31845
- */
31846
- _getWatchHelpers(path24) {
31847
- return new WatchHelper(path24, this.options.followSymlinks, this);
31848
- }
31849
- // Directory helpers
31850
- // -----------------
31851
- /**
31852
- * Provides directory tracking objects
31853
- * @param directory path of the directory
31854
- */
31855
- _getWatchedDir(directory) {
31856
- const dir = sysPath2.resolve(directory);
31857
- if (!this._watched.has(dir))
31858
- this._watched.set(dir, new DirEntry(dir, this._boundRemove));
31859
- return this._watched.get(dir);
31860
- }
31861
- // File helpers
31862
- // ------------
31863
- /**
31864
- * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
31865
- */
31866
- _hasReadPermissions(stats) {
31867
- if (this.options.ignorePermissionErrors)
31868
- return true;
31869
- return Boolean(Number(stats.mode) & 256);
31870
- }
31871
- /**
31872
- * Handles emitting unlink events for
31873
- * files and directories, and via recursion, for
31874
- * files and directories within directories that are unlinked
31875
- * @param directory within which the following item is located
31876
- * @param item base path of item/directory
31877
- */
31878
- _remove(directory, item, isDirectory) {
31879
- const path24 = sysPath2.join(directory, item);
31880
- const fullPath = sysPath2.resolve(path24);
31881
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path24) || this._watched.has(fullPath);
31882
- if (!this._throttle("remove", path24, 100))
31883
- return;
31884
- if (!isDirectory && this._watched.size === 1) {
31885
- this.add(directory, item, true);
31886
- }
31887
- const wp = this._getWatchedDir(path24);
31888
- const nestedDirectoryChildren = wp.getChildren();
31889
- nestedDirectoryChildren.forEach((nested) => this._remove(path24, nested));
31890
- const parent = this._getWatchedDir(directory);
31891
- const wasTracked = parent.has(item);
31892
- parent.remove(item);
31893
- if (this._symlinkPaths.has(fullPath)) {
31894
- this._symlinkPaths.delete(fullPath);
31895
- }
31896
- let relPath = path24;
31897
- if (this.options.cwd)
31898
- relPath = sysPath2.relative(this.options.cwd, path24);
31899
- if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
31900
- const event = this._pendingWrites.get(relPath).cancelWait();
31901
- if (event === EVENTS.ADD)
31902
- return;
31903
- }
31904
- this._watched.delete(path24);
31905
- this._watched.delete(fullPath);
31906
- const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
31907
- if (wasTracked && !this._isIgnored(path24))
31908
- this._emit(eventName, path24);
31909
- this._closePath(path24);
31910
- }
31911
- /**
31912
- * Closes all watchers for a path
31913
- */
31914
- _closePath(path24) {
31915
- this._closeFile(path24);
31916
- const dir = sysPath2.dirname(path24);
31917
- this._getWatchedDir(dir).remove(sysPath2.basename(path24));
31918
- }
31919
- /**
31920
- * Closes only file-specific watchers
31921
- */
31922
- _closeFile(path24) {
31923
- const closers = this._closers.get(path24);
31924
- if (!closers)
31925
- return;
31926
- closers.forEach((closer) => closer());
31927
- this._closers.delete(path24);
31928
- }
31929
- _addPathCloser(path24, closer) {
31930
- if (!closer)
31931
- return;
31932
- let list = this._closers.get(path24);
31933
- if (!list) {
31934
- list = [];
31935
- this._closers.set(path24, list);
31936
- }
31937
- list.push(closer);
31938
- }
31939
- _readdirp(root, opts) {
31940
- if (this.closed)
31941
- return;
31942
- const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
31943
- let stream = readdirp(root, options);
31944
- this._streams.add(stream);
31945
- stream.once(STR_CLOSE, () => {
31946
- stream = void 0;
31947
- });
31948
- stream.once(STR_END, () => {
31949
- if (stream) {
31950
- this._streams.delete(stream);
31951
- stream = void 0;
31952
- }
31953
- });
31954
- return stream;
31955
- }
31956
- };
31957
- function watch(paths, options = {}) {
31958
- const watcher = new FSWatcher(options);
31959
- watcher.add(paths);
31960
- return watcher;
31961
- }
31962
- var esm_default = { watch, FSWatcher };
31963
-
31964
- // src/files/watch-file-index.ts
31965
30273
  var DEBOUNCE_MS = 900;
31966
30274
  function shouldIgnoreRelative(rel) {
31967
30275
  const n = rel.replace(/\\/g, "/");
@@ -31970,8 +30278,43 @@ function shouldIgnoreRelative(rel) {
31970
30278
  if (n.includes("/.buildautomaton/") || n.startsWith(".buildautomaton/")) return true;
31971
30279
  return false;
31972
30280
  }
30281
+ function attachWatchErrorLog(w) {
30282
+ w.on("error", (err) => {
30283
+ console.error("[file-index] fs.watch error:", err);
30284
+ });
30285
+ }
30286
+ function createFsWatcher(resolved, schedule) {
30287
+ const onEvent = (_event, filename) => {
30288
+ if (filename != null) {
30289
+ const rel = typeof filename === "string" ? filename.replace(/\\/g, "/") : filename.toString("utf8").replace(/\\/g, "/");
30290
+ if (shouldIgnoreRelative(rel)) return;
30291
+ }
30292
+ schedule();
30293
+ };
30294
+ try {
30295
+ const w = watch(resolved, { recursive: true }, onEvent);
30296
+ attachWatchErrorLog(w);
30297
+ return w;
30298
+ } catch (e) {
30299
+ const code = typeof e === "object" && e !== null && "code" in e ? e.code : void 0;
30300
+ if (code === "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM") {
30301
+ console.warn(
30302
+ "[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."
30303
+ );
30304
+ const w = watch(resolved, { recursive: false }, onEvent);
30305
+ attachWatchErrorLog(w);
30306
+ return w;
30307
+ }
30308
+ throw e;
30309
+ }
30310
+ }
31973
30311
  function startFileIndexWatcher(cwd3 = process.cwd()) {
31974
30312
  const resolved = path21.resolve(cwd3);
30313
+ try {
30314
+ buildFileIndex(resolved);
30315
+ } catch (e) {
30316
+ console.error("[file-index] Initial index build failed:", e);
30317
+ }
31975
30318
  let timer = null;
31976
30319
  const runRebuild = () => {
31977
30320
  try {
@@ -31987,27 +30330,13 @@ function startFileIndexWatcher(cwd3 = process.cwd()) {
31987
30330
  runRebuild();
31988
30331
  }, DEBOUNCE_MS);
31989
30332
  };
31990
- const watcher = esm_default.watch(".", {
31991
- cwd: resolved,
31992
- ignoreInitial: true,
31993
- persistent: true,
31994
- ignored: (p) => {
31995
- const rel = path21.isAbsolute(p) ? path21.relative(resolved, p).replace(/\\/g, "/") : p.replace(/\\/g, "/");
31996
- return shouldIgnoreRelative(rel || ".");
31997
- },
31998
- awaitWriteFinish: { stabilityThreshold: 250, pollInterval: 100 }
31999
- });
32000
- watcher.on("add", schedule);
32001
- watcher.on("change", schedule);
32002
- watcher.on("unlink", schedule);
32003
- watcher.on("addDir", schedule);
32004
- watcher.on("unlinkDir", schedule);
30333
+ const watcher = createFsWatcher(resolved, schedule);
32005
30334
  return () => {
32006
30335
  if (timer) {
32007
30336
  clearTimeout(timer);
32008
30337
  timer = null;
32009
30338
  }
32010
- void watcher.close();
30339
+ watcher.close();
32011
30340
  };
32012
30341
  }
32013
30342
 
@@ -32031,15 +30360,15 @@ function sendDevServerStatus(getWs, serverId, status, options) {
32031
30360
 
32032
30361
  // src/dev-servers/process/terminate-child-process.ts
32033
30362
  async function sigtermAndWaitForExit(proc, graceMs, log2, shortId) {
32034
- const exited = new Promise((resolve16) => {
32035
- proc.once("exit", () => resolve16());
30363
+ const exited = new Promise((resolve14) => {
30364
+ proc.once("exit", () => resolve14());
32036
30365
  });
32037
30366
  log2(`[dev-server] Sending SIGTERM to ${shortId} (pid=${proc.pid ?? "?"})\u2026`);
32038
30367
  try {
32039
30368
  proc.kill("SIGTERM");
32040
30369
  } catch {
32041
30370
  }
32042
- await Promise.race([exited, new Promise((resolve16) => setTimeout(resolve16, graceMs))]);
30371
+ await Promise.race([exited, new Promise((resolve14) => setTimeout(resolve14, graceMs))]);
32043
30372
  }
32044
30373
  function forceKillChild(proc, log2, shortId, graceMs) {
32045
30374
  log2(`[dev-server] ${shortId} did not exit within ${graceMs}ms; sending SIGKILL (pid=${proc.pid ?? "?"})\u2026`);
@@ -33381,9 +31710,4 @@ export {
33381
31710
  runPendingAuth,
33382
31711
  sendWsMessage
33383
31712
  };
33384
- /*! Bundled license information:
33385
-
33386
- chokidar/esm/index.js:
33387
- (*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
33388
- */
33389
31713
  //# sourceMappingURL=index.js.map