Created
May 14, 2025 00:22
-
-
Save alexeagle/244b0aef68a25d4d936ec6e1e3b08b16 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -euo pipefail | |
bazel 2>/dev/null build --build_runfile_links @yq | |
YQ=$(bazel 2>/dev/null info execution_root)/$(bazel 2>/dev/null cquery --output=files @yq) | |
for pkg in $($YQ eval ' | |
(.importers.".".dependencies // {} | |
+ .importers.".".devDependencies // {} | |
+ .importers.".".optionalDependencies // {}) | |
| to_entries | |
| map(.key + "@" + .value.version) | |
| .[]' pnpm-lock.yaml); do | |
# Try to find matching packages in .packages | |
match=$($YQ eval " | |
.packages | |
| to_entries | |
| map(select(.key | test(\"^/${pkg}\"))) | |
| map(select(.value.hasBin == true)) | |
| length | |
" pnpm-lock.yaml) | |
if [[ "$match" -gt 0 ]]; then | |
pkg_name="${pkg%@*}" | |
# Modify pkg_name for Starlark loads: | |
# 1. Remove the leading '@' if present | |
# 2. Replace '-' with '_' | |
starlark_pkg_name="${pkg_name/#@/}" # Remove the leading '@' if present | |
starlark_pkg_name="${starlark_pkg_name//-/_}" # Replace '-' with '_' | |
echo "load(\"@npm//tools:$pkg_name/package_json.bzl\", $starlark_pkg_name = \"bin\")" | |
echo "$starlark_pkg_name.ng_binary(name = \"ng\")" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment