mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-12-04 15:51:04 +00:00
chore(dev): replace dogfood:build/install with dogfood:local and dogfood:all (#5271)
dogfood:local builds and installs the local dogfood app (--build-only skips installation); dogfood:all <remote_name> runs it alongside dogfood:remote in parallel with [local]/[remote] prefixed output, validates the SSH configuration before the local build starts, stops the sibling process tree on failure, and runs the remote restart prompt once after both finish. AGENTS.md, mise tasks and the setup docs use the new names. Co-authored-by: dengliu <5108773+dengliu@users.noreply.github.com>
This commit is contained in:
1 parent
397522e099
commit
aee72d994e
8 files changed
+326
-55
No files matched your search
@@ -79,8 +79,9 @@ Shared agent skills live in `.agents/skills/` (`.claude/skills/` links to them):
|
||||
`pnpm dev:app` also enables the global Tauri API. `pnpm dev:status` reports
|
||||
this worktree's running MCP bridges and actual ports.
|
||||
- `pnpm build` — typecheck + bundle frontend.
|
||||
- `pnpm dogfood:build` / `pnpm dogfood:install` (or `mise run dogfood:build` / `mise run dogfood:install`) — build and locally install the grey-icon dogfood desktop app sharing release settings and data.
|
||||
- `pnpm dogfood:local [--build-only]` (or `mise run dogfood:local`) — build and locally install the grey-icon dogfood desktop app sharing release settings and data.
|
||||
- `pnpm dogfood:remote <remote_name> [--restart | --no-restart] [--clean]` (or `mise run dogfood:remote <remote_name>`) — sync backend sources to a host from **Tools › SSH Configurations**, build `openidea-server`, and stage it for Remote Development.
|
||||
- `pnpm dogfood:all <remote_name> [--restart | --no-restart]` (or `mise run dogfood:all <remote_name>`) — run `dogfood:local` and `dogfood:remote <remote_name>` in parallel.
|
||||
- `cargo nextest run --workspace` (or `cargo test`), `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt --all`.
|
||||
- `cargo test -p ide-host --test language_smoke -- --ignored --exact <language>` — code intelligence
|
||||
on `fixtures/` with that language's real server installed (CI: `Language smoke`, pinned versions).
|
||||
|
||||
@@ -67,7 +67,7 @@ mise run dev
|
||||
|
||||
`setup` runs `pnpm install` in this worktree. `dev` and `dev:app` use the same worktree-aware launchers as the direct commands. No shell activation is needed for `mise run`.
|
||||
|
||||
Run `mise tasks` to list all tasks. `mise run build` builds the frontend (not a desktop installer); `mise run dogfood:build` and `mise run dogfood:install` build and locally install a grey-icon dogfood desktop app that shares settings and data with the release app. Only one of the two apps runs at a time, since they share one instance; settings written by the newer dogfood build can make an older release ignore the settings file. The dogfood app never updates itself: run `dogfood:install` again to pick up new changes. `mise run dogfood:remote <remote_name>` builds and stages `openidea-server` on an SSH host configured in **Tools › SSH Configurations** (`--clean` removes the override). `mise run test` runs Vitest and `cargo test --workspace`; `mise run check` runs the format, lint, type and unused-code checks, then both test suites. Neither requires nextest or the plugin WASM target.
|
||||
Run `mise tasks` to list all tasks. `mise run build` builds the frontend (not a desktop installer); `mise run dogfood:local` builds and locally installs a grey-icon dogfood desktop app (`--build-only` skips installation) that shares settings and data with the release app. Only one of the two apps runs at a time, since they share one instance; settings written by the newer dogfood build can make an older release ignore the settings file. The dogfood app never updates itself: run `dogfood:local` again to pick up new changes. `mise run dogfood:remote <remote_name>` builds and stages `openidea-server` on an SSH host configured in **Tools › SSH Configurations** (`--clean` removes the override), and `mise run dogfood:all <remote_name>` runs `dogfood:local` and `dogfood:remote <remote_name>` in parallel. `mise run test` runs Vitest and `cargo test --workspace`; `mise run check` runs the format, lint, type and unused-code checks, then both test suites. Neither requires nextest or the plugin WASM target.
|
||||
|
||||
## Worktrees
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ mise run dev
|
||||
|
||||
`setup` 在当前 worktree 中执行 `pnpm install`。`dev` 和 `dev:app` 都沿用原来的启动脚本,保留 worktree 隔离。使用 `mise run` 不需要在 shell 中激活 mise。
|
||||
|
||||
运行 `mise tasks` 可以查看全部任务。`mise run build` 构建前端,不生成桌面安装包;`mise run dogfood:build` 和 `mise run dogfood:install` 用于构建并在本地安装灰色图标的 dogfood 桌面版(与正式版共享设置和数据)。两者共用同一个实例,同一时间只能运行一个;较新的 dogfood 版写入的设置可能让较旧的正式版忽略整个设置文件。dogfood 版不会自动更新,需要更新时重新运行 `dogfood:install`。`mise run dogfood:remote <remote_name>` 在 **工具 › SSH 配置** 中指定的远程主机上构建并部署 `openidea-server`(`--clean` 可移除覆盖)。`mise run test` 运行 Vitest 和 `cargo test --workspace`;`mise run check` 先检查格式、代码规范、类型和未使用的代码,再运行这两套测试。两者都不需要 nextest 或插件的 WASM 目标。
|
||||
运行 `mise tasks` 可以查看全部任务。`mise run build` 构建前端,不生成桌面安装包;`mise run dogfood:local` 用于构建并在本地安装灰色图标的 dogfood 桌面版(与正式版共享设置和数据;`--build-only` 仅构建不安装)。两者共用同一个实例,同一时间只能运行一个;较新的 dogfood 版写入的设置可能让较旧的正式版忽略整个设置文件。dogfood 版不会自动更新,需要更新时重新运行 `dogfood:local`。`mise run dogfood:remote <remote_name>` 在 **工具 › SSH 配置** 中指定的远程主机上构建并部署 `openidea-server`(`--clean` 可移除覆盖),`mise run dogfood:all <remote_name>` 则并行执行 `dogfood:local` 与 `dogfood:remote <remote_name>`。`mise run test` 运行 Vitest 和 `cargo test --workspace`;`mise run check` 先检查格式、代码规范、类型和未使用的代码,再运行这两套测试。两者都不需要 nextest 或插件的 WASM 目标。
|
||||
|
||||
## Worktree
|
||||
|
||||
|
||||
@@ -20,19 +20,18 @@ run = "pnpm dev:app"
|
||||
description = "Typecheck, bundle and verify the frontend"
|
||||
run = "pnpm build"
|
||||
|
||||
[tasks."dogfood:build"]
|
||||
description = "Build a local dogfood desktop app bundle"
|
||||
run = "pnpm dogfood:build"
|
||||
|
||||
[tasks."dogfood:install"]
|
||||
description = "Build and install the local dogfood desktop app"
|
||||
depends = ["dogfood:build"]
|
||||
run = "pnpm dogfood:install --no-build"
|
||||
[tasks."dogfood:local"]
|
||||
description = "Build and locally install the dogfood desktop app"
|
||||
run = "pnpm dogfood:local"
|
||||
|
||||
[tasks."dogfood:remote"]
|
||||
description = "Build and install a local dogfood openidea-server on a configured SSH remote"
|
||||
run = "pnpm dogfood:remote"
|
||||
|
||||
[tasks."dogfood:all"]
|
||||
description = "Build and install the local dogfood desktop app and remote openidea-server in parallel"
|
||||
run = "pnpm dogfood:all"
|
||||
|
||||
[tasks.test]
|
||||
description = "Run the frontend and Rust workspace tests"
|
||||
run = ["pnpm test", "cargo test --workspace"]
|
||||
|
||||
+3
-3
@@ -34,9 +34,9 @@
|
||||
"perf:rust": "node perf/rust.ts",
|
||||
"eval": "node evals/run.ts",
|
||||
"release:prepare": "node scripts/release-prepare.ts",
|
||||
"dogfood:build": "node scripts/dogfood.ts build",
|
||||
"dogfood:install": "node scripts/dogfood.ts install",
|
||||
"dogfood:remote": "node scripts/dogfood-remote.ts"
|
||||
"dogfood:local": "node scripts/dogfood.ts local",
|
||||
"dogfood:remote": "node scripts/dogfood-remote.ts",
|
||||
"dogfood:all": "node scripts/dogfood.ts all"
|
||||
},
|
||||
"simple-git-hooks": {
|
||||
"pre-commit": "pnpm lint-staged"
|
||||
|
||||
+36
-10
@@ -1058,16 +1058,48 @@ async function handleRunningRemoteServers(
|
||||
}
|
||||
}
|
||||
|
||||
export async function runDogfoodRemote(root: string, cliArgs: readonly string[]) {
|
||||
const parsed = parseDogfoodRemoteArgs(cliArgs);
|
||||
export interface DogfoodRemoteTarget {
|
||||
remoteConfig: SshRemoteConfig;
|
||||
remoteContext: RemoteContext;
|
||||
sshArgs: string[];
|
||||
version: string;
|
||||
rustVersion: string;
|
||||
localDataDir: string;
|
||||
}
|
||||
|
||||
export function resolveDogfoodRemoteTarget(root: string, parsed: DogfoodRemoteArgs): DogfoodRemoteTarget {
|
||||
const { version, rustVersion } = readWorkspaceMetadata(root);
|
||||
const { configDir, localDataDir } = resolveAppDirs();
|
||||
|
||||
const envOpts = (process.env.DOGFOOD_SSH_OPTS ?? "")
|
||||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
const extraSshOpts = [...envOpts, ...parsed.sshOpts];
|
||||
const configs = loadSshConfigs(configDir, root);
|
||||
const remoteConfig = resolveSshConfig(configs, parsed.remoteName!);
|
||||
const remoteContext: RemoteContext = {
|
||||
name: remoteConfig.name,
|
||||
endpoint: formatRemoteEndpoint(remoteConfig),
|
||||
};
|
||||
const sshArgs = buildSshArgs(remoteConfig, extraSshOpts);
|
||||
return { remoteConfig, remoteContext, sshArgs, version, rustVersion, localDataDir };
|
||||
}
|
||||
|
||||
export async function finishDogfoodRemoteRestart(root: string, parsed: DogfoodRemoteArgs) {
|
||||
if (parsed.restart === "never" || !parsed.remoteName) return;
|
||||
const { remoteContext, sshArgs, version, localDataDir } = resolveDogfoodRemoteTarget(root, parsed);
|
||||
const { os, arch } = probeRemote(sshArgs, remoteContext);
|
||||
const markerPath = join(localDataDir, "server", version, `${os}-${arch}`, DOGFOOD_MARKER_FILE);
|
||||
if (!existsSync(markerPath)) return;
|
||||
const buildId = readFileSync(markerPath, "utf8").trim();
|
||||
if (!buildId) return;
|
||||
await handleRunningRemoteServers(sshArgs, remoteContext, buildId, parsed.restart);
|
||||
}
|
||||
|
||||
export async function runDogfoodRemote(root: string, cliArgs: readonly string[]) {
|
||||
const parsed = parseDogfoodRemoteArgs(cliArgs);
|
||||
const { version } = readWorkspaceMetadata(root);
|
||||
const { localDataDir } = resolveAppDirs();
|
||||
|
||||
if (parsed.clean && !parsed.remoteName) {
|
||||
const cleaned = cleanLocalDogfoodServers(localDataDir, version);
|
||||
@@ -1083,13 +1115,7 @@ export async function runDogfoodRemote(root: string, cliArgs: readonly string[])
|
||||
return;
|
||||
}
|
||||
|
||||
const configs = loadSshConfigs(configDir, root);
|
||||
const remoteConfig = resolveSshConfig(configs, parsed.remoteName!);
|
||||
const remoteContext: RemoteContext = {
|
||||
name: remoteConfig.name,
|
||||
endpoint: formatRemoteEndpoint(remoteConfig),
|
||||
};
|
||||
const sshArgs = buildSshArgs(remoteConfig, extraSshOpts);
|
||||
const { remoteConfig, remoteContext, sshArgs, rustVersion } = resolveDogfoodRemoteTarget(root, parsed);
|
||||
const probe = probeRemote(sshArgs, remoteContext);
|
||||
const { os, arch } = probe;
|
||||
const platformKey = `${os}-${arch}`;
|
||||
|
||||
+76
-8
@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
DEFAULT_DOGFOOD_APP_NAME,
|
||||
deferRestartArgs,
|
||||
dogfoodBuildEnv,
|
||||
dogfoodCliArgs,
|
||||
dogfoodPaths,
|
||||
@@ -13,18 +14,85 @@ import {
|
||||
generateDogfoodIcons,
|
||||
installDogfood,
|
||||
parseDogfoodArgs,
|
||||
runParallelTasks,
|
||||
} from "./dogfood.ts";
|
||||
|
||||
const root = fileURLToPath(new URL("..", import.meta.url));
|
||||
|
||||
describe("dogfood build and install", () => {
|
||||
it("parses build and install arguments, including pnpm separator flags", () => {
|
||||
expect(parseDogfoodArgs(["build"])).toEqual({ action: "build", skipBuild: false });
|
||||
expect(parseDogfoodArgs(["install"])).toEqual({ action: "install", skipBuild: false });
|
||||
expect(parseDogfoodArgs(["install", "--no-build"])).toEqual({ action: "install", skipBuild: true });
|
||||
expect(parseDogfoodArgs(["install", "--", "--no-build"])).toEqual({ action: "install", skipBuild: true });
|
||||
expect(() => parseDogfoodArgs([])).toThrow(/Expected 'build' or 'install'/);
|
||||
expect(() => parseDogfoodArgs(["build", "--no-build"])).toThrow(/Unexpected option/);
|
||||
describe("dogfood local and all", () => {
|
||||
it("parses local and all arguments, including pnpm separator flags", () => {
|
||||
expect(parseDogfoodArgs(["local"])).toEqual({ action: "local", buildOnly: false });
|
||||
expect(parseDogfoodArgs(["local", "--build-only"])).toEqual({ action: "local", buildOnly: true });
|
||||
expect(parseDogfoodArgs(["local", "--", "--build-only"])).toEqual({ action: "local", buildOnly: true });
|
||||
expect(parseDogfoodArgs(["all", "--", "my-remote", "--build-only", "--restart", "--ssh-opt", "Port=2222"])).toEqual(
|
||||
{
|
||||
action: "all",
|
||||
buildOnly: true,
|
||||
remoteArgs: ["my-remote", "--restart", "--ssh-opt", "Port=2222"],
|
||||
remote: {
|
||||
remoteName: "my-remote",
|
||||
clean: false,
|
||||
installRust: false,
|
||||
restart: "always",
|
||||
sshOpts: ["Port=2222"],
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(deferRestartArgs(["my-remote", "--restart", "--ssh-opt", "Port=2222"])).toEqual([
|
||||
"my-remote",
|
||||
"--ssh-opt",
|
||||
"Port=2222",
|
||||
"--no-restart",
|
||||
]);
|
||||
expect(() => parseDogfoodArgs([])).toThrow(/Expected 'local' or 'all'/);
|
||||
expect(() => parseDogfoodArgs(["build"])).toThrow(/Expected 'local' or 'all'/);
|
||||
expect(() => parseDogfoodArgs(["local", "my-remote"])).toThrow(/Unexpected option/);
|
||||
expect(() => parseDogfoodArgs(["all"])).toThrow(/Usage: dogfood:all <remote_name>/);
|
||||
expect(() => parseDogfoodArgs(["all", "my-remote", "--clean"])).toThrow(/dogfood:remote <remote_name> --clean/);
|
||||
});
|
||||
|
||||
it("runs parallel tasks concurrently, prefixes lines, and terminates siblings on failure", async () => {
|
||||
const out: string[] = [];
|
||||
const err: string[] = [];
|
||||
await runParallelTasks(
|
||||
[
|
||||
{
|
||||
label: "local",
|
||||
command: process.execPath,
|
||||
args: ["-e", 'process.stdout.write("step 1\\nstep "); setTimeout(() => process.stdout.write("2"), 40);'],
|
||||
},
|
||||
{
|
||||
label: "remote",
|
||||
command: process.execPath,
|
||||
args: ["-e", 'process.stderr.write("warn line\\n"); process.stdout.write("done\\n");'],
|
||||
},
|
||||
],
|
||||
{ stdout: (line) => out.push(line), stderr: (line) => err.push(line) },
|
||||
);
|
||||
expect(out).toContain("[local] step 1\n");
|
||||
expect(out).toContain("[local] step 2\n");
|
||||
expect(out).toContain("[remote] done\n");
|
||||
expect(err).toEqual(["[remote] warn line\n"]);
|
||||
|
||||
const started = Date.now();
|
||||
await expect(
|
||||
runParallelTasks(
|
||||
[
|
||||
{
|
||||
label: "local",
|
||||
command: process.execPath,
|
||||
args: ["-e", "setTimeout(() => {}, 10_000)"],
|
||||
},
|
||||
{
|
||||
label: "remote",
|
||||
command: process.execPath,
|
||||
args: ["-e", "setTimeout(() => process.exit(2), 50)"],
|
||||
},
|
||||
],
|
||||
{ stdout: () => {}, stderr: () => {} },
|
||||
),
|
||||
).rejects.toThrow(/\[remote\] exited with status 2/);
|
||||
expect(Date.now() - started).toBeLessThan(3_000);
|
||||
});
|
||||
|
||||
it("keeps the vanilla app identifier so settings, MCP, Skills and agent sessions are shared, without updates", () => {
|
||||
|
||||
+200
-23
@@ -1,4 +1,4 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { spawn, spawnSync, type ChildProcess } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
chmodSync,
|
||||
@@ -16,16 +16,29 @@ import { createRequire } from "node:module";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join, relative } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import {
|
||||
finishDogfoodRemoteRestart,
|
||||
parseDogfoodRemoteArgs,
|
||||
resolveDogfoodRemoteTarget,
|
||||
type DogfoodRemoteArgs,
|
||||
} from "./dogfood-remote.ts";
|
||||
|
||||
export const DEFAULT_DOGFOOD_APP_NAME = "openidea_dogfood";
|
||||
|
||||
const LSREGISTER_PATH =
|
||||
"/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister";
|
||||
|
||||
export interface DogfoodCommand {
|
||||
action: "build" | "install";
|
||||
skipBuild: boolean;
|
||||
}
|
||||
export type DogfoodCommand =
|
||||
| {
|
||||
action: "local";
|
||||
buildOnly: boolean;
|
||||
}
|
||||
| {
|
||||
action: "all";
|
||||
buildOnly: boolean;
|
||||
remoteArgs: string[];
|
||||
remote: DogfoodRemoteArgs;
|
||||
};
|
||||
|
||||
export interface DogfoodPaths {
|
||||
bundlePath: string;
|
||||
@@ -35,18 +48,39 @@ export interface DogfoodPaths {
|
||||
export function parseDogfoodArgs(args: readonly string[]): DogfoodCommand {
|
||||
const filtered = args.filter((arg) => arg !== "--");
|
||||
const action = filtered[0];
|
||||
if (action !== "build" && action !== "install") {
|
||||
throw new Error(`Expected 'build' or 'install', got ${action ? `'${action}'` : "no command"}`);
|
||||
if (action !== "local" && action !== "all") {
|
||||
throw new Error(`Expected 'local' or 'all', got ${action ? `'${action}'` : "no command"}`);
|
||||
}
|
||||
let skipBuild = false;
|
||||
for (const flag of filtered.slice(1)) {
|
||||
if (action === "install" && flag === "--no-build") {
|
||||
skipBuild = true;
|
||||
let buildOnly = false;
|
||||
const rest: string[] = [];
|
||||
for (const arg of filtered.slice(1)) {
|
||||
if (arg === "--build-only") {
|
||||
buildOnly = true;
|
||||
} else if (action === "local") {
|
||||
throw new Error(`Unexpected option '${arg}' for 'local'`);
|
||||
} else {
|
||||
throw new Error(`Unexpected option '${flag}' for '${action}'`);
|
||||
rest.push(arg);
|
||||
}
|
||||
}
|
||||
return { action, skipBuild };
|
||||
if (action === "local") {
|
||||
return { action: "local", buildOnly };
|
||||
}
|
||||
if (rest.includes("--clean")) {
|
||||
throw new Error("Unexpected option '--clean' for 'all'; use 'dogfood:remote <remote_name> --clean' instead");
|
||||
}
|
||||
let remote: DogfoodRemoteArgs;
|
||||
try {
|
||||
remote = parseDogfoodRemoteArgs(rest);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
throw new Error(
|
||||
message.startsWith("Usage:")
|
||||
? "Usage: dogfood:all <remote_name> [--build-only] [--install-rust] [--restart | --no-restart] [--ssh-opt key=value]"
|
||||
: message,
|
||||
{ cause: error },
|
||||
);
|
||||
}
|
||||
return { action: "all", buildOnly, remoteArgs: rest, remote };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +252,7 @@ export function buildDogfood(root: string, appName: string) {
|
||||
const SHARED_DATA_NOTES = [
|
||||
"The dogfood app shares its single instance with OpenIDEA: quit one before opening the other.",
|
||||
"It writes OpenIDEA's settings and data; a setting only newer builds know can make an older OpenIDEA ignore your settings file.",
|
||||
"It never updates itself: run 'pnpm dogfood:install' again to pick up new changes.",
|
||||
"It never updates itself: run 'pnpm dogfood:local' again to pick up new changes.",
|
||||
];
|
||||
|
||||
export function installDogfood(
|
||||
@@ -240,7 +274,7 @@ function installBundle(
|
||||
installPath: string,
|
||||
) {
|
||||
if (!existsSync(bundlePath)) {
|
||||
throw new Error(`Dogfood build output not found at ${bundlePath}; run 'mise run dogfood:build' first`);
|
||||
throw new Error(`Dogfood build output not found at ${bundlePath}; run 'mise run dogfood:local --build-only' first`);
|
||||
}
|
||||
|
||||
if (platform === "darwin") {
|
||||
@@ -297,21 +331,164 @@ function installBundle(
|
||||
console.log(`Installed ${appName} to ${installPath}`);
|
||||
}
|
||||
|
||||
function main() {
|
||||
const root = realpathSync(fileURLToPath(new URL("..", import.meta.url)));
|
||||
const { action, skipBuild } = parseDogfoodArgs(process.argv.slice(2));
|
||||
const appName = process.env.DOGFOOD_APP_NAME?.trim() || DEFAULT_DOGFOOD_APP_NAME;
|
||||
if (action === "build" || !skipBuild) {
|
||||
buildDogfood(root, appName);
|
||||
export interface ParallelTaskSpec {
|
||||
label: string;
|
||||
command: string;
|
||||
args: string[];
|
||||
cwd?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
function stopProcessTree(child: ChildProcess, signal: NodeJS.Signals) {
|
||||
if (!child.pid) return;
|
||||
if (process.platform === "win32") {
|
||||
spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" });
|
||||
} else {
|
||||
try {
|
||||
process.kill(-child.pid, signal);
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== "ESRCH") throw error;
|
||||
}
|
||||
}
|
||||
if (action === "install") {
|
||||
}
|
||||
|
||||
function pipePrefixedLines(
|
||||
stream: NodeJS.ReadableStream | null,
|
||||
prefix: string,
|
||||
writeLine: (line: string) => void,
|
||||
): Promise<void> {
|
||||
if (!stream) return Promise.resolve();
|
||||
return new Promise((resolve) => {
|
||||
let remainder = "";
|
||||
stream.setEncoding("utf8");
|
||||
stream.on("data", (chunk: string) => {
|
||||
remainder += chunk;
|
||||
let newline = remainder.indexOf("\n");
|
||||
while (newline !== -1) {
|
||||
const line = remainder.slice(0, newline).replace(/\r$/, "");
|
||||
writeLine(`[${prefix}] ${line}\n`);
|
||||
remainder = remainder.slice(newline + 1);
|
||||
newline = remainder.indexOf("\n");
|
||||
}
|
||||
});
|
||||
stream.on("end", () => {
|
||||
if (remainder.length > 0) {
|
||||
writeLine(`[${prefix}] ${remainder.replace(/\r$/, "")}\n`);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
stream.on("error", () => resolve());
|
||||
});
|
||||
}
|
||||
|
||||
export async function runParallelTasks(
|
||||
specs: readonly ParallelTaskSpec[],
|
||||
writers: {
|
||||
stdout?: (text: string) => void;
|
||||
stderr?: (text: string) => void;
|
||||
} = {},
|
||||
): Promise<void> {
|
||||
const writeOut = writers.stdout ?? ((text: string) => process.stdout.write(text));
|
||||
const writeErr = writers.stderr ?? ((text: string) => process.stderr.write(text));
|
||||
const children: ChildProcess[] = [];
|
||||
let firstError: Error | null = null;
|
||||
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const stopAll = (signal: NodeJS.Signals) => {
|
||||
for (const child of children) stopProcessTree(child, signal);
|
||||
if (signal === "SIGTERM") {
|
||||
killTimer ??= setTimeout(() => {
|
||||
for (const child of children) stopProcessTree(child, "SIGKILL");
|
||||
}, 5000);
|
||||
killTimer.unref();
|
||||
}
|
||||
};
|
||||
|
||||
const onSigint = () => stopAll("SIGTERM");
|
||||
const onSigterm = () => stopAll("SIGTERM");
|
||||
process.on("SIGINT", onSigint);
|
||||
process.on("SIGTERM", onSigterm);
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
specs.map(
|
||||
(spec) =>
|
||||
new Promise<void>((resolve) => {
|
||||
const child = spawn(spec.command, spec.args, {
|
||||
cwd: spec.cwd,
|
||||
env: spec.env,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
detached: process.platform !== "win32",
|
||||
});
|
||||
children.push(child);
|
||||
const outDone = pipePrefixedLines(child.stdout, spec.label, writeOut);
|
||||
const errDone = pipePrefixedLines(child.stderr, spec.label, writeErr);
|
||||
child.once("error", (err) => {
|
||||
if (!firstError) {
|
||||
firstError = new Error(`[${spec.label}] ${err.message}`);
|
||||
stopAll("SIGTERM");
|
||||
}
|
||||
void Promise.all([outDone, errDone]).then(() => resolve());
|
||||
});
|
||||
child.once("close", (code, signal) => {
|
||||
if (code !== 0 && !firstError) {
|
||||
firstError = new Error(
|
||||
`[${spec.label}] exited with ${code !== null ? `status ${code}` : `signal ${signal}`}`,
|
||||
);
|
||||
stopAll("SIGTERM");
|
||||
}
|
||||
void Promise.all([outDone, errDone]).then(() => resolve());
|
||||
});
|
||||
}),
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
if (killTimer) clearTimeout(killTimer);
|
||||
process.off("SIGINT", onSigint);
|
||||
process.off("SIGTERM", onSigterm);
|
||||
}
|
||||
|
||||
if (firstError) throw firstError;
|
||||
}
|
||||
|
||||
export function deferRestartArgs(remoteArgs: readonly string[]): string[] {
|
||||
return [...remoteArgs.filter((arg) => arg !== "--restart" && arg !== "--no-restart"), "--no-restart"];
|
||||
}
|
||||
|
||||
async function runDogfoodAll(root: string, command: Extract<DogfoodCommand, { action: "all" }>) {
|
||||
// Validate the SSH remote exists in settings.toml before starting the local Cargo build.
|
||||
resolveDogfoodRemoteTarget(root, command.remote);
|
||||
|
||||
const localArgs = [join(root, "scripts", "dogfood.ts"), "local"];
|
||||
if (command.buildOnly) localArgs.push("--build-only");
|
||||
|
||||
const remoteScriptArgs = [join(root, "scripts", "dogfood-remote.ts"), ...deferRestartArgs(command.remoteArgs)];
|
||||
|
||||
await runParallelTasks([
|
||||
{ label: "local", command: process.execPath, args: localArgs, cwd: root, env: process.env },
|
||||
{ label: "remote", command: process.execPath, args: remoteScriptArgs, cwd: root, env: process.env },
|
||||
]);
|
||||
|
||||
await finishDogfoodRemoteRestart(root, command.remote);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const root = realpathSync(fileURLToPath(new URL("..", import.meta.url)));
|
||||
const parsed = parseDogfoodArgs(process.argv.slice(2));
|
||||
if (parsed.action === "all") {
|
||||
await runDogfoodAll(root, parsed);
|
||||
return;
|
||||
}
|
||||
const appName = process.env.DOGFOOD_APP_NAME?.trim() || DEFAULT_DOGFOOD_APP_NAME;
|
||||
buildDogfood(root, appName);
|
||||
if (!parsed.buildOnly) {
|
||||
installDogfood(root, appName);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
|
||||
try {
|
||||
main();
|
||||
await main();
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exitCode = 1;
|
||||
|
||||
Reference in new issue
Block a user