|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Script to verify that platform-specific native bindings and required dependencies |
| 5 | + * are included in the packaged .vsix file |
| 6 | + */ |
| 7 | + |
| 8 | +import fs from "fs"; |
| 9 | +import path from "path"; |
| 10 | +import { fileURLToPath } from "url"; |
| 11 | +import { execSync } from "child_process"; |
| 12 | + |
| 13 | +const __filename = fileURLToPath(import.meta.url); |
| 14 | +const __dirname = path.dirname(__filename); |
| 15 | +const ROOT_DIR = path.join(__dirname, ".."); |
| 16 | + |
| 17 | +// Find .vsix file |
| 18 | +const vsixFiles = fs |
| 19 | + .readdirSync(ROOT_DIR) |
| 20 | + .filter((f) => f.endsWith(".vsix")) |
| 21 | + .sort((a, b) => { |
| 22 | + const statA = fs.statSync(path.join(ROOT_DIR, a)); |
| 23 | + const statB = fs.statSync(path.join(ROOT_DIR, b)); |
| 24 | + return statB.mtimeMs - statA.mtimeMs; // Most recent first |
| 25 | + }); |
| 26 | + |
| 27 | +if (vsixFiles.length === 0) { |
| 28 | + console.error('No .vsix file found. Run "npx vsce package" first.'); |
| 29 | + process.exit(1); |
| 30 | +} |
| 31 | + |
| 32 | +const vsixFile = vsixFiles[0]; |
| 33 | +console.log(`Checking ${vsixFile}...\n`); |
| 34 | + |
| 35 | +// Extract and check contents |
| 36 | +const tempDir = path.join(ROOT_DIR, ".vsix-check"); |
| 37 | +try { |
| 38 | + fs.mkdirSync(tempDir, { recursive: true }); |
| 39 | + |
| 40 | + // .vsix is just a zip file |
| 41 | + execSync(`unzip -q "${path.join(ROOT_DIR, vsixFile)}" -d "${tempDir}"`, { |
| 42 | + stdio: "inherit", |
| 43 | + }); |
| 44 | + |
| 45 | + const extensionDir = path.join(tempDir, "extension"); |
| 46 | + const oxcParserDir = path.join(extensionDir, "node_modules", "@oxc-parser"); |
| 47 | + |
| 48 | + // Platform-specific bindings that should be included |
| 49 | + const platformBindings = [ |
| 50 | + "@oxc-parser/binding-darwin-arm64", |
| 51 | + "@oxc-parser/binding-darwin-x64", |
| 52 | + "@oxc-parser/binding-linux-x64-gnu", |
| 53 | + "@oxc-parser/binding-win32-x64-msvc", |
| 54 | + ]; |
| 55 | + |
| 56 | + const checks = [ |
| 57 | + { |
| 58 | + name: "oxc-parser", |
| 59 | + path: path.join(extensionDir, "node_modules", "oxc-parser"), |
| 60 | + required: true, |
| 61 | + }, |
| 62 | + ...platformBindings.map((binding) => ({ |
| 63 | + name: binding, |
| 64 | + path: path.join(oxcParserDir, binding.replace("@oxc-parser/", "")), |
| 65 | + required: true, |
| 66 | + })), |
| 67 | + ]; |
| 68 | + |
| 69 | + let allGood = true; |
| 70 | + let foundCount = 0; |
| 71 | + |
| 72 | + for (const check of checks) { |
| 73 | + const exists = fs.existsSync(check.path); |
| 74 | + const status = exists ? "✓" : "✗"; |
| 75 | + console.log(`${status} ${check.name}: ${exists ? "FOUND" : "MISSING"}`); |
| 76 | + |
| 77 | + if (exists) { |
| 78 | + foundCount++; |
| 79 | + // Check for key files in bindings |
| 80 | + if (check.name.startsWith("@oxc-parser/binding-")) { |
| 81 | + // Look for .node files (native bindings) or package.json |
| 82 | + const packageJson = path.join(check.path, "package.json"); |
| 83 | + if (fs.existsSync(packageJson)) { |
| 84 | + console.log(` ✓ package.json found`); |
| 85 | + } else { |
| 86 | + console.log(` ✗ package.json missing`); |
| 87 | + allGood = false; |
| 88 | + } |
| 89 | + } |
| 90 | + } else if (check.required) { |
| 91 | + allGood = false; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + console.log(""); |
| 96 | + console.log(`Found ${foundCount}/${checks.length} required packages`); |
| 97 | + |
| 98 | + if (allGood && foundCount === checks.length) { |
| 99 | + console.log("✓ All required files are included in the package!"); |
| 100 | + } else { |
| 101 | + console.log("✗ Some required files are missing!"); |
| 102 | + if (foundCount < platformBindings.length) { |
| 103 | + console.log( |
| 104 | + ` Warning: Only ${foundCount - 1} platform bindings found, expected ${platformBindings.length}`, |
| 105 | + ); |
| 106 | + console.log(" The extension may not work on all platforms."); |
| 107 | + } |
| 108 | + process.exit(1); |
| 109 | + } |
| 110 | +} finally { |
| 111 | + // Cleanup |
| 112 | + if (fs.existsSync(tempDir)) { |
| 113 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 114 | + } |
| 115 | +} |
0 commit comments