Skip to content

Commit e51dbbc

Browse files
JOHNJOHN
authored andcommitted
Add build validation script to check for common errors
- Validates content.js is IIFE format (not ES modules) - Checks all required files exist - Verifies manifest.json configuration - Can be run with: npm run build:check
1 parent bcc86a6 commit e51dbbc

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

check-build.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Build validation script - checks for common issues
4+
*/
5+
6+
import fs from 'fs';
7+
import path from 'path';
8+
import { fileURLToPath } from 'url';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
13+
const distDir = path.join(__dirname, 'dist');
14+
const errors = [];
15+
const warnings = [];
16+
17+
console.log('🔍 Checking build...\n');
18+
19+
// Check if dist directory exists
20+
if (!fs.existsSync(distDir)) {
21+
errors.push('❌ dist/ directory does not exist. Run: npm run build');
22+
console.error(errors[0]);
23+
process.exit(1);
24+
}
25+
26+
// Check content.js
27+
const contentJs = path.join(distDir, 'content.js');
28+
if (!fs.existsSync(contentJs)) {
29+
errors.push('❌ dist/content.js is missing. Run: npm run build');
30+
} else {
31+
const content = fs.readFileSync(contentJs, 'utf8');
32+
33+
// Check format
34+
if (content.trim().startsWith('var ') || content.trim().startsWith('(function')) {
35+
console.log('✅ content.js is in IIFE format');
36+
} else if (content.includes('const _vite_mapDeps') || content.includes('import ') || content.includes('export ')) {
37+
errors.push('❌ content.js contains ES module syntax (import/export). Should be IIFE format.');
38+
} else {
39+
warnings.push('⚠️ content.js format unclear - may need manual inspection');
40+
}
41+
42+
// Check size
43+
const size = fs.statSync(contentJs).size;
44+
if (size < 10000) {
45+
warnings.push(`⚠️ content.js is very small (${size} bytes) - may be incomplete`);
46+
} else {
47+
console.log(`✅ content.js size: ${(size / 1024).toFixed(1)} KB`);
48+
}
49+
}
50+
51+
// Check manifest.json
52+
const manifestJson = path.join(distDir, 'manifest.json');
53+
if (!fs.existsSync(manifestJson)) {
54+
errors.push('❌ dist/manifest.json is missing');
55+
} else {
56+
const manifest = JSON.parse(fs.readFileSync(manifestJson, 'utf8'));
57+
58+
// Check content script config
59+
if (manifest.content_scripts && manifest.content_scripts[0]) {
60+
const cs = manifest.content_scripts[0];
61+
if (cs.js && cs.js.includes('content.js')) {
62+
console.log('✅ manifest.json correctly references content.js');
63+
} else {
64+
errors.push('❌ manifest.json content_scripts does not reference content.js');
65+
}
66+
} else {
67+
errors.push('❌ manifest.json missing content_scripts configuration');
68+
}
69+
}
70+
71+
// Check background.js
72+
const backgroundJs = path.join(distDir, 'background.js');
73+
if (!fs.existsSync(backgroundJs)) {
74+
errors.push('❌ dist/background.js is missing');
75+
} else {
76+
console.log('✅ background.js exists');
77+
}
78+
79+
// Check icons
80+
const iconsDir = path.join(distDir, 'icons');
81+
if (!fs.existsSync(iconsDir)) {
82+
warnings.push('⚠️ dist/icons/ directory missing');
83+
} else {
84+
const requiredIcons = ['icon16.png', 'icon48.png', 'icon128.png'];
85+
const missingIcons = requiredIcons.filter(icon =>
86+
!fs.existsSync(path.join(iconsDir, icon))
87+
);
88+
if (missingIcons.length > 0) {
89+
warnings.push(`⚠️ Missing icons: ${missingIcons.join(', ')}`);
90+
} else {
91+
console.log('✅ All required icons present');
92+
}
93+
}
94+
95+
// Summary
96+
console.log('\n' + '='.repeat(50));
97+
if (errors.length > 0) {
98+
console.error('\n❌ ERRORS FOUND:');
99+
errors.forEach(e => console.error(' ' + e));
100+
process.exit(1);
101+
} else {
102+
console.log('\n✅ Build validation passed!');
103+
if (warnings.length > 0) {
104+
console.log('\n⚠️ WARNINGS:');
105+
warnings.forEach(w => console.warn(' ' + w));
106+
}
107+
console.log('\n📦 Extension is ready to load in Chrome');
108+
console.log(' Location: ' + distDir);
109+
process.exit(0);
110+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"dev": "vite build --watch --mode development",
88
"build": "tsc && vite build && vite build --config vite.content.config.ts",
9+
"build:check": "npm run build && node check-build.js",
910
"build:analyze": "tsc && vite build && npm run analyze",
1011
"analyze": "npx vite-bundle-visualizer --open",
1112
"preview": "vite preview",

0 commit comments

Comments
 (0)