fix(scanner): support Windows cmd shims for ast-grep (npm installs) - #141
Merged
JordanCoin merged 1 commit intoAug 21, 2026
Merged
Conversation
npm's 'npm install -g @ast-grep/cli' ships ast-grep.cmd / sg.cmd shims instead of real executables. Go's exec cannot run .cmd files directly, so findAstGrepBinary rejected a working ast-grep and --deps failed with 'ast-grep not found' even though ast-grep was on PATH. Three changes: - astGrepCommand wraps .cmd/.bat invocation in 'cmd.exe /c' so version checks and scans can execute shims at all - cmd.exe cannot reliably carry the multi-line --inline-rules argument, so shim scans materialize the embedded rules into a temp dir and pass a short --config path instead (rules subdirectory + generated sgconfig.yml; ast-grep ignores ruleDirs pointing at the config's own directory) - Close() removes the materialized rules directory Windows-gated regression tests cover version-check detection and a full ScanDirectory through a .cmd shim. TestAstGrepAnalyzer/TestAstGrepPython now pass on Windows with the npm shim; blast-radius root-package tests fail on main already (extensionless test binary) and are unrelated.
This was referenced Aug 21, 2026
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.
What does this PR do?
On Windows,
npm install -g @ast-grep/cli(the easiest install route — brew/cargo/pipx are not the Windows defaults) shipsast-grep.cmd/sg.cmdshims instead of real executables. Go'sexeccannot run.cmdfiles directly, sofindAstGrepBinaryrejected a working ast-grep and--deps/--importersfailed withast-grep not found (checked bundled tools and PATH)even though ast-grep was on PATH.Reproduction (Windows 11, codemap 4.4.0):
Three changes:
astGrepCommandwraps.cmd/.batinvocation incmd.exe /cso version checks and scans can execute shims at all.cmd.execannot reliably carry the multi-line--inline-rulesargument (quoting + line-length limits mangle it), so shim scans materialize the embedded rules into a temp dir and pass a short--configpath instead. Two gotchas encoded in the helper:ruleDirspointing at the directory that containssgconfig.ymlitself (ruleDirs: ["."]" is a no-op), so rules go into arules/` subdirectory with a generated config.Close()..cmdshim, and a fullScanDirectorythrough one.Type of change
Checklist
go build && ./codemap .— built from this branch, with only the npm.cmdshim on PATH:--deps .on a mixed Expo/TS + Java repo now produces the full dependency flow (was:ast-grep not found).TestAstGrepAnalyzerandTestAstGrepPythonnow pass on Windows with the npm shim (they previously failed on main in this environment).Additional notes
TestBlastRadius*) fail on unmodified main on Windows as well — they build an extensionlesscodemap_test_binarythat Windows cannot execute. Pre-existing and unrelated to this change; happy to look at it in a follow-up if useful.--importers app/src/lib/typing.tsreported no importers although grep confirms 4 files import it in my test repo. Looks like a resolver-mapping issue independent of the shim path.