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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) .json  (7) .rs  (2) No extension  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions crates/cli/src/bin/alias.rs
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
fn print_deprecation_warning() {
eprintln!(
"\
========================================================================
WARNING: `sg` is deprecated. Use `ast-grep` instead.
========================================================================"
);
}

// Microsoft Defender has quarantined the small Windows forwarding executable as
// Trojan:Win64/Lazy!MTB, breaking pip and downstream installs. Build `sg.exe` as
// the complete CLI to avoid that false positive. See #2799 and #2841.
#[cfg(windows)]
fn main() -> anyhow::Result<std::process::ExitCode> {
print_deprecation_warning();
ast_grep::execute_main()
}

Expand All @@ -11,6 +21,7 @@ fn main() -> anyhow::Result<std::process::ExitCode> {
fn main() -> std::io::Result<()> {
use std::env::args;
use std::process::{Command, Stdio};
print_deprecation_warning();
let mut child = Command::new("ast-grep")
.args(args().skip(1))
.stdin(Stdio::inherit())
Expand Down
18 changes: 18 additions & 0 deletions crates/cli/tests/help_test.rs
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ use assert_cmd::{Command, cargo_bin};
use common::create_test_files;
use predicates::str::contains;

#[test]
fn test_sg_prints_deprecation_warning() -> Result<()> {
let ast_grep = cargo_bin!("ast-grep");
let mut paths = vec![ast_grep.parent().unwrap().to_path_buf()];
if let Some(path) = std::env::var_os("PATH") {
paths.extend(std::env::split_paths(&path));
}
Command::new(cargo_bin!("sg"))
.env("PATH", std::env::join_paths(paths)?)
.arg("--version")
.assert()
.success()
.stderr(contains(
"WARNING: `sg` is deprecated. Use `ast-grep` instead.",
));
Ok(())
}

#[test]
fn test_help_work_for_invalid_sgconfig() -> Result<()> {
let dir = create_test_files([("sgconfig.yml", "invalid")])?;
Expand Down
5 changes: 3 additions & 2 deletions npm/platforms/darwin-arm64/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"arm64"
],
"files": [
"ast-grep"
"ast-grep",
"sg"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -27,4 +28,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
5 changes: 3 additions & 2 deletions npm/platforms/darwin-x64/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"x64"
],
"files": [
"ast-grep"
"ast-grep",
"sg"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -27,4 +28,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
5 changes: 3 additions & 2 deletions npm/platforms/linux-arm64-gnu/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"glibc"
],
"files": [
"ast-grep"
"ast-grep",
"sg"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -30,4 +31,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
5 changes: 3 additions & 2 deletions npm/platforms/linux-x64-gnu/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"glibc"
],
"files": [
"ast-grep"
"ast-grep",
"sg"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -30,4 +31,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
5 changes: 3 additions & 2 deletions npm/platforms/win32-arm64-msvc/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"arm64"
],
"files": [
"ast-grep.exe"
"ast-grep.exe",
"sg.exe"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -27,4 +28,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
5 changes: 3 additions & 2 deletions npm/platforms/win32-ia32-msvc/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"ia32"
],
"files": [
"ast-grep.exe"
"ast-grep.exe",
"sg.exe"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -27,4 +28,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
5 changes: 3 additions & 2 deletions npm/platforms/win32-x64-msvc/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"x64"
],
"files": [
"ast-grep.exe"
"ast-grep.exe",
"sg.exe"
],
"description": "Search and Rewrite code at large scale using precise AST pattern",
"keywords": [
Expand All @@ -27,4 +28,4 @@
"access": "public"
},
"repository": "https://github.com/ast-grep/ast-grep"
}
}
22 changes: 13 additions & 9 deletions npm/postinstall.js
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ function resolveBinaryPath() {
return dir ? path.join(dir, binaryName) : null;
}

function installBinary(src, dest) {
try {
fs.linkSync(src, dest);
} catch (_) {
fs.copyFileSync(src, dest);
}
}

function main() {
const sourceDir = resolveBinaryDir();
if (!sourceDir) {
Expand All @@ -59,20 +67,16 @@ function main() {
}

const src = path.join(sourceDir, binaryName);
const srcAlt = path.join(sourceDir, alternativeName);
const destBin = path.join(__dirname, binaryName);
const destAlt = path.join(__dirname, alternativeName);

try {
fs.linkSync(src, destBin);
fs.linkSync(src, destAlt);
installBinary(src, destBin);
installBinary(srcAlt, destAlt);
Comment thread
HerringtonDarkholme marked this conversation as resolved.
} catch (_) {
try {
fs.copyFileSync(src, destBin);
fs.copyFileSync(src, destAlt);
} catch (err) {
console.error("Failed to move @ast-grep/cli binary into place.");
process.exit(1);
}
console.error("Failed to move @ast-grep/cli binaries into place.");
process.exit(1);
}

// Keep the extensionless JS shims on Windows: npm-generated global wrappers
Expand Down
7 changes: 7 additions & 0 deletions npm/sg
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
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#!/usr/bin/env node
console.error(
[
"========================================================================",
"WARNING: `sg` is deprecated. Use `ast-grep` instead.",
"========================================================================",
].join("\n"),
);
require("./ast-grep");
Loading

Back | FazBrowse Home | New Git URL