fix: add postinstall permission fix for CLI and hook scripts (#330)#348
Conversation
After npm global install, the CLI entry point and hook scripts lack execute permissions because the published tarball preserves the source file modes. Add scripts/fix-permissions.cjs that runs as part of postinstall to chmod +x the affected files on Unix systems. No-op on Windows. Also ensure hooks/ and scripts/ have +x in the git index so the published tarball includes correct permissions. Fixes #330 Related: #322 (similar permission issue on darwin/arm)
|
@ShunsukeHayashi is attempting to deploy a commit to the NexusCore Team on Vercel. A member of the Team first needs to authorize it. |
|
@claude is there a way to fix this without having to have to run a post script? Research about related problems and see if there's an industry standard for this. |
|
Claude finished @magyargergo's task in 1m 42s —— View job Research: Fixing Permissions Without a Postinstall Script
Yes — there are cleaner, industry-standard ways to handle this. Here's the breakdown: The Two Categories of FilesThis PR fixes two different categories of files, each with a better solution: 1.
|
postinstall |
prepack (+ git index fix) |
|
|---|---|---|
| Runs on | Every installer's machine | Publisher's machine once |
| Security surface | Executes arbitrary code for all users | No user-side execution |
| npm audit concerns | Flagged by some security scanners | None |
| Windows compatibility | Needs platform guard | Not needed (publisher is Unix) |
| Covers dist/ artifacts | ✅ | ✅ |
| Covers git-tracked scripts | ✅ (redundant) | ✅ via git index |
The npm docs explicitly list prepack as running "before a tarball is packed." Many popular CLI packages (e.g., create-react-app, various @angular/cli releases) use this pattern.
Recommended Approach (no postinstall needed)
- Remove
fix-permissions.cjsand drop it from postinstall - Keep the git index fix from this PR (
hooks/files at 100755) — this is correct and necessary - Add
prepackto cover the CLI build artifact:"prepack": "npm run build && chmod +x dist/cli/index.js"
- Rely on npm's
binfield to handle the symlink/wrapper (it sets 0755 automatically)
This eliminates user-side script execution entirely and is the approach used by the broader npm ecosystem.
|
Could you please tackle with this? 🙏 |
Per review feedback from @magyargergo and @claude: - Remove fix-permissions.cjs postinstall script (security surface, redundant) - Add prepack script: 'npm run build && chmod +x dist/cli/index.js' - Keep git index 100755 for hooks/ (already correct from previous commit) - Rely on npm bin field for CLI symlink permissions prepack runs on the publisher's machine before npm pack/publish, so correct permissions are baked into the tarball. No user-side script execution needed. This follows the npm ecosystem standard (prepack over postinstall) as documented in npm docs life-cycle-scripts.
|
Good call @magyargergo, and great research by @claude. Updated the PR:
This follows the npm ecosystem standard — permissions are baked into the tarball at publish time, no user-side script execution needed. |
Problem
After
npm install -g gitnexus, the CLI and hook scripts lack execute permissions (#330):Affected files (published as
644instead of755):dist/cli/index.js— Main CLI entry point (has shebang)hooks/claude/pre-tool-use.shhooks/claude/session-start.shhooks/claude/gitnexus-hook.cjsRoot Cause
100644instead of100755Fix
1.
scripts/fix-permissions.cjs(new)A postinstall script that
chmod +xthe affected files on Unix systems. No-op on Windows.2.
package.jsonpostinstall update3. Git index permissions
Set
+xonhooks/andscripts/files in the git index so the published tarball includes correct permissions from the start.After this fix
Backward compatibility
process.platform === 'win32'and exits immediatelypatch-tree-sitter-swift.cjspostinstall is preserved (chained with&&)Related: #322 (similar permission issue on darwin/arm)