The settings checklist pulled values from the contracts barrel, which Turbopack cannot follow. The catalog now lives in its own entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { readdir, readFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
// The console's bundler (Turbopack) cannot follow the NodeNext `.js` imports inside the contracts
|
|
// entry point, and that entry would carry zod and every schema into the browser. The console
|
|
// takes only types from it; values come from entries that import nothing.
|
|
async function sources(directory: string): Promise<string[]> {
|
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
const nested = await Promise.all(
|
|
entries.map(entry => {
|
|
const location = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) return sources(location);
|
|
return /\.tsx?$/.test(entry.name) ? [location] : [];
|
|
}),
|
|
);
|
|
return nested.flat();
|
|
}
|
|
|
|
describe('console bundle', () => {
|
|
it('imports only types from the contracts entry point', async () => {
|
|
const valueImports: string[] = [];
|
|
for (const file of await sources('apps/web/src')) {
|
|
const text = await readFile(file, 'utf8');
|
|
for (const match of text.matchAll(/^\s*(?:import|export)\s+(?!type\b)[^;]*?\bfrom\s+'@wishforge\/contracts'/gm))
|
|
valueImports.push(`${file}: ${match[0].trim()}`);
|
|
}
|
|
expect(valueImports).toEqual([]);
|
|
});
|
|
it('takes the provider catalog, release risk reasons, path rules, wish format, permissions and models from entries that import nothing', async () => {
|
|
const manifest = JSON.parse(await readFile('packages/contracts/package.json', 'utf8'));
|
|
for (const entry of ['providers', 'release-risk', 'path-rules', 'wish', 'permissions', 'models']) {
|
|
expect(manifest.exports[`./${entry}`]).toBe(`./src/${entry}.ts`);
|
|
expect(await readFile(`packages/contracts/src/${entry}.ts`, 'utf8')).not.toMatch(
|
|
/^\s*(?:import|export)\b.*\bfrom\s/m,
|
|
);
|
|
}
|
|
});
|
|
});
|