From 1a6953e256db4a78a3c74cef5748a6c9a38be488 Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Fri, 13 Dec 2024 10:46:15 -0500 Subject: [PATCH] registry: pin deps --- sites/docs/scripts/registry.ts | 15 ++++++++++++--- sites/docs/scripts/tmp.ts | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 sites/docs/scripts/tmp.ts diff --git a/sites/docs/scripts/registry.ts b/sites/docs/scripts/registry.ts index dd420e02f..29f189a59 100644 --- a/sites/docs/scripts/registry.ts +++ b/sites/docs/scripts/registry.ts @@ -3,6 +3,7 @@ import path from "node:path"; import { parse, preprocess, walk } from "svelte/compiler"; import { type Registry, styles } from "../src/lib/registry"; import config from "../svelte.config.js"; +import { TMP_PINNED_DEPS } from "./tmp"; // [Dependency, [...PeerDependencies]] const DEPENDENCIES = new Map([ @@ -48,6 +49,14 @@ export async function buildRegistry() { return registry; } +function getDepsWithPinned(deps: Set) { + return Array.from(deps).map((dep) => { + const pinnedDep = TMP_PINNED_DEPS.get(dep) + if (pinnedDep) return pinnedDep + return dep + }) +} + async function crawlUI(rootPath: string, style: string) { const dir = fs.readdirSync(rootPath, { recursive: true, @@ -102,7 +111,7 @@ async function buildUIRegistry(componentPath: string, componentName: string, sty files, name: componentName, registryDependencies: Array.from(registryDependencies), - dependencies: Array.from(dependencies), + dependencies: getDepsWithPinned(dependencies), } satisfies RegistryItem; } @@ -133,7 +142,7 @@ async function crawlDemo(rootPath: string, style: string, demoType: "example" | style, files: [file], registryDependencies: Array.from(registryDependencies), - dependencies: Array.from(dependencies), + dependencies: getDepsWithPinned(dependencies), }); } @@ -147,8 +156,8 @@ async function getDependencies(filename: string, source: string) { const registryDependencies = new Set(); const dependencies = new Set(); - // @ts-expect-error annoying walk(ast.instance, { + // @ts-expect-error annoying enter(node) { if (node.type === "ImportDeclaration") { const source = node.source.value as string; diff --git a/sites/docs/scripts/tmp.ts b/sites/docs/scripts/tmp.ts new file mode 100644 index 000000000..ab6204b97 --- /dev/null +++ b/sites/docs/scripts/tmp.ts @@ -0,0 +1,3 @@ +export const TMP_PINNED_DEPS = new Map([[ + "formsnap", "formsnap@0.1.1" +]]) \ No newline at end of file