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

feat: add target marker to sh shims - #51

Merged
zkochan merged 3 commits into
mainfrom
feat/shim-target-marker
Mar 26, 2026
Merged

zkochan merged 3 commits into
mainfrom
feat/shim-target-marker

Conversation

@zkochan

@zkochan zkochan commented Mar 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Append a # cmd-shim-target=<normalized-path> comment to every generated sh shim
  • Export isShimPointingAt(shimContent, src) to check the marker

This lets consumers (e.g. pnpm's link-bins) detect whether an existing shim already points at the correct target without parsing the script content. Path separators are normalized to / and the trailing newline ensures full-path matching (no subdirectory false positives).

Needed by pnpm/pnpm#11069.

Test plan

  • 3 new tests for isShimPointingAt: correct target, wrong target, subdirectory prefix
  • Snapshot tests updated to include the marker line

Append a `# cmd-shim-target=<normalized-path>` comment to every
generated sh shim. This lets consumers detect whether an existing
shim already points at the correct target without parsing the
script content.

Export `isShimPointingAt(shimContent, src)` so callers can check
the marker reliably, with normalized separators and full-path
matching (no subdirectory false positives).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a stable “target marker” comment to generated POSIX sh shims and exposes a helper API to detect whether an existing shim already points at a given target, enabling consumers (like pnpm) to avoid reparsing shim scripts.

Changes:

  • Append # cmd-shim-target=<normalized-path>\n to generated sh shim content.
  • Export cmdShim.isShimPointingAt(shimContent, src) to check the marker.
  • Add unit tests for isShimPointingAt and update existing snapshots to include the marker line.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

File Description
src/index.ts Adds marker emission to generateShShim and exports isShimPointingAt.
test/test.js Adds new tests covering marker matching behavior and prefix safety.
test/__snapshots__/test.js.snap Updates snapshots to include the appended marker line.
pnpm-lock.yaml Updates lockfile content (currently introduces an invalid duplicated YAML document).
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pnpm-lock.yaml Resolved
@zkochan
zkochan force-pushed the feat/shim-target-marker branch from 8924459 to 2746f4a Compare March 26, 2026 00:34
Append a `# cmd-shim-target=<normalized-path>` comment to every
generated sh shim. This lets consumers detect whether an existing
shim already points at the correct target without parsing the
script content.

Export `isShimPointingAt(shimContent, src)` so callers can check
the marker reliably, with normalized separators and full-path
matching (no subdirectory false positives).
@zkochan
zkochan force-pushed the feat/shim-target-marker branch from 2746f4a to 7bdf064 Compare March 26, 2026 00:37
@zkochan
zkochan merged commit 05e5558 into main Mar 26, 2026
4 checks passed
@zkochan
zkochan deleted the feat/shim-target-marker branch March 26, 2026 00:48
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.

2 participants