|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Bundler Compatibility Validator |
| 5 | + * |
| 6 | + * Purpose: Verify SDK can be bundled with popular bundlers (Webpack, Vite, Rollup) |
| 7 | + * This catches bundling issues before customers hit them! |
| 8 | + * |
| 9 | + * Usage: node scripts/test-bundlers.js |
| 10 | + */ |
| 11 | + |
| 12 | +const { execSync } = require('child_process'); |
| 13 | +const fs = require('fs'); |
| 14 | +const path = require('path'); |
| 15 | + |
| 16 | +// ANSI color codes |
| 17 | +const colors = { |
| 18 | + reset: '\x1b[0m', |
| 19 | + red: '\x1b[31m', |
| 20 | + green: '\x1b[32m', |
| 21 | + yellow: '\x1b[33m', |
| 22 | + blue: '\x1b[34m', |
| 23 | +}; |
| 24 | + |
| 25 | +console.log(`${colors.blue}🔧 Bundler Compatibility Tests${colors.reset}\n`); |
| 26 | + |
| 27 | +// Test configurations for different bundlers |
| 28 | +const bundlerTests = [ |
| 29 | + { |
| 30 | + name: 'Webpack (Browser)', |
| 31 | + command: 'npx webpack --mode production --entry ./src/index.ts --output-path ./test-dist/webpack --target web', |
| 32 | + enabled: true, |
| 33 | + }, |
| 34 | + { |
| 35 | + name: 'Vite (Browser)', |
| 36 | + command: 'npx vite build --outDir ./test-dist/vite', |
| 37 | + enabled: false, // Would need vite.config.js |
| 38 | + note: 'Requires vite.config.js - skipping for now', |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'Rollup (Browser)', |
| 42 | + command: 'npx rollup src/index.ts --file test-dist/rollup/bundle.js --format esm', |
| 43 | + enabled: false, // Would need rollup.config.js |
| 44 | + note: 'Requires rollup.config.js - skipping for now', |
| 45 | + }, |
| 46 | +]; |
| 47 | + |
| 48 | +let passed = 0; |
| 49 | +let failed = 0; |
| 50 | +let skipped = 0; |
| 51 | + |
| 52 | +bundlerTests.forEach(({ name, command, enabled, note }) => { |
| 53 | + if (!enabled) { |
| 54 | + console.log(`${colors.yellow}⊘ SKIPPED: ${name}${colors.reset}`); |
| 55 | + if (note) { |
| 56 | + console.log(` ${colors.yellow}└─ ${note}${colors.reset}\n`); |
| 57 | + } |
| 58 | + skipped++; |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + console.log(`${colors.blue}🔨 Testing: ${name}${colors.reset}`); |
| 63 | + console.log(` Command: ${command}`); |
| 64 | + |
| 65 | + try { |
| 66 | + // Run bundler |
| 67 | + execSync(command, { |
| 68 | + stdio: 'pipe', |
| 69 | + encoding: 'utf8', |
| 70 | + }); |
| 71 | + |
| 72 | + console.log(`${colors.green}✅ PASSED: ${name}${colors.reset}\n`); |
| 73 | + passed++; |
| 74 | + } catch (error) { |
| 75 | + console.log(`${colors.red}❌ FAILED: ${name}${colors.reset}`); |
| 76 | + console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`); |
| 77 | + failed++; |
| 78 | + } |
| 79 | +}); |
| 80 | + |
| 81 | +// Summary |
| 82 | +console.log(`${colors.blue}═══════════════════════════════════════════${colors.reset}`); |
| 83 | +console.log(`${colors.blue}Summary:${colors.reset}`); |
| 84 | +console.log(` Passed: ${colors.green}${passed}${colors.reset}`); |
| 85 | +console.log(` Failed: ${failed > 0 ? colors.red + failed : colors.green + '0'}${colors.reset}`); |
| 86 | +console.log(` Skipped: ${colors.yellow}${skipped}${colors.reset}`); |
| 87 | + |
| 88 | +// Cleanup test output |
| 89 | +try { |
| 90 | + if (fs.existsSync('./test-dist')) { |
| 91 | + fs.rmSync('./test-dist', { recursive: true }); |
| 92 | + console.log(`\n${colors.blue}🧹 Cleaned up test artifacts${colors.reset}`); |
| 93 | + } |
| 94 | +} catch (e) { |
| 95 | + // Ignore cleanup errors |
| 96 | +} |
| 97 | + |
| 98 | +if (failed > 0) { |
| 99 | + console.log(`\n${colors.red}⛔ BUNDLER TESTS FAILED${colors.reset}\n`); |
| 100 | + process.exit(1); |
| 101 | +} else { |
| 102 | + console.log(`\n${colors.green}✅ ALL BUNDLER TESTS PASSED${colors.reset}\n`); |
| 103 | + process.exit(0); |
| 104 | +} |
| 105 | + |
0 commit comments