diffhub 0.1.22 → 0.1.23
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/.next/standalone/apps/cli/.next/BUILD_ID +1 -1
- package/.next/standalone/apps/cli/.next/app-path-routes-manifest.json +1 -0
- package/.next/standalone/apps/cli/.next/build-manifest.json +3 -3
- package/.next/standalone/apps/cli/.next/prerender-manifest.json +3 -3
- package/.next/standalone/apps/cli/.next/routes-manifest.json +6 -0
- package/.next/standalone/apps/cli/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_global-error.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/apps/cli/.next/server/app/api/watch/route.js +2 -2
- package/.next/standalone/apps/cli/.next/server/app/api/watch/route.js.nft.json +1 -1
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route/app-paths-manifest.json +3 -0
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route/build-manifest.json +9 -0
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route/server-reference-manifest.json +4 -0
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route.js +8 -0
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route.js.map +5 -0
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route.js.nft.json +1 -0
- package/.next/standalone/apps/cli/.next/server/app/api/watch-events/route_client-reference-manifest.js +3 -0
- package/.next/standalone/apps/cli/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/apps/cli/.next/server/app-paths-manifest.json +1 -0
- package/.next/standalone/apps/cli/.next/server/chunks/[root-of-the-server]__05nbqqx._.js +4 -0
- package/.next/standalone/apps/cli/.next/server/chunks/[root-of-the-server]__05wbal-._.js +2 -2
- package/.next/standalone/apps/cli/.next/server/chunks/[root-of-the-server]__0qe921e._.js +3 -0
- package/.next/standalone/apps/cli/.next/server/chunks/[root-of-the-server]__101690.._.js +9 -0
- package/.next/standalone/apps/cli/.next/server/chunks/apps_cli__next-internal_server_app_api_watch-events_route_actions_0i.gzl8.js +3 -0
- package/.next/standalone/apps/cli/.next/server/chunks/ssr/_07okxca._.js +2 -2
- package/.next/standalone/apps/cli/.next/server/chunks/ssr/_13g0g_e._.js +1 -1
- package/.next/standalone/apps/cli/.next/server/functions-config-manifest.json +2 -1
- package/.next/standalone/apps/cli/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/apps/cli/.next/server/pages/404.html +1 -1
- package/.next/standalone/apps/cli/.next/server/pages/500.html +1 -1
- package/.next/standalone/apps/cli/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/apps/cli/.next/server/server-reference-manifest.json +1 -1
- package/.next/standalone/apps/cli/.next/static/chunks/{0-le8unvr3s~..js → 0vm79-lt-4syt.js} +5 -5
- package/.next/standalone/apps/cli/package.json +1 -1
- package/bin/diffhub.mjs +275 -5
- package/package.json +1 -1
- package/.next/standalone/apps/cli/.next/server/chunks/[root-of-the-server]__01oij46._.js +0 -8
- package/.next/standalone/apps/cli/.next/server/chunks/[root-of-the-server]__126jjll._.js +0 -4
- /package/.next/standalone/apps/cli/.next/static/{Hr5DhyyWmSFusFY7-HlJ- → XaFUoKZbR-bS9r4T4fiPI}/_buildManifest.js +0 -0
- /package/.next/standalone/apps/cli/.next/static/{Hr5DhyyWmSFusFY7-HlJ- → XaFUoKZbR-bS9r4T4fiPI}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/apps/cli/.next/static/{Hr5DhyyWmSFusFY7-HlJ- → XaFUoKZbR-bS9r4T4fiPI}/_ssgManifest.js +0 -0
package/bin/diffhub.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "node:fs";
|
|
15
15
|
import { createServer } from "node:net";
|
|
16
16
|
import { tmpdir } from "node:os";
|
|
17
|
-
import { join, resolve } from "node:path";
|
|
17
|
+
import { dirname, join, resolve } from "node:path";
|
|
18
18
|
import { promisify } from "node:util";
|
|
19
19
|
import {
|
|
20
20
|
findMissingStandaloneNodeModuleAliases,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
|
|
24
24
|
const execFile = promisify(execFileCb);
|
|
25
25
|
const __dirname = import.meta.dirname;
|
|
26
|
+
const __filename = import.meta.filename;
|
|
26
27
|
const PREFERRED_BASE_BRANCHES = ["main", "master", "develop", "dev"];
|
|
27
28
|
|
|
28
29
|
// Fast-fail on unsupported Node.js versions
|
|
@@ -147,11 +148,19 @@ const getCmuxWriterPidPath = (repoPath) => {
|
|
|
147
148
|
return join(tmpdir(), `diffhub-cmux-writer-${hash}.pid`);
|
|
148
149
|
};
|
|
149
150
|
|
|
151
|
+
const getCmuxWatchEventsPidPath = (repoPath) => {
|
|
152
|
+
const hash = createHash("md5").update(repoPath).digest("hex").slice(0, 8);
|
|
153
|
+
return join(tmpdir(), `diffhub-cmux-watch-events-${hash}.pid`);
|
|
154
|
+
};
|
|
155
|
+
|
|
150
156
|
const createServerBootId = (repoPath, baseBranch) =>
|
|
151
157
|
createHash("sha1")
|
|
152
158
|
.update(`${repoPath}:${baseBranch}:${Date.now()}:${Math.random()}`)
|
|
153
159
|
.digest("hex");
|
|
154
160
|
|
|
161
|
+
const createWatchToken = () =>
|
|
162
|
+
createHash("sha1").update(`watch:${process.pid}:${Date.now()}:${Math.random()}`).digest("hex");
|
|
163
|
+
|
|
155
164
|
const clearRepoSnapshotFiles = (repoPath) => {
|
|
156
165
|
const prefix = `diffhub-snapshot-${createHash("sha1").update(repoPath).digest("hex")}-`;
|
|
157
166
|
for (const entry of readdirSync(tmpdir())) {
|
|
@@ -307,6 +316,36 @@ const resolveBaseBranch = async (repoPath, explicitBaseBranch) => {
|
|
|
307
316
|
return "origin/main";
|
|
308
317
|
};
|
|
309
318
|
|
|
319
|
+
const getGitDirectory = (repoPath) =>
|
|
320
|
+
execFileSync("git", ["rev-parse", "--path-format=absolute", "--git-dir"], {
|
|
321
|
+
cwd: repoPath,
|
|
322
|
+
encoding: "utf-8",
|
|
323
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
324
|
+
}).trim();
|
|
325
|
+
|
|
326
|
+
const getTrackedWatchDirectories = (repoPath) => {
|
|
327
|
+
const rawFiles = execFileSync("git", ["ls-files", "-z"], {
|
|
328
|
+
cwd: repoPath,
|
|
329
|
+
encoding: "utf-8",
|
|
330
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
331
|
+
});
|
|
332
|
+
const directories = new Set([repoPath]);
|
|
333
|
+
|
|
334
|
+
for (const file of rawFiles.split("\0")) {
|
|
335
|
+
if (!file) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const relativeDirectory = dirname(file);
|
|
340
|
+
const directory = relativeDirectory === "." ? repoPath : join(repoPath, relativeDirectory);
|
|
341
|
+
if (existsSync(directory)) {
|
|
342
|
+
directories.add(directory);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return [...directories];
|
|
347
|
+
};
|
|
348
|
+
|
|
310
349
|
const buildSnapshot = async (repoPath, explicitBaseBranch, mode, serverBootId) => {
|
|
311
350
|
const branchOutput = await runGitSnapshotCommand(repoPath, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
312
351
|
const branch = branchOutput.trim();
|
|
@@ -480,6 +519,89 @@ const startSnapshotWriter = async (repoPath, explicitBaseBranch, serverBootId) =
|
|
|
480
519
|
};
|
|
481
520
|
};
|
|
482
521
|
|
|
522
|
+
const postWatchEvent = async (port, token, event, path) => {
|
|
523
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/watch-events`, {
|
|
524
|
+
body: JSON.stringify({ event, path }),
|
|
525
|
+
headers: {
|
|
526
|
+
Connection: "close",
|
|
527
|
+
"Content-Type": "application/json",
|
|
528
|
+
"x-diffhub-watch-token": token,
|
|
529
|
+
},
|
|
530
|
+
method: "POST",
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
if (!response.ok) {
|
|
534
|
+
throw new Error(`watch event POST failed with ${response.status}`);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
const startWatchEventForwarder = (repoPath, port, token) => {
|
|
539
|
+
const gitDir = getGitDirectory(repoPath);
|
|
540
|
+
const watchTargets = [
|
|
541
|
+
...getTrackedWatchDirectories(repoPath),
|
|
542
|
+
join(gitDir, "HEAD"),
|
|
543
|
+
join(gitDir, "index"),
|
|
544
|
+
join(gitDir, "packed-refs"),
|
|
545
|
+
].filter(existsSync);
|
|
546
|
+
|
|
547
|
+
let sendTimer = null;
|
|
548
|
+
let pendingEvent = null;
|
|
549
|
+
|
|
550
|
+
const sendPendingEvent = async (nextEvent) => {
|
|
551
|
+
try {
|
|
552
|
+
await postWatchEvent(port, token, nextEvent.event, nextEvent.path);
|
|
553
|
+
} catch (error) {
|
|
554
|
+
console.error("[diffhub] failed to forward watch event", { error });
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
const flushPendingEvent = () => {
|
|
559
|
+
const nextEvent = pendingEvent;
|
|
560
|
+
pendingEvent = null;
|
|
561
|
+
sendTimer = null;
|
|
562
|
+
|
|
563
|
+
if (!nextEvent) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
void sendPendingEvent(nextEvent);
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
const scheduleEvent = (event, path = null) => {
|
|
571
|
+
pendingEvent = { event, path };
|
|
572
|
+
if (sendTimer) {
|
|
573
|
+
clearTimeout(sendTimer);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
sendTimer = setTimeout(flushPendingEvent, 150);
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
const watcher = watch(watchTargets, {
|
|
580
|
+
atomic: true,
|
|
581
|
+
depth: 0,
|
|
582
|
+
ignoreInitial: true,
|
|
583
|
+
ignored: (pathToCheck) => shouldIgnoreWatchPath(pathToCheck, repoPath),
|
|
584
|
+
persistent: true,
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
watcher.on("add", (path) => scheduleEvent("add", path));
|
|
588
|
+
watcher.on("addDir", (path) => scheduleEvent("addDir", path));
|
|
589
|
+
watcher.on("change", (path) => scheduleEvent("change", path));
|
|
590
|
+
watcher.on("unlink", (path) => scheduleEvent("unlink", path));
|
|
591
|
+
watcher.on("unlinkDir", (path) => scheduleEvent("unlinkDir", path));
|
|
592
|
+
watcher.on("error", (error) => {
|
|
593
|
+
console.error("[diffhub] watch event forwarder failed", { error });
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
return async () => {
|
|
597
|
+
if (sendTimer) {
|
|
598
|
+
clearTimeout(sendTimer);
|
|
599
|
+
sendTimer = null;
|
|
600
|
+
}
|
|
601
|
+
await watcher.close();
|
|
602
|
+
};
|
|
603
|
+
};
|
|
604
|
+
|
|
483
605
|
const listSnapshotWriterProcesses = async (repoPath) => {
|
|
484
606
|
try {
|
|
485
607
|
const { stdout } = await execFile("ps", ["-axo", "pid=,command="], {
|
|
@@ -594,6 +716,115 @@ const stopSnapshotWriterProcess = async (repoPath) => {
|
|
|
594
716
|
}
|
|
595
717
|
};
|
|
596
718
|
|
|
719
|
+
const listWatchEventProcesses = async (repoPath) => {
|
|
720
|
+
try {
|
|
721
|
+
const { stdout } = await execFile("ps", ["-axo", "pid=,command="], {
|
|
722
|
+
encoding: "utf-8",
|
|
723
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
const repoMatcher = `--repo ${repoPath}`;
|
|
727
|
+
return stdout
|
|
728
|
+
.split("\n")
|
|
729
|
+
.map((line) => line.trim())
|
|
730
|
+
.filter(Boolean)
|
|
731
|
+
.map((line) => {
|
|
732
|
+
const firstSpace = line.indexOf(" ");
|
|
733
|
+
if (firstSpace === -1) {
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
const pid = Number.parseInt(line.slice(0, firstSpace), 10);
|
|
738
|
+
const command = line.slice(firstSpace + 1);
|
|
739
|
+
if (
|
|
740
|
+
!Number.isInteger(pid) ||
|
|
741
|
+
pid <= 0 ||
|
|
742
|
+
pid === process.pid ||
|
|
743
|
+
!command.includes("internal-watch-events") ||
|
|
744
|
+
!command.includes(repoMatcher)
|
|
745
|
+
) {
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
return { command, pid };
|
|
750
|
+
})
|
|
751
|
+
.filter(Boolean);
|
|
752
|
+
} catch {
|
|
753
|
+
return [];
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
const stopWatchEventsProcess = async (repoPath) => {
|
|
758
|
+
const pidPath = getCmuxWatchEventsPidPath(repoPath);
|
|
759
|
+
const targetPids = new Set();
|
|
760
|
+
|
|
761
|
+
try {
|
|
762
|
+
const pid = Number.parseInt(readFileSync(pidPath, "utf-8").trim(), 10);
|
|
763
|
+
if (Number.isInteger(pid) && pid > 0 && pid !== process.pid) {
|
|
764
|
+
targetPids.add(pid);
|
|
765
|
+
}
|
|
766
|
+
} catch {
|
|
767
|
+
// empty
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const runningWatchers = await listWatchEventProcesses(repoPath);
|
|
771
|
+
for (const watcher of runningWatchers) {
|
|
772
|
+
targetPids.add(watcher.pid);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
for (const pid of targetPids) {
|
|
776
|
+
try {
|
|
777
|
+
process.kill(pid, "SIGTERM");
|
|
778
|
+
} catch {
|
|
779
|
+
// empty
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const remainingPids = [...targetPids];
|
|
784
|
+
const exited = await waitForProcessesToExit(remainingPids);
|
|
785
|
+
if (!exited) {
|
|
786
|
+
for (const pid of remainingPids) {
|
|
787
|
+
try {
|
|
788
|
+
process.kill(pid, "SIGKILL");
|
|
789
|
+
} catch {
|
|
790
|
+
// empty
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
await waitForProcessesToExit(remainingPids, 1000);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
try {
|
|
798
|
+
unlinkSync(pidPath);
|
|
799
|
+
} catch {
|
|
800
|
+
// empty
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
const startWatchEventsProcess = (repoPath, port, token) => {
|
|
805
|
+
const child = spawn(
|
|
806
|
+
process.execPath,
|
|
807
|
+
[
|
|
808
|
+
__filename,
|
|
809
|
+
"internal-watch-events",
|
|
810
|
+
"--repo",
|
|
811
|
+
repoPath,
|
|
812
|
+
"--port",
|
|
813
|
+
String(port),
|
|
814
|
+
"--token",
|
|
815
|
+
token,
|
|
816
|
+
],
|
|
817
|
+
{
|
|
818
|
+
detached: true,
|
|
819
|
+
stdio: "ignore",
|
|
820
|
+
},
|
|
821
|
+
);
|
|
822
|
+
|
|
823
|
+
child.unref();
|
|
824
|
+
writeFileSync(getCmuxWatchEventsPidPath(repoPath), `${child.pid ?? ""}\n`);
|
|
825
|
+
return child;
|
|
826
|
+
};
|
|
827
|
+
|
|
597
828
|
const REPO_POINTER = "/tmp/diffhub-active-repo";
|
|
598
829
|
|
|
599
830
|
const readRepoPointer = () => {
|
|
@@ -734,8 +965,10 @@ const startServer = (repoPath, baseBranch, port, options = {}) => {
|
|
|
734
965
|
cmux = false,
|
|
735
966
|
detached = false,
|
|
736
967
|
disableWatch,
|
|
968
|
+
externalWatcher = false,
|
|
737
969
|
logPath,
|
|
738
970
|
serverBootId = createServerBootId(repoPath, baseBranch),
|
|
971
|
+
watchToken,
|
|
739
972
|
} = options;
|
|
740
973
|
const shouldDisableWatch = disableWatch ?? Boolean(logPath);
|
|
741
974
|
let stdio = ["ignore", "inherit", "inherit"];
|
|
@@ -759,7 +992,9 @@ const startServer = (repoPath, baseBranch, port, options = {}) => {
|
|
|
759
992
|
...process.env,
|
|
760
993
|
...(baseBranch ? { DIFFHUB_BASE: baseBranch } : {}),
|
|
761
994
|
...(cmux ? { DIFFHUB_CMUX: "1" } : {}),
|
|
995
|
+
...(externalWatcher ? { DIFFHUB_EXTERNAL_WATCHER: "1" } : {}),
|
|
762
996
|
...(shouldDisablePrerender ? { DIFFHUB_DISABLE_PRERENDER: "1" } : {}),
|
|
997
|
+
...(watchToken ? { DIFFHUB_WATCH_TOKEN: watchToken } : {}),
|
|
763
998
|
DIFFHUB_REPO: repoPath,
|
|
764
999
|
DIFFHUB_SERVER_BOOT_ID: serverBootId,
|
|
765
1000
|
HOSTNAME: "127.0.0.1",
|
|
@@ -862,6 +1097,25 @@ const internalSnapshotWriterAction = async (opts) => {
|
|
|
862
1097
|
process.on("SIGTERM", cleanup);
|
|
863
1098
|
};
|
|
864
1099
|
|
|
1100
|
+
const internalWatchEventsAction = (opts) => {
|
|
1101
|
+
const repoPath = validateRepo(resolve(opts.repo));
|
|
1102
|
+
const port = Number.parseInt(opts.port, 10);
|
|
1103
|
+
if (!Number.isInteger(port) || port <= 0) {
|
|
1104
|
+
console.error("❌ Invalid port:", opts.port);
|
|
1105
|
+
process.exit(1);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
const stopWatchEventForwarder = startWatchEventForwarder(repoPath, port, opts.token);
|
|
1109
|
+
|
|
1110
|
+
const cleanup = async () => {
|
|
1111
|
+
await stopWatchEventForwarder();
|
|
1112
|
+
process.exit(0);
|
|
1113
|
+
};
|
|
1114
|
+
|
|
1115
|
+
process.on("SIGINT", cleanup);
|
|
1116
|
+
process.on("SIGTERM", cleanup);
|
|
1117
|
+
};
|
|
1118
|
+
|
|
865
1119
|
// -- serve action (default) --------------------------------------------------
|
|
866
1120
|
|
|
867
1121
|
const serveAction = async (opts) => {
|
|
@@ -933,26 +1187,34 @@ const cmuxAction = async (opts) => {
|
|
|
933
1187
|
const serverLogPath = getCmuxServerLogPath(repoPath);
|
|
934
1188
|
const restoreRepoPointer = syncCmuxRepoPointer(repoPath);
|
|
935
1189
|
const serverBootId = createServerBootId(repoPath, baseBranch);
|
|
1190
|
+
const watchToken = createWatchToken();
|
|
936
1191
|
|
|
937
1192
|
await stopListeningProcesses(port);
|
|
938
1193
|
await stopSnapshotWriterProcess(repoPath);
|
|
1194
|
+
await stopWatchEventsProcess(repoPath);
|
|
939
1195
|
clearRepoSnapshotFiles(repoPath);
|
|
940
1196
|
|
|
941
1197
|
await cmuxNotify("diffhub", "Starting server...");
|
|
942
1198
|
|
|
943
|
-
//
|
|
944
|
-
//
|
|
945
|
-
//
|
|
946
|
-
// The server's built-in fs.watch + async spawn pipeline works reliably.
|
|
1199
|
+
// Keep chokidar out of the standalone Next server. A separate helper watches
|
|
1200
|
+
// files and forwards local events into the server, so git spawning and
|
|
1201
|
+
// FSEvents live in different processes.
|
|
947
1202
|
const { bootId, server } = startServer(repoPath, baseBranch, port, {
|
|
948
1203
|
cmux: true,
|
|
949
1204
|
detached: true,
|
|
950
1205
|
disableWatch: false,
|
|
1206
|
+
externalWatcher: true,
|
|
951
1207
|
logPath: serverLogPath,
|
|
952
1208
|
serverBootId,
|
|
1209
|
+
watchToken,
|
|
953
1210
|
});
|
|
1211
|
+
let watchEventsProcess = null;
|
|
954
1212
|
|
|
955
1213
|
const cleanup = () => {
|
|
1214
|
+
if (watchEventsProcess && !watchEventsProcess.killed) {
|
|
1215
|
+
watchEventsProcess.kill();
|
|
1216
|
+
}
|
|
1217
|
+
rmSync(getCmuxWatchEventsPidPath(repoPath), { force: true });
|
|
956
1218
|
server.kill();
|
|
957
1219
|
restoreRepoPointer();
|
|
958
1220
|
process.exit(0);
|
|
@@ -968,6 +1230,7 @@ const cmuxAction = async (opts) => {
|
|
|
968
1230
|
return;
|
|
969
1231
|
}
|
|
970
1232
|
|
|
1233
|
+
watchEventsProcess = startWatchEventsProcess(repoPath, port, watchToken);
|
|
971
1234
|
await cmuxNotify("diffhub", `Opening diff: ${repoPath}`);
|
|
972
1235
|
|
|
973
1236
|
const surfaceRef = await cmuxOpenSplit(url);
|
|
@@ -1014,4 +1277,11 @@ program
|
|
|
1014
1277
|
.requiredOption("--boot-id <id>", "Boot identifier for snapshot generation")
|
|
1015
1278
|
.action(internalSnapshotWriterAction);
|
|
1016
1279
|
|
|
1280
|
+
program
|
|
1281
|
+
.command("internal-watch-events")
|
|
1282
|
+
.option("-r, --repo <path>", "Git repository path")
|
|
1283
|
+
.requiredOption("--port <port>", "DiffHub server port")
|
|
1284
|
+
.requiredOption("--token <token>", "Watch event authentication token")
|
|
1285
|
+
.action(internalWatchEventsAction);
|
|
1286
|
+
|
|
1017
1287
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
module.exports=[87769,(e,t,i)=>{t.exports=e.x("node:events",()=>require("node:events"))},12714,(e,t,i)=>{t.exports=e.x("node:fs/promises",()=>require("node:fs/promises"))},81111,(e,t,i)=>{t.exports=e.x("node:stream",()=>require("node:stream"))},14916,e=>{"use strict";var t=e.i(47909),i=e.i(74017),s=e.i(96250),r=e.i(59756),a=e.i(61916),n=e.i(74677),o=e.i(69741),l=e.i(16795),h=e.i(87718),d=e.i(95169),c=e.i(47587),u=e.i(66012),p=e.i(70101),f=e.i(26937),m=e.i(10372),w=e.i(93695);e.i(20232);var _=e.i(220),g=e.i(16781),v=e.i(50227),y=e.i(87769),b=e.i(2157),E=e.i(12714),P=e.i(81111);let R="files",x="directories",C="files_directories",D={root:".",fileFilter:e=>!0,directoryFilter:e=>!0,type:R,lstat:!1,depth:0x80000000,alwaysStat:!1,highWaterMark:4096};Object.freeze(D);let S="READDIRP_RECURSIVE_ERROR",k=new Set(["ENOENT","EPERM","EACCES","ELOOP",S]),I=[x,"all",C,R],A=new Set([x,"all",C]),W=new Set(["all",C,R]);process.platform;let T=e=>!0,F=e=>{if(void 0===e)return T;if("function"==typeof e)return e;if("string"==typeof e){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return T};class N extends P.Readable{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});const t={...D,...e},{root:i,type:s}=t;this._fileFilter=F(t.fileFilter),this._directoryFilter=F(t.directoryFilter);const r=t.lstat?E.lstat:E.stat;this._stat=r,this._maxDepth=null!=t.depth&&Number.isSafeInteger(t.depth)?t.depth:D.depth,this._wantsDir=!!s&&A.has(s),this._wantsFile=!!s&&W.has(s),this._wantsEverything="all"===s,this._root=(0,v.resolve)(i),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,i=t&&t.files;if(i&&i.length>0){let{path:s,depth:r}=t,a=i.splice(0,e).map(e=>this._formatEntry(e,s));for(let t of(await Promise.all(a))){if(!t)continue;if(this.destroyed)return;let i=await this._getEntryType(t);"directory"===i&&this._directoryFilter(t)?(r<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,r+1)),this._wantsDir&&(this.push(t),e--)):("file"===i||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let i;try{i=await (0,E.readdir)(e,this._rdOptions)}catch(e){this._onError(e)}return{files:i,depth:t,path:e}}async _formatEntry(e,t){let i,s=this._isDirent?e.name:e;try{let r=(0,v.resolve)((0,v.join)(t,s));(i={path:(0,v.relative)(this._root,r),fullPath:r,basename:s})[this._statsProp]=this._isDirent?e:await this._stat(r)}catch(e){this._onError(e);return}return i}_onError(e){k.has(e.code)&&!this.destroyed?this.emit("warn",e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return"";let t=e[this._statsProp];if(t.isFile())return"file";if(t.isDirectory())return"directory";if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await (0,E.realpath)(t),i=await (0,E.lstat)(e);if(i.isFile())return"file";if(i.isDirectory()){let i=e.length;if(t.startsWith(e)&&t.substr(i,1)===v.sep){let i=Error(`Circular symlink detected: "${t}" points to "${e}"`);return i.code=S,this._onError(i)}return"directory"}}catch(e){return this._onError(e),""}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}}var O=e.i(60526);let j=()=>{},M=process.platform,z="win32"===M,H="darwin"===M,U="linux"===M,q="freebsd"===M,$="OS400"===(0,O.type)(),L="all",B="ready",K="add",G="change",V="addDir",X="unlink",J="unlinkDir",Z="raw",Q="error",Y={lstat:E.lstat,stat:E.stat},ee="listeners",et="errHandlers",ei="rawEmitters",es=[ee,et,ei],er=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),ea=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},en=(e,t,i)=>{let s=e[t];s instanceof Set||(e[t]=s=new Set([s])),s.add(i)},eo=(e,t,i)=>{let s=e[t];s instanceof Set?s.delete(i):s===i&&delete e[t]},el=e=>e instanceof Set?0===e.size:!e,eh=new Map;function ed(e,t,i,s,r){try{return(0,b.watch)(e,{persistent:t.persistent},(t,s)=>{i(e),r(t,s,{watchedPath:e}),s&&e!==s&&ec(v.resolve(e,s),ee,v.join(e,s))})}catch(e){s(e);return}}let ec=(e,t,i,s,r)=>{let a=eh.get(e);a&&ea(a[t],e=>{e(i,s,r)})},eu=new Map;class ep{fsw;_boundHandleError;constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let i,s=this.fsw.options,r=v.dirname(e),a=v.basename(e);this.fsw._getWatchedDir(r).add(a);let n=v.resolve(e),o={persistent:s.persistent};if(t||(t=j),s.usePolling)o.interval=s.interval!==s.binaryInterval&&er.has(v.extname(a).slice(1).toLowerCase())?s.binaryInterval:s.interval,i=((e,t,i,s)=>{let{listener:r,rawEmitter:a}=s,n=eu.get(t),o=n&&n.options;return o&&(o.persistent<i.persistent||o.interval>i.interval)&&((0,b.unwatchFile)(t),n=void 0),n?(en(n,ee,r),en(n,ei,a)):(n={listeners:r,rawEmitters:a,options:i,watcher:(0,b.watchFile)(t,i,(i,s)=>{ea(n.rawEmitters,e=>{e(G,t,{curr:i,prev:s})});let r=i.mtimeMs;(i.size!==s.size||r>s.mtimeMs||0===r)&&ea(n.listeners,t=>t(e,i))})},eu.set(t,n)),()=>{eo(n,ee,r),eo(n,ei,a),el(n.listeners)&&(eu.delete(t),(0,b.unwatchFile)(t),n.options=n.watcher=void 0,Object.freeze(n))}})(e,n,o,{listener:t,rawEmitter:this.fsw._emitRaw});else i=((e,t,i,s)=>{let r,{listener:a,errHandler:n,rawEmitter:o}=s,l=eh.get(t);if(!i.persistent){if(!(r=ed(e,i,a,n,o)))return;return r.close.bind(r)}if(l)en(l,ee,a),en(l,et,n),en(l,ei,o);else{if(!(r=ed(e,i,ec.bind(null,t,ee),n,ec.bind(null,t,ei))))return;r.on(Q,async e=>{let i=ec.bind(null,t,et);l&&(l.watcherUnusable=!0),i(e)}),l={listeners:a,errHandlers:n,rawEmitters:o,watcher:r},eh.set(t,l)}return()=>{if(eo(l,ee,a),eo(l,et,n),eo(l,ei,o),el(l.listeners)){let e;l.watcher.close(),eh.delete(t),es.forEach((e=l,t=>{let i=e[t];i instanceof Set?i.clear():delete e[t]})),l.watcher=void 0,Object.freeze(l)}}})(e,n,o,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return i}_handleFile(e,t,i){if(this.fsw.closed)return;let s=v.dirname(e),r=v.basename(e),a=this.fsw._getWatchedDir(s),n=t;if(a.has(r))return;let o=async(t,i)=>{if(this.fsw._throttle("watch",e,5))if(i&&0!==i.mtimeMs){if(a.has(r)){let t=i.atimeMs,s=i.mtimeMs;(!t||t<=s||s!==n.mtimeMs)&&this.fsw._emit(G,e,i),n=i}}else try{let i=await (0,E.stat)(e);if(this.fsw.closed)return;let s=i.atimeMs,r=i.mtimeMs;if((!s||s<=r||r!==n.mtimeMs)&&this.fsw._emit(G,e,i),(H||U||q)&&n.ino!==i.ino){this.fsw._closeFile(t),n=i;let s=this._watchWithNodeFs(e,o);s&&this.fsw._addPathCloser(t,s)}else n=i}catch(e){this.fsw._remove(s,r)}},l=this._watchWithNodeFs(e,o);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(K,e,0))return;this.fsw._emit(K,e,t)}return l}async _handleSymlink(e,t,i,s){if(this.fsw.closed)return;let r=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){let t;this.fsw._incrReadyCount();try{t=await (0,E.realpath)(i)}catch(e){return this.fsw._emitReady(),!0}if(this.fsw.closed)return;return a.has(s)?this.fsw._symlinkPaths.get(r)!==t&&(this.fsw._symlinkPaths.set(r,t),this.fsw._emit(G,i,e.stats)):(a.add(s),this.fsw._symlinkPaths.set(r,t),this.fsw._emit(K,i,e.stats)),this.fsw._emitReady(),!0}if(this.fsw._symlinkPaths.has(r))return!0;this.fsw._symlinkPaths.set(r,!0)}_handleRead(e,t,i,s,r,a,n){e=v.join(e,"");let o=s?`${e}:${s}`:e;if(!(n=this.fsw._throttle("readdir",o,1e3)))return;let l=this.fsw._getWatchedDir(i.path),h=new Set,d=this.fsw._readdirp(e,{fileFilter:e=>i.filterPath(e),directoryFilter:e=>i.filterDir(e)});if(d)return d.on("data",async n=>{if(this.fsw.closed){d=void 0;return}let o=n.path,c=v.join(e,o);if(h.add(o),!(n.stats.isSymbolicLink()&&await this._handleSymlink(n,e,c,o))){if(this.fsw.closed){d=void 0;return}o!==s&&(s||l.has(o))||(this.fsw._incrReadyCount(),c=v.join(r,v.relative(r,c)),this._addToNodeFs(c,t,i,a+1))}}).on(Q,this._boundHandleError),new Promise((t,o)=>{if(!d)return o();d.once("end",()=>{if(this.fsw.closed){d=void 0;return}let o=!!n&&n.clear();t(void 0),l.getChildren().filter(t=>t!==e&&!h.has(t)).forEach(t=>{this.fsw._remove(e,t)}),d=void 0,o&&this._handleRead(e,!1,i,s,r,a,n)})})}async _handleDir(e,t,i,s,r,a,n){let o,l,h=this.fsw._getWatchedDir(v.dirname(e)),d=h.has(v.basename(e));i&&this.fsw.options.ignoreInitial||r||d||this.fsw._emit(V,e,t),h.add(v.basename(e)),this.fsw._getWatchedDir(e);let c=this.fsw.options.depth;if((null==c||s<=c)&&!this.fsw._symlinkPaths.has(n)){if(!r&&(await this._handleRead(e,i,a,r,e,s,o),this.fsw.closed))return;l=this._watchWithNodeFs(e,(t,i)=>{i&&0===i.mtimeMs||this._handleRead(t,!1,a,r,e,s,o)})}return l}async _addToNodeFs(e,t,i,s,r){let a=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return a(),!1;let n=this.fsw._getWatchHelpers(e);i&&(n.filterPath=e=>i.filterPath(e),n.filterDir=e=>i.filterDir(e));try{let i,o=await Y[n.statMethod](n.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(n.watchPath,o))return a(),!1;let l=this.fsw.options.followSymlinks;if(o.isDirectory()){let a=v.resolve(e),h=l?await (0,E.realpath)(e):e;if(this.fsw.closed||(i=await this._handleDir(n.watchPath,o,t,s,r,n,h),this.fsw.closed))return;a!==h&&void 0!==h&&this.fsw._symlinkPaths.set(a,h)}else if(o.isSymbolicLink()){let r=l?await (0,E.realpath)(e):e;if(this.fsw.closed)return;let a=v.dirname(n.watchPath);if(this.fsw._getWatchedDir(a).add(n.watchPath),this.fsw._emit(K,n.watchPath,o),i=await this._handleDir(a,o,t,s,e,n,r),this.fsw.closed)return;void 0!==r&&this.fsw._symlinkPaths.set(v.resolve(e),r)}else i=this._handleFile(n.watchPath,o,t);return a(),i&&this.fsw._addPathCloser(e,i),!1}catch(t){if(this.fsw._handleError(t))return a(),e}}}let ef=/\\/g,em=/\/\//g,ew=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,e_=/^\.[/\\]/;function eg(e){return Array.isArray(e)?e:[e]}let ev=e=>"object"==typeof e&&null!==e&&!(e instanceof RegExp);function ey(e,t,i){let s=function(e){if("string"!=typeof e)throw Error("string expected");e=(e=v.normalize(e)).replace(/\\/g,"/");let t=!1;return e.startsWith("//")&&(t=!0),e=e.replace(em,"/"),t&&(e="/"+e),e}(t);for(let t=0;t<e.length;t++)if((0,e[t])(s,i))return!0;return!1}let eb=e=>{let t=eg(e).flat();if(!t.every(e=>"string"==typeof e))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(eP)},eE=e=>{let t=e.replace(ef,"/"),i=!1;return t.startsWith("//")&&(i=!0),t=t.replace(em,"/"),i&&(t="/"+t),t},eP=e=>eE(v.normalize(eE(e))),eR=(e="")=>t=>"string"==typeof t?eP(v.isAbsolute(t)?t:v.join(e,t)):t,ex=Object.freeze(new Set);class eC{path;_removeWatcher;items;constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&"."!==e&&".."!==e&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let i=this.path;try{await (0,E.readdir)(i)}catch(e){this._removeWatcher&&this._removeWatcher(v.dirname(i),v.basename(i))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=j,this.items=ex,Object.freeze(this)}}class eD{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(e,t,i){this.fsw=i;const s=e;this.path=e=e.replace(e_,""),this.watchPath=s,this.fullWatchPath=v.resolve(s),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?"stat":"lstat"}entryPath(e){return v.join(this.watchPath,v.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let i=this.entryPath(e);return this.fsw._isntIgnored(i,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}}class eS extends y.EventEmitter{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;const t=e.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?eg(e.ignored):eg([]),awaitWriteFinish:!0===t?i:"object"==typeof t&&{...i,...t}};$&&(s.usePolling=!0),void 0===s.atomic&&(s.atomic=!s.usePolling);const r=process.env.CHOKIDAR_USEPOLLING;if(void 0!==r){const e=r.toLowerCase();"false"===e||"0"===e?s.usePolling=!1:"true"===e||"1"===e?s.usePolling=!0:s.usePolling=!!e}const a=process.env.CHOKIDAR_INTERVAL;a&&(s.interval=Number.parseInt(a,10));let n=0;this._emitReady=()=>{++n>=this._readyCount&&(this._emitReady=j,this._readyEmitted=!0,process.nextTick(()=>this.emit(B)))},this._emitRaw=(...e)=>this.emit(Z,...e),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new ep(this),Object.freeze(s)}_addIgnoredPath(e){if(ev(e)){for(let t of this._ignoredPaths)if(ev(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),"string"==typeof e)for(let t of this._ignoredPaths)ev(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,i){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let r=eb(e);return s&&(r=r.map(e=>v.isAbsolute(e)?e:v.join(s,e))),r.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=r.length,Promise.all(r.map(async e=>{let s=await this._nodeFsHandler._addToNodeFs(e,!i,void 0,0,t);return s&&this._emitReady(),s})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(v.dirname(e),v.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=eb(e),{cwd:i}=this.options;return t.forEach(e=>{v.isAbsolute(e)||this._closers.has(e)||(i&&(e=v.join(i,e)),e=v.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let i=t();i instanceof Promise&&e.push(i)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,i)=>{e[(this.options.cwd?v.relative(this.options.cwd,i):i)||"."]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==Q&&this.emit(L,e,...t)}async _emit(e,t,i){let s;if(this.closed)return;let r=this.options;z&&(t=v.normalize(t)),r.cwd&&(t=v.relative(r.cwd,t));let a=[t];null!=i&&a.push(i);let n=r.awaitWriteFinish;if(n&&(s=this._pendingWrites.get(t)))return s.lastChange=new Date,this;if(r.atomic){if(e===X)return this._pendingUnlinks.set(t,[e,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(L,...e),this._pendingUnlinks.delete(t)})},"number"==typeof r.atomic?r.atomic:100),this;e===K&&this._pendingUnlinks.has(t)&&(e=G,this._pendingUnlinks.delete(t))}if(n&&(e===K||e===G)&&this._readyEmitted){let i=(t,i)=>{t?(e=Q,a[0]=t,this.emitWithAll(e,a)):i&&(a.length>1?a[1]=i:a.push(i),this.emitWithAll(e,a))};return this._awaitWriteFinish(t,n.stabilityThreshold,e,i),this}if(e===G&&!this._throttle(G,t,50))return this;if(r.alwaysStat&&void 0===i&&(e===K||e===V||e===G)){let e,i=r.cwd?v.join(r.cwd,t):t;try{e=await (0,E.stat)(i)}catch(e){}if(!e||this.closed)return;a.push(e)}return this.emitWithAll(e,a),this}_handleError(e){let t=e&&e.code;return e&&"ENOENT"!==t&&"ENOTDIR"!==t&&(!this.options.ignorePermissionErrors||"EPERM"!==t&&"EACCES"!==t)&&this.emit(Q,e),e||this.closed}_throttle(e,t,i){let s;this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error("invalid throttle");let a=r.get(t);if(a)return a.count++,!1;let n=()=>{let e=r.get(t),i=e?e.count:0;return r.delete(t),clearTimeout(s),e&&clearTimeout(e.timeoutObject),i},o={timeoutObject:s=setTimeout(n,i),clear:n,count:0};return r.set(t,o),o}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,t,i,s){let r,a=this.options.awaitWriteFinish;if("object"!=typeof a)return;let n=a.pollInterval,o=e;this.options.cwd&&!v.isAbsolute(e)&&(o=v.join(this.options.cwd,e));let l=new Date,h=this._pendingWrites;h.has(e)||(h.set(e,{lastChange:l,cancelWait:()=>(h.delete(e),clearTimeout(r),i)}),r=setTimeout(function i(a){(0,b.stat)(o,(o,l)=>{if(o||!h.has(e)){o&&"ENOENT"!==o.code&&s(o);return}let d=Number(new Date);a&&l.size!==a.size&&(h.get(e).lastChange=d),d-h.get(e).lastChange>=t?(h.delete(e),s(void 0,l)):r=setTimeout(i,n,l)})},n))}_isIgnored(e,t){if(this.options.atomic&&ew.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=(this.options.ignored||[]).map(eR(e)),i=[...[...this._ignoredPaths].map(eR(e)),...t];this._userIgnored=function(e,t){if(null==e)throw TypeError("anymatch: specify first argument");let i=eg(e).map(e=>"function"==typeof e?e:"string"==typeof e?t=>e===t:e instanceof RegExp?t=>e.test(t):"object"==typeof e&&null!==e?t=>{if(e.path===t)return!0;if(e.recursive){let i=v.relative(e.path,t);return!!i&&!i.startsWith("..")&&!v.isAbsolute(i)}return!1}:()=>!1);return null==t?(e,t)=>ey(i,e,t):ey(i,t)}(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new eD(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=v.resolve(e);return this._watched.has(t)||this._watched.set(t,new eC(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return!!this.options.ignorePermissionErrors||!!(256&Number(e.mode))}_remove(e,t,i){let s=v.join(e,t),r=v.resolve(s);if(i=null!=i?i:this._watched.has(s)||this._watched.has(r),!this._throttle("remove",s,100))return;i||1!==this._watched.size||this.add(e,t,!0),this._getWatchedDir(s).getChildren().forEach(e=>this._remove(s,e));let a=this._getWatchedDir(e),n=a.has(t);a.remove(t),this._symlinkPaths.has(r)&&this._symlinkPaths.delete(r);let o=s;if(this.options.cwd&&(o=v.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(o)&&this._pendingWrites.get(o).cancelWait()===K)return;this._watched.delete(s),this._watched.delete(r);let l=i?J:X;n&&!this._isIgnored(s)&&this._emit(l,s),this._closePath(s)}_closePath(e){this._closeFile(e);let t=v.dirname(e);this._getWatchedDir(t).remove(v.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let i=this._closers.get(e);i||(i=[],this._closers.set(e,i)),i.push(t)}_readdirp(e,t){if(this.closed)return;let i=function(e,t={}){let i=t.entryType||t.type;if("both"===i&&(i=C),i&&(t.type=i),e){if("string"!=typeof e)throw TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");else if(i&&!I.includes(i))throw Error(`readdirp: Invalid type passed. Use one of ${I.join(", ")}`)}else throw Error("readdirp: root argument is required. Usage: readdirp(root, options)");return t.root=e,new N(t)}(e,{type:L,alwaysStat:!0,lstat:!0,...t,depth:0});return this._streams.add(i),i.once("close",()=>{i=void 0}),i.once("end",()=>{i&&(this._streams.delete(i),i=void 0)}),i}}var ek=e.i(57405),eI=e.i(23318);let eA=[".next",".turbo","node_modules"],eW=["HEAD","index","packed-refs","refs"],eT=()=>void 0,eF=(e,t)=>{for(let i of e.subscribers)i(t)},eN=(e,t,i)=>{0!==e.subscribers.size&&(e.pendingChange={event:t,path:i},e.timer&&clearTimeout(e.timer),e.timer=setTimeout(()=>(e=>{let{pendingChange:t}=e;e.pendingChange=null,e.timer=null,t&&0!==e.subscribers.size&&((0,eI.invalidateGitCache)(e.repoPath),e.eventId+=1,eF(e,{createdAt:new Date().toISOString(),event:t.event,id:e.eventId,path:t.path,repoPath:e.repoPath,type:"change"}))})(e),150))},eO=new TextEncoder;e.s(["GET",0,e=>{if("1"===process.env.DIFFHUB_DISABLE_WATCH)return new Response(null,{status:204});let t=(0,g.getConfiguredRepoPath)(),i=null,s=null,r=null,a=!1,n=()=>{if(!a){a=!0,e.signal.removeEventListener("abort",n),r&&(clearInterval(r),r=null),s?.(),s=null;try{i?.close()}catch{}}};return new Response(new ReadableStream({cancel(){n()},start(o){i=o;let l=(e,t)=>{!a&&o.enqueue(eO.encode(`event: ${e}
|
|
2
|
-
data: ${JSON.stringify(t)}
|
|
3
|
-
|
|
4
|
-
`))};e.signal.addEventListener("abort",n,{once:!0}),s=((e,t)=>{let i;if("1"===process.env.DIFFHUB_DISABLE_WATCH)return eT;let s=(i=globalThis,i.__diffhubRepoWatchRuntimeState??={entries:new Map},i.__diffhubRepoWatchRuntimeState),r=s.entries.get(e);return r||(r=(e=>{let t,i={eventId:0,pendingChange:null,repoPath:e,subscribers:new Set,timer:null,watcher:function(e,t={}){let i=new eS(t);return i.add(e),i}((t=(0,ek.getGitDirectory)(e),[e,...eW.map(e=>(0,v.join)(t,e))]),{atomic:!0,ignoreInitial:!0,ignored:t=>((e,t)=>{let i=t.endsWith("/")?t:`${t}/`,s=(e.startsWith(i)?e.slice(i.length):e).replaceAll("\\","/");if(!s||s.startsWith(".."))return!1;for(let e of eA)if(s===e||s.startsWith(`${e}/`))return!0;return!(!(".git"===s||s.startsWith(".git/"))||".git/HEAD"===s||".git/index"===s||".git/packed-refs"===s||".git/refs"===s||s.startsWith(".git/refs/"))})(t,e),persistent:!0})};for(let e of["add","addDir","change","unlink","unlinkDir"])i.watcher.on(e,t=>eN(i,e,t??null));return i.watcher.on("error",t=>{i.eventId+=1,eF(i,{createdAt:new Date().toISOString(),error:t instanceof Error?t.message:String(t),id:i.eventId,repoPath:e,type:"error"})}),i})(e),s.entries.set(e,r)),r.subscribers.add(t),()=>{let i=s.entries.get(e);i&&(i.subscribers.delete(t),0===i.subscribers.size)&&(s.entries.delete(e),i.timer&&(clearTimeout(i.timer),i.timer=null),i.subscribers.clear(),(async()=>{try{await i.watcher.close()}catch(e){console.error("[diffhub] failed to close repo watcher",{error:e})}})())}})(t,e=>{l("error"===e.type?"watch-error":"change",{createdAt:e.createdAt,id:e.id})}),l("ready",{}),r=setInterval(()=>{a||o.enqueue(eO.encode(`: keep-alive
|
|
5
|
-
|
|
6
|
-
`))},25e3)}}),{headers:{"Cache-Control":"no-cache, no-transform",Connection:"keep-alive","Content-Type":"text/event-stream; charset=utf-8","X-Accel-Buffering":"no"}})},"dynamic",0,"force-dynamic","runtime",0,"nodejs"],57106);var ej=e.i(57106);let eM=new t.AppRouteRouteModule({definition:{kind:i.RouteKind.APP_ROUTE,page:"/api/watch/route",pathname:"/api/watch",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/apps/cli/app/api/watch/route.ts",nextConfigOutput:"standalone",userland:ej,...{}}),{workAsyncStorage:ez,workUnitAsyncStorage:eH,serverHooks:eU}=eM;async function eq(e,t,s){s.requestMeta&&(0,r.setRequestMeta)(e,s.requestMeta),eM.isDev&&(0,r.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let g="/api/watch/route";g=g.replace(/\/index$/,"")||"/";let v=await eM.prepare(e,t,{srcPage:g,multiZoneDraftMode:!1});if(!v)return t.statusCode=400,t.end("Bad Request"),null==s.waitUntil||s.waitUntil.call(s,Promise.resolve()),null;let{buildId:y,params:b,nextConfig:E,parsedUrl:P,isDraftMode:R,prerenderManifest:x,routerServerContext:C,isOnDemandRevalidate:D,revalidateOnlyGenerated:S,resolvedPathname:k,clientReferenceManifest:I,serverActionsManifest:A}=v,W=(0,o.normalizeAppPath)(g),T=!!(x.dynamicRoutes[W]||x.routes[k]),F=async()=>((null==C?void 0:C.render404)?await C.render404(e,t,P,!1):t.end("This page could not be found"),null);if(T&&!R){let e=!!x.routes[k],t=x.dynamicRoutes[W];if(t&&!1===t.fallback&&!e){if(E.adapterPath)return await F();throw new w.NoFallbackError}}let N=null;!T||eM.isDev||R||(N="/index"===(N=k)?"/":N);let O=!0===eM.isDev||!T,j=T&&!O;A&&I&&(0,n.setManifestsSingleton)({page:g,clientReferenceManifest:I,serverActionsManifest:A});let M=e.method||"GET",z=(0,a.getTracer)(),H=z.getActiveScopeSpan(),U=!!(null==C?void 0:C.isWrappedByNextServer),q=!!(0,r.getRequestMeta)(e,"minimalMode"),$=(0,r.getRequestMeta)(e,"incrementalCache")||await eM.getIncrementalCache(e,E,x,q);null==$||$.resetRequestCache(),globalThis.__incrementalCache=$;let L={params:b,previewProps:x.preview,renderOpts:{experimental:{authInterrupts:!!E.experimental.authInterrupts},cacheComponents:!!E.cacheComponents,supportsDynamicResponse:O,incrementalCache:$,cacheLifeProfiles:E.cacheLife,waitUntil:s.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,i,s,r)=>eM.onRequestError(e,t,s,r,C)},sharedContext:{buildId:y}},B=new l.NodeNextRequest(e),K=new l.NodeNextResponse(t),G=h.NextRequestAdapter.fromNodeNextRequest(B,(0,h.signalFromNodeResponse)(t));try{let r,n=async e=>eM.handle(G,L).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let i=z.getRootSpanAttributes();if(!i)return;if(i.get("next.span_type")!==d.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${i.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let s=i.get("next.route");if(s){let t=`${M} ${s}`;e.setAttributes({"next.route":s,"http.route":s,"next.span_name":t}),e.updateName(t),r&&r!==e&&(r.setAttribute("http.route",s),r.updateName(t))}else e.updateName(`${M} ${g}`)}),o=async r=>{var a,o;let l=async({previousCacheEntry:i})=>{try{if(!q&&D&&S&&!i)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let a=await n(r);e.fetchMetrics=L.renderOpts.fetchMetrics;let o=L.renderOpts.pendingWaitUntil;o&&s.waitUntil&&(s.waitUntil(o),o=void 0);let l=L.renderOpts.collectedTags;if(!T)return await (0,u.sendResponse)(B,K,a,L.renderOpts.pendingWaitUntil),null;{let e=await a.blob(),t=(0,p.toNodeOutgoingHttpHeaders)(a.headers);l&&(t[m.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let i=void 0!==L.renderOpts.collectedRevalidate&&!(L.renderOpts.collectedRevalidate>=m.INFINITE_CACHE)&&L.renderOpts.collectedRevalidate,s=void 0===L.renderOpts.collectedExpire||L.renderOpts.collectedExpire>=m.INFINITE_CACHE?void 0:L.renderOpts.collectedExpire;return{value:{kind:_.CachedRouteKind.APP_ROUTE,status:a.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:i,expire:s}}}}catch(t){throw(null==i?void 0:i.isStale)&&await eM.onRequestError(e,t,{routerKind:"App Router",routePath:g,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:j,isOnDemandRevalidate:D})},!1,C),t}},h=await eM.handleResponse({req:e,nextConfig:E,cacheKey:N,routeKind:i.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:x,isRoutePPREnabled:!1,isOnDemandRevalidate:D,revalidateOnlyGenerated:S,responseGenerator:l,waitUntil:s.waitUntil,isMinimalMode:q});if(!T)return null;if((null==h||null==(a=h.value)?void 0:a.kind)!==_.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==h||null==(o=h.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});q||t.setHeader("x-nextjs-cache",D?"REVALIDATED":h.isMiss?"MISS":h.isStale?"STALE":"HIT"),R&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let d=(0,p.fromNodeOutgoingHttpHeaders)(h.value.headers);return q&&T||d.delete(m.NEXT_CACHE_TAGS_HEADER),!h.cacheControl||t.getHeader("Cache-Control")||d.get("Cache-Control")||d.set("Cache-Control",(0,f.getCacheControlHeader)(h.cacheControl)),await (0,u.sendResponse)(B,K,new Response(h.value.body,{headers:d,status:h.value.status||200})),null};U&&H?await o(H):(r=z.getActiveScopeSpan(),await z.withPropagatedContext(e.headers,()=>z.trace(d.BaseServerSpan.handleRequest,{spanName:`${M} ${g}`,kind:a.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},o),void 0,!U))}catch(t){if(t instanceof w.NoFallbackError||await eM.onRequestError(e,t,{routerKind:"App Router",routePath:W,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:j,isOnDemandRevalidate:D})},!1,C),T)throw t;return await (0,u.sendResponse)(B,K,new Response(null,{status:500})),null}}e.s(["handler",0,eq,"patchFetch",0,function(){return(0,s.patchFetch)({workAsyncStorage:ez,workUnitAsyncStorage:eH})},"routeModule",0,eM,"serverHooks",0,eU,"workAsyncStorage",0,ez,"workUnitAsyncStorage",0,eH],14916)}];
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__01oij46._.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
module.exports=[18622,(e,t,r)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},70406,(e,t,r)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},93695,(e,t,r)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},2157,(e,t,r)=>{t.exports=e.x("node:fs",()=>require("node:fs"))},16781,e=>{"use strict";var t=e.i(2157);let r="/tmp/diffhub-active-repo";e.s(["REPO_POINTER",0,r,"getConfiguredRepoPath",0,()=>{if(process.env.DIFFHUB_REPO)return process.env.DIFFHUB_REPO;let e=(()=>{try{let e=(0,t.readFileSync)(r,"utf-8").trim();if(e)return e}catch{}return null})();return e||process.cwd()}])},50227,(e,t,r)=>{t.exports=e.x("node:path",()=>require("node:path"))},57405,e=>{"use strict";var t=e.i(2157),r=e.i(50227);let i="gitdir:";class n extends Error{constructor(e){super(`Invalid repo-relative path: ${e}`),this.name="InvalidRepoFilePathError"}}e.s(["InvalidRepoFilePathError",0,n,"getGitDirectory",0,e=>{let n=(0,r.join)(e,".git");if(!(0,t.existsSync)(n)||(0,t.lstatSync)(n).isDirectory())return n;let a=(0,t.readFileSync)(n,"utf-8").trim();if(!a.startsWith(i))return n;let s=a.slice(i.length).trim();return(0,r.resolve)((0,r.dirname)(n),s)},"resolveRepoFilePath",0,(e,t)=>{if(!t||(0,r.isAbsolute)(t))throw new n(t);let i=(0,r.resolve)(e,t),a=(0,r.relative)(e,i);if(a.startsWith("..")||(0,r.isAbsolute)(a))throw new n(t);return i}])},60526,(e,t,r)=>{t.exports=e.x("node:os",()=>require("node:os"))},74533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},66680,(e,t,r)=>{t.exports=e.x("node:crypto",()=>require("node:crypto"))},23318,e=>{"use strict";var t=e.i(74533),r=e.i(66680),i=e.i(2157),n=e.i(60526),a=e.i(50227),s=e.i(57405),o=e.i(16781);let l=(()=>{let e=globalThis;if(!e.__diffhubGitRuntimeState){let t=process.env.DIFFHUB_SERVER_BOOT_ID;e.__diffhubGitRuntimeState={cache:new Map,gitCommandQueue:Promise.resolve(),inflight:new Map,lastPointerMtime:0,serverBootId:t??(0,r.createHash)("sha1").update(`${process.pid}:${Date.now()}:${Math.random()}`).digest("hex")}}return e.__diffhubGitRuntimeState})(),{cache:d,inflight:c}=l,f=["main","master","develop","dev"],u="1"===process.env.DIFFHUB_DEBUG,p=e=>`diffhub-snapshot-${(0,r.createHash)("sha1").update(e).digest("hex")}-`,h=(e,t,i,s)=>{let o=JSON.stringify({base:t??"",mode:i??"",whitespace:s??""}),l=(0,r.createHash)("sha1").update(o).digest("hex");return(0,a.join)((0,n.tmpdir)(),`${p(e)}${l}.json`)},m=e=>{if(!e)return void d.clear();let t=`:${e}`;for(let e of d.keys())e.includes(t)&&d.delete(e)},g=e=>{if(m(e),"1"!==process.env.DIFFHUB_CMUX||"1"===process.env.DIFFHUB_EXTERNAL_SNAPSHOT_WRITER)return;if(!e){for(let e of(0,i.readdirSync)((0,n.tmpdir)()))e.startsWith("diffhub-snapshot-")&&(0,i.rmSync)((0,a.join)((0,n.tmpdir)(),e),{force:!0});return}let t=p(e);for(let e of(0,i.readdirSync)((0,n.tmpdir)()))e.startsWith(t)&&(0,i.rmSync)((0,a.join)((0,n.tmpdir)(),e),{force:!0})},w=async(e,t,r)=>{try{let e=(0,i.statSync)(o.REPO_POINTER).mtimeMs;e!==l.lastPointerMtime&&(l.lastPointerMtime=e,"1"===process.env.DIFFHUB_EXTERNAL_SNAPSHOT_WRITER?m():g())}catch{}let n=d.get(e);if(n&&n.expires>Date.now())return n.value;let a=await r();return d.set(e,{expires:Date.now()+t,value:a}),a},x=()=>(0,o.getConfiguredRepoPath)(),b=async e=>{let r=Date.now();u&&console.info("[diffhub] git command start",{args:e});try{let i,n,{promise:a,reject:s,resolve:o}={promise:new Promise((e,t)=>{i=e,n=t}),reject:n,resolve:i};{let r=(0,t.spawn)("git",e,{cwd:x(),env:{...process.env,GIT_TERMINAL_PROMPT:"0"},stdio:["ignore","pipe","pipe"]}),i=[],n=[],a=0,l=!1,d=e=>{l||(l=!0,e())},c=(t,i)=>{let n=Buffer.isBuffer(i)?i:Buffer.from(i);if((a+=n.length)>0x1400000){r.kill("SIGKILL"),d(()=>{s(Error(`git ${e.join(" ")} failed: output exceeded 20971520 bytes`))});return}t.push(n)};r.stdout.on("data",e=>{c(i,e)}),r.stderr.on("data",e=>{c(n,e)}),r.on("error",e=>{d(()=>s(e))}),r.on("close",t=>{let r=Buffer.concat(i).toString("utf-8"),a=Buffer.concat(n).toString("utf-8").trim();0===t?d(()=>o(r)):d(()=>{s(Object.assign(Error(a||`git ${e.join(" ")} failed with exit code ${t??"unknown"}`),{code:t,status:t??void 0,stderr:a}))})})}let l=await a;return u&&console.info("[diffhub] git command success",{args:e,durationMs:Date.now()-r}),l}catch(i){let t="string"==typeof i.stderr?i.stderr.trim():i.stderr?.toString("utf-8").trim()||"";if(console.error("[diffhub] git command failed",{args:e,code:i.code,durationMs:Date.now()-r,error:i,status:i.status,stderr:t||null}),i instanceof Error&&!t)throw i;throw Error(t||`git ${e.join(" ")} failed: ${i.message}`,{cause:i})}},y=async e=>{let t,r=new Promise(e=>{t=e}),i=l.gitCommandQueue;l.gitCommandQueue=r,await i;try{return await b(e)}finally{t()}},v=e=>e.split("\n").map(e=>e.trim()).filter(Boolean),B=e=>(0,r.createHash)("sha1").update(e).digest("hex"),F=(e,t,r,n,a)=>{if("1"!==process.env.DIFFHUB_CMUX)return null;let s=h(e,t,r,n);try{let t=(0,i.readFileSync)(s,"utf-8"),r=JSON.parse(t),n=Date.now()-r.metadata.createdAt;if(void 0!==a&&r.generation!==a||r.metadata.bootId!==l.serverBootId||r.metadata.repoPath!==e)return u&&console.info("[diffhub] snapshot cache stale",{ageMs:n,expectedBootId:l.serverBootId,expectedGeneration:a??null,repoPath:e,snapshotBootId:r.metadata.bootId,snapshotGeneration:r.generation,snapshotRepoPath:r.metadata.repoPath,source:"disk"}),null;return u&&console.info("[diffhub] snapshot cache hit",{ageMs:Date.now()-r.metadata.createdAt,generation:r.generation,repoPath:e,source:"disk"}),{...r,patchByFile:new Map(Object.entries(r.patchByFile))}}catch{return null}},E=async(e,t,r,i,n)=>{let a=Date.now()+1e3;for(;Date.now()<a;){let a=F(e,t,r,i,n);if(a)return a;await new Promise(e=>{setTimeout(e,50)})}return null},I=(e,t,n,a)=>{let s=x(),o=`snapshot:${s}:${e??""}:${t??""}:${n??""}:${a??""}`;return w(o,15e3,()=>{let d=c.get(o);if(d)return d;let p=(async()=>{try{let o,d,c,p,m=F(s,e,t,n,a);if(m)return m;if("1"===process.env.DIFFHUB_EXTERNAL_SNAPSHOT_WRITER){let r=await E(s,e,t,n,a);if(r)return r;console.warn("[diffhub] external snapshot unavailable, recomputing inline",{expectedGeneration:a??null,mode:t??"all",repoPath:s,whitespace:n??"default"})}let g=(await y(["rev-parse","--abbrev-ref","HEAD"])).trim(),b="uncommitted"===t?"HEAD":e??process.env.DIFFHUB_BASE??await (o=x(),w(`baseBranch:${o}`,3e4,async()=>{let e=v(await y(["branch","-r","--format=%(refname:short)"]));for(let t of f)if(e.includes(`origin/${t}`))return`origin/${t}`;let t=v(await y(["branch","--format=%(refname:short)"]));for(let e of f)if(t.includes(e))return e;return"origin/main"})),B="uncommitted"===t?"HEAD":await (d=x(),w(`mergeBase:${d}:${b}`,3e4,async()=>(await y(["merge-base","HEAD",b])).trim())),I=(c=[B],"ignore"===n?["-w",...c]:c),[D,$]=await Promise.all([y(["diff",...I]),y(["diff","--numstat","-z","-M",...I])]),R=(0,r.createHash)("sha1").update(D).digest("hex"),_=(e=>{let t=[],r=0,i=0,n=0;for(;n<e.length;){let a=e.indexOf(" ",n);if(-1===a)break;let s=e.indexOf(" ",a+1);if(-1===s)throw Error("Malformed git diff --numstat output");let o=e.slice(n,a),l=e.slice(a+1,s),d="";if("\0"===e[n=s+1]){n+=1;let t=e.indexOf("\0",n);if(-1===t)throw Error("Malformed git diff --numstat rename output");n=t+1;let r=e.indexOf("\0",n);if(-1===r)throw Error("Malformed git diff --numstat rename output");d=e.slice(n,r),n=r+1}else{let t=e.indexOf("\0",n);if(-1===t)throw Error("Malformed git diff --numstat output");d=e.slice(n,t),n=t+1}let c="-"===o||"-"===l,f=c?0:Number.parseInt(o,10)||0,u=c?0:Number.parseInt(l,10)||0;t.push({binary:c,changes:f+u,deletions:u,file:d,insertions:f}),r+=f,i+=u}return{deletions:i,files:t,insertions:r}})($),S=Date.now(),P=(p=l.serverBootId,(0,r.createHash)("sha1").update(`${p}:${R}:${B}`).digest("hex")),O={baseBranch:b,branch:g,deletions:_.deletions,files:_.files,fingerprint:R,fullPatch:D,generation:P,insertions:_.insertions,mergeBase:B,metadata:{bootId:l.serverBootId,createdAt:S,repoPath:s},patchByFile:(e=>{let t=new Map,r=/^diff --git a\/(.+?) b\/(.+)$/gm,i=[],n=r.exec(e);for(;n;)i.push({file:n[2],start:n.index}),n=r.exec(e);for(let[r,n]of i.entries()){let a=i[r+1]?.start??e.length,s=e.slice(n.start,a).trimEnd();t.set(n.file,s?`${s}
|
|
2
|
-
`:"")}return t})(D)};return u&&console.info("[diffhub] snapshot cache miss",{generation:P,repoPath:s,source:"recomputed"}),((e,t,r,n,a)=>{if("1"!==process.env.DIFFHUB_CMUX)return;let s={...a,patchByFile:Object.fromEntries(a.patchByFile)};(0,i.writeFileSync)(h(e,t,r,n),JSON.stringify(s),"utf-8"),u&&console.info("[diffhub] snapshot cache wrote",{generation:a.generation,repoPath:e,source:"disk"})})(s,e,t,n,O),O}finally{c.delete(o)}})();return c.set(o,p),p})},D=async(e,t,r,i,n)=>{let a=await I(t,r,i,n),s=a.patchByFile.get(e)??"";return{baseBranch:a.baseBranch,branch:a.branch,fingerprint:a.fingerprint,generation:a.generation,mergeBase:a.mergeBase,patch:s,reviewKey:B(s)}},$=async(e,t,r,i)=>{let n=await I(e,t,r,i),a=Object.fromEntries(n.patchByFile),s=Object.fromEntries(Object.entries(a).map(([e,t])=>[e,B(t)]));return{baseBranch:n.baseBranch,branch:n.branch,deletions:n.deletions,files:n.files,fingerprint:n.fingerprint,generation:n.generation,insertions:n.insertions,mergeBase:n.mergeBase,patchByFile:a,reviewKeyByFile:s}},R=async(e,t,r)=>{let i=await I(e,t,r);return{baseBranch:i.baseBranch,branch:i.branch,deletions:i.deletions,files:i.files,fingerprint:i.fingerprint,generation:i.generation,insertions:i.insertions}},_=async e=>{await y(["restore","--staged","--worktree","--",e])};e.s(["discardFile",0,_,"getDiffForFile",0,D,"getDiffStats",0,R,"getFileAtRef",0,(e,t)=>{let r=x();if("WORKING_TREE"===t)try{return Promise.resolve((0,i.readFileSync)((0,s.resolveRepoFilePath)(r,e),"utf-8"))}catch{return Promise.resolve("")}return w(`file:${r}:${t}:${e}`,3e4,async()=>{try{return await y(["show",`${t}:${e}`])}catch{return""}})},"getMultiFileDiff",0,$,"invalidateGitCache",0,g],23318)}];
|
|
3
|
-
|
|
4
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__126jjll._.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|