mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
- Removes `rootDirs` so all imports will be relative in the frontend - Updates (and unifies) imports to be `../types/...` etc instead of relying on "types" being in the rootDir for the frontend. - Fixes one type that was being picked up from `lib` in the frontend. - Adds a precommit hook to check in future Paves the way to writing _unit_ tests for the frontend for the subset of the frontend code we can import from `node` (which might be a lot of it!)
30 lines
941 B
JavaScript
30 lines
941 B
JavaScript
#!/usr/bin/env node
|
|
// Check that frontend (static/) code doesn't import from backend (lib/)
|
|
|
|
import {execSync} from 'child_process';
|
|
|
|
try {
|
|
const violations = execSync(
|
|
'git grep -n "from [\'\\\"]\\.\\./.*lib/" -- "static/*.ts" "static/**/*.ts"',
|
|
{encoding: 'utf8'}
|
|
).trim();
|
|
|
|
if (violations) {
|
|
console.error('❌ Error: Frontend code cannot import from backend (lib/) directory!');
|
|
console.error('');
|
|
console.error('Found violations:');
|
|
console.error(violations);
|
|
console.error('');
|
|
console.error('Frontend code should use API calls or import from types/ instead of directly importing backend code.');
|
|
process.exit(1);
|
|
}
|
|
} catch (e) {
|
|
// git grep returns non-zero when no matches found, which is what we want
|
|
if (e.status !== 1) {
|
|
console.error('Error running git grep:', e.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
process.exit(0);
|