shadcn 2.6.0 → 2.6.1

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
@@ -62,7 +62,7 @@ Once configured, you can use the cli to add components.`),q$1.break(),process.ex
62
62
  `}});r.append(c);}}}}function Ar(e){return e.nodes[0].toString().includes("'")?"single":"double"}function At(e){if(e.startsWith("hsl")||e.startsWith("rgb")||e.startsWith("#")||e.startsWith("oklch"))return !1;let t=e.split(" ");return t.length===3&&t.slice(1,3).every(r=>r.includes("%"))}function _r(e){return e.startsWith("hsl")||e.startsWith("rgb")||e.startsWith("#")||e.startsWith("oklch")}async function be(e,{withFallback:t}={withFallback:!1}){let r=await detect({programmatic:!0,cwd:e});if(r==="yarn@berry")return "yarn";if(r==="pnpm@6")return "pnpm";if(r==="bun")return "bun";if(r==="deno")return "deno";if(!t)return r??"npm";let i=process.env.npm_config_user_agent||"";return i.startsWith("yarn")?"yarn":i.startsWith("pnpm")?"pnpm":i.startsWith("bun")?"bun":"npm"}async function ne(e,t,r$1,i){if(e=Array.from(new Set(e)),t=Array.from(new Set(t)),!e?.length&&!t?.length)return;i={silent:!1,...i};let o=r("Installing dependencies.",{silent:i.silent})?.start(),n=await be(r$1.resolvedPaths.cwd),s="";if(Mr(r$1)&&n==="npm")if(i.silent)s="force";else {o.stopAndPersist(),q$1.warn(`
63
63
  It looks like you are using React 19.
64
64
  Some packages may fail to install due to peer dependency issues in npm (see https://ui.shadcn.com/react-19).
65
- `);let a=await Qe([{type:"select",name:"flag",message:"How would you like to proceed?",choices:[{title:"Use --force",value:"force"},{title:"Use --legacy-peer-deps",value:"legacy-peer-deps"}]}]);a&&(s=a.flag);}o?.start(),e?.length&&await execa(n,[n==="npm"?"install":"add",...n==="npm"&&s?[`--${s}`]:[],...n==="deno"?e.map(a=>`npm:${a}`):e],{cwd:r$1.resolvedPaths.cwd}),t?.length&&await execa(n,[n==="npm"?"install":"add",...n==="npm"&&s?[`--${s}`]:[],"-D",...n==="deno"?t.map(a=>`npm:${a}`):t],{cwd:r$1.resolvedPaths.cwd}),o?.succeed();}function Mr(e){let t=m(e.resolvedPaths.cwd,!1);return t?.dependencies?.react?/^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(t.dependencies.react):!1}var Se=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(i=>{let o=i.getText();if(o){let n=Br(o.replace(/"/g,""),r.inlineColors);i.replaceWithText(`"${n.trim()}"`);}}),e);function Ye(e){if(!e.includes("/")&&!e.includes(":"))return [null,e,null];let t=[],[r,i]=e.split("/");if(!r.includes(":"))return [null,r,i];let o=r.split(":"),n=o.pop(),s=o.join(":");return t.push(s??null,n??null,i??null),t}var Wr=["bg-","text-","border-","ring-offset-","ring-"];function Br(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),i=new Set,o=new Set;for(let n of r){let[s,a,c]=Ye(n),f=Wr.find(m=>a?.startsWith(m));if(!f){i.has(n)||i.add(n);continue}let d=a?.replace(f,"");if(d&&d in t.light){i.add([s,`${f}${t.light[d]}`].filter(Boolean).join(":")+(c?`/${c}`:"")),o.add(["dark",s,`${f}${t.dark[d]}`].filter(Boolean).join(":")+(c?`/${c}`:""));continue}i.has(n)||i.add(n);}return [...Array.from(i),...Array.from(o)].join(" ").trim()}var _={lucide:{name:"lucide-react",package:"lucide-react",import:"lucide-react"},radix:{name:"@radix-ui/react-icons",package:"@radix-ui/react-icons",import:"@radix-ui/react-icons"}};var Vt="lucide",Re=async({sourceFile:e,config:t})=>{if(!t.iconLibrary||!(t.iconLibrary in _))return e;let r=await L(),i=Vt,o=t.iconLibrary;if(i===o)return e;let n=[];for(let s of e.getImportDeclarations()??[])if(s.getModuleSpecifier()?.getText()===`"${_[Vt].import}"`){for(let a of s.getNamedImports()??[]){let c=a.getName(),f=r[c]?.[o];!f||n.includes(f)||(n.push(f),a.remove(),e.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(d=>d.getTagNameNode()?.getText()===c).forEach(d=>d.getTagNameNode()?.replaceWithText(f)));}s.getNamedImports()?.length===0&&s.remove();}if(n.length>0){let s=e.addImportDeclaration({moduleSpecifier:_[o]?.import,namedImports:n.map(a=>({name:a}))});Kr(e)||s.replaceWithText(s.getText().replace(";",""));}return e};function Kr(e){return e.getImportDeclarations()?.[0]?.getText().endsWith(";")??!1}var ve=async({sourceFile:e,config:t,isRemote:r})=>{let o=`@${t.aliases?.utils?.split("/")[0]?.slice(1)}/lib/utils`,n=e.getImportDeclarations();if(![".tsx",".ts",".jsx",".js"].includes(e.getExtension()))return e;for(let s of n){let a=Gr(s.getModuleSpecifierValue(),t,r);s.setModuleSpecifier(a),(o===a||a==="@/lib/utils")&&s.getNamedImports().find(d=>d.getName()==="cn")&&s.setModuleSpecifier(o===a?a.replace(o,t.aliases.utils):t.aliases.utils);}return e};function Gr(e,t,r=!1){if(!e.startsWith("@/")&&!r)return e;if(r&&e.startsWith("@/")&&(e=e.replace(/^@\//,"@/registry/new-york/")),!e.startsWith("@/registry/")){let i=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${i}/`)}return e.match(/^@\/registry\/(.+)\/ui/)?e.replace(/^@\/registry\/(.+)\/ui/,t.aliases.ui??`${t.aliases.components}/ui`):t.aliases.components&&e.match(/^@\/registry\/(.+)\/components/)?e.replace(/^@\/registry\/(.+)\/components/,t.aliases.components):t.aliases.lib&&e.match(/^@\/registry\/(.+)\/lib/)?e.replace(/^@\/registry\/(.+)\/lib/,t.aliases.lib):t.aliases.hooks&&e.match(/^@\/registry\/(.+)\/hooks/)?e.replace(/^@\/registry\/(.+)\/hooks/,t.aliases.hooks):e.replace(/^@\/registry\/[^/]+/,t.aliases.components)}var qr={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},Lt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=Ie.parse(r,{parser:{parse:n=>parse(n,qr)}}),o=transformFromAstSync(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Xr],configFile:!1});if(!o||!o.ast)throw new Error("Failed to transform JSX");return Ie.print(o.ast).code};var Qr=/^["']use client["']$/g,Ce=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&Qr.test(r.getText())&&r.remove(),e};var Pe=async({sourceFile:e,config:t})=>{if(!t.tailwind?.prefix)return e;let r=await p(t);return e.getDescendantsOfKind(SyntaxKind.CallExpression).filter(i=>i.getExpression().getText()==="cva").forEach(i=>{if(i.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)){let o=i.getArguments()[0];o&&o.replaceWithText(`"${U(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}i.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&i.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find(o=>o.getName()==="variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(o=>{o.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(n=>{let s=n.getInitializerIfKind(SyntaxKind.StringLiteral);s&&s?.replaceWithText(`"${U(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});});}),e.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(i=>{if(i.getName()==="className"){if(i.getInitializer()?.isKind(SyntaxKind.StringLiteral)){let o=i.getInitializer();o&&o.replaceWithText(`"${U(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}if(i.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let o=i.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find(n=>n.getExpression().getText()==="cn");o&&o.getArguments().forEach(n=>{(n.isKind(SyntaxKind.ConditionalExpression)||n.isKind(SyntaxKind.BinaryExpression))&&n.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(s=>{s.replaceWithText(`"${U(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),n.isKind(SyntaxKind.StringLiteral)&&n.replaceWithText(`"${U(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}}i.getName()==="classNames"&&i.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&i.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(o=>{if(o.getInitializer()?.isKind(SyntaxKind.CallExpression)){let n=o.getInitializerIfKind(SyntaxKind.CallExpression);n&&n.getArguments().forEach(s=>{s.isKind(SyntaxKind.ConditionalExpression)&&s.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(a=>{a.replaceWithText(`"${U(a.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),s.isKind(SyntaxKind.StringLiteral)&&s.replaceWithText(`"${U(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}if(o.getInitializer()?.isKind(SyntaxKind.StringLiteral)&&o.getName()!=="variant"){let n=o.getInitializer();n&&n.replaceWithText(`"${U(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}});}),e};function U(e,t="",r){return r==="v3"?e.split(" ").map(i=>{let[o,n,s]=Ye(i);return o?s?`${o}:${t}${n}/${s}`:`${o}:${t}${n}`:s?`${t}${n}/${s}`:`${t}${n}`}).join(" "):e.split(" ").map(i=>i.indexOf(`${t}:`)===0?i:`${t}:${i.trim()}`).join(" ")}var ii=new Project({compilerOptions:{}});async function oi(e){let t=await promises.mkdtemp(w__default.join(tmpdir(),"shadcn-"));return w__default.join(t,e)}async function ke(e,t=[ve,Ce,Se,Pe,Re]){let r=await oi(e.filename),i=ii.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let o of t)await o({sourceFile:i,...e});return e.transformJsx?await Lt({sourceFile:i,...e}):i.getText()}async function Xe(e,t,r$1){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r$1={overwrite:!1,force:!1,silent:!1,isRemote:!1,...r$1};let i=r("Updating files.",{silent:r$1.silent})?.start(),[o,n$1]=await Promise.all([n(t.resolvedPaths.cwd),O(t.tailwind.baseColor)]),s=[],a$1=[],c=[];for(let u of e){if(!u.content)continue;let g=fi(u,t,{isSrcDir:o?.isSrcDir,framework:o?.framework.name,commonRoot:mi(e.map(x=>x.path),u.path)});if(!g)continue;let b=basename(u.path),h=w__default.dirname(g);t.tsx||(g=g.replace(/\.tsx?$/,x=>x===".tsx"?".jsx":".js"));let I=existsSync(g),T=await ke({filename:u.path,raw:u.content,config:t,baseColor:n$1,transformJsx:!t.tsx,isRemote:r$1.isRemote},[ve,Ce,Se,Pe,Re]);if(I){let x=await promises.readFile(g,"utf-8"),[P,C]=await Promise.all([zt(x),zt(T)]);if(P===C){c.push(w__default.relative(t.resolvedPaths.cwd,g));continue}}if(I&&!r$1.overwrite){i.stop(),r$1.rootSpinner&&r$1.rootSpinner.stop();let{overwrite:x}=await Qe({type:"confirm",name:"overwrite",message:`The file ${a.info(b)} already exists. Would you like to overwrite?`,initial:!1});if(!x){c.push(w__default.relative(t.resolvedPaths.cwd,g)),r$1.rootSpinner&&r$1.rootSpinner.start();continue}i?.start(),r$1.rootSpinner&&r$1.rootSpinner.start();}existsSync(h)||await promises.mkdir(h,{recursive:!0}),await promises.writeFile(g,T,"utf-8"),I?a$1.push(w__default.relative(t.resolvedPaths.cwd,g)):s.push(w__default.relative(t.resolvedPaths.cwd,g));}let f=[...s,...a$1,...c],d=await gi(f,t);if(a$1.push(...d),a$1=a$1.filter(u=>!s.includes(u)),!(s.length||a$1.length)&&!c.length&&i?.info("No files updated."),s=Array.from(new Set(s)),a$1=Array.from(new Set(a$1)),c=Array.from(new Set(c)),s.length){if(i?.succeed(`Created ${s.length} ${s.length===1?"file":"files"}:`),!r$1.silent)for(let u of s)q$1.log(` - ${u}`);}else i?.stop();if(a$1.length&&(r(`Updated ${a$1.length} ${a$1.length===1?"file":"files"}:`,{silent:r$1.silent})?.info(),!r$1.silent))for(let u of a$1)q$1.log(` - ${u}`);if(c.length&&(r(`Skipped ${c.length} ${a$1.length===1?"file":"files"}: (files might be identical, use --overwrite to overwrite)`,{silent:r$1.silent})?.info(),!r$1.silent))for(let u of c)q$1.log(` - ${u}`);return r$1.silent||q$1.break(),{filesCreated:s,filesUpdated:a$1,filesSkipped:c}}function fi(e,t,r){if(e.target){if(e.target.startsWith("~/"))return w__default.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let n=e.target;return e.type==="registry:page"&&(n=ui(n,r.framework),!n)?"":r.isSrcDir?w__default.join(t.resolvedPaths.cwd,"src",n.replace("src/","")):w__default.join(t.resolvedPaths.cwd,n.replace("src/",""))}let i=pi(e,t),o=di(e.path,i);return w__default.join(i,o)}function pi(e,t){return e.type==="registry:ui"?t.resolvedPaths.ui:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:block"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:hook"?t.resolvedPaths.hooks:t.resolvedPaths.components}function mi(e,t){let r=e.map(s=>s.replace(/^\//,"")),i=t.replace(/^\//,""),o=i.split("/").slice(0,-1).join("/");if(!o)return "";let n=o.split("/");for(let s=n.length;s>0;s--){let a=n.slice(0,s).join("/");if(r.some(f=>f!==i&&f.startsWith(a+"/")))return "/"+a}return "/"+o}function di(e,t){let r=e.replace(/^\/|\/$/g,""),i=t.replace(/^\/|\/$/g,""),o=r.split("/"),n=i.split("/"),s=n[n.length-1],a=o.findIndex(c=>c===s);return a===-1?o[o.length-1]:o.slice(a+1).join("/")}async function zt(e){return e.replace(/\r\n/g,`
65
+ `);let a=await Qe([{type:"select",name:"flag",message:"How would you like to proceed?",choices:[{title:"Use --force",value:"force"},{title:"Use --legacy-peer-deps",value:"legacy-peer-deps"}]}]);a&&(s=a.flag);}o?.start(),e?.length&&await execa(n,[n==="npm"?"install":"add",...n==="npm"&&s?[`--${s}`]:[],...n==="deno"?e.map(a=>`npm:${a}`):e],{cwd:r$1.resolvedPaths.cwd}),t?.length&&await execa(n,[n==="npm"?"install":"add",...n==="npm"&&s?[`--${s}`]:[],"-D",...n==="deno"?t.map(a=>`npm:${a}`):t],{cwd:r$1.resolvedPaths.cwd}),o?.succeed();}function Mr(e){let t=m(e.resolvedPaths.cwd,!1);if(!t?.dependencies?.react)return !1;let r=/^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(t.dependencies.react),i=t.dependencies["react-day-picker"]?.startsWith("8");return r&&i}var Se=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(i=>{let o=i.getText();if(o){let n=Br(o.replace(/"/g,""),r.inlineColors);i.replaceWithText(`"${n.trim()}"`);}}),e);function Ye(e){if(!e.includes("/")&&!e.includes(":"))return [null,e,null];let t=[],[r,i]=e.split("/");if(!r.includes(":"))return [null,r,i];let o=r.split(":"),n=o.pop(),s=o.join(":");return t.push(s??null,n??null,i??null),t}var Wr=["bg-","text-","border-","ring-offset-","ring-"];function Br(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),i=new Set,o=new Set;for(let n of r){let[s,a,c]=Ye(n),f=Wr.find(m=>a?.startsWith(m));if(!f){i.has(n)||i.add(n);continue}let d=a?.replace(f,"");if(d&&d in t.light){i.add([s,`${f}${t.light[d]}`].filter(Boolean).join(":")+(c?`/${c}`:"")),o.add(["dark",s,`${f}${t.dark[d]}`].filter(Boolean).join(":")+(c?`/${c}`:""));continue}i.has(n)||i.add(n);}return [...Array.from(i),...Array.from(o)].join(" ").trim()}var _={lucide:{name:"lucide-react",package:"lucide-react",import:"lucide-react"},radix:{name:"@radix-ui/react-icons",package:"@radix-ui/react-icons",import:"@radix-ui/react-icons"}};var Vt="lucide",Re=async({sourceFile:e,config:t})=>{if(!t.iconLibrary||!(t.iconLibrary in _))return e;let r=await L(),i=Vt,o=t.iconLibrary;if(i===o)return e;let n=[];for(let s of e.getImportDeclarations()??[])if(s.getModuleSpecifier()?.getText()===`"${_[Vt].import}"`){for(let a of s.getNamedImports()??[]){let c=a.getName(),f=r[c]?.[o];!f||n.includes(f)||(n.push(f),a.remove(),e.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(d=>d.getTagNameNode()?.getText()===c).forEach(d=>d.getTagNameNode()?.replaceWithText(f)));}s.getNamedImports()?.length===0&&s.remove();}if(n.length>0){let s=e.addImportDeclaration({moduleSpecifier:_[o]?.import,namedImports:n.map(a=>({name:a}))});Kr(e)||s.replaceWithText(s.getText().replace(";",""));}return e};function Kr(e){return e.getImportDeclarations()?.[0]?.getText().endsWith(";")??!1}var ve=async({sourceFile:e,config:t,isRemote:r})=>{let o=`@${t.aliases?.utils?.split("/")[0]?.slice(1)}/lib/utils`,n=e.getImportDeclarations();if(![".tsx",".ts",".jsx",".js"].includes(e.getExtension()))return e;for(let s of n){let a=Gr(s.getModuleSpecifierValue(),t,r);s.setModuleSpecifier(a),(o===a||a==="@/lib/utils")&&s.getNamedImports().find(d=>d.getName()==="cn")&&s.setModuleSpecifier(o===a?a.replace(o,t.aliases.utils):t.aliases.utils);}return e};function Gr(e,t,r=!1){if(!e.startsWith("@/")&&!r)return e;if(r&&e.startsWith("@/")&&(e=e.replace(/^@\//,"@/registry/new-york/")),!e.startsWith("@/registry/")){let i=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${i}/`)}return e.match(/^@\/registry\/(.+)\/ui/)?e.replace(/^@\/registry\/(.+)\/ui/,t.aliases.ui??`${t.aliases.components}/ui`):t.aliases.components&&e.match(/^@\/registry\/(.+)\/components/)?e.replace(/^@\/registry\/(.+)\/components/,t.aliases.components):t.aliases.lib&&e.match(/^@\/registry\/(.+)\/lib/)?e.replace(/^@\/registry\/(.+)\/lib/,t.aliases.lib):t.aliases.hooks&&e.match(/^@\/registry\/(.+)\/hooks/)?e.replace(/^@\/registry\/(.+)\/hooks/,t.aliases.hooks):e.replace(/^@\/registry\/[^/]+/,t.aliases.components)}var qr={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},Lt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=Ie.parse(r,{parser:{parse:n=>parse(n,qr)}}),o=transformFromAstSync(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Xr],configFile:!1});if(!o||!o.ast)throw new Error("Failed to transform JSX");return Ie.print(o.ast).code};var Qr=/^["']use client["']$/g,Ce=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&Qr.test(r.getText())&&r.remove(),e};var Pe=async({sourceFile:e,config:t})=>{if(!t.tailwind?.prefix)return e;let r=await p(t);return e.getDescendantsOfKind(SyntaxKind.CallExpression).filter(i=>i.getExpression().getText()==="cva").forEach(i=>{if(i.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)){let o=i.getArguments()[0];o&&o.replaceWithText(`"${U(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}i.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&i.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find(o=>o.getName()==="variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(o=>{o.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(n=>{let s=n.getInitializerIfKind(SyntaxKind.StringLiteral);s&&s?.replaceWithText(`"${U(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});});}),e.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(i=>{if(i.getName()==="className"){if(i.getInitializer()?.isKind(SyntaxKind.StringLiteral)){let o=i.getInitializer();o&&o.replaceWithText(`"${U(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}if(i.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let o=i.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find(n=>n.getExpression().getText()==="cn");o&&o.getArguments().forEach(n=>{(n.isKind(SyntaxKind.ConditionalExpression)||n.isKind(SyntaxKind.BinaryExpression))&&n.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(s=>{s.replaceWithText(`"${U(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),n.isKind(SyntaxKind.StringLiteral)&&n.replaceWithText(`"${U(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}}i.getName()==="classNames"&&i.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&i.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(o=>{if(o.getInitializer()?.isKind(SyntaxKind.CallExpression)){let n=o.getInitializerIfKind(SyntaxKind.CallExpression);n&&n.getArguments().forEach(s=>{s.isKind(SyntaxKind.ConditionalExpression)&&s.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(a=>{a.replaceWithText(`"${U(a.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),s.isKind(SyntaxKind.StringLiteral)&&s.replaceWithText(`"${U(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}if(o.getInitializer()?.isKind(SyntaxKind.StringLiteral)&&o.getName()!=="variant"){let n=o.getInitializer();n&&n.replaceWithText(`"${U(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}});}),e};function U(e,t="",r){return r==="v3"?e.split(" ").map(i=>{let[o,n,s]=Ye(i);return o?s?`${o}:${t}${n}/${s}`:`${o}:${t}${n}`:s?`${t}${n}/${s}`:`${t}${n}`}).join(" "):e.split(" ").map(i=>i.indexOf(`${t}:`)===0?i:`${t}:${i.trim()}`).join(" ")}var ii=new Project({compilerOptions:{}});async function oi(e){let t=await promises.mkdtemp(w__default.join(tmpdir(),"shadcn-"));return w__default.join(t,e)}async function ke(e,t=[ve,Ce,Se,Pe,Re]){let r=await oi(e.filename),i=ii.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let o of t)await o({sourceFile:i,...e});return e.transformJsx?await Lt({sourceFile:i,...e}):i.getText()}async function Xe(e,t,r$1){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r$1={overwrite:!1,force:!1,silent:!1,isRemote:!1,...r$1};let i=r("Updating files.",{silent:r$1.silent})?.start(),[o,n$1]=await Promise.all([n(t.resolvedPaths.cwd),O(t.tailwind.baseColor)]),s=[],a$1=[],c=[];for(let u of e){if(!u.content)continue;let g=fi(u,t,{isSrcDir:o?.isSrcDir,framework:o?.framework.name,commonRoot:mi(e.map(x=>x.path),u.path)});if(!g)continue;let b=basename(u.path),h=w__default.dirname(g);t.tsx||(g=g.replace(/\.tsx?$/,x=>x===".tsx"?".jsx":".js"));let I=existsSync(g),T=await ke({filename:u.path,raw:u.content,config:t,baseColor:n$1,transformJsx:!t.tsx,isRemote:r$1.isRemote},[ve,Ce,Se,Pe,Re]);if(I){let x=await promises.readFile(g,"utf-8"),[P,C]=await Promise.all([zt(x),zt(T)]);if(P===C){c.push(w__default.relative(t.resolvedPaths.cwd,g));continue}}if(I&&!r$1.overwrite){i.stop(),r$1.rootSpinner&&r$1.rootSpinner.stop();let{overwrite:x}=await Qe({type:"confirm",name:"overwrite",message:`The file ${a.info(b)} already exists. Would you like to overwrite?`,initial:!1});if(!x){c.push(w__default.relative(t.resolvedPaths.cwd,g)),r$1.rootSpinner&&r$1.rootSpinner.start();continue}i?.start(),r$1.rootSpinner&&r$1.rootSpinner.start();}existsSync(h)||await promises.mkdir(h,{recursive:!0}),await promises.writeFile(g,T,"utf-8"),I?a$1.push(w__default.relative(t.resolvedPaths.cwd,g)):s.push(w__default.relative(t.resolvedPaths.cwd,g));}let f=[...s,...a$1,...c],d=await gi(f,t);if(a$1.push(...d),a$1=a$1.filter(u=>!s.includes(u)),!(s.length||a$1.length)&&!c.length&&i?.info("No files updated."),s=Array.from(new Set(s)),a$1=Array.from(new Set(a$1)),c=Array.from(new Set(c)),s.length){if(i?.succeed(`Created ${s.length} ${s.length===1?"file":"files"}:`),!r$1.silent)for(let u of s)q$1.log(` - ${u}`);}else i?.stop();if(a$1.length&&(r(`Updated ${a$1.length} ${a$1.length===1?"file":"files"}:`,{silent:r$1.silent})?.info(),!r$1.silent))for(let u of a$1)q$1.log(` - ${u}`);if(c.length&&(r(`Skipped ${c.length} ${a$1.length===1?"file":"files"}: (files might be identical, use --overwrite to overwrite)`,{silent:r$1.silent})?.info(),!r$1.silent))for(let u of c)q$1.log(` - ${u}`);return r$1.silent||q$1.break(),{filesCreated:s,filesUpdated:a$1,filesSkipped:c}}function fi(e,t,r){if(e.target){if(e.target.startsWith("~/"))return w__default.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let n=e.target;return e.type==="registry:page"&&(n=ui(n,r.framework),!n)?"":r.isSrcDir?w__default.join(t.resolvedPaths.cwd,"src",n.replace("src/","")):w__default.join(t.resolvedPaths.cwd,n.replace("src/",""))}let i=pi(e,t),o=di(e.path,i);return w__default.join(i,o)}function pi(e,t){return e.type==="registry:ui"?t.resolvedPaths.ui:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:block"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:hook"?t.resolvedPaths.hooks:t.resolvedPaths.components}function mi(e,t){let r=e.map(s=>s.replace(/^\//,"")),i=t.replace(/^\//,""),o=i.split("/").slice(0,-1).join("/");if(!o)return "";let n=o.split("/");for(let s=n.length;s>0;s--){let a=n.slice(0,s).join("/");if(r.some(f=>f!==i&&f.startsWith(a+"/")))return "/"+a}return "/"+o}function di(e,t){let r=e.replace(/^\/|\/$/g,""),i=t.replace(/^\/|\/$/g,""),o=r.split("/"),n=i.split("/"),s=n[n.length-1],a=o.findIndex(c=>c===s);return a===-1?o[o.length-1]:o.slice(a+1).join("/")}async function zt(e){return e.replace(/\r\n/g,`
66
66
  `).trim()}function ui(e,t){if(!t)return "";if(t==="next-app")return e;if(t==="next-pages"){let r=e.replace(/^app\//,"pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="react-router"){let r=e.replace(/^app\//,"app/routes/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="laravel"){let r=e.replace(/^app\//,"resources/js/pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}return ""}async function gi(e,t){let r=new Project({compilerOptions:{}}),i=await n(t.resolvedPaths.cwd),o=await loadConfig(t.resolvedPaths.cwd),n$1=[];if(!i||o.resultType==="failed")return [];for(let s of e){let a=w__default.resolve(t.resolvedPaths.cwd,s);if(!existsSync(a))continue;let c=await promises.readFile(a,"utf-8"),f=await promises.mkdtemp(w__default.join(tmpdir(),"shadcn-")),d=r.createSourceFile(w__default.join(f,basename(a)),c,{scriptKind:ScriptKind.TSX});if(![".tsx",".ts",".jsx",".js"].includes(d.getExtension()))continue;let m=d.getImportDeclarations();for(let u of m){let g=u.getModuleSpecifierValue();if(i?.aliasPrefix&&!g.startsWith(`${i.aliasPrefix}/`))continue;let b$1=await b(g,o);if(!b$1)continue;let h=hi(b$1,e,t);if(!h)continue;let I=yi(h,t,i);!I||I===g||(u.setModuleSpecifier(I),await promises.writeFile(a,d.getFullText(),"utf-8"),n$1.push(s));}}return n$1}function hi(e,t,r,i=[".tsx",".ts",".js",".jsx",".css"]){let o=w__default.normalize(r.resolvedPaths.cwd),n=t.map(I=>I.split(w__default.sep).join(w__default.posix.sep)),s=new Set(n),a=w__default.extname(e),c=a!=="",f=c?e.slice(0,-a.length):e,m=w__default.relative(o,f).split(w__default.sep).join(w__default.posix.sep),u=c?[a]:i,g=new Set;for(let I of u){let T=f+I,x=w__default.posix.normalize(w__default.relative(o,T));(s.has(x)||existsSync(T))&&g.add(x);let P=w__default.join(f,`index${I}`),C=w__default.posix.normalize(w__default.relative(o,P));(s.has(C)||existsSync(P))&&g.add(C);}let b=w__default.basename(f);for(let I of n)u.some(T=>I.endsWith(`/${b}${T}`))&&g.add(I);return g.size===0?null:Array.from(g).sort((I,T)=>{let x=w__default.posix.extname(I),P=w__default.posix.extname(T),C=u.indexOf(x)-u.indexOf(P);if(C!==0)return C;let Q=m&&I.startsWith(m)?-1:1,F=m&&T.startsWith(m)?-1:1;return Q-F})[0]}function yi(e,t,r){let i=w__default.normalize(w__default.join(t.resolvedPaths.cwd,e)),o=Object.entries(t.resolvedPaths).filter(([,b])=>b&&i.startsWith(w__default.normalize(b+w__default.sep))).sort((b,h)=>h[1].length-b[1].length);if(o.length===0)return null;let[n,s]=o[0],a=w__default.relative(s,i);a=a.split(w__default.sep).join("/");let c=w__default.posix.extname(a),d=[".ts",".tsx",".js",".jsx"].includes(c)?"":c,m=a.slice(0,a.length-c.length);m.endsWith("/index")&&(m=m.slice(0,-6));let u=n==="cwd"?r.aliasPrefix:t.aliases[n];if(!u)return null;let g=m===""?"":`/${m}`;return g=g.replace("/src",""),`${u}${g}${d}`}async function je(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,style:"index",...r};let i=await j(t);return i&&i.ui&&i.ui.resolvedPaths.cwd!==t.resolvedPaths.cwd?await xi(e,t,i,{...r,isRemote:e?.length===1&&!!e[0].match(/\/chat\/b\//)}):await wi(e,t,r)}async function wi(e,t$1,r$1){let i=r("Checking registry.",{silent:r$1.silent})?.start(),o=await U$1(e,t$1);if(!o)return i?.fail(),s(new Error("Failed to fetch components from registry."));i?.succeed();let n=await p(t$1);await t(o.tailwind?.config,t$1,{silent:r$1.silent,tailwindVersion:n});let s$1=await Ut(e,t$1);await Je(o.cssVars,t$1,{cleanupDefaultNextStyles:r$1.isNewProject,silent:r$1.silent,tailwindVersion:n,tailwindConfig:o.tailwind?.config,overwriteCssVars:s$1,initIndex:r$1.style?r$1.style==="index":!1}),await Ge(o.css,t$1,{silent:r$1.silent}),await ne(o.dependencies,o.devDependencies,t$1,{silent:r$1.silent}),await Xe(o.files,t$1,{overwrite:r$1.overwrite,silent:r$1.silent}),o.docs&&q$1.info(o.docs);}async function xi(e,t$1,r$1,i){let o=r("Checking registry.",{silent:i.silent})?.start(),n=await X$1(e,t$1),s$1=await S(n),a=z$1.array(B).parse(s$1);if(!a)return o?.fail(),s(new Error("Failed to fetch components from registry."));o?.succeed();let c=Z(a),f=Y(),d=[],m=[],u=[],g=r("Installing components.")?.start();for(let h of a){let I=f.get(h.type),T=c.get(h.name);if(!I)continue;let x=h.type==="registry:ui"||T?.type==="registry:ui"?r$1.ui:t$1,P=await p(x),C=l(t$1.resolvedPaths.cwd,x.resolvedPaths.ui),Q=await k(C,x.resolvedPaths.cwd)??x.resolvedPaths.cwd;if(h.tailwind?.config&&(await t(h.tailwind?.config,x,{silent:!0,tailwindVersion:P}),m.push(w__default.relative(C,x.resolvedPaths.tailwindConfig))),h.cssVars){let W=await Ut(e,t$1);await Je(h.cssVars,x,{silent:!0,tailwindVersion:P,tailwindConfig:h.tailwind?.config,overwriteCssVars:W}),m.push(w__default.relative(C,x.resolvedPaths.tailwindCss));}h.css&&(await Ge(h.css,x,{silent:!0}),m.push(w__default.relative(C,x.resolvedPaths.tailwindCss))),await ne(h.dependencies,h.devDependencies,x,{silent:!0});let F=await Xe(h.files,x,{overwrite:i.overwrite,silent:!0,rootSpinner:g,isRemote:i.isRemote});d.push(...F.filesCreated.map(W=>w__default.relative(C,w__default.join(Q,W)))),m.push(...F.filesUpdated.map(W=>w__default.relative(C,w__default.join(Q,W)))),u.push(...F.filesSkipped.map(W=>w__default.relative(C,w__default.join(Q,W))));}if(g?.succeed(),d.sort(),m.sort(),u.sort(),!(d.length||m.length)&&!u.length&&r("No files updated.",{silent:i.silent})?.info(),d.length){r(`Created ${d.length} ${d.length===1?"file":"files"}:`,{silent:i.silent})?.succeed();for(let h of d)q$1.log(` - ${h}`);}if(m.length){r(`Updated ${m.length} ${m.length===1?"file":"files"}:`,{silent:i.silent})?.info();for(let h of m)q$1.log(` - ${h}`);}if(u.length){r(`Skipped ${u.length} ${m.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i.silent})?.info();for(let h of u)q$1.log(` - ${h}`);}}async function Ut(e,t){let r=await X$1(e,t),i=await S(r);return z$1.array(B).parse(i).some(n=>n.type==="registry:theme"||n.type==="registry:style")}var Ri="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",q={next:"next","next-monorepo":"next-monorepo"};async function Te(e){e={srcDir:!1,...e};let t=e.template&&q[e.template]?e.template:"next",r=t===q.next?"my-app":"my-monorepo",i="latest",o=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&o)try{let[a]=await S(e.components),{meta:c}=z$1.object({meta:z$1.object({nextVersion:z$1.string()})}).parse(a);i=c.nextVersion,t=q.next;}catch(a){q$1.break(),s(a);}if(!e.force){let{type:a$1,name:c}=await Qe([{type:e.template||o?null:"select",name:"type",message:`The path ${a.info(e.cwd)} does not contain a package.json file.
67
67
  Would you like to start a new project?`,choices:[{title:"Next.js",value:"next"},{title:"Next.js (Monorepo)",value:"next-monorepo"}],initial:0},{type:"text",name:"name",message:"What is your project named?",initial:r,format:f=>f.trim(),validate:f=>f.length>128?"Name should be less than 128 characters.":!0}]);t=a$1??t,r=c;}let n=await be(e.cwd,{withFallback:!0}),s$1=`${e.cwd}/${r}`;try{await H.access(e.cwd,H.constants.W_OK);}catch{q$1.break(),q$1.error(`The path ${a.info(e.cwd)} is not writable.`),q$1.error(`It is likely you do not have write permissions for this folder or the path ${a.info(e.cwd)} does not exist.`),q$1.break(),process.exit(1);}return H.existsSync(w__default.resolve(e.cwd,r,"package.json"))&&(q$1.break(),q$1.error(`A project with the name ${a.info(r)} already exists.`),q$1.error("Please choose a different name and try again."),q$1.break(),process.exit(1)),t===q.next&&await vi(s$1,{version:i,cwd:e.cwd,packageManager:n,srcDir:!!e.srcDir}),t===q["next-monorepo"]&&await Ii(s$1,{packageManager:n}),{projectPath:s$1,projectName:r,template:t}}async function vi(e,t){let r$1=r("Creating a new Next.js project. This may take a few minutes.").start(),i=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];(t.version.startsWith("15")||t.version.startsWith("latest")||t.version.startsWith("canary"))&&i.push("--turbopack");try{await execa("npx",[`create-next-app@${t.version}`,e,"--silent",...i],{cwd:t.cwd});}catch{q$1.break(),q$1.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(1);}r$1?.succeed("Creating a new Next.js project.");}async function Ii(e,t){let r$1=r("Creating a new Next.js monorepo. This may take a few minutes.").start();try{let i=w__default.join(bi.tmpdir(),`shadcn-template-${Date.now()}`);await H.ensureDir(i);let o=await fetch(Ri);if(!o.ok)throw new Error(`Failed to download template: ${o.statusText}`);let n=w__default.resolve(i,"template.tar.gz");await H.writeFile(n,Buffer.from(await o.arrayBuffer())),await execa("tar",["-xzf",n,"-C",i,"--strip-components=2","ui-main/templates/monorepo-next"]);let s=w__default.resolve(i,"monorepo-next");await H.move(s,e),await H.remove(i),await execa(t.packageManager,["install"],{cwd:e});let a=process.cwd();await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),await execa("cd",[a]),r$1?.succeed("Creating a new Next.js monorepo.");}catch(i){r$1?.fail("Something went wrong creating a new Next.js monorepo."),s(i);}}async function Gt(e,t,r$1){if(!e)return;r$1={silent:!1,...r$1};let i=w__default.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),o=r(`Updating ${a.info(i)}`,{silent:r$1.silent}).start(),n=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),s=await Pi(n,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,s,"utf8"),o?.succeed();}async function Pi(e,t,r){let i=await u(e,r),o=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(n=>n.getProperties().some(s=>s.isKind(SyntaxKind.PropertyAssignment)&&s.getName()==="content"));return o?(ki(o,t),i.getFullText()):e}async function ki(e,t){let r=v(e),i=e.getProperty("content");if(!i){let o={name:"content",initializer:`[${r}${t.join(`${r}, ${r}`)}${r}]`};return e.addPropertyAssignment(o),e}if(i.isKind(SyntaxKind.PropertyAssignment)){let o=i.getInitializer();if(o?.isKind(SyntaxKind.ArrayLiteralExpression))for(let n of t){let s=`${r}${n}${r}`;o.getElements().map(a=>a.getText()).includes(s)||o.addElement(s);}return e}return e}var Ti=z$1.object({cwd:z$1.string(),components:z$1.array(z$1.string()).optional(),yes:z$1.boolean(),defaults:z$1.boolean(),force:z$1.boolean(),silent:z$1.boolean(),isNewProject:z$1.boolean(),srcDir:z$1.boolean().optional(),cssVariables:z$1.boolean(),template:z$1.string().optional().refine(e=>e?q[e]:!0,{message:"Invalid template. Please use 'next' or 'next-monorepo'."}),baseColor:z$1.string().optional().refine(e=>e?I.find(t=>t.name===e):!0,{message:`Invalid base color. Please use '${I.map(e=>e.name).join("', '")}'`}),style:z$1.string()}),Jt=new Command().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add or a url to the component.").option("-t, --template <template>","the template to use. (next, next-monorepo)").option("-b, --base-color <base-color>","the base color to use. (neutral, gray, zinc, stone, slate)",void 0).option("-y, --yes","skip confirmation prompt.",!0).option("-d, --defaults,","use default configuration.",!1).option("-f, --force","force overwrite of existing configuration.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).option("--no-src-dir","do not use the src directory when creating a new project.").option("--css-variables","use css variables for theming.",!0).option("--no-css-variables","do not use css variables for theming.").action(async(e,t)=>{try{let r=Ti.parse({cwd:w__default.resolve(t.cwd),isNewProject:!1,components:e,style:"index",...t});if(e.length>0&&W(e[0])){let i=await M(e[0],"");i?.type==="registry:style"&&(r.baseColor="neutral",r.style=i.extends??"index");}await $e(r),q$1.log(`${a.success("Success!")} Project initialization completed.
68
68
  You may now add components.`),q$1.break();}catch(r){q$1.break(),s(r);}});async function $e(e){let t,r$1;if(e.skipPreflight)t=await n(e.cwd);else {let f=await Tt(e);if(f.errors[D]){let{projectPath:d,template:m}=await Te(e);d||process.exit(1),e.cwd=d,e.isNewProject=!0,r$1=m;}t=f.projectInfo;}if(r$1==="next-monorepo")return e.cwd=w__default.resolve(e.cwd,"apps/web"),await h(e.cwd);let i$1=await o(e.cwd,t),o$1=i$1?await $i(i$1,e):await Oi(await h(e.cwd));if(!e.yes){let{proceed:f}=await Qe({type:"confirm",name:"proceed",message:`Write configuration to ${a.info("components.json")}. Proceed?`,initial:!0});f||process.exit(0);}let n$1=r("Writing components.json.").start(),s=w__default.resolve(e.cwd,"components.json");await promises.writeFile(s,JSON.stringify(o$1,null,2),"utf8"),n$1.succeed();let a$1=await i(e.cwd,o$1),c=[...e.style==="none"?[]:[e.style],...e.components??[]];return await je(c,a$1,{overwrite:!0,silent:e.silent,style:e.style,isNewProject:e.isNewProject||t?.framework.name==="next-app"}),e.isNewProject&&e.srcDir&&await Gt(["./src/**/*.{js,ts,jsx,tsx,mdx}"],a$1,{silent:e.silent}),a$1}async function Oi(e$1=null){let[t,r]=await Promise.all([K(),N()]);q$1.info("");let i=await Qe([{type:"toggle",name:"typescript",message:`Would you like to use ${a.info("TypeScript")} (recommended)?`,initial:e$1?.tsx??!0,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${a.info("style")} would you like to use?`,choices:t.map(o=>({title:o.label,value:o.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${a.info("base color")}?`,choices:r.map(o=>({title:o.label,value:o.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${a.info("global CSS")} file?`,initial:e$1?.tailwind.css??e},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${a.info("CSS variables")} for theming?`,initial:e$1?.tailwind.cssVariables??!0,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${a.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${a.info("tailwind.config.js")} located?`,initial:e$1?.tailwind.config??f},{type:"text",name:"components",message:`Configure the import alias for ${a.info("components")}:`,initial:e$1?.aliases.components??c},{type:"text",name:"utils",message:`Configure the import alias for ${a.info("utils")}:`,initial:e$1?.aliases.utils??d},{type:"toggle",name:"rsc",message:`Are you using ${a.info("React Server Components")}?`,initial:e$1?.rsc??!0,active:"yes",inactive:"no"}]);return g.parse({$schema:"https://ui.shadcn.com/schema.json",style:i.style,tailwind:{config:i.tailwindConfig,css:i.tailwindCss,baseColor:i.tailwindBaseColor,cssVariables:i.tailwindCssVariables,prefix:i.tailwindPrefix},rsc:i.rsc,tsx:i.typescript,aliases:{utils:i.utils,components:i.components,lib:i.components.replace(/\/components$/,"lib"),hooks:i.components.replace(/\/components$/,"hooks")}})}async function $i(e,t){let r=e.style,i=t.baseColor,o=e.tailwind.cssVariables;if(!t.defaults){let[n,s,a$1]=await Promise.all([K(),N(),p(e)]),c=await Qe([{type:a$1==="v4"?null:"select",name:"style",message:`Which ${a.info("style")} would you like to use?`,choices:n.map(f=>({title:f.name==="new-york"?"New York (Recommended)":f.label,value:f.name})),initial:0},{type:t.baseColor?null:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${a.info("base color")}?`,choices:s.map(f=>({title:f.label,value:f.name}))}]);r=c.style??"new-york",i=c.tailwindBaseColor??i,o=t.cssVariables;}return g.parse({$schema:e?.$schema,style:r,tailwind:{...e?.tailwind,baseColor:i,cssVariables:o},rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases,iconLibrary:e?.iconLibrary})}async function Xt(e){let t={};if(!H.existsSync(e.cwd)||!H.existsSync(w__default.resolve(e.cwd,"package.json")))return t[D]=!0,{errors:t,config:null};if(!H.existsSync(w__default.resolve(e.cwd,"components.json")))return t[A]=!0,{errors:t,config:null};try{let r=await h(e.cwd);return {errors:t,config:r}}catch{q$1.break(),q$1.error(`An invalid ${a.info("components.json")} file was found at ${a.info(e.cwd)}.
@@ -73,6 +73,6 @@ export default function Page() {
73
73
  }`;await z__default.writeFile(r,o,"utf8");}var tt=[{name:"toast",deprecatedBy:"sonner",message:"The toast component is deprecated. Use the sonner component instead."},{name:"toaster",deprecatedBy:"sonner",message:"The toaster component is deprecated. Use the sonner component instead."}],Di=z$1.object({components:z$1.array(z$1.string()).optional(),yes:z$1.boolean(),overwrite:z$1.boolean(),cwd:z$1.string(),all:z$1.boolean(),path:z$1.string().optional(),silent:z$1.boolean(),srcDir:z$1.boolean().optional(),cssVariables:z$1.boolean()}),Zt=new Command().name("add").description("add a component to your project").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",!1).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).option("--no-src-dir","do not use the src directory when creating a new project.").option("--css-variables","use css variables for theming.",!0).option("--no-css-variables","do not use css variables for theming.").action(async(e,t)=>{try{let r=Di.parse({components:e,cwd:w__default.resolve(t.cwd),...t}),i;if(e.length>0&&W(e[0])&&(i=(await M(e[0],""))?.type),!r.yes&&(i==="registry:style"||i==="registry:theme")){q$1.break();let{confirm:c}=await Qe({type:"confirm",name:"confirm",message:a.warn(`You are about to install a new ${i.replace("registry:","")}.
74
74
  Existing CSS variables and components will be overwritten. Continue?`)});c||(q$1.break(),q$1.log("Installation cancelled."),q$1.break(),process.exit(1));}if(r.components?.length||(r.components=await Ai(r)),(await n(r.cwd))?.tailwindVersion==="v4"){let c=tt.filter(f=>r.components?.includes(f.name));c?.length&&(q$1.break(),c.forEach(f=>{q$1.warn(a.warn(f.message));}),q$1.break(),process.exit(1));}let{errors:n$1,config:s}=await Xt(r);if(n$1[A]){let{proceed:c}=await Qe({type:"confirm",name:"proceed",message:`You need to create a ${a.info("components.json")} file to add components. Proceed?`,initial:!0});c||(q$1.break(),process.exit(1)),s=await $e({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:!0,isNewProject:!1,srcDir:r.srcDir,cssVariables:r.cssVariables,style:"index"});}let a$1=!1;if(n$1[D]){let{projectPath:c,template:f}=await Te({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});c||(q$1.break(),process.exit(1)),r.cwd=c,f==="next-monorepo"?(r.cwd=w__default.resolve(r.cwd,"apps/web"),s=await h(r.cwd)):(s=await $e({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!0,isNewProject:!0,srcDir:r.srcDir,cssVariables:r.cssVariables,style:"index"}),a$1=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}if(!s)throw new Error(`Failed to read config at ${a.info(r.cwd)}.`);await je(r.components,s,r),a$1&&await Ht(r.components[0],s);}catch(r){q$1.break(),s(r);}});async function Ai(e){let t=await J();if(!t)return q$1.break(),s(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(o=>o.name).filter(o=>!tt.some(n=>n.name===o));if(e.components?.length)return e.components;let{components:r}=await Qe({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:!1,choices:t.filter(o=>o.type==="registry:ui"&&!tt.some(n=>n.name===o.name)).map(o=>({title:o.name,value:o.name,selected:e.all?!0:e.components?.includes(o.name)}))});r?.length||(q$1.warn("No components selected. Exiting."),q$1.info(""),process.exit(1));let i=z$1.array(z$1.string()).safeParse(r);return i.success?i.data:(q$1.error(""),s(new Error("Something went wrong. Please try again.")),[])}async function rr(e){let t={},r={cwd:e.cwd,registryFile:w__default.resolve(e.cwd,e.registryFile),outputDir:w__default.resolve(e.cwd,e.outputDir)};return H.existsSync(r.registryFile)||(t[X]=!0),await H.mkdir(r.outputDir,{recursive:!0}),Object.keys(t).length>0&&(t[X]&&(q$1.break(),q$1.error(`The path ${a.info(r.registryFile)} does not exist.`)),q$1.break(),process.exit(1)),{errors:t,resolvePaths:r}}var Vi=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string()}),ir=new Command().name("build").description("build components for a shadcn registry").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()).action(async(e,t)=>{try{let r$1=Vi.parse({cwd:w.resolve(t.cwd),registryFile:e,outputDir:t.output}),{resolvePaths:i}=await rr(r$1),o=await z.readFile(i.registryFile,"utf-8"),n=C.safeParse(JSON.parse(o));n.success||(q$1.error(`Invalid registry file found at ${a.info(i.registryFile)}.`),process.exit(1));let s=r("Building registry...");for(let a$1 of n.data.items){if(!a$1.files)continue;s.start(`Building ${a$1.name}...`),a$1.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let f of a$1.files)f.content=await z.readFile(w.resolve(i.cwd,f.path),"utf-8");let c=B.safeParse(a$1);if(!c.success){q$1.error(`Invalid registry item found for ${a.info(a$1.name)}.`);continue}await z.writeFile(w.resolve(i.outputDir,`${c.data.name}.json`),JSON.stringify(c.data,null,2));}s.succeed("Building registry.");}catch(r){q$1.break(),s(r);}});var Wi=z$1.object({component:z$1.string().optional(),yes:z$1.boolean(),cwd:z$1.string(),path:z$1.string().optional()}),nr=new Command().name("diff").description("check for updates against the registry").argument("[component]","the component name").option("-y, --yes","skip confirmation prompt.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=Wi.parse({component:e,...t}),i=w__default.resolve(r.cwd);existsSync(i)||(q$1.error(`The path ${i} does not exist. Please try again.`),process.exit(1));let o=await h(i);o||(q$1.warn(`Configuration is missing. Please run ${a.success("init")} to create a components.json file.`),process.exit(1));let n=await J();if(n||(s(new Error("Failed to fetch registry index.")),process.exit(1)),!r.component){let c=o.resolvedPaths.components,f=n.filter(m=>{for(let u of m.files??[]){let g=w__default.resolve(c,typeof u=="string"?u:u.path);if(existsSync(g))return !0}return !1}),d=[];for(let m of f){let u=await or(m,o);u.length&&d.push({name:m.name,changes:u});}d.length||(q$1.info("No updates found."),process.exit(0)),q$1.info("The following components have updates available:");for(let m of d){q$1.info(`- ${m.name}`);for(let u of m.changes)q$1.info(` - ${u.filePath}`);}q$1.break(),q$1.info(`Run ${a.success("diff <component>")} to see the changes.`),process.exit(0);}let s$1=n.find(c=>c.name===r.component);s$1||(q$1.error(`The component ${a.success(r.component)} does not exist.`),process.exit(1));let a$1=await or(s$1,o);a$1.length||(q$1.info(`No updates found for ${r.component}.`),process.exit(0));for(let c of a$1)q$1.info(`- ${c.filePath}`),await Bi(c.patch),q$1.info("");}catch(r){s(r);}});async function or(e,t){let r=await Q(t.style,[e]),i=await O(t.tailwind.baseColor);if(!r)return [];let o=[];for(let n of r){let s=await R(t,n);if(s)for(let a of n.files??[]){let c=w__default.resolve(s,typeof a=="string"?a:a.path);if(!existsSync(c))continue;let f=await promises.readFile(c,"utf8");if(typeof a=="string"||!a.content)continue;let d=await ke({filename:a.path,raw:a.content,config:t,baseColor:i}),m=diffLines(d,f);m.length>1&&o.push({filePath:c,patch:m});}}return o}async function Bi(e){e.forEach(t=>{if(t)return t.added?process.stdout.write(a.success(t.value)):t.removed?process.stdout.write(a.error(t.value)):process.stdout.write(t.value)});}var sr=new Command().name("info").description("get information about your project").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{q$1.info("> project info"),console.log(await n(e.cwd)),q$1.break(),q$1.info("> components.json"),console.log(await h(e.cwd));});async function cr(e){if(!e.resolvedPaths.ui)throw new Error("We could not find a valid `ui` path in your `components.json` file. Please ensure you have a valid `ui` path in your `components.json` file.");let t=e.resolvedPaths.ui,[r$1,i]=await Promise.all([Ji("**/*.{js,ts,jsx,tsx}",{cwd:t}),L()]);if(Object.keys(i).length===0)throw new Error("Something went wrong fetching the registry icons.");let o=Object.entries(_).map(([d,m])=>({title:m.name,value:d})),n=await Qe([{type:"select",name:"sourceLibrary",message:`Which icon library would you like to ${a.info("migrate from")}?`,choices:o},{type:"select",name:"targetLibrary",message:`Which icon library would you like to ${a.info("migrate to")}?`,choices:o}]);if(n.sourceLibrary===n.targetLibrary)throw new Error("You cannot migrate to the same icon library. Please choose a different icon library.");if(!(n.sourceLibrary in _&&n.targetLibrary in _))throw new Error("Invalid icon library. Please choose a valid icon library.");let s=_[n.sourceLibrary],a$1=_[n.targetLibrary],{confirm:c}=await Qe({type:"confirm",name:"confirm",initial:!0,message:`We will migrate ${a.info(r$1.length)} files in ${a.info(`./${w__default.relative(e.resolvedPaths.cwd,t)}`)} from ${a.info(s.name)} to ${a.info(a$1.name)}. Continue?`});c||(q$1.info("Migration cancelled."),process.exit(0)),a$1.package&&await ne([a$1.package],[],e,{silent:!1});let f=r("Migrating icons...")?.start();await Promise.all(r$1.map(async d=>{f.text=`Migrating ${d}...`;let m=w__default.join(t,d),u=await promises.readFile(m,"utf-8"),g=await Hi(u,n.sourceLibrary,n.targetLibrary,i);await promises.writeFile(m,g);})),f.succeed("Migration complete.");}async function Hi(e,t,r,i){let o=_[t]?.import,n=_[r]?.import,s=await promises.mkdtemp(w__default.join(tmpdir(),"shadcn-")),a=new Project({compilerOptions:{}}),c=w__default.join(s,`shadcn-icons-${randomBytes(4).toString("hex")}.tsx`),f=a.createSourceFile(c,e,{scriptKind:ScriptKind.TSX}),d=[];for(let m of f.getImportDeclarations()??[])if(m.getModuleSpecifier()?.getText()===`"${o}"`){for(let u of m.getNamedImports()??[]){let g=u.getName(),b=Object.values(i).find(h=>h[t]===g)?.[r];!b||d.includes(b)||(d.push(b),u.remove(),f.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(h=>h.getTagNameNode()?.getText()===g).forEach(h=>h.getTagNameNode()?.replaceWithText(b)));}m.getNamedImports()?.length===0&&m.remove();}return d.length>0&&f.addImportDeclaration({moduleSpecifier:n,namedImports:d.map(m=>({name:m}))}),await f.getText()}async function fr(e){let t={};if(!H.existsSync(e.cwd)||!H.existsSync(w__default.resolve(e.cwd,"package.json")))return t[D]=!0,{errors:t,config:null};if(!H.existsSync(w__default.resolve(e.cwd,"components.json")))return t[A]=!0,{errors:t,config:null};try{let r=await h(e.cwd);return {errors:t,config:r}}catch{q$1.break(),q$1.error(`An invalid ${a.info("components.json")} file was found at ${a.info(e.cwd)}.
75
75
  Before you can run a migration, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),q$1.error(`Learn more at ${a.info("https://ui.shadcn.com/docs/components-json")}.`),q$1.break(),process.exit(1);}}var pr=[{name:"icons",description:"migrate your ui components to a different icon library."}],eo=z$1.object({cwd:z$1.string(),list:z$1.boolean(),migration:z$1.string().refine(e=>e&&pr.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),mr=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",!1).action(async(e,t)=>{try{let r=eo.parse({cwd:w__default.resolve(t.cwd),migration:e,list:t.list});if(r.list||!r.migration){q$1.info("Available migrations:");for(let n of pr)q$1.info(`- ${n.name}: ${n.description}`);return}if(!r.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:o}=await fr(r);if(i[D]||i[A])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.");r.migration==="icons"&&await cr(o);}catch(r){q$1.break(),s(r);}});async function dr(e){let t={},r={cwd:e.cwd,registryFile:w__default.resolve(e.cwd,e.registryFile),outputDir:w__default.resolve(e.cwd,e.outputDir)};if(!H.existsSync(r.registryFile))return t[X]=!0,{errors:t,resolvePaths:null,config:null};if(!H.existsSync(w__default.resolve(e.cwd,"components.json")))return t[A]=!0,{errors:t,resolvePaths:null,config:null};await H.mkdir(r.outputDir,{recursive:!0});try{let i=await h(e.cwd);return {errors:t,config:i,resolvePaths:r}}catch{q$1.break(),q$1.error(`An invalid ${a.info("components.json")} file was found at ${a.info(e.cwd)}.
76
- Before you can build the registry, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),q$1.break(),process.exit(1);}}var ur=[".tsx",".ts",".jsx",".js",".css"],gr=["lib/utils.ts"],no=[/^(react|react-dom|next)(\/.*)?$/,/^(node|jsr|npm):.*$/],so=new Project({compilerOptions:{}});function ao(e){if(no.some(t=>t.test(e)))return null;if(!e.startsWith("@")&&e.includes("/")&&(e=e.split("/")[0]),e.startsWith("@")){let t=e.split("/");t.length>2&&(e=t.slice(0,2).join("/"));}return e}async function ct(e,t,r,i=new Set){let o=w.resolve(t.resolvedPaths.cwd,e),n=w.relative(t.resolvedPaths.cwd,o);if(gr.includes(n))return {dependencies:[],files:[]};let s=w.extname(e);if(!ur.includes(s))return {dependencies:[],files:[]};if(i.has(n))return {dependencies:[],files:[]};if(i.add(n),!(await z.stat(o)).isFile())return {dependencies:[],files:[]};let c=await z.readFile(o,"utf-8"),f=await co(w.basename(o)),d=so.createSourceFile(f,c,{scriptKind:ScriptKind.TSX}),m=await loadConfig(t.resolvedPaths.cwd);if(m.resultType==="failed")return {dependencies:[],files:[]};let u=[],g=new Set,b$1=hr(e),h={path:n,type:b$1,target:""};u.push(h);let I=d.getImportDeclarations();for(let x of I){let P=x.getModuleSpecifierValue(),C=P.startsWith(".");if(!P.startsWith(`${r.aliasPrefix}/`)&&!C){let V=ao(P);V&&g.add(V);continue}let F=await b(P,m);if(C&&(F=w.resolve(w.dirname(o),P)),!F)continue;if(!w.extname(F))for(let V of ur){let ft=`${F}${V}`;try{await z.access(ft),F=ft;break}catch{continue}}let fe=w.relative(t.resolvedPaths.cwd,F);if(i.has(fe)||gr.includes(fe))continue;let _e=hr(P),lt={path:fe,type:_e,target:""};(_e==="registry:page"||_e==="registry:file")&&(lt.target=P),u.push(lt);let pe=await ct(fe,t,r,i);if(pe.files)for(let V of pe.files)i.has(V.path)||(i.add(V.path),u.push(V));pe.dependencies&&pe.dependencies.forEach(V=>g.add(V));}let T=Array.from(new Map(u.map(x=>[x.path,x])).values());return {dependencies:Array.from(g),files:T}}async function co(e){let t=await z.mkdtemp(w.join(tmpdir(),"shadcn-"));return w.join(t,e)}function hr(e){return e.includes("/ui/")?"registry:ui":e.includes("/lib/")?"registry:lib":e.includes("/hooks/")?"registry:hook":(e.includes("/components/"),"registry:component")}var fo=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(!1)}),yr=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 po({cwd:w.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function po(e){try{let t=fo.parse(e),[{errors:r$1,resolvePaths:i,config:o},n$1]=await Promise.all([dr(t),n(t.cwd)]);(r$1[A]||!o||!n$1)&&(q$1.error(`A ${a.info("components.json")} file is required to build the registry. Run ${a.info("shadcn init")} to create one.`),q$1.break(),process.exit(1)),(r$1[X]||!i)&&(q$1.error(`We could not find a registry file at ${a.info(w.resolve(t.cwd,t.registryFile))}.`),q$1.break(),process.exit(1));let s=await z.readFile(i.registryFile,"utf-8"),a$1=C.safeParse(JSON.parse(s));a$1.success||(q$1.error(`Invalid registry file found at ${a.info(i.registryFile)}.`),q$1.break(),process.exit(1));let c=r("Building registry..."),f=await mo(a$1.data,o,n$1);for(let d of f.items)d.files=d.files?.filter((m,u,g)=>u===g.findIndex(b=>b.path===m.path)),d.dependencies&&(d.dependencies=d.dependencies.filter((m,u,g)=>u===g.findIndex(b=>b===m)));for(let d of f.items){if(!d.files)continue;c.start(`Building ${d.name}...`),d.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let u of d.files){let g=w.resolve(i.cwd,u.path);try{if(!(await z.stat(g)).isFile())continue;u.content=await z.readFile(g,"utf-8");}catch(b){console.error("Error reading file in registry build:",g,b);continue}}let m=B.safeParse(d);if(!m.success){q$1.error(`Invalid registry item found for ${a.info(d.name)}.`);continue}await z.writeFile(w.resolve(i.outputDir,`${m.data.name}.json`),JSON.stringify(m.data,null,2));}if(await z.copyFile(i.registryFile,w.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t.verbose){r(`The registry has ${a.info(f.items.length.toString())} items:`).succeed();for(let d of f.items){q$1.log(` - ${d.name} (${a.info(d.type)})`);for(let m of d.files??[])q$1.log(` - ${m.path}`);}}}catch(t){q$1.break(),s(t);}}async function mo(e,t,r){for(let i of e.items)if(i.files?.length)for(let o of i.files){let n=await ct(o.path,t,r);n.files=n.files?.filter(s=>s.path!==o.path),n.files&&i.files.push(...n.files),n.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(n.dependencies):n.dependencies);}return e}var wr=new Command().name("registry:mcp").description("starts the registry MCP server [EXPERIMENTAL]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{try{let e=new StdioServerTransport;await a$1.connect(e);}catch(e){q$1.break(),s(e);}});var xr={name:"shadcn",version:"2.6.0",description:"Add components to your apps.",publishConfig:{access:"public"},license:"MIT",author:{name:"shadcn",url:"https://twitter.com/shadcn"},repository:{type:"git",url:"https://github.com/shadcn/ui.git",directory:"packages/shadcn"},files:["dist"],keywords:["components","ui","tailwind","radix-ui","shadcn"],type:"module",exports:{".":{types:"./dist/index.d.ts",default:"./dist/index.js"},"./registry":{types:"./dist/registry/index.d.ts",default:"./dist/registry/index.js"},"./mcp":{types:"./dist/mcp/index.d.ts",default:"./dist/mcp/index.js"}},bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rimraf dist && rimraf components","start:dev":"cross-env REGISTRY_URL=http://localhost:4000/r node dist/index.js","start:prod":"cross-env REGISTRY_URL=https://ui.shadcn.com/r node dist/index.js",start:"node dist/index.js","format:write":'prettier --write "**/*.{ts,tsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,mdx}" --cache',release:"changeset version","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:next":"pnpm build && pnpm publish --no-git-checks --access public --tag next","pub:release":"pnpm build && pnpm publish --access public",test:"vitest run","test:dev":"REGISTRY_URL=http://localhost:4000/r vitest run"},dependencies:{"@antfu/ni":"^23.2.0","@babel/core":"^7.22.1","@babel/parser":"^7.22.6","@babel/plugin-transform-typescript":"^7.22.5","@modelcontextprotocol/sdk":"^1.10.2",commander:"^10.0.0",cosmiconfig:"^8.1.3",deepmerge:"^4.3.1",diff:"^5.1.0",execa:"^7.0.0","fast-glob":"^3.3.2","fs-extra":"^11.1.0","https-proxy-agent":"^6.2.0",kleur:"^4.1.5",msw:"^2.7.1","node-fetch":"^3.3.0",ora:"^6.1.2",postcss:"^8.4.24",prompts:"^2.4.2",recast:"^0.23.2","stringify-object":"^5.0.0","ts-morph":"^18.0.0","tsconfig-paths":"^4.2.0",zod:"^3.20.2","zod-to-json-schema":"^3.24.5"},devDependencies:{"@types/babel__core":"^7.20.1","@types/diff":"^5.0.3","@types/fs-extra":"^11.0.1","@types/prompts":"^2.4.2","@types/stringify-object":"^4.0.5",rimraf:"^6.0.1",tsup:"^6.6.3","type-fest":"^3.8.0",typescript:"^4.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function wo(){let e=new Command().name("shadcn").description("add components and dependencies to your project").version(xr.version,"-v, --version","display the version number");e.addCommand(Jt).addCommand(Zt).addCommand(nr).addCommand(mr).addCommand(sr).addCommand(ir),e.addCommand(yr).addCommand(wr),e.parse();}wo();
76
+ Before you can build the registry, you must create a valid ${a.info("components.json")} file by running the ${a.info("init")} command.`),q$1.break(),process.exit(1);}}var ur=[".tsx",".ts",".jsx",".js",".css"],gr=["lib/utils.ts"],no=[/^(react|react-dom|next)(\/.*)?$/,/^(node|jsr|npm):.*$/],so=new Project({compilerOptions:{}});function ao(e){if(no.some(t=>t.test(e)))return null;if(!e.startsWith("@")&&e.includes("/")&&(e=e.split("/")[0]),e.startsWith("@")){let t=e.split("/");t.length>2&&(e=t.slice(0,2).join("/"));}return e}async function ct(e,t,r,i=new Set){let o=w.resolve(t.resolvedPaths.cwd,e),n=w.relative(t.resolvedPaths.cwd,o);if(gr.includes(n))return {dependencies:[],files:[]};let s=w.extname(e);if(!ur.includes(s))return {dependencies:[],files:[]};if(i.has(n))return {dependencies:[],files:[]};if(i.add(n),!(await z.stat(o)).isFile())return {dependencies:[],files:[]};let c=await z.readFile(o,"utf-8"),f=await co(w.basename(o)),d=so.createSourceFile(f,c,{scriptKind:ScriptKind.TSX}),m=await loadConfig(t.resolvedPaths.cwd);if(m.resultType==="failed")return {dependencies:[],files:[]};let u=[],g=new Set,b$1=hr(e),h={path:n,type:b$1,target:""};u.push(h);let I=d.getImportDeclarations();for(let x of I){let P=x.getModuleSpecifierValue(),C=P.startsWith(".");if(!P.startsWith(`${r.aliasPrefix}/`)&&!C){let V=ao(P);V&&g.add(V);continue}let F=await b(P,m);if(C&&(F=w.resolve(w.dirname(o),P)),!F)continue;if(!w.extname(F))for(let V of ur){let ft=`${F}${V}`;try{await z.access(ft),F=ft;break}catch{continue}}let fe=w.relative(t.resolvedPaths.cwd,F);if(i.has(fe)||gr.includes(fe))continue;let _e=hr(P),lt={path:fe,type:_e,target:""};(_e==="registry:page"||_e==="registry:file")&&(lt.target=P),u.push(lt);let pe=await ct(fe,t,r,i);if(pe.files)for(let V of pe.files)i.has(V.path)||(i.add(V.path),u.push(V));pe.dependencies&&pe.dependencies.forEach(V=>g.add(V));}let T=Array.from(new Map(u.map(x=>[x.path,x])).values());return {dependencies:Array.from(g),files:T}}async function co(e){let t=await z.mkdtemp(w.join(tmpdir(),"shadcn-"));return w.join(t,e)}function hr(e){return e.includes("/ui/")?"registry:ui":e.includes("/lib/")?"registry:lib":e.includes("/hooks/")?"registry:hook":(e.includes("/components/"),"registry:component")}var fo=z$1.object({cwd:z$1.string(),registryFile:z$1.string(),outputDir:z$1.string(),verbose:z$1.boolean().optional().default(!1)}),yr=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 po({cwd:w.resolve(t.cwd),registryFile:e,outputDir:t.output,verbose:t.verbose});});async function po(e){try{let t=fo.parse(e),[{errors:r$1,resolvePaths:i,config:o},n$1]=await Promise.all([dr(t),n(t.cwd)]);(r$1[A]||!o||!n$1)&&(q$1.error(`A ${a.info("components.json")} file is required to build the registry. Run ${a.info("shadcn init")} to create one.`),q$1.break(),process.exit(1)),(r$1[X]||!i)&&(q$1.error(`We could not find a registry file at ${a.info(w.resolve(t.cwd,t.registryFile))}.`),q$1.break(),process.exit(1));let s=await z.readFile(i.registryFile,"utf-8"),a$1=C.safeParse(JSON.parse(s));a$1.success||(q$1.error(`Invalid registry file found at ${a.info(i.registryFile)}.`),q$1.break(),process.exit(1));let c=r("Building registry..."),f=await mo(a$1.data,o,n$1);for(let d of f.items)d.files=d.files?.filter((m,u,g)=>u===g.findIndex(b=>b.path===m.path)),d.dependencies&&(d.dependencies=d.dependencies.filter((m,u,g)=>u===g.findIndex(b=>b===m)));for(let d of f.items){if(!d.files)continue;c.start(`Building ${d.name}...`),d.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let u of d.files){let g=w.resolve(i.cwd,u.path);try{if(!(await z.stat(g)).isFile())continue;u.content=await z.readFile(g,"utf-8");}catch(b){console.error("Error reading file in registry build:",g,b);continue}}let m=B.safeParse(d);if(!m.success){q$1.error(`Invalid registry item found for ${a.info(d.name)}.`);continue}await z.writeFile(w.resolve(i.outputDir,`${m.data.name}.json`),JSON.stringify(m.data,null,2));}if(await z.copyFile(i.registryFile,w.resolve(i.outputDir,"registry.json")),c.succeed("Building registry."),t.verbose){r(`The registry has ${a.info(f.items.length.toString())} items:`).succeed();for(let d of f.items){q$1.log(` - ${d.name} (${a.info(d.type)})`);for(let m of d.files??[])q$1.log(` - ${m.path}`);}}}catch(t){q$1.break(),s(t);}}async function mo(e,t,r){for(let i of e.items)if(i.files?.length)for(let o of i.files){let n=await ct(o.path,t,r);n.files=n.files?.filter(s=>s.path!==o.path),n.files&&i.files.push(...n.files),n.dependencies&&(i.dependencies=i.dependencies?i.dependencies.concat(n.dependencies):n.dependencies);}return e}var wr=new Command().name("registry:mcp").description("starts the registry MCP server [EXPERIMENTAL]").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async()=>{try{let e=new StdioServerTransport;await a$1.connect(e);}catch(e){q$1.break(),s(e);}});var xr={name:"shadcn",version:"2.6.1",description:"Add components to your apps.",publishConfig:{access:"public"},license:"MIT",author:{name:"shadcn",url:"https://twitter.com/shadcn"},repository:{type:"git",url:"https://github.com/shadcn/ui.git",directory:"packages/shadcn"},files:["dist"],keywords:["components","ui","tailwind","radix-ui","shadcn"],type:"module",exports:{".":{types:"./dist/index.d.ts",default:"./dist/index.js"},"./registry":{types:"./dist/registry/index.d.ts",default:"./dist/registry/index.js"},"./mcp":{types:"./dist/mcp/index.d.ts",default:"./dist/mcp/index.js"}},bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rimraf dist && rimraf components","start:dev":"cross-env REGISTRY_URL=http://localhost:4000/r node dist/index.js","start:prod":"cross-env REGISTRY_URL=https://ui.shadcn.com/r node dist/index.js",start:"node dist/index.js","format:write":'prettier --write "**/*.{ts,tsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,mdx}" --cache',release:"changeset version","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:next":"pnpm build && pnpm publish --no-git-checks --access public --tag next","pub:release":"pnpm build && pnpm publish --access public",test:"vitest run","test:dev":"REGISTRY_URL=http://localhost:4000/r vitest run"},dependencies:{"@antfu/ni":"^23.2.0","@babel/core":"^7.22.1","@babel/parser":"^7.22.6","@babel/plugin-transform-typescript":"^7.22.5","@modelcontextprotocol/sdk":"^1.10.2",commander:"^10.0.0",cosmiconfig:"^8.1.3",deepmerge:"^4.3.1",diff:"^5.1.0",execa:"^7.0.0","fast-glob":"^3.3.2","fs-extra":"^11.1.0","https-proxy-agent":"^6.2.0",kleur:"^4.1.5",msw:"^2.7.1","node-fetch":"^3.3.0",ora:"^6.1.2",postcss:"^8.4.24",prompts:"^2.4.2",recast:"^0.23.2","stringify-object":"^5.0.0","ts-morph":"^18.0.0","tsconfig-paths":"^4.2.0",zod:"^3.20.2","zod-to-json-schema":"^3.24.5"},devDependencies:{"@types/babel__core":"^7.20.1","@types/diff":"^5.0.3","@types/fs-extra":"^11.0.1","@types/prompts":"^2.4.2","@types/stringify-object":"^4.0.5",rimraf:"^6.0.1",tsup:"^6.6.3","type-fest":"^3.8.0",typescript:"^4.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function wo(){let e=new Command().name("shadcn").description("add components and dependencies to your project").version(xr.version,"-v, --version","display the version number");e.addCommand(Jt).addCommand(Zt).addCommand(nr).addCommand(mr).addCommand(sr).addCommand(ir),e.addCommand(yr).addCommand(wr),e.parse();}wo();
77
77
  //# sourceMappingURL=out.js.map
78
78
  //# sourceMappingURL=index.js.map