@lunora/rspack 1.0.0-alpha.110 → 1.0.0-alpha.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createRequire as r}from"node:module";import{L as e,r as a}from"./packem_shared/plugin-DElZkO5-.mjs";const t=o=>new e(a(o)),p=r(import.meta.url)("../package.json").version;export{e as LunoraRspackPlugin,p as VERSION,t as lunoraRspack};
1
+ import{createRequire as r}from"node:module";import{L as e,r as a}from"./packem_shared/plugin-BCIvzW8O.mjs";const t=o=>new e(a(o)),p=r(import.meta.url)("../package.json").version;export{e as LunoraRspackPlugin,p as VERSION,t as lunoraRspack};
@@ -0,0 +1 @@
1
+ import{L as r,P as s}from"./plugin-BCIvzW8O.mjs";export{r as LunoraRspackPlugin,s as PLUGIN_NAME};
@@ -0,0 +1,4 @@
1
+ import{createHash as P}from"node:crypto";import{existsSync as h,realpathSync as v,readFileSync as F}from"node:fs";import{join as a,resolve as u,dirname as d,basename as D,sep as p}from"node:path";import{createCodegenProject as T,refreshCodegenProject as C,runCodegen as b,findTsconfig as w,PROJECT_CONFIG_FILENAMES as S,projectConfigCandidatePaths as f,fingerprintSchemaSources as $,listLunoraSourceFiles as I}from"@lunora/codegen";import{resolveTargetOrThrow as L,isRunnableTarget as A,runnableTargetIds as O,assertBuildTargetMatches as _,resolveLazyFunctions as M,LUNORA_TAG as j,writeApiSpecMarker as N,reportCodegenFindings as W,blockingFindingsMessage as x,STRICT_ADVISORIES_ENV as B,isCodegenDisabled as G,CODEGEN_ENV as R,lunoraLine as l,runPostCodegenHook as z,ensureDevVariables as U,createConfirm as H,fillDevSecrets as V,ensureDevWorkerEnv as J,detectAgentRules as X,claimAgentRulesHint as q,AGENT_RULES_HINT as K,secretSourcesFromBindings as Q,inferLunoraBindings as Y}from"@lunora/config";import{wranglerCodegenInputs as Z,reconcileWranglerExtras as ee,WRANGLER_FILES as te,warnCloudflareCliConfigOnce as re,findWranglerFile as se,reconcileBindingsSafely as ie,assertWranglerSatisfiesSchema as ne}from"@lunora/config/cloudflare";const k=(t,e)=>{const r=L(t,e);if(!A(r))throw new Error(`target "${r}" has no command-line toolchain, so the Lunora Rspack plugin cannot build for it — it can only generate for it (\`lunora codegen --target ${r}\`). Buildable targets: ${O().join(", ")}`);return _(r,t),r},je=t=>{const e=t??{},r=e.projectRoot??process.cwd();return{apiSpec:e.apiSpec??"openapi",explicitTarget:e.target,lazyFunctions:M(e.lazyFunctions),projectRoot:r,schemaDir:e.schemaDir??"lunora",target:k(r,e.target),validateWrangler:e.validateWrangler??!0}},oe=(t,e,r)=>{const s=a(t.projectRoot,t.schemaDir,"schema.ts");if(!h(s))return e.warn(`${j} no schema found at ${s} — run \`lunora init\` or create it, then rebuild.`),{};const i=b({apiSpec:t.apiSpec,lazyFunctions:t.lazyFunctions,lunoraDirectory:t.schemaDir,project:r,projectRoot:t.projectRoot,target:t.target,...Z(t.projectRoot)});ee(t.projectRoot,i.cronTriggers,e);let c;try{N(t.projectRoot,t.apiSpec)}catch(n){c=`${j} could not write the API spec marker: ${n instanceof Error?n.message:String(n)}`,e.error(c)}return W(i,e),{blockingMessage:x(i,{strictAdvisories:process.env[B]!=="0"}),markerFailure:c}},ae=t=>{let e;return{drop:()=>{e=void 0},get:()=>(e===void 0?e=T(t):C(e,t),e)}},E="LunoraRspackPlugin",ce=2,g=t=>{try{return F(t,"utf8")}catch{return""}},m=t=>{try{return h(t)?v(t):a(v(d(t)),D(t))}catch{return t}},he=(t,e)=>{const r=[];for(let s=t;s!==d(s);s=d(s)){const i=a(s,"tsconfig.json");if(i===e)break;r.push(i)}return r},ue=t=>[...new Set(f(t).map(e=>d(e)))].flatMap(e=>{const r=a(e,".git");return h(r)?[a(e,"package.json")]:[a(e,"package.json"),r]}),de=t=>{if(!h(t))return[];const e=m(t);return[...I(t,{includeSkipped:!0}),a(t,"schema.ts")].map(r=>m(r)).filter(r=>!r.startsWith(`${e}${p}`))},le=(t,e)=>t===e||t.startsWith(`${e}${p}`)||e.startsWith(`${t}${p}`),o={error:t=>{console.error(t)},info:t=>{console.info(t)},warn:t=>{console.warn(t)}},ge=async(t,e,r)=>{try{return Q(await Y({projectRoot:t,schemaDir:e}))}catch(s){r(`could not read the project's bindings, so every dev secret is generated: ${s instanceof Error?s.message:String(s)}`);return}},y=async t=>{const e=s=>{o.info(l(s))};await U({confirm:H("[lunora] "),cwd:t.projectRoot,info:e});const r=await ge(t.projectRoot,t.schemaDir,e);V({cwd:t.projectRoot,info:e,secretSources:r}),J(t.projectRoot,e),!X(t.projectRoot).installed&&q()&&o.warn(`
2
+ ${l(K)}
3
+ `)};class Re{#e;#u;#t;#d;#o;#i=!1;#l=!1;#n;#g;#s=[];#r;#a;#c=[];#p=[];constructor(e){this.#e=e,this.#t=u(e.projectRoot,e.schemaDir),this.#d=G(process.env[R]),this.#o=ae(this.#t)}async prepareDevSession(){this.#h(),!this.#i&&(this.#i=!0,await y(this.#e))}async generateForDev(){return await this.#f(!0),this.#u??this.#e.target}apply(e){e.hooks.beforeCompile.tapPromise(E,async()=>{const r=e.watchMode===!0;this.#h(),!(r&&this.#v(e.modifiedFiles,e.removedFiles))&&await this.#f(r)}),e.hooks.afterCompile.tapPromise(E,r=>{r.contextDependencies.add(this.#t);const s=w(this.#t);s!==void 0&&r.fileDependencies.add(s);const i=[...te.map(n=>u(this.#e.projectRoot,n)),...S.map(n=>u(this.#e.projectRoot,n)),...f(this.#t),...ue(this.#t),...he(this.#t,s),...this.#p];for(const n of new Set(i))h(n)?r.fileDependencies.add(n):r.missingDependencies.add(n);const c=[this.#t,...s===void 0?[]:[s],...i];this.#c=[...new Set([...c,...c.map(n=>m(n))])];for(const n of this.#s)r.errors.push(n);return Promise.resolve()})}async#f(e){this.#a??=this.#w(e).finally(()=>{this.#a=void 0}),await this.#a}#v(e,r){if(e===void 0||this.#c.length===0||this.#n===void 0||this.#r!==void 0||this.#a!==void 0)return!1;for(const s of[...e,...r??[]])if(this.#c.some(i=>le(s,i)))return!1;return!0}#h(){this.#l||(this.#l=re(this.#e.projectRoot,e=>{o.warn(l(e))}))}async#w(e){if(this.#h(),e&&this.#d){this.#i||(this.#i=!0,o.info(l(`codegen disabled via ${R} — skipping generation and the wrangler checks.`)));return}const r=this.#E();r!==this.#g&&(this.#o.drop(),this.#g=r,this.#n=void 0);const s=this.#j(r);if(!this.#S(s)){this.#p=de(this.#t),this.#s=[];try{!this.#i&&e&&await y(this.#e),this.#i=!0,await this.#R(e),this.#s.length===0?(this.#n=s,this.#r=void 0):this.#m(s)}catch(i){this.#o.drop(),this.#n=void 0,this.#s.push(i instanceof Error?i:new Error(String(i))),this.#m(s),o.error(i instanceof Error?i.message:String(i))}}}#S(e){return e===this.#n?!0:this.#r!==void 0&&this.#r.fingerprint===e&&this.#r.attempts>=ce}#m(e){this.#r=this.#r?.fingerprint===e?{attempts:this.#r.attempts+1,fingerprint:e}:{attempts:1,fingerprint:e}}#j(e){const r=se(this.#e.projectRoot);return[$(this.#t),e,r===void 0?"":g(r)].map(i=>P("sha256").update(i).digest("hex")).join("")}async#R(e){this.#e={...this.#e,target:k(this.#e.projectRoot,this.#e.explicitTarget)},await ie(this.#e,o),this.#e.validateWrangler&&ne(this.#e,o.warn,"Update your wrangler.jsonc and rebuild.");const{blockingMessage:r,markerFailure:s}=oe(this.#e,o,this.#o.get());this.#u=this.#e.target;const i=await z({cwd:this.#e.projectRoot,logger:o});i.error!==void 0&&this.#s.push(new Error(i.error)),!e&&r!==void 0&&this.#s.push(new Error(r)),!e&&s!==void 0&&this.#s.push(new Error(s))}#E(){const e=w(this.#t),s=[...new Set([...f(this.#t),...S.map(i=>u(this.#e.projectRoot,i))])].map(i=>`${i}
4
+ ${g(i)}`);return[e===void 0?"":g(e),...s].join("\0")}}export{Re as L,E as P,je as r};
package/dist/rsbuild.mjs CHANGED
@@ -1 +1 @@
1
- import{formatLunoraEvent as h,lunoraLine as l,acceptsConnection as y,startDevProcess as S,targetRunsOwnDevServer as R,startCelldDevSession as k}from"@lunora/config";import{r as A,L as D}from"./packem_shared/plugin-DElZkO5-.mjs";import{existsSync as b,mkdirSync as L}from"node:fs";import{resolve as f,dirname as P}from"node:path";import{findWranglerFile as E,readWranglerJsonc as W}from"@lunora/config/cloudflare";const j=8787,x=3e4,v=(r,e,t)=>{let o;for(const[n,s]of r.entries())s.startsWith(`${e}=`)?o=s.slice(e.length+1):(s===e||s===t)&&n+1<r.length&&(o=r[n+1]);return o},p=(r,e=[])=>{const t=v(e,"--config","-c"),o=t===void 0?E(r):f(r,t);if(o===void 0||!b(o))return;const{parsed:n}=W(o);return n===void 0?void 0:{config:n,env:v(e,"--env","-e"),path:o}},O=(r,e,t)=>{if(e!==void 0)return e;const o=p(r,t)?.config.dev?.port;return typeof o=="number"?o:j},_=(r,e)=>{const t=p(r,e);if(t===void 0)return;const n=((t.env===void 0?void 0:t.config.env?.[t.env]?.assets)??t.config.assets)?.directory;typeof n=="string"&&L(f(P(t.path),n),{recursive:!0})},w=r=>{const e=h(r);if(e===void 0){r.trim()!==""&&console.log(r);return}const t=l(e.text);e.level==="error"?console.error(t):e.level==="warn"?console.warn(t):console.info(t)},$=async r=>{if(await y(r.port))throw new Error(`could not start the worker: port ${String(r.port)} is already in use. Stop whatever is serving there (another \`rsbuild dev\` or \`lunora dev\`?), or set \`workerPort\`.`);_(r.projectRoot,r.wranglerArgs);const e=process.platform==="win32",t=await S({args:["dev","--port",String(r.port),"--var","WORKER_ENV:development",...r.wranglerArgs??[]],command:e?"wrangler.cmd":"wrangler",cwd:r.projectRoot,label:"wrangler dev",notFound:"could not start the worker: `wrangler` was not found on PATH. Add it to the project (`npm install -D wrangler`), or pass `worker: false` to run the worker yourself.",onLine:w,port:r.port,readyTimeoutMs:x,shell:e});return{port:r.port,stop:t.stop}},g="/_lunora",T="lunora:rsbuild",C=(r,e)=>{const t=`http://127.0.0.1:${String(e)}`;return Array.isArray(r)?[...r,{changeOrigin:!0,pathFilter:g,target:t,ws:!0}]:{[g]:{changeOrigin:!0,target:t,ws:!0},...r}},F=(r,e)=>{r.onBeforeStartDevServer(async({server:t})=>{const{base:o,host:n}=r.getRsbuildConfig().server??{},{createStudioMiddleware:s,isNonLoopbackHost:i}=await import("@lunora/config/studio-host");t.middlewares.use(s({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,base:o,isNonLoopbackBind:i(n),projectRoot:e.projectRoot,schemaDirectory:e.schemaDir}))}),r.onAfterStartDevServer(async({port:t})=>{const{studioMountPath:o}=await import("@lunora/config/studio-host");console.info(l(`studio on http://localhost:${String(t)}${o(r.getRsbuildConfig().server?.base)}`))})},I=r=>{const e=A(r),t=O(e.projectRoot,r?.workerPort,r?.wranglerArgs),o=new D(e);return{name:T,setup:n=>{if(n.modifyRspackConfig(a=>({...a,plugins:[...Array.isArray(a.plugins)?a.plugins:[],o]})),n.modifyRsbuildConfig(a=>({...a,server:{...a.server,proxy:C(a.server?.proxy,t)}})),r?.studio!==!1&&F(n,e),r?.worker===!1)return;let s,i;n.onBeforeStartDevServer(async()=>{await o.prepareDevSession();const a=await o.generateForDev();if(console.info(l(`starting the worker on http://127.0.0.1:${String(t)} …`)),R(a)){const d=await k({log:(c,{tag:u})=>{w(u==="celld"?c:`[${u}] ${c}`)},port:t,projectRoot:e.projectRoot});i=d;const m=c=>{console.error(l(`the worker on celld exited (code ${String(c)}) — restart \`rsbuild dev\` to bring it back`))};d.exited.then(m).catch(()=>{});return}s=await $({port:t,projectRoot:e.projectRoot,wranglerArgs:r?.wranglerArgs})}),n.onCloseDevServer(async()=>{await s?.stop(),await i?.stop(),s=void 0,i=void 0})}}};export{g as LUNORA_PATH,T as RSBUILD_PLUGIN_NAME,I as lunoraRsbuild,C as withLunoraProxy};
1
+ import{formatLunoraEvent as h,lunoraLine as l,acceptsConnection as y,startDevProcess as S,targetRunsOwnDevServer as R,startCelldDevSession as k}from"@lunora/config";import{r as A,L as D}from"./packem_shared/plugin-BCIvzW8O.mjs";import{existsSync as b,mkdirSync as L}from"node:fs";import{resolve as f,dirname as P}from"node:path";import{findWranglerFile as E,readWranglerJsonc as W}from"@lunora/config/cloudflare";const j=8787,x=3e4,v=(r,e,t)=>{let o;for(const[n,s]of r.entries())s.startsWith(`${e}=`)?o=s.slice(e.length+1):(s===e||s===t)&&n+1<r.length&&(o=r[n+1]);return o},p=(r,e=[])=>{const t=v(e,"--config","-c"),o=t===void 0?E(r):f(r,t);if(o===void 0||!b(o))return;const{parsed:n}=W(o);return n===void 0?void 0:{config:n,env:v(e,"--env","-e"),path:o}},O=(r,e,t)=>{if(e!==void 0)return e;const o=p(r,t)?.config.dev?.port;return typeof o=="number"?o:j},_=(r,e)=>{const t=p(r,e);if(t===void 0)return;const n=((t.env===void 0?void 0:t.config.env?.[t.env]?.assets)??t.config.assets)?.directory;typeof n=="string"&&L(f(P(t.path),n),{recursive:!0})},w=r=>{const e=h(r);if(e===void 0){r.trim()!==""&&console.log(r);return}const t=l(e.text);e.level==="error"?console.error(t):e.level==="warn"?console.warn(t):console.info(t)},$=async r=>{if(await y(r.port))throw new Error(`could not start the worker: port ${String(r.port)} is already in use. Stop whatever is serving there (another \`rsbuild dev\` or \`lunora dev\`?), or set \`workerPort\`.`);_(r.projectRoot,r.wranglerArgs);const e=process.platform==="win32",t=await S({args:["dev","--port",String(r.port),"--var","WORKER_ENV:development",...r.wranglerArgs??[]],command:e?"wrangler.cmd":"wrangler",cwd:r.projectRoot,label:"wrangler dev",notFound:"could not start the worker: `wrangler` was not found on PATH. Add it to the project (`npm install -D wrangler`), or pass `worker: false` to run the worker yourself.",onLine:w,port:r.port,readyTimeoutMs:x,shell:e});return{port:r.port,stop:t.stop}},g="/_lunora",T="lunora:rsbuild",C=(r,e)=>{const t=`http://127.0.0.1:${String(e)}`;return Array.isArray(r)?[...r,{changeOrigin:!0,pathFilter:g,target:t,ws:!0}]:{[g]:{changeOrigin:!0,target:t,ws:!0},...r}},F=(r,e)=>{r.onBeforeStartDevServer(async({server:t})=>{const{base:o,host:n}=r.getRsbuildConfig().server??{},{createStudioMiddleware:s,isNonLoopbackHost:i}=await import("@lunora/config/studio-host");t.middlewares.use(s({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,base:o,isNonLoopbackBind:i(n),projectRoot:e.projectRoot,schemaDirectory:e.schemaDir}))}),r.onAfterStartDevServer(async({port:t})=>{const{studioMountPath:o}=await import("@lunora/config/studio-host");console.info(l(`studio on http://localhost:${String(t)}${o(r.getRsbuildConfig().server?.base)}`))})},I=r=>{const e=A(r),t=O(e.projectRoot,r?.workerPort,r?.wranglerArgs),o=new D(e);return{name:T,setup:n=>{if(n.modifyRspackConfig(a=>({...a,plugins:[...Array.isArray(a.plugins)?a.plugins:[],o]})),n.modifyRsbuildConfig(a=>({...a,server:{...a.server,proxy:C(a.server?.proxy,t)}})),r?.studio!==!1&&F(n,e),r?.worker===!1)return;let s,i;n.onBeforeStartDevServer(async()=>{await o.prepareDevSession();const a=await o.generateForDev();if(console.info(l(`starting the worker on http://127.0.0.1:${String(t)} …`)),R(a)){const d=await k({log:(c,{tag:u})=>{w(u==="celld"?c:`[${u}] ${c}`)},port:t,projectRoot:e.projectRoot});i=d;const m=c=>{console.error(l(`the worker on celld exited (code ${String(c)}) — restart \`rsbuild dev\` to bring it back`))};d.exited.then(m).catch(()=>{});return}s=await $({port:t,projectRoot:e.projectRoot,wranglerArgs:r?.wranglerArgs})}),n.onCloseDevServer(async()=>{await s?.stop(),await i?.stop(),s=void 0,i=void 0})}}};export{g as LUNORA_PATH,T as RSBUILD_PLUGIN_NAME,I as lunoraRsbuild,C as withLunoraProxy};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/rspack",
3
- "version": "1.0.0-alpha.110",
3
+ "version": "1.0.0-alpha.111",
4
4
  "description": "The Lunora Rspack plugin: codegen, binding provisioning, and wrangler validation for Rspack projects",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -51,8 +51,8 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@lunora/codegen": "1.0.0-alpha.359",
