MCPcopy
hub / github.com/shadcn-ui/ui / createRegistryServer

Function createRegistryServer

packages/tests/src/utils/registry.ts:5–256  ·  view source on GitHub ↗
(
  items: Array<{ name: string; type: string } & Record<string, unknown>>,
  {
    port = 4444,
    path = "/r",
  }: {
    port?: number
    path?: string
  }
)

Source from the content-addressed store, hash-verified

3import fs from "fs-extra"
4
5export async function createRegistryServer(
6 items: Array<{ name: string; type: string } & Record<string, unknown>>,
7 {
8 port = 4444,
9 path = "/r",
10 }: {
11 port?: number
12 path?: string
13 }
14) {
15 const server = createServer((request, response) => {
16 const urlRaw = request.url?.split("?")[0]
17
18 // Handle registries.json endpoint (don't strip .json for this one).
19 if (urlRaw?.endsWith("/registries.json")) {
20 response.writeHead(200, { "Content-Type": "application/json" })
21 // Return empty registry array for tests - we want to test manual configuration.
22 response.end(JSON.stringify([]))
23 return
24 }
25
26 // For other endpoints, strip .json extension
27 const urlWithoutQuery = urlRaw?.replace(/\.json$/, "")
28
29 if (urlWithoutQuery?.includes("icons/index")) {
30 response.writeHead(200, { "Content-Type": "application/json" })
31 response.end(
32 JSON.stringify({
33 AlertCircle: {
34 lucide: "AlertCircle",
35 radix: "ExclamationTriangleIcon",
36 },
37 ArrowLeft: {
38 lucide: "ArrowLeft",
39 radix: "ArrowLeftIcon",
40 },
41 })
42 )
43 return
44 }
45
46 if (urlWithoutQuery?.includes("colors/neutral")) {
47 response.writeHead(200, { "Content-Type": "application/json" })
48 response.end(
49 JSON.stringify({
50 inlineColors: {
51 light: {
52 background: "white",
53 foreground: "neutral-950",
54 },
55 dark: {
56 background: "neutral-950",
57 foreground: "neutral-50",
58 },
59 },
60 cssVars: {
61 light: {
62 background: "0 0% 100%",

Callers 6

init.test.tsFile · 0.90
view.test.tsFile · 0.90
registries.test.tsFile · 0.90
add.test.tsFile · 0.90
search.test.tsFile · 0.90
resolver.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected