@turbo/gen 2.5.4-canary.0 → 2.5.4

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.
Files changed (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -74,7 +74,7 @@ Please report this to https://github.com/szmarczak/http2-wrapper/`);y(_)}return}
74
74
  `:""}var C5=S5,R5={dump:C5};function yl(e,t){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+t+" instead, which is now safe by default.")}}var F5=je,T5=mg,O5=bg,k5=Dg,P5=xg,B5=dl,I5=$g.load,L5=$g.loadAll,N5=R5.dump,M5=rt,q5={binary:Tg,float:Ag,map:_g,null:Eg,pairs:kg,set:Pg,timestamp:Rg,bool:wg,int:vg,merge:Fg,omap:Og,seq:yg,str:gg},j5=yl("safeLoad","load"),H5=yl("safeLoadAll","loadAll"),$5=yl("safeDump","dump"),U5={Type:F5,Schema:T5,FAILSAFE_SCHEMA:O5,JSON_SCHEMA:k5,CORE_SCHEMA:P5,DEFAULT_SCHEMA:B5,load:I5,loadAll:L5,dump:N5,YAMLException:M5,types:q5,safeLoad:j5,safeLoadAll:H5,safeDump:$5},ey=U5;var aw=X(H_());var L={};JC(L,{bold:()=>TB,dimmed:()=>kB,error:()=>ct,grey:()=>PB,info:()=>FB,item:()=>BB,log:()=>dr,turboBlue:()=>mi,turboGradient:()=>RB,turboLoader:()=>Mh,turboRed:()=>iw,underline:()=>OB,warn:()=>qh,yellow:()=>sw});var ut=require("picocolors"),ew=X(SE()),tw=X(QE()),rw="#0099F7",nw="#F11712",CB="#FFFF00",Nh=e=>{let t=IB(e);return r=>`\x1B[38;5;${t}m${r}${(0,ut.reset)("")}`},RB=(0,tw.default)(rw,nw),mi=Nh(rw),iw=Nh(nw),sw=Nh(CB),Mh=e=>(0,ew.default)({text:e,spinner:{frames:[" ",mi("> "),mi(">> "),mi(">>>")]}}),FB=(...e)=>{dr(mi((0,ut.bold)(">>>")),e.join(" "))},TB=(...e)=>{dr((0,ut.bold)(e.join(" ")))},OB=(...e)=>{dr((0,ut.underline)(e.join(" ")))},kB=(...e)=>{dr((0,ut.dim)(e.join(" ")))},PB=(...e)=>{dr((0,ut.gray)(e.join(" ")))},BB=(...e)=>{dr(mi((0,ut.bold)(" \u2022")),e.join(" "))},dr=(...e)=>{console.log(...e)},qh=(...e)=>{console.error(sw((0,ut.bold)(">>>")),e.join(" "))},ct=(...e)=>{console.error(iw((0,ut.bold)(">>>")),e.join(" "))};function IB(e){let t=parseInt(e.slice(1),16),r=Math.floor(t/(256*256))%256,n=Math.floor(t/256)%256,i=t%256;return 16+36*Math.round(r/255*5)+6*Math.round(n/255*5)+Math.round(i/255*5)}var ow="{turbo.json,turbo.jsonc}";var jh={};function LB(e){try{if(Fs.default.existsSync(Ur.default.join(e,"pnpm-workspace.yaml")))return ey.load(Fs.default.readFileSync(Ur.default.join(e,"pnpm-workspace.yaml"),"utf8")).packages||[];let t=JSON.parse(Fs.default.readFileSync(Ur.default.join(e,"package.json"),"utf8"));if(t.workspaces){if("packages"in t.workspaces)return t.workspaces.packages||[];if(Array.isArray(t.workspaces))return t.workspaces}return[]}catch{return[]}}function Hh(e,t){var s;let r=cs(e,t),n=[],i=(s=t==null?void 0:t.cache)!=null?s:!0;if(i&&e&&e in jh)return jh[e];if(r){let a=LB(r).map(l=>`${l}/${ow}`),u=(0,aw.sync)([ow,...a],{cwd:r,onlyFiles:!0,followSymbolicLinks:!1,suppressErrors:!0}).map(l=>Ur.default.join(r,l)),c={};for(let l of u){let f=Ur.default.dirname(l);c[f]||(c[f]=[]),c[f].push(l)}for(let[l,f]of Object.entries(c)){if(f.length>1){let p=`Found both turbo.json and turbo.jsonc in the same directory: ${l}
75
75
  Please use either turbo.json or turbo.jsonc, but not both.`;throw ct(p),new Error(p)}let h=f[0];try{let p=Fs.default.readFileSync(h,"utf8"),y=Co.parse(p),_=Ur.default.dirname(h)===r;if(_){if("extends"in y)continue}else if(!("extends"in y))continue;n.push({config:y,turboConfigPath:h,workspacePath:Ur.default.dirname(h),isRootConfig:_})}catch(p){qh(p)}}}return i&&e&&(jh[e]=n),n}var FL=X(require("os")),TL=X(Bv());var Iv=X(require("fs-extra")),OL=[".DS_Store",".git",".gitattributes",".gitignore",".gitlab-ci.yml",".hg",".hgcheck",".hgignore",".idea",".npmignore",".travis.yml","LICENSE","Thumbs.db","docs","mkdocs.yml","npm-debug.log","yarn-debug.log","yarn-error.log","yarnrc.yml",".yarn"];function Bs(e){let t=Iv.default.readdirSync(e).filter(r=>!OL.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:t.length===0,conflicts:t}}var id=X(require("path")),sd=X(require("fs-extra")),od=X(require("picocolors"));function Wa(e){let t=id.default.resolve(e),r=id.default.basename(t),n=sd.default.existsSync(t),i=sd.default.lstatSync(t,{throwIfNoEntry:!1});if(i&&!i.isDirectory())return{valid:!1,root:t,projectName:r,error:`${od.default.dim(r)} is not a directory - please try a different location`};if(n){let{isEmpty:s,conflicts:o}=Bs(t);if(!s)return{valid:!1,root:t,projectName:r,error:`${od.default.dim(r)} (${t}) has ${o.length} conflicting ${o.length===1?"file":"files"} - please try a different location`}}return{valid:!0,root:t,projectName:r}}var nC=require("stream"),iC=require("util"),sC=require("path"),oC=require("os"),fo=require("fs"),em=X(kx()),xc=X(rC()),m9=(0,iC.promisify)(nC.Stream.pipeline);async function Dc(e){try{return(await xc.default.head(e)).statusCode===200}catch{return!1}}async function tm(e,t){let[,r,n,i,s,...o]=e.pathname.split("/"),a=t?t.replace(/^\//,""):o.join("/");if(i===void 0||i===""&&s===void 0)try{let c=await(0,xc.default)(`https://api.github.com/repos/${r}/${n}`),l=JSON.parse(c.body);return{username:r,name:n,branch:l.default_branch,filePath:a}}catch{return}let u=t?`${s}/${o.join("/")}`.replace(new RegExp(`/${a}|/$`),""):s;if(r&&n&&u&&i==="tree")return{username:r,name:n,branch:u,filePath:a}}function rm({username:e,name:t,branch:r,filePath:n}){let i=`https://api.github.com/repos/${e}/${t}/contents`,s=`${n?`/${n}`:""}/package.json`;return Dc(`${i+s}?ref=${r}`)}function nm(e){try{let t=new URL(e);return Dc(t.href)}catch{return Dc(`https://api.github.com/repos/vercel/turborepo/contents/examples/${encodeURIComponent(e)}`)}}async function aC(e,t){let r=(0,sC.join)((0,oC.tmpdir)(),`${t}.temp-${Date.now()}`);return await m9(xc.default.stream(e),(0,fo.createWriteStream)(r)),r}async function im(e,{username:t,name:r,branch:n,filePath:i}){let s=await aC(`https://codeload.github.com/${t}/${r}/tar.gz/${n}`,"turbo-ct-example"),o=null;await(0,em.x)({file:s,cwd:e,strip:i?i.split("/").length+1:1,filter:a=>{if(o===null){let u=a.split("/");o=u.length?u[0]:null}return a.startsWith(`${o}${i?`/${i}/`:"/"}`)}}),await fo.promises.unlink(s)}async function sm(e,t){let r=await aC("https://codeload.github.com/vercel/turborepo/tar.gz/main","turbo-ct-example"),n=null;await(0,em.x)({file:r,cwd:e,strip:2+t.split("/").length,filter:i=>{if(n===null){let s=i.split("/");n=s.length?s[0]:null}return i.includes(`${n}/examples/${t}/`)}}),await fo.promises.unlink(r)}var om=X(require("fs-extra"));async function am(e){try{return await om.default.access(e,om.default.constants.W_OK),!0}catch{return!1}}var ts=X(require("path")),um=X(pC()),Nn=X(require("picocolors")),Sc=X(require("fs-extra"));function b9(e){return typeof e=="object"&&e!==null&&typeof e.message=="string"}var Cc=class extends Error{};async function cm({appPath:e,example:t,isDefaultExample:r,examplePath:n}){let i,s;if(r)i={username:"vercel",name:"turborepo",branch:"main",filePath:"examples/basic"};else{try{s=new URL(t)}catch(m){m.code!=="ERR_INVALID_URL"&&(ct(m),process.exit(1))}s?(s.origin!=="https://github.com"&&(ct(`Invalid URL: ${Nn.default.red(`"${t}"`)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`),process.exit(1)),i=await tm(s,n),i||(ct(`Unable to fetch repository information from: ${Nn.default.red(`"${t}"`)}. Please fix the URL and try again.`),process.exit(1)),await rm(i)||(ct(`Could not locate the repository for ${Nn.default.red(`"${t}"`)}. Please check that the repository exists and try again.`),process.exit(1))):await nm(t)||(ct(`Could not locate an example named ${Nn.default.red(`"${t}"`)}. It could be due to the following:
76
76
  `,`1. Your spelling of example ${Nn.default.red(`"${t}"`)} might be incorrect.
77
- `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=ts.default.resolve(e);await am(ts.default.dirname(o))||(ct("The application path is not writable, please check folder permissions and try again."),ct("It is likely you do not have write permissions for this folder."),process.exit(1));let a=ts.default.basename(o);try{await Sc.default.mkdir(o,{recursive:!0})}catch(m){ct("Unable to create project directory"),ct(m),process.exit(1)}let{isEmpty:u,conflicts:c}=Bs(o);u||(ct(`${Nn.default.dim(o)} has ${c.length} conflicting ${c.length===1?"file":"files"} - please try a different location`),process.exit(1));let l=process.cwd();process.chdir(o),dr();let f=Mh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,um.default)(()=>im(o,i),{retries:3})):(f.start(),await(0,um.default)(()=>sm(o,t),{retries:3}))}catch(m){throw new Cc(b9(m)?m.message:String(m))}finally{f.stop()}let h=ts.default.join(o,"package.json"),p=Sc.default.existsSync(h),y=[];if(p){let m;try{m=Sc.default.readJsonSync(h)}catch{}m&&y.push(...Object.keys(m.scripts||{}))}let _=e;return ts.default.join(l,a)===e&&(_=a),{cdPath:_,hasPackageJson:p,availableScripts:y,repoInfo:i}}function lm(e,t={to:"camel"}){switch(t.to){case"camel":return e.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var UC=require("proxy-agent");var ho={name:"@turbo/gen",version:"2.5.4-canary.0",description:"Extend a Turborepo",homepage:"https://turborepo.com",license:"MIT",repository:{type:"git",url:"https://github.com/vercel/turborepo",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turborepo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit"},dependencies:{"@turbo/workspaces":"workspace:*",commander:"^10.0.0","fs-extra":"^10.1.0",inquirer:"^8.2.4",minimatch:"^9.0.0","node-plop":"^0.26.3",picocolors:"1.0.1","proxy-agent":"^6.5.0","ts-node":"^10.9.2","update-check":"^1.5.4","validate-npm-package-name":"^5.0.0"},devDependencies:{"@jest/globals":"^29.7.0","@turbo/eslint-config":"workspace:*","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"^9.0.13","@types/inquirer":"^8.2.5","@types/node":"^18.17.2","@types/validate-npm-package-name":"^4.0.0",jest:"^29.7.0","ts-jest":"^29.2.5",tsup:"^6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var fm=X(require("picocolors")),mC=X(require("update-check"));var w9=(0,mC.default)(ho).catch(()=>null);async function hm(){try{let e=await w9;e!=null&&e.latest&&(L.log(),L.log(fm.default.yellow(fm.default.bold(`A new version of \`${ho.name}\` is available!`))),L.log()),process.exit()}catch{}}var gC=require("@turbo/workspaces");async function Rc({root:e}){let t=e||process.cwd(),r=cs(t);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,gC.getWorkspaceDetails)({root:r})}catch{L.error(`Unable to determine workspace details. Make sure "${t}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var Tr=X(require("path")),Tc=X(require("fs-extra")),Fc=X(require("node-plop")),yC=require("ts-node"),_C=require("inquirer");var $e=class extends Error{constructor(r,n){var i;super(r);this.name="GenerateError",this.type=(i=n==null?void 0:n.type)!=null?i:"unknown",Error.captureStackTrace(this,$e)}};var bC=["ts","js","cjs"],v9=Tr.default.join("turbo","generators"),EC=bC.map(e=>Tr.default.join(v9,`config.${e}`)),A9=[...EC,...bC.map(e=>Tr.default.join(`plopfile.${e}`))];function wC({project:e,configPath:t}){(0,yC.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=x9({project:e}),n;if(t){if(!Tc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,Fc.default)(t,{destBasePath:t,force:!1})}catch(i){L.error(i)}}else{for(let i of A9){let s=Tr.default.join(e.paths.root,i);if(Tc.default.existsSync(s))try{n=(0,Fc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,Fc.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){L.error(s)}}),n}function dm({project:e,configPath:t}){let r=wC({project:e,configPath:t});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=e.workspaceData.workspaces.find(l=>{if(u.basePath===e.paths.root)return!1;let f=u.basePath.split(Tr.default.sep);return f.pop(),f.pop(),Tr.default.join("/",...f)===l.paths.root});c?(c.name in s||(s[c.name]=[]),s[c.name].push(u)):("root"in s||(s.root=[]),s.root.push(u))});let o=[];return Object.keys(s).forEach(a=>{o.push(new _C.Separator(a)),o.push(...s[a])}),o}function D9({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?us({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=Hh(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function x9({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of EC)Tc.default.existsSync(Tr.default.join(r.paths.root,n))&&t.push({config:Tr.default.join(r.paths.root,n),root:r.paths.root})}),t}async function vC({project:e,generator:t,bypassArgs:r,configPath:n}){let i=wC({project:e,configPath:n});if(!i)throw new $e("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(t);if(!s)throw new $e(`Generator ${t} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...D9({project:e,generator:s})},{onComment:u=>{L.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?L.error(`Error - ${u.message}`):L.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new $e(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(L.info("Changes made:"),a.changes.forEach(u=>{u.path&&L.item(`${u.path} (${u.type})`)}))}var Mn=require("inquirer");async function AC({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Mn.Separator)&&n.name===t))return{selectedGenerator:t};L.warn(`Generator "${t}" not found`),L.log()}return await(0,Mn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Mn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function DC(){return(0,Mn.prompt)({type:"list",name:"answer",message:"Should the generator config be created with TS or JS?",default:"ts",choices:[{name:"JavaScript",value:"js"},{name:"TypeScript",value:"ts"}]})}async function xC({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var pm=X(require("path")),mm=X(require("fs-extra"));async function SC({project:e,template:t}){let r=pm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await mm.default.pathExists(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await mm.default.copy(pm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function gm({generator:e,project:t,opts:r}){let n=!1,i=dm({project:t,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await xC({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await DC();try{await SC({project:t,template:a})}catch(u){throw u instanceof $e||L.error("Failed to create generator config"),u}if(L.log(),L.info("Generator config successfully created!"),L.info("Loading generator config..."),L.log(),i=dm({project:t,configPath:r.config}),!i.length){L.error("Error loading generator");return}}else{L.log(),L.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:s}=await AC({generators:i,generator:e});try{await vC({project:t,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof $e)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new $e(a,{type:"plop_error_running_generator"})}finally{n&&(L.log(),L.info("Congrats! You just ran your first Turborepo generator"),L.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators"))}L.log(),L.bold(L.turboGradient(">>> Success!"))}var Em=X(require("path")),Bc=X(require("fs-extra")),NC=X(require("picocolors"));var po=X(require("path")),TC=X(require("fs-extra")),Bt=require("inquirer"),OC=require("minimatch"),bm=X(require("validate-npm-package-name"));var ym=X(require("path"));var CC=X(require("path"));function RC({project:e}){let r=e.workspaceData.workspaces.map(i=>CC.default.relative(e.paths.root,i.paths.root)),n=new Set;return e.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function _m({project:e,workspace:t}){return ym.default.relative(e.paths.root,t.paths.root).split(ym.default.sep)[0]}function Oc({project:e}){let t=RC({project:e}),r=t.includes("apps"),n=t.includes("packages"),i={},s=[];return e.workspaceData.workspaces.forEach(o=>{let a=_m({project:e,workspace:o});a!=="apps"&&s.push(o),a in i||(i[a]=[]),i[a].push(o)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:i,nonAppWorkspaces:s}}var FC=require("inquirer");function kc({project:e,type:t,showAllDependencies:r}){let n=Oc({project:e}),i=[],s=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=_m({project:e,workspace:a});u!==o&&i.push(new FC.Separator(u)),o=u,i.push(a)}),i}async function kC({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,bm.default)(e||"");return e&&n?{answer:e}:(0,Bt.prompt)({type:"input",name:"answer",default:t,validate:i=>{let{validForNewPackages:s}=(0,bm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function PC({override:e,message:t}){return e?{answer:e}:(0,Bt.prompt)({type:"list",name:"answer",message:t!=null?t:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function BC({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Wa(r);if(u)return{absolute:c,relative:po.default.relative(n.paths.root,c)}}let s,o=Oc({project:n});e==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:e==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,Bt.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:s?po.default.relative(n.paths.root,s):void 0,validate:u=>{let c=po.default.join(n.paths.root,u),{valid:l,error:f}=Wa(c),h=n.workspaceData.globs.some(p=>(0,OC.minimatch)(u,p));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:po.default.join(n.paths.root,a),relative:a}}async function IC({override:e,workspaces:t,workspaceName:r}){if(e){let i=t.find(s=>s instanceof Bt.Separator?!1:s.name===e);if(i)return{answer:i};L.warn(`Workspace "${e}" not found`),L.log()}return await(0,Bt.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(i=>i instanceof Bt.Separator?i:{name:` ${i.name}`,value:i})})}async function LC({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await C9({message:`Add workspace dependencies to "${e}"?`});if(!s)return i;let{answer:o}=await(0,Bt.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${e}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=kc({project:t,type:"package",showAllDependencies:n}),u=r?TC.default.readJsonSync(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,Bt.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${e}?`,loop:!1,choices:a.map(h=>h instanceof Bt.Separator?h:{name:` ${h.name}`,value:h.name})}),f=(u==null?void 0:u[c])||{};if(Object.keys(f).length){let h=new Set(Object.keys(f));l.forEach(p=>{h.has(p)||(f[p]=t.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,p)=>({...h,[p]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function C9({message:e}){return(0,Bt.prompt)({type:"confirm",name:"answer",message:e})}async function Pc({project:e,opts:t}){var u;let r,n=t.method==="copy"&&t.copy.type==="external"?((u=t.examplePath)==null?void 0:u.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:i}=await PC({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await kC({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await IC({override:t.copy.source,workspaces:kc({project:e,type:i}),workspaceName:s});r=c}let o=await BC({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await LC({workspaceName:s,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function wm({project:e,opts:t}){let{name:r,location:n,dependencies:i}=await Pc({project:e,opts:t}),s={name:r,version:"0.0.0",private:!0,scripts:{dev:"echo 'Add dev script here'",build:"echo 'Add build script here'",test:"echo 'Add test script here'",lint:"echo 'Add lint script here'"}};Object.keys(i).forEach(o=>{let a=i[o];a&&Object.keys(a).length>0&&(s[o]=a)}),Bc.default.mkdirSync(n.absolute,{recursive:!0}),Bc.default.writeFileSync(Em.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),Bc.default.writeFileSync(Em.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${NC.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var vm=X(require("path")),un=X(require("fs-extra")),MC=X(require("picocolors"));async function Am({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Pc({project:e,opts:t}),a=vm.default.join(i.absolute,"package.json");if(t.copy.type==="external"){L.log(),L.warn("Some manual modifications may be required."),L.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await cm({appPath:i.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(un.default.existsSync(a)){if((await un.default.readJSON(a)).workspaces)throw new Error("New workspace root detected - unexpected 'workspaces' field in package.json")}else throw new Error("New workspace is missing a package.json file");if(un.default.existsSync(vm.default.join(i.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(c){let l="UNKNOWN_ERROR";c instanceof Error&&(l=c.message),L.error(l),await un.default.rm(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=L.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await un.default.copy(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await un.default.readJSON(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await un.default.writeJSON(a,u,{spaces:2}),L.log(),L.log(`${MC.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function F9(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",i=typeof t=="string"?t:"",s=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function mo(e){let t=await Rc(e),r=F9(e);L.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?L.info(`Copy a remote workspace from ${r.copy.source}`):L.info(`Copy an existing workspace from "${t.name}"`),L.log(),await Am(n)):(L.info(`Add an empty workspace to "${t.name}"`),L.log(),await wm(n))}async function go(e,t){let r=await Rc(t);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await gm({generator:e,project:r,opts:t})}function qC(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=lm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){L.error("Error parsing arguments",t),process.exit(1)}}async function Dm(e,t){var r;if(e==="workspace"){let n=qC(t.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let i=!1,s=n.empty||!0;n.copy===""||n.copy===!0?(i=!0,s=!1):n.copy&&n.copy.length>0&&(i=n.copy,s=!1),n.copy=i,n.empty=s,await mo(n)}else if(e==="run"){let n=qC(t.json),{generatorName:i,...s}=n;await go(i,s)}else L.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var GC=new UC.ProxyAgent;jC.default.globalAgent=GC;HC.default.globalAgent=GC;var yo=new Ue.Command;yo.name($C.default.bold(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(ho.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);yo.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new Ue.Argument("[generator-name]","The name of the generator to run")).addOption(new Ue.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new Ue.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new Ue.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(go);yo.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new Ue.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new Ue.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new Ue.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
77
+ `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=ts.default.resolve(e);await am(ts.default.dirname(o))||(ct("The application path is not writable, please check folder permissions and try again."),ct("It is likely you do not have write permissions for this folder."),process.exit(1));let a=ts.default.basename(o);try{await Sc.default.mkdir(o,{recursive:!0})}catch(m){ct("Unable to create project directory"),ct(m),process.exit(1)}let{isEmpty:u,conflicts:c}=Bs(o);u||(ct(`${Nn.default.dim(o)} has ${c.length} conflicting ${c.length===1?"file":"files"} - please try a different location`),process.exit(1));let l=process.cwd();process.chdir(o),dr();let f=Mh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,um.default)(()=>im(o,i),{retries:3})):(f.start(),await(0,um.default)(()=>sm(o,t),{retries:3}))}catch(m){throw new Cc(b9(m)?m.message:String(m))}finally{f.stop()}let h=ts.default.join(o,"package.json"),p=Sc.default.existsSync(h),y=[];if(p){let m;try{m=Sc.default.readJsonSync(h)}catch{}m&&y.push(...Object.keys(m.scripts||{}))}let _=e;return ts.default.join(l,a)===e&&(_=a),{cdPath:_,hasPackageJson:p,availableScripts:y,repoInfo:i}}function lm(e,t={to:"camel"}){switch(t.to){case"camel":return e.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var UC=require("proxy-agent");var ho={name:"@turbo/gen",version:"2.5.4",description:"Extend a Turborepo",homepage:"https://turborepo.com",license:"MIT",repository:{type:"git",url:"https://github.com/vercel/turborepo",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turborepo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit"},dependencies:{"@turbo/workspaces":"workspace:*",commander:"^10.0.0","fs-extra":"^10.1.0",inquirer:"^8.2.4",minimatch:"^9.0.0","node-plop":"^0.26.3",picocolors:"1.0.1","proxy-agent":"^6.5.0","ts-node":"^10.9.2","update-check":"^1.5.4","validate-npm-package-name":"^5.0.0"},devDependencies:{"@jest/globals":"^29.7.0","@turbo/eslint-config":"workspace:*","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"^9.0.13","@types/inquirer":"^8.2.5","@types/node":"^18.17.2","@types/validate-npm-package-name":"^4.0.0",jest:"^29.7.0","ts-jest":"^29.2.5",tsup:"^6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var fm=X(require("picocolors")),mC=X(require("update-check"));var w9=(0,mC.default)(ho).catch(()=>null);async function hm(){try{let e=await w9;e!=null&&e.latest&&(L.log(),L.log(fm.default.yellow(fm.default.bold(`A new version of \`${ho.name}\` is available!`))),L.log()),process.exit()}catch{}}var gC=require("@turbo/workspaces");async function Rc({root:e}){let t=e||process.cwd(),r=cs(t);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,gC.getWorkspaceDetails)({root:r})}catch{L.error(`Unable to determine workspace details. Make sure "${t}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var Tr=X(require("path")),Tc=X(require("fs-extra")),Fc=X(require("node-plop")),yC=require("ts-node"),_C=require("inquirer");var $e=class extends Error{constructor(r,n){var i;super(r);this.name="GenerateError",this.type=(i=n==null?void 0:n.type)!=null?i:"unknown",Error.captureStackTrace(this,$e)}};var bC=["ts","js","cjs"],v9=Tr.default.join("turbo","generators"),EC=bC.map(e=>Tr.default.join(v9,`config.${e}`)),A9=[...EC,...bC.map(e=>Tr.default.join(`plopfile.${e}`))];function wC({project:e,configPath:t}){(0,yC.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=x9({project:e}),n;if(t){if(!Tc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,Fc.default)(t,{destBasePath:t,force:!1})}catch(i){L.error(i)}}else{for(let i of A9){let s=Tr.default.join(e.paths.root,i);if(Tc.default.existsSync(s))try{n=(0,Fc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,Fc.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){L.error(s)}}),n}function dm({project:e,configPath:t}){let r=wC({project:e,configPath:t});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=e.workspaceData.workspaces.find(l=>{if(u.basePath===e.paths.root)return!1;let f=u.basePath.split(Tr.default.sep);return f.pop(),f.pop(),Tr.default.join("/",...f)===l.paths.root});c?(c.name in s||(s[c.name]=[]),s[c.name].push(u)):("root"in s||(s.root=[]),s.root.push(u))});let o=[];return Object.keys(s).forEach(a=>{o.push(new _C.Separator(a)),o.push(...s[a])}),o}function D9({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?us({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=Hh(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function x9({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of EC)Tc.default.existsSync(Tr.default.join(r.paths.root,n))&&t.push({config:Tr.default.join(r.paths.root,n),root:r.paths.root})}),t}async function vC({project:e,generator:t,bypassArgs:r,configPath:n}){let i=wC({project:e,configPath:n});if(!i)throw new $e("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(t);if(!s)throw new $e(`Generator ${t} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...D9({project:e,generator:s})},{onComment:u=>{L.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?L.error(`Error - ${u.message}`):L.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new $e(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(L.info("Changes made:"),a.changes.forEach(u=>{u.path&&L.item(`${u.path} (${u.type})`)}))}var Mn=require("inquirer");async function AC({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Mn.Separator)&&n.name===t))return{selectedGenerator:t};L.warn(`Generator "${t}" not found`),L.log()}return await(0,Mn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Mn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function DC(){return(0,Mn.prompt)({type:"list",name:"answer",message:"Should the generator config be created with TS or JS?",default:"ts",choices:[{name:"JavaScript",value:"js"},{name:"TypeScript",value:"ts"}]})}async function xC({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var pm=X(require("path")),mm=X(require("fs-extra"));async function SC({project:e,template:t}){let r=pm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await mm.default.pathExists(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await mm.default.copy(pm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function gm({generator:e,project:t,opts:r}){let n=!1,i=dm({project:t,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await xC({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await DC();try{await SC({project:t,template:a})}catch(u){throw u instanceof $e||L.error("Failed to create generator config"),u}if(L.log(),L.info("Generator config successfully created!"),L.info("Loading generator config..."),L.log(),i=dm({project:t,configPath:r.config}),!i.length){L.error("Error loading generator");return}}else{L.log(),L.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:s}=await AC({generators:i,generator:e});try{await vC({project:t,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof $e)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new $e(a,{type:"plop_error_running_generator"})}finally{n&&(L.log(),L.info("Congrats! You just ran your first Turborepo generator"),L.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators"))}L.log(),L.bold(L.turboGradient(">>> Success!"))}var Em=X(require("path")),Bc=X(require("fs-extra")),NC=X(require("picocolors"));var po=X(require("path")),TC=X(require("fs-extra")),Bt=require("inquirer"),OC=require("minimatch"),bm=X(require("validate-npm-package-name"));var ym=X(require("path"));var CC=X(require("path"));function RC({project:e}){let r=e.workspaceData.workspaces.map(i=>CC.default.relative(e.paths.root,i.paths.root)),n=new Set;return e.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function _m({project:e,workspace:t}){return ym.default.relative(e.paths.root,t.paths.root).split(ym.default.sep)[0]}function Oc({project:e}){let t=RC({project:e}),r=t.includes("apps"),n=t.includes("packages"),i={},s=[];return e.workspaceData.workspaces.forEach(o=>{let a=_m({project:e,workspace:o});a!=="apps"&&s.push(o),a in i||(i[a]=[]),i[a].push(o)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:i,nonAppWorkspaces:s}}var FC=require("inquirer");function kc({project:e,type:t,showAllDependencies:r}){let n=Oc({project:e}),i=[],s=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=_m({project:e,workspace:a});u!==o&&i.push(new FC.Separator(u)),o=u,i.push(a)}),i}async function kC({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,bm.default)(e||"");return e&&n?{answer:e}:(0,Bt.prompt)({type:"input",name:"answer",default:t,validate:i=>{let{validForNewPackages:s}=(0,bm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function PC({override:e,message:t}){return e?{answer:e}:(0,Bt.prompt)({type:"list",name:"answer",message:t!=null?t:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function BC({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Wa(r);if(u)return{absolute:c,relative:po.default.relative(n.paths.root,c)}}let s,o=Oc({project:n});e==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:e==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,Bt.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:s?po.default.relative(n.paths.root,s):void 0,validate:u=>{let c=po.default.join(n.paths.root,u),{valid:l,error:f}=Wa(c),h=n.workspaceData.globs.some(p=>(0,OC.minimatch)(u,p));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:po.default.join(n.paths.root,a),relative:a}}async function IC({override:e,workspaces:t,workspaceName:r}){if(e){let i=t.find(s=>s instanceof Bt.Separator?!1:s.name===e);if(i)return{answer:i};L.warn(`Workspace "${e}" not found`),L.log()}return await(0,Bt.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(i=>i instanceof Bt.Separator?i:{name:` ${i.name}`,value:i})})}async function LC({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await C9({message:`Add workspace dependencies to "${e}"?`});if(!s)return i;let{answer:o}=await(0,Bt.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${e}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=kc({project:t,type:"package",showAllDependencies:n}),u=r?TC.default.readJsonSync(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,Bt.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${e}?`,loop:!1,choices:a.map(h=>h instanceof Bt.Separator?h:{name:` ${h.name}`,value:h.name})}),f=(u==null?void 0:u[c])||{};if(Object.keys(f).length){let h=new Set(Object.keys(f));l.forEach(p=>{h.has(p)||(f[p]=t.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,p)=>({...h,[p]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function C9({message:e}){return(0,Bt.prompt)({type:"confirm",name:"answer",message:e})}async function Pc({project:e,opts:t}){var u;let r,n=t.method==="copy"&&t.copy.type==="external"?((u=t.examplePath)==null?void 0:u.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:i}=await PC({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await kC({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await IC({override:t.copy.source,workspaces:kc({project:e,type:i}),workspaceName:s});r=c}let o=await BC({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await LC({workspaceName:s,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function wm({project:e,opts:t}){let{name:r,location:n,dependencies:i}=await Pc({project:e,opts:t}),s={name:r,version:"0.0.0",private:!0,scripts:{dev:"echo 'Add dev script here'",build:"echo 'Add build script here'",test:"echo 'Add test script here'",lint:"echo 'Add lint script here'"}};Object.keys(i).forEach(o=>{let a=i[o];a&&Object.keys(a).length>0&&(s[o]=a)}),Bc.default.mkdirSync(n.absolute,{recursive:!0}),Bc.default.writeFileSync(Em.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),Bc.default.writeFileSync(Em.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${NC.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var vm=X(require("path")),un=X(require("fs-extra")),MC=X(require("picocolors"));async function Am({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Pc({project:e,opts:t}),a=vm.default.join(i.absolute,"package.json");if(t.copy.type==="external"){L.log(),L.warn("Some manual modifications may be required."),L.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await cm({appPath:i.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(un.default.existsSync(a)){if((await un.default.readJSON(a)).workspaces)throw new Error("New workspace root detected - unexpected 'workspaces' field in package.json")}else throw new Error("New workspace is missing a package.json file");if(un.default.existsSync(vm.default.join(i.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(c){let l="UNKNOWN_ERROR";c instanceof Error&&(l=c.message),L.error(l),await un.default.rm(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=L.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await un.default.copy(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await un.default.readJSON(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await un.default.writeJSON(a,u,{spaces:2}),L.log(),L.log(`${MC.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function F9(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",i=typeof t=="string"?t:"",s=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function mo(e){let t=await Rc(e),r=F9(e);L.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?L.info(`Copy a remote workspace from ${r.copy.source}`):L.info(`Copy an existing workspace from "${t.name}"`),L.log(),await Am(n)):(L.info(`Add an empty workspace to "${t.name}"`),L.log(),await wm(n))}async function go(e,t){let r=await Rc(t);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await gm({generator:e,project:r,opts:t})}function qC(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=lm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){L.error("Error parsing arguments",t),process.exit(1)}}async function Dm(e,t){var r;if(e==="workspace"){let n=qC(t.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let i=!1,s=n.empty||!0;n.copy===""||n.copy===!0?(i=!0,s=!1):n.copy&&n.copy.length>0&&(i=n.copy,s=!1),n.copy=i,n.empty=s,await mo(n)}else if(e==="run"){let n=qC(t.json),{generatorName:i,...s}=n;await go(i,s)}else L.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var GC=new UC.ProxyAgent;jC.default.globalAgent=GC;HC.default.globalAgent=GC;var yo=new Ue.Command;yo.name($C.default.bold(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(ho.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);yo.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new Ue.Argument("[generator-name]","The name of the generator to run")).addOption(new Ue.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new Ue.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new Ue.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(go);yo.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new Ue.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new Ue.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new Ue.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
78
78
  within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
79
79
  `).conflicts("empty")).addOption(new Ue.Option("-d, --destination <dir>","Where the new workspace should be created")).addOption(new Ue.Option("-t, --type <type>","The type of workspace to create").choices(["app","package"])).addOption(new Ue.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new Ue.Option("-p, --example-path <path-to-example>",`In a rare case, your GitHub URL might contain a branch name with
80
80
  a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbo/gen",
3
- "version": "2.5.4-canary.0",
3
+ "version": "2.5.4",
4
4
  "description": "Extend a Turborepo",
5
5
  "homepage": "https://turborepo.com",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "ts-node": "^10.9.2",
26
26
  "update-check": "^1.5.4",
27
27
  "validate-npm-package-name": "^5.0.0",
28
- "@turbo/workspaces": "2.5.4-canary.0"
28
+ "@turbo/workspaces": "2.5.4"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@jest/globals": "^29.7.0",
@@ -37,9 +37,9 @@
37
37
  "ts-jest": "^29.2.5",
38
38
  "tsup": "^6.7.0",
39
39
  "typescript": "5.5.4",
40
+ "@turbo/eslint-config": "0.0.0",
40
41
  "@turbo/test-utils": "0.0.0",
41
42
  "@turbo/tsconfig": "0.0.0",
42
- "@turbo/eslint-config": "0.0.0",
43
43
  "@turbo/utils": "0.0.0"
44
44
  },
45
45
  "files": [