Skip to content

Commit e9152c8

Browse files
committed
CLI: fix recursive build
1 parent b068de4 commit e9152c8

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ apps/docs/content/docs/ui/typescript.mdx
2929
packages/mdx-remote/test/fixtures/**/*.js
3030
packages/mdx-remote/test/fixtures/**/*.json
3131
packages/core/test/fixtures/page-trees/**/*.json
32-
build/
32+
3333
routeTree.gen.ts

packages/cli/src/build/validate.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import type { Output, OutputComponent } from '@/registry/schema';
22

33
export function validateOutput(registry: Output) {
4-
function validateComponent(
5-
comp: OutputComponent,
6-
ctx: {
7-
stack?: Map<string, Set<string>>;
8-
} = {},
9-
) {
10-
const { stack = new Map<string, Set<string>>() } = ctx;
4+
const validatedComps = new Set<string>();
5+
const fileToComps = new Map<string, Set<string>>();
6+
7+
function validateComponent(comp: OutputComponent) {
8+
if (validatedComps.has(comp.name)) return;
9+
validatedComps.add(comp.name);
1110

1211
for (const file of comp.files) {
13-
const parents = stack.get(file.path);
12+
const parents = fileToComps.get(file.path);
1413

1514
if (parents) {
1615
parents.add(comp.name);
1716
} else {
18-
stack.set(file.path, new Set([comp.name]));
17+
fileToComps.set(file.path, new Set([comp.name]));
1918
}
2019
}
2120

@@ -26,28 +25,22 @@ export function validateOutput(registry: Output) {
2625
continue;
2726
}
2827

29-
validateComponent(subComp, {
30-
stack,
31-
});
28+
validateComponent(subComp);
3229
}
3330

3431
for (const file of comp.files) {
35-
const parents = stack.get(file.path);
36-
if (!parents) continue;
37-
if (parents.size <= 1) continue;
32+
const parents = fileToComps.get(file.path);
33+
if (!parents || parents.size <= 1) continue;
3834

3935
throw new Error(
4036
`Duplicated file in same component ${Array.from(parents).join(', ')}: ${file.path}`,
4137
);
4238
}
4339
}
4440

45-
const compSet = new Set<string>();
4641
for (const comp of registry.components) {
47-
if (compSet.has(comp.name))
48-
throw new Error(`duplicated component name ${comp.name}`);
49-
compSet.add(comp.name);
50-
42+
// per comp
43+
fileToComps.clear();
5144
validateComponent(comp);
5245
}
5346
}

0 commit comments

Comments
 (0)