shadcn-svelte

Output your registry as a shadcn-svelte registry.

The @jsrepo/shadcn-svelte package helps you distribute your jsrepo registry as a shadcn-svelte registry.

Usage

To get started install the package:

npm install @jsrepo/shadcn-svelte -D

Next let's add the output to our config file:

jsrepo.config.ts
import { defineConfig } from "jsrepo";
import { output } from "@jsrepo/shadcn-svelte/output";

export default defineConfig({
	registry: {
        // ...
		outputs: [
			output({ 
				dir: "./public/r/shadcn-svelte",
				// while jsrepo doesn't need you to define aliases to resolve your imports shadcn-svelte does
				// because of this you will need to define them here so the shadcn-svelte cli can use them
				aliases: {
					"lib": "$lib",
					"ui": "$lib/registry/ui",
					"components": "$lib/registry/components",
					"utils": "$lib/utils",
					"hooks": "$lib/hooks",
				},
			})
		],
	},
});

Now running jsrepo build will output a shadcn-svelte registry to the ./public/r/shadcn-svelte directory. This is the same index.json and [item].json format that shadcn-svelte registry build produces, so your users can add your items with the shadcn-svelte CLI.

Unlike running shadcn-svelte registry build yourself, the output is generated from your jsrepo build so any transforms you have configured are applied to the files that your users receive.

Aliases

The shadcn-svelte CLI replaces your registry's internal import paths with the aliases from your users' project when they add an item. For this to work the aliases option needs to match the paths that you use to import code within your registry.

Any alias that you don't provide uses the same default as shadcn-svelte registry build: $lib/registry/ui, $lib/registry/components, $lib/registry/hooks, $lib/registry/lib and $lib/utils.

Targets

By default each file is installed using its path relative to the item (for example button/index.ts for a folder item) inside of the directory for the type of the file, so a ui item is installed into your user's ui alias.

If you set a target on a file it is converted to the format that shadcn-svelte expects:

  • registry:file and registry:page files require a target and it is used as is. Use ~/ to install relative to the root of the project (for example ~/.env.example).
  • For other types a target inside of the alias for the type (for example $lib/components/fancy/card.svelte with a components alias of $lib/components) is made relative to that alias (fancy/card.svelte).
  • Targets that start with ~/ are always passed through as is.
  • Any other target will throw an error since shadcn-svelte has no way to install it.

What is included

  • Files with the example, doc and test roles are not included in the output since they should not be installed in your users' projects. Items that only have those files are not output.
  • Items of type registry:base and registry:font are not supported.
  • envVars are not supported by shadcn-svelte so they are ignored.

defineShadcnSvelteRegistry

shadcn-svelte registries are defined a bit differently than jsrepo registries, generally this plugin should correctly resolve those differences or warn you if it is unable to.

If you only distribute your registry as a shadcn-svelte registry and want to define it in the shadcn-svelte shape, use defineShadcnSvelteRegistry.

jsrepo.config.ts
import { defineConfig } from "jsrepo";
import { defineShadcnSvelteRegistry, output } from "@jsrepo/shadcn-svelte";

export default defineConfig({
	registry: defineShadcnSvelteRegistry({
		// make sure you still include the output
		outputs: [
			output({ 
				dir: "./public/r/shadcn-svelte",
				aliases: {
					// ...
				},
			})
		],
	}),
});

Outputting jsrepo registries alongside shadcn-svelte registries

As with the shadcn output, the jsrepo default outputs and shadcn-svelte output are not compatible in the same directory. Serve each registry from a different URL.

The preferred way to avoid this conflict is to publish your registry to jsrepo.com.

Otherwise, postfix the shadcn-svelte registry output dir option (for example ./public/r/shadcn-svelte).

jsrepo.config.ts
import { defineConfig } from "jsrepo";
import { distributed } from "jsrepo/outputs";
import { output } from "@jsrepo/shadcn-svelte/output";

export default defineConfig({
	registry: {
		outputs: [
            distributed({ dir: "./public/r" }),
            output({ dir: "./public/r" }), 
            output({ dir: "./public/r/shadcn-svelte" }), 
        ],
	},
});

Remapping item types

If you are already using custom item types in your registry and you want to support building to shadcn-svelte you can use the typeMap option to remap the types to the correct shadcn-svelte type.

jsrepo.config.ts
import { defineConfig } from "jsrepo";
import { output } from "@jsrepo/shadcn-svelte/output";

export default defineConfig({
	registry: {
		outputs: [
			output({ 
				dir: "./public/r/shadcn-svelte", 
				typeMap: {
					"custom-type": "registry:ui"
				} 
			})
		],
	},
});