Adjust UI install for offline pnpm fetch (#568)

* 🤖 codex: make ui build install prod deps for offline pnpm (issue-pnpm-offline)

* 🤖 codex: ensure ui:test installs dev deps (issue-pnpm-offline)
This commit is contained in:
Josh Palmer
2026-01-09 13:38:46 +01:00
committed by GitHub
parent 17a7dfc966
commit 7b79823b24
3 changed files with 31 additions and 10 deletions

View File

@@ -64,21 +64,26 @@ function run(cmd, args) {
});
}
function runSync(cmd, args) {
function runSync(cmd, args, envOverride) {
const result = spawnSync(cmd, args, {
cwd: uiDir,
stdio: "inherit",
env: process.env,
env: envOverride ?? process.env,
});
if (result.signal) process.exit(1);
if ((result.status ?? 1) !== 0) process.exit(result.status ?? 1);
}
function depsInstalled() {
function depsInstalled(kind) {
try {
const require = createRequire(path.join(uiDir, "package.json"));
require.resolve("vite");
require.resolve("dompurify");
if (kind === "test") {
require.resolve("vitest");
require.resolve("@vitest/browser-playwright");
require.resolve("playwright");
}
return true;
} catch {
return false;
@@ -118,13 +123,29 @@ if (action !== "install" && !script) {
if (runner.kind === "bun") {
if (action === "install") run(runner.cmd, ["install", ...rest]);
else {
if (!depsInstalled()) runSync(runner.cmd, ["install"]);
if (!depsInstalled(action === "test" ? "test" : "build")) {
const installEnv =
action === "build"
? { ...process.env, NODE_ENV: "production" }
: process.env;
const installArgs =
action === "build" ? ["install", "--production"] : ["install"];
runSync(runner.cmd, installArgs, installEnv);
}
run(runner.cmd, ["run", script, ...rest]);
}
} else {
if (action === "install") run(runner.cmd, ["install", ...rest]);
else {
if (!depsInstalled()) runSync(runner.cmd, ["install"]);
if (!depsInstalled(action === "test" ? "test" : "build")) {
const installEnv =
action === "build"
? { ...process.env, NODE_ENV: "production" }
: process.env;
const installArgs =
action === "build" ? ["install", "--prod"] : ["install"];
runSync(runner.cmd, installArgs, installEnv);
}
run(runner.cmd, ["run", script, ...rest]);
}
}