builder.io 1.5.9 → 1.5.10
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/cli/index.cjs +248 -279
- package/cli/index.cjs.map +4 -4
- package/core/index.cjs +9 -9
- package/core/index.mjs +9 -9
- package/node/index.cjs +1 -1
- package/node/index.mjs +1 -1
- package/package.json +1 -1
- package/server/index.cjs +119 -119
- package/server/index.mjs +106 -106
- package/types/cli/figma-utils.d.ts +41 -0
- package/types/cli/generate.d.ts +10 -50
- package/types/cli/index.d.ts +2 -0
package/core/index.cjs
CHANGED
|
@@ -913,7 +913,7 @@ export class Counter {
|
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
915
|
|
|
916
|
-
`.trimStart()}async function bo(e){await Jt(e);let t=await e.readFile(e.registryPath);return t?Zs(e,t):{components:[],sourceFile:I(e,"")}}async function Zs(e,t){let r=I(e,t);return eu(e,r)}async function eu(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await bn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function bn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=K(a)),n.importName=a;let u=await he(e,e.registryPath,t,a);if(!u)continue;if(n.filePath=u.filePath,n.relFilePath=u.relFilePath,await e.exists(u.filePath)?n.importPath=V(e,u.filePath):(n.externalImportPath=u.importPath,n.importPath=n.externalImportPath),n.displayFilePath=u.displayFilePath,n.exportType=u.exportType,n.externalImportPath)n.exportName=a;else{let p=await go(e,u.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let m=p.find(f=>f.cmpInfo.exportName===a);m&&(n.exportName=m.cmpInfo.exportName)}}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await $(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ve(e,t,r,n,o,i,a,s){let u=await Me(e),[p,m,f]=await Promise.all([fo(e,u),bo(e),Pt(e)]),c=p.map(x=>x.cmpInfo),d=m.components,C={components:me(c,d),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ee(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return C.components=await Do(e,p,C.components),C;let l=!1,D=m.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let x=g.map(A=>{let S=p.find(O=>O.cmpInfo.id===A);if(!S)throw new Error(`Component ${A} not found`);return S}),E=Array.from(new Set(x.map(A=>A.cmpInfo.filePath))),P=await G(e,E);for(let A of x){let S=C.components.find(L=>L.id===A.cmpInfo.id),O=await En(e,A,P);ie(S,O);let z=c.findIndex(L=>L.id===A.cmpInfo.id);c[z].inputs=O;let j=Pe(A.cmpInfo.id,c,d,r,n,o,i),{elements:F,elmIndex:y,statementIndex:H,statement:le,variableDeclaration:Y}=await nu(e,D,A);if(j.addCmpToRegistry)F.push(tu(e,j.addCmpToRegistry)),l=!0;else if(j.removeCmpFromRegistry)F.splice(y,1),l=!0;else if(j.updateRegisteredCmp){let L=Q(e,F[y],j.updateRegisteredCmp);F[y]=e.ts.factory.updateObjectLiteralExpression(L,[vo(e,j.updateRegisteredCmp),...L.properties.slice(1)]),l=!0}if(l&&a){let L=[...D.statements];L[H]=e.ts.factory.updateVariableStatement(le,le.modifiers,e.ts.factory.updateVariableDeclarationList(le.declarationList,[e.ts.factory.updateVariableDeclaration(Y,Y.name,Y.exclamationToken,Y.type,e.ts.factory.createArrayLiteralExpression(Ae(e,F)))])),D=e.ts.factory.updateSourceFile(D,L),S.exportType==="named"?D=v(e,D,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}):D=v(e,D,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}),D=v(e,D,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),D=ye(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),C.components=j.components,d=j.components.filter(X=>X.isRegistered)}}}if(l&&a){D=Fe(e,D),D=Se(e,D);let x=_(e,D);x=pe(x),x=await e.formatCode(e.registryPath,x),await e.writeFile(e.registryPath,x)}return C}function vo(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function tu(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([vo(e,t)],!0),t)}async function nu(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await bn(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Io(e){let t=await ru(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>yo(t),ensureFigmaImportPage:()=>wo(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>ve(t,null,!1,!1,null,null,!1,!!o?.readAllInputTypes),addExternalPackage:async o=>{r[o]||(r[o]=`export * from "${o}";`)},loadComponent:async o=>{let i=await ve(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>ve(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>ve(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>ve(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>ve(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Pt(t),setPublicApiKey:o=>co(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>De(t),setCache:o=>Ce(t,o)}}async function ru(e){let t=await ou(e),r=e.getAppRootDir(),n=e.join(r,"src"),o=await re(e),i=e.join(n,"app"),a=await ae(e,i),s={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:a,angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);s.srcDir=n,s.appDir=i,s.componentsDir=e.join(s.appDir,"components"),s.builderPageComponentPath=e.join(s.componentsDir,`builder-page.component.${o?"ts":"js"}`);let u=`app.module.${o?"ts":"js"}`,p=e.join(s.appDir,u);return await e.exists(p)&&(s.hasAppModule=!0),s}async function ou(e){let t=e.join(e.getAppRootDir(),"angular.json");if(await e.exists(t))return t;let r=e.join(e.getAppRootDir(),"project.json");if(await e.exists(r))return r;throw new Error(`Could not find Angular config file. Searched for angular.json & project.json in "${e.getAppRootDir()}".`)}var Xt=Qn(Uo(),1);async function zo(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:ce(e.relative(e.getAppRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:oe(i.inputs)};return oe(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,Xt.compress)(n);return btoa(JSON.stringify(o))}async function qo(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,Xt.decompress)(o),a=oe(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let u=ce(e.normalize(s.filePath)),p=n.components.find(f=>ce(f.filePath).endsWith(u)&&f.exportName===s.exportName);if(!p){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${p.id})`,p.filePath),await t.registerComponent({cmpId:p.id});for(let f of s.inputs)e.debug(`set input (${p.id})`),await t.setRegisteredComponentInput({cmpId:p.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${p.id}) info`);let m=await t.setRegisteredComponentInfo({cmpId:p.id,name:s.name,image:s.image,description:s.description});a=oe(m)}return a}var de={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Ad={[de.react]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.remix]:[{version:w.gen1,recommended:!1},{version:w.gen2,recommended:!0}],[de.angular]:[{version:w.gen2,recommended:!0}],[de.next]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.qwik]:[{version:w.gen2,recommended:!0}]};async function Jo(e,t){let r=[],n=new Set;async function o(s){let u=e.join(s,"package.json");try{let p=await e.readFile(u);if(p===null)throw new Error(`Failed to read package.json at ${u}`);let m=JSON.parse(p);if(n.has(m.name))return null;n.add(m.name);let f={name:m.name,subPackages:[]},c=await e.readdir(s);for(let d of c)d!=="node_modules"&&(await e.stat(e.join(s,d))).isDirectory()&&f.subPackages.push(d);return r.push(f),f}catch(p){return console.error(`Error reading package.json at ${s}:`,p),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),u={...s.dependencies,...s.devDependencies};for(let p of Object.keys(u)){let m=e.join(t,"node_modules",p);await o(m)}if(s.workspaces)for(let p of s.workspaces){let m=await e.readdir(e.join(t,p));for(let f of m){let c=e.join(t,p,f);await o(c)}}}return r}var bu={"@builder.io/qwik-city":Qr,next:Lr,"@remix-run/react":to,react:lo,"@angular/core":Io},vu={"@builder.io/qwik-city":de.qwik,next:de.next,"@remix-run/react":de.remix,react:de.react,"@angular/core":de.angular};async function Qo(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await je(e)),e.frameworks.length===0)throw new Error("Supported Devtools framework for not found");for(let t of e.frameworks){let r=bu[t.name];if(r){if(t.name==="next"&&await tr(e))throw new Error("Turbopack does not support the Builder.io devtools cli. Please disable Turbopack or manually integrate Builder.io into your Next.js project.");let n=await r(e);return{...n,exportRegistry:()=>zo(e,n),importRegistry:i=>qo(e,n,i),framework:vu[t.name],findAllDependencies:async()=>await Jo(e,e.getRepoRootDir())}}}throw new Error(`Devtools framework not found for ${e.getAppRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Wo(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let d="",C=0,l=-1,D=0,g;for(let x=0;x<=f.length;++x){if(x<f.length)g=f.charCodeAt(x);else{if(g===47)break;g=47}if(g===47){if(!(l===x-1||D===1))if(l!==x-1&&D===2){if(d.length<2||C!==2||d.charCodeAt(d.length-1)!==46||d.charCodeAt(d.length-2)!==46){if(d.length>2){let E=d.lastIndexOf("/");if(E!==d.length-1){E===-1?(d="",C=0):(d=d.slice(0,E),C=d.length-1-d.lastIndexOf("/")),l=x,D=0;continue}}else if(d.length===2||d.length===1){d="",C=0,l=x,D=0;continue}}c&&(d.length>0?d+="/..":d="..",C=2)}else d.length>0?d+="/"+f.slice(l+1,x):d=f.slice(l+1,x),C=x-l-1;l=x,D=0}else g===46&&D!==-1?++D:D=-1}return d}let n=function(...c){let d="",C=!1;for(let l=c.length-1;l>=-1&&!C;l--){let D;l>=0?D=c[l]:e.cwd?D=e.cwd():D="/",t(D),D.length!==0&&(d=D+"/"+d,C=D.charCodeAt(0)===47)}return d=r(d,!C),C?d.length>0?"/"+d:"/":d.length>0?d:"."},o=function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0)===47,C=c.charCodeAt(c.length-1)===47;return c=r(c,!d),c.length===0&&!d&&(c="."),c.length>0&&C&&(c+="/"),d?"/"+c:c};return{relative:function(c,d){if(t(c),t(d),c===d||(c=n(c),d=n(d),c===d))return"";let C=1;for(;C<c.length&&c.charCodeAt(C)===47;++C);let l=c.length,D=l-C,g=1;for(;g<d.length&&d.charCodeAt(g)===47;++g);let E=d.length-g,P=D<E?D:E,A=-1,S=0;for(;S<=P;++S){if(S===P){if(E>P){if(d.charCodeAt(g+S)===47)return d.slice(g+S+1);if(S===0)return d.slice(g+S)}else D>P&&(c.charCodeAt(C+S)===47?A=S:S===0&&(A=0));break}let z=c.charCodeAt(C+S),j=d.charCodeAt(g+S);if(z!==j)break;z===47&&(A=S)}let O="";for(S=C+A+1;S<=l;++S)(S===l||c.charCodeAt(S)===47)&&(O.length===0?O+="..":O+="/..");return O.length>0?O+d.slice(g+A):(g+=A,d.charCodeAt(g)===47&&++g,d.slice(g))},resolve:n,join:function(...c){if(c.length===0)return".";let d;for(let C=0;C<c.length;++C){let l=c[C];t(l),l.length>0&&(d===void 0?d=l:d+="/"+l)}return d===void 0?".":o(d)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,d){if(d!==void 0&&typeof d!="string")throw new TypeError('"ext" argument must be a string');t(c);let C=0,l=-1,D=!0,g;if(d!==void 0&&d.length>0&&d.length<=c.length){if(d.length===c.length&&d===c)return"";let x=d.length-1,E=-1;for(g=c.length-1;g>=0;--g){let P=c.charCodeAt(g);if(P===47){if(!D){C=g+1;break}}else E===-1&&(D=!1,E=g+1),x>=0&&(P===d.charCodeAt(x)?--x===-1&&(l=g):(x=-1,l=E))}return C===l?l=E:l===-1&&(l=c.length),c.slice(C,l)}else{for(g=c.length-1;g>=0;--g)if(c.charCodeAt(g)===47){if(!D){C=g+1;break}}else l===-1&&(D=!1,l=g+1);return l===-1?"":c.slice(C,l)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0),C=d===47,l=-1,D=!0;for(let g=c.length-1;g>=1;--g)if(d=c.charCodeAt(g),d===47){if(!D){l=g;break}}else D=!1;return l===-1?C?"/":".":C&&l===1?"//":c.slice(0,l)},extname:function(c){t(c);let d=-1,C=0,l=-1,D=!0,g=0;for(let x=c.length-1;x>=0;--x){let E=c.charCodeAt(x);if(E===47){if(!D){C=x+1;break}continue}l===-1&&(D=!1,l=x+1),E===46?d===-1?d=x:g!==1&&(g=1):d!==-1&&(g=-1)}return d===-1||l===-1||g===0||g===1&&d===l-1&&d===C+1?"":c.slice(d,l)}}}async function Yo(e){let t=e.getRepoRootDir?e.getRepoRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Wo({cwd:r,...e}),o=new Map,i=l=>n.normalize(n.resolve(r(),l)),a=l=>{for(let[D]of o)if((D+"/").startsWith(l))return!0;return l===t()},s=l=>(l=i(l),o.has(l)?!0:a(l)),u=l=>{l=i(l);let D=l===t()?l:l+"/",g=D.split("/").length-1,x=[];for(let[E]of o)if(E.split("/").slice(0,g).join("/")+"/"===D){let S=E.split("/")[g];S&&!x.includes(S)&&x.push(S)}return x.sort()},p=l=>{l=i(l);let D=o.get(l);return typeof D=="string"?D:null},m=l=>(l=i(l),{isFile:()=>o.has(l),isDirectory:()=>!o.has(l)&&a(l)}),f=async l=>{if(typeof crypto<"u"){let x=new TextEncoder().encode(l),E=await crypto.subtle.digest("SHA-256",x);return Array.from(new Uint8Array(E)).map(P=>P.toString(16).padStart(2,"0")).join("")}let D=0;for(let g=0;g<l.length;g++){let x=l.charCodeAt(g);D=(D<<5)-D+x,D|=0}return Number(Math.abs(D)).toString(36)},c=new Set,d={getRepoRootDir:t,getAppRootDir:t,getCwdDir:r,cwd:r,exists:async l=>s(l),existsSync:s,readdir:async l=>u(l),readdirSync:u,readFile:async l=>p(l),readdirRecursive:async(l,D)=>u(l)??[],readFileSync:p,stat:async l=>m(l),statSync:m,writeFile:async(l,D)=>{l=i(l),o.set(l,D);let g={path:l,basename:n.basename(l),dirname:n.dirname(l),extname:n.extname(l)};for(let x of c)await x(g)},unlink:async l=>{l=i(l),o.delete(l)},unlinkSync:l=>{l=i(l),o.delete(l)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(l,D)=>D,on:(l,D)=>{l==="change"&&c.add(D)},off:(l,D)=>{l==="change"&&c.delete(D)},debug:(...l)=>{console.debug("[builder-dev-tools]",...l)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null,magicast:void 0,spawnSync:void 0,Sentry:void 0},C=await je(d);return d.getFrameworks=e.getFrameworks?e.getFrameworks:()=>C,d}async function Go(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Ho(e,n))return o;let a=ue(e,n,"cjs"),s=ue(e,n);if(a.length!==1&&s.length!==1)throw new Error("Expected an export from file");if(s.length===1){let m=s[0];if(!m.isDefaultExport)throw new Error("Expected a default export from file");let f=m.statement;if(!e.ts.isVariableStatement(f))throw new Error(`Unexpected export type in ${t}
|
|
916
|
+
`.trimStart()}async function bo(e){await Jt(e);let t=await e.readFile(e.registryPath);return t?Zs(e,t):{components:[],sourceFile:I(e,"")}}async function Zs(e,t){let r=I(e,t);return eu(e,r)}async function eu(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await bn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function bn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=K(a)),n.importName=a;let u=await he(e,e.registryPath,t,a);if(!u)continue;if(n.filePath=u.filePath,n.relFilePath=u.relFilePath,await e.exists(u.filePath)?n.importPath=V(e,u.filePath):(n.externalImportPath=u.importPath,n.importPath=n.externalImportPath),n.displayFilePath=u.displayFilePath,n.exportType=u.exportType,n.externalImportPath)n.exportName=a;else{let p=await go(e,u.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let m=p.find(f=>f.cmpInfo.exportName===a);m&&(n.exportName=m.cmpInfo.exportName)}}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await $(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ve(e,t,r,n,o,i,a,s){let u=await Me(e),[p,m,f]=await Promise.all([fo(e,u),bo(e),Pt(e)]),c=p.map(x=>x.cmpInfo),d=m.components,C={components:me(c,d),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ee(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return C.components=await Do(e,p,C.components),C;let l=!1,D=m.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let x=g.map(A=>{let S=p.find(O=>O.cmpInfo.id===A);if(!S)throw new Error(`Component ${A} not found`);return S}),E=Array.from(new Set(x.map(A=>A.cmpInfo.filePath))),P=await G(e,E);for(let A of x){let S=C.components.find(L=>L.id===A.cmpInfo.id),O=await En(e,A,P);ie(S,O);let z=c.findIndex(L=>L.id===A.cmpInfo.id);c[z].inputs=O;let j=Pe(A.cmpInfo.id,c,d,r,n,o,i),{elements:F,elmIndex:y,statementIndex:H,statement:le,variableDeclaration:Y}=await nu(e,D,A);if(j.addCmpToRegistry)F.push(tu(e,j.addCmpToRegistry)),l=!0;else if(j.removeCmpFromRegistry)F.splice(y,1),l=!0;else if(j.updateRegisteredCmp){let L=Q(e,F[y],j.updateRegisteredCmp);F[y]=e.ts.factory.updateObjectLiteralExpression(L,[vo(e,j.updateRegisteredCmp),...L.properties.slice(1)]),l=!0}if(l&&a){let L=[...D.statements];L[H]=e.ts.factory.updateVariableStatement(le,le.modifiers,e.ts.factory.updateVariableDeclarationList(le.declarationList,[e.ts.factory.updateVariableDeclaration(Y,Y.name,Y.exclamationToken,Y.type,e.ts.factory.createArrayLiteralExpression(Ae(e,F)))])),D=e.ts.factory.updateSourceFile(D,L),S.exportType==="named"?D=v(e,D,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}):D=v(e,D,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}),D=v(e,D,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),D=ye(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),C.components=j.components,d=j.components.filter(X=>X.isRegistered)}}}if(l&&a){D=Fe(e,D),D=Se(e,D);let x=_(e,D);x=pe(x),x=await e.formatCode(e.registryPath,x),await e.writeFile(e.registryPath,x)}return C}function vo(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function tu(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([vo(e,t)],!0),t)}async function nu(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await bn(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Io(e){let t=await ru(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>yo(t),ensureFigmaImportPage:()=>wo(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>ve(t,null,!1,!1,null,null,!1,!!o?.readAllInputTypes),addExternalPackage:async o=>{r[o]||(r[o]=`export * from "${o}";`)},loadComponent:async o=>{let i=await ve(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>ve(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>ve(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>ve(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>ve(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Pt(t),setPublicApiKey:o=>co(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>De(t),setCache:o=>Ce(t,o)}}async function ru(e){let t=await ou(e),r=e.getAppRootDir(),n=e.join(r,"src"),o=await re(e),i=e.join(n,"app"),a=await ae(e,i),s={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:a,angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);s.srcDir=n,s.appDir=i,s.componentsDir=e.join(s.appDir,"components"),s.builderPageComponentPath=e.join(s.componentsDir,`builder-page.component.${o?"ts":"js"}`);let u=`app.module.${o?"ts":"js"}`,p=e.join(s.appDir,u);return await e.exists(p)&&(s.hasAppModule=!0),s}async function ou(e){let t=e.join(e.getAppRootDir(),"angular.json");if(await e.exists(t))return t;let r=e.join(e.getAppRootDir(),"project.json");if(await e.exists(r))return r;throw new Error(`Could not find Angular config file. Searched for angular.json & project.json in "${e.getAppRootDir()}".`)}var Xt=Qn(Uo(),1);async function zo(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:ce(e.relative(e.getAppRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:oe(i.inputs)};return oe(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,Xt.compress)(n);return btoa(JSON.stringify(o))}async function qo(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,Xt.decompress)(o),a=oe(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let u=ce(e.normalize(s.filePath)),p=n.components.find(f=>ce(f.filePath).endsWith(u)&&f.exportName===s.exportName);if(!p){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${p.id})`,p.filePath),await t.registerComponent({cmpId:p.id});for(let f of s.inputs)e.debug(`set input (${p.id})`),await t.setRegisteredComponentInput({cmpId:p.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${p.id}) info`);let m=await t.setRegisteredComponentInfo({cmpId:p.id,name:s.name,image:s.image,description:s.description});a=oe(m)}return a}var de={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Ad={[de.react]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.remix]:[{version:w.gen1,recommended:!1},{version:w.gen2,recommended:!0}],[de.angular]:[{version:w.gen2,recommended:!0}],[de.next]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.qwik]:[{version:w.gen2,recommended:!0}]};async function Jo(e,t){let r=[],n=new Set;async function o(s){let u=e.join(s,"package.json");try{let p=await e.readFile(u);if(p===null)throw new Error(`Failed to read package.json at ${u}`);let m=JSON.parse(p);if(n.has(m.name))return null;n.add(m.name);let f={name:m.name,subPackages:[]},c=await e.readdir(s);for(let d of c)d!=="node_modules"&&(await e.stat(e.join(s,d))).isDirectory()&&f.subPackages.push(d);return r.push(f),f}catch(p){return console.error(`Error reading package.json at ${s}:`,p),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),u={...s.dependencies,...s.devDependencies};for(let p of Object.keys(u)){let m=e.join(t,"node_modules",p);await o(m)}if(s.workspaces)for(let p of s.workspaces){let m=await e.readdir(e.join(t,p));for(let f of m){let c=e.join(t,p,f);await o(c)}}}return r}var bu={"@builder.io/qwik-city":Qr,next:Lr,"@remix-run/react":to,react:lo,"@angular/core":Io},vu={"@builder.io/qwik-city":de.qwik,next:de.next,"@remix-run/react":de.remix,react:de.react,"@angular/core":de.angular};async function Qo(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await je(e)),e.frameworks.length===0)throw new Error("Supported Devtools framework for not found");for(let t of e.frameworks){let r=bu[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>zo(e,n),importRegistry:i=>qo(e,n,i),framework:vu[t.name],findAllDependencies:async()=>await Jo(e,e.getRepoRootDir())}}}throw new Error(`Devtools framework not found for ${e.getAppRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Wo(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let d="",C=0,l=-1,D=0,g;for(let x=0;x<=f.length;++x){if(x<f.length)g=f.charCodeAt(x);else{if(g===47)break;g=47}if(g===47){if(!(l===x-1||D===1))if(l!==x-1&&D===2){if(d.length<2||C!==2||d.charCodeAt(d.length-1)!==46||d.charCodeAt(d.length-2)!==46){if(d.length>2){let E=d.lastIndexOf("/");if(E!==d.length-1){E===-1?(d="",C=0):(d=d.slice(0,E),C=d.length-1-d.lastIndexOf("/")),l=x,D=0;continue}}else if(d.length===2||d.length===1){d="",C=0,l=x,D=0;continue}}c&&(d.length>0?d+="/..":d="..",C=2)}else d.length>0?d+="/"+f.slice(l+1,x):d=f.slice(l+1,x),C=x-l-1;l=x,D=0}else g===46&&D!==-1?++D:D=-1}return d}let n=function(...c){let d="",C=!1;for(let l=c.length-1;l>=-1&&!C;l--){let D;l>=0?D=c[l]:e.cwd?D=e.cwd():D="/",t(D),D.length!==0&&(d=D+"/"+d,C=D.charCodeAt(0)===47)}return d=r(d,!C),C?d.length>0?"/"+d:"/":d.length>0?d:"."},o=function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0)===47,C=c.charCodeAt(c.length-1)===47;return c=r(c,!d),c.length===0&&!d&&(c="."),c.length>0&&C&&(c+="/"),d?"/"+c:c};return{relative:function(c,d){if(t(c),t(d),c===d||(c=n(c),d=n(d),c===d))return"";let C=1;for(;C<c.length&&c.charCodeAt(C)===47;++C);let l=c.length,D=l-C,g=1;for(;g<d.length&&d.charCodeAt(g)===47;++g);let E=d.length-g,P=D<E?D:E,A=-1,S=0;for(;S<=P;++S){if(S===P){if(E>P){if(d.charCodeAt(g+S)===47)return d.slice(g+S+1);if(S===0)return d.slice(g+S)}else D>P&&(c.charCodeAt(C+S)===47?A=S:S===0&&(A=0));break}let z=c.charCodeAt(C+S),j=d.charCodeAt(g+S);if(z!==j)break;z===47&&(A=S)}let O="";for(S=C+A+1;S<=l;++S)(S===l||c.charCodeAt(S)===47)&&(O.length===0?O+="..":O+="/..");return O.length>0?O+d.slice(g+A):(g+=A,d.charCodeAt(g)===47&&++g,d.slice(g))},resolve:n,join:function(...c){if(c.length===0)return".";let d;for(let C=0;C<c.length;++C){let l=c[C];t(l),l.length>0&&(d===void 0?d=l:d+="/"+l)}return d===void 0?".":o(d)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,d){if(d!==void 0&&typeof d!="string")throw new TypeError('"ext" argument must be a string');t(c);let C=0,l=-1,D=!0,g;if(d!==void 0&&d.length>0&&d.length<=c.length){if(d.length===c.length&&d===c)return"";let x=d.length-1,E=-1;for(g=c.length-1;g>=0;--g){let P=c.charCodeAt(g);if(P===47){if(!D){C=g+1;break}}else E===-1&&(D=!1,E=g+1),x>=0&&(P===d.charCodeAt(x)?--x===-1&&(l=g):(x=-1,l=E))}return C===l?l=E:l===-1&&(l=c.length),c.slice(C,l)}else{for(g=c.length-1;g>=0;--g)if(c.charCodeAt(g)===47){if(!D){C=g+1;break}}else l===-1&&(D=!1,l=g+1);return l===-1?"":c.slice(C,l)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0),C=d===47,l=-1,D=!0;for(let g=c.length-1;g>=1;--g)if(d=c.charCodeAt(g),d===47){if(!D){l=g;break}}else D=!1;return l===-1?C?"/":".":C&&l===1?"//":c.slice(0,l)},extname:function(c){t(c);let d=-1,C=0,l=-1,D=!0,g=0;for(let x=c.length-1;x>=0;--x){let E=c.charCodeAt(x);if(E===47){if(!D){C=x+1;break}continue}l===-1&&(D=!1,l=x+1),E===46?d===-1?d=x:g!==1&&(g=1):d!==-1&&(g=-1)}return d===-1||l===-1||g===0||g===1&&d===l-1&&d===C+1?"":c.slice(d,l)}}}async function Yo(e){let t=e.getRepoRootDir?e.getRepoRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Wo({cwd:r,...e}),o=new Map,i=l=>n.normalize(n.resolve(r(),l)),a=l=>{for(let[D]of o)if((D+"/").startsWith(l))return!0;return l===t()},s=l=>(l=i(l),o.has(l)?!0:a(l)),u=l=>{l=i(l);let D=l===t()?l:l+"/",g=D.split("/").length-1,x=[];for(let[E]of o)if(E.split("/").slice(0,g).join("/")+"/"===D){let S=E.split("/")[g];S&&!x.includes(S)&&x.push(S)}return x.sort()},p=l=>{l=i(l);let D=o.get(l);return typeof D=="string"?D:null},m=l=>(l=i(l),{isFile:()=>o.has(l),isDirectory:()=>!o.has(l)&&a(l)}),f=async l=>{if(typeof crypto<"u"){let x=new TextEncoder().encode(l),E=await crypto.subtle.digest("SHA-256",x);return Array.from(new Uint8Array(E)).map(P=>P.toString(16).padStart(2,"0")).join("")}let D=0;for(let g=0;g<l.length;g++){let x=l.charCodeAt(g);D=(D<<5)-D+x,D|=0}return Number(Math.abs(D)).toString(36)},c=new Set,d={getRepoRootDir:t,getAppRootDir:t,getCwdDir:r,cwd:r,exists:async l=>s(l),existsSync:s,readdir:async l=>u(l),readdirSync:u,readFile:async l=>p(l),readdirRecursive:async(l,D)=>u(l)??[],readFileSync:p,stat:async l=>m(l),statSync:m,writeFile:async(l,D)=>{l=i(l),o.set(l,D);let g={path:l,basename:n.basename(l),dirname:n.dirname(l),extname:n.extname(l)};for(let x of c)await x(g)},unlink:async l=>{l=i(l),o.delete(l)},unlinkSync:l=>{l=i(l),o.delete(l)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(l,D)=>D,on:(l,D)=>{l==="change"&&c.add(D)},off:(l,D)=>{l==="change"&&c.delete(D)},debug:(...l)=>{console.debug("[builder-dev-tools]",...l)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null,magicast:void 0,spawnSync:void 0,Sentry:void 0},C=await je(d);return d.getFrameworks=e.getFrameworks?e.getFrameworks:()=>C,d}async function Go(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(await tr(e))return console.warn("Turbopack does not support the Builder.io devtools cli. Please disable Turbopack or manually integrate Builder.io into your Next.js project."),o;if(Ho(e,n))return o;let s=ue(e,n,"cjs"),u=ue(e,n);if(s.length!==1&&u.length!==1)throw new Error("Expected an export from file");if(u.length===1){let f=u[0];if(!f.isDefaultExport)throw new Error("Expected a default export from file");let c=f.statement;if(!e.ts.isVariableStatement(c))throw new Error(`Unexpected export type in ${t}
|
|
917
917
|
Found config content:
|
|
918
918
|
${r}
|
|
919
919
|
|
|
@@ -926,7 +926,7 @@ The config file must follow one of these formats:
|
|
|
926
926
|
|
|
927
927
|
3. export default { /* config */ }
|
|
928
928
|
|
|
929
|
-
Current export type: ${
|
|
929
|
+
Current export type: ${c.kind?e.ts.SyntaxKind[c.kind]:"none"}`);let d=f.statement;if(e.ts.isVariableStatement(d)){let C=[...d.declarationList.declarations];if(C.length!==1)throw new Error("Expected a single variable declaration");let l=C[0];if(!l.initializer)throw new Error("Expected an initializer on the declaration");let D=l.initializer;if(e.ts.isObjectLiteralExpression(D)||e.ts.isCallExpression(D)){let g="BuilderDevTools()",x=[...n.statements],E=x.indexOf(d);return x[E]=e.ts.factory.updateVariableStatement(d,d.modifiers,e.ts.factory.updateVariableDeclarationList(d.declarationList,[e.ts.factory.updateVariableDeclaration(l,l.name,l.exclamationToken,l.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[D]))])),n=e.ts.factory.updateSourceFile(n,x),n=v(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error(`Unexpected initializer on the variable statement in file
|
|
930
930
|
Found config content:
|
|
931
931
|
${r}
|
|
932
932
|
|
|
@@ -934,15 +934,15 @@ The config variable must be initialized with either:
|
|
|
934
934
|
1. An object literal: const nextConfig = { /* config */ }
|
|
935
935
|
2. A function call: const nextConfig = withSomePlugin({ /* config */ })
|
|
936
936
|
|
|
937
|
-
Current initializer type: ${
|
|
938
|
-
Expected types: ObjectLiteralExpression or CallExpression`)}}let
|
|
937
|
+
Current initializer type: ${D?.kind?e.ts.SyntaxKind[D.kind]:"none"}
|
|
938
|
+
Expected types: ObjectLiteralExpression or CallExpression`)}}let p=s[0];if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}
|
|
939
939
|
Found config content:
|
|
940
940
|
${r}
|
|
941
|
-
Detected export type: ${
|
|
941
|
+
Detected export type: ${p?.statement.kind??"none"}
|
|
942
942
|
Valid formats:
|
|
943
943
|
1. module.exports = { ... }
|
|
944
944
|
2. module.exports = (phase, config) => { return { ... } }
|
|
945
|
-
3. export default { ... }`);if(e.ts.isObjectLiteralExpression(
|
|
945
|
+
3. export default { ... }`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let f=p.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let d=Mn(e,n);n=d.sourceFile;let C=[...n.statements],l=C.indexOf(f);return C[l]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d.withFnVariableName),void 0,[c.right]))),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}let m=p.statement;if(e.ts.isVariableStatement(m)){let f=[...m.declarationList.declarations];if(f.length!==1)throw new Error("Expected a single variable declaration");let c=f[0];if(!c.initializer)throw new Error("Expected an initializer on the declaration");let d=c.initializer;if(e.ts.isObjectLiteralExpression(d)||e.ts.isCallExpression(d)){let C=Mn(e,n);n=C.sourceFile;let l=[...n.statements],D=l.indexOf(m);return l[D]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(c,c.name,c.exclamationToken,c.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[d]))])),n=e.ts.factory.updateSourceFile(n,l),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error(`Unexpected initializer on the variable statement in ${t}
|
|
946
946
|
Found config content:
|
|
947
947
|
${r}
|
|
948
948
|
|
|
@@ -950,8 +950,8 @@ The config variable must be initialized with either:
|
|
|
950
950
|
1. An object literal: const nextConfig = { /* config */ }
|
|
951
951
|
2. A function call: const nextConfig = withSomePlugin({ /* config */ })
|
|
952
952
|
|
|
953
|
-
Current initializer type: ${
|
|
954
|
-
Expected types: ${e.ts.SyntaxKind.ObjectLiteralExpression} or ${e.ts.SyntaxKind.CallExpression}`)}if(e.ts.isArrowFunction(u.node)){let m=u.node,f=u.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let C=u.node.body;if(!e.ts.isBlock(C))throw new Error("Expected a block body on the next config function");let l=[...C.statements],D=l.findIndex(A=>e.ts.isReturnStatement(A));if(D===-1)throw new Error("Expected a return statement on the next config function");let g=l[D],x=Mn(e,n);n=x.sourceFile,l[D]=e.ts.factory.updateReturnStatement(g,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(x.withFnVariableName),void 0,[g.expression]));let E=[...n.statements],P=E.indexOf(f);return E[P]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.updateArrowFunction(m,m.modifiers,m.typeParameters,m.parameters,m.type,m.equalsGreaterThanToken,e.ts.factory.updateBlock(C,l)))),n=e.ts.factory.updateSourceFile(n,E),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Ho(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Mn(e,t){let r=Ho(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function ei(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(ti(e,n))return o;let a=ue(e,n,"cjs"),s=ue(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let u=a[0];if(s.length===1){let m=s[0];if(!m.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=m.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",d=Iu(e,f.expression);if(!d)return o;let C=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[d]),l=[...n.statements],D=l.indexOf(f);return l[D]=e.ts.factory.updateExportAssignment(f,f.modifiers,C),n=e.ts.factory.updateSourceFile(n,l),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=_(e,n),o.hasContentUpdates=!0,o}}if(!u.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(u.node)||e.ts.isCallExpression(u.node)){let m=u.statement;if(!e.ts.isExpressionStatement(m))throw new Error("Expected an expression statement for the default export");let f=m.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Xo(e,n);n=c.sourceFile;let d=[...n.statements],C=d.indexOf(m);return d[C]=e.ts.factory.updateExpressionStatement(m,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,d),o.content=_(e,n),o.hasContentUpdates=!0,o}let p=u.statement;if(e.ts.isVariableStatement(p)){let m=[...p.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let f=m[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let d=Xo(e,n);n=d.sourceFile;let C=[...n.statements],l=C.indexOf(p);return C[l]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function ti(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Xo(e,t){let r=ti(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function Iu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Zo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Zo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Zo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function ri(e,t,r){try{let n=I(e,r),o=ue(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let u=[...i.node.arguments];if(u.length===0)throw new Error("Expected an argument in defineConfig()");let p=u[0];if(e.ts.isArrowFunction(p)){let m=Ru(e,p);if(!m)return s;u[0]=e.ts.factory.updateArrowFunction(p,p.modifiers,p.typeParameters,p.parameters,p.type,p.equalsGreaterThanToken,m);let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,u)),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(p)){let m=Un(e,p);if(!m)return s;let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[m])),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let u=Un(e,a.expression);if(!u)return s;let p=[...n.statements],m=p.indexOf(a);return p[m]=e.ts.factory.updateExportAssignment(a,a.modifiers,u),n=e.ts.factory.updateSourceFile(n,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Ru(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=Un(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function Un(e,t){if(Ou(e)){let i=Nu(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=ni(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=ni(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function ni(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function Nu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Bu(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=zn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function Bu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=zn(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=zn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function zn(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Ou(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function oi(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function ai(e,t,r){e.debug("Angular config updates are currently in progress...");try{await _u(e)}catch{console.error("Unable to update package.json.")}return await ku(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function ku(e){let t=e.getAppRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await Lu(e,o);await e.writeFile(n,i)}async function Lu(e,t){let r=t,n=I(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
953
|
+
Current initializer type: ${d.kind}
|
|
954
|
+
Expected types: ${e.ts.SyntaxKind.ObjectLiteralExpression} or ${e.ts.SyntaxKind.CallExpression}`)}if(e.ts.isArrowFunction(p.node)){let f=p.node,c=p.statement;if(!e.ts.isExpressionStatement(c))throw new Error("Expected an expression statement for the default export");let d=c.expression;if(!e.ts.isBinaryExpression(d))throw new Error("Expected a binary expression for the default export");let l=p.node.body;if(!e.ts.isBlock(l))throw new Error("Expected a block body on the next config function");let D=[...l.statements],g=D.findIndex(S=>e.ts.isReturnStatement(S));if(g===-1)throw new Error("Expected a return statement on the next config function");let x=D[g],E=Mn(e,n);n=E.sourceFile,D[g]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(E.withFnVariableName),void 0,[x.expression]));let P=[...n.statements],A=P.indexOf(c);return P[A]=e.ts.factory.updateExpressionStatement(c,e.ts.factory.updateBinaryExpression(d,d.left,d.operatorToken,e.ts.factory.updateArrowFunction(f,f.modifiers,f.typeParameters,f.parameters,f.type,f.equalsGreaterThanToken,e.ts.factory.updateBlock(l,D)))),n=e.ts.factory.updateSourceFile(n,P),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Ho(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Mn(e,t){let r=Ho(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function ei(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(ti(e,n))return o;let a=ue(e,n,"cjs"),s=ue(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let u=a[0];if(s.length===1){let m=s[0];if(!m.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=m.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",d=Iu(e,f.expression);if(!d)return o;let C=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[d]),l=[...n.statements],D=l.indexOf(f);return l[D]=e.ts.factory.updateExportAssignment(f,f.modifiers,C),n=e.ts.factory.updateSourceFile(n,l),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=_(e,n),o.hasContentUpdates=!0,o}}if(!u.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(u.node)||e.ts.isCallExpression(u.node)){let m=u.statement;if(!e.ts.isExpressionStatement(m))throw new Error("Expected an expression statement for the default export");let f=m.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Xo(e,n);n=c.sourceFile;let d=[...n.statements],C=d.indexOf(m);return d[C]=e.ts.factory.updateExpressionStatement(m,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,d),o.content=_(e,n),o.hasContentUpdates=!0,o}let p=u.statement;if(e.ts.isVariableStatement(p)){let m=[...p.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let f=m[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let d=Xo(e,n);n=d.sourceFile;let C=[...n.statements],l=C.indexOf(p);return C[l]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function ti(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Xo(e,t){let r=ti(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function Iu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Zo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Zo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Zo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function ri(e,t,r){try{let n=I(e,r),o=ue(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let u=[...i.node.arguments];if(u.length===0)throw new Error("Expected an argument in defineConfig()");let p=u[0];if(e.ts.isArrowFunction(p)){let m=Ru(e,p);if(!m)return s;u[0]=e.ts.factory.updateArrowFunction(p,p.modifiers,p.typeParameters,p.parameters,p.type,p.equalsGreaterThanToken,m);let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,u)),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(p)){let m=Un(e,p);if(!m)return s;let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[m])),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let u=Un(e,a.expression);if(!u)return s;let p=[...n.statements],m=p.indexOf(a);return p[m]=e.ts.factory.updateExportAssignment(a,a.modifiers,u),n=e.ts.factory.updateSourceFile(n,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Ru(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=Un(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function Un(e,t){if(Ou(e)){let i=Nu(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=ni(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=ni(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function ni(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function Nu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Bu(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=zn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function Bu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=zn(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=zn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function zn(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Ou(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function oi(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function ai(e,t,r){e.debug("Angular config updates are currently in progress...");try{await _u(e)}catch{console.error("Unable to update package.json.")}return await ku(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function ku(e){let t=e.getAppRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await Lu(e,o);await e.writeFile(n,i)}async function Lu(e,t){let r=t,n=I(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
955
955
|
builderDevTools().catch((err: Error) =>
|
|
956
956
|
console.error("Error starting dev tools:", err)
|
|
957
957
|
);`;return r=_(e,n),o||(r+=i),r}async function _u(e){let t=e.getRepoRootDir(),r=e.join(t,"package.json"),n=await e.readFile(r);if(!n)throw new Error(`Unable to read package.json at ${r}`);let o=ju(e,n);o&&await e.writeFile(r,o)}function ju(e,t){let r=JSON.parse(t);if(r.scripts=r.scripts||{},r.scripts[ii])return;let n=r.scripts.start||r.scripts.dev||"ng serve";if(!n.includes("concurrently")){let o=e.getRepoRootDir(),i=e.getAppRootDir(),a=o===i?"":` --cwd ${e.relative(o,i)}`,s=`concurrently "${n}" "${Vu}${a}"`;r.scripts.start=s,r.scripts[ii]=s}return JSON.stringify(r,null,2)+`
|
|
@@ -974,4 +974,4 @@ module.exports = nextConfig
|
|
|
974
974
|
`,n+=` }
|
|
975
975
|
`,n+=` }
|
|
976
976
|
`,n+=`})();
|
|
977
|
-
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var It="1.5.
|
|
977
|
+
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var It="1.5.10";
|
package/core/index.mjs
CHANGED
|
@@ -913,7 +913,7 @@ export class Counter {
|
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
915
|
|
|
916
|
-
`.trimStart()}async function wo(e){await zt(e);let t=await e.readFile(e.registryPath);return t?Qs(e,t):{components:[],sourceFile:I(e,"")}}async function Qs(e,t){let r=I(e,t);return Ws(e,r)}async function Ws(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await yn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function yn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=K(a)),n.importName=a;let u=await he(e,e.registryPath,t,a);if(!u)continue;if(n.filePath=u.filePath,n.relFilePath=u.relFilePath,await e.exists(u.filePath)?n.importPath=V(e,u.filePath):(n.externalImportPath=u.importPath,n.importPath=n.externalImportPath),n.displayFilePath=u.displayFilePath,n.exportType=u.exportType,n.externalImportPath)n.exportName=a;else{let p=await mo(e,u.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let m=p.find(f=>f.cmpInfo.exportName===a);m&&(n.exportName=m.cmpInfo.exportName)}}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await $(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ve(e,t,r,n,o,i,a,s){let u=await Ke(e),[p,m,f]=await Promise.all([co(e,u),wo(e),Pt(e)]),c=p.map(x=>x.cmpInfo),d=m.components,C={components:me(c,d),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ee(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return C.components=await fo(e,p,C.components),C;let l=!1,D=m.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let x=g.map(A=>{let S=p.find(O=>O.cmpInfo.id===A);if(!S)throw new Error(`Component ${A} not found`);return S}),E=Array.from(new Set(x.map(A=>A.cmpInfo.filePath))),P=await G(e,E);for(let A of x){let S=C.components.find(L=>L.id===A.cmpInfo.id),O=await Cn(e,A,P);ie(S,O);let z=c.findIndex(L=>L.id===A.cmpInfo.id);c[z].inputs=O;let j=Pe(A.cmpInfo.id,c,d,r,n,o,i),{elements:F,elmIndex:y,statementIndex:H,statement:le,variableDeclaration:Y}=await Gs(e,D,A);if(j.addCmpToRegistry)F.push(Ys(e,j.addCmpToRegistry)),l=!0;else if(j.removeCmpFromRegistry)F.splice(y,1),l=!0;else if(j.updateRegisteredCmp){let L=Q(e,F[y],j.updateRegisteredCmp);F[y]=e.ts.factory.updateObjectLiteralExpression(L,[To(e,j.updateRegisteredCmp),...L.properties.slice(1)]),l=!0}if(l&&a){let L=[...D.statements];L[H]=e.ts.factory.updateVariableStatement(le,le.modifiers,e.ts.factory.updateVariableDeclarationList(le.declarationList,[e.ts.factory.updateVariableDeclaration(Y,Y.name,Y.exclamationToken,Y.type,e.ts.factory.createArrayLiteralExpression(Ae(e,F)))])),D=e.ts.factory.updateSourceFile(D,L),S.exportType==="named"?D=v(e,D,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}):D=v(e,D,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}),D=v(e,D,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),D=ye(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),C.components=j.components,d=j.components.filter(X=>X.isRegistered)}}}if(l&&a){D=Fe(e,D),D=Se(e,D);let x=_(e,D);x=pe(x),x=await e.formatCode(e.registryPath,x),await e.writeFile(e.registryPath,x)}return C}function To(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Ys(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([To(e,t)],!0),t)}async function Gs(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await yn(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function bo(e){let t=await Hs(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Fo(t),ensureFigmaImportPage:()=>Po(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>ve(t,null,!1,!1,null,null,!1,!!o?.readAllInputTypes),addExternalPackage:async o=>{r[o]||(r[o]=`export * from "${o}";`)},loadComponent:async o=>{let i=await ve(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>ve(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>ve(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>ve(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>ve(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Pt(t),setPublicApiKey:o=>po(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>De(t),setCache:o=>Ce(t,o)}}async function Hs(e){let t=await Xs(e),r=e.getAppRootDir(),n=e.join(r,"src"),o=await re(e),i=e.join(n,"app"),a=await ae(e,i),s={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:a,angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);s.srcDir=n,s.appDir=i,s.componentsDir=e.join(s.appDir,"components"),s.builderPageComponentPath=e.join(s.componentsDir,`builder-page.component.${o?"ts":"js"}`);let u=`app.module.${o?"ts":"js"}`,p=e.join(s.appDir,u);return await e.exists(p)&&(s.hasAppModule=!0),s}async function Xs(e){let t=e.join(e.getAppRootDir(),"angular.json");if(await e.exists(t))return t;let r=e.join(e.getAppRootDir(),"project.json");if(await e.exists(r))return r;throw new Error(`Could not find Angular config file. Searched for angular.json & project.json in "${e.getAppRootDir()}".`)}var Gt=Un(Ko(),1);async function Mo(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:ce(e.relative(e.getAppRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:oe(i.inputs)};return oe(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,Gt.compress)(n);return btoa(JSON.stringify(o))}async function Uo(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,Gt.decompress)(o),a=oe(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let u=ce(e.normalize(s.filePath)),p=n.components.find(f=>ce(f.filePath).endsWith(u)&&f.exportName===s.exportName);if(!p){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${p.id})`,p.filePath),await t.registerComponent({cmpId:p.id});for(let f of s.inputs)e.debug(`set input (${p.id})`),await t.setRegisteredComponentInput({cmpId:p.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${p.id}) info`);let m=await t.setRegisteredComponentInfo({cmpId:p.id,name:s.name,image:s.image,description:s.description});a=oe(m)}return a}var de={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},hd={[de.react]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.remix]:[{version:w.gen1,recommended:!1},{version:w.gen2,recommended:!0}],[de.angular]:[{version:w.gen2,recommended:!0}],[de.next]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.qwik]:[{version:w.gen2,recommended:!0}]};async function zo(e,t){let r=[],n=new Set;async function o(s){let u=e.join(s,"package.json");try{let p=await e.readFile(u);if(p===null)throw new Error(`Failed to read package.json at ${u}`);let m=JSON.parse(p);if(n.has(m.name))return null;n.add(m.name);let f={name:m.name,subPackages:[]},c=await e.readdir(s);for(let d of c)d!=="node_modules"&&(await e.stat(e.join(s,d))).isDirectory()&&f.subPackages.push(d);return r.push(f),f}catch(p){return console.error(`Error reading package.json at ${s}:`,p),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),u={...s.dependencies,...s.devDependencies};for(let p of Object.keys(u)){let m=e.join(t,"node_modules",p);await o(m)}if(s.workspaces)for(let p of s.workspaces){let m=await e.readdir(e.join(t,p));for(let f of m){let c=e.join(t,p,f);await o(c)}}}return r}var Au={"@builder.io/qwik-city":qr,next:Or,"@remix-run/react":Zr,react:uo,"@angular/core":bo},Fu={"@builder.io/qwik-city":de.qwik,next:de.next,"@remix-run/react":de.remix,react:de.react,"@angular/core":de.angular};async function Pu(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await Je(e)),e.frameworks.length===0)throw new Error("Supported Devtools framework for not found");for(let t of e.frameworks){let r=Au[t.name];if(r){if(t.name==="next"&&await Hn(e))throw new Error("Turbopack does not support the Builder.io devtools cli. Please disable Turbopack or manually integrate Builder.io into your Next.js project.");let n=await r(e);return{...n,exportRegistry:()=>Mo(e,n),importRegistry:i=>Uo(e,n,i),framework:Fu[t.name],findAllDependencies:async()=>await zo(e,e.getRepoRootDir())}}}throw new Error(`Devtools framework not found for ${e.getAppRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function qo(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let d="",C=0,l=-1,D=0,g;for(let x=0;x<=f.length;++x){if(x<f.length)g=f.charCodeAt(x);else{if(g===47)break;g=47}if(g===47){if(!(l===x-1||D===1))if(l!==x-1&&D===2){if(d.length<2||C!==2||d.charCodeAt(d.length-1)!==46||d.charCodeAt(d.length-2)!==46){if(d.length>2){let E=d.lastIndexOf("/");if(E!==d.length-1){E===-1?(d="",C=0):(d=d.slice(0,E),C=d.length-1-d.lastIndexOf("/")),l=x,D=0;continue}}else if(d.length===2||d.length===1){d="",C=0,l=x,D=0;continue}}c&&(d.length>0?d+="/..":d="..",C=2)}else d.length>0?d+="/"+f.slice(l+1,x):d=f.slice(l+1,x),C=x-l-1;l=x,D=0}else g===46&&D!==-1?++D:D=-1}return d}let n=function(...c){let d="",C=!1;for(let l=c.length-1;l>=-1&&!C;l--){let D;l>=0?D=c[l]:e.cwd?D=e.cwd():D="/",t(D),D.length!==0&&(d=D+"/"+d,C=D.charCodeAt(0)===47)}return d=r(d,!C),C?d.length>0?"/"+d:"/":d.length>0?d:"."},o=function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0)===47,C=c.charCodeAt(c.length-1)===47;return c=r(c,!d),c.length===0&&!d&&(c="."),c.length>0&&C&&(c+="/"),d?"/"+c:c};return{relative:function(c,d){if(t(c),t(d),c===d||(c=n(c),d=n(d),c===d))return"";let C=1;for(;C<c.length&&c.charCodeAt(C)===47;++C);let l=c.length,D=l-C,g=1;for(;g<d.length&&d.charCodeAt(g)===47;++g);let E=d.length-g,P=D<E?D:E,A=-1,S=0;for(;S<=P;++S){if(S===P){if(E>P){if(d.charCodeAt(g+S)===47)return d.slice(g+S+1);if(S===0)return d.slice(g+S)}else D>P&&(c.charCodeAt(C+S)===47?A=S:S===0&&(A=0));break}let z=c.charCodeAt(C+S),j=d.charCodeAt(g+S);if(z!==j)break;z===47&&(A=S)}let O="";for(S=C+A+1;S<=l;++S)(S===l||c.charCodeAt(S)===47)&&(O.length===0?O+="..":O+="/..");return O.length>0?O+d.slice(g+A):(g+=A,d.charCodeAt(g)===47&&++g,d.slice(g))},resolve:n,join:function(...c){if(c.length===0)return".";let d;for(let C=0;C<c.length;++C){let l=c[C];t(l),l.length>0&&(d===void 0?d=l:d+="/"+l)}return d===void 0?".":o(d)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,d){if(d!==void 0&&typeof d!="string")throw new TypeError('"ext" argument must be a string');t(c);let C=0,l=-1,D=!0,g;if(d!==void 0&&d.length>0&&d.length<=c.length){if(d.length===c.length&&d===c)return"";let x=d.length-1,E=-1;for(g=c.length-1;g>=0;--g){let P=c.charCodeAt(g);if(P===47){if(!D){C=g+1;break}}else E===-1&&(D=!1,E=g+1),x>=0&&(P===d.charCodeAt(x)?--x===-1&&(l=g):(x=-1,l=E))}return C===l?l=E:l===-1&&(l=c.length),c.slice(C,l)}else{for(g=c.length-1;g>=0;--g)if(c.charCodeAt(g)===47){if(!D){C=g+1;break}}else l===-1&&(D=!1,l=g+1);return l===-1?"":c.slice(C,l)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0),C=d===47,l=-1,D=!0;for(let g=c.length-1;g>=1;--g)if(d=c.charCodeAt(g),d===47){if(!D){l=g;break}}else D=!1;return l===-1?C?"/":".":C&&l===1?"//":c.slice(0,l)},extname:function(c){t(c);let d=-1,C=0,l=-1,D=!0,g=0;for(let x=c.length-1;x>=0;--x){let E=c.charCodeAt(x);if(E===47){if(!D){C=x+1;break}continue}l===-1&&(D=!1,l=x+1),E===46?d===-1?d=x:g!==1&&(g=1):d!==-1&&(g=-1)}return d===-1||l===-1||g===0||g===1&&d===l-1&&d===C+1?"":c.slice(d,l)}}}async function yu(e){let t=e.getRepoRootDir?e.getRepoRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=qo({cwd:r,...e}),o=new Map,i=l=>n.normalize(n.resolve(r(),l)),a=l=>{for(let[D]of o)if((D+"/").startsWith(l))return!0;return l===t()},s=l=>(l=i(l),o.has(l)?!0:a(l)),u=l=>{l=i(l);let D=l===t()?l:l+"/",g=D.split("/").length-1,x=[];for(let[E]of o)if(E.split("/").slice(0,g).join("/")+"/"===D){let S=E.split("/")[g];S&&!x.includes(S)&&x.push(S)}return x.sort()},p=l=>{l=i(l);let D=o.get(l);return typeof D=="string"?D:null},m=l=>(l=i(l),{isFile:()=>o.has(l),isDirectory:()=>!o.has(l)&&a(l)}),f=async l=>{if(typeof crypto<"u"){let x=new TextEncoder().encode(l),E=await crypto.subtle.digest("SHA-256",x);return Array.from(new Uint8Array(E)).map(P=>P.toString(16).padStart(2,"0")).join("")}let D=0;for(let g=0;g<l.length;g++){let x=l.charCodeAt(g);D=(D<<5)-D+x,D|=0}return Number(Math.abs(D)).toString(36)},c=new Set,d={getRepoRootDir:t,getAppRootDir:t,getCwdDir:r,cwd:r,exists:async l=>s(l),existsSync:s,readdir:async l=>u(l),readdirSync:u,readFile:async l=>p(l),readdirRecursive:async(l,D)=>u(l)??[],readFileSync:p,stat:async l=>m(l),statSync:m,writeFile:async(l,D)=>{l=i(l),o.set(l,D);let g={path:l,basename:n.basename(l),dirname:n.dirname(l),extname:n.extname(l)};for(let x of c)await x(g)},unlink:async l=>{l=i(l),o.delete(l)},unlinkSync:l=>{l=i(l),o.delete(l)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(l,D)=>D,on:(l,D)=>{l==="change"&&c.add(D)},off:(l,D)=>{l==="change"&&c.delete(D)},debug:(...l)=>{console.debug("[builder-dev-tools]",...l)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null,magicast:void 0,spawnSync:void 0,Sentry:void 0},C=await Je(d);return d.getFrameworks=e.getFrameworks?e.getFrameworks:()=>C,d}async function Jo(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Qo(e,n))return o;let a=ue(e,n,"cjs"),s=ue(e,n);if(a.length!==1&&s.length!==1)throw new Error("Expected an export from file");if(s.length===1){let m=s[0];if(!m.isDefaultExport)throw new Error("Expected a default export from file");let f=m.statement;if(!e.ts.isVariableStatement(f))throw new Error(`Unexpected export type in ${t}
|
|
916
|
+
`.trimStart()}async function wo(e){await zt(e);let t=await e.readFile(e.registryPath);return t?Qs(e,t):{components:[],sourceFile:I(e,"")}}async function Qs(e,t){let r=I(e,t);return Ws(e,r)}async function Ws(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await yn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function yn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=K(a)),n.importName=a;let u=await he(e,e.registryPath,t,a);if(!u)continue;if(n.filePath=u.filePath,n.relFilePath=u.relFilePath,await e.exists(u.filePath)?n.importPath=V(e,u.filePath):(n.externalImportPath=u.importPath,n.importPath=n.externalImportPath),n.displayFilePath=u.displayFilePath,n.exportType=u.exportType,n.externalImportPath)n.exportName=a;else{let p=await mo(e,u.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let m=p.find(f=>f.cmpInfo.exportName===a);m&&(n.exportName=m.cmpInfo.exportName)}}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await $(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ve(e,t,r,n,o,i,a,s){let u=await Ke(e),[p,m,f]=await Promise.all([co(e,u),wo(e),Pt(e)]),c=p.map(x=>x.cmpInfo),d=m.components,C={components:me(c,d),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ee(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return C.components=await fo(e,p,C.components),C;let l=!1,D=m.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let x=g.map(A=>{let S=p.find(O=>O.cmpInfo.id===A);if(!S)throw new Error(`Component ${A} not found`);return S}),E=Array.from(new Set(x.map(A=>A.cmpInfo.filePath))),P=await G(e,E);for(let A of x){let S=C.components.find(L=>L.id===A.cmpInfo.id),O=await Cn(e,A,P);ie(S,O);let z=c.findIndex(L=>L.id===A.cmpInfo.id);c[z].inputs=O;let j=Pe(A.cmpInfo.id,c,d,r,n,o,i),{elements:F,elmIndex:y,statementIndex:H,statement:le,variableDeclaration:Y}=await Gs(e,D,A);if(j.addCmpToRegistry)F.push(Ys(e,j.addCmpToRegistry)),l=!0;else if(j.removeCmpFromRegistry)F.splice(y,1),l=!0;else if(j.updateRegisteredCmp){let L=Q(e,F[y],j.updateRegisteredCmp);F[y]=e.ts.factory.updateObjectLiteralExpression(L,[To(e,j.updateRegisteredCmp),...L.properties.slice(1)]),l=!0}if(l&&a){let L=[...D.statements];L[H]=e.ts.factory.updateVariableStatement(le,le.modifiers,e.ts.factory.updateVariableDeclarationList(le.declarationList,[e.ts.factory.updateVariableDeclaration(Y,Y.name,Y.exclamationToken,Y.type,e.ts.factory.createArrayLiteralExpression(Ae(e,F)))])),D=e.ts.factory.updateSourceFile(D,L),S.exportType==="named"?D=v(e,D,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}):D=v(e,D,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:B(e,e.registryPath,S.filePath)}),D=v(e,D,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),D=ye(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),C.components=j.components,d=j.components.filter(X=>X.isRegistered)}}}if(l&&a){D=Fe(e,D),D=Se(e,D);let x=_(e,D);x=pe(x),x=await e.formatCode(e.registryPath,x),await e.writeFile(e.registryPath,x)}return C}function To(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Ys(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([To(e,t)],!0),t)}async function Gs(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await yn(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function bo(e){let t=await Hs(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Fo(t),ensureFigmaImportPage:()=>Po(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>ve(t,null,!1,!1,null,null,!1,!!o?.readAllInputTypes),addExternalPackage:async o=>{r[o]||(r[o]=`export * from "${o}";`)},loadComponent:async o=>{let i=await ve(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>ve(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>ve(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>ve(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>ve(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Pt(t),setPublicApiKey:o=>po(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>De(t),setCache:o=>Ce(t,o)}}async function Hs(e){let t=await Xs(e),r=e.getAppRootDir(),n=e.join(r,"src"),o=await re(e),i=e.join(n,"app"),a=await ae(e,i),s={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:a,angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);s.srcDir=n,s.appDir=i,s.componentsDir=e.join(s.appDir,"components"),s.builderPageComponentPath=e.join(s.componentsDir,`builder-page.component.${o?"ts":"js"}`);let u=`app.module.${o?"ts":"js"}`,p=e.join(s.appDir,u);return await e.exists(p)&&(s.hasAppModule=!0),s}async function Xs(e){let t=e.join(e.getAppRootDir(),"angular.json");if(await e.exists(t))return t;let r=e.join(e.getAppRootDir(),"project.json");if(await e.exists(r))return r;throw new Error(`Could not find Angular config file. Searched for angular.json & project.json in "${e.getAppRootDir()}".`)}var Gt=Un(Ko(),1);async function Mo(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:ce(e.relative(e.getAppRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:oe(i.inputs)};return oe(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,Gt.compress)(n);return btoa(JSON.stringify(o))}async function Uo(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,Gt.decompress)(o),a=oe(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let u=ce(e.normalize(s.filePath)),p=n.components.find(f=>ce(f.filePath).endsWith(u)&&f.exportName===s.exportName);if(!p){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${p.id})`,p.filePath),await t.registerComponent({cmpId:p.id});for(let f of s.inputs)e.debug(`set input (${p.id})`),await t.setRegisteredComponentInput({cmpId:p.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${p.id}) info`);let m=await t.setRegisteredComponentInfo({cmpId:p.id,name:s.name,image:s.image,description:s.description});a=oe(m)}return a}var de={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},hd={[de.react]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.remix]:[{version:w.gen1,recommended:!1},{version:w.gen2,recommended:!0}],[de.angular]:[{version:w.gen2,recommended:!0}],[de.next]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[de.qwik]:[{version:w.gen2,recommended:!0}]};async function zo(e,t){let r=[],n=new Set;async function o(s){let u=e.join(s,"package.json");try{let p=await e.readFile(u);if(p===null)throw new Error(`Failed to read package.json at ${u}`);let m=JSON.parse(p);if(n.has(m.name))return null;n.add(m.name);let f={name:m.name,subPackages:[]},c=await e.readdir(s);for(let d of c)d!=="node_modules"&&(await e.stat(e.join(s,d))).isDirectory()&&f.subPackages.push(d);return r.push(f),f}catch(p){return console.error(`Error reading package.json at ${s}:`,p),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),u={...s.dependencies,...s.devDependencies};for(let p of Object.keys(u)){let m=e.join(t,"node_modules",p);await o(m)}if(s.workspaces)for(let p of s.workspaces){let m=await e.readdir(e.join(t,p));for(let f of m){let c=e.join(t,p,f);await o(c)}}}return r}var Au={"@builder.io/qwik-city":qr,next:Or,"@remix-run/react":Zr,react:uo,"@angular/core":bo},Fu={"@builder.io/qwik-city":de.qwik,next:de.next,"@remix-run/react":de.remix,react:de.react,"@angular/core":de.angular};async function Pu(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await Je(e)),e.frameworks.length===0)throw new Error("Supported Devtools framework for not found");for(let t of e.frameworks){let r=Au[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Mo(e,n),importRegistry:i=>Uo(e,n,i),framework:Fu[t.name],findAllDependencies:async()=>await zo(e,e.getRepoRootDir())}}}throw new Error(`Devtools framework not found for ${e.getAppRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function qo(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let d="",C=0,l=-1,D=0,g;for(let x=0;x<=f.length;++x){if(x<f.length)g=f.charCodeAt(x);else{if(g===47)break;g=47}if(g===47){if(!(l===x-1||D===1))if(l!==x-1&&D===2){if(d.length<2||C!==2||d.charCodeAt(d.length-1)!==46||d.charCodeAt(d.length-2)!==46){if(d.length>2){let E=d.lastIndexOf("/");if(E!==d.length-1){E===-1?(d="",C=0):(d=d.slice(0,E),C=d.length-1-d.lastIndexOf("/")),l=x,D=0;continue}}else if(d.length===2||d.length===1){d="",C=0,l=x,D=0;continue}}c&&(d.length>0?d+="/..":d="..",C=2)}else d.length>0?d+="/"+f.slice(l+1,x):d=f.slice(l+1,x),C=x-l-1;l=x,D=0}else g===46&&D!==-1?++D:D=-1}return d}let n=function(...c){let d="",C=!1;for(let l=c.length-1;l>=-1&&!C;l--){let D;l>=0?D=c[l]:e.cwd?D=e.cwd():D="/",t(D),D.length!==0&&(d=D+"/"+d,C=D.charCodeAt(0)===47)}return d=r(d,!C),C?d.length>0?"/"+d:"/":d.length>0?d:"."},o=function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0)===47,C=c.charCodeAt(c.length-1)===47;return c=r(c,!d),c.length===0&&!d&&(c="."),c.length>0&&C&&(c+="/"),d?"/"+c:c};return{relative:function(c,d){if(t(c),t(d),c===d||(c=n(c),d=n(d),c===d))return"";let C=1;for(;C<c.length&&c.charCodeAt(C)===47;++C);let l=c.length,D=l-C,g=1;for(;g<d.length&&d.charCodeAt(g)===47;++g);let E=d.length-g,P=D<E?D:E,A=-1,S=0;for(;S<=P;++S){if(S===P){if(E>P){if(d.charCodeAt(g+S)===47)return d.slice(g+S+1);if(S===0)return d.slice(g+S)}else D>P&&(c.charCodeAt(C+S)===47?A=S:S===0&&(A=0));break}let z=c.charCodeAt(C+S),j=d.charCodeAt(g+S);if(z!==j)break;z===47&&(A=S)}let O="";for(S=C+A+1;S<=l;++S)(S===l||c.charCodeAt(S)===47)&&(O.length===0?O+="..":O+="/..");return O.length>0?O+d.slice(g+A):(g+=A,d.charCodeAt(g)===47&&++g,d.slice(g))},resolve:n,join:function(...c){if(c.length===0)return".";let d;for(let C=0;C<c.length;++C){let l=c[C];t(l),l.length>0&&(d===void 0?d=l:d+="/"+l)}return d===void 0?".":o(d)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,d){if(d!==void 0&&typeof d!="string")throw new TypeError('"ext" argument must be a string');t(c);let C=0,l=-1,D=!0,g;if(d!==void 0&&d.length>0&&d.length<=c.length){if(d.length===c.length&&d===c)return"";let x=d.length-1,E=-1;for(g=c.length-1;g>=0;--g){let P=c.charCodeAt(g);if(P===47){if(!D){C=g+1;break}}else E===-1&&(D=!1,E=g+1),x>=0&&(P===d.charCodeAt(x)?--x===-1&&(l=g):(x=-1,l=E))}return C===l?l=E:l===-1&&(l=c.length),c.slice(C,l)}else{for(g=c.length-1;g>=0;--g)if(c.charCodeAt(g)===47){if(!D){C=g+1;break}}else l===-1&&(D=!1,l=g+1);return l===-1?"":c.slice(C,l)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let d=c.charCodeAt(0),C=d===47,l=-1,D=!0;for(let g=c.length-1;g>=1;--g)if(d=c.charCodeAt(g),d===47){if(!D){l=g;break}}else D=!1;return l===-1?C?"/":".":C&&l===1?"//":c.slice(0,l)},extname:function(c){t(c);let d=-1,C=0,l=-1,D=!0,g=0;for(let x=c.length-1;x>=0;--x){let E=c.charCodeAt(x);if(E===47){if(!D){C=x+1;break}continue}l===-1&&(D=!1,l=x+1),E===46?d===-1?d=x:g!==1&&(g=1):d!==-1&&(g=-1)}return d===-1||l===-1||g===0||g===1&&d===l-1&&d===C+1?"":c.slice(d,l)}}}async function yu(e){let t=e.getRepoRootDir?e.getRepoRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=qo({cwd:r,...e}),o=new Map,i=l=>n.normalize(n.resolve(r(),l)),a=l=>{for(let[D]of o)if((D+"/").startsWith(l))return!0;return l===t()},s=l=>(l=i(l),o.has(l)?!0:a(l)),u=l=>{l=i(l);let D=l===t()?l:l+"/",g=D.split("/").length-1,x=[];for(let[E]of o)if(E.split("/").slice(0,g).join("/")+"/"===D){let S=E.split("/")[g];S&&!x.includes(S)&&x.push(S)}return x.sort()},p=l=>{l=i(l);let D=o.get(l);return typeof D=="string"?D:null},m=l=>(l=i(l),{isFile:()=>o.has(l),isDirectory:()=>!o.has(l)&&a(l)}),f=async l=>{if(typeof crypto<"u"){let x=new TextEncoder().encode(l),E=await crypto.subtle.digest("SHA-256",x);return Array.from(new Uint8Array(E)).map(P=>P.toString(16).padStart(2,"0")).join("")}let D=0;for(let g=0;g<l.length;g++){let x=l.charCodeAt(g);D=(D<<5)-D+x,D|=0}return Number(Math.abs(D)).toString(36)},c=new Set,d={getRepoRootDir:t,getAppRootDir:t,getCwdDir:r,cwd:r,exists:async l=>s(l),existsSync:s,readdir:async l=>u(l),readdirSync:u,readFile:async l=>p(l),readdirRecursive:async(l,D)=>u(l)??[],readFileSync:p,stat:async l=>m(l),statSync:m,writeFile:async(l,D)=>{l=i(l),o.set(l,D);let g={path:l,basename:n.basename(l),dirname:n.dirname(l),extname:n.extname(l)};for(let x of c)await x(g)},unlink:async l=>{l=i(l),o.delete(l)},unlinkSync:l=>{l=i(l),o.delete(l)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(l,D)=>D,on:(l,D)=>{l==="change"&&c.add(D)},off:(l,D)=>{l==="change"&&c.delete(D)},debug:(...l)=>{console.debug("[builder-dev-tools]",...l)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null,magicast:void 0,spawnSync:void 0,Sentry:void 0},C=await Je(d);return d.getFrameworks=e.getFrameworks?e.getFrameworks:()=>C,d}async function Jo(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(await Hn(e))return console.warn("Turbopack does not support the Builder.io devtools cli. Please disable Turbopack or manually integrate Builder.io into your Next.js project."),o;if(Qo(e,n))return o;let s=ue(e,n,"cjs"),u=ue(e,n);if(s.length!==1&&u.length!==1)throw new Error("Expected an export from file");if(u.length===1){let f=u[0];if(!f.isDefaultExport)throw new Error("Expected a default export from file");let c=f.statement;if(!e.ts.isVariableStatement(c))throw new Error(`Unexpected export type in ${t}
|
|
917
917
|
Found config content:
|
|
918
918
|
${r}
|
|
919
919
|
|
|
@@ -926,7 +926,7 @@ The config file must follow one of these formats:
|
|
|
926
926
|
|
|
927
927
|
3. export default { /* config */ }
|
|
928
928
|
|
|
929
|
-
Current export type: ${
|
|
929
|
+
Current export type: ${c.kind?e.ts.SyntaxKind[c.kind]:"none"}`);let d=f.statement;if(e.ts.isVariableStatement(d)){let C=[...d.declarationList.declarations];if(C.length!==1)throw new Error("Expected a single variable declaration");let l=C[0];if(!l.initializer)throw new Error("Expected an initializer on the declaration");let D=l.initializer;if(e.ts.isObjectLiteralExpression(D)||e.ts.isCallExpression(D)){let g="BuilderDevTools()",x=[...n.statements],E=x.indexOf(d);return x[E]=e.ts.factory.updateVariableStatement(d,d.modifiers,e.ts.factory.updateVariableDeclarationList(d.declarationList,[e.ts.factory.updateVariableDeclaration(l,l.name,l.exclamationToken,l.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[D]))])),n=e.ts.factory.updateSourceFile(n,x),n=v(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error(`Unexpected initializer on the variable statement in file
|
|
930
930
|
Found config content:
|
|
931
931
|
${r}
|
|
932
932
|
|
|
@@ -934,15 +934,15 @@ The config variable must be initialized with either:
|
|
|
934
934
|
1. An object literal: const nextConfig = { /* config */ }
|
|
935
935
|
2. A function call: const nextConfig = withSomePlugin({ /* config */ })
|
|
936
936
|
|
|
937
|
-
Current initializer type: ${
|
|
938
|
-
Expected types: ObjectLiteralExpression or CallExpression`)}}let
|
|
937
|
+
Current initializer type: ${D?.kind?e.ts.SyntaxKind[D.kind]:"none"}
|
|
938
|
+
Expected types: ObjectLiteralExpression or CallExpression`)}}let p=s[0];if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}
|
|
939
939
|
Found config content:
|
|
940
940
|
${r}
|
|
941
|
-
Detected export type: ${
|
|
941
|
+
Detected export type: ${p?.statement.kind??"none"}
|
|
942
942
|
Valid formats:
|
|
943
943
|
1. module.exports = { ... }
|
|
944
944
|
2. module.exports = (phase, config) => { return { ... } }
|
|
945
|
-
3. export default { ... }`);if(e.ts.isObjectLiteralExpression(
|
|
945
|
+
3. export default { ... }`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let f=p.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let d=Vn(e,n);n=d.sourceFile;let C=[...n.statements],l=C.indexOf(f);return C[l]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d.withFnVariableName),void 0,[c.right]))),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}let m=p.statement;if(e.ts.isVariableStatement(m)){let f=[...m.declarationList.declarations];if(f.length!==1)throw new Error("Expected a single variable declaration");let c=f[0];if(!c.initializer)throw new Error("Expected an initializer on the declaration");let d=c.initializer;if(e.ts.isObjectLiteralExpression(d)||e.ts.isCallExpression(d)){let C=Vn(e,n);n=C.sourceFile;let l=[...n.statements],D=l.indexOf(m);return l[D]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(c,c.name,c.exclamationToken,c.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[d]))])),n=e.ts.factory.updateSourceFile(n,l),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error(`Unexpected initializer on the variable statement in ${t}
|
|
946
946
|
Found config content:
|
|
947
947
|
${r}
|
|
948
948
|
|
|
@@ -950,8 +950,8 @@ The config variable must be initialized with either:
|
|
|
950
950
|
1. An object literal: const nextConfig = { /* config */ }
|
|
951
951
|
2. A function call: const nextConfig = withSomePlugin({ /* config */ })
|
|
952
952
|
|
|
953
|
-
Current initializer type: ${
|
|
954
|
-
Expected types: ${e.ts.SyntaxKind.ObjectLiteralExpression} or ${e.ts.SyntaxKind.CallExpression}`)}if(e.ts.isArrowFunction(u.node)){let m=u.node,f=u.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let C=u.node.body;if(!e.ts.isBlock(C))throw new Error("Expected a block body on the next config function");let l=[...C.statements],D=l.findIndex(A=>e.ts.isReturnStatement(A));if(D===-1)throw new Error("Expected a return statement on the next config function");let g=l[D],x=Vn(e,n);n=x.sourceFile,l[D]=e.ts.factory.updateReturnStatement(g,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(x.withFnVariableName),void 0,[g.expression]));let E=[...n.statements],P=E.indexOf(f);return E[P]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.updateArrowFunction(m,m.modifiers,m.typeParameters,m.parameters,m.type,m.equalsGreaterThanToken,e.ts.factory.updateBlock(C,l)))),n=e.ts.factory.updateSourceFile(n,E),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Qo(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Vn(e,t){let r=Qo(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function Go(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Ho(e,n))return o;let a=ue(e,n,"cjs"),s=ue(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let u=a[0];if(s.length===1){let m=s[0];if(!m.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=m.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",d=wu(e,f.expression);if(!d)return o;let C=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[d]),l=[...n.statements],D=l.indexOf(f);return l[D]=e.ts.factory.updateExportAssignment(f,f.modifiers,C),n=e.ts.factory.updateSourceFile(n,l),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=_(e,n),o.hasContentUpdates=!0,o}}if(!u.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(u.node)||e.ts.isCallExpression(u.node)){let m=u.statement;if(!e.ts.isExpressionStatement(m))throw new Error("Expected an expression statement for the default export");let f=m.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Wo(e,n);n=c.sourceFile;let d=[...n.statements],C=d.indexOf(m);return d[C]=e.ts.factory.updateExpressionStatement(m,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,d),o.content=_(e,n),o.hasContentUpdates=!0,o}let p=u.statement;if(e.ts.isVariableStatement(p)){let m=[...p.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let f=m[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let d=Wo(e,n);n=d.sourceFile;let C=[...n.statements],l=C.indexOf(p);return C[l]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Ho(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Wo(e,t){let r=Ho(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function wu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Yo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Yo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Yo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function Zo(e,t,r){try{let n=I(e,r),o=ue(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let u=[...i.node.arguments];if(u.length===0)throw new Error("Expected an argument in defineConfig()");let p=u[0];if(e.ts.isArrowFunction(p)){let m=Tu(e,p);if(!m)return s;u[0]=e.ts.factory.updateArrowFunction(p,p.modifiers,p.typeParameters,p.parameters,p.type,p.equalsGreaterThanToken,m);let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,u)),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(p)){let m=$n(e,p);if(!m)return s;let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[m])),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let u=$n(e,a.expression);if(!u)return s;let p=[...n.statements],m=p.indexOf(a);return p[m]=e.ts.factory.updateExportAssignment(a,a.modifiers,u),n=e.ts.factory.updateSourceFile(n,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Tu(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=$n(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function $n(e,t){if(Iu(e)){let i=bu(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Xo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Xo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Xo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function bu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=vu(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Kn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function vu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Kn(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Kn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function Kn(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Iu(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function ei(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function ni(e,t,r){e.debug("Angular config updates are currently in progress...");try{await Bu(e)}catch{console.error("Unable to update package.json.")}return await Ru(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Ru(e){let t=e.getAppRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await Nu(e,o);await e.writeFile(n,i)}async function Nu(e,t){let r=t,n=I(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
953
|
+
Current initializer type: ${d.kind}
|
|
954
|
+
Expected types: ${e.ts.SyntaxKind.ObjectLiteralExpression} or ${e.ts.SyntaxKind.CallExpression}`)}if(e.ts.isArrowFunction(p.node)){let f=p.node,c=p.statement;if(!e.ts.isExpressionStatement(c))throw new Error("Expected an expression statement for the default export");let d=c.expression;if(!e.ts.isBinaryExpression(d))throw new Error("Expected a binary expression for the default export");let l=p.node.body;if(!e.ts.isBlock(l))throw new Error("Expected a block body on the next config function");let D=[...l.statements],g=D.findIndex(S=>e.ts.isReturnStatement(S));if(g===-1)throw new Error("Expected a return statement on the next config function");let x=D[g],E=Vn(e,n);n=E.sourceFile,D[g]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(E.withFnVariableName),void 0,[x.expression]));let P=[...n.statements],A=P.indexOf(c);return P[A]=e.ts.factory.updateExpressionStatement(c,e.ts.factory.updateBinaryExpression(d,d.left,d.operatorToken,e.ts.factory.updateArrowFunction(f,f.modifiers,f.typeParameters,f.parameters,f.type,f.equalsGreaterThanToken,e.ts.factory.updateBlock(l,D)))),n=e.ts.factory.updateSourceFile(n,P),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Qo(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Vn(e,t){let r=Qo(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function Go(e,t,r){try{let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Ho(e,n))return o;let a=ue(e,n,"cjs"),s=ue(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let u=a[0];if(s.length===1){let m=s[0];if(!m.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=m.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",d=wu(e,f.expression);if(!d)return o;let C=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[d]),l=[...n.statements],D=l.indexOf(f);return l[D]=e.ts.factory.updateExportAssignment(f,f.modifiers,C),n=e.ts.factory.updateSourceFile(n,l),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=_(e,n),o.hasContentUpdates=!0,o}}if(!u.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(u.node)||e.ts.isCallExpression(u.node)){let m=u.statement;if(!e.ts.isExpressionStatement(m))throw new Error("Expected an expression statement for the default export");let f=m.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Wo(e,n);n=c.sourceFile;let d=[...n.statements],C=d.indexOf(m);return d[C]=e.ts.factory.updateExpressionStatement(m,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,d),o.content=_(e,n),o.hasContentUpdates=!0,o}let p=u.statement;if(e.ts.isVariableStatement(p)){let m=[...p.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let f=m[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let d=Wo(e,n);n=d.sourceFile;let C=[...n.statements],l=C.indexOf(p);return C[l]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Ho(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Wo(e,t){let r=Ho(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function wu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Yo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Yo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Yo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function Zo(e,t,r){try{let n=I(e,r),o=ue(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let u=[...i.node.arguments];if(u.length===0)throw new Error("Expected an argument in defineConfig()");let p=u[0];if(e.ts.isArrowFunction(p)){let m=Tu(e,p);if(!m)return s;u[0]=e.ts.factory.updateArrowFunction(p,p.modifiers,p.typeParameters,p.parameters,p.type,p.equalsGreaterThanToken,m);let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,u)),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(p)){let m=$n(e,p);if(!m)return s;let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[m])),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let u=$n(e,a.expression);if(!u)return s;let p=[...n.statements],m=p.indexOf(a);return p[m]=e.ts.factory.updateExportAssignment(a,a.modifiers,u),n=e.ts.factory.updateSourceFile(n,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}catch(n){throw e.Sentry?.captureException(n,{extra:{configFilePath:t,configContent:r}}),n}}function Tu(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=$n(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function $n(e,t){if(Iu(e)){let i=bu(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Xo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Xo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Xo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function bu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=vu(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Kn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function vu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Kn(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Kn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function Kn(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Iu(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function ei(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function ni(e,t,r){e.debug("Angular config updates are currently in progress...");try{await Bu(e)}catch{console.error("Unable to update package.json.")}return await Ru(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Ru(e){let t=e.getAppRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await Nu(e,o);await e.writeFile(n,i)}async function Nu(e,t){let r=t,n=I(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
955
955
|
builderDevTools().catch((err: Error) =>
|
|
956
956
|
console.error("Error starting dev tools:", err)
|
|
957
957
|
);`;return r=_(e,n),o||(r+=i),r}async function Bu(e){let t=e.getRepoRootDir(),r=e.join(t,"package.json"),n=await e.readFile(r);if(!n)throw new Error(`Unable to read package.json at ${r}`);let o=Ou(e,n);o&&await e.writeFile(r,o)}function Ou(e,t){let r=JSON.parse(t);if(r.scripts=r.scripts||{},r.scripts[ti])return;let n=r.scripts.start||r.scripts.dev||"ng serve";if(!n.includes("concurrently")){let o=e.getRepoRootDir(),i=e.getAppRootDir(),a=o===i?"":` --cwd ${e.relative(o,i)}`,s=`concurrently "${n}" "${ku}${a}"`;r.scripts.start=s,r.scripts[ti]=s}return JSON.stringify(r,null,2)+`
|
|
@@ -974,4 +974,4 @@ module.exports = nextConfig
|
|
|
974
974
|
`,n+=` }
|
|
975
975
|
`,n+=` }
|
|
976
976
|
`,n+=`})();
|
|
977
|
-
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var Ht="1.5.
|
|
977
|
+
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var Ht="1.5.10";export{Pu as createDevTools,yu as createDevToolsSys,Je as detectFrameworks,Xn as detectFrameworksFromPackageJson,Lu as ensureConfigPlugin,ii as findBuildToolConfig,_u as getClientScript,er as parseDotEnvContent,Ht as version};
|
package/node/index.cjs
CHANGED
|
@@ -101,6 +101,6 @@ ${" ".repeat(6+r)}^`),c));s+=`
|
|
|
101
101
|
${l.join(`
|
|
102
102
|
`)}
|
|
103
103
|
`}this.message=s}},Cc=new Set(["Literal","StringLiteral","NumericLiteral","BooleanLiteral","NullLiteral","RegExpLiteral","BigIntLiteral"]),Yn=new Set(["string","number","boolean","bigint","symbol","undefined"]),ee=yt;function Ic(i){return/^[$A-Z_a-z][\w$]*$/.test(i)}var qr="__magicast_proxy";function ce(i,s=new Set){if(i===void 0)return ee.identifier("undefined");if(i===null)return ee.literal(null);if(Yn.has(typeof i))return ee.literal(i);if(s.has(i))throw new re("Can not serialize circular reference");if(s.add(i),i[qr])return i.$ast;if(i instanceof RegExp){let e=ee.regExpLiteral(i.source,i.flags);return delete e.extra.raw,e}return i instanceof Set?ee.newExpression(ee.identifier("Set"),[ee.arrayExpression([...i].map(e=>ce(e,s)))]):i instanceof Date?ee.newExpression(ee.identifier("Date"),[ee.literal(i.toISOString())]):i instanceof Map?ee.newExpression(ee.identifier("Map"),[ee.arrayExpression([...i].map(([e,t])=>ee.arrayExpression([ce(e,s),ce(t,s)])))]):Array.isArray(i)?ee.arrayExpression(i.map(e=>ce(e,s))):typeof i=="object"?ee.objectExpression(Object.entries(i).map(([e,t])=>ee.property("init",/^[$A-Z_a-z][\w$]*$/g.test(e)?ee.identifier(e):ee.literal(e),ce(t,s)))):ee.literal(i)}function Nc(i,s={}){let e=s;return e[qr]=!0,e.$ast=i,e.$type||(e.$type="object"),e}var kc={enumerable:!0,configurable:!0};function be(i,s,e){let t=Nc(i,s);return new Proxy({},{ownKeys(){return Object.keys(t).filter(r=>r!==qr&&!r.startsWith("$"))},getOwnPropertyDescriptor(){return kc},has(r,n){return n in t},...e,get(r,n,a){if(n in t)return t[n];if(e.get)return e.get(r,n,a)},set(r,n,a,o){return n in t?(t[n]=a,!0):e.set?e.set(r,n,a,o):!1}})}var de=yt,Ir=new WeakMap;function Lc(i,s,e){if(Ir.has(s))return Ir.get(s);let t=be(s,{get $declaration(){return i},get imported(){return s.type==="ImportDefaultSpecifier"?"default":s.type==="ImportNamespaceSpecifier"?"*":s.imported.type==="Identifier"?s.imported.name:s.imported.value},set imported(r){if(s.type!=="ImportSpecifier")throw new re("Changing import name is not yet implemented");s.imported.type==="Identifier"?s.imported.name=r:s.imported.value=r},get local(){return s.local.name},set local(r){s.local.name=r},get from(){return i.source.value},set from(r){if(r===i.source.value)return;i.specifiers=i.specifiers.filter(a=>a!==s),i.specifiers.length===0&&(e.body=e.body.filter(a=>a!==i));let n=e.body.find(a=>a.type==="ImportDeclaration"&&a.source.value===r);n?n.specifiers.push(s):e.body.unshift(de.importDeclaration([s],de.stringLiteral(r)))},toJSON(){return{imported:this.imported,local:this.local,from:this.from}}},{ownKeys(){return["imported","local","from","toJSON"]}});return Ir.set(s,t),t}function Dc(i,s){let e=()=>{let a=[];for(let o of i.body)if(o.type==="ImportDeclaration")for(let l of o.specifiers)a.push(Lc(o,l,i));return a},t=(a,o,l)=>{let c=e(),u=c.find(p=>p.local===a),h=o.local||a;if(u)return u.imported=o.imported,u.local=h,u.from=o.from,!0;let f=o.imported==="default"?de.importDefaultSpecifier(de.identifier(h)):o.imported==="*"?de.importNamespaceSpecifier(de.identifier(h)):de.importSpecifier(de.identifier(o.imported),de.identifier(h)),d=c.find(p=>p.from===o.from)?.$declaration;if(d)d.specifiers.push(f);else if(l==="prepend"||c.length===0)i.body.unshift(de.importDeclaration([f],de.stringLiteral(o.from)));else{let p=c.at(-1).$declaration,g=i.body.indexOf(p);i.body.splice(g+1,0,de.importDeclaration([f],de.stringLiteral(o.from)))}return!0},r=a=>{let o=e().find(u=>u.local===a);if(!o)return!1;let l=o.$declaration,c=o.$ast;return l.specifiers=l.specifiers.filter(u=>u!==c),l.specifiers.length===0&&(i.body=i.body.filter(u=>u!==l)),!0};return be(i,{$type:"imports",$add(a){t(a.local||a.imported,a,"prepend")},$prepend(a){t(a.local||a.imported,a,"prepend")},$append(a){t(a.local||a.imported,a,"append")},get $items(){return e()},toJSON(){return e().reduce((a,o)=>(a[o.local]=o,a),{})}},{get(a,o){return e().find(l=>l.local===o)},set(a,o,l){return t(o,l,"prepend")},deleteProperty(a,o){return r(o)},ownKeys(){return e().map(a=>a.local)},has(a,o){return e().some(l=>l.local===o)}})}function Cs(i,s,e){let t=n=>s[n],r=(n,a)=>{s[n]=a};return be(i,{$type:"array",push(n){s.push(ce(n))},pop(){return le(s.pop(),e)},unshift(n){s.unshift(ce(n))},shift(){return le(s.shift(),e)},splice(n,a,...o){return s.splice(n,a,...o.map(c=>ce(c))).map(c=>le(c,e))},find(n){return s.map(a=>le(a,e)).find(n)},findIndex(n){return s.map(a=>le(a,e)).findIndex(n)},includes(n){return s.map(a=>le(a,e)).includes(n)},toJSON(){return s.map(n=>le(n,e))}},{get(n,a){if(a==="length")return s.length;if(a===Symbol.iterator)return function*(){for(let c of s)yield le(c,e)};if(typeof a=="symbol")return;let o=+a;if(Number.isNaN(o))return;let l=t(o);if(l)return le(l,e)},set(n,a,o){if(typeof a=="symbol")return!1;let l=+a;return Number.isNaN(l)?!1:(r(l,ce(o)),!0)},deleteProperty(n,a){if(typeof a=="symbol")return!1;let o=+a;return Number.isNaN(o)?!1:(s[o]=ce(void 0),!0)},ownKeys(){return["length",...s.map((n,a)=>a.toString())]}})}function Oc(i,s){if("elements"in i)return Cs(i,i.elements,s)}function Zn(i,s){if(i.type!=="CallExpression")throw new re("Not a function call");function e(r){if(r.type==="Identifier")return r.name;if(r.type==="MemberExpression")return`${e(r.object)}.${e(r.property)}`;throw new re("Not implemented")}let t=Cs(i,i.arguments,s);return be(i,{$type:"function-call",$callee:e(i.callee),$args:t},{})}function Mc(i,s){if(i.type!=="ArrowFunctionExpression")throw new re("Not an arrow function expression");let e=Cs(i,i.params,s);return be(i,{$type:"arrow-function-expression",$params:e,$body:le(i.body,s)},{})}var Fc=yt;function Bc(i,s){if(!("properties"in i))return;let e=n=>{for(let a of i.properties){if("key"in a&&"name"in a.key&&a.key.name===n)return a.value;if(a.type==="ObjectProperty"&&(a.key.type==="StringLiteral"||a.key.type==="NumericLiteral"||a.key.type==="BooleanLiteral")&&a.key.value.toString()===n)return a.value.value??a.value}},t=(n,a=!1)=>{if("key"in n&&"name"in n.key)return n.key.name;if(n.type==="ObjectProperty"&&(n.key.type==="StringLiteral"||n.key.type==="NumericLiteral"||n.key.type==="BooleanLiteral"))return n.key.value.toString();if(a)throw new re(`Casting "${n.type}" is not supported`,{ast:n,code:s?.$code})},r=(n,a)=>{let o=i.properties.find(l=>t(l)===n);o?o.value=a:Ic(n)?i.properties.push({type:"Property",key:{type:"Identifier",name:n},value:a}):i.properties.push({type:"ObjectProperty",key:Fc.stringLiteral(n),value:a})};return be(i,{$type:"object",toJSON(){return i.properties.reduce((n,a)=>("key"in a&&"name"in a.key&&(n[a.key.name]=le(a.value,s)),n),{})}},{get(n,a){let o=e(a);if(o)return le(o,s)},set(n,a,o){return typeof a!="string"&&(a=String(a)),r(a,ce(o)),!0},deleteProperty(n,a){typeof a!="string"&&(a=String(a));let o=i.properties.findIndex(l=>"key"in l&&"name"in l.key&&l.key.name===a);return o!==-1&&i.properties.splice(o,1),!0},ownKeys(){return i.properties.map(n=>t(n,!0)).filter(Boolean)}})}function ea(i,s){if(i.type!=="NewExpression")throw new re("Not a new expression");function e(r){if(r.type==="Identifier")return r.name;if(r.type==="MemberExpression")return`${e(r.object)}.${e(r.property)}`;throw new re("Not implemented")}let t=Cs(i,i.arguments,s);return be(i,{$type:"new-expression",$callee:e(i.callee),$args:t},{})}function _c(i){if(i.type!=="Identifier")throw new re("Not an identifier");return be(i,{$type:"identifier",$name:i.name},{})}function jc(i){if(i.type!=="LogicalExpression")throw new re("Not a logical expression");return be(i,{$type:"logicalExpression"},{})}function Rc(i){if(i.type!=="MemberExpression")throw new re("Not a member expression");return be(i,{$type:"memberExpression"},{})}var Nr=new WeakMap;function le(i,s){if(Yn.has(typeof i))return i;if(Cc.has(i.type))return i.value;if(Nr.has(i))return Nr.get(i);let e;switch(i.type){case"ObjectExpression":{e=Bc(i,s);break}case"ArrayExpression":{e=Oc(i,s);break}case"CallExpression":{e=Zn(i,s);break}case"ArrowFunctionExpression":{e=Mc(i,s);break}case"NewExpression":{e=ea(i,s);break}case"Identifier":{e=_c(i);break}case"LogicalExpression":{e=jc(i);break}case"MemberExpression":{e=Rc(i);break}case"TSAsExpression":case"TSSatisfiesExpression":{e=le(i.expression,s);break}default:throw new re(`Casting "${i.type}" is not supported`,{ast:i,code:s?.$code})}return Nr.set(i,e),e}var _t=yt;function Uc(i,s){let e=r=>{let n=r==="default"?"ExportDefaultDeclaration":"ExportNamedDeclaration";for(let a of i.body)if(a.type===n){if(r==="default")return a.declaration;if(a.declaration&&"declarations"in a.declaration){let o=a.declaration.declarations[0];if("name"in o.id&&o.id.name===r)return o.init}}},t=(r,n)=>{let a=r==="default"?"ExportDefaultDeclaration":"ExportNamedDeclaration",o=ce(n);for(let l of i.body)if(l.type===a){if(r==="default"){l.declaration=o;return}if(l.declaration&&"declarations"in l.declaration){let c=l.declaration.declarations[0];if("name"in c.id&&c.id.name===r){c.init=o;return}}}i.body.push(r==="default"?_t.exportDefaultDeclaration(o):_t.exportNamedDeclaration(_t.variableDeclaration("const",[_t.variableDeclarator(_t.identifier(r),o)])))};return be(i,{$type:"exports"},{get(r,n){let a=e(n);if(a)return le(a,s)},set(r,n,a){return t(n,a),!0},ownKeys(){return i.body.flatMap(r=>r.type==="ExportDefaultDeclaration"?["default"]:r.type==="ExportNamedDeclaration"&&r.declaration&&"declarations"in r.declaration?r.declaration.declarations.map(n=>"name"in n.id?n.id.name:""):[]).filter(Boolean)},deleteProperty(r,n){let a=n==="default"?"ExportDefaultDeclaration":"ExportNamedDeclaration";for(let o=0;o<i.body.length;o++){let l=i.body[o];if(l.type===a){if(n==="default")return i.body.splice(o,1),!0;if(l.declaration&&"declarations"in l.declaration){let c=l.declaration.declarations[0];if("name"in c.id&&c.id.name===n)return i.body.splice(o,1),!0}}}return!1}})}function Vc(i,s){let e=i.program;if(e.type!=="Program")throw new re(`Cannot proxify ${i.type} as module`);let t={$code:s,$type:"module"},r=be(e,t,{ownKeys(){return["imports","exports","generate"]}});return t.exports=Uc(e,r),t.imports=Dc(e),t.generate=n=>zr(r,n),r}function ta(i,s={}){let e={wrapColumn:s.wrapColumn===void 0,indent:s.tabWidth===void 0||s.useTabs===void 0,quote:s.quote===void 0,arrowParens:s.arrowParensAlways===void 0,trailingComma:s.trailingComma===void 0},t=2,r=0,n=0,a=0,o=0,l=/(?<doubleQuote>"[^"]+")|(?<singleQuote>'[^']+')|(?<singleParam>\([^),]+\)\s*=>)|(?<trailingComma>,\s*[\]}])/g,c={doubleQuote:0,singleQuote:0,singleParam:0,trailingComma:0},u=(i||"").split(`
|
|
104
|
-
`),h=!1;for(let f of u){let d=f.trim();if(d.length!==0){if(e.wrapColumn&&f.length>a&&(a=f.length),e.indent){let p=f.match(/^\s+/)?.[0]||"";p.length>0&&(p.length>0&&p.length<t&&(t=p.length),p[0]===" "?r++:p.length>0&&r--)}if(d.at(-1)===";"?n++:d.length>0&&n--,e.quote||e.arrowParens){let p=d.matchAll(l);for(let g of p)if(g.groups)for(let y in c)g.groups[y]&&c[y]++}e.trailingComma&&((f.startsWith("}")||f.startsWith("]"))&&(h?o++:o--),h=d.endsWith(","))}}return{wrapColumn:a,useTabs:r>0,tabWidth:t,quote:c.singleQuote>c.doubleQuote?"single":"double",arrowParensAlways:c.singleParam>0,trailingComma:o>0||c.trailingComma>0,useSemi:n>0,arrayBracketSpacing:void 0,objectCurlySpacing:void 0,...s}}function sa(i,s){let e=Un(i,{parser:s?.parser||Qn(),...s});return Vc(e,i)}function ra(i,s){let e=Un("("+i+")",{parser:s?.parser||Qn(),...s}),t=e.program.body[0];t.type==="ExpressionStatement"&&(t=t.expression),t.extra?.parenthesized&&(t.extra.parenthesized=!1);let r={$ast:e,$code:" "+i+" ",$type:"module"};return le(t,r)}function zr(i,s={}){let e=i.$ast||i,t=s.format===!1||!("$code"in i)?{}:ta(i.$code,s.format),{code:r,map:n}=Ac(e,{...s,...t});return{code:r,map:n}}async function $c(i,s={}){let e=await ys.promises.readFile(i,"utf8");return s.sourceFileName=s.sourceFileName??i,sa(e,s)}async function qc(i,s,e){let t="$ast"in i?i.$ast:i,{code:r,map:n}=zr(t,e);await ys.promises.writeFile(s,r),n&&await ys.promises.writeFile(s+".map",n)}var fs=yt,zc={functionCall(i,...s){let e=fs.callExpression(fs.identifier(i),s.map(t=>ce(t)));return Zn(e)},newExpression(i,...s){let e=fs.newExpression(fs.identifier(i),s.map(t=>ce(t)));return ea(e)},literal(i){return ce(i)},raw(i){return ra(i)}};var Wc=je(require("@sentry/node"),1);async function oa(i,s){let e=await(0,ue.readdir)(i,{withFileTypes:!0}),t=[];for(let r of e){let n=V.default.join(i,r.name);if(r.isDirectory()){if(!s.has(r.name)){let a=await oa(n,s);t.push(...a)}}else t.push(n)}return t}async function la(i){let s=new Set,e=(...c)=>{if(process.env.DEBUG){let u=new Date,h=`${String(u.getMinutes()).padStart(2,"0")}:${String(u.getSeconds()).padStart(2,"0")}.${String(u.getMilliseconds()).padStart(3,"0")}`;console.debug(h,"[builder-dev-tools]",...c)}},t=async c=>{let u=(0,ia.createHash)("md5");return u.update(c),u.digest("hex")},r=V.default.normalize(i.cwd),n=Gc(V.default.normalize(i.cwd))??r,a=Qc(V.default.normalize(i.cwd))??n,o={...V.default,getCwdDir:()=>r,getRepoRootDir:()=>n,getAppRootDir:()=>a,cwd:()=>process.cwd(),exists:async c=>{try{return await(0,ue.access)(c),!0}catch{return!1}},magicast:Wr,existsSync:c=>(0,G.existsSync)(c),readdir:async(c,u)=>{let h=await(0,ue.readdir)(c);return u?h.map(f=>V.default.join(c,f)):h},readdirRecursive:async(c,u)=>oa(c,new Set(u)),readdirSync:c=>(0,G.readdirSync)(c),readFile:async c=>{try{return await(0,ue.readFile)(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},readFileSync(c){try{return(0,G.readFileSync)(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},spawnSync:gt.spawnSync,stat:async c=>await(0,ue.stat)(c),statSync:c=>(0,G.statSync)(c),unlinkSync:c=>{(0,G.unlinkSync)(c)},unlink:async c=>{await(0,ue.unlink)(c)},writeFile:async(c,u)=>{c=V.default.normalize(c);let h={path:c,basename:V.default.basename(c),dirname:V.default.dirname(c),extname:V.default.extname(c)};await(0,ue.mkdir)(V.default.dirname(c),{recursive:!0}),await(0,ue.writeFile)(c,u);for(let f of s)await f(h)},hash:t,getDeviceId:()=>t(`${(0,Is.hostname)()}:${(0,Is.homedir)()}`),formatCode:async(c,u)=>{let h=null;try{h=await Jr.default.resolveConfig(c)}catch{}try{return Jr.default.format(u,{...h,filepath:c})}catch{}return u},on:(c,u)=>{c==="change"&&s.add(u)},off:(c,u)=>{c==="change"&&s.delete(u)},debug:e,launchEditor:async c=>{try{let u=c.filePath;typeof c.line=="number"&&(u+=`:${c.line}`,typeof c.column=="number"&&(u+=`:${c.column}`)),(0,aa.default)(u,"code",(h,f)=>{console.error(`Failed to launch editor for ${h}`),f&&console.error(f)})}catch(u){console.error(`Failed to launch editor for ${String(u.message||u)}`)}},platform:()=>({runtime:"node",os:process.platform}),getRepoInfo:async()=>{let c=V.default.normalize(i.cwd);return{remoteUrl:Jc(c),defaultBranch:Kc(c),commit:Hc(c),currentBranch:Xc(c)}},getFrameworks:()=>[],ts:na.default,Sentry:Wc,version:"1.5.
|
|
104
|
+
`),h=!1;for(let f of u){let d=f.trim();if(d.length!==0){if(e.wrapColumn&&f.length>a&&(a=f.length),e.indent){let p=f.match(/^\s+/)?.[0]||"";p.length>0&&(p.length>0&&p.length<t&&(t=p.length),p[0]===" "?r++:p.length>0&&r--)}if(d.at(-1)===";"?n++:d.length>0&&n--,e.quote||e.arrowParens){let p=d.matchAll(l);for(let g of p)if(g.groups)for(let y in c)g.groups[y]&&c[y]++}e.trailingComma&&((f.startsWith("}")||f.startsWith("]"))&&(h?o++:o--),h=d.endsWith(","))}}return{wrapColumn:a,useTabs:r>0,tabWidth:t,quote:c.singleQuote>c.doubleQuote?"single":"double",arrowParensAlways:c.singleParam>0,trailingComma:o>0||c.trailingComma>0,useSemi:n>0,arrayBracketSpacing:void 0,objectCurlySpacing:void 0,...s}}function sa(i,s){let e=Un(i,{parser:s?.parser||Qn(),...s});return Vc(e,i)}function ra(i,s){let e=Un("("+i+")",{parser:s?.parser||Qn(),...s}),t=e.program.body[0];t.type==="ExpressionStatement"&&(t=t.expression),t.extra?.parenthesized&&(t.extra.parenthesized=!1);let r={$ast:e,$code:" "+i+" ",$type:"module"};return le(t,r)}function zr(i,s={}){let e=i.$ast||i,t=s.format===!1||!("$code"in i)?{}:ta(i.$code,s.format),{code:r,map:n}=Ac(e,{...s,...t});return{code:r,map:n}}async function $c(i,s={}){let e=await ys.promises.readFile(i,"utf8");return s.sourceFileName=s.sourceFileName??i,sa(e,s)}async function qc(i,s,e){let t="$ast"in i?i.$ast:i,{code:r,map:n}=zr(t,e);await ys.promises.writeFile(s,r),n&&await ys.promises.writeFile(s+".map",n)}var fs=yt,zc={functionCall(i,...s){let e=fs.callExpression(fs.identifier(i),s.map(t=>ce(t)));return Zn(e)},newExpression(i,...s){let e=fs.newExpression(fs.identifier(i),s.map(t=>ce(t)));return ea(e)},literal(i){return ce(i)},raw(i){return ra(i)}};var Wc=je(require("@sentry/node"),1);async function oa(i,s){let e=await(0,ue.readdir)(i,{withFileTypes:!0}),t=[];for(let r of e){let n=V.default.join(i,r.name);if(r.isDirectory()){if(!s.has(r.name)){let a=await oa(n,s);t.push(...a)}}else t.push(n)}return t}async function la(i){let s=new Set,e=(...c)=>{if(process.env.DEBUG){let u=new Date,h=`${String(u.getMinutes()).padStart(2,"0")}:${String(u.getSeconds()).padStart(2,"0")}.${String(u.getMilliseconds()).padStart(3,"0")}`;console.debug(h,"[builder-dev-tools]",...c)}},t=async c=>{let u=(0,ia.createHash)("md5");return u.update(c),u.digest("hex")},r=V.default.normalize(i.cwd),n=Gc(V.default.normalize(i.cwd))??r,a=Qc(V.default.normalize(i.cwd))??n,o={...V.default,getCwdDir:()=>r,getRepoRootDir:()=>n,getAppRootDir:()=>a,cwd:()=>process.cwd(),exists:async c=>{try{return await(0,ue.access)(c),!0}catch{return!1}},magicast:Wr,existsSync:c=>(0,G.existsSync)(c),readdir:async(c,u)=>{let h=await(0,ue.readdir)(c);return u?h.map(f=>V.default.join(c,f)):h},readdirRecursive:async(c,u)=>oa(c,new Set(u)),readdirSync:c=>(0,G.readdirSync)(c),readFile:async c=>{try{return await(0,ue.readFile)(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},readFileSync(c){try{return(0,G.readFileSync)(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},spawnSync:gt.spawnSync,stat:async c=>await(0,ue.stat)(c),statSync:c=>(0,G.statSync)(c),unlinkSync:c=>{(0,G.unlinkSync)(c)},unlink:async c=>{await(0,ue.unlink)(c)},writeFile:async(c,u)=>{c=V.default.normalize(c);let h={path:c,basename:V.default.basename(c),dirname:V.default.dirname(c),extname:V.default.extname(c)};await(0,ue.mkdir)(V.default.dirname(c),{recursive:!0}),await(0,ue.writeFile)(c,u);for(let f of s)await f(h)},hash:t,getDeviceId:()=>t(`${(0,Is.hostname)()}:${(0,Is.homedir)()}`),formatCode:async(c,u)=>{let h=null;try{h=await Jr.default.resolveConfig(c)}catch{}try{return Jr.default.format(u,{...h,filepath:c})}catch{}return u},on:(c,u)=>{c==="change"&&s.add(u)},off:(c,u)=>{c==="change"&&s.delete(u)},debug:e,launchEditor:async c=>{try{let u=c.filePath;typeof c.line=="number"&&(u+=`:${c.line}`,typeof c.column=="number"&&(u+=`:${c.column}`)),(0,aa.default)(u,"code",(h,f)=>{console.error(`Failed to launch editor for ${h}`),f&&console.error(f)})}catch(u){console.error(`Failed to launch editor for ${String(u.message||u)}`)}},platform:()=>({runtime:"node",os:process.platform}),getRepoInfo:async()=>{let c=V.default.normalize(i.cwd);return{remoteUrl:Jc(c),defaultBranch:Kc(c),commit:Hc(c),currentBranch:Xc(c)}},getFrameworks:()=>[],ts:na.default,Sentry:Wc,version:"1.5.10",sdkVersion:null,ignoreMissingConfig:i.ignoreMissingConfig,kind:null},l=await si(o);return o.getFrameworks=()=>l,o}function Jc(i){try{return((0,gt.spawnSync)("git",["config","--get","remote.origin.url"],{cwd:i}).stdout||"").toString().trim()}catch(s){return console.error("Error getting git remote URL:",s),""}}function Kc(i){let s="master";try{let e=(0,gt.spawnSync)("git",["branch","-r"],{cwd:i});return e.stdout&&e.stdout.toString().trim().split(`
|
|
105
105
|
`).map(r=>r.trim()).includes("origin/main")?"main":s}catch(e){return console.error("Error getting git default branch name:",e.toString().split(`
|
|
106
106
|
`)[0]),s}}function Hc(i){try{return((0,gt.spawnSync)("git",["rev-parse","HEAD"],{cwd:i}).stdout||"").toString().trim()}catch(s){return console.error("Error getting git commit:",s),""}}function Xc(i){try{return((0,gt.spawnSync)("git",["branch","--show-current"],{cwd:i}).stdout||"").toString().trim()}catch(s){return console.error("Error getting current branch name:",s),""}}function Gc(i){let s=V.default.resolve("/");for(let e=0;e<20;e++){let t=V.default.join(i,"package.json");if((0,G.existsSync)(t))return i;if(i===s)break;i=V.default.dirname(i)}return null}function Qc(i){let s=V.default.resolve("/");for(let e=0;e<20;e++){if((0,G.existsSync)(V.default.join(i,"package.json"))||(0,G.existsSync)(V.default.join(i,"remix.config.js"))||(0,G.existsSync)(V.default.join(i,"remix.config.mjs"))||(0,G.existsSync)(V.default.join(i,"remix.config.ts"))||(0,G.existsSync)(V.default.join(i,"vite.config.js"))||(0,G.existsSync)(V.default.join(i,"vite.config.ts"))||(0,G.existsSync)(V.default.join(i,"vite.config.mjs"))||(0,G.existsSync)(V.default.join(i,"next.config.js"))||(0,G.existsSync)(V.default.join(i,"next.config.ts"))||(0,G.existsSync)(V.default.join(i,"angular.json"))||(0,G.existsSync)(V.default.join(i,"project.json"))||(0,G.existsSync)(V.default.join(i,"tsconfig.json")))return i;if(i===s)break;i=V.default.dirname(i)}return null}0&&(module.exports={createDevToolsNodeSys});
|
package/node/index.mjs
CHANGED
|
@@ -101,6 +101,6 @@ ${" ".repeat(6+r)}^`),c));s+=`
|
|
|
101
101
|
${l.join(`
|
|
102
102
|
`)}
|
|
103
103
|
`}this.message=s}},Pc=new Set(["Literal","StringLiteral","NumericLiteral","BooleanLiteral","NullLiteral","RegExpLiteral","BigIntLiteral"]),Kn=new Set(["string","number","boolean","bigint","symbol","undefined"]),Z=dt;function Sc(i){return/^[$A-Z_a-z][\w$]*$/.test(i)}var Vr="__magicast_proxy";function le(i,s=new Set){if(i===void 0)return Z.identifier("undefined");if(i===null)return Z.literal(null);if(Kn.has(typeof i))return Z.literal(i);if(s.has(i))throw new se("Can not serialize circular reference");if(s.add(i),i[Vr])return i.$ast;if(i instanceof RegExp){let e=Z.regExpLiteral(i.source,i.flags);return delete e.extra.raw,e}return i instanceof Set?Z.newExpression(Z.identifier("Set"),[Z.arrayExpression([...i].map(e=>le(e,s)))]):i instanceof Date?Z.newExpression(Z.identifier("Date"),[Z.literal(i.toISOString())]):i instanceof Map?Z.newExpression(Z.identifier("Map"),[Z.arrayExpression([...i].map(([e,t])=>Z.arrayExpression([le(e,s),le(t,s)])))]):Array.isArray(i)?Z.arrayExpression(i.map(e=>le(e,s))):typeof i=="object"?Z.objectExpression(Object.entries(i).map(([e,t])=>Z.property("init",/^[$A-Z_a-z][\w$]*$/g.test(e)?Z.identifier(e):Z.literal(e),le(t,s)))):Z.literal(i)}function Ac(i,s={}){let e=s;return e[Vr]=!0,e.$ast=i,e.$type||(e.$type="object"),e}var Ec={enumerable:!0,configurable:!0};function xe(i,s,e){let t=Ac(i,s);return new Proxy({},{ownKeys(){return Object.keys(t).filter(r=>r!==Vr&&!r.startsWith("$"))},getOwnPropertyDescriptor(){return Ec},has(r,n){return n in t},...e,get(r,n,a){if(n in t)return t[n];if(e.get)return e.get(r,n,a)},set(r,n,a,o){return n in t?(t[n]=a,!0):e.set?e.set(r,n,a,o):!1}})}var fe=dt,wr=new WeakMap;function wc(i,s,e){if(wr.has(s))return wr.get(s);let t=xe(s,{get $declaration(){return i},get imported(){return s.type==="ImportDefaultSpecifier"?"default":s.type==="ImportNamespaceSpecifier"?"*":s.imported.type==="Identifier"?s.imported.name:s.imported.value},set imported(r){if(s.type!=="ImportSpecifier")throw new se("Changing import name is not yet implemented");s.imported.type==="Identifier"?s.imported.name=r:s.imported.value=r},get local(){return s.local.name},set local(r){s.local.name=r},get from(){return i.source.value},set from(r){if(r===i.source.value)return;i.specifiers=i.specifiers.filter(a=>a!==s),i.specifiers.length===0&&(e.body=e.body.filter(a=>a!==i));let n=e.body.find(a=>a.type==="ImportDeclaration"&&a.source.value===r);n?n.specifiers.push(s):e.body.unshift(fe.importDeclaration([s],fe.stringLiteral(r)))},toJSON(){return{imported:this.imported,local:this.local,from:this.from}}},{ownKeys(){return["imported","local","from","toJSON"]}});return wr.set(s,t),t}function vc(i,s){let e=()=>{let a=[];for(let o of i.body)if(o.type==="ImportDeclaration")for(let l of o.specifiers)a.push(wc(o,l,i));return a},t=(a,o,l)=>{let c=e(),u=c.find(p=>p.local===a),h=o.local||a;if(u)return u.imported=o.imported,u.local=h,u.from=o.from,!0;let f=o.imported==="default"?fe.importDefaultSpecifier(fe.identifier(h)):o.imported==="*"?fe.importNamespaceSpecifier(fe.identifier(h)):fe.importSpecifier(fe.identifier(o.imported),fe.identifier(h)),d=c.find(p=>p.from===o.from)?.$declaration;if(d)d.specifiers.push(f);else if(l==="prepend"||c.length===0)i.body.unshift(fe.importDeclaration([f],fe.stringLiteral(o.from)));else{let p=c.at(-1).$declaration,g=i.body.indexOf(p);i.body.splice(g+1,0,fe.importDeclaration([f],fe.stringLiteral(o.from)))}return!0},r=a=>{let o=e().find(u=>u.local===a);if(!o)return!1;let l=o.$declaration,c=o.$ast;return l.specifiers=l.specifiers.filter(u=>u!==c),l.specifiers.length===0&&(i.body=i.body.filter(u=>u!==l)),!0};return xe(i,{$type:"imports",$add(a){t(a.local||a.imported,a,"prepend")},$prepend(a){t(a.local||a.imported,a,"prepend")},$append(a){t(a.local||a.imported,a,"append")},get $items(){return e()},toJSON(){return e().reduce((a,o)=>(a[o.local]=o,a),{})}},{get(a,o){return e().find(l=>l.local===o)},set(a,o,l){return t(o,l,"prepend")},deleteProperty(a,o){return r(o)},ownKeys(){return e().map(a=>a.local)},has(a,o){return e().some(l=>l.local===o)}})}function As(i,s,e){let t=n=>s[n],r=(n,a)=>{s[n]=a};return xe(i,{$type:"array",push(n){s.push(le(n))},pop(){return oe(s.pop(),e)},unshift(n){s.unshift(le(n))},shift(){return oe(s.shift(),e)},splice(n,a,...o){return s.splice(n,a,...o.map(c=>le(c))).map(c=>oe(c,e))},find(n){return s.map(a=>oe(a,e)).find(n)},findIndex(n){return s.map(a=>oe(a,e)).findIndex(n)},includes(n){return s.map(a=>oe(a,e)).includes(n)},toJSON(){return s.map(n=>oe(n,e))}},{get(n,a){if(a==="length")return s.length;if(a===Symbol.iterator)return function*(){for(let c of s)yield oe(c,e)};if(typeof a=="symbol")return;let o=+a;if(Number.isNaN(o))return;let l=t(o);if(l)return oe(l,e)},set(n,a,o){if(typeof a=="symbol")return!1;let l=+a;return Number.isNaN(l)?!1:(r(l,le(o)),!0)},deleteProperty(n,a){if(typeof a=="symbol")return!1;let o=+a;return Number.isNaN(o)?!1:(s[o]=le(void 0),!0)},ownKeys(){return["length",...s.map((n,a)=>a.toString())]}})}function Cc(i,s){if("elements"in i)return As(i,i.elements,s)}function Hn(i,s){if(i.type!=="CallExpression")throw new se("Not a function call");function e(r){if(r.type==="Identifier")return r.name;if(r.type==="MemberExpression")return`${e(r.object)}.${e(r.property)}`;throw new se("Not implemented")}let t=As(i,i.arguments,s);return xe(i,{$type:"function-call",$callee:e(i.callee),$args:t},{})}function Ic(i,s){if(i.type!=="ArrowFunctionExpression")throw new se("Not an arrow function expression");let e=As(i,i.params,s);return xe(i,{$type:"arrow-function-expression",$params:e,$body:oe(i.body,s)},{})}var Nc=dt;function kc(i,s){if(!("properties"in i))return;let e=n=>{for(let a of i.properties){if("key"in a&&"name"in a.key&&a.key.name===n)return a.value;if(a.type==="ObjectProperty"&&(a.key.type==="StringLiteral"||a.key.type==="NumericLiteral"||a.key.type==="BooleanLiteral")&&a.key.value.toString()===n)return a.value.value??a.value}},t=(n,a=!1)=>{if("key"in n&&"name"in n.key)return n.key.name;if(n.type==="ObjectProperty"&&(n.key.type==="StringLiteral"||n.key.type==="NumericLiteral"||n.key.type==="BooleanLiteral"))return n.key.value.toString();if(a)throw new se(`Casting "${n.type}" is not supported`,{ast:n,code:s?.$code})},r=(n,a)=>{let o=i.properties.find(l=>t(l)===n);o?o.value=a:Sc(n)?i.properties.push({type:"Property",key:{type:"Identifier",name:n},value:a}):i.properties.push({type:"ObjectProperty",key:Nc.stringLiteral(n),value:a})};return xe(i,{$type:"object",toJSON(){return i.properties.reduce((n,a)=>("key"in a&&"name"in a.key&&(n[a.key.name]=oe(a.value,s)),n),{})}},{get(n,a){let o=e(a);if(o)return oe(o,s)},set(n,a,o){return typeof a!="string"&&(a=String(a)),r(a,le(o)),!0},deleteProperty(n,a){typeof a!="string"&&(a=String(a));let o=i.properties.findIndex(l=>"key"in l&&"name"in l.key&&l.key.name===a);return o!==-1&&i.properties.splice(o,1),!0},ownKeys(){return i.properties.map(n=>t(n,!0)).filter(Boolean)}})}function Xn(i,s){if(i.type!=="NewExpression")throw new se("Not a new expression");function e(r){if(r.type==="Identifier")return r.name;if(r.type==="MemberExpression")return`${e(r.object)}.${e(r.property)}`;throw new se("Not implemented")}let t=As(i,i.arguments,s);return xe(i,{$type:"new-expression",$callee:e(i.callee),$args:t},{})}function Lc(i){if(i.type!=="Identifier")throw new se("Not an identifier");return xe(i,{$type:"identifier",$name:i.name},{})}function Dc(i){if(i.type!=="LogicalExpression")throw new se("Not a logical expression");return xe(i,{$type:"logicalExpression"},{})}function Oc(i){if(i.type!=="MemberExpression")throw new se("Not a member expression");return xe(i,{$type:"memberExpression"},{})}var vr=new WeakMap;function oe(i,s){if(Kn.has(typeof i))return i;if(Pc.has(i.type))return i.value;if(vr.has(i))return vr.get(i);let e;switch(i.type){case"ObjectExpression":{e=kc(i,s);break}case"ArrayExpression":{e=Cc(i,s);break}case"CallExpression":{e=Hn(i,s);break}case"ArrowFunctionExpression":{e=Ic(i,s);break}case"NewExpression":{e=Xn(i,s);break}case"Identifier":{e=Lc(i);break}case"LogicalExpression":{e=Dc(i);break}case"MemberExpression":{e=Oc(i);break}case"TSAsExpression":case"TSSatisfiesExpression":{e=oe(i.expression,s);break}default:throw new se(`Casting "${i.type}" is not supported`,{ast:i,code:s?.$code})}return vr.set(i,e),e}var Mt=dt;function Mc(i,s){let e=r=>{let n=r==="default"?"ExportDefaultDeclaration":"ExportNamedDeclaration";for(let a of i.body)if(a.type===n){if(r==="default")return a.declaration;if(a.declaration&&"declarations"in a.declaration){let o=a.declaration.declarations[0];if("name"in o.id&&o.id.name===r)return o.init}}},t=(r,n)=>{let a=r==="default"?"ExportDefaultDeclaration":"ExportNamedDeclaration",o=le(n);for(let l of i.body)if(l.type===a){if(r==="default"){l.declaration=o;return}if(l.declaration&&"declarations"in l.declaration){let c=l.declaration.declarations[0];if("name"in c.id&&c.id.name===r){c.init=o;return}}}i.body.push(r==="default"?Mt.exportDefaultDeclaration(o):Mt.exportNamedDeclaration(Mt.variableDeclaration("const",[Mt.variableDeclarator(Mt.identifier(r),o)])))};return xe(i,{$type:"exports"},{get(r,n){let a=e(n);if(a)return oe(a,s)},set(r,n,a){return t(n,a),!0},ownKeys(){return i.body.flatMap(r=>r.type==="ExportDefaultDeclaration"?["default"]:r.type==="ExportNamedDeclaration"&&r.declaration&&"declarations"in r.declaration?r.declaration.declarations.map(n=>"name"in n.id?n.id.name:""):[]).filter(Boolean)},deleteProperty(r,n){let a=n==="default"?"ExportDefaultDeclaration":"ExportNamedDeclaration";for(let o=0;o<i.body.length;o++){let l=i.body[o];if(l.type===a){if(n==="default")return i.body.splice(o,1),!0;if(l.declaration&&"declarations"in l.declaration){let c=l.declaration.declarations[0];if("name"in c.id&&c.id.name===n)return i.body.splice(o,1),!0}}}return!1}})}function Fc(i,s){let e=i.program;if(e.type!=="Program")throw new se(`Cannot proxify ${i.type} as module`);let t={$code:s,$type:"module"},r=xe(e,t,{ownKeys(){return["imports","exports","generate"]}});return t.exports=Mc(e,r),t.imports=vc(e),t.generate=n=>$r(r,n),r}function Gn(i,s={}){let e={wrapColumn:s.wrapColumn===void 0,indent:s.tabWidth===void 0||s.useTabs===void 0,quote:s.quote===void 0,arrowParens:s.arrowParensAlways===void 0,trailingComma:s.trailingComma===void 0},t=2,r=0,n=0,a=0,o=0,l=/(?<doubleQuote>"[^"]+")|(?<singleQuote>'[^']+')|(?<singleParam>\([^),]+\)\s*=>)|(?<trailingComma>,\s*[\]}])/g,c={doubleQuote:0,singleQuote:0,singleParam:0,trailingComma:0},u=(i||"").split(`
|
|
104
|
-
`),h=!1;for(let f of u){let d=f.trim();if(d.length!==0){if(e.wrapColumn&&f.length>a&&(a=f.length),e.indent){let p=f.match(/^\s+/)?.[0]||"";p.length>0&&(p.length>0&&p.length<t&&(t=p.length),p[0]===" "?r++:p.length>0&&r--)}if(d.at(-1)===";"?n++:d.length>0&&n--,e.quote||e.arrowParens){let p=d.matchAll(l);for(let g of p)if(g.groups)for(let y in c)g.groups[y]&&c[y]++}e.trailingComma&&((f.startsWith("}")||f.startsWith("]"))&&(h?o++:o--),h=d.endsWith(","))}}return{wrapColumn:a,useTabs:r>0,tabWidth:t,quote:c.singleQuote>c.doubleQuote?"single":"double",arrowParensAlways:c.singleParam>0,trailingComma:o>0||c.trailingComma>0,useSemi:n>0,arrayBracketSpacing:void 0,objectCurlySpacing:void 0,...s}}function Qn(i,s){let e=Fn(i,{parser:s?.parser||Jn(),...s});return Fc(e,i)}function Yn(i,s){let e=Fn("("+i+")",{parser:s?.parser||Jn(),...s}),t=e.program.body[0];t.type==="ExpressionStatement"&&(t=t.expression),t.extra?.parenthesized&&(t.extra.parenthesized=!1);let r={$ast:e,$code:" "+i+" ",$type:"module"};return oe(t,r)}function $r(i,s={}){let e=i.$ast||i,t=s.format===!1||!("$code"in i)?{}:Gn(i.$code,s.format),{code:r,map:n}=gc(e,{...s,...t});return{code:r,map:n}}async function Bc(i,s={}){let e=await Cr.readFile(i,"utf8");return s.sourceFileName=s.sourceFileName??i,Qn(e,s)}async function _c(i,s,e){let t="$ast"in i?i.$ast:i,{code:r,map:n}=$r(t,e);await Cr.writeFile(s,r),n&&await Cr.writeFile(s+".map",n)}var us=dt,jc={functionCall(i,...s){let e=us.callExpression(us.identifier(i),s.map(t=>le(t)));return Hn(e)},newExpression(i,...s){let e=us.newExpression(us.identifier(i),s.map(t=>le(t)));return Xn(e)},literal(i){return le(i)},raw(i){return Yn(i)}};import*as eu from"@sentry/node";async function ta(i,s){let e=await ea(i,{withFileTypes:!0}),t=[];for(let r of e){let n=$.join(i,r.name);if(r.isDirectory()){if(!s.has(r.name)){let a=await ta(n,s);t.push(...a)}}else t.push(n)}return t}async function tu(i){let s=new Set,e=(...c)=>{if(process.env.DEBUG){let u=new Date,h=`${String(u.getMinutes()).padStart(2,"0")}:${String(u.getSeconds()).padStart(2,"0")}.${String(u.getMilliseconds()).padStart(3,"0")}`;console.debug(h,"[builder-dev-tools]",...c)}},t=async c=>{let u=Wc("md5");return u.update(c),u.digest("hex")},r=$.normalize(i.cwd),n=au($.normalize(i.cwd))??r,a=ou($.normalize(i.cwd))??n,o={...$,getCwdDir:()=>r,getRepoRootDir:()=>n,getAppRootDir:()=>a,cwd:()=>process.cwd(),exists:async c=>{try{return await Rc(c),!0}catch{return!1}},magicast:qr,existsSync:c=>ce(c),readdir:async(c,u)=>{let h=await ea(c);return u?h.map(f=>$.join(c,f)):h},readdirRecursive:async(c,u)=>ta(c,new Set(u)),readdirSync:c=>Jc(c),readFile:async c=>{try{return await Vc(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},readFileSync(c){try{return Kc(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},spawnSync:$t,stat:async c=>await $c(c),statSync:c=>Hc(c),unlinkSync:c=>{Xc(c)},unlink:async c=>{await qc(c)},writeFile:async(c,u)=>{c=$.normalize(c);let h={path:c,basename:$.basename(c),dirname:$.dirname(c),extname:$.extname(c)};await Uc($.dirname(c),{recursive:!0}),await zc(c,u);for(let f of s)await f(h)},hash:t,getDeviceId:()=>t(`${Qc()}:${Gc()}`),formatCode:async(c,u)=>{let h=null;try{h=await Zn.resolveConfig(c)}catch{}try{return Zn.format(u,{...h,filepath:c})}catch{}return u},on:(c,u)=>{c==="change"&&s.add(u)},off:(c,u)=>{c==="change"&&s.delete(u)},debug:e,launchEditor:async c=>{try{let u=c.filePath;typeof c.line=="number"&&(u+=`:${c.line}`,typeof c.column=="number"&&(u+=`:${c.column}`)),Zc(u,"code",(h,f)=>{console.error(`Failed to launch editor for ${h}`),f&&console.error(f)})}catch(u){console.error(`Failed to launch editor for ${String(u.message||u)}`)}},platform:()=>({runtime:"node",os:process.platform}),getRepoInfo:async()=>{let c=$.normalize(i.cwd);return{remoteUrl:su(c),defaultBranch:ru(c),commit:iu(c),currentBranch:nu(c)}},getFrameworks:()=>[],ts:Yc,Sentry:eu,version:"1.5.
|
|
104
|
+
`),h=!1;for(let f of u){let d=f.trim();if(d.length!==0){if(e.wrapColumn&&f.length>a&&(a=f.length),e.indent){let p=f.match(/^\s+/)?.[0]||"";p.length>0&&(p.length>0&&p.length<t&&(t=p.length),p[0]===" "?r++:p.length>0&&r--)}if(d.at(-1)===";"?n++:d.length>0&&n--,e.quote||e.arrowParens){let p=d.matchAll(l);for(let g of p)if(g.groups)for(let y in c)g.groups[y]&&c[y]++}e.trailingComma&&((f.startsWith("}")||f.startsWith("]"))&&(h?o++:o--),h=d.endsWith(","))}}return{wrapColumn:a,useTabs:r>0,tabWidth:t,quote:c.singleQuote>c.doubleQuote?"single":"double",arrowParensAlways:c.singleParam>0,trailingComma:o>0||c.trailingComma>0,useSemi:n>0,arrayBracketSpacing:void 0,objectCurlySpacing:void 0,...s}}function Qn(i,s){let e=Fn(i,{parser:s?.parser||Jn(),...s});return Fc(e,i)}function Yn(i,s){let e=Fn("("+i+")",{parser:s?.parser||Jn(),...s}),t=e.program.body[0];t.type==="ExpressionStatement"&&(t=t.expression),t.extra?.parenthesized&&(t.extra.parenthesized=!1);let r={$ast:e,$code:" "+i+" ",$type:"module"};return oe(t,r)}function $r(i,s={}){let e=i.$ast||i,t=s.format===!1||!("$code"in i)?{}:Gn(i.$code,s.format),{code:r,map:n}=gc(e,{...s,...t});return{code:r,map:n}}async function Bc(i,s={}){let e=await Cr.readFile(i,"utf8");return s.sourceFileName=s.sourceFileName??i,Qn(e,s)}async function _c(i,s,e){let t="$ast"in i?i.$ast:i,{code:r,map:n}=$r(t,e);await Cr.writeFile(s,r),n&&await Cr.writeFile(s+".map",n)}var us=dt,jc={functionCall(i,...s){let e=us.callExpression(us.identifier(i),s.map(t=>le(t)));return Hn(e)},newExpression(i,...s){let e=us.newExpression(us.identifier(i),s.map(t=>le(t)));return Xn(e)},literal(i){return le(i)},raw(i){return Yn(i)}};import*as eu from"@sentry/node";async function ta(i,s){let e=await ea(i,{withFileTypes:!0}),t=[];for(let r of e){let n=$.join(i,r.name);if(r.isDirectory()){if(!s.has(r.name)){let a=await ta(n,s);t.push(...a)}}else t.push(n)}return t}async function tu(i){let s=new Set,e=(...c)=>{if(process.env.DEBUG){let u=new Date,h=`${String(u.getMinutes()).padStart(2,"0")}:${String(u.getSeconds()).padStart(2,"0")}.${String(u.getMilliseconds()).padStart(3,"0")}`;console.debug(h,"[builder-dev-tools]",...c)}},t=async c=>{let u=Wc("md5");return u.update(c),u.digest("hex")},r=$.normalize(i.cwd),n=au($.normalize(i.cwd))??r,a=ou($.normalize(i.cwd))??n,o={...$,getCwdDir:()=>r,getRepoRootDir:()=>n,getAppRootDir:()=>a,cwd:()=>process.cwd(),exists:async c=>{try{return await Rc(c),!0}catch{return!1}},magicast:qr,existsSync:c=>ce(c),readdir:async(c,u)=>{let h=await ea(c);return u?h.map(f=>$.join(c,f)):h},readdirRecursive:async(c,u)=>ta(c,new Set(u)),readdirSync:c=>Jc(c),readFile:async c=>{try{return await Vc(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},readFileSync(c){try{return Kc(c,"utf-8")}catch(u){if(u.code==="ENOENT")return null;throw e(u,c),u}},spawnSync:$t,stat:async c=>await $c(c),statSync:c=>Hc(c),unlinkSync:c=>{Xc(c)},unlink:async c=>{await qc(c)},writeFile:async(c,u)=>{c=$.normalize(c);let h={path:c,basename:$.basename(c),dirname:$.dirname(c),extname:$.extname(c)};await Uc($.dirname(c),{recursive:!0}),await zc(c,u);for(let f of s)await f(h)},hash:t,getDeviceId:()=>t(`${Qc()}:${Gc()}`),formatCode:async(c,u)=>{let h=null;try{h=await Zn.resolveConfig(c)}catch{}try{return Zn.format(u,{...h,filepath:c})}catch{}return u},on:(c,u)=>{c==="change"&&s.add(u)},off:(c,u)=>{c==="change"&&s.delete(u)},debug:e,launchEditor:async c=>{try{let u=c.filePath;typeof c.line=="number"&&(u+=`:${c.line}`,typeof c.column=="number"&&(u+=`:${c.column}`)),Zc(u,"code",(h,f)=>{console.error(`Failed to launch editor for ${h}`),f&&console.error(f)})}catch(u){console.error(`Failed to launch editor for ${String(u.message||u)}`)}},platform:()=>({runtime:"node",os:process.platform}),getRepoInfo:async()=>{let c=$.normalize(i.cwd);return{remoteUrl:su(c),defaultBranch:ru(c),commit:iu(c),currentBranch:nu(c)}},getFrameworks:()=>[],ts:Yc,Sentry:eu,version:"1.5.10",sdkVersion:null,ignoreMissingConfig:i.ignoreMissingConfig,kind:null},l=await Qr(o);return o.getFrameworks=()=>l,o}function su(i){try{return($t("git",["config","--get","remote.origin.url"],{cwd:i}).stdout||"").toString().trim()}catch(s){return console.error("Error getting git remote URL:",s),""}}function ru(i){let s="master";try{let e=$t("git",["branch","-r"],{cwd:i});return e.stdout&&e.stdout.toString().trim().split(`
|
|
105
105
|
`).map(r=>r.trim()).includes("origin/main")?"main":s}catch(e){return console.error("Error getting git default branch name:",e.toString().split(`
|
|
106
106
|
`)[0]),s}}function iu(i){try{return($t("git",["rev-parse","HEAD"],{cwd:i}).stdout||"").toString().trim()}catch(s){return console.error("Error getting git commit:",s),""}}function nu(i){try{return($t("git",["branch","--show-current"],{cwd:i}).stdout||"").toString().trim()}catch(s){return console.error("Error getting current branch name:",s),""}}function au(i){let s=$.resolve("/");for(let e=0;e<20;e++){let t=$.join(i,"package.json");if(ce(t))return i;if(i===s)break;i=$.dirname(i)}return null}function ou(i){let s=$.resolve("/");for(let e=0;e<20;e++){if(ce($.join(i,"package.json"))||ce($.join(i,"remix.config.js"))||ce($.join(i,"remix.config.mjs"))||ce($.join(i,"remix.config.ts"))||ce($.join(i,"vite.config.js"))||ce($.join(i,"vite.config.ts"))||ce($.join(i,"vite.config.mjs"))||ce($.join(i,"next.config.js"))||ce($.join(i,"next.config.ts"))||ce($.join(i,"angular.json"))||ce($.join(i,"project.json"))||ce($.join(i,"tsconfig.json")))return i;if(i===s)break;i=$.dirname(i)}return null}export{tu as createDevToolsNodeSys};
|