Skip to content

Commit 93776ca

Browse files
authored
Merge pull request #30 from tpsdev-ai/fix-install-ux
Install UX cleanup: postinstall + --version + CJS wrapper
2 parents 1cc357b + dc078b2 commit 93776ca

7 files changed

Lines changed: 61 additions & 19 deletions

File tree

Dockerfile.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ COPY package.json bun.lock* tsconfig*.json ./
2424

2525
# Copy package manifests first for layer caching
2626
COPY packages/cli/package.json packages/cli/tsconfig.json ./packages/cli/
27+
COPY packages/cli/scripts/ ./packages/cli/scripts/
2728
COPY packages/agent/package.json packages/agent/tsconfig.json ./packages/agent/
2829

2930
RUN bun install --frozen-lockfile 2>/dev/null || bun install

bun.lock

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/bin/tps.cjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ const platform = process.platform;
77
const arch = process.arch;
88
const pkg = `@tpsdev-ai/cli-${platform}-${arch}`;
99

10+
if (process.argv.includes('--version') || process.argv.includes('-v')) {
11+
// Fast-path version output even when native binary package is missing.
12+
// eslint-disable-next-line @typescript-eslint/no-var-requires
13+
const version = require('../package.json').version;
14+
console.log(version);
15+
process.exit(0);
16+
}
17+
1018
// Search for the platform binary relative to this package, not the cwd.
1119
// npm nests optionalDependencies inside the parent's node_modules.
1220
const searchPaths = [path.join(__dirname, '..'), path.join(__dirname, '..', '..')];
@@ -21,10 +29,19 @@ function runBinary() {
2129
// Fall through to error message
2230
}
2331

32+
// Fallback for source/dev installs where dist JS exists.
33+
try {
34+
const jsCli = path.join(__dirname, '..', 'dist', 'bin', 'tps.js');
35+
execFileSync(process.execPath, [jsCli, ...process.argv.slice(2)], { stdio: 'inherit' });
36+
return;
37+
} catch (_) {
38+
// continue to error output
39+
}
40+
2441
console.error(`Failed to load native binding`);
2542
console.error(`TPS: no binary package available for ${platform}-${arch}.`);
26-
console.error(`Run npm install -g ${pkg} to install the platform binary package.`);
27-
console.error('Or run from source inside the repository via `bun run tps` in packages/cli.');
43+
console.error(`Try reinstalling main package: npm install -g @tpsdev-ai/cli@${require('../package.json').version}`);
44+
console.error(`Or install platform binary directly: npm install -g ${pkg}@${require('../package.json').version}`);
2845
process.exitCode = 1;
2946
}
3047

packages/cli/bin/tps.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ async function checkNono() {
122122
}
123123

124124
async function main() {
125+
if (process.argv.includes("--version") || process.argv.includes("-v")) {
126+
const { readFileSync } = await import("node:fs");
127+
const { dirname, join } = await import("node:path");
128+
const { fileURLToPath } = await import("node:url");
129+
const here = dirname(fileURLToPath(import.meta.url));
130+
const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf-8"));
131+
console.log(pkg.version);
132+
return;
133+
}
134+
125135
await checkNono();
126136
switch (command) {
127137
case "hire": {

packages/cli/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"tps": "./bin/tps.cjs"
88
},
99
"optionalDependencies": {
10-
"@tpsdev-ai/cli-darwin-arm64": "0.4.2",
11-
"@tpsdev-ai/cli-darwin-x64": "0.4.2",
12-
"@tpsdev-ai/cli-linux-arm64": "0.4.2",
13-
"@tpsdev-ai/cli-linux-x64": "0.4.2"
10+
"@tpsdev-ai/cli-darwin-arm64": "0.5.0",
11+
"@tpsdev-ai/cli-darwin-x64": "0.5.0",
12+
"@tpsdev-ai/cli-linux-arm64": "0.5.0",
13+
"@tpsdev-ai/cli-linux-x64": "0.5.0"
1414
},
1515
"scripts": {
1616
"build": "tsc",
@@ -25,7 +25,8 @@
2525
"lint": "biome lint ./src ./bin",
2626
"lint:ci": "biome lint ./src ./bin --max-diagnostics=200",
2727
"pretest": "tsc",
28-
"test": "bun test"
28+
"test": "bun test",
29+
"postinstall": "node scripts/postinstall.cjs"
2930
},
3031
"keywords": [
3132
"cli",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if (process.env.CI) process.exit(0);
2+
const { execSync } = require("child_process");
3+
const { arch, platform } = process;
4+
const pkg = `@tpsdev-ai/cli-${platform}-${arch}`;
5+
const version = require("../package.json").version;
6+
7+
try {
8+
execSync(`npm install -g ${pkg}@${version}`, { stdio: "inherit" });
9+
} catch {
10+
console.warn(`Optional: install ${pkg}@${version} for native binary performance.`);
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { execSync } = require("child_process");
2+
const { arch, platform } = process;
3+
const pkg = `@tpsdev-ai/cli-${platform}-${arch}`;
4+
const version = require("../package.json").version;
5+
6+
try {
7+
execSync(`npm install -g ${pkg}@${version}`, { stdio: "inherit" });
8+
} catch {
9+
console.warn(`Optional: install ${pkg}@${version} for native binary performance.`);
10+
}

0 commit comments

Comments
 (0)