fix: use service command shims for pi web install

This commit is contained in:
Federico Jaramillo Martinez
2026-05-14 22:52:57 +02:00
parent c547478f80
commit 559436c1fc
2 changed files with 6 additions and 20 deletions
@@ -0,0 +1,5 @@
---
"@jmfederico/pi-web": patch
---
Install Pi Web services from the Pi extension using the normal login-shell command shims instead of hardcoded Node paths, so sessions use the same PATH for node and npm.
+1 -20
View File
@@ -6,8 +6,6 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
const cliPath = join(packageRoot, "dist", "cli.js");
const serverPath = join(packageRoot, "dist", "server", "index.js");
const sessiondPath = join(packageRoot, "dist", "server", "sessiond.js");
const serviceNames = ["pi-web-sessiond.service", "pi-web.service"];
const subcommands = [
@@ -25,14 +23,6 @@ const subcommands = [
type Subcommand = (typeof subcommands)[number];
function shellSingleQuote(value: string): string {
return `'${value.replaceAll("'", "'\\''")}'`;
}
function nodeCommand(scriptPath: string): string {
return `${shellSingleQuote(process.execPath)} ${shellSingleQuote(scriptPath)}`;
}
function parseArgs(args: string): string[] {
return args.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((part) => {
if ((part.startsWith('"') && part.endsWith('"')) || (part.startsWith("'") && part.endsWith("'"))) {
@@ -85,14 +75,6 @@ function isSubcommand(value: string): value is Subcommand {
return subcommands.some((command) => command === value);
}
function installEnv(): NodeJS.ProcessEnv {
if (!existsSync(serverPath) || !existsSync(sessiondPath)) return {};
return {
PI_WEB_SERVER_EXEC: nodeCommand(serverPath),
PI_WEB_SESSIOND_EXEC: nodeCommand(sessiondPath),
};
}
async function boundedLogs(): Promise<{ code: number; output: string }> {
return run("journalctl", ["--user", "-u", serviceNames[0] ?? "", "-u", serviceNames[1] ?? "", "-n", "100", "--no-pager"]);
}
@@ -137,8 +119,7 @@ export default function piWebExtension(pi: ExtensionAPI): void {
return;
}
const env = subcommand === "install" ? installEnv() : {};
showResult(ctx, `pi-web ${subcommand}`, await runPiWeb([subcommand, ...rest], env));
showResult(ctx, `pi-web ${subcommand}`, await runPiWeb([subcommand, ...rest]));
},
});
}