Last active
October 14, 2025 15:24
-
-
Save Loskir/7541f26c8df183bf7c07acc86c3e5397 to your computer and use it in GitHub Desktop.
Download and patch TypeScript Native VSCode extension to work with Cursor
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 -e # Exit on any error | |
| # Configuration | |
| PUBLISHER="TypeScriptTeam" | |
| EXTENSION_NAME="native-preview" | |
| ARCHITECTURE="darwin-arm64" | |
| echo "Step 1: Requesting extension information from VS Code Marketplace..." | |
| # Make the API request to get extension information | |
| if ! response=$(curl -s 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \ | |
| --compressed \ | |
| -X POST \ | |
| -H 'Accept: application/json;api-version=7.2-preview.1;excludeUrls=true' \ | |
| -H 'Content-Type: application/json' \ | |
| --data-raw "{\"assetTypes\":null,\"filters\":[{\"criteria\":[{\"filterType\":7,\"value\":\"$PUBLISHER.$EXTENSION_NAME\"}],\"direction\":2,\"pageSize\":100,\"pageNumber\":1,\"sortBy\":0,\"sortOrder\":0,\"pagingToken\":null}],\"flags\":2151}"); then | |
| echo "Error: Failed to fetch extension information" | |
| exit 1 | |
| fi | |
| echo "✓ Extension information retrieved successfully" | |
| # Display basic info about the response | |
| echo "" | |
| echo "Response preview:" | |
| echo "$response" | head -c 200 | |
| echo "..." | |
| echo "" | |
| echo "Step 2: Finding $ARCHITECTURE version..." | |
| # Check if jq is available | |
| if ! command -v jq &> /dev/null; then | |
| echo "Error: jq is required but not installed. Please install jq first." | |
| exit 1 | |
| fi | |
| # Extract the first version with targetPlatform = $ARCHITECTURE | |
| version=$(echo "$response" | jq -r ".results[0].extensions[0].versions[] | select(.targetPlatform == \"$ARCHITECTURE\") | .version" | head -1) | |
| if [ -z "$version" ]; then | |
| echo "Error: No $ARCHITECTURE version found" | |
| exit 1 | |
| fi | |
| echo "✓ Found $ARCHITECTURE version: $version" | |
| echo "" | |
| echo "Step 3: Downloading extension package..." | |
| # Download the extension package | |
| download_url="https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${PUBLISHER}/vsextensions/${EXTENSION_NAME}/${version}/vspackage?targetPlatform=${ARCHITECTURE}" | |
| echo "Download URL: $download_url" | |
| if ! curl -L "$download_url" -o "tsgo_original.vsix"; then | |
| echo "Error: Failed to download extension package" | |
| exit 1 | |
| fi | |
| echo "✓ Extension package downloaded as tsgo_original.vsix" | |
| echo "" | |
| echo "Step 4: Unzipping the extension package..." | |
| # Create a temporary directory for extraction | |
| temp_dir="tsgo_extraction_temp" | |
| rm -rf "$temp_dir" | |
| mkdir -p "$temp_dir" | |
| # First, check if the file is gzip compressed | |
| if file "tsgo_original.vsix" | grep -q "gzip"; then | |
| echo "File is gzip compressed, decompressing first..." | |
| gunzip -c "tsgo_original.vsix" > "tsgo_decompressed.vsix" | |
| vsix_file="tsgo_decompressed.vsix" | |
| else | |
| vsix_file="tsgo_original.vsix" | |
| fi | |
| # Unzip the extension package | |
| if ! unzip -q "$vsix_file" -d "$temp_dir"; then | |
| echo "Error: Failed to unzip extension package" | |
| exit 1 | |
| fi | |
| echo "✓ Extension package unzipped to $temp_dir" | |
| # List the contents to verify | |
| echo "Contents of extracted package:" | |
| ls -la "$temp_dir" | |
| echo "" | |
| echo "Step 5: Patching package.json..." | |
| # Check if the extension folder exists | |
| if [ ! -d "$temp_dir/extension" ]; then | |
| echo "Error: extension folder not found in extracted package" | |
| exit 1 | |
| fi | |
| # Check if package.json exists | |
| package_json="$temp_dir/extension/package.json" | |
| if [ ! -f "$package_json" ]; then | |
| echo "Error: package.json not found in extension folder" | |
| exit 1 | |
| fi | |
| # Show current engines.vscode value | |
| echo "Current engines.vscode value:" | |
| jq '.engines.vscode' "$package_json" | |
| # Patch the package.json to set engines.vscode to "^1.0.0" | |
| if ! jq '.engines.vscode = "^1.0.0"' "$package_json" > "$package_json.tmp" || ! mv "$package_json.tmp" "$package_json"; then | |
| echo "Error: Failed to patch package.json" | |
| exit 1 | |
| fi | |
| echo "✓ package.json patched successfully" | |
| echo "" | |
| echo "Step 6: Creating final tsgo.vsix package..." | |
| # Navigate to the temp directory and zip only the extension folder | |
| cd "$temp_dir" | |
| if ! zip -r "../tsgo.vsix" extension/ > /dev/null; then | |
| echo "Error: Failed to create tsgo.vsix" | |
| exit 1 | |
| fi | |
| cd .. | |
| echo "✓ tsgo.vsix created successfully" | |
| # Show final file info | |
| echo "" | |
| echo "Final result:" | |
| ls -la tsgo.vsix | |
| echo "" | |
| echo "✓ All steps completed successfully!" | |
| echo "The patched extension is now available as tsgo.vsix" | |
| # Clean up temporary files | |
| echo "" | |
| echo "Cleaning up temporary files..." | |
| rm -rf "$temp_dir" | |
| rm -f "tsgo_original.vsix" | |
| rm -f "tsgo_decompressed.vsix" | |
| echo "✓ Cleanup completed" | |
| echo "" | |
| echo "Installing extension into Cursor..." | |
| vsix_path="$(pwd)/tsgo.vsix" | |
| # Check if cursor command is available | |
| if ! command -v cursor &> /dev/null; then | |
| echo "Warning: cursor command not found. Skipping automatic installation." | |
| echo "You can manually install the extension using one of these methods:" | |
| echo "1. Command line: cursor --install-extension \"$vsix_path\"" | |
| echo "2. In Cursor: Command Palette (Cmd+Shift+P) → \"Extensions: Install from VSIX...\" → select tsgo.vsix" | |
| echo "3. In Cursor: Right-click on tsgo.vsix file → \"Install extension VSIX\"" | |
| exit 0 | |
| fi | |
| if cursor --install-extension "$vsix_path"; then | |
| echo "✓ Extension installed successfully into Cursor" | |
| else | |
| echo "Error: Failed to install extension into Cursor" | |
| echo "You can manually install the extension using one of these methods:" | |
| echo "1. Command line: cursor --install-extension \"$vsix_path\"" | |
| echo "2. In Cursor: Command Palette (Cmd+Shift+P) → \"Extensions: Install from VSIX...\" → select tsgo.vsix" | |
| echo "3. In Cursor: Right-click on tsgo.vsix file → \"Install extension VSIX\"" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment