UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
chore(www): remove unused rehype plugins (#1023)
Jinho030f2f1db7f9
diff --git a/apps/www/lib/rehype-component.ts b/apps/www/lib/rehype-component.tsdeleted file mode 100644index f1bfc93d..00000000--- a/apps/www/lib/rehype-component.ts+++ /dev/null@@ -1,149 +0,0 @@-import fs from "fs"-import path from "path"-import { type UnistNode, type UnistTree } from "types/unist"-import { u } from "unist-builder"-import { visit } from "unist-util-visit"--import { Index } from "@/registry/__index__"--export function rehypeComponent() {- return async (tree: UnistTree) => {- visit(tree, (node: UnistNode) => {- // src prop overrides both name and fileName.- const { value: srcPath } =- (getNodeAttributeByName(node, "src") as {- name: string- value?: string- type?: string- }) ?? {}-- if (node.name === "ComponentSource") {- const name = getNodeAttributeByName(node, "name")?.value as string- const fileName = getNodeAttributeByName(node, "fileName")?.value as- string | undefined-- if (!name && !srcPath) {- return null- }-- try {- let src: string-- if (srcPath) {- src = path.join(process.cwd(), srcPath)- } else {- const component = Index[name]- src = fileName- ? (component.files.find((file: unknown) => {- if (typeof file === "string") {- return (- file.endsWith(`${fileName}.tsx`) ||- file.endsWith(`${fileName}.ts`)- )- }- return false- }) ?? component.files[0]?.path)- : component.files[0]?.path- }-- // Read the source file.- const filePath = src- let source = fs.readFileSync(filePath, "utf8")-- // Replace imports.- // TODO: Use @swc/core and a visitor to replace this.- // For now a simple regex should do.- source = source.replaceAll(`@/registry/${name}/`, "@/components/")- source = source.replaceAll("export default", "export")-- // Add code as children so that rehype can take over at build time.- node.children?.push(- u("element", {- tagName: "pre",- properties: {- __src__: src,- __style__: name,- },- attributes: [- {- name: "styleName",- type: "mdxJsxAttribute",- value: name,- },- ],- children: [- u("element", {- tagName: "code",- properties: {- className: ["language-tsx"],- },- children: [- {- type: "text",- value: source,- },- ],- }),- ],- })- )- } catch (error) {- console.error(error)- }- }-- if (node.name === "ComponentPreview") {- const name = getNodeAttributeByName(node, "name")?.value as string-- if (!name) {- return null- }-- try {- const component = Index[name]- const src = component.files[0]?.path-- // Read the source file.- const filePath = src- let source = fs.readFileSync(filePath, "utf8")-- // Replace imports.- // TODO: Use @swc/core and a visitor to replace this.- // For now a simple regex should do.- source = source.replaceAll(`@/registry/${name}/`, "@/components/")- source = source.replaceAll("export default", "export")-- // Add code as children so that rehype can take over at build time.- node.children?.push(- u("element", {- tagName: "pre",- properties: {- __src__: src,- },- children: [- u("element", {- tagName: "code",- properties: {- className: ["language-tsx"],- },- children: [- {- type: "text",- value: source,- },- ],- }),- ],- })- )- } catch (error) {- console.error(error)- }- }- })- }-}--function getNodeAttributeByName(node: UnistNode, name: string) {- return node.attributes?.find((attribute) => attribute.name === name)-}diff --git a/apps/www/lib/rehype-npm-command.ts b/apps/www/lib/rehype-npm-command.tsdeleted file mode 100644index 55b46216..00000000--- a/apps/www/lib/rehype-npm-command.ts+++ /dev/null@@ -1,99 +0,0 @@-import { type UnistNode, type UnistTree } from "types/unist"-import { visit } from "unist-util-visit"--export function rehypeNpmCommand() {- return (tree: UnistTree) => {- visit(tree, (node: UnistNode) => {- if (node.type !== "element" || node?.tagName !== "pre") {- return- }-- // npm install.- if (node.properties?.["__rawString__"]?.startsWith("npm install")) {- const npmCommand = node.properties?.["__rawString__"]- node.properties["__npmCommand__"] = npmCommand- node.properties["__yarnCommand__"] = npmCommand.replace(- "npm install",- "yarn add"- )- node.properties["__pnpmCommand__"] = npmCommand.replace(- "npm install",- "pnpm add"- )- node.properties["__bunCommand__"] = npmCommand.replace(- "npm install",- "bun add"- )- }-- // npx create-.- if (node.properties?.["__rawString__"]?.startsWith("npx create-")) {- const npmCommand = node.properties?.["__rawString__"]- node.properties["__npmCommand__"] = npmCommand- node.properties["__yarnCommand__"] = npmCommand.replace(- "npx create-",- "yarn create "- )- node.properties["__pnpmCommand__"] = npmCommand.replace(- "npx create-",- "pnpm create "- )- node.properties["__bunCommand__"] = npmCommand.replace(- "npx",- "bun x --bun"- )- }-- // npm create.- if (node.properties?.["__rawString__"]?.startsWith("npm create")) {- const npmCommand = node.properties?.["__rawString__"]- node.properties["__npmCommand__"] = npmCommand- node.properties["__yarnCommand__"] = npmCommand.replace(- "npm create",- "yarn create"- )- node.properties["__pnpmCommand__"] = npmCommand.replace(- "npm create",- "pnpm create"- )- node.properties["__bunCommand__"] = npmCommand.replace(- "npm create",- "bun create"- )- }-- // npx.- if (- node.properties?.["__rawString__"]?.startsWith("npx") &&- !node.properties?.["__rawString__"]?.startsWith("npx create-")- ) {- const npmCommand = node.properties?.["__rawString__"]- node.properties["__npmCommand__"] = npmCommand- node.properties["__yarnCommand__"] = npmCommand- node.properties["__pnpmCommand__"] = npmCommand.replace(- "npx",- "pnpm dlx"- )- node.properties["__bunCommand__"] = npmCommand.replace(- "npx",- "bun x --bun"- )- }-- // npm run.- if (node.properties?.["__rawString__"]?.startsWith("npm run")) {- const npmCommand = node.properties?.["__rawString__"]- node.properties["__npmCommand__"] = npmCommand- node.properties["__yarnCommand__"] = npmCommand.replace(- "npm run",- "yarn"- )- node.properties["__pnpmCommand__"] = npmCommand.replace(- "npm run",- "pnpm"- )- node.properties["__bunCommand__"] = npmCommand.replace("npm run", "bun")- }- })- }-}diff --git a/apps/www/package.json b/apps/www/package.jsonindex bb73643f..275d5477 100644--- a/apps/www/package.json+++ b/apps/www/package.json@@ -85,7 +85,6 @@"@types/node": "^22.20.1","@types/react": "^19.1.1","@types/react-dom": "^19.1.1",- "@types/unist": "^3.0.3","eslint": "^9.36.0","eslint-config-next": "15.5.4","eslint-config-prettier": "^10.1.8",@@ -104,9 +103,7 @@"shadcn": "3.3.1","shiki": "^2.5.0","tsx": "^4.20.5",- "typescript": "^5.9.2",- "unist-builder": "4.0.0",- "unist-util-visit": "^5.0.0"+ "typescript": "^5.9.2"},"engines": {"node": ">=22.14.0",diff --git a/apps/www/types/unist.ts b/apps/www/types/unist.tsdeleted file mode 100644index b0a62d04..00000000--- a/apps/www/types/unist.ts+++ /dev/null@@ -1,31 +0,0 @@-import type { Node } from "unist"--export interface UnistNode extends Node {- type: string- name?: string- tagName?: string- value?: string- properties?: {- __rawString__?: string- __className__?: string- __event__?: string- [key: string]: unknown- } & NpmCommands- attributes?: {- name: string- value: unknown- type?: string- }[]- children?: UnistNode[]-}--export interface UnistTree extends UnistNode {- children: UnistNode[]-}--export interface NpmCommands {- __npmCommand__?: string- __yarnCommand__?: string- __pnpmCommand__?: string- __bunCommand__?: string-}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex c768fcca..6d646861 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -213,9 +213,6 @@ importers:'@types/react-dom':specifier: ^19.1.1version: 19.2.7(@types/[email protected])- '@types/unist':- specifier: ^3.0.3- version: 3.0.3eslint:specifier: ^9.36.0version: 9.39.5([email protected])@@ -273,12 +270,6 @@ importers:typescript:specifier: ^5.9.2version: 5.9.3- unist-builder:- specifier: 4.0.0- version: 4.0.0- unist-util-visit:- specifier: ^5.0.0- version: 5.1.0packages:@@ -5654,9 +5645,6 @@ packages:resolution: {integrity: sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA==}- resolution: {integrity: sha512-wmRFnH+BLpZnTKpc5L7O67Kac89s9HMrtELpnNaE6TAobq5DTZZs5YaTQfAZBA9bFPECx2uVAPO31c+GVug8mg==}-resolution: {integrity: sha512-u9njyyfEh43npf1M+yGKDGVPbY/JWEemg5nH05ncKPfi+kBbKBJoTdsogMu33uhytuLlv9y0O7GH7fEdwLdLQw==}@@ -11868,10 +11856,6 @@ snapshots:trough: 2.2.0vfile: 6.0.3- dependencies:- '@types/unist': 3.0.3-dependencies:'@types/unist': 2.0.11