Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): wrong validation has been fixed in rehype-component.ts #6204

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions apps/www/lib/rehype-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { UnistNode, UnistTree } from "types/unist"
import { u } from "unist-builder"
import { visit } from "unist-util-visit"

import { type RegistryItem } from "@/registry/schema"

import { Index } from "../__registry__"
import { styles } from "../registry/registry-styles"

Expand Down Expand Up @@ -35,18 +37,24 @@ export function rehypeComponent() {
if (srcPath) {
src = path.join(process.cwd(), srcPath)
} else {
const component = Index[style.name][name]
src = fileName
? component.files.find((file: unknown) => {
if (typeof file === "string") {
const component: RegistryItem = Index[style.name][name]
if (component.files) {
console.log(fileName)

src = fileName
? component.files.find((file) => {
return (
file.endsWith(`${fileName}.tsx`) ||
file.endsWith(`${fileName}.ts`)
file.path.endsWith(`${fileName}.tsx`) ||
file.path.endsWith(`${fileName}.ts`)
)
}
return false
}) || component.files[0]?.path
: component.files[0]?.path
})?.path || component.files[0]?.path
: component.files[0]?.path
} else {
// TODO: Is files always exist in Registry type?
// Because in registryItemSchema it is marked like optional.
src = component.files![0]?.path
}
console.log(src);
}

// Read the source file.
Expand Down
2 changes: 2 additions & 0 deletions apps/www/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const registryItemSchema = z.object({
export const registrySchema = z.array(registryItemSchema)

export type Registry = z.infer<typeof registrySchema>
export type RegistryItem = Registry[number]
export type FileRegistry = Registry[number]['files']

export const blockSchema = registryItemSchema.extend({
type: z.literal("registry:block"),
Expand Down