Repository navigation
Conversation
npm_execpath is only a JS entry when pnpm comes from the npm package. Under @pnpm/exe (standalone installer, Homebrew, mise) it points at a native executable, so handing it to process.execPath made Node parse a Mach-O/PE binary as JavaScript and fail with 'SyntaxError: Invalid or unexpected token'. CI never hit this because pnpm/action-setup installs the JS build. Route through Node only for a .js/.cjs/.mjs npm_execpath, otherwise execute npm_execpath directly so the pinned pnpm version is preserved, and spawn Windows .cmd/.bat entries through a shell since Node refuses them otherwise.
build:native exits on win32 before it ever calls runPnpmScript, so the .cmd/.bat shell handling in withWindowsShell cannot fire in production. Keep it as a guard against a future Windows caller reintroducing the CVE-2024-27980 spawn failure, but say so, and group the two win32 cases under a resolver-contract describe so they stop reading as proof that Windows is covered end to end.
The entry guard compared process.argv[1], which keeps the symlinked path, against import.meta.filename, which Node resolves to the realpath. Behind a symlinked checkout the two never matched, so the script fell through and exited 0 without building anything: a silent no-op worse than the crash it replaced. Compare the realpath of both sides instead. Also surface result.error, so a spawn that never starts (missing pnpm, non-executable npm_execpath) reports its cause instead of exiting 1 mute, and fold the duplicated spawn-and-exit tails into one helper. Cover the guard with tests: a symlinked entry path resolves, and on linux the script spawned through a symlink still reaches its build flow.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe native build script resolves pnpm through JavaScript entry points, native executables, PATH fallback, and Windows shell scripts. It centralizes process execution and spawn-error handling. It uses realpath-based entry-point detection, runs the Windows launcher through Node, and preserves platform-specific build branching. Tests cover command resolution, symlink-aware entry detection, invalid paths, and Linux execution through a symlink. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — the CI-exercised path (JS-based pnpm) is unchanged, and the new native-binary path is well-tested with no logic errors found. The detection regex correctly distinguishes .cjs/.mjs/.js from native binaries, the isEntryPoint guard makes the module importable without side effects, and the previously flagged realpathSync ENOENT risk is now covered by the try/catch. The Windows quoting is correct. No functional regressions identified. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| config/scripts/build-native-for-platform.mjs | Refactors pnpm invocation to detect JS vs native binary via file-extension regex, adds isEntryPoint export with symlink-safe realpathSync, and moves top-level side effects behind the entry guard — all clean with no logic errors found. |
| config/scripts/build-native-for-platform.test.mjs | New test file covering all npm_execpath shapes (.cjs, native binary, unset, win32 .cmd), plus entry-guard symlink round-trip on Linux; tests are honest about the win32 resolver being unreachable from production entry paths. |
Reviews (2): Last reviewed commit: "fix(build): harden the entry guard and W..." | Re-trigger Greptile
isEntryPoint is exported, so it can be handed a path that no longer exists; realpathSync then threw ENOENT instead of answering the question. A path that cannot be resolved is not this module, so return false. Double any quote embedded in the Windows command before wrapping it, the cmd.exe escape convention. Windows forbids a quote in a path name so no real npm_execpath can hit this, but the routine is exported and the quoting is only correct if it holds for its whole input domain. Both review comments from greptile-apps on PR stablyai#11738.
|
Correction: the intended reference is the standalone pnpm npm_execpath failure. We are taking ownership in issue #16655 and will reimplement safely on current main. No contributor action is requested; your credit remains preserved. |
Summary
pnpm build:nativefails on any machine where pnpm is installed as a standalone native binary.config/scripts/build-native-for-platform.mjsassumedprocess.env.npm_execpathis always a JavaScript file and ran it through Node:That holds when pnpm comes from the npm package. It does not hold for
@pnpm/exe, which the official installer, Homebrew and mise all use: therenpm_execpathpoints at a ~60 MB Mach-O (or PE) executable, so Node is handed a binary to parse as JavaScript and dies withSyntaxError: Invalid or unexpected token. The wholebuild:nativestep, and thereforepnpm build, is unusable for those contributors.CI never caught this because every workflow installs pnpm through
pnpm/action-setup@v6, which provides the JavaScript build.npm_execpathends in.cjsthere, theprocess.execPathbranch is correct, and everything passes. The bug is invisible in CI and reproduces only locally.The fix routes through Node only when
npm_execpathactually looks like JavaScript (/\.[cm]?js$/i), and otherwise executesnpm_execpathdirectly, which also preserves the exact pinned pnpm version instead of falling back to whatever is onPATH. The unset case keeps today'spnpm/pnpm.cmdfallback.The invocation logic moved into an exported
resolvePnpmInvocation(scriptName, npmExecPath, platform)so it can be unit tested, and the top-level build flow now sits behind the repo's existingimport.meta.url === pathToFileURL(process.argv[1]).hrefentry guard (the idiom already used by 19 other scripts inconfig/scripts) so the module is importable from a test without executing the build.Verified end to end:
pnpm run build:nativenow reachesbuild:computer-macosinstead of dying withSyntaxError.Screenshots
No visual change— this is a build script, with no UI surface.Testing
pnpm lint— oxfmt--check, oxlint root, oxlint code-quality-native and oxlint--type-awareall cleanpnpm test— new test file passes 5/5pnpm typecheck— does not cover these files;config/scriptsis in no tsconfigincludepnpm build— see noteconfig/scripts/build-native-for-platform.test.mjscovers every shapenpm_execpathcan take: a.cjspath (the CI path, which must not regress), a native@pnpm/exebinary (the bug), unset on both darwin and win32, and a Windows.cmd. It is picked up by CI automatically —config/vitest.config.tsalready includesconfig/scripts/**/*.test.mjs.Note on
pnpm build: it cannot complete on the machine this was developed on, becausebuild:nativeis precisely what was broken. The five other steps (typecheck,build:relay,build:cli,build:electron-vite,build:web-from-renderer) were each run individually and all pass. CI runs the full build.AI Review Report
Reviewed by a second agent against five questions: regex correctness, Windows
.cmdhandling, regression risk on the CI-exercised path, whether the tests are real, and cross-platform assumptions.It confirmed the detection logic and the Windows quoting are correct, and — the important one — that the previous working JavaScript-pnpm path is behaviorally identical, so the CI regression risk is nil. That was the main risk worth checking: every CI job in the repo depends on that branch continuing to behave exactly as before.
It raised three low findings. Two were investigated and deliberately not acted on:
import.meta.urlentry guard can in theory no-op under a symlinked or case-mismatched invocation. Real, but that idiom appears in 19 files underconfig/scripts; changing it here alone would make this file inconsistent with the repo. It is a repo-wide topic, not something this PR introduced.resolvePnpmInvocation's return value without spying onspawnSync. Extracting a pure function and testing its contract is a deliberate design choice.The third was acted on, in the second commit. The Windows shell branch is unreachable in production:
runPnpmScriptis only called after the entry path has already exited on win32, andresolvePnpmInvocationhas no other consumers, soneedsShellcan never be true at runtime. Two tests asserting Windows behavior therefore implied a Windows coverage that does not exist. Rather than delete four correct lines, the branch now carries a why-comment stating it is unreachable today and kept so a future Windows caller cannot reintroduce theCVE-2024-27980spawn failure, and the win32 tests moved under a describe namedwin32 resolver contract, unreachable from the build:native entry pathso the runner output states the framing instead of implying support.Cross-platform (macOS, Linux, Windows): the change is about spawning correctly on all three. macOS and Linux take the direct-execution path; Windows keeps the
shell: truehandling required since Node refused.cmd/.batspawns as part of theCVE-2024-27980fix. No new path handling, no shell-specific string building beyond that quoting.SSH / remote / local:
build:nativeis a local packaging step; it does not run against remote or SSH hosts.Agent / integration / git-provider compatibility: not touched.
Performance: none — this resolves a command once per script invocation.
UI quality: not applicable, no UI surface.
Security Audit
Low risk. The one security-relevant aspect is the Windows
shell: truebranch, since spawning through a shell is where argument injection normally appears. It was reviewed specifically: the shell path is only taken for a.cmd/.batcommand, the command is quoted, and the only arguments are the literal stringrunplus a script name that comes from this file's own call sites (build:computer-macos,build:notification-status-macos), never from user input or the environment.npm_execpathitself is set by the package manager, not by untrusted input.No input handling, auth, secrets, IPC or dependency changes. No follow-up needed.
Notes
No behavior change for anyone whose pnpm is the JavaScript build, which includes all of CI.
The
pnpm buildcheckbox is unchecked above for the honest reason that this PR is the fix for what blocks it locally.Related
Independent of, and mergeable in any order with, the pnpm settings migration in the linked PR below. Same theme — this repo's pnpm integration drifting from the behavior of the pinned
[email protected]— but no dependency between them, and no shared files.See #11736.