mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-14 16:07:52 +00:00
fix(dev): apply the worktree's Vite URL when dev:app is given a project path (#3212)
`pnpm dev:app <path>` 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.
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
+13
-2
@@ -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 <project path>` 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",
|
||||
|
||||
Reference in New Issue
Block a user