Skip to content

Commit 9c292ad

Browse files
author
root
committed
fix(cli): harden runtime version and launch handling
1 parent eaa5b2c commit 9c292ad

6 files changed

Lines changed: 19 additions & 3 deletions

File tree

packages/cli/src/bin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ EXAMPLES:
128128
}
129129

130130
function showVersion(): void {
131-
const version = "0.0.1";
131+
const manifestPath = [
132+
new URL("../package.json", import.meta.url),
133+
new URL("../../package.json", import.meta.url),
134+
].find((candidate) => existsSync(candidate));
135+
if (!manifestPath) {
136+
throw new Error("Unable to locate CLI package.json");
137+
}
138+
const manifest = JSON.parse(readFileSync(manifestPath, "utf-8")) as { version?: string };
139+
const version = manifest.version ?? "0.0.0";
132140
console.log(`@spencer-kit/coder-studio v${version}`);
133141
}
134142

packages/cli/src/config-store.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync, mkdtempSync, readFileSync, rmSync } from "fs";
2-
import { homedir, tmpdir } from "os";
2+
import { tmpdir } from "os";
33
import { join } from "path";
44
import { afterEach, beforeEach, describe, expect, it } from "vitest";
55
import {

packages/cli/src/parse-args.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ export function parseArgs(argv: string[]): CliArgs {
102102

103103
for (let i = 0; i < argv.length; i++) {
104104
const arg = argv[i];
105+
if (arg === undefined) {
106+
continue;
107+
}
105108

106109
switch (arg) {
107110
case "serve":

packages/cli/src/pm2-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function loadPm2(): Promise<Pm2Module> {
7272
let pm2Module: Pm2Module;
7373
try {
7474
const pm2 = await import("pm2");
75-
pm2Module = pm2.default as Pm2Module;
75+
pm2Module = pm2.default as unknown as Pm2Module;
7676
} catch {
7777
throw new Error(
7878
"pm2 is not installed. Run `npm install -g pm2` to use background server management."

packages/cli/src/server-runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { readCliConfig } from "./config-store.js";
44
import { getStaticAssetsDir, hasWebAssets } from "./embed.js";
55
import { assertSupportedNodeVersion } from "./node-version.js";
66

7+
const MISSING_WEB_ASSETS_WARNING = "Warning: Web assets not found. Frontend will not be available.";
8+
79
export const buildServerConfig = (): Partial<ServerConfig> => {
810
const savedConfig = readCliConfig();
911
const config: Partial<ServerConfig> = {

packages/server/src/terminal/pty-host.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export class NodePtyHost implements PtyHost {
201201
}
202202

203203
const [command, ...args] = argv;
204+
if (command === undefined) {
205+
throw new Error("PTY spawn requires a command");
206+
}
204207

205208
const ptyProcess = pty.spawn(command, args, {
206209
cwd: options.cwd,

0 commit comments

Comments
 (0)