Skip to content

Commit 02417c7

Browse files
fix: handle npm git dep installation for GitHub installs
npm v11's git dep preparation runs `prepare` before node_modules exist in the temp clone directory. This causes TypeScript compilation to fail. Changes: - build.js: skip build gracefully when node_modules absent, use node directly instead of pnpm for npm compatibility - package.json: add `prepack` hook for pack-phase build, make postinstall non-fatal (|| true) to handle stale CWD after temp dir cleanup Install from GitHub with: npm pack github:user/repo#branch npm install -g ./fission-ai-openspec-1.2.0.tgz Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f821833 commit 02417c7

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

build.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { execFileSync } from 'child_process';
44
import { existsSync, rmSync } from 'fs';
55
import { createRequire } from 'module';
66

7+
// When npm installs from a git dep (github:user/repo#branch), it runs
8+
// `prepare` before node_modules exist. Skip gracefully and let `prepack`
9+
// handle the build during the pack phase where deps are available.
10+
if (!existsSync('node_modules')) {
11+
console.log('⏭️ Skipping build (node_modules not yet available)');
12+
process.exit(0);
13+
}
14+
715
const require = createRequire(import.meta.url);
816

917
const runTsc = (args = []) => {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
"test:ui": "vitest --ui",
4949
"test:coverage": "vitest --coverage",
5050
"test:postinstall": "node scripts/postinstall.js",
51-
"prepare": "pnpm run build",
51+
"prepare": "node build.js",
52+
"prepack": "node build.js",
5253
"prepublishOnly": "pnpm run build",
53-
"postinstall": "node scripts/postinstall.js",
54+
"postinstall": "node scripts/postinstall.js || true",
5455
"check:pack-version": "node scripts/pack-version-check.mjs",
5556
"release": "pnpm run release:ci",
5657
"release:ci": "pnpm run check:pack-version && pnpm exec changeset publish",

0 commit comments

Comments
 (0)