shadcn 3.8.2 → 3.8.3
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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -90,5 +90,5 @@ args = ["shadcn@${oe}", "mcp"]`),t.break(),t.info("3. Restart Codex to load the
|
|
|
90
90
|
`));let w=Array.from(new Set(n));return {content:s,replacedPackages:w}}var ao=["sidebar.tsx","pagination.tsx","calendar.tsx"],co="https://ui.shadcn.com/docs/rtl#manual-migration-optional";async function Yr(e$2,t$1={}){let r,i;if(t$1.path){if(i=e$2.resolvedPaths.cwd,t$1.path.includes("*"))r=await bt(t$1.path,{cwd:i,onlyFiles:true,ignore:["**/node_modules/**"]});else {let l=E__default.resolve(i,t$1.path),m=await promises.stat(l).catch(()=>null);if(!m)throw new Error(`File not found: ${t$1.path}`);if(m.isDirectory())i=l,r=await bt("**/*.{js,ts,jsx,tsx}",{cwd:i,onlyFiles:true,ignore:["**/node_modules/**"]});else if(m.isFile())r=[t$1.path];else throw new Error(`Unsupported path type: ${t$1.path}`)}if(r.length===0)throw new Error(`No files found matching: ${t$1.path}`)}else {if(!e$2.resolvedPaths.ui)throw new Error("Could not find a valid `ui` path in your `components.json`. Please provide a path or glob pattern.");i=e$2.resolvedPaths.ui,r=await bt("**/*.{js,ts,jsx,tsx}",{cwd:i,onlyFiles:true});}if(!t$1.yes){let c=t$1.path?t$1.path:`./${E__default.relative(e$2.resolvedPaths.cwd,i)}`,{confirm:l}=await _e({type:"confirm",name:"confirm",initial:true,message:`We will migrate ${e.info(r.length)} file(s) in ${e.info(c)} to RTL. Continue?`});l||(t.info("Migration cancelled."),process.exit(0));}let n=u("Updating components.json...").start();try{let c=E__default.resolve(e$2.resolvedPaths.cwd,"components.json"),l=JSON.parse(await promises.readFile(c,"utf-8"));l.rtl=!0,await promises.writeFile(c,JSON.stringify(l,null,2)+`
|
|
91
91
|
`),n.succeed("Updated components.json.");}catch{throw n.fail("Failed to update components.json."),new Error("Could not update components.json. Please manually set `rtl: true`.")}let o=u("Migrating files to RTL...").start(),a=0,s=[];if(await Promise.all(r.map(async c=>{o.text=`Migrating ${c}...`;let l=E__default.join(i,c),m=await promises.readFile(l,"utf-8"),d=await e$1(m,true);d!==m&&(await promises.writeFile(l,d),a++);let g=E__default.basename(c);ao.includes(g)&&s.push(c);})),o.succeed(`Migration complete. ${a} file(s) transformed.`),s.length>0){t.break(),t.warn("The following components may need manual RTL adjustments:");for(let c of s)t.info(` - ${c}`);t.break(),t.info(`See ${e.info(co)} for more information.`);}}async function qr(e$1){let t$1={};if(!R.existsSync(e$1.cwd)||!R.existsSync(E__default.resolve(e$1.cwd,"package.json")))return t$1["1"]=true,{errors:t$1,config:null};if(!R.existsSync(E__default.resolve(e$1.cwd,"components.json")))return t$1["3"]=true,{errors:t$1,config:null};try{let r=await j(e$1.cwd);return {errors:t$1,config:r}}catch{t.break(),t.error(`An invalid ${e.info("components.json")} file was found at ${e.info(e$1.cwd)}.
|
|
92
92
|
Before you can run a migration, you must create a valid ${e.info("components.json")} file by running the ${e.info("init")} command.`),t.error(`Learn more at ${e.info("https://ui.shadcn.com/docs/components-json")}.`),t.break(),process.exit(1);}}var Hr=[{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)."}],fo=z.object({cwd:z.string(),list:z.boolean(),yes:z.boolean(),migration:z.string().refine(e=>e&&Hr.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()}),Xr=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$1,r)=>{try{let i=fo.parse({cwd:E__default.resolve(r.cwd),migration:e,path:t$1,list:r.list,yes:r.yes});if(i.list||!i.migration){t.info("Available migrations:");for(let a of Hr)t.info(`- ${a.name}: ${a.description}`);return}if(!i.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:n,config:o}=await qr(i);if(n["1"]||n["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.");i.migration==="icons"&&await Gr(o),i.migration==="radix"&&await Jr(o,{yes:i.yes,path:i.path}),i.migration==="rtl"&&await Yr(o,{yes:i.yes,path:i.path});}catch(i){t.break(),Z(i);}});var go=z.object({cwd:z.string(),silent:z.boolean()}),Zr=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$1)=>{try{let r=go.parse({cwd:E__default.resolve(t$1.cwd),silent:t$1.silent}),i=e.length>0?e:await yo({silent:r.silent});await wo(i,r.cwd,{silent:r.silent});}catch(r){t.break(),Z(r);}});function ho(e$1){let[t,...r]=e$1.split("="),i=r.length>0?r.join("="):void 0;if(!t.startsWith("@"))throw new Error(`Invalid registry namespace: ${e.info(t)}. Registry names must start with @ (e.g., @acme).`);return {namespace:t,url:i}}function Ct(e,t,r){return `${e} ${e===1?t:r}`}async function wo(e$1,t$1,r){let i=E__default.resolve(t$1,"components.json");if(!R.existsSync(i))throw new Error(`No ${e.info("components.json")} found. Run ${e.info("shadcn init")} first.`);let n=e$1.map(ho),o=n.filter(u=>!u.url),a=[];if(o.length>0){let u$1=u("Fetching registries.",{silent:r.silent}).start(),h=await ka();if(!h)throw u$1.fail(),new Error("Failed to fetch registries.");u$1.succeed(),a=h;}let s={};for(let{namespace:u,url:h}of n){if(u in c$1){t.warn(`${e.info(u)} is a built-in registry and cannot be added.`);continue}if(h){if(!h.includes("{name}"))throw new Error(`Invalid registry URL for ${e.info(u)}. URL must include {name} placeholder. Example: ${e.info(`${u}=https://example.com/r/{name}.json`)}`);s[u]=h;}else {let b=a.find(v=>v.name===u);if(!b)throw new Error(`Registry ${e.info(u)} not found. Provide a URL: ${e.info(`${u}=https://.../{name}.json`)}`);s[u]=b.url;}}if(Object.keys(s).length===0)return {addedRegistries:[]};let c=await R.readJson(i),l=c.registries||{},m={},d=[];for(let[u,h]of Object.entries(s))l[u]?d.push(u):m[u]=h;if(Object.keys(m).length===0){if(d.length>0&&!r.silent){u(`Skipped ${Ct(d.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let u of d)t.log(` - ${u}`);}else r.silent||t.info("No new registries to add.");return}let g={...c,registries:{...l,...m}},w=u("Updating components.json.",{silent:r.silent}).start();if(await R.writeJson(i,g,{spaces:2}),w.succeed(),!r.silent){let u$1=Object.keys(m);u(`Added ${Ct(u$1.length,"registry","registries")}:`,{silent:r.silent})?.succeed();for(let h of u$1)t.log(` - ${h}`);if(d.length>0){u(`Skipped ${Ct(d.length,"registry","registries")}: (already configured)`,{silent:r.silent})?.info();for(let h of d)t.log(` - ${h}`);}}}async function yo(e){let t$1=u("Fetching registries.",{silent:e.silent}).start(),r=await ka();if(!r)throw t$1.fail(),new Error("Failed to fetch registries.");t$1.succeed();let i=[...r].sort((o,a)=>o.name.localeCompare(a.name)),{selected:n}=await _e({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:i.map(o=>({title:o.name,description:o.description,value:o.name}))});return n?.length||(t.warn("No registries selected. Exiting."),t.info(""),process.exit(1)),n}var ei=new Command().name("registry").description("manage registries").addCommand(Zr);async function ti(e$1){let t$1={},r={cwd:e$1.cwd,registryFile:E__default.resolve(e$1.cwd,e$1.registryFile),outputDir:E__default.resolve(e$1.cwd,e$1.outputDir)};if(!R.existsSync(r.registryFile))return t$1["13"]=true,{errors:t$1,resolvePaths:null,config:null};if(!R.existsSync(E__default.resolve(e$1.cwd,"components.json")))return t$1["3"]=true,{errors:t$1,resolvePaths:null,config:null};await R.mkdir(r.outputDir,{recursive:true});try{let i=await j(e$1.cwd);return {errors:t$1,config:i,resolvePaths:r}}catch{t.break(),t.error(`An invalid ${e.info("components.json")} file was found at ${e.info(e$1.cwd)}.
|
|
93
|
-
Before you can build the registry, you must create a valid ${e.info("components.json")} file by running the ${e.info("init")} command.`),t.break(),process.exit(1);}}var vo=z.object({cwd:z.string(),registryFile:z.string(),outputDir:z.string(),verbose:z.boolean().optional().default(false)}),ri=new Command().name("registry:build").description("builds the registry [EXPERIMENTAL]").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-v, --verbose","verbose output").action(async(e,t)=>{await So({cwd:E.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function So(e$1){try{let t$1=vo.parse(e$1),[{errors:r,resolvePaths:i,config:n$1},o]=await Promise.all([ti(t$1),q(t$1.cwd)]);(r["3"]||!n$1||!o)&&(t.error(`A ${e.info("components.json")} file is required to build the registry. Run ${e.info("shadcn init")} to create one.`),t.break(),process.exit(1)),(r["13"]||!i)&&(t.error(`We could not find a registry file at ${e.info(E.resolve(t$1.cwd,t$1.registryFile))}.`),t.break(),process.exit(1));let a=await Y.readFile(i.registryFile,"utf-8"),s=o$1.safeParse(JSON.parse(a));s.success||(t.error(`Invalid registry file found at ${e.info(i.registryFile)}.`),t.break(),process.exit(1));let c=u("Building registry..."),l=await Ro(s.data,n$1,o);for(let m of l.items)m.files=m.files?.filter((d,g,w)=>g===w.findIndex(u=>u.path===d.path)),m.dependencies&&(m.dependencies=m.dependencies.filter((d,g,w)=>g===w.findIndex(u=>u===d)));for(let m of l.items){if(!m.files)continue;c.start(`Building ${m.name}...`),m.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let g of m.files){let w=E.resolve(i.cwd,g.path);try{if(!(await Y.stat(w)).isFile())continue;g.content=await Y.readFile(w,"utf-8");}catch(u){console.error("Error reading file in registry build:",w,u);continue}}let d=n.safeParse(m);if(!d.success){t.error(`Invalid registry item found for ${e.info(m.name)}.`);continue}await Y.writeFile(E.resolve(i.outputDir,`${d.data.name}.json`),JSON.stringify(d.data,null,2));}if(await Y.copyFile(i.registryFile,E.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t$1.verbose){u(`The registry has ${e.info(l.items.length.toString())} items:`).succeed();for(let m of l.items){t.log(` - ${m.name} (${e.info(m.type)})`);for(let d of m.files??[])t.log(` - ${d.path}`);}}}catch(t$1){t.break(),Z(t$1);}}async function Ro(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await M(n.path,t,r);o.files=o.files?.filter(a=>a.path!==n.path),o.files&&i.files.push(...o.files),o.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(o.dependencies):o.dependencies);}return e}var ii=new Command().name("registry:mcp").description("starts the registry MCP server [DEPRECATED]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{t.warn(`The ${e.info("shadcn registry:mcp")} command is deprecated. Use the ${e.info("shadcn mcp")} command instead.`),t.break();});var ko=z.object({cwd:z.string(),query:z.string().optional(),limit:z.number().optional(),offset:z.number().optional()}),si=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=ko.parse({cwd:E__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 B(r.cwd);let i=o({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n=P(i),o$1=E__default.resolve(r.cwd,"components.json");if(R.existsSync(o$1)){let m=await R.readJson(o$1),d=c.partial().parse(m);n=P({...i,...d});}let a=n;try{let m=await j(r.cwd);m&&(a=P(m));}catch{}let{config:s,newRegistries:c$1}=await F(e.map(m=>`${m}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),R$1(e,a);let l=await oa(e,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(l,null,2)),process.exit(0);}catch(r){Z(r);}finally{Q();}});var jo=z.object({cwd:z.string()}),mi=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=jo.parse({cwd:E__default.resolve(t.cwd)});await B(r.cwd);let i=P({}),n=E__default.resolve(r.cwd,"components.json");if(R.existsSync(n)){let l=await R.readJson(n),m=c.partial().parse(l);i=P(m);}let o=i;try{let l=await j(r.cwd);l&&(o=P(l));}catch{}let{config:a,newRegistries:s}=await F(e,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),R$1(e,o);let c$1=await $(e,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){Z(r);}finally{Q();}});var fi={version:"3.8.
|
|
93
|
+
Before you can build the registry, you must create a valid ${e.info("components.json")} file by running the ${e.info("init")} command.`),t.break(),process.exit(1);}}var vo=z.object({cwd:z.string(),registryFile:z.string(),outputDir:z.string(),verbose:z.boolean().optional().default(false)}),ri=new Command().name("registry:build").description("builds the registry [EXPERIMENTAL]").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-v, --verbose","verbose output").action(async(e,t)=>{await So({cwd:E.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function So(e$1){try{let t$1=vo.parse(e$1),[{errors:r,resolvePaths:i,config:n$1},o]=await Promise.all([ti(t$1),q(t$1.cwd)]);(r["3"]||!n$1||!o)&&(t.error(`A ${e.info("components.json")} file is required to build the registry. Run ${e.info("shadcn init")} to create one.`),t.break(),process.exit(1)),(r["13"]||!i)&&(t.error(`We could not find a registry file at ${e.info(E.resolve(t$1.cwd,t$1.registryFile))}.`),t.break(),process.exit(1));let a=await Y.readFile(i.registryFile,"utf-8"),s=o$1.safeParse(JSON.parse(a));s.success||(t.error(`Invalid registry file found at ${e.info(i.registryFile)}.`),t.break(),process.exit(1));let c=u("Building registry..."),l=await Ro(s.data,n$1,o);for(let m of l.items)m.files=m.files?.filter((d,g,w)=>g===w.findIndex(u=>u.path===d.path)),m.dependencies&&(m.dependencies=m.dependencies.filter((d,g,w)=>g===w.findIndex(u=>u===d)));for(let m of l.items){if(!m.files)continue;c.start(`Building ${m.name}...`),m.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let g of m.files){let w=E.resolve(i.cwd,g.path);try{if(!(await Y.stat(w)).isFile())continue;g.content=await Y.readFile(w,"utf-8");}catch(u){console.error("Error reading file in registry build:",w,u);continue}}let d=n.safeParse(m);if(!d.success){t.error(`Invalid registry item found for ${e.info(m.name)}.`);continue}await Y.writeFile(E.resolve(i.outputDir,`${d.data.name}.json`),JSON.stringify(d.data,null,2));}if(await Y.copyFile(i.registryFile,E.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t$1.verbose){u(`The registry has ${e.info(l.items.length.toString())} items:`).succeed();for(let m of l.items){t.log(` - ${m.name} (${e.info(m.type)})`);for(let d of m.files??[])t.log(` - ${d.path}`);}}}catch(t$1){t.break(),Z(t$1);}}async function Ro(e,t,r){for(let i of e.items)if(i.files?.length)for(let n of i.files){let o=await M(n.path,t,r);o.files=o.files?.filter(a=>a.path!==n.path),o.files&&i.files.push(...o.files),o.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(o.dependencies):o.dependencies);}return e}var ii=new Command().name("registry:mcp").description("starts the registry MCP server [DEPRECATED]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{t.warn(`The ${e.info("shadcn registry:mcp")} command is deprecated. Use the ${e.info("shadcn mcp")} command instead.`),t.break();});var ko=z.object({cwd:z.string(),query:z.string().optional(),limit:z.number().optional(),offset:z.number().optional()}),si=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=ko.parse({cwd:E__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 B(r.cwd);let i=o({style:"new-york",resolvedPaths:{cwd:r.cwd}}),n=P(i),o$1=E__default.resolve(r.cwd,"components.json");if(R.existsSync(o$1)){let m=await R.readJson(o$1),d=c.partial().parse(m);n=P({...i,...d});}let a=n;try{let m=await j(r.cwd);m&&(a=P(m));}catch{}let{config:s,newRegistries:c$1}=await F(e.map(m=>`${m}/registry`),a,{silent:!0,writeFile:!1});c$1.length>0&&(a.registries=s.registries),R$1(e,a);let l=await oa(e,{query:r.query,limit:r.limit,offset:r.offset,config:a});console.log(JSON.stringify(l,null,2)),process.exit(0);}catch(r){Z(r);}finally{Q();}});var jo=z.object({cwd:z.string()}),mi=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=jo.parse({cwd:E__default.resolve(t.cwd)});await B(r.cwd);let i=P({}),n=E__default.resolve(r.cwd,"components.json");if(R.existsSync(n)){let l=await R.readJson(n),m=c.partial().parse(l);i=P(m);}let o=i;try{let l=await j(r.cwd);l&&(o=P(l));}catch{}let{config:a,newRegistries:s}=await F(e,o,{silent:!0,writeFile:!1});s.length>0&&(o.registries=a.registries),R$1(e,o);let c$1=await $(e,{config:o});console.log(JSON.stringify(c$1,null,2)),process.exit(0);}catch(r){Z(r);}finally{Q();}});var fi={version:"3.8.3"};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function No(){let e=new Command().name("shadcn").description("add items from registries to your project").version(fi.version,"-v, --version","display the version number");e.addCommand(Rr).addCommand(_r).addCommand(Er).addCommand(Vr).addCommand(mi).addCommand(si).addCommand(Xr).addCommand(Mr).addCommand(Fr).addCommand(wt).addCommand(ei),e.addCommand(ri).addCommand(ii),e.parse();}No();//# sourceMappingURL=index.js.map
|
|
94
94
|
//# sourceMappingURL=index.js.map
|