55
- "@lunora/config": "1.0.0-alpha.413"
54
+ "@lunora/codegen": "1.0.0-alpha.360",
55
+ "@lunora/config": "1.0.0-alpha.414"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@lunora/studio": ">=1.0.0-alpha.50 <2.0.0-0",
@@ -1 +0,0 @@
1
- import{L as r,P as s}from"./plugin-DElZkO5-.mjs";export{r as LunoraRspackPlugin,s as PLUGIN_NAME};
@@ -1,4 +0,0 @@
1
- import{createHash as y}from"node:crypto";import{existsSync as h,realpathSync as v,readFileSync as F}from"node:fs";import{join as a,resolve as u,dirname as l,basename as T,sep as g}from"node:path";import{createCodegenProject as C,refreshCodegenProject as D,runCodegen as b,findTsconfig as w,PROJECT_CONFIG_FILENAMES as j,projectConfigCandidatePaths as f,fingerprintSchemaSources as $,listLunoraSourceFiles as I}from"@lunora/codegen";import{resolveTargetOrThrow as L,isRunnableTarget as A,runnableTargetIds as _,assertBuildTargetMatches as M,resolveLazyFunctions as N,LUNORA_TAG as R,writeApiSpecMarker as O,reportCodegenFindings as W,blockingFindingsMessage as x,STRICT_ADVISORIES_ENV as G,isCodegenDisabled as z,CODEGEN_ENV as S,lunoraLine as d,runPostCodegenHook as B,ensureDevVariables as H,createConfirm as U,fillDevSecrets as V,ensureDevWorkerEnv as J,detectAgentRules as X,claimAgentRulesHint as q,AGENT_RULES_HINT as K}from"@lunora/config";import{wranglerCodegenInputs as Q,reconcileWranglerExtras as Y,WRANGLER_FILES as Z,warnCloudflareCliConfigOnce as tt,findWranglerFile as et,reconcileBindingsSafely as rt,assertWranglerSatisfiesSchema as st}from"@lunora/config/cloudflare";const P=(e,t)=>{const r=L(e,t);if(!A(r))throw new Error(`target "${r}" has no command-line toolchain, so the Lunora Rspack plugin cannot build for it — it can only generate for it (\`lunora codegen --target ${r}\`). Buildable targets: ${_().join(", ")}`);return M(r,e),r},vt=e=>{const t=e??{},r=t.projectRoot??process.cwd();return{apiSpec:t.apiSpec??"openapi",explicitTarget:t.target,lazyFunctions:N(t.lazyFunctions),projectRoot:r,schemaDir:t.schemaDir??"lunora",target:P(r,t.target),validateWrangler:t.validateWrangler??!0}},it=(e,t,r)=>{const i=a(e.projectRoot,e.schemaDir,"schema.ts");if(!h(i))return t.warn(`${R} no schema found at ${i} — run \`lunora init\` or create it, then rebuild.`),{};const s=b({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:r,projectRoot:e.projectRoot,target:e.target,...Q(e.projectRoot)});Y(e.projectRoot,s.cronTriggers,t);let c;try{O(e.projectRoot,e.apiSpec)}catch(n){c=`${R} could not write the API spec marker: ${n instanceof Error?n.message:String(n)}`,t.error(c)}return W(s,t),{blockingMessage:x(s,{strictAdvisories:process.env[G]!=="0"}),markerFailure:c}},nt=e=>{let t;return{drop:()=>{t=void 0},get:()=>(t===void 0?t=C(e):D(t,e),t)}},E="LunoraRspackPlugin",ot=2,p=e=>{try{return F(e,"utf8")}catch{return""}},m=e=>{try{return h(e)?v(e):a(v(l(e)),T(e))}catch{return e}},at=(e,t)=>{const r=[];for(let i=e;i!==l(i);i=l(i)){const s=a(i,"tsconfig.json");if(s===t)break;r.push(s)}return r},ct=e=>[...new Set(f(e).map(t=>l(t)))].flatMap(t=>{const r=a(t,".git");return h(r)?[a(t,"package.json")]:[a(t,"package.json"),r]}),ht=e=>{if(!h(e))return[];const t=m(e);return[...I(e,{includeSkipped:!0}),a(e,"schema.ts")].map(r=>m(r)).filter(r=>!r.startsWith(`${t}${g}`))},ut=(e,t)=>e===t||e.startsWith(`${t}${g}`)||t.startsWith(`${e}${g}`),o={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},k=async e=>{const t=r=>{o.info(d(r))};await H({confirm:U("[lunora] "),cwd:e.projectRoot,info:t}),V({cwd:e.projectRoot,info:t}),J(e.projectRoot,t),!X(e.projectRoot).installed&&q()&&o.warn(`
2
- ${d(K)}
3
- `)};class wt{#t;#u;#e;#l;#o;#i=!1;#d=!1;#n;#p;#s=[];#r;#a;#c=[];#g=[];constructor(t){this.#t=t,this.#e=u(t.projectRoot,t.schemaDir),this.#l=z(process.env[S]),this.#o=nt(this.#e)}async prepareDevSession(){this.#h(),!this.#i&&(this.#i=!0,await k(this.#t))}async generateForDev(){return await this.#f(!0),this.#u??this.#t.target}apply(t){t.hooks.beforeCompile.tapPromise(E,async()=>{const r=t.watchMode===!0;this.#h(),!(r&&this.#v(t.modifiedFiles,t.removedFiles))&&await this.#f(r)}),t.hooks.afterCompile.tapPromise(E,r=>{r.contextDependencies.add(this.#e);const i=w(this.#e);i!==void 0&&r.fileDependencies.add(i);const s=[...Z.map(n=>u(this.#t.projectRoot,n)),...j.map(n=>u(this.#t.projectRoot,n)),...f(this.#e),...ct(this.#e),...at(this.#e,i),...this.#g];for(const n of new Set(s))h(n)?r.fileDependencies.add(n):r.missingDependencies.add(n);const c=[this.#e,...i===void 0?[]:[i],...s];this.#c=[...new Set([...c,...c.map(n=>m(n))])];for(const n of this.#s)r.errors.push(n);return Promise.resolve()})}async#f(t){this.#a??=this.#w(t).finally(()=>{this.#a=void 0}),await this.#a}#v(t,r){if(t===void 0||this.#c.length===0||this.#n===void 0||this.#r!==void 0||this.#a!==void 0)return!1;for(const i of[...t,...r??[]])if(this.#c.some(s=>ut(i,s)))return!1;return!0}#h(){this.#d||(this.#d=tt(this.#t.projectRoot,t=>{o.warn(d(t))}))}async#w(t){if(this.#h(),t&&this.#l){this.#i||(this.#i=!0,o.info(d(`codegen disabled via ${S} — skipping generation and the wrangler checks.`)));return}const r=this.#E();r!==this.#p&&(this.#o.drop(),this.#p=r,this.#n=void 0);const i=this.#R(r);if(!this.#j(i)){this.#g=ht(this.#e),this.#s=[];try{!this.#i&&t&&await k(this.#t),this.#i=!0,await this.#S(t),this.#s.length===0?(this.#n=i,this.#r=void 0):this.#m(i)}catch(s){this.#o.drop(),this.#n=void 0,this.#s.push(s instanceof Error?s:new Error(String(s))),this.#m(i),o.error(s instanceof Error?s.message:String(s))}}}#j(t){return t===this.#n?!0:this.#r!==void 0&&this.#r.fingerprint===t&&this.#r.attempts>=ot}#m(t){this.#r=this.#r?.fingerprint===t?{attempts:this.#r.attempts+1,fingerprint:t}:{attempts:1,fingerprint:t}}#R(t){const r=et(this.#t.projectRoot);return[$(this.#e),t,r===void 0?"":p(r)].map(s=>y("sha256").update(s).digest("hex")).join("")}async#S(t){this.#t={...this.#t,target:P(this.#t.projectRoot,this.#t.explicitTarget)},await rt(this.#t,o),this.#t.validateWrangler&&st(this.#t,o.warn,"Update your wrangler.jsonc and rebuild.");const{blockingMessage:r,markerFailure:i}=it(this.#t,o,this.#o.get());this.#u=this.#t.target;const s=await B({cwd:this.#t.projectRoot,logger:o});s.error!==void 0&&this.#s.push(new Error(s.error)),!t&&r!==void 0&&this.#s.push(new Error(r)),!t&&i!==void 0&&this.#s.push(new Error(i))}#E(){const t=w(this.#e),i=[...new Set([...f(this.#e),...j.map(s=>u(this.#t.projectRoot,s))])].map(s=>`${s}
4
- ${p(s)}`);return[t===void 0?"":p(t),...i].join("\0")}}export{wt as L,E as P,vt as r};