Skip to content

Commit 10ce76a

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(desktop): ignore installed dependencies in pack watchers (#1767)
## Problem pnpm hardlink metadata changes can rebuild desktop bundles and relaunch Electron without a source edit. ## Change Wrap the pack array once to apply the existing watch exclusion to every desktop bundle: ```ts ignoreWatch: /[\\/]node_modules[\\/]/ ``` Workspace imports resolve through their symlinks to source paths outside `node_modules`, so they remain watchable. One bounded fixture build checks that installed dependencies are excluded while linked `contracts` and `shared` sources remain watchable. ## Scope and approval Refs #1614. This PR covers only the Watch condition; the historical 14:10:20 hardlink-source condition stays open. The host approved this scope and owns runtime grounding; no watcher or Electron instance was started by the worker. ## Verification - [x] Focused bundle tests: 3 passed - [x] Targeted lint and desktop typecheck - [x] Desktop production pack - [x] `vp run fork:ci`: 762 tests passed - [x] Host-owned Electron runtime grounding: below The regression test checks actual bundler-resolved paths against the configured filter, not runtime filesystem events. ## Grounding **Claim:** under `vp run dev:app --desktop`, dependency changes keep Electron running; source edits relaunch it. - **Build:** PR head `f227ae6fed` - **Client:** Electron dev app, checkout-local state - **Dependency:** bundled `effect` `Pipeable.js` | Step | Windows created | Electron | | --- | --- | --- | | launch | 1 | running | | dependency `chmod` and `touch` | 1 | same PID | | dependency hardlink (links 14 → 15) | 1 | same PID | | touch `apps/desktop/src/main.ts` | 2 | relaunched | | touch `packages/contracts/src/background.ts` | 3 | relaunched | | touch `packages/shared/src/schemaJson.ts` | 4 | relaunched | **Not grounded:** the pre-fix relaunch; no baseline run. Model: GPT Sol (`gpt-6.1-sol`). Harness: Pi. ## Fork trailers Squashes: - d27acaf fix(desktop): ignore installed dependencies in pack watchers (#1767) (#1767) - fcd9ce3 fixup! fix(desktop): ignore installed dependencies in pack watchers (#1767) (#1767) Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: yes Co-authored-by: donjor <[email protected]>
1 parent 3bb83d3 commit 10ce76a

3 files changed

Lines changed: 79 additions & 2 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import * as NodeFSP from "node:fs/promises";
2+
import * as NodeOS from "node:os";
3+
import * as NodePath from "node:path";
4+
import { build } from "vite-plus/pack";
5+
import { assert, it } from "vite-plus/test";
6+
7+
import desktopConfig from "../vite.config.ts";
8+
9+
it("ignores installed dependencies but keeps symlinked workspace sources watchable", async () => {
10+
const directory = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-pack-watch-"));
11+
try {
12+
const installed = NodePath.join(directory, "node_modules/dependency");
13+
await NodeFSP.mkdir(installed, { recursive: true });
14+
const dependencyFile = NodePath.join(installed, "index.js");
15+
await NodeFSP.writeFile(dependencyFile, "export const dependency = 1;");
16+
await NodeFSP.mkdir(NodePath.join(directory, "node_modules/@t3tools"));
17+
const workspaceFiles = [];
18+
for (const name of ["contracts", "shared"]) {
19+
const workspace = NodePath.join(directory, "packages", name);
20+
await NodeFSP.mkdir(workspace, { recursive: true });
21+
const source = NodePath.join(workspace, "index.js");
22+
await NodeFSP.writeFile(source, `export const ${name} = 1;`);
23+
workspaceFiles.push(await NodeFSP.realpath(source));
24+
await NodeFSP.symlink(
25+
workspace,
26+
NodePath.join(directory, "node_modules/@t3tools", name),
27+
"junction",
28+
);
29+
}
30+
const entry = NodePath.join(directory, "main.ts");
31+
await NodeFSP.writeFile(
32+
entry,
33+
`import { dependency } from "dependency";
34+
import { contracts } from "@t3tools/contracts";
35+
import { shared } from "@t3tools/shared";
36+
console.log(dependency + contracts + shared);`,
37+
);
38+
39+
const modules = new Set();
40+
await build({
41+
...desktopConfig.pack[0],
42+
cwd: directory,
43+
config: false,
44+
tsconfig: false,
45+
entry: [entry],
46+
write: false,
47+
onSuccess: undefined,
48+
logLevel: "silent",
49+
plugins: [
50+
{
51+
name: "inspect-watch-inputs",
52+
moduleParsed(module) {
53+
modules.add(module.id);
54+
},
55+
},
56+
],
57+
});
58+
const ignored = await NodeFSP.realpath(dependencyFile);
59+
const watched = [await NodeFSP.realpath(entry), ...workspaceFiles];
60+
for (const source of [ignored, ...watched]) assert.ok(modules.has(source), source);
61+
for (const config of desktopConfig.pack) {
62+
assert.ok(config.ignoreWatch.test(ignored));
63+
for (const source of watched) assert.ok(!config.ignoreWatch.test(source), source);
64+
}
65+
} finally {
66+
await NodeFSP.rm(directory, { recursive: true, force: true });
67+
}
68+
});

‎apps/desktop/vite.config.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defaultInclude, defineConfig } from "vite-plus";
33

44
import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
55
import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
6+
import { withDesktopPackWatchFork } from "../../scripts/lib/desktop-pack-watch.fork.ts"; // fork-hook: upstream-fixes/desktop-pack-watch-import
67

78
const repoEnv = loadRepoEnv();
89

@@ -48,7 +49,8 @@ export default defineConfig({
4849
},
4950
},
5051
},
51-
pack: [
52+
pack: withDesktopPackWatchFork([
53+
// fork-hook: upstream-fixes/desktop-pack-watch
5254
{
5355
format: "cjs",
5456
outDir: "dist-electron",
@@ -140,7 +142,7 @@ export default defineConfig({
140142
outExtensions: () => ({ js: ".cjs" }),
141143
entry: ["src/mac-permission-preload.ts"],
142144
},
143-
],
145+
]),
144146
test: {
145147
include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"],
146148
// The Windows lane runs workspace suites concurrently; filesystem-heavy
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { UserConfig } from "vite-plus/pack";
2+
3+
// pnpm store hardlinks can change ctime during another checkout's install.
4+
// Workspace symlinks resolve to source paths outside node_modules.
5+
export function withDesktopPackWatchFork(configs: UserConfig[]): UserConfig[] {
6+
return configs.map((config) => ({ ...config, ignoreWatch: /[\\/]node_modules[\\/]/ }));
7+
}

0 commit comments

Comments
 (0)