FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Deprecate the sg command on all platforms by HerringtonDarkholme · Pull Request #2843 · ast-grep/ast-grep · GitHub

Deprecate the sg command on all platforms - #2843

Merged
HerringtonDarkholme merged 1 commit into
mainfrom
feat/deprecate-sg
Jul 23, 2026
Merged

HerringtonDarkholme merged 1 commit into
mainfrom
feat/deprecate-sg

Conversation

HerringtonDarkholme commented Jul 23, 2026
edited
Loading

Copy link
Copy Markdown
Member

Print a prominent deprecation warning to stderr whenever sg is invoked and direct users to ast-grep. Package the real sg binary in every native npm platform package so npm installations receive the warning too, while preserving the same warning in the JavaScript fallback when lifecycle scripts do not run. Includes an integration test for the stderr warning. Checks: cargo fmt, targeted Rust integration tests, cargo check, clippy, JavaScript syntax checks, and package JSON validation.

Related to #56

Summary by CodeRabbit

  • New Features

    • Added support for installing and publishing the sg command across supported platforms.
    • Added a deprecation warning directing users from sg to ast-grep.
  • Bug Fixes

    • Improved native binary installation with a fallback from hard-linking to copying when required.
  • Tests

    • Added coverage verifying that sg displays the deprecation warning.

Copilot AI review requested due to automatic review settings July 23, 2026 15:54

coderabbitai Bot commented Jul 23, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

📝 Walkthrough

Walkthrough

The sg launchers now emit deprecation warnings before delegating to ast-grep. npm platform packages publish both binaries, postinstall installs both, and CLI tests verify the warning.

Changes

sg deprecation and distribution

