@turbo/gen 2.7.4-canary.2 → 2.7.4-canary.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -114,7 +114,7 @@ ${s}`;break;case"retry":eO(s)&&(n[i]=s);break;case"id":tO(s)&&(n[i]=s);break;cas
|
|
|
114
114
|
Please use either turbo.json or turbo.jsonc, but not both.`;throw mt(d),new Error(d)}let h=l[0];try{let d=Lu.default.readFileSync(h,"utf8"),f=Ml.parse(d),g=WA.default.dirname(h)===r;if(g){if("extends"in f)continue}else if(!("extends"in f))continue;n.push({config:f,turboConfigPath:h,workspacePath:WA.default.dirname(h),isRootConfig:g})}catch(d){po(d)}}}return A&&e&&(kQ[e]=n),n}var Z6=ue(require("os")),K6=ue(U2());var _2=ue(require("fs-extra")),X6=[".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 Ou(e){let t=_2.default.readdirSync(e).filter(r=>!X6.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:t.length===0,conflicts:t}}var jQ=ue(require("path")),zQ=ue(require("fs-extra")),ZQ=ue(require("picocolors"));function $h(e){let t=jQ.default.resolve(e),r=jQ.default.basename(t),n=zQ.default.existsSync(t),A=zQ.default.lstatSync(t,{throwIfNoEntry:!1});if(A&&!A.isDirectory())return{valid:!1,root:t,projectName:r,error:`${ZQ.default.dim(r)} is not a directory - please try a different location`};if(n){let{isEmpty:i,conflicts:s}=Ou(t);if(!i)return{valid:!1,root:t,projectName:r,error:`${ZQ.default.dim(r)} (${t}) has ${s.length} conflicting ${s.length===1?"file":"files"} - please try a different location`}}return{valid:!0,root:t,projectName:r}}var BO=require("stream"),QO=require("stream/promises"),IO=require("zlib"),Wn=require("fs"),EC=require("fs/promises"),$t=require("path"),pO=require("os"),gC=require("child_process"),CC=ue(Tv()),mO=ue(CO());var gue=1e4,yO=12e4;function wO(e){return new URL(e).protocol==="https:"?process.env.https_proxy||process.env.HTTPS_PROXY||process.env.http_proxy||process.env.HTTP_PROXY:process.env.http_proxy||process.env.HTTP_PROXY}var hC,dO;function DO(e){return hC&&dO===e||(dO=e,hC=new mO.ProxyAgent(e)),hC}async function rw(e,t={},r=gue){let n=new AbortController,A=setTimeout(()=>{n.abort()},r);try{let i=wO(e),s=i?DO(i):void 0;return await fetch(e,{...t,signal:n.signal,dispatcher:s})}finally{clearTimeout(A)}}async function fC(e){try{return(await rw(e,{method:"HEAD"})).ok}catch{return!1}}async function nw(e,t){let[,r,n,A,i,...s]=e.pathname.split("/"),o=t?t.replace(/^\//,""):s.join("/");if(A===void 0||A===""&&i===void 0)try{let u=await rw(`https://api.github.com/repos/${r}/${n}`);if(!u.ok)return;let c=await u.json();return{username:r,name:n,branch:c.default_branch,filePath:o}}catch{return}let a=t?`${i}/${s.join("/")}`.replace(new RegExp(`/${o}|/$`),""):i;if(r&&n&&a&&A==="tree")return{username:r,name:n,branch:a,filePath:o}}function Aw({username:e,name:t,branch:r,filePath:n}){let A=`https://api.github.com/repos/${e}/${t}/contents`,i=`${n?`/${n}`:""}/package.json`;return fC(`${A+i}?ref=${r}`)}function iw(e){try{let t=new URL(e);return fC(t.href)}catch{return fC(`https://api.github.com/repos/vercel/turborepo/contents/examples/${encodeURIComponent(e)}`)}}function fue(e,t,r){if(t.includes("\0"))return!1;let A=t.replace(/\\/g,"/").normalize("NFC"),i=r!=null?r:(0,$t.resolve)(e),s=(0,$t.resolve)(i,A);return!(0,$t.relative)(i,s).startsWith("..")&&(0,$t.resolve)(s)===s}function Eue(e){return e==="SymbolicLink"||e==="Link"}async function Cue({url:e,root:t,strip:r,filter:n}){let A=new AbortController,i=setTimeout(()=>{A.abort()},yO),s=[],o=(0,$t.resolve)(t),a=new Set;try{let u=wO(e),c=u?DO(u):void 0,l=await fetch(e,{signal:A.signal,dispatcher:c});if(!l.ok||!l.body)throw new Error(`Failed to download: ${l.status}`);let h=BO.Readable.fromWeb(l.body),d=null,f=[],g=new CC.Parse({filter:p=>{if(d===null){let Q=p.split("/");d=Q.length?Q[0]:null}return n(p,d)},onentry:p=>{let w=p.path.split("/").slice(r).join("/");if(!w){p.resume();return}if(!fue(t,w,o)){mt(`Blocked path traversal attempt: ${p.path}`),p.resume();return}if(p.type&&Eue(p.type)){po(`Blocked symlink: ${p.path}`),p.resume();return}let S=(0,$t.resolve)(o,w);if(p.type==="Directory")a.has(S)||((0,Wn.mkdirSync)(S,{recursive:!0}),a.add(S)),p.resume();else if(p.type==="File"){let D=(0,$t.dirname)(S);a.has(D)||((0,Wn.mkdirSync)(D,{recursive:!0}),a.add(D));let b=(0,Wn.createWriteStream)(S);s.push(b),f.push(new Promise((H,U)=>{b.on("finish",H),b.on("error",U)})),p.pipe(b)}else p.resume()}});await(0,QO.pipeline)(h,(0,IO.createGunzip)(),g),await Promise.all(f)}finally{clearTimeout(i);for(let u of s)u.destroy()}}async function sw(e,{username:t,name:r,branch:n,filePath:A}){let i=`https://codeload.github.com/${t}/${r}/tar.gz/${n}`,s=(0,$t.join)((0,pO.tmpdir)(),`turbo-download-${Date.now()}.tar.gz`),o=await rw(i,{},yO);if(!o.ok||!o.body)throw new Error(`Failed to download: ${o.status}`);let a=Buffer.from(await o.arrayBuffer());await(0,EC.writeFile)(s,a);let u=null;try{await(0,CC.extract)({file:s,cwd:e,strip:A?A.split("/").length+1:1,filter:c=>{if(u===null){let l=c.split("/");u=l.length?l[0]:null}return c.startsWith(`${u}${A?`/${A}/`:"/"}`)}})}finally{await(0,EC.unlink)(s)}}async function ow(e,t){if(!t||!/^[a-zA-Z0-9_-]+$/.test(t))throw new Error(`Invalid example name: ${t}`);let r=(0,$t.resolve)(e);if(!r||r.includes("\0")||r.startsWith("-"))throw new Error(`Invalid project root: ${r}`);let n=(0,$t.join)(r,".turbo-clone-temp");if(!n||n.includes("\0")||n.startsWith("-"))throw new Error(`Invalid temporary directory: ${n}`);try{(0,gC.execFileSync)("git",["clone","--filter=blob:none","--no-checkout","--depth","1","--sparse","https://github.com/vercel/turborepo.git",n],{stdio:"pipe"}),(0,gC.execFileSync)("git",["sparse-checkout","set",`examples/${t}`],{cwd:n,stdio:"pipe"}),(0,gC.execFileSync)("git",["checkout"],{cwd:n,stdio:"pipe"});let A=(0,$t.join)(n,"examples",t);(0,Wn.cpSync)(A,r,{recursive:!0})}catch{(0,Wn.rmSync)(n,{recursive:!0,force:!0}),po(`Git is not available. Downloading example via tarball (slower).
|
|
115
115
|
For faster downloads, install git: https://git-scm.com/downloads`),await Cue({url:"https://codeload.github.com/vercel/turborepo/tar.gz/main",root:r,strip:3,filter:(i,s)=>i.startsWith(`${s}/examples/${t}/`)});return}(0,Wn.rmSync)(n,{recursive:!0,force:!0})}var aw=ue(require("fs-extra"));async function uw(e){try{return await aw.default.access(e,aw.default.constants.W_OK),!0}catch{return!1}}var au=ue(require("path")),cw=ue(NO()),Os=ue(require("picocolors")),dC=ue(require("fs-extra"));function Iue(e){return typeof e=="object"&&e!==null&&typeof e.message=="string"}var BC=class extends Error{};function pue(e){return e.hostname==="github.com"}async function lw({appPath:e,example:t,isDefaultExample:r,examplePath:n}){let A,i;nr();let s=RQ("Downloading files...");s.start();try{if(!r){try{i=new URL(t)}catch(p){p.code!=="ERR_INVALID_URL"&&(s.stop(),mt(p),process.exit(1))}i?(pue(i)||(s.stop(),mt(`Invalid URL: ${Os.default.red(`"${t}"`)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`),process.exit(1)),A=await nw(i,n),A||(s.stop(),mt(`Unable to fetch repository information from: ${Os.default.red(`"${t}"`)}. Please fix the URL and try again.`),process.exit(1)),await Aw(A)||(s.stop(),mt(`Could not locate the repository for ${Os.default.red(`"${t}"`)}. Please check that the repository exists and try again.`),process.exit(1))):(await iw(t)||(s.stop(),mt(`Could not locate an example named ${Os.default.red(`"${t}"`)}. It could be due to the following:
|
|
116
116
|
`,`1. Your spelling of example ${Os.default.red(`"${t}"`)} might be incorrect.
|
|
117
|
-
`,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1)),A={username:"vercel",name:"turborepo",branch:"main",filePath:`examples/${t}`})}let o=au.default.resolve(e);await uw(au.default.dirname(o))||(s.stop(),mt("The application path is not writable, please check folder permissions and try again."),mt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=au.default.basename(o);try{await dC.default.mkdir(o,{recursive:!0})}catch(p){s.stop(),mt("Unable to create project directory"),mt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=Ou(o);u||(s.stop(),mt(`${Os.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),r||A?await(0,cw.default)(()=>sw(o,A!=null?A:{username:"vercel",name:"turborepo",branch:"main",filePath:"examples/basic"}),{retries:3}):await(0,cw.default)(()=>ow(o,t),{retries:3}),s.stop();let h=au.default.join(o,"package.json"),d=dC.default.existsSync(h),f=[];if(d){let p;try{p=dC.default.readJsonSync(h)}catch{}p&&f.push(...Object.keys(p.scripts||{}))}let g=e;return au.default.join(l,a)===e&&(g=a),{cdPath:g,hasPackageJson:d,availableScripts:f,repoInfo:A}}catch(o){throw s.stop(),new BC(Iue(o)?o.message:String(o))}}function hw(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 QC=ue(require("picocolors")),vO=ue(require("update-check"));function gw(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,vO.default)(t).catch(()=>null);return async function(i=0){try{let s=await n;if(s!=null&&s.latest){nr(),nr(QC.default.yellow(QC.default.bold(`A new version of \`${t.name}\` is available!`)));let o=typeof r=="function"?await r():r;o&&nr(`You can update by running: ${QC.default.cyan(o)}`),nr()}process.exit(i)}catch(s){process.env.DEBUG&&mt("Update check failed:",s),process.exit(i)}}}var aH=require("proxy-agent");var fw={name:"@turbo/gen",version:"2.7.4-canary.2",description:"Extend a Turborepo",type:"commonjs",homepage:"https://turborepo.com",license:"MIT",repository:{type:"git",url:"git+https://github.com/vercel/turborepo.git",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","check-types":"tsc --noEmit","package:types":"attw --profile node16 --pack"},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:{"@arethetypeswrong/cli":"0.18.2","@jest/globals":"29.7.0","@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.4","@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 MO=require("@turbo/workspaces");async function IC({root:e}){let t=e||process.cwd(),r=Cu(t);if(!r)P.error("Unable to infer repository root - override with --root");else try{return(0,MO.getWorkspaceDetails)({root:r})}catch{P.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 MA=ue(require("path")),mC=ue(require("fs-extra")),pC=ue(require("node-plop")),TO=require("ts-node"),LO=require("inquirer");var Nt=class extends Error{constructor(r,n){var A;super(r);this.name="GenerateError",this.type=(A=n==null?void 0:n.type)!=null?A:"unknown",Error.captureStackTrace(this,Nt)}};var UO=["ts","js","cjs"],yue=MA.default.join("turbo","generators"),_O=UO.map(e=>MA.default.join(yue,`config.${e}`)),wue=[..._O,...UO.map(e=>MA.default.join(`plopfile.${e}`))];function GO({project:e,configPath:t}){(0,TO.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=bue({project:e}),n;if(t){if(!mC.default.existsSync(t))throw new Nt(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,pC.default)(t,{destBasePath:t,force:!1})}catch(A){P.error(A)}}else{for(let A of wue){let i=MA.default.join(e.paths.root,A);if(mC.default.existsSync(i))try{n=(0,pC.default)(i,{destBasePath:e.paths.root,force:!1});break}catch(s){P.error(s)}}!n&&r.length>0&&(n=(0,pC.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(A=>{try{n.load(A.config,{destBasePath:A.root,force:!1})}catch(i){P.error(i)}}),n}function Ew({project:e,configPath:t}){let r=GO({project:e,configPath:t});if(!r)return[];let A=r.getGeneratorList().map(o=>r.getGenerator(o.name)),i={};A.forEach(o=>{let a=o,u=e.workspaceData.workspaces.find(c=>{if(a.basePath===e.paths.root)return!1;let l=a.basePath.split(MA.default.sep);return l.pop(),l.pop(),MA.default.join("/",...l)===c.paths.root});u?(u.name in i||(i[u.name]=[]),i[u.name].push(a)):("root"in i||(i.root=[]),i.root.push(a))});let s=[];return Object.keys(i).forEach(o=>{s.push(new LO.Separator(o)),s.push(...i[o])}),s}function Due({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?Eu({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=xQ(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function bue({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of _O)mC.default.existsSync(MA.default.join(r.paths.root,n))&&t.push({config:MA.default.join(r.paths.root,n),root:r.paths.root})}),t}async function YO({project:e,generator:t,bypassArgs:r,configPath:n}){let A=GO({project:e,configPath:n});if(!A)throw new Nt("Unable to load generators",{type:"plop_unable_to_load_config"});let i=A.getGenerator(t);if(!i)throw new Nt(`Generator ${t} not found`,{type:"plop_generator_not_found"});let s=await i.runPrompts(r),o=await i.runActions({...s,...Due({project:e,generator:i})},{onComment:a=>{P.dimmed(a)}});if(o.failures.length>0)throw o.failures.forEach(a=>{a instanceof Error?P.error(`Error - ${a.message}`):P.error(`Error - ${a.error}. Unable to ${a.type} to "${a.path}"`)}),new Nt(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});o.changes.length>0&&(P.info("Changes made:"),o.changes.forEach(a=>{a.path&&P.item(`${a.path} (${a.type})`)}))}var Hs=require("inquirer");async function OO({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Hs.Separator)&&n.name===t))return{selectedGenerator:t};P.warn(`Generator "${t}" not found`),P.log()}return await(0,Hs.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Hs.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function HO(){return(0,Hs.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 PO({message:e}){return(0,Hs.prompt)({type:"confirm",name:"answer",message:e})}var Cw=ue(require("path")),dw=ue(require("fs-extra"));async function JO({project:e,template:t}){let r=Cw.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await dw.default.pathExists(r))throw new Nt(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await dw.default.copy(Cw.default.join(__dirname,"templates",n),r,{recursive:!0})}async function Bw({generator:e,project:t,opts:r}){let n=!1,A=Ew({project:t,configPath:r.config});if(!A.length){P.error("No generators found."),P.log();let{answer:s}=await PO({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(s){n=!0;let{answer:o}=await HO();try{await JO({project:t,template:o})}catch(a){throw a instanceof Nt||P.error("Failed to create generator config"),a}if(P.log(),P.info("Generator config successfully created!"),P.info("Loading generator config..."),P.log(),A=Ew({project:t,configPath:r.config}),!A.length){P.error("Error loading generator");return}}else{P.log(),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:i}=await OO({generators:A,generator:e});try{await YO({project:t,generator:i,bypassArgs:r.args,configPath:r.config})}catch(s){if(s instanceof Nt)throw s;let o="Failed to run generator";throw s instanceof Error&&(o=s.message),new Nt(o,{type:"plop_error_running_generator"})}finally{n&&(P.log(),P.info("Congrats! You just ran your first Turborepo generator"),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators"))}P.log(),P.bold(P.turboGradient(">>> Success!"))}var mw=ue(require("path")),bC=ue(require("fs-extra")),tH=ue(require("picocolors"));var Il=ue(require("path")),jO=ue(require("fs-extra")),$r=require("inquirer"),zO=require("minimatch"),pw=ue(require("validate-npm-package-name"));var Qw=ue(require("path"));var qO=ue(require("path"));function VO({project:e}){let r=e.workspaceData.workspaces.map(A=>qO.default.relative(e.paths.root,A.paths.root)),n=new Set;return e.workspaceData.globs.forEach(A=>{if(!r.includes(A)){if(!A.startsWith("!")){let s=A.split("/")[0];n.add(s)}}}),Array.from(n)}function Iw({project:e,workspace:t}){return Qw.default.relative(e.paths.root,t.paths.root).split(Qw.default.sep)[0]}function yC({project:e}){let t=VO({project:e}),r=t.includes("apps"),n=t.includes("packages"),A={},i=[];return e.workspaceData.workspaces.forEach(s=>{let o=Iw({project:e,workspace:s});o!=="apps"&&i.push(s),o in A||(A[o]=[]),A[o].push(s)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:A,nonAppWorkspaces:i}}var WO=require("inquirer");function wC({project:e,type:t,showAllDependencies:r}){let n=yC({project:e}),A=[],i=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?i=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(i=n.nonAppWorkspaces));let s;return i.forEach(o=>{let a=Iw({project:e,workspace:o});a!==s&&A.push(new WO.Separator(a)),s=a,A.push(o)}),A}async function ZO({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,pw.default)(e||"");return e&&n?{answer:e}:(0,$r.prompt)({type:"input",name:"answer",default:t,validate:A=>{let{validForNewPackages:i}=(0,pw.default)(A);return i||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function KO({override:e,message:t}){return e?{answer:e}:(0,$r.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 XO({workspaceType:e,workspaceName:t,destination:r,project:n}){let A=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:a,root:u}=$h(r);if(a)return{absolute:u,relative:Il.default.relative(n.paths.root,u)}}let i,s=yC({project:n});e==="app"&&s.hasRootApps?i=`${n.paths.root}/apps/${A}`:e==="package"&&s.hasRootPackages&&(i=`${n.paths.root}/packages/${A}`);let{answer:o}=await(0,$r.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:i?Il.default.relative(n.paths.root,i):void 0,validate:a=>{let u=Il.default.join(n.paths.root,a),{valid:c,error:l}=$h(u),h=n.workspaceData.globs.some(d=>(0,zO.minimatch)(a,d));return c&&h?!0:h?l:`${a} is not a valid workspace location`}});return{absolute:Il.default.join(n.paths.root,o),relative:o}}async function $O({override:e,workspaces:t,workspaceName:r}){if(e){let A=t.find(i=>i instanceof $r.Separator?!1:i.name===e);if(A)return{answer:A};P.warn(`Workspace "${e}" not found`),P.log()}return await(0,$r.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(A=>A instanceof $r.Separator?A:{name:` ${A.name}`,value:A})})}async function eH({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let A={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:i}=await Sue({message:`Add workspace dependencies to "${e}"?`});if(!i)return A;let{answer:s}=await(0,$r.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"}]}),o=wC({project:t,type:"package",showAllDependencies:n}),a=r?jO.default.readJsonSync(r.paths.packageJson):void 0;for(let u of s){let{answer:c}=await(0,$r.prompt)({type:"checkbox",name:"answer",default:a&&Object.keys(a[u]||{}),pageSize:15,message:`Which packages should be added as ${u} to "${e}?`,loop:!1,choices:o.map(h=>h instanceof $r.Separator?h:{name:` ${h.name}`,value:h.name})}),l=(a==null?void 0:a[u])||{};if(Object.keys(l).length){let h=new Set(Object.keys(l));c.forEach(d=>{h.has(d)||(l[d]=t.packageManager==="pnpm"?"workspace:*":"*")}),A[u]=l}else A[u]=c.reduce((h,d)=>({...h,[d]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return A}async function Sue({message:e}){return(0,$r.prompt)({type:"confirm",name:"answer",message:e})}async function DC({project:e,opts:t}){var a;let r,n=t.method==="copy"&&t.copy.type==="external"?((a=t.examplePath)==null?void 0:a.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:A}=await KO({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:i}=await ZO({override:t.name,workspaceType:A,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:u}=await $O({override:t.copy.source,workspaces:wC({project:e,type:A}),workspaceName:i});r=u}let s=await XO({workspaceType:A,workspaceName:i,project:e,destination:t.destination}),o=await eH({workspaceName:i,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:A,name:i,location:s,source:r,dependencies:o}}async function yw({project:e,opts:t}){let{name:r,location:n,dependencies:A}=await DC({project:e,opts:t}),i={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(A).forEach(s=>{let o=A[s];o&&Object.keys(o).length>0&&(i[s]=o)}),bC.default.mkdirSync(n.absolute,{recursive:!0}),bC.default.writeFileSync(mw.default.join(n.absolute,"package.json"),JSON.stringify(i,null,2)),bC.default.writeFileSync(mw.default.join(n.absolute,"README.md"),`# \`${r}\``),P.log(),P.log(`${tH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var ww=ue(require("path")),Mi=ue(require("fs-extra")),rH=ue(require("picocolors"));async function Dw({project:e,opts:t}){let{name:r,type:n,location:A,source:i,dependencies:s}=await DC({project:e,opts:t}),o=ww.default.join(A.absolute,"package.json");if(t.copy.type==="external"){P.log(),P.warn("Some manual modifications may be required."),P.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await lw({appPath:A.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(Mi.default.existsSync(o)){if((await Mi.default.readJSON(o)).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(Mi.default.existsSync(ww.default.join(A.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(u){let c="UNKNOWN_ERROR";u instanceof Error&&(c=u.message),P.error(c),await Mi.default.rm(A.absolute,{recursive:!0,force:!0});return}}else if(i){let u=async l=>Promise.resolve(!l.includes("node_modules")),c=P.turboLoader(`Creating "${r}" from "${i.name}"...`);c.start(),await Mi.default.copy(i.paths.root,A.absolute,{filter:u}),c.stop()}let a=await Mi.default.readJSON(o);a.name=r,Object.keys(s).forEach(u=>{let c=s[u];c&&Object.keys(c).length>0&&(a[u]=c)}),await Mi.default.writeJSON(o,a,{spaces:2}),P.log(),P.log(`${rH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${A.relative}"`)}function kue(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",A=typeof t=="string"?t:"",i=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:i,source:A},...r}}async function pl(e){let t=await IC(e),r=kue(e);P.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?P.info(`Copy a remote workspace from ${r.copy.source}`):P.info(`Copy an existing workspace from "${t.name}"`),P.log(),await Dw(n)):(P.info(`Add an empty workspace to "${t.name}"`),P.log(),await yw(n))}async function ml(e,t){let r=await IC(t);P.log(),P.info(`Modify "${r.name}" using custom generators`),P.log(),await Bw({generator:e,project:r,opts:t})}function nH(e){try{let t=JSON.parse(e),r={};for(let n in t){let A=hw(n,{to:"camel"});r[A]=t[n]}return r}catch(t){P.error("Error parsing arguments",t),process.exit(1)}}async function bw(e,t){var r;if(e==="workspace"){let n=nH(t.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let A=!1,i=n.empty||!0;n.copy===""||n.copy===!0?(A=!0,i=!1):n.copy&&n.copy.length>0&&(A=n.copy,i=!1),n.copy=A,n.empty=i,await pl(n)}else if(e==="run"){let n=nH(t.json),{generatorName:A,...i}=n;await ml(A,i)}else P.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var AH=gw({packageInfo:fw}),uH=new aH.ProxyAgent;iH.default.globalAgent=uH;sH.default.globalAgent=uH;var yl=new vt.Command;yl.name(oH.default.bold(P.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(fw.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);yl.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new vt.Argument("[generator-name]","The name of the generator to run")).addOption(new vt.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new vt.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new vt.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(ml);yl.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new vt.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new vt.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new vt.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
|
|
117
|
+
`,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1)),A={username:"vercel",name:"turborepo",branch:"main",filePath:`examples/${t}`})}let o=au.default.resolve(e);await uw(au.default.dirname(o))||(s.stop(),mt("The application path is not writable, please check folder permissions and try again."),mt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=au.default.basename(o);try{await dC.default.mkdir(o,{recursive:!0})}catch(p){s.stop(),mt("Unable to create project directory"),mt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=Ou(o);u||(s.stop(),mt(`${Os.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),r||A?await(0,cw.default)(()=>sw(o,A!=null?A:{username:"vercel",name:"turborepo",branch:"main",filePath:"examples/basic"}),{retries:3}):await(0,cw.default)(()=>ow(o,t),{retries:3}),s.stop();let h=au.default.join(o,"package.json"),d=dC.default.existsSync(h),f=[];if(d){let p;try{p=dC.default.readJsonSync(h)}catch{}p&&f.push(...Object.keys(p.scripts||{}))}let g=e;return au.default.join(l,a)===e&&(g=a),{cdPath:g,hasPackageJson:d,availableScripts:f,repoInfo:A}}catch(o){throw s.stop(),new BC(Iue(o)?o.message:String(o))}}function hw(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 QC=ue(require("picocolors")),vO=ue(require("update-check"));function gw(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,vO.default)(t).catch(()=>null);return async function(i=0){try{let s=await n;if(s!=null&&s.latest){nr(),nr(QC.default.yellow(QC.default.bold(`A new version of \`${t.name}\` is available!`)));let o=typeof r=="function"?await r():r;o&&nr(`You can update by running: ${QC.default.cyan(o)}`),nr()}process.exit(i)}catch(s){process.env.DEBUG&&mt("Update check failed:",s),process.exit(i)}}}var aH=require("proxy-agent");var fw={name:"@turbo/gen",version:"2.7.4-canary.3",description:"Extend a Turborepo",type:"commonjs",homepage:"https://turborepo.com",license:"MIT",repository:{type:"git",url:"git+https://github.com/vercel/turborepo.git",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","check-types":"tsc --noEmit","package:types":"attw --profile node16 --pack"},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:{"@arethetypeswrong/cli":"0.18.2","@jest/globals":"29.7.0","@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.4","@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 MO=require("@turbo/workspaces");async function IC({root:e}){let t=e||process.cwd(),r=Cu(t);if(!r)P.error("Unable to infer repository root - override with --root");else try{return(0,MO.getWorkspaceDetails)({root:r})}catch{P.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 MA=ue(require("path")),mC=ue(require("fs-extra")),pC=ue(require("node-plop")),TO=require("ts-node"),LO=require("inquirer");var Nt=class extends Error{constructor(r,n){var A;super(r);this.name="GenerateError",this.type=(A=n==null?void 0:n.type)!=null?A:"unknown",Error.captureStackTrace(this,Nt)}};var UO=["ts","js","cjs"],yue=MA.default.join("turbo","generators"),_O=UO.map(e=>MA.default.join(yue,`config.${e}`)),wue=[..._O,...UO.map(e=>MA.default.join(`plopfile.${e}`))];function GO({project:e,configPath:t}){(0,TO.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=bue({project:e}),n;if(t){if(!mC.default.existsSync(t))throw new Nt(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,pC.default)(t,{destBasePath:t,force:!1})}catch(A){P.error(A)}}else{for(let A of wue){let i=MA.default.join(e.paths.root,A);if(mC.default.existsSync(i))try{n=(0,pC.default)(i,{destBasePath:e.paths.root,force:!1});break}catch(s){P.error(s)}}!n&&r.length>0&&(n=(0,pC.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(A=>{try{n.load(A.config,{destBasePath:A.root,force:!1})}catch(i){P.error(i)}}),n}function Ew({project:e,configPath:t}){let r=GO({project:e,configPath:t});if(!r)return[];let A=r.getGeneratorList().map(o=>r.getGenerator(o.name)),i={};A.forEach(o=>{let a=o,u=e.workspaceData.workspaces.find(c=>{if(a.basePath===e.paths.root)return!1;let l=a.basePath.split(MA.default.sep);return l.pop(),l.pop(),MA.default.join("/",...l)===c.paths.root});u?(u.name in i||(i[u.name]=[]),i[u.name].push(a)):("root"in i||(i.root=[]),i.root.push(a))});let s=[];return Object.keys(i).forEach(o=>{s.push(new LO.Separator(o)),s.push(...i[o])}),s}function Due({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?Eu({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=xQ(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function bue({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of _O)mC.default.existsSync(MA.default.join(r.paths.root,n))&&t.push({config:MA.default.join(r.paths.root,n),root:r.paths.root})}),t}async function YO({project:e,generator:t,bypassArgs:r,configPath:n}){let A=GO({project:e,configPath:n});if(!A)throw new Nt("Unable to load generators",{type:"plop_unable_to_load_config"});let i=A.getGenerator(t);if(!i)throw new Nt(`Generator ${t} not found`,{type:"plop_generator_not_found"});let s=await i.runPrompts(r),o=await i.runActions({...s,...Due({project:e,generator:i})},{onComment:a=>{P.dimmed(a)}});if(o.failures.length>0)throw o.failures.forEach(a=>{a instanceof Error?P.error(`Error - ${a.message}`):P.error(`Error - ${a.error}. Unable to ${a.type} to "${a.path}"`)}),new Nt(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});o.changes.length>0&&(P.info("Changes made:"),o.changes.forEach(a=>{a.path&&P.item(`${a.path} (${a.type})`)}))}var Hs=require("inquirer");async function OO({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Hs.Separator)&&n.name===t))return{selectedGenerator:t};P.warn(`Generator "${t}" not found`),P.log()}return await(0,Hs.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Hs.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function HO(){return(0,Hs.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 PO({message:e}){return(0,Hs.prompt)({type:"confirm",name:"answer",message:e})}var Cw=ue(require("path")),dw=ue(require("fs-extra"));async function JO({project:e,template:t}){let r=Cw.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await dw.default.pathExists(r))throw new Nt(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await dw.default.copy(Cw.default.join(__dirname,"templates",n),r,{recursive:!0})}async function Bw({generator:e,project:t,opts:r}){let n=!1,A=Ew({project:t,configPath:r.config});if(!A.length){P.error("No generators found."),P.log();let{answer:s}=await PO({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(s){n=!0;let{answer:o}=await HO();try{await JO({project:t,template:o})}catch(a){throw a instanceof Nt||P.error("Failed to create generator config"),a}if(P.log(),P.info("Generator config successfully created!"),P.info("Loading generator config..."),P.log(),A=Ew({project:t,configPath:r.config}),!A.length){P.error("Error loading generator");return}}else{P.log(),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:i}=await OO({generators:A,generator:e});try{await YO({project:t,generator:i,bypassArgs:r.args,configPath:r.config})}catch(s){if(s instanceof Nt)throw s;let o="Failed to run generator";throw s instanceof Error&&(o=s.message),new Nt(o,{type:"plop_error_running_generator"})}finally{n&&(P.log(),P.info("Congrats! You just ran your first Turborepo generator"),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators"))}P.log(),P.bold(P.turboGradient(">>> Success!"))}var mw=ue(require("path")),bC=ue(require("fs-extra")),tH=ue(require("picocolors"));var Il=ue(require("path")),jO=ue(require("fs-extra")),$r=require("inquirer"),zO=require("minimatch"),pw=ue(require("validate-npm-package-name"));var Qw=ue(require("path"));var qO=ue(require("path"));function VO({project:e}){let r=e.workspaceData.workspaces.map(A=>qO.default.relative(e.paths.root,A.paths.root)),n=new Set;return e.workspaceData.globs.forEach(A=>{if(!r.includes(A)){if(!A.startsWith("!")){let s=A.split("/")[0];n.add(s)}}}),Array.from(n)}function Iw({project:e,workspace:t}){return Qw.default.relative(e.paths.root,t.paths.root).split(Qw.default.sep)[0]}function yC({project:e}){let t=VO({project:e}),r=t.includes("apps"),n=t.includes("packages"),A={},i=[];return e.workspaceData.workspaces.forEach(s=>{let o=Iw({project:e,workspace:s});o!=="apps"&&i.push(s),o in A||(A[o]=[]),A[o].push(s)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:A,nonAppWorkspaces:i}}var WO=require("inquirer");function wC({project:e,type:t,showAllDependencies:r}){let n=yC({project:e}),A=[],i=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?i=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(i=n.nonAppWorkspaces));let s;return i.forEach(o=>{let a=Iw({project:e,workspace:o});a!==s&&A.push(new WO.Separator(a)),s=a,A.push(o)}),A}async function ZO({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,pw.default)(e||"");return e&&n?{answer:e}:(0,$r.prompt)({type:"input",name:"answer",default:t,validate:A=>{let{validForNewPackages:i}=(0,pw.default)(A);return i||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function KO({override:e,message:t}){return e?{answer:e}:(0,$r.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 XO({workspaceType:e,workspaceName:t,destination:r,project:n}){let A=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:a,root:u}=$h(r);if(a)return{absolute:u,relative:Il.default.relative(n.paths.root,u)}}let i,s=yC({project:n});e==="app"&&s.hasRootApps?i=`${n.paths.root}/apps/${A}`:e==="package"&&s.hasRootPackages&&(i=`${n.paths.root}/packages/${A}`);let{answer:o}=await(0,$r.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:i?Il.default.relative(n.paths.root,i):void 0,validate:a=>{let u=Il.default.join(n.paths.root,a),{valid:c,error:l}=$h(u),h=n.workspaceData.globs.some(d=>(0,zO.minimatch)(a,d));return c&&h?!0:h?l:`${a} is not a valid workspace location`}});return{absolute:Il.default.join(n.paths.root,o),relative:o}}async function $O({override:e,workspaces:t,workspaceName:r}){if(e){let A=t.find(i=>i instanceof $r.Separator?!1:i.name===e);if(A)return{answer:A};P.warn(`Workspace "${e}" not found`),P.log()}return await(0,$r.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(A=>A instanceof $r.Separator?A:{name:` ${A.name}`,value:A})})}async function eH({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let A={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:i}=await Sue({message:`Add workspace dependencies to "${e}"?`});if(!i)return A;let{answer:s}=await(0,$r.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"}]}),o=wC({project:t,type:"package",showAllDependencies:n}),a=r?jO.default.readJsonSync(r.paths.packageJson):void 0;for(let u of s){let{answer:c}=await(0,$r.prompt)({type:"checkbox",name:"answer",default:a&&Object.keys(a[u]||{}),pageSize:15,message:`Which packages should be added as ${u} to "${e}?`,loop:!1,choices:o.map(h=>h instanceof $r.Separator?h:{name:` ${h.name}`,value:h.name})}),l=(a==null?void 0:a[u])||{};if(Object.keys(l).length){let h=new Set(Object.keys(l));c.forEach(d=>{h.has(d)||(l[d]=t.packageManager==="pnpm"?"workspace:*":"*")}),A[u]=l}else A[u]=c.reduce((h,d)=>({...h,[d]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return A}async function Sue({message:e}){return(0,$r.prompt)({type:"confirm",name:"answer",message:e})}async function DC({project:e,opts:t}){var a;let r,n=t.method==="copy"&&t.copy.type==="external"?((a=t.examplePath)==null?void 0:a.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:A}=await KO({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:i}=await ZO({override:t.name,workspaceType:A,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:u}=await $O({override:t.copy.source,workspaces:wC({project:e,type:A}),workspaceName:i});r=u}let s=await XO({workspaceType:A,workspaceName:i,project:e,destination:t.destination}),o=await eH({workspaceName:i,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:A,name:i,location:s,source:r,dependencies:o}}async function yw({project:e,opts:t}){let{name:r,location:n,dependencies:A}=await DC({project:e,opts:t}),i={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(A).forEach(s=>{let o=A[s];o&&Object.keys(o).length>0&&(i[s]=o)}),bC.default.mkdirSync(n.absolute,{recursive:!0}),bC.default.writeFileSync(mw.default.join(n.absolute,"package.json"),JSON.stringify(i,null,2)),bC.default.writeFileSync(mw.default.join(n.absolute,"README.md"),`# \`${r}\``),P.log(),P.log(`${tH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var ww=ue(require("path")),Mi=ue(require("fs-extra")),rH=ue(require("picocolors"));async function Dw({project:e,opts:t}){let{name:r,type:n,location:A,source:i,dependencies:s}=await DC({project:e,opts:t}),o=ww.default.join(A.absolute,"package.json");if(t.copy.type==="external"){P.log(),P.warn("Some manual modifications may be required."),P.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await lw({appPath:A.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(Mi.default.existsSync(o)){if((await Mi.default.readJSON(o)).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(Mi.default.existsSync(ww.default.join(A.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(u){let c="UNKNOWN_ERROR";u instanceof Error&&(c=u.message),P.error(c),await Mi.default.rm(A.absolute,{recursive:!0,force:!0});return}}else if(i){let u=async l=>Promise.resolve(!l.includes("node_modules")),c=P.turboLoader(`Creating "${r}" from "${i.name}"...`);c.start(),await Mi.default.copy(i.paths.root,A.absolute,{filter:u}),c.stop()}let a=await Mi.default.readJSON(o);a.name=r,Object.keys(s).forEach(u=>{let c=s[u];c&&Object.keys(c).length>0&&(a[u]=c)}),await Mi.default.writeJSON(o,a,{spaces:2}),P.log(),P.log(`${rH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${A.relative}"`)}function kue(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",A=typeof t=="string"?t:"",i=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:i,source:A},...r}}async function pl(e){let t=await IC(e),r=kue(e);P.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?P.info(`Copy a remote workspace from ${r.copy.source}`):P.info(`Copy an existing workspace from "${t.name}"`),P.log(),await Dw(n)):(P.info(`Add an empty workspace to "${t.name}"`),P.log(),await yw(n))}async function ml(e,t){let r=await IC(t);P.log(),P.info(`Modify "${r.name}" using custom generators`),P.log(),await Bw({generator:e,project:r,opts:t})}function nH(e){try{let t=JSON.parse(e),r={};for(let n in t){let A=hw(n,{to:"camel"});r[A]=t[n]}return r}catch(t){P.error("Error parsing arguments",t),process.exit(1)}}async function bw(e,t){var r;if(e==="workspace"){let n=nH(t.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let A=!1,i=n.empty||!0;n.copy===""||n.copy===!0?(A=!0,i=!1):n.copy&&n.copy.length>0&&(A=n.copy,i=!1),n.copy=A,n.empty=i,await pl(n)}else if(e==="run"){let n=nH(t.json),{generatorName:A,...i}=n;await ml(A,i)}else P.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var AH=gw({packageInfo:fw}),uH=new aH.ProxyAgent;iH.default.globalAgent=uH;sH.default.globalAgent=uH;var yl=new vt.Command;yl.name(oH.default.bold(P.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(fw.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);yl.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new vt.Argument("[generator-name]","The name of the generator to run")).addOption(new vt.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new vt.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new vt.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(ml);yl.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new vt.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new vt.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new vt.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
|
|
118
118
|
within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
|
|
119
119
|
`).conflicts("empty")).addOption(new vt.Option("-d, --destination <dir>","Where the new workspace should be created")).addOption(new vt.Option("-t, --type <type>","The type of workspace to create").choices(["app","package"])).addOption(new vt.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new vt.Option("-p, --example-path <path-to-example>",`In a rare case, your GitHub URL might contain a branch name with
|
|
120
120
|
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.7.4-canary.
|
|
3
|
+
"version": "2.7.4-canary.3",
|
|
4
4
|
"description": "Extend a Turborepo",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"homepage": "https://turborepo.com",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"ts-node": "10.9.2",
|
|
27
27
|
"update-check": "1.5.4",
|
|
28
28
|
"validate-npm-package-name": "5.0.0",
|
|
29
|
-
"@turbo/workspaces": "2.7.4-canary.
|
|
29
|
+
"@turbo/workspaces": "2.7.4-canary.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@arethetypeswrong/cli": "0.18.2",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"ts-jest": "29.2.5",
|
|
40
40
|
"tsup": "6.7.0",
|
|
41
41
|
"typescript": "5.5.4",
|
|
42
|
+
"@turbo/test-utils": "0.0.0",
|
|
42
43
|
"@turbo/tsconfig": "0.0.0",
|
|
43
|
-
"@turbo/utils": "0.0.0"
|
|
44
|
-
"@turbo/test-utils": "0.0.0"
|
|
44
|
+
"@turbo/utils": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist"
|