shadcn 4.0.7 → 4.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import {b as b$1,a as a$1}from'./chunk-BRAYUB7V.js';import {o,n}from'./chunk-ISTYEIAA.js';import {b,a,G,ra,ua,c as c$1,$,V,sa,N,O,w,d,P,M,fa,ha,K as K$1,L,I,J,ta as ta$1,T,ba,H,e,ea,ka,ia,la,B as B$1,S,ma,U as U$1,W,va,_ as _$1,X as X$1,na,ga,qa,q as q$1,Z,k,R,Y as Y$1,Q,D as D$1,E,F,s,x,y,A as A$1,C,z as z$1,r,t,v,u}from'./chunk-2QWB2ZQC.js';export{ka as fetchTree,la as getItemTargetPath,pa as getPreset,oa as getPresets,ma as getRegistries,da as getRegistriesConfig,na as getRegistriesIndex,aa as getRegistry,ia as getRegistryBaseColor,ha as getRegistryBaseColors,ga as getRegistryIcons,ba as getRegistryItems,fa as getRegistryStyles,ea as getShadcnRegistryIndex,ca as resolveRegistryItems,ja as resolveTree}from'./chunk-2QWB2ZQC.js';import {c,o as o$1,n as n$1}from'./chunk-HW2MEAJZ.js';import {e as e$1,a as a$3,c as c$2,f,d as d$1}from'./chunk-JPE2JKEP.js';import {a as a$2}from'./chunk-CHWMSXYA.js';import*as te from'path';import te__default,{join}from'path';import {promises,existsSync}from'fs';import Qt from'fast-glob';import A from'fs-extra';import So from'open';import pe from'prompts';import cn from'dedent';import Io,{tmpdir}from'os';import {execa}from'execa';import k$1 from'postcss';import Oo from'postcss/lib/at-rule';import qt,{z}from'zod';import {twMerge}from'tailwind-merge';import {Project,ScriptKind,SyntaxKind,VariableDeclarationKind}from'ts-morph';import an from'deepmerge';import {Command}from'commander';import {diffLines,structuredPatch,diffWords}from'diff';import {dim,yellow,bold,green,cyan,red}from'kleur/colors';import*as ve from'fs/promises';import ve__default from'fs/promises';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {randomBytes}from'crypto';var bo=["next.config.*","vite.config.*","astro.config.*","remix.config.*","nuxt.config.*","svelte.config.*","gatsby-config.*","angular.json"];async function Y(e){if(A.existsSync(te__default.resolve(e,"pnpm-workspace.yaml")))return true;let t=te__default.resolve(e,"package.json");if(A.existsSync(t))try{if((await A.readJson(t)).workspaces)return !0}catch{}return !!(A.existsSync(te__default.resolve(e,"lerna.json"))||A.existsSync(te__default.resolve(e,"nx.json")))}async function K(e){let t=await xo(e);if(!t.length)return [];let r=await Qt(t,{cwd:e,onlyDirectories:true,ignore:["**/node_modules/**"]}),n=[];for(let i of r){let o=te__default.resolve(e,i);if(!A.existsSync(te__default.resolve(o,"package.json")))continue;let s=A.existsSync(te__default.resolve(o,"components.json")),c=bo.some(a=>Qt.sync(a,{cwd:o,dot:true}).length>0);(s||c)&&n.push({name:i,hasConfig:s});}return n}function q(e,t){b.break(),b.log(`It looks like you are running ${a.info(e)} from a monorepo root.`),b.log(`To use shadcn in a specific workspace, use the ${a.info("-c")} flag:`),b.break();for(let r of t)b.log(` shadcn ${e} -c ${r.name}`);b.break();}async function xo(e){let t=[],r=te__default.resolve(e,"pnpm-workspace.yaml");if(A.existsSync(r)){let i=await A.readFile(r,"utf8"),o=Array.from(i.matchAll(/^\s*-\s*["']?([^"'\n#]+)["']?\s*$/gm));for(let s of o)t.push(s[1].trim());}let n=te__default.resolve(e,"package.json");if(A.existsSync(n))try{let i=await A.readJson(n),o=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;Array.isArray(o)&&t.push(...o.filter(s=>!s.startsWith("!")));}catch{}return Array.from(new Set(t))}async function Jr(e){let t={};if(!A.existsSync(e.cwd)||!A.existsSync(te__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,projectInfo:null};let r=w("Preflight checks.",{silent:e.silent}).start();A.existsSync(te__default.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),b.break(),b.error(`A ${a.info("components.json")} file already exists at ${a.info(e.cwd)}.
2
+ import {b as b$1,a as a$1}from'./chunk-DIKCRF5U.js';import {o,n}from'./chunk-ISTYEIAA.js';import {b,a,G,ra,ua,c as c$1,$,V,sa,N,O,w,d,P,M,fa,ha,K as K$1,L,I,J,ta as ta$1,T,ba,H,e,ea,ka,ia,la,B as B$1,S,ma,U as U$1,W,va,_ as _$1,X as X$1,na,ga,qa,q as q$1,Z,k,R,Y as Y$1,Q,D as D$1,E,F,s,x,y,A as A$1,C,z as z$1,r,t,v,u}from'./chunk-2QWB2ZQC.js';export{ka as fetchTree,la as getItemTargetPath,pa as getPreset,oa as getPresets,ma as getRegistries,da as getRegistriesConfig,na as getRegistriesIndex,aa as getRegistry,ia as getRegistryBaseColor,ha as getRegistryBaseColors,ga as getRegistryIcons,ba as getRegistryItems,fa as getRegistryStyles,ea as getShadcnRegistryIndex,ca as resolveRegistryItems,ja as resolveTree}from'./chunk-2QWB2ZQC.js';import {c,o as o$1,n as n$1}from'./chunk-HW2MEAJZ.js';import {e as e$1,a as a$3,c as c$2,f,d as d$1}from'./chunk-JPE2JKEP.js';import {a as a$2}from'./chunk-CHWMSXYA.js';import*as te from'path';import te__default,{join}from'path';import {promises,existsSync}from'fs';import Qt from'fast-glob';import A from'fs-extra';import So from'open';import pe from'prompts';import cn from'dedent';import Io,{tmpdir}from'os';import {execa}from'execa';import k$1 from'postcss';import Oo from'postcss/lib/at-rule';import qt,{z}from'zod';import {twMerge}from'tailwind-merge';import {Project,ScriptKind,SyntaxKind,VariableDeclarationKind}from'ts-morph';import an from'deepmerge';import {Command}from'commander';import {diffLines,structuredPatch,diffWords}from'diff';import {dim,yellow,bold,green,cyan,red}from'kleur/colors';import*as ve from'fs/promises';import ve__default from'fs/promises';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {randomBytes}from'crypto';var bo=["next.config.*","vite.config.*","astro.config.*","remix.config.*","nuxt.config.*","svelte.config.*","gatsby-config.*","angular.json"];async function Y(e){if(A.existsSync(te__default.resolve(e,"pnpm-workspace.yaml")))return true;let t=te__default.resolve(e,"package.json");if(A.existsSync(t))try{if((await A.readJson(t)).workspaces)return !0}catch{}return !!(A.existsSync(te__default.resolve(e,"lerna.json"))||A.existsSync(te__default.resolve(e,"nx.json")))}async function K(e){let t=await xo(e);if(!t.length)return [];let r=await Qt(t,{cwd:e,onlyDirectories:true,ignore:["**/node_modules/**"]}),n=[];for(let i of r){let o=te__default.resolve(e,i);if(!A.existsSync(te__default.resolve(o,"package.json")))continue;let s=A.existsSync(te__default.resolve(o,"components.json")),c=bo.some(a=>Qt.sync(a,{cwd:o,dot:true}).length>0);(s||c)&&n.push({name:i,hasConfig:s});}return n}function q(e,t){b.break(),b.log(`It looks like you are running ${a.info(e)} from a monorepo root.`),b.log(`To use shadcn in a specific workspace, use the ${a.info("-c")} flag:`),b.break();for(let r of t)b.log(` shadcn ${e} -c ${r.name}`);b.break();}async function xo(e){let t=[],r=te__default.resolve(e,"pnpm-workspace.yaml");if(A.existsSync(r)){let i=await A.readFile(r,"utf8"),o=Array.from(i.matchAll(/^\s*-\s*["']?([^"'\n#]+)["']?\s*$/gm));for(let s of o)t.push(s[1].trim());}let n=te__default.resolve(e,"package.json");if(A.existsSync(n))try{let i=await A.readJson(n),o=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;Array.isArray(o)&&t.push(...o.filter(s=>!s.startsWith("!")));}catch{}return Array.from(new Set(t))}async function Jr(e){let t={};if(!A.existsSync(e.cwd)||!A.existsSync(te__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,projectInfo:null};let r=w("Preflight checks.",{silent:e.silent}).start();A.existsSync(te__default.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),b.break(),b.error(`A ${a.info("components.json")} file already exists at ${a.info(e.cwd)}.
3
3
  To start over, remove the ${a.info("components.json")} file and run ${a.info("init")} again.`),b.break(),process.exit(1)),r?.succeed();let n=w("Verifying framework.",{silent:e.silent}).start(),i=e.existingConfig?.tailwind,o=await ra(e.cwd,{configCssFile:typeof i?.css=="string"?i.css:void 0});if(!o||o?.framework.name==="manual"){if(t["7"]=true,n?.fail(),!e.monorepo&&await Y(e.cwd)){let f=await K(e.cwd);f.length>0&&(q("init",f),process.exit(1));}b.break(),o?.framework.links.installation&&b.error(`We could not detect a supported framework at ${a.info(e.cwd)}.
4
4
  Visit ${a.info(o?.framework.links.installation)} to manually configure your project.
5
5
  Once configured, you can use the cli to add components.`),b.break(),process.exit(1);}n?.succeed(`Verifying framework. Found ${a.info(o.framework.label)}.`);let s="Validating Tailwind CSS.";o.tailwindVersion==="v4"&&(s=`Validating Tailwind CSS. Found ${a.info("v4")}.`);let c=w(s,{silent:e.silent}).start();o.tailwindVersion==="v3"&&(!o?.tailwindConfigFile||!o?.tailwindCssFile)?(t["5"]=true,c?.fail()):o.tailwindVersion==="v4"&&!o?.tailwindCssFile?(t["5"]=true,c?.fail()):o.tailwindVersion?c?.succeed():(t["5"]=true,c?.fail());let a$1=w("Validating import alias.",{silent:e.silent}).start();return o?.aliasPrefix?a$1?.succeed():(t["6"]=true,a$1?.fail()),Object.keys(t).length>0&&(t["5"]&&(b.break(),b.error(`No Tailwind CSS configuration found at ${a.info(e.cwd)}.`),b.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),b.error("Install Tailwind CSS then try again."),o?.framework.links.tailwind&&b.error(`Visit ${a.info(o?.framework.links.tailwind)} to get started.`)),t["6"]&&(b.break(),b.error("No import alias found in your tsconfig.json file."),o?.framework.links.installation&&b.error(`Visit ${a.info(o?.framework.links.installation)} to learn how to set an import alias.`)),b.break(),process.exit(1)),{errors:t,projectInfo:o}}async function Gr(e,t){let r=new Set,n=new Set,i=[...e];for(;i.length>0;){let o=i.shift();if(n.has(o))continue;n.add(o);let{registry:s}=q$1(o);s&&!d[s]&&r.add(s);try{let[c]=await Z([o],t,{useCache:!0});if(c?.registryDependencies)for(let a of c.registryDependencies){let{registry:f}=q$1(a);f&&!d[f]&&r.add(f),n.has(a)||i.push(a);}}catch(c){if(c instanceof k){let{registry:a}=q$1(o);a&&!d[a]&&r.add(a);continue}continue}}return Array.from(r)}async function _(e,t,r={}){r={silent:false,writeFile:true,...r};let i=(await Gr(e,t)).filter(f=>!t.registries?.[f]&&!Object.keys(d).includes(f));if(i.length===0)return {config:t,newRegistries:[]};let o=await na({useCache:process.env.NODE_ENV!=="development"});if(!o)return {config:t,newRegistries:[]};let s={};for(let f of i)o[f]&&(s[f]=o[f]);if(Object.keys(s).length===0)return {config:t,newRegistries:[]};let c$1=Object.fromEntries(Object.entries(t.registries||{}).filter(([f])=>!Object.keys(d).includes(f))),a={...t,registries:{...c$1,...s}};if(r.writeFile){let{resolvedPaths:f,...l}=a,m=w("Updating components.json.",{silent:r.silent}).start(),d=c.parse(l);await A.writeFile(te__default.resolve(t.resolvedPaths.cwd,"components.json"),JSON.stringify(d,null,2)+`
@@ -159,4 +159,4 @@ args = ["shadcn@${Ce}", "mcp"]`),b.break(),b.info("3. Restart Codex to load the
159
159
  `).map(x=>{if(x.trim().startsWith("import "))return x;let v=x;return v=v.replace(/\b(asChild\s*\?\s*)Slot(\s*:)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bReact\.ComponentProps<typeof\s+Slot>/g,"React.ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/\bComponentProps<typeof\s+Slot>/g,"ComponentProps<typeof __SLOT_PLACEHOLDER__>"),v=v.replace(/(<\/?)Slot(\s*\/?>)/g,"$1__SLOT_PLACEHOLDER__$2"),v=v.replace(/\bSlot\b/g,(P,C,R)=>{let $=R.substring(0,C),M=($.match(/"/g)||[]).length,Z=($.match(/'/g)||[]).length;return M%2!==0||Z%2!==0?P:"__SLOT_PLACEHOLDER__"}),v=v.replace(/__SLOT_PLACEHOLDER__/g,"SlotPrimitive.Slot"),v}).join(`
160
160
  `));let h=Array.from(new Set(i));return {content:c,replacedPackages:h}}var Ws=["sidebar.tsx","pagination.tsx","calendar.tsx"],Ms=`${c$1}/docs/rtl#manual-migration-optional`;async function ro(e,t={}){let r,n;if(t.path){if(n=e.resolvedPaths.cwd,t.path.includes("*"))r=await Qt(t.path,{cwd:n,onlyFiles:true,ignore:["**/node_modules/**"]});else {let f=te__default.resolve(n,t.path),l=await promises.stat(f).catch(()=>null);if(!l)throw new Error(`File not found: ${t.path}`);if(l.isDirectory())n=f,r=await Qt("**/*.{js,ts,jsx,tsx}",{cwd:n,onlyFiles:true,ignore:["**/node_modules/**"]});else if(l.isFile())r=[t.path];else throw new Error(`Unsupported path type: ${t.path}`)}if(r.length===0)throw new Error(`No files found matching: ${t.path}`)}else {if(!e.resolvedPaths.ui)throw new Error("Could not find a valid `ui` path in your `components.json`. Please provide a path or glob pattern.");n=e.resolvedPaths.ui,r=await Qt("**/*.{js,ts,jsx,tsx}",{cwd:n,onlyFiles:true});}if(!t.yes){let a$1=t.path?t.path:`./${te__default.relative(e.resolvedPaths.cwd,n)}`,{confirm:f}=await pe({type:"confirm",name:"confirm",initial:true,message:`We will migrate ${a.info(r.length)} file(s) in ${a.info(a$1)} to RTL. Continue?`});f||(b.info("Migration cancelled."),process.exit(0));}let i=w("Updating components.json...").start();try{let a=te__default.resolve(e.resolvedPaths.cwd,"components.json"),f=JSON.parse(await promises.readFile(a,"utf-8"));f.rtl=!0,await promises.writeFile(a,JSON.stringify(f,null,2)+`
161
161
  `),i.succeed("Updated components.json.");}catch{throw i.fail("Failed to update components.json."),new Error("Could not update components.json. Please manually set `rtl: true`.")}let o=w("Migrating files to RTL...").start(),s=0,c=[];if(await Promise.all(r.map(async a=>{o.text=`Migrating ${a}...`;let f=te__default.join(n,a),l=await promises.readFile(f,"utf-8"),m=await e$1(l,true);m!==l&&(await promises.writeFile(f,m),s++);let d=te__default.basename(a);Ws.includes(d)&&c.push(a);})),o.succeed(`Migration complete. ${s} file(s) transformed.`),c.length>0){b.break(),b.warn("The following components may need manual RTL adjustments:");for(let a of c)b.info(` - ${a}`);b.break(),b.info(`See ${a.info(Ms)} for more information.`);}}async function oo(e){let t={};if(!A.existsSync(e.cwd)||!A.existsSync(te__default.resolve(e.cwd,"package.json")))return t["1"]=true,{errors:t,config:null};if(!A.existsSync(te__default.resolve(e.cwd,"components.json")))return t["3"]=true,{errors:t,config:null};try{let r=await N(e.cwd);return {errors:t,config:r}}catch{b.break(),b.error(`An invalid ${a.info("components.json")} file was found at ${a.info(e.cwd)}.
162
- Before you can run a migration, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),b.error(`Learn more at ${a.info(`${c$1}/docs/components-json`)}.`),b.break(),process.exit(1);}}var io=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."},{name:"rtl",description:"migrate your components to support RTL (right-to-left)."}],zs=z.object({cwd:z.string(),list:z.boolean(),yes:z.boolean(),migration:z.string().refine(e=>e&&io.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional(),path:z.string().optional()}),so=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").argument("[path]","optional path or glob pattern to migrate.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",false).option("-y, --yes","skip confirmation prompt.",false).action(async(e,t,r)=>{try{let n=zs.parse({cwd:te__default.resolve(r.cwd),migration:e,path:t,list:r.list,yes:r.yes});if(n.list||!n.migration){b.info("Available migrations:");for(let s of io)b.info(`- ${s.name}: ${s.description}`);return}if(!n.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:o}=await oo(n);if(i["1"]||i["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!o)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");n.migration==="icons"&&await eo(o),n.migration==="radix"&&await to(o,{yes:n.yes,path:n.path}),n.migration==="rtl"&&await ro(o,{yes:n.yes,path:n.path});}catch(n){b.break(),$(n);}});var Hs=z.object({cwd:z.string(),silent:z.boolean()}),co=new Command().name("add").description("add registries to your project").argument("[registries...]","registries (@namespace) or registry URLs (@namespace=url)").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",false).action(async(e,t)=>{try{let r=Hs.parse({cwd:te__default.resolve(t.cwd),silent:t.silent}),n=e.length>0?e:await qs({silent:r.silent});await Ks(n,r.cwd,{silent:r.silent});}catch(r){b.break(),$(r);}});function Ys(e){let[t,...r]=e.split("="),n=r.length>0?r.join("="):void 0;if(!t.startsWith("@"))throw new Error(`Invalid registry namespace: ${a.info(t)}. Registry names must start with @ (e.g., @acme).`);return {namespace:t,url:n}}function or(e,t,r){return `${e} ${e===1?t:r}`}async function Ks(e,t,r){let n=te__default.resolve(t,"components.json");if(!A.existsSync(n))throw new Error(`No ${a.info("components.json")} found. Run ${a.info("shadcn init")} first.`);let i=e.map(Ys),o=i.filter(g=>!g.url),s=[];if(o.length>0){let g=w("Fetching registries.",{silent:r.silent}).start(),w$1=await ma();if(!w$1)throw g.fail(),new Error("Failed to fetch registries.");g.succeed(),s=w$1;}let c={};for(let{namespace:g,url:w}of i){if(g in d){b.warn(`${a.info(g)} is a built-in registry and cannot be added.`);continue}if(w){if(!w.includes("{name}"))throw new Error(`Invalid registry URL for ${a.info(g)}. URL must include {name} placeholder. Example: ${a.info(`${g}=https://example.com/r/{name}.json`)}`);c[g]=w;}else {let x=s.find(v=>v.name===g);if(!x)throw new Error(`Registry ${a.info(g)} not found. Provide a URL: ${a.info(`${g}=https://.../{name}.json`)}`);c[g]=x.url;}}if(Object.keys(c).length===0)return {addedRegistries:[]};let a$1=await A.readJson(n),f=a$1.registries||{},l={},m=[];for(let[g,w]of Object.entries(c))f[g]?m.push(g):l[g]=w;if(Object.keys(l).length===0){if(m.length>0&&!r.silent){w(`Skipped ${or(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let g of m)b.log(` - ${g}`);}else r.silent||b.info("No new registries to add.");return}let d$1={...a$1,registries:{...f,...l}},h=w("Updating components.json.",{silent:r.silent}).start();if(await A.writeJson(n,d$1,{spaces:2}),h.succeed(),!r.silent){let g=Object.keys(l);w(`Added ${or(g.length,"registry","registries")}:`,{silent:r.silent})?.succeed();for(let w of g)b.log(` - ${w}`);if(m.length>0){w(`Skipped ${or(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let w of m)b.log(` - ${w}`);}}}async function qs(e){let t=w("Fetching registries.",{silent:e.silent}).start(),r=await ma();if(!r)throw t.fail(),new Error("Failed to fetch registries.");t.succeed();let n=[...r].sort((o,s)=>o.name.localeCompare(s.name)),{selected:i}=await pe({type:"autocompleteMultiselect",name:"selected",message:"Which registries would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:n.map(o=>({title:o.name,description:o.description,value:o.name}))});return i?.length||(b.warn("No registries selected. Exiting."),b.info(""),process.exit(1)),i}var lo=new Command().name("registry").description("manage registries").addCommand(co);var Qs=z.object({cwd:z.string(),query:z.string().optional(),limit:z.number().optional(),offset:z.number().optional()}),mo=new Command().name("search").alias("list").description("search items from registries").argument("<registries...>","the registry names or urls to search items from. Names must be prefixed with @.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-q, --query <query>","query string").option("-l, --limit <number>","maximum number of items to display per registry","100").option("-o, --offset <number>","number of items to skip","0").action(async(e,t)=>{try{let r=Qs.parse({cwd:te__default.resolve(t.cwd),query:t.query,limit:t.limit?parseInt(t.limit,10):void 0,offset:t.offset?parseInt(t.offset,10):void 0});await X(r.cwd);let n=T({style:"new-york",resolvedPaths:{cwd:r.cwd}}),i=U$1(n),o=te__default.resolve(r.cwd,"components.json");if(A.existsSync(o)){let l=await A.readJson(o),m=c.partial().parse(l);i=U$1({...n,...m});}let s=i;try{let l=await N(r.cwd);l&&(s=U$1(l));}catch{}let{config:c$1,newRegistries:a}=await _(e.map(l=>`${l}/registry`),s,{silent:!0,writeFile:!1});a.length>0&&(s.registries=c$1.registries),W(e,s);let f=await va(e,{query:r.query,limit:r.limit,offset:r.offset,config:s});console.log(JSON.stringify(f,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var ta=z.object({cwd:z.string()}),yo=new Command().name("view").description("view items from the registry").argument("<items...>","the item names or URLs to view").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=ta.parse({cwd:te__default.resolve(t.cwd)});await X(r.cwd);let n=U$1({}),i=te__default.resolve(r.cwd,"components.json");if(A.existsSync(i)){let f=await A.readJson(i),l=c.partial().parse(f);n=U$1(l);}let o=n;try{let f=await N(r.cwd);f&&(o=U$1(f));}catch{}let{config:s,newRegistries:c$1}=await _(e,o,{silent:!0,writeFile:!1});c$1.length>0&&(o.registries=s.registries),W(e,o);let a=await ba(e,{config:o});console.log(JSON.stringify(a,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var wo={version:"4.0.7"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function oa(){let e=new Command().name("shadcn").description("build your component library").version(wo.version,"-v, --version","display the version number");e.addCommand(Sn).addCommand(_n).addCommand(Jn).addCommand(Gn).addCommand(yo).addCommand(mo).addCommand(so).addCommand(Kn).addCommand(Bn).addCommand(Xt).addCommand(lo),e.parse();}oa();
162
+ Before you can run a migration, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),b.error(`Learn more at ${a.info(`${c$1}/docs/components-json`)}.`),b.break(),process.exit(1);}}var io=[{name:"icons",description:"migrate your ui components to a different icon library."},{name:"radix",description:"migrate to radix-ui."},{name:"rtl",description:"migrate your components to support RTL (right-to-left)."}],zs=z.object({cwd:z.string(),list:z.boolean(),yes:z.boolean(),migration:z.string().refine(e=>e&&io.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional(),path:z.string().optional()}),so=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").argument("[path]","optional path or glob pattern to migrate.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",false).option("-y, --yes","skip confirmation prompt.",false).action(async(e,t,r)=>{try{let n=zs.parse({cwd:te__default.resolve(r.cwd),migration:e,path:t,list:r.list,yes:r.yes});if(n.list||!n.migration){b.info("Available migrations:");for(let s of io)b.info(`- ${s.name}: ${s.description}`);return}if(!n.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:o}=await oo(n);if(i["1"]||i["3"])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!o)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");n.migration==="icons"&&await eo(o),n.migration==="radix"&&await to(o,{yes:n.yes,path:n.path}),n.migration==="rtl"&&await ro(o,{yes:n.yes,path:n.path});}catch(n){b.break(),$(n);}});var Hs=z.object({cwd:z.string(),silent:z.boolean()}),co=new Command().name("add").description("add registries to your project").argument("[registries...]","registries (@namespace) or registry URLs (@namespace=url)").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",false).action(async(e,t)=>{try{let r=Hs.parse({cwd:te__default.resolve(t.cwd),silent:t.silent}),n=e.length>0?e:await qs({silent:r.silent});await Ks(n,r.cwd,{silent:r.silent});}catch(r){b.break(),$(r);}});function Ys(e){let[t,...r]=e.split("="),n=r.length>0?r.join("="):void 0;if(!t.startsWith("@"))throw new Error(`Invalid registry namespace: ${a.info(t)}. Registry names must start with @ (e.g., @acme).`);return {namespace:t,url:n}}function or(e,t,r){return `${e} ${e===1?t:r}`}async function Ks(e,t,r){let n=te__default.resolve(t,"components.json");if(!A.existsSync(n))throw new Error(`No ${a.info("components.json")} found. Run ${a.info("shadcn init")} first.`);let i=e.map(Ys),o=i.filter(g=>!g.url),s=[];if(o.length>0){let g=w("Fetching registries.",{silent:r.silent}).start(),w$1=await ma();if(!w$1)throw g.fail(),new Error("Failed to fetch registries.");g.succeed(),s=w$1;}let c={};for(let{namespace:g,url:w}of i){if(g in d){b.warn(`${a.info(g)} is a built-in registry and cannot be added.`);continue}if(w){if(!w.includes("{name}"))throw new Error(`Invalid registry URL for ${a.info(g)}. URL must include {name} placeholder. Example: ${a.info(`${g}=https://example.com/r/{name}.json`)}`);c[g]=w;}else {let x=s.find(v=>v.name===g);if(!x)throw new Error(`Registry ${a.info(g)} not found. Provide a URL: ${a.info(`${g}=https://.../{name}.json`)}`);c[g]=x.url;}}if(Object.keys(c).length===0)return {addedRegistries:[]};let a$1=await A.readJson(n),f=a$1.registries||{},l={},m=[];for(let[g,w]of Object.entries(c))f[g]?m.push(g):l[g]=w;if(Object.keys(l).length===0){if(m.length>0&&!r.silent){w(`Skipped ${or(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let g of m)b.log(` - ${g}`);}else r.silent||b.info("No new registries to add.");return}let d$1={...a$1,registries:{...f,...l}},h=w("Updating components.json.",{silent:r.silent}).start();if(await A.writeJson(n,d$1,{spaces:2}),h.succeed(),!r.silent){let g=Object.keys(l);w(`Added ${or(g.length,"registry","registries")}:`,{silent:r.silent})?.succeed();for(let w of g)b.log(` - ${w}`);if(m.length>0){w(`Skipped ${or(m.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let w of m)b.log(` - ${w}`);}}}async function qs(e){let t=w("Fetching registries.",{silent:e.silent}).start(),r=await ma();if(!r)throw t.fail(),new Error("Failed to fetch registries.");t.succeed();let n=[...r].sort((o,s)=>o.name.localeCompare(s.name)),{selected:i}=await pe({type:"autocompleteMultiselect",name:"selected",message:"Which registries would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:false,choices:n.map(o=>({title:o.name,description:o.description,value:o.name}))});return i?.length||(b.warn("No registries selected. Exiting."),b.info(""),process.exit(1)),i}var lo=new Command().name("registry").description("manage registries").addCommand(co);var Qs=z.object({cwd:z.string(),query:z.string().optional(),limit:z.number().optional(),offset:z.number().optional()}),mo=new Command().name("search").alias("list").description("search items from registries").argument("<registries...>","the registry names or urls to search items from. Names must be prefixed with @.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-q, --query <query>","query string").option("-l, --limit <number>","maximum number of items to display per registry","100").option("-o, --offset <number>","number of items to skip","0").action(async(e,t)=>{try{let r=Qs.parse({cwd:te__default.resolve(t.cwd),query:t.query,limit:t.limit?parseInt(t.limit,10):void 0,offset:t.offset?parseInt(t.offset,10):void 0});await X(r.cwd);let n=T({style:"new-york",resolvedPaths:{cwd:r.cwd}}),i=U$1(n),o=te__default.resolve(r.cwd,"components.json");if(A.existsSync(o)){let l=await A.readJson(o),m=c.partial().parse(l);i=U$1({...n,...m});}let s=i;try{let l=await N(r.cwd);l&&(s=U$1(l));}catch{}let{config:c$1,newRegistries:a}=await _(e.map(l=>`${l}/registry`),s,{silent:!0,writeFile:!1});a.length>0&&(s.registries=c$1.registries),W(e,s);let f=await va(e,{query:r.query,limit:r.limit,offset:r.offset,config:s});console.log(JSON.stringify(f,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var ta=z.object({cwd:z.string()}),yo=new Command().name("view").description("view items from the registry").argument("<items...>","the item names or URLs to view").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=ta.parse({cwd:te__default.resolve(t.cwd)});await X(r.cwd);let n=U$1({}),i=te__default.resolve(r.cwd,"components.json");if(A.existsSync(i)){let f=await A.readJson(i),l=c.partial().parse(f);n=U$1(l);}let o=n;try{let f=await N(r.cwd);f&&(o=U$1(f));}catch{}let{config:s,newRegistries:c$1}=await _(e,o,{silent:!0,writeFile:!1});c$1.length>0&&(o.registries=s.registries),W(e,o);let a=await ba(e,{config:o});console.log(JSON.stringify(a,null,2)),process.exit(0);}catch(r){$(r);}finally{V();}});var wo={version:"4.0.8"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function oa(){let e=new Command().name("shadcn").description("build your component library").version(wo.version,"-v, --version","display the version number");e.addCommand(Sn).addCommand(_n).addCommand(Jn).addCommand(Gn).addCommand(yo).addCommand(mo).addCommand(so).addCommand(Kn).addCommand(Bn).addCommand(Xt).addCommand(lo),e.parse();}oa();
package/dist/mcp/index.js CHANGED
@@ -1 +1 @@
1
- export{b as server}from'../chunk-BRAYUB7V.js';import'../chunk-2QWB2ZQC.js';import'../chunk-HW2MEAJZ.js';import'../chunk-JPE2JKEP.js';import'../chunk-CHWMSXYA.js';
1
+ export{b as server}from'../chunk-DIKCRF5U.js';import'../chunk-2QWB2ZQC.js';import'../chunk-HW2MEAJZ.js';import'../chunk-JPE2JKEP.js';import'../chunk-CHWMSXYA.js';
@@ -11,17 +11,17 @@ declare function searchRegistries(registries: string[], options?: {
11
11
  useCache?: boolean;
12
12
  }): Promise<{
13
13
  items: {
14
- registry: string;
15
14
  name: string;
15
+ registry: string;
16
16
  addCommandArgument: string;
17
- type?: string | undefined;
18
17
  description?: string | undefined;
18
+ type?: string | undefined;
19
19
  }[];
20
20
  pagination: {
21
21
  total: number;
22
- offset: number;
23
- limit: number;
24
22
  hasMore: boolean;
23
+ limit: number;
24
+ offset: number;
25
25
  };
26
26
  }>;
27
27