Visual Studio Code, rebuilt in Rust
Rust
#!/usr/bin/env bash
# Downloads product.json `builtInExtensions` (js-debug, js-debug-companion, vscode-js-profile-table) and
# port/product.json `portBuiltInExtensions` (tombi, path-intellisense) from Open VSX into <folder>, by default
# .build/builtInExtensions of the VS Code tree (VSCODE_SRC), where the app scans them as upstream's dev build does.
# A platform-specific extension (tombi) is downloaded for <target>, VS Code's target platform name, by default the
# host's (darwin-arm64). All of them are MIT (port/notes.md).
# Usage: port/tools/fetch-builtin-extensions [<folder> <target>]
set -euo pipefail
source "$(dirname "$0")/vscode-src.sh"
port_product=$(cd "$(dirname "$0")/../.." && pwd)/port/product.json
folder=${1:-$VSCODE_SRC/.build/builtInExtensions}
mkdir -p "$folder"
folder=$(cd "$folder" && pwd)
case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) os=win32 ;; esac
case "$(uname -m)" in arm64 | aarch64) arch=arm64 ;; *) arch=x64 ;; esac
target=${2:-$os-$arch}
cd "$VSCODE_SRC"
# jq on Windows ends lines with CRLF, and the \r in the version made curl exit 3 (malformed URL).
jq -r '(.builtInExtensions // []) + (.portBuiltInExtensions // []) | .[] | "\(.name) \(.version) \(.activationEvents | tojson)"' product.json "$port_product" | tr -d '\r' | while read -r name version events; do
if [[ "$(jq -r .version "$folder/$name/package.json" 2>/dev/null)" != "$version" ]]; then
publisher=${name%%.*}
extension=${name#*.}
url=$(curl -sf "https://open-vsx.org/api/$publisher/$extension/$version" | jq -r --arg target "$target" '.downloads[$target] // .downloads.universal')
vsix=$(mktemp)
curl -sfL -o "$vsix" "$url"
unpacked=$(mktemp -d)
unzip -q "$vsix" 'extension/*' -d "$unpacked"
rm -rf "${folder:?}/$name"
mv "$unpacked/extension" "$folder/$name"
rm -rf "$vsix" "$unpacked"
echo "$name $version $target"
fi
# port/product.json may narrow an extension's activation events: tombi's `workspaceContains:**/*.toml` searched every
# opened folder and started its server with no TOML file open.
if [[ $events != null ]]; then
manifest=$(jq --argjson events "$events" '.activationEvents = $events' "$folder/$name/package.json")
printf '%s\n' "$manifest" >"$folder/$name/package.json"
fi
done