fix(cli): locate runtime include dir on npm install (#134)#145
Merged
Conversation
`--build`/`--test` aborted with "Could not locate runtime include directory" on a global/npm install, even though the headers ship in the package. The package places the runtime at <pkg>/src/runtime/include but the CLI runs from <pkg>/dist/node, so reaching it needs two levels up (../../src/runtime/include). findRuntimeIncludeDir only climbed one (../src/runtime/include → <pkg>/dist/src, absent), so auto-discovery landed one directory short. It only worked when run from the project root, where the cwd-relative candidate happened to hit — which is never the case on a global install (cwd is the user's project). Add the two-level package-relative candidate to both the import.meta and __dirname blocks, mirroring the libs locator just below (which already uses ../../libs). Verified end-to-end: `--build` from a foreign cwd now locates the headers and produces a working binary. Strengthen the previously-lenient build-utils test (it mocked cwd to /tmp but only asserted "doesn't throw") into a real #134 regression that requires the package-relative lookup to resolve src/runtime/include, plus a -I cxx-flags fallback case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #134 — on a global/npm install,
--buildand--testaborted withCould not locate runtime include directory, forcing users to pass--cxx-flags "-I<pkg>/src/runtime/include"by hand. The headers are shipped; the locator just missed them by one directory level.Root cause
The package ships the runtime at
<pkg>/src/runtime/include(thefilesentry"src/runtime/"), but the CLI runs from<pkg>/dist/node.findRuntimeIncludeDironly tried:Reaching the shipped headers needs two levels up:
../../src/runtime/include→<pkg>/src/runtime/include. Auto-discovery only worked when run from the project root (where the cwd-relative candidate happens to hit) — never the case on a global install, where cwd is the user's project. The libs locator just below already does the right thing with../../libs.Fix
Add the two-level package-relative candidate to both the
import.meta(ESM — npm install) and__dirname(CJS bundle / pkg binary) blocks. Fromdist/nodeit resolves to<pkg>/src/runtime/include; from thesrc/nodedev layout it resolves to the samesrc/runtime/include, so one candidate covers both.Verification
findRuntimeIncludeDir('')from a foreign cwd returnednullbefore the fix.src/runtime/include, andstrucpp p.st -o p.cpp --buildrun from/tmpcompiles and produces a working binary end-to-end.build-utilstest (it mocked cwd to/tmpbut only asserted "doesn't throw") into a real CLI: --build/--test cannot auto-locate runtime include dir on npm install (off-by-one path) #134 regression that requires the package-relative lookup to resolvesrc/runtime/include, plus a-Icxx-flags fallback case.🤖 Generated with Claude Code