-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathcheck-bundle-owner-files.ts
More file actions
34 lines (29 loc) · 1.36 KB
/
Copy pathcheck-bundle-owner-files.ts
File metadata and controls
34 lines (29 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from 'node:fs';
import path from 'node:path';
import { COMMAND_OWNER_FILES } from '@agent-device/command-registry/owner-files';
import { getDaemonRouteOwnerFiles } from '../src/daemon/route-owner-files.ts';
import { walkFiles } from './lib/walk-files.ts';
const repoRoot = path.resolve(import.meta.dirname, '..');
const distRoot = path.join(repoRoot, 'dist', 'src');
const ownerPaths = new Set([
...Object.values(COMMAND_OWNER_FILES).flat(),
...Object.values(getDaemonRouteOwnerFiles()),
]);
const forbiddenMetadata = new Set(['ownerFiles', ...ownerPaths]);
const bundleFiles = walkFiles(distRoot).filter((file) => file.endsWith('.js'));
if (bundleFiles.length === 0) {
throw new Error('No dist/src JavaScript files found. Run `pnpm build` first.');
}
const leaks = bundleFiles.flatMap((file) => {
const content = fs.readFileSync(file, 'utf8');
return [...forbiddenMetadata]
.filter((value) => content.includes(value))
.map((value) => ({ file: path.relative(repoRoot, file), value }));
});
if (leaks.length > 0) {
const details = leaks.map(({ file, value }) => `- ${value} in ${file}`).join('\n');
throw new Error(`Owner-file navigation metadata leaked into production bundles:\n${details}`);
}
process.stdout.write(
`Verified the ownerFiles key and ${ownerPaths.size} owner-file paths are absent from ${bundleFiles.length} production bundles.\n`,
);