- Remove legacy compute-worker monolith under `src/compute/`, including PDF and Whisper inference, control-plane, and runtime orchestration - Move PDF and Whisper inference logic to new `src/inference/` module - Move control-plane, orchestrator, and state machine logic to `src/operations/` - Move NATS/JetStream adapters to `src/infrastructure/` - Move job orchestration, progress, and artifact persistence to `src/jobs/` - Update imports throughout tests and main app to reference new module structure - Update Dockerfile and scripts to use new asset paths - Add new entrypoints: `src/api/app.ts` and `src/api/contracts.ts` - Remove obsolete files and update `.gitignore` for new dev artifacts This refactor modularizes the compute-worker, improving maintainability and separation of concerns. No functional changes to inference or orchestration logic. BREAKING CHANGE: compute-worker internal APIs, directory structure, and imports have changed; downstream code must update imports and integration points.
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const root = process.cwd();
|
|
const serverDir = path.join(root, '.next', 'server');
|
|
|
|
if (!fs.existsSync(serverDir)) {
|
|
console.error('[bundle-guard] Missing .next/server. Run `pnpm build` first.');
|
|
process.exit(1);
|
|
}
|
|
|
|
const forbidden = [
|
|
'onnxruntime-node',
|
|
'@huggingface/tokenizers',
|
|
'@openreader/compute-worker',
|
|
'/compute-worker/src/inference/',
|
|
];
|
|
|
|
const includeExt = new Set(['.js', '.mjs', '.cjs']);
|
|
const failures = [];
|
|
|
|
function walk(dir) {
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const fullPath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
walk(fullPath);
|
|
continue;
|
|
}
|
|
if (!entry.isFile()) continue;
|
|
const ext = path.extname(entry.name).toLowerCase();
|
|
if (!includeExt.has(ext)) continue;
|
|
const text = fs.readFileSync(fullPath, 'utf8');
|
|
for (const pattern of forbidden) {
|
|
if (text.includes(pattern)) {
|
|
failures.push({ file: fullPath, pattern });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
walk(serverDir);
|
|
|
|
if (failures.length > 0) {
|
|
console.error('[bundle-guard] Forbidden compute deps detected in Next server bundle:');
|
|
for (const failure of failures) {
|
|
console.error(`- ${failure.pattern} in ${path.relative(root, failure.file)}`);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
|
|
console.info('[bundle-guard] OK: no forbidden compute deps in .next/server');
|