Skip to content

Commit 5a8510a

Browse files
committed
refactor(registry/utils): move determineFileType to dedicated file to utils/registry/determine-file-type.ts avoid upcoming circular deps
- `createFileObject` (to be imported into `utils.ts`) will use `determineFileType`, which currently lives in `utils.ts`. - moving it out prevents circular imports between `utils.ts` and `createFileObject`.
1 parent 77e6f28 commit 5a8510a

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

packages/shadcn/src/registry/utils.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@/src/schema"
99
import { Config } from "@/src/utils/get-config"
1010
import { ProjectInfo, getProjectInfo } from "@/src/utils/get-project-info"
11+
import { determineFileType } from "@/src/utils/registry/determine-file-type"
1112
import { resolveImport } from "@/src/utils/resolve-import"
1213
import {
1314
findCommonRoot,
@@ -227,30 +228,6 @@ async function createTempSourceFile(filename: string) {
227228
return path.join(dir, filename)
228229
}
229230

230-
// This is a bit tricky to accurately determine.
231-
// For now we'll use the module specifier to determine the type.
232-
function determineFileType(
233-
moduleSpecifier: string
234-
): z.infer<typeof registryItemSchema>["type"] {
235-
if (moduleSpecifier.includes("/ui/")) {
236-
return "registry:ui"
237-
}
238-
239-
if (moduleSpecifier.includes("/lib/")) {
240-
return "registry:lib"
241-
}
242-
243-
if (moduleSpecifier.includes("/hooks/")) {
244-
return "registry:hook"
245-
}
246-
247-
if (moduleSpecifier.includes("/components/")) {
248-
return "registry:component"
249-
}
250-
251-
return "registry:component"
252-
}
253-
254231
// Additional utility functions for local file support
255232
export function isUrl(path: string) {
256233
try {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { RegistryItem } from "@/src/registry/schema"
2+
3+
// This is a bit tricky to accurately determine.
4+
// For now we'll use the module specifier to determine the type.
5+
const determineFileType = (moduleSpecifier: string): RegistryItem["type"] => {
6+
if (moduleSpecifier.includes("/ui/")) {
7+
return "registry:ui"
8+
}
9+
10+
if (moduleSpecifier.includes("/lib/")) {
11+
return "registry:lib"
12+
}
13+
14+
if (moduleSpecifier.includes("/hooks/")) {
15+
return "registry:hook"
16+
}
17+
18+
if (moduleSpecifier.includes("/components/")) {
19+
return "registry:component"
20+
}
21+
22+
return "registry:component"
23+
}
24+
25+
export { determineFileType }

0 commit comments

Comments
 (0)