Skip to content

Commit dad5a33

Browse files
jhedlundclaude
andauthored
fix(desktop): keep packaged frontendDist relative so Windows embeds assets (#7177)
## Root cause `tauri-command.mjs` points `frontendDist` at a `mkdtemp` directory so concurrent OSS/internal packages cannot overwrite each other's assets. On Windows that is an absolute path with a drive letter. `FrontendDist` is an untagged serde enum whose **first** variant is `Url(Url)`, and `C:\Users\...` is a valid WHATWG URL with scheme `c:`, so serde selects `Url`. `tauri-codegen` then does: FrontendDist::Url(_url) => Default::default(), // embed nothing A missing *directory* panics with a clear message; a URL is silent. The build exits 0 and produces an installable app with no frontend assets, which boots to `ERR_FILE_NOT_FOUND` in the WebView. Linux and macOS are unaffected — `/tmp/...` has no scheme, so it falls through to `Directory`. This affects every Windows build that goes through `pnpm tauri build`, including `release.yml`'s NSIS job and `windows-canary.yml`. ## Fix Pass the path relative to the config's own directory. `tauri-codegen` resolves `frontendDist` with `config_parent.join(path)`, so a relative path reaches the same directory and cannot parse as a URL. When the temp directory is on another drive there is no relative form, so the scratch root is created beside the config instead. `BUZZ_PROTECTED_BUILD_OUTPUT` still receives the absolute path, and cleanup is unchanged. ## Testing `tauriCommand.test.mjs` asserted against the value it had just been handed, so it could not observe this. Its fake CLI also resolved `frontendDist` against the process cwd, which is not what Tauri does. - Fake CLI now resolves against the config directory, matching `config_parent.join(path)`. - New case asserts the packaged `frontendDist` is not absolute and does not parse as a URL. The absolute check is what fails on Linux/macOS, so the regression stays covered on every platform. - Verified the new case fails on the unpatched wrapper and passes with the fix; the two existing cases pass either way. - Desktop suite: 5844 passed. `useDocumentVisible` has a pre-existing load-dependent flake that also reproduces on an unmodified checkout. - Biome check clean on both files. Verified end to end by rebuilding the Windows NSIS installer: embedded asset keys in `buzz-desktop.exe` went from 0 to 490, and the app launches. --------- Signed-off-by: Jeff Hedlund <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent f038cbb commit dad5a33

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

‎desktop/scripts/tauri-command.mjs‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,28 @@ export function runTauriCommand(args) {
3636
// Tauri runs beforeBuildCommand and then consumes frontendDist. Give the
3737
// entire invocation a private directory so concurrent OSS/internal packages
3838
// cannot replace one another's assets between those two operations.
39-
const invocationRoot = mkdtempSync(
39+
let invocationRoot = mkdtempSync(
4040
path.join(tmpdir(), "buzz-tauri-package-assets-"),
4141
);
42+
// `frontendDist` deserializes into an untagged enum whose first variant is a
43+
// URL, and a Windows absolute path parses as one -- `C:` becomes the scheme.
44+
// Tauri then embeds zero assets, exits 0, and the app boots to
45+
// ERR_FILE_NOT_FOUND. Hand it a path relative to the config's own directory,
46+
// which can never parse as a URL. If the temp dir is on another drive there
47+
// is no relative form, so put the scratch root beside the config instead.
48+
const configDir = path.join(desktopRoot, "src-tauri");
49+
const relativeTo = (root) =>
50+
path.relative(configDir, path.join(root, "dist"));
51+
if (path.isAbsolute(relativeTo(invocationRoot))) {
52+
rmSync(invocationRoot, { recursive: true, force: true });
53+
invocationRoot = mkdtempSync(
54+
path.join(desktopRoot, ".buzz-tauri-package-assets-"),
55+
);
56+
}
4257
const frontendDist = path.join(invocationRoot, "dist");
43-
const outputOverride = JSON.stringify({ build: { frontendDist } });
58+
const outputOverride = JSON.stringify({
59+
build: { frontendDist: relativeTo(invocationRoot) },
60+
});
4461

4562
try {
4663
const delimiterIndex = args.indexOf("--");

‎desktop/src/protectedFeatures/tauriCommand.test.mjs‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const desktopRoot = path.resolve(
1010
path.dirname(fileURLToPath(import.meta.url)),
1111
"../..",
1212
);
13+
const configDir = path.join(desktopRoot, "src-tauri");
1314
const wrapper = path.join(desktopRoot, "scripts/tauri-command.mjs");
1415
const fakeCli = path.join(tmpdir(), `buzz-fake-tauri-${process.pid}.mjs`);
1516

@@ -20,14 +21,21 @@ import path from "node:path";
2021
const args = process.argv.slice(2);
2122
const configIndex = args.lastIndexOf("--config");
2223
const override = JSON.parse(args[configIndex + 1]);
23-
const output = override.build.frontendDist;
24-
mkdirSync(output, { recursive: true });
25-
writeFileSync(path.join(output, "variant.txt"), process.env.VITE_BUZZ_BESTIE);
24+
const configured = override.build.frontendDist;
25+
// Tauri resolves frontendDist against the directory holding tauri.conf.json
26+
// (config_parent.join(path) in tauri-codegen), not against the process cwd.
27+
const output = path.resolve(process.env.BUZZ_TEST_CONFIG_DIR, configured);
28+
// Write through the producer path the wrapper publishes and read back through
29+
// the config-resolved consumer path. Doing both against one path would make the
30+
// fake agree with itself no matter where the wrapper pointed frontendDist.
31+
const producer = process.env.BUZZ_PROTECTED_BUILD_OUTPUT;
32+
mkdirSync(producer, { recursive: true });
33+
writeFileSync(path.join(producer, "variant.txt"), process.env.VITE_BUZZ_BESTIE);
2634
await new Promise((resolve) => setTimeout(resolve, 100));
2735
const observed = readFileSync(path.join(output, "variant.txt"), "utf8");
2836
writeFileSync(
2937
process.env.BUZZ_TEST_RESULT,
30-
JSON.stringify({ args, output, observed }),
38+
JSON.stringify({ args, configured, output, observed }),
3139
);
3240
`,
3341
);
@@ -42,6 +50,7 @@ function packageVariant(variant, result, runnerArguments = []) {
4250
env: {
4351
...process.env,
4452
BUZZ_TAURI_CLI_ENTRYPOINT: fakeCli,
53+
BUZZ_TEST_CONFIG_DIR: configDir,
4554
BUZZ_TEST_RESULT: result,
4655
VITE_BUZZ_BESTIE: variant,
4756
},
@@ -92,6 +101,30 @@ test("private config precedes Cargo runner arguments", async () => {
92101
assert.equal(invocation.args[delimiterIndex + 1], "--locked");
93102
assert.equal(
94103
JSON.parse(invocation.args[privateConfigIndex + 1]).build.frontendDist,
95-
invocation.output,
104+
invocation.configured,
96105
);
97106
});
107+
108+
test("private frontendDist is never mistaken for a URL", async () => {
109+
const result = path.join(
110+
tmpdir(),
111+
`buzz-tauri-frontend-dist-${process.pid}.json`,
112+
);
113+
await packageVariant("0", result);
114+
const invocation = JSON.parse(readFileSync(result, "utf8"));
115+
116+
// `FrontendDist` is an untagged enum whose first variant is `Url(Url)`, and
117+
// tauri-codegen embeds *no assets without erroring* for that variant. A
118+
// Windows absolute path parses as a URL -- `C:` becomes the scheme -- so an
119+
// absolute frontendDist produces a UI-less app that still exits 0.
120+
assert.ok(
121+
!path.isAbsolute(invocation.configured),
122+
`frontendDist must stay relative, got ${invocation.configured}`,
123+
);
124+
// Rust's `url` crate and Node's `URL` both implement the WHATWG standard, so
125+
// this is the same parse serde performs. It only rejects absolute paths on
126+
// Windows, which is why the assertion above carries the check on Linux/macOS.
127+
assert.throws(() => new URL(invocation.configured));
128+
// The relative path still has to reach the directory the wrapper published.
129+
assert.equal(invocation.observed, "0");
130+
});

0 commit comments

Comments
 (0)