Skip to content

Commit

Permalink
registry: pin deps
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Dec 13, 2024
1 parent 5cd7061 commit 1a6953e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions sites/docs/scripts/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]>([
Expand Down Expand Up @@ -48,6 +49,14 @@ export async function buildRegistry() {
return registry;
}

function getDepsWithPinned(deps: Set<string>) {
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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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),
});
}

Expand All @@ -147,8 +156,8 @@ async function getDependencies(filename: string, source: string) {
const registryDependencies = new Set<string>();
const dependencies = new Set<string>();

// @ts-expect-error annoying
walk(ast.instance, {
// @ts-expect-error annoying
enter(node) {
if (node.type === "ImportDeclaration") {
const source = node.source.value as string;
Expand Down
3 changes: 3 additions & 0 deletions sites/docs/scripts/tmp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const TMP_PINNED_DEPS = new Map<string, string>([[
"formsnap", "[email protected]"
]])

0 comments on commit 1a6953e

Please sign in to comment.