@turbo/codemod 1.10.12 → 1.10.13-canary.0

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.
@@ -1 +1 @@
1
- "use strict";var v=Object.create;var g=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var D=(r,e)=>{for(var t in e)g(r,t,{get:e[t],enumerable:!0})},w=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of S(e))!J.call(r,o)&&o!==t&&g(r,o,{get:()=>e[o],enumerable:!(s=x(e,o))||s.enumerable});return r};var l=(r,e,t)=>(t=r!=null?v(I(r)):{},w(e||!r||!r.__esModule?g(t,"default",{value:r,enumerable:!0}):t,r)),U=r=>w(g({},"__esModule",{value:!0}),r);var G={};D(G,{default:()=>$,transformer:()=>O});module.exports=U(G);var p=l(require("fs-extra")),F=l(require("path"));var m=l(require("chalk"));var u=l(require("chalk")),y=require("diff"),c=l(require("fs-extra")),N=l(require("os")),b=l(require("path")),d=class{constructor(e){this.changes=[];if(this.filePath=e.filePath,this.rootPath=e.rootPath,this.after=e.after,this.error=e.error,e.before===void 0)try{b.default.extname(e.filePath)===".json"?this.before=c.default.readJsonSync(e.filePath):this.before=c.default.readFileSync(e.filePath)}catch{this.before=""}else e.before===null?this.before="":this.before=e.before;e.after?typeof this.before=="object"||typeof e.after=="object"?this.changes=(0,y.diffJson)(this.before,e.after):this.changes=(0,y.diffLines)(this.before,e.after):this.changes=[]}fileName(){return b.default.relative(this.rootPath,this.filePath)}write(){this.after&&(typeof this.after=="object"?c.default.writeJsonSync(this.filePath,this.after,{spaces:2}):c.default.writeFileSync(this.filePath,this.after))}additions(){return this.changes.filter(e=>e.added).length}deletions(){return this.changes.filter(e=>e.removed).length}hasChanges(){return this.additions()>0||this.deletions()>0}log(e){e.diff?(this.changes.forEach(t=>{t.added?process.stdout.write(u.default.green(t.value)):t.removed?process.stdout.write(u.default.red(t.value)):process.stdout.write(u.default.dim(t.value))}),console.log(N.default.EOL)):console.log(this.after)}};var n=l(require("chalk")),h=class{constructor(e){this.transform=e.transformer,this.dry=e.dry}modified(...e){console.log(n.default.green(" MODIFIED "),...e,this.dry?n.default.dim("(dry run)"):"")}unchanged(...e){console.log(n.default.gray(" UNCHANGED "),...e,this.dry?n.default.dim("(dry run)"):"")}skipped(...e){console.log(n.default.yellow(" SKIPPED "),...e,this.dry?n.default.dim("(dry run)"):"")}error(...e){console.log(n.default.red(" ERROR "),...e,this.dry?n.default.dim("(dry run)"):"")}info(...e){console.log(n.default.bold(" INFO "),...e,this.dry?n.default.dim("(dry run)"):"")}};var P=class{constructor(e){this.modifications={};this.transform=e.transformer,this.rootPath=e.rootPath,this.dry=e.dry,this.print=e.print,this.logger=new h(e)}abortTransform(e){return this.logger.error(e.reason),{fatalError:new Error(e.reason),changes:e.changes||{}}}modifyFile(e){this.modifications[e.filePath]=new d({rootPath:this.rootPath,...e})}finish(){let e={changes:{}};return Object.keys(this.modifications).forEach(s=>{let o=this.modifications[s],i={action:"unchanged",additions:o.additions(),deletions:o.deletions()};if(o.hasChanges()){if(this.dry)i.action="skipped",this.logger.skipped(m.default.dim(o.fileName()));else try{o.write(),i.action="modified",this.logger.modified(m.default.bold(o.fileName()))}catch(a){let f="Unknown error";a instanceof Error&&(f=a.message),i.error=new Error(f),i.action="error",this.logger.error(o.fileName(),f)}this.print&&o.log({diff:!0})}else this.logger.unchanged(m.default.dim(o.fileName()));e.changes[o.fileName()]=i}),Object.keys(e.changes).some(s=>e.changes[s].action==="error")?this.abortTransform({reason:"Encountered an error while transforming files",changes:e.changes}):e}static logResults(e){let t=Object.keys(e.changes);if(console.log(),t.length>0){console.log(m.default.bold("Results:"));let s={};t.forEach(o=>{var a;let i=e.changes[o];s[o]={action:i.action,additions:i.additions,deletions:i.deletions,error:((a=i.error)==null?void 0:a.message)||"None"}}),console.table(s),console.log()}}},T=P;function R({transformer:r,rootPath:e,options:t}){let s={transformer:r,rootPath:e,...t},o=new h(s),i=new T(s);return{log:o,runner:i}}var k="create-turbo-config",L='Create the `turbo.json` file from an existing "turbo" key in `package.json`',M="1.1.0";function O({root:r,options:e}){let{log:t,runner:s}=R({transformer:k,rootPath:r,options:e});t.info('Migrating "package.json" "turbo" key to "turbo.json" file...');let o=F.default.join(r,"turbo.json"),i=F.default.join(r,"package.json");if(!p.default.existsSync(i))return s.abortTransform({reason:`No package.json found at ${r}. Is the path correct?`});let a=p.default.readJsonSync(i),f=null;try{f=p.default.readJSONSync(o)}catch{f=null}let A=a,E=f;if(!f&&a.turbo){let{turbo:j,...C}=a;E=j,A=C}return s.modifyFile({filePath:o,after:E}),s.modifyFile({filePath:i,after:A}),s.finish()}var H={name:`${k}: ${L}`,value:k,introducedIn:M,transformer:O},$=H;0&&(module.exports={transformer});
1
+ "use strict";var x=Object.create;var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var D=(e,r)=>{for(var t in r)g(e,t,{get:r[t],enumerable:!0})},j=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of v(r))!J.call(e,o)&&o!==t&&g(e,o,{get:()=>r[o],enumerable:!(s=S(r,o))||s.enumerable});return e};var l=(e,r,t)=>(t=e!=null?x(I(e)):{},j(r||!e||!e.__esModule?g(t,"default",{value:e,enumerable:!0}):t,e)),U=e=>j(g({},"__esModule",{value:!0}),e);var K={};D(K,{default:()=>G,transformer:()=>O});module.exports=U(K);var p=l(require("fs-extra")),F=l(require("path"));var m=l(require("chalk"));var u=l(require("chalk")),y=require("diff"),h=l(require("fs-extra")),w=l(require("os")),b=l(require("path")),d=class{constructor(r){this.changes=[];if(this.filePath=r.filePath,this.rootPath=r.rootPath,this.after=r.after,this.error=r.error,r.before===void 0)try{b.default.extname(r.filePath)===".json"?this.before=h.default.readJsonSync(r.filePath):this.before=h.default.readFileSync(r.filePath)}catch{this.before=""}else r.before===null?this.before="":this.before=r.before;r.after?typeof this.before=="object"||typeof r.after=="object"?this.changes=(0,y.diffJson)(this.before,r.after):this.changes=(0,y.diffLines)(this.before,r.after):this.changes=[]}fileName(){return b.default.relative(this.rootPath,this.filePath)}write(){this.after&&(typeof this.after=="object"?h.default.writeJsonSync(this.filePath,this.after,{spaces:2}):h.default.writeFileSync(this.filePath,this.after))}additions(){return this.changes.filter(r=>r.added).length}deletions(){return this.changes.filter(r=>r.removed).length}hasChanges(){return this.additions()>0||this.deletions()>0}log(r){r.diff?(this.changes.forEach(t=>{t.added?process.stdout.write(u.default.green(t.value)):t.removed?process.stdout.write(u.default.red(t.value)):process.stdout.write(u.default.dim(t.value))}),console.log(w.default.EOL)):console.log(this.after)}};var n=l(require("chalk")),c=class{constructor(r){this.transform=r.transformer,this.dry=r.dry}modified(...r){console.log(n.default.green(" MODIFIED "),...r,this.dry?n.default.dim("(dry run)"):"")}unchanged(...r){console.log(n.default.gray(" UNCHANGED "),...r,this.dry?n.default.dim("(dry run)"):"")}skipped(...r){console.log(n.default.yellow(" SKIPPED "),...r,this.dry?n.default.dim("(dry run)"):"")}error(...r){console.log(n.default.red(" ERROR "),...r,this.dry?n.default.dim("(dry run)"):"")}info(...r){console.log(n.default.bold(" INFO "),...r,this.dry?n.default.dim("(dry run)"):"")}};var P=class{constructor(r){this.modifications={};this.transform=r.transformer,this.rootPath=r.rootPath,this.dry=r.dry,this.print=r.print,this.logger=new c(r)}abortTransform(r){return this.logger.error(r.reason),{fatalError:new Error(r.reason),changes:r.changes||{}}}modifyFile(r){this.modifications[r.filePath]=new d({rootPath:this.rootPath,...r})}finish(){let r={changes:{}};return Object.keys(this.modifications).forEach(s=>{let o=this.modifications[s],i={action:"unchanged",additions:o.additions(),deletions:o.deletions()};if(o.hasChanges()){if(this.dry)i.action="skipped",this.logger.skipped(m.default.dim(o.fileName()));else try{o.write(),i.action="modified",this.logger.modified(m.default.bold(o.fileName()))}catch(a){let f="Unknown error";a instanceof Error&&(f=a.message),i.error=new Error(f),i.action="error",this.logger.error(o.fileName(),f)}this.print&&o.log({diff:!0})}else this.logger.unchanged(m.default.dim(o.fileName()));r.changes[o.fileName()]=i}),Object.keys(r.changes).some(s=>r.changes[s].action==="error")?this.abortTransform({reason:"Encountered an error while transforming files",changes:r.changes}):r}static logResults(r){let t=Object.keys(r.changes);if(console.log(),t.length>0){console.log(m.default.bold("Results:"));let s={};t.forEach(o=>{var a;let i=r.changes[o];s[o]={action:i.action,additions:i.additions,deletions:i.deletions,error:((a=i.error)==null?void 0:a.message)||"None"}}),console.table(s),console.log()}}},T=P;function R({transformer:e,rootPath:r,options:t}){let s={transformer:e,rootPath:r,...t},o=new c(s),i=new T(s);return{log:o,runner:i}}var N="create-turbo-config",L='Create the `turbo.json` file from an existing "turbo" key in `package.json`',M="1.1.0";function O({root:e,options:r}){let{log:t,runner:s}=R({transformer:N,rootPath:e,options:r});t.info('Migrating "package.json" "turbo" key to "turbo.json" file...');let o=F.default.join(e,"turbo.json"),i=F.default.join(e,"package.json");if(!p.default.existsSync(i))return s.abortTransform({reason:`No package.json found at ${e}. Is the path correct?`});let a=p.default.readJsonSync(i),f=null;try{f=p.default.readJSONSync(o)}catch{f=null}let k=a,A=f;if(!f&&a.turbo){let{turbo:E,...C}=a;A=E,k=C}return s.modifyFile({filePath:o,after:A}),s.modifyFile({filePath:i,after:k}),s.finish()}var H={name:N,description:L,introducedIn:M,transformer:O},G=H;0&&(module.exports={transformer});