Fix: update tauri-updater script to use node for JSON parsing and replace ripgrep with grep#1101
Conversation
…lace ripgrep with grep
Coverage Report
File CoverageNo changed files found. |
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Tauri dependency updater script by replacing external tools (jq and ripgrep) with alternatives that leverage existing project dependencies. The script is used in the weekly automated workflow (auto-update-tauri.yml) that runs on Ubuntu to keep Tauri-related packages up to date.
Changes:
- Replaced
jqwith Node.js for JSON parsing in the npm package update logic - Replaced
ripgrep(rg) with GNUgrepfor extracting Tauri plugin names from Cargo.toml
chore(deps-tauri): update tauri dependencies
| PLUGINS=$(rg -o 'tauri-plugin-[a-zA-Z0-9_-]+' Cargo.toml | sort -u || true) | ||
| if [ -n "${PLUGINS}" ]; then | ||
| for p in ${PLUGINS}; do | ||
| mapfile -t PLUGINS < <(grep -oP 'tauri-plugin-[a-zA-Z0-9_-]+' Cargo.toml | sort -u || true) |
There was a problem hiding this comment.
grep -oP requires PCRE support (GNU grep) and will fail on environments with BSD grep (e.g., macOS). Since the pattern doesn’t need PCRE features, prefer grep -oE to keep the script portable while still removing the ripgrep dependency.
| mapfile -t PLUGINS < <(grep -oP 'tauri-plugin-[a-zA-Z0-9_-]+' Cargo.toml | sort -u || true) | |
| mapfile -t PLUGINS < <(grep -oE 'tauri-plugin-[a-zA-Z0-9_-]+' Cargo.toml | sort -u || true) |
| OUTDATED_JSON="$(npm outdated --json 2>/dev/null | sed -n '/^{/,/^}/p' || true)" | ||
| if [ -n "${OUTDATED_JSON}" ] && [ "${OUTDATED_JSON}" != "null" ]; then | ||
| mapfile -t PKGS < <(echo "$OUTDATED_JSON" | jq -r 'keys[]' | grep '^@tauri-apps/' || true) | ||
| mapfile -t PKGS < <(echo "$OUTDATED_JSON" | node -e 'let s="";process.stdin.on("data",c=>s+=c);process.stdin.on("end",()=>{for(const k of Object.keys(JSON.parse(s)))console.log(k)})' | grep '^@tauri-apps/' || true) |
There was a problem hiding this comment.
The inline node -e JSON parsing one-liner is hard to read/maintain and makes failures easy to miss (the surrounding || true will silently produce an empty package list if parsing breaks). Consider switching to a small, more readable Node snippet (e.g., using fs.readFileSync(0, "utf8") and a try/catch) or factoring it into a helper function within the script.
| mapfile -t PKGS < <(echo "$OUTDATED_JSON" | node -e 'let s="";process.stdin.on("data",c=>s+=c);process.stdin.on("end",()=>{for(const k of Object.keys(JSON.parse(s)))console.log(k)})' | grep '^@tauri-apps/' || true) | |
| mapfile -t PKGS < <(node <<'EOF' "$OUTDATED_JSON" | |
| const data = process.argv[2] || ""; | |
| try { | |
| const trimmed = data.trim(); | |
| if (!trimmed || trimmed === "null") { | |
| process.exit(0); | |
| } | |
| const obj = JSON.parse(trimmed); | |
| for (const key of Object.keys(obj)) { | |
| if (key.startsWith("@tauri-apps/")) { | |
| console.log(key); | |
| } | |
| } | |
| } catch (err) { | |
| console.error("Failed to parse npm outdated JSON:", err && err.message ? err.message : err); | |
| process.exit(1); | |
| } | |
| EOF | |
| ) |
No description provided.