Skip to content

Commit 445d45b

Browse files
feat: implement low priority tasks
- Add TypeScript gradual adoption (tsconfig.json) - Allow JS files, enable checking gradually - Path mapping for @app, @packages, @templates - Set up bundle size monitoring (scripts/bundle-size-check.js) - Checks JS/CSS file sizes against limits - Warns on large bundles (>500KB JS, >100KB CSS) - Add check-bundle-size script to package.json - Update TODO.md with progress
1 parent 2af4a6e commit 445d45b

3 files changed

Lines changed: 177 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"format": "prettier --write apps/*/app/**/*.js packages/**/*.js",
2525
"audit": "pnpm audit --audit-level moderate",
2626
"prepare": "husky",
27-
"validate-build": "bash scripts/validate-build.sh"
27+
"validate-build": "bash scripts/validate-build.sh",
28+
"check-bundle-size": "node scripts/bundle-size-check.js"
2829
},
2930
"lint-staged": {
3031
"*.js": [

scripts/bundle-size-check.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Bundle Size Monitoring Script
5+
* Checks JS/CSS bundle sizes and alerts on significant increases
6+
*/
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
11+
// Configuration
12+
const CONFIG = {
13+
distDir: 'dist',
14+
maxSizes: {
15+
js: 500 * 1024, // 500KB per JS chunk
16+
css: 100 * 1024, // 100KB per CSS file
17+
total: 2 * 1024 * 1024 // 2MB total
18+
},
19+
// Optional: store previous sizes for comparison
20+
sizeHistoryFile: '.bundle-size-history.json'
21+
};
22+
23+
// Get file size in human readable format
24+
function formatSize(bytes) {
25+
if (bytes < 1024) return bytes + ' B';
26+
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB';
27+
return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
28+
}
29+
30+
// Get all files of a specific type
31+
function getFiles(dir, ext, results = []) {
32+
try {
33+
const files = fs.readdirSync(dir);
34+
for (const file of files) {
35+
const fullPath = path.join(dir, file);
36+
const stat = fs.statSync(fullPath);
37+
if (stat.isDirectory()) {
38+
getFiles(fullPath, ext, results);
39+
} else if (file.endsWith(ext)) {
40+
results.push(fullPath);
41+
}
42+
}
43+
} catch (e) {
44+
console.error(`Error reading directory ${dir}:`, e.message);
45+
}
46+
return results;
47+
}
48+
49+
// Main check function
50+
function checkBundleSizes() {
51+
console.log('🔍 Checking bundle sizes...\n');
52+
53+
if (!fs.existsSync(CONFIG.distDir)) {
54+
console.error('❌ Error: dist/ directory not found. Run "pnpm build" first.');
55+
process.exit(1);
56+
}
57+
58+
// Get all JS and CSS files
59+
const jsFiles = getFiles(CONFIG.distDir, '.js');
60+
const cssFiles = getFiles(CONFIG.distDir, '.css');
61+
62+
let hasWarnings = false;
63+
let totalSize = 0;
64+
65+
// Check JS files
66+
console.log('📜 JavaScript files:');
67+
for (const file of jsFiles) {
68+
const stats = fs.statSync(file);
69+
const size = stats.size;
70+
totalSize += size;
71+
const relativePath = path.relative(CONFIG.distDir, file);
72+
const sizeStr = formatSize(size);
73+
74+
if (size > CONFIG.maxSizes.js) {
75+
console.log(` ❌ ${relativePath}: ${sizeStr} (exceeds ${formatSize(CONFIG.maxSizes.js)})`);
76+
hasWarnings = true;
77+
} else {
78+
console.log(` ✅ ${relativePath}: ${sizeStr}`);
79+
}
80+
}
81+
82+
// Check CSS files
83+
console.log('\n🎨 CSS files:');
84+
for (const file of cssFiles) {
85+
const stats = fs.statSync(file);
86+
const size = stats.size;
87+
totalSize += size;
88+
const relativePath = path.relative(CONFIG.distDir, file);
89+
const sizeStr = formatSize(size);
90+
91+
if (size > CONFIG.maxSizes.css) {
92+
console.log(` ❌ ${relativePath}: ${sizeStr} (exceeds ${formatSize(CONFIG.maxSizes.css)})`);
93+
hasWarnings = true;
94+
} else {
95+
console.log(` ✅ ${relativePath}: ${sizeStr}`);
96+
}
97+
}
98+
99+
// Check total size
100+
console.log(`\n📊 Total bundle size: ${formatSize(totalSize)}`);
101+
if (totalSize > CONFIG.maxSizes.total) {
102+
console.log(`❌ Total size exceeds limit of ${formatSize(CONFIG.maxSizes.total)}`);
103+
hasWarnings = true;
104+
}
105+
106+
// Summary
107+
console.log('\n' + '='.repeat(50));
108+
if (hasWarnings) {
109+
console.log('⚠️ Bundle size warnings detected!');
110+
console.log(' Consider code splitting or lazy loading.');
111+
} else {
112+
console.log('✅ All bundle sizes are within limits!');
113+
}
114+
115+
return !hasWarnings;
116+
}
117+
118+
// Run the check
119+
const success = checkBundleSizes();
120+
process.exit(success ? 0 : 1);

tsconfig.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"compilerOptions": {
3+
// TypeScript configuration for gradual adoption
4+
// Allows mixing JS and TS files during migration
5+
6+
// Basic settings
7+
"target": "ES2020",
8+
"module": "ESNext",
9+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
10+
"moduleResolution": "node",
11+
"allowJs": true, // Allow JS files in the project
12+
"checkJs": false, // Don't type-check JS files (enable gradually)
13+
"maxNodeModuleJsDepth": 2,
14+
15+
// Output settings (not used with Vite, but needed for IDE)
16+
"noEmit": true,
17+
18+
// Strictness (enable gradually)
19+
"strict": false,
20+
"noImplicitAny": false,
21+
"strictNullChecks": false,
22+
"strictFunctionTypes": false,
23+
"strictBindCallApply": false,
24+
"strictPropertyInitialization": false,
25+
"noImplicitThis": false,
26+
"alwaysStrict": false,
27+
28+
// Additional checks
29+
"noUnusedLocals": false,
30+
"noUnusedParameters": false,
31+
"noImplicitReturns": false,
32+
33+
// Module resolution
34+
"baseUrl": ".",
35+
"paths": {
36+
"@app/*": ["apps/main-app/app/*"],
37+
"@packages/*": ["packages/*"],
38+
"@templates/*": ["packages/templates/*"]
39+
},
40+
41+
// Include/exclude
42+
"include": [
43+
"apps/**/*.js",
44+
"packages/**/*.js",
45+
"tests/**/*.js"
46+
],
47+
"exclude": [
48+
"node_modules",
49+
"dist",
50+
"**/*.spec.js",
51+
"**/*.Spec.js"
52+
]
53+
},
54+
"compileOnSave": false
55+
}

0 commit comments

Comments
 (0)