Layer / File(s) Summary
Native sg deprecation path
crates/cli/src/bin/alias.rs, crates/cli/tests/help_test.rs
Native Windows and Unix launchers print the warning before execution, with a regression test covering sg --version.
npm binary publication and installation
npm/platforms/*/package.json, npm/postinstall.js
Platform manifests include the sg executable, and postinstall uses shared hard-link-or-copy logic for both binaries.
npm sg deprecation entrypoint
npm/sg
The npm sg wrapper writes the deprecation warning to stderr before loading ast-grep.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: copilot

Poem

I’m a rabbit guarding sg’s old trail,
“Use ast-grep!” I thump without fail.
Binaries hop in, links or copies fly,
Warnings wave softly as commands pass by.
The CLI burrows forward, bright-eyed and spry.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: deprecating the sg command across platforms.
✨ Finishing Touches 📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/deprecate-sg

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

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

codecov Bot commented Jul 23, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.43%. Comparing base (64d2a26) to head (c889def).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2843      +/-   ##
==========================================
+ Coverage   86.39%   86.43%   +0.04%     
==========================================
  Files         126      126              
  Lines       22832    22836       +4     
==========================================
+ Hits        19726    19739      +13     
+ Misses       3106     3097       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This PR deprecates the sg command by emitting a prominent warning on every invocation and directing users to ast-grep, across Rust binaries and npm-distributed shims/binaries.

Changes:

  • Add a deprecation warning to the npm sg JavaScript shim (stderr), preserving warnings even when lifecycle scripts don’t run.
  • Update npm postinstall logic to install both ast-grep and sg native binaries from platform packages.
  • Add sg to the shipped files for each native npm platform package and add an integration test asserting the warning appears on stderr.

Reviewed changes

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

Show a summary per file
File Description
npm/sg Prints a deprecation warning to stderr before delegating to ast-grep.
npm/postinstall.js Installs both ast-grep and sg binaries into the npm package during postinstall.
npm/platforms/win32-x64-msvc/package.json Ships sg.exe alongside ast-grep.exe for this platform package.
npm/platforms/win32-ia32-msvc/package.json Ships sg.exe alongside ast-grep.exe for this platform package.
npm/platforms/win32-arm64-msvc/package.json Ships sg.exe alongside ast-grep.exe for this platform package.
npm/platforms/linux-x64-gnu/package.json Ships sg alongside ast-grep for this platform package.
npm/platforms/linux-arm64-gnu/package.json Ships sg alongside ast-grep for this platform package.
npm/platforms/darwin-x64/package.json Ships sg alongside ast-grep for this platform package.
npm/platforms/darwin-arm64/package.json Ships sg alongside ast-grep for this platform package.
crates/cli/tests/help_test.rs Adds an integration test asserting sg prints the deprecation warning to stderr.
crates/cli/src/bin/alias.rs Prints a deprecation warning when sg is invoked (Windows runs full CLI; Unix forwards).
Comments suppressed due to low confidence (1)

crates/cli/src/bin/alias.rs:28

  • On Unix this launcher executes ast-grep by name (Command::new("ast-grep")), which relies on PATH. When sg is invoked via an absolute path (common for npm-generated wrappers executing the binary directly), PATH may not include the directory containing ast-grep, causing sg to fail to forward.

Prefer resolving a sibling ast-grep next to the current sg executable (and fall back to PATH search if it’s not found).

  print_deprecation_warning();
  let mut child = Command::new("ast-grep")
    .args(args().skip(1))
    .stdin(Stdio::inherit())
    .stdout(Stdio::inherit())

Comment thread npm/postinstall.js
HerringtonDarkholme added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit 6fc7053 Jul 23, 2026
11 of 12 checks passed
HerringtonDarkholme deleted the feat/deprecate-sg branch July 23, 2026 16:04

coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
🧹 Nitpick comments (1)
npm/postinstall.js (1)

54-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Swallowed errors hinder install failure diagnosis.

Both installBinary's fallback and main's catch discard the underlying error (catch (_)), so if both linkSync and copyFileSync fail, users only see a generic message with no indication of which binary failed or why (permissions, missing source, disk full, etc.).

♻️ Proposed fix to surface the underlying error
 function installBinary(src, dest) {
   try {
     fs.linkSync(src, dest);
-  } catch (_) {
-    fs.copyFileSync(src, dest);
+  } catch (_) {
+    fs.copyFileSync(src, dest);
   }
 }
 ...
   try {
     installBinary(src, destBin);
     installBinary(srcAlt, destAlt);
-  } catch (_) {
-    console.error("Failed to move `@ast-grep/cli` binaries into place.");
+  } catch (err) {
+    console.error("Failed to move `@ast-grep/cli` binaries into place.", err);
     process.exit(1);
   }

Also applies to: 74-80

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@npm/postinstall.js` around lines 54 - 61, Update installBinary and main error
handling to preserve and surface the original errors instead of discarding them
with catch (_). When linkSync fails, retain its error and include it alongside
any copyFileSync failure; ensure main’s failure message identifies the affected
binary and includes the underlying error details.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@npm/postinstall.js`:
- Around line 54-61: Update installBinary and main error handling to preserve
and surface the original errors instead of discarding them with catch (_). When
linkSync fails, retain its error and include it alongside any copyFileSync
failure; ensure main’s failure message identifies the affected binary and
includes the underlying error details.

ℹ️ Review info ⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9b0283e-b308-4b75-ad2e-dbd74724a322

📥 Commits

Reviewing files that changed from the base of the PR and between 64d2a26 and c889def.

📒 Files selected for processing (11)
  • crates/cli/src/bin/alias.rs
  • crates/cli/tests/help_test.rs
  • npm/platforms/darwin-arm64/package.json
  • npm/platforms/darwin-x64/package.json
  • npm/platforms/linux-arm64-gnu/package.json
  • npm/platforms/linux-x64-gnu/package.json
  • npm/platforms/win32-arm64-msvc/package.json
  • npm/platforms/win32-ia32-msvc/package.json
  • npm/platforms/win32-x64-msvc/package.json
  • npm/postinstall.js
  • npm/sg

social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
ast-grep 0.45.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>- feat: deprecate the sg command [`#2843`](ast-grep/ast-grep#2843)
- fix: avoid Defender false positive for Windows sg [`#2842`](ast-grep/ast-grep#2842)
- chore(deps): update dependency @napi-rs/cli to v3.7.4 [`#2834`](ast-grep/ast-grep#2834)
- chore(deps): update dependency oxlint to v1.75.0 [`#2838`](ast-grep/ast-grep#2838)
- chore(deps): update actions/setup-node action to v7 [`#2810`](ast-grep/ast-grep#2810)
- chore(deps): update actions/setup-python action to v7 [`#2829`](ast-grep/ast-grep#2829)
- fix: specify correct MSRV in Cargo.toml [`#2837`](ast-grep/ast-grep#2837)
- Revert "chore(deps): update dependency typescript to v7 (#2795)" [`#2831`](ast-grep/ast-grep#2831)
- chore(deps): update astral-sh/setup-uv action to v8.3.2 [`#2790`](ast-grep/ast-grep#2790)
- chore(deps): update dependency typescript to v7 [`#2795`](ast-grep/ast-grep#2795)
- chore(deps): update rust crate thiserror to v2.0.19 [`#2819`](ast-grep/ast-grep#2819)
- chore(deps): update dependency @napi-rs/cli to v3.7.3 [`#2801`](ast-grep/ast-grep#2801)
- chore(deps): update dependency web-tree-sitter to v0.26.11 [`#2802`](ast-grep/ast-grep#2802)
- chore(deps): update rust crate target-triple to v1.0.1 [`#2817`](ast-grep/ast-grep#2817)
- chore(deps): update dependency oxlint to v1.74.0 [`#2809`](ast-grep/ast-grep#2809)
- chore(deps): update dependency dprint to v0.55.2 [`#2808`](ast-grep/ast-grep#2808)
- chore(deps): update dependency @ast-grep/napi to v0.44.1 [`#2789`](ast-grep/ast-grep#2789)
- chore(deps): update dependency oxlint to v1.73.0 [`#2793`](ast-grep/ast-grep#2793)
- chore(deps): update dependency @types/node to v24.13.3 [`#2794`](ast-grep/ast-grep#2794)
- chore(deps): update rust crate bit-set to 0.11.0 [`#2791`](ast-grep/ast-grep#2791)
- fix: use is_extra instead of comment heuristic [`#2821`](ast-grep/ast-grep#2821)
- fix: stop using ignore files outside rule_dirs [`#2803`](ast-grep/ast-grep#2803)
- chore: update dependencies [`b24ca85`](ast-grep/ast-grep@b24ca85)
- feat(outline): support ambient TypeScript modules [`4f75c21`](ast-grep/ast-grep@4f75c21)
- chore: bump versions [`82eb291`](https://github.com/ast-grep/ast-grep/commit/82eb2916782ae5ed572813272f5845214b5aa321)</pre>
  <p>View the full release notes at <a href="https://github.com/ast-grep/ast-grep/releases/tag/0.45.0">https://github.com/ast-grep/ast-grep/releases/tag/0.45.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!14931
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL