Skip to content
This repository was archived by the owner on Sep 30, 2026. It is now read-only.

fix: use printf instead of echo for POSIX path normalization - #61

Closed
Yahiro025 wants to merge 2 commits into
pnpm:mainfrom
Yahiro025:cursor/posix-shim-printf-43fe
Closed

Yahiro025 wants to merge 2 commits into
pnpm:mainfrom
Yahiro025:cursor/posix-shim-printf-43fe

Conversation

@Yahiro025

@Yahiro025 Yahiro025 commented Sep 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes the POSIX bin shim header so Windows-form paths keep their backslashes until sed converts them.

Related: pnpm/pnpm#14867. POSIX echo can interpret \n / \t / etc. before sed runs, so a path like C:\node_modules\.bin\tsc becomes corrupted on dash and macOS /bin/sh. pnpm 11 generates these shims via @zkochan/cmd-shim.

The generated header now uses:

basedir=$(printf '%s\n' "$link" | command -p sed -e 's,\\,/,g')

instead of echo "$link". The commented documentation template above the live JS string is updated to match.

The Rust/pacquet copy of this header was already fixed in pnpm/pnpm#14878. This is the remaining @zkochan/cmd-shim / pnpm 11 path.

Test plan

  • npx tsc --build && node --test test/test.js test/e2e.test.js (68 passed on Linux; /bin/sh is dash)
  • Generated shims contain printf '%s\n' "$link" and not echo "$link"
  • /bin/sh turns C:\node_modules\.bin\tsc into C:/node_modules/.bin/tsc without injecting a newline or tab
  • Existing snapshot tests updated for the new header line

AI disclosure

I used Cursor to help draft the fix and tests. I reviewed the diff and verified the regression coverage before opening this PR.

Summary by CodeRabbit

  • Bug Fixes

    • Improved POSIX shell shim handling of Windows-style paths containing escape sequences, so characters such as \n and \t are preserved during path normalization.
  • Tests

    • Added coverage verifying generated shell shim output and correct normalization of Windows-style paths.

POSIX echo can interpret backslash escapes and corrupt Windows-form
paths in the generated shim header (pnpm/pnpm#14867). Print $link
with printf '%s\n' so sed still converts backslashes. The Rust/pacquet
copy of this header was fixed in pnpm/pnpm#14878.

Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f78ee5f7-f9df-4fea-a36a-77621ed4f9e5

📥 Commits

Reviewing files that changed from the base of the PR and between 6f43df5 and cebfc80.

📒 Files selected for processing (1)
  • appveyor.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
🔇 Additional comments (1)
appveyor.yml (1)

1-12: LGTM!


📝 Walkthrough

Walkthrough

The POSIX sh shim now uses printf '%s\n' "$link" instead of echo "$link" before converting backslashes with sed. Tests and snapshots verify the generated command and normalized Windows-form paths. AppVeyor is configured to use Node.js 22 and run the test suite.

Changes

POSIX shim path handling

Layer / File(s) Summary
Update sh shim generation
src/index.ts
The generated sh shim uses printf to pass $link to sed for basedir conversion.
Validate generated shims
test/e2e.test.js, test/test.js, test/*.snapshot
POSIX tests verify the command and normalize C:\node_modules\.bin\tsc to C:/node_modules/.bin/tsc. Shim snapshots record the updated command across cases.

AppVeyor test configuration

Layer / File(s) Summary
Configure AppVeyor test run
appveyor.yml
AppVeyor installs Node.js 22 and pnpm, installs dependencies with the frozen lockfile, checks tool versions, and runs pnpm test.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to cebfc

The shim change has targeted regression coverage, and AppVeyor is configured to run the tests. No actionable merge-blocking risk is indicated.

Architecture Summary

Architecture risk: 🔵 Low · up to cebfc

The change affects 3 systems.

Changed systems: test, appveyor.yml, src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — test (service) was modified; 4 changed files map to changed impact.
  • observed — appveyor.yml (service) was modified; 1 changed file maps to changed impact.
  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/index.ts: The sh-shim template comment now shows basedir=$(printf '%s\n' "$link" | command -p sed -e 's,\\,/,g') instead of the echo-based form; comment-only change.
  • observed — Modified behavior in src/index.ts: The generated sh script now computes basedir with printf '%s\n' piped into sed rather than echo, so backslash characters are emitted literally instead of being interpreted/expanded by echo.
  • observed — Modified behavior in test/e2e.test.js: Adds a describeOnPosix block with a test that creates a shim via cmdShim with createCmdFile: false, reads the generated file, locates the basedir=$(...) header line, asserts it uses printf '%s\n' "$link" and not echo "$link", then executes a script setting link='C:\node_modules\.bin\tsc' through the conversion and asserting the printed basedir is normalized to C:/node_modules/.bin/tsc.
  • observed — Modified behavior in test/e2e.test.js.snapshot: The shim template now derives basedir using printf '%s\n' "$link" piped into command -p sed instead of piping echo "$link"; both feed the same s,\\\\,/,g substitution. Output of the generated shim string is otherwise identical.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing echo with printf for POSIX path normalization.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

A rabbit checks the shim at night,
printf keeps each backslash right.
Through sed the paths now neatly flow,
The snapshots mark the change we know.
AppVeyor runs the tests in line,
Then hops away beneath the pine.

Comment @coderabbitai help to get the list of available commands.

AppVeyor defaults to MSBuild and fails when the repository has no Visual
Studio project. Install Node 22 and pnpm 12.4.1, then run pnpm test.
@zkochan

zkochan commented Sep 30, 2026

Copy link
Copy Markdown
Member

This package has been moved to the pnpm/pnpm monorepo. if you need to change it, make PRs to that repo.

@zkochan zkochan closed this Sep 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants