From a4b62ad27fa63490701484a664cfdee64cd24dec Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sat, 14 Nov 2026 01:10:20 +0800 Subject: [PATCH] fix(dev): apply the worktree's Vite URL when dev:app is given a project path (#3212) `pnpm dev:app ` appended `--config {devUrl}` after the path, and `tauri dev` hands the first positional argument and everything after it to the app. The config was dropped: tauri ran `pnpm dev` on port 1420 as well, and a full reload loaded that server instead of the worktree's, failing with "Could not load startup script". The config now goes before the first positional argument. --- scripts/dev-session.test.ts | 13 +++++++++++++ scripts/dev-session.ts | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/dev-session.test.ts b/scripts/dev-session.test.ts index 4020f66b4..cee009ffc 100644 --- a/scripts/dev-session.test.ts +++ b/scripts/dev-session.test.ts @@ -92,4 +92,17 @@ describe("development worktrees", () => { expect(args.slice(-5)).toEqual(["--", "--features", "test", "--", "/project"]); expect(JSON.parse(args[4]!)).toEqual({ build: { beforeDevCommand: "", devUrl: "http://localhost:54321/" } }); }); + + it("puts the Vite URL before a project path, which tauri dev hands to the app with what follows", () => { + const config = JSON.stringify({ build: { beforeDevCommand: "", devUrl: "http://localhost:54321/" } }); + expect( + withDevConfig(["dev", "--config", "custom.json", "/project", "--verbose"], "http://localhost:54321/"), + ).toEqual(["dev", "--config", "custom.json", "--config", config, "/project", "--verbose"]); + expect(withDevConfig(["dev", "--release"], "http://localhost:54321/")).toEqual([ + "dev", + "--release", + "--config", + config, + ]); + }); }); diff --git a/scripts/dev-session.ts b/scripts/dev-session.ts index ce3dd5c99..cf92e3705 100644 --- a/scripts/dev-session.ts +++ b/scripts/dev-session.ts @@ -79,9 +79,20 @@ export async function claimSession( throw new Error("No available development session port"); } +/** `tauri dev` options that take a value as the next argument. */ +const VALUE_OPTIONS = new Set(["-c", "--config", "-t", "--target", "-f", "--features", "-r", "--runner", "--port"]); + +/** + * `args` with the session's Vite URL as the last `--config`, placed before the first + * positional argument: `tauri dev` passes everything from there on to the app, so a config + * after `pnpm dev:app ` would be ignored. + */ export function withDevConfig(args: string[], devUrl: string): string[] { - const separator = args.indexOf("--"); - const index = separator < 0 ? args.length : separator; + let index = 1; + while (index < args.length && args[index] !== "--" && args[index]!.startsWith("-")) { + index += VALUE_OPTIONS.has(args[index]!) ? 2 : 1; + } + index = Math.min(index, args.length); return [ ...args.slice(0, index), "--config",