|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * This script replaces vsdbg debugger dependencies with Samsung/netcoredbg |
| 5 | + * in the package.json of the upstream vscode-csharp extension. |
| 6 | + * |
| 7 | + * This is necessary because vsdbg cannot be used with VS Code forks |
| 8 | + * that don't have access to the Microsoft marketplace. |
| 9 | + */ |
| 10 | + |
| 11 | +const fs = require('fs'); |
| 12 | +const path = require('path'); |
| 13 | + |
| 14 | +const NETCOREDBG_VERSION = '3.1.2-1054'; |
| 15 | +const NETCOREDBG_BASE_URL = `https://github.com/Samsung/netcoredbg/releases/download/${NETCOREDBG_VERSION}`; |
| 16 | + |
| 17 | +// Mapping from upstream platforms/architectures to netcoredbg download files |
| 18 | +const platformMapping = { |
| 19 | + // Windows x64 (used for both x86_64 and arm64 on Windows as netcoredbg doesn't have separate ARM64 build for Windows) |
| 20 | + 'win32-x86_64': { |
| 21 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-win64.zip`, |
| 22 | + testPath: './.debugger/x86_64/netcoredbg.exe', |
| 23 | + binaries: ['./netcoredbg.exe'] |
| 24 | + }, |
| 25 | + // Windows ARM64 - use the same x64 build |
| 26 | + 'win32-arm64': { |
| 27 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-win64.zip`, |
| 28 | + testPath: './.debugger/arm64/netcoredbg.exe', |
| 29 | + binaries: ['./netcoredbg.exe'] |
| 30 | + }, |
| 31 | + // macOS x64 |
| 32 | + 'darwin-x86_64': { |
| 33 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-osx-amd64.tar.gz`, |
| 34 | + testPath: './.debugger/x86_64/netcoredbg', |
| 35 | + binaries: ['./netcoredbg'] |
| 36 | + }, |
| 37 | + // macOS ARM64 - use the same x64 build (Rosetta 2) |
| 38 | + 'darwin-arm64': { |
| 39 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-osx-amd64.tar.gz`, |
| 40 | + testPath: './.debugger/arm64/netcoredbg', |
| 41 | + binaries: ['./netcoredbg'] |
| 42 | + }, |
| 43 | + // Linux x64 |
| 44 | + 'linux-x86_64': { |
| 45 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-linux-amd64.tar.gz`, |
| 46 | + testPath: './.debugger/netcoredbg', |
| 47 | + binaries: ['./netcoredbg'] |
| 48 | + }, |
| 49 | + // Linux ARM64 |
| 50 | + 'linux-arm64': { |
| 51 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-linux-arm64.tar.gz`, |
| 52 | + testPath: './.debugger/netcoredbg', |
| 53 | + binaries: ['./netcoredbg'] |
| 54 | + }, |
| 55 | + // Linux musl x64 - use standard linux build |
| 56 | + 'linux-musl-x86_64': { |
| 57 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-linux-amd64.tar.gz`, |
| 58 | + testPath: './.debugger/netcoredbg', |
| 59 | + binaries: ['./netcoredbg'] |
| 60 | + }, |
| 61 | + // Linux musl ARM64 - use standard linux ARM64 build |
| 62 | + 'linux-musl-arm64': { |
| 63 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-linux-arm64.tar.gz`, |
| 64 | + testPath: './.debugger/netcoredbg', |
| 65 | + binaries: ['./netcoredbg'] |
| 66 | + }, |
| 67 | + // Linux ARM - use ARM64 build (most compatible option) |
| 68 | + 'linux-arm': { |
| 69 | + url: `${NETCOREDBG_BASE_URL}/netcoredbg-linux-arm64.tar.gz`, |
| 70 | + testPath: './.debugger/netcoredbg', |
| 71 | + binaries: ['./netcoredbg'] |
| 72 | + } |
| 73 | +}; |
| 74 | + |
| 75 | +function replaceDebugger(packageJsonPath) { |
| 76 | + console.log('Reading package.json...'); |
| 77 | + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 78 | + |
| 79 | + if (!packageJson.runtimeDependencies) { |
| 80 | + console.error('Error: runtimeDependencies not found in package.json'); |
| 81 | + process.exit(1); |
| 82 | + } |
| 83 | + |
| 84 | + console.log('Replacing vsdbg debugger dependencies with netcoredbg...'); |
| 85 | + |
| 86 | + // Find and replace debugger dependencies |
| 87 | + packageJson.runtimeDependencies = packageJson.runtimeDependencies.map(dep => { |
| 88 | + if (dep.id !== 'Debugger') { |
| 89 | + return dep; |
| 90 | + } |
| 91 | + |
| 92 | + // Build platform key |
| 93 | + const platform = dep.platforms[0]; |
| 94 | + const arch = dep.architectures[0]; |
| 95 | + const platformKey = `${platform}-${arch}`; |
| 96 | + |
| 97 | + console.log(` Processing: ${platform}/${arch}`); |
| 98 | + |
| 99 | + if (!platformMapping[platformKey]) { |
| 100 | + console.warn(` Warning: No mapping found for ${platformKey}, keeping original`); |
| 101 | + return dep; |
| 102 | + } |
| 103 | + |
| 104 | + const mapping = platformMapping[platformKey]; |
| 105 | + |
| 106 | + // Create new dependency with netcoredbg |
| 107 | + const newDep = { |
| 108 | + id: 'Debugger', |
| 109 | + description: dep.description.replace('vsdbg', 'netcoredbg').replace('.NET Core Debugger', 'Samsung NetCoreDbg Debugger'), |
| 110 | + url: mapping.url, |
| 111 | + installPath: dep.installPath, |
| 112 | + platforms: dep.platforms, |
| 113 | + architectures: dep.architectures, |
| 114 | + installTestPath: mapping.testPath |
| 115 | + }; |
| 116 | + |
| 117 | + // Add binaries array for non-Windows platforms |
| 118 | + if (mapping.binaries && mapping.binaries.length > 0) { |
| 119 | + newDep.binaries = mapping.binaries; |
| 120 | + } |
| 121 | + |
| 122 | + console.log(` Replaced with: ${mapping.url}`); |
| 123 | + |
| 124 | + // Note: We're removing the integrity field as the hashes will be different |
| 125 | + // The extension should still work without integrity checks |
| 126 | + |
| 127 | + return newDep; |
| 128 | + }); |
| 129 | + |
| 130 | + console.log('Writing updated package.json...'); |
| 131 | + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); |
| 132 | + console.log('✓ Successfully replaced debugger dependencies with netcoredbg'); |
| 133 | +} |
| 134 | + |
| 135 | +// Main execution |
| 136 | +if (require.main === module) { |
| 137 | + const packageJsonPath = process.argv[2] || path.join(__dirname, 'upstream', 'package.json'); |
| 138 | + |
| 139 | + if (!fs.existsSync(packageJsonPath)) { |
| 140 | + console.error(`Error: package.json not found at ${packageJsonPath}`); |
| 141 | + process.exit(1); |
| 142 | + } |
| 143 | + |
| 144 | + replaceDebugger(packageJsonPath); |
| 145 | +} |
| 146 | + |
| 147 | +module.exports = { replaceDebugger }; |
0 commit comments