@lunora/rspack 1.0.0-alpha.1 → 1.0.0-alpha.100
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/README.md +6 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/LunoraRspackPlugin-DI75z-kD.mjs +1 -0
- package/dist/packem_shared/plugin-DTSWDf5-.mjs +4 -0
- package/dist/packem_shared/{types.d-CcVYk-6N.d.mts → types.d-DCaFxXeH.d.mts} +8 -2
- package/dist/packem_shared/{types.d-CcVYk-6N.d.ts → types.d-DCaFxXeH.d.ts} +8 -2
- package/dist/rsbuild.d.mts +26 -3
- package/dist/rsbuild.d.ts +26 -3
- package/dist/rsbuild.mjs +1 -2
- package/package.json +7 -3
- package/dist/packem_shared/LunoraRspackPlugin-BM3r07nu.mjs +0 -3
- package/dist/packem_shared/options-rWtSt-oe.mjs +0 -1
package/README.md
CHANGED
|
@@ -68,6 +68,8 @@ export default defineConfig({
|
|
|
68
68
|
|
|
69
69
|
`rsbuild dev` now starts the client dev server **and** the Lunora Worker, and routes `/_lunora/*` to it. Nothing else to wire — no hand-written proxy, no second terminal, no `wrangler.dev.jsonc`. One entry registers codegen, binding provisioning, wrangler validation, the Worker, and the proxy.
|
|
70
70
|
|
|
71
|
+
To start from a working app, `lunora init -t rspack-react` scaffolds a React SPA and `lunora init -t tanstack-start-react-rspack` a TanStack Start app that deploys as one Worker.
|
|
72
|
+
|
|
71
73
|
On bare Rspack (or webpack 5), the plugin half works on its own — codegen and config only, no Worker:
|
|
72
74
|
|
|
73
75
|
```js
|
|
@@ -90,12 +92,15 @@ lunoraRsbuild({
|
|
|
90
92
|
validateWrangler: true, // set false to skip the wrangler.jsonc check
|
|
91
93
|
|
|
92
94
|
// Rsbuild only:
|
|
95
|
+
studio: true, // Lunora Studio at /__lunora (needs @lunora/studio)
|
|
93
96
|
worker: true, // false to run the Worker yourself (the proxy is still injected)
|
|
94
97
|
workerPort: 8787, // defaults to the wrangler config's `dev.port`, then 8787
|
|
95
98
|
wranglerArgs: [], // extra arguments appended to `wrangler dev`
|
|
96
99
|
});
|
|
97
100
|
```
|
|
98
101
|
|
|
102
|
+
`target` must match the target the CLI resolved for the run. `lunora build` and `lunora deploy` set `LUNORA_BUILD_TARGET`, and a plugin whose target differs fails the build rather than emit an artifact for another host. Set the same target in the plugin options and `lunora.config.*`, or leave it unset to use the project's.
|
|
103
|
+
|
|
99
104
|
`LUNORA_CODEGEN=0` skips generation and the wrangler checks **in watch mode only**. A production build keeps generating: the ERROR-advisory gate is the only thing that fails it, so honouring the variable there would let an app ship against a surface its target cannot serve, green the whole way.
|
|
100
105
|
|
|
101
106
|
## How the Worker runs
|
|
@@ -110,7 +115,7 @@ So `lunoraRsbuild` spawns `wrangler dev` and proxies to it. From your seat that
|
|
|
110
115
|
| Binding / cron / compatibility-date sync | ✅ | — |
|
|
111
116
|
| `.dev.vars` scaffolding + `WORKER_ENV` | ✅ (watch mode) | — |
|
|
112
117
|
| Worker running on `dev` | ✅ (Rsbuild) | — |
|
|
113
|
-
| Studio at `/
|
|
118
|
+
| Studio at `/__lunora` | ✅ (Rsbuild) | — |
|
|
114
119
|
| Browser error overlay | ❌ | `@lunora/vite` |
|
|
115
120
|
| Per-module HMR inside the Worker | ❌ (restarts) | `@lunora/vite` |
|
|
116
121
|
| Remote-binding dev (`LUNORA_REMOTE`) | ❌ | `lunora dev` |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ResolvedLunoraRspackOptions, L as LunoraRspackOptions } from "./packem_shared/types.d-
|
|
1
|
+
import { R as ResolvedLunoraRspackOptions, L as LunoraRspackOptions } from "./packem_shared/types.d-DCaFxXeH.mjs";
|
|
2
2
|
import '@lunora/codegen';
|
|
3
3
|
/**
|
|
4
4
|
* The slice of the Rspack compiler this plugin touches, projected structurally.
|
|
@@ -36,6 +36,8 @@ interface CompilationLike {
|
|
|
36
36
|
errors: Error[];
|
|
37
37
|
/** Individual files that invalidate this compilation when they change. */
|
|
38
38
|
fileDependencies: DependencySet;
|
|
39
|
+
/** Files that do not exist yet, and invalidate this compilation when they appear. */
|
|
40
|
+
missingDependencies: DependencySet;
|
|
39
41
|
}
|
|
40
42
|
/** The slice of `Compiler` this plugin taps. */
|
|
41
43
|
interface CompilerLike {
|
|
@@ -93,6 +95,22 @@ declare class LunoraRspackPlugin {
|
|
|
93
95
|
* Idempotent: the pass below sees `#started` and skips its own call.
|
|
94
96
|
*/
|
|
95
97
|
prepareDevSession(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Run a watch-mode codegen pass now, ahead of the first compilation.
|
|
100
|
+
*
|
|
101
|
+
* Public for the same ordering reason as {@link prepareDevSession}: the
|
|
102
|
+
* Worker `@lunora/rspack/rsbuild` spawns is bundled by `wrangler dev` at
|
|
103
|
+
* startup, and it imports `_generated/app` — which, on a fresh clone, only
|
|
104
|
+
* this pass writes. Spawned first, wrangler dies on an unresolvable import
|
|
105
|
+
* before the first compilation ever generates it. The first compilation then
|
|
106
|
+
* finds the fingerprint unchanged and skips its own pass.
|
|
107
|
+
*
|
|
108
|
+
* Returns the target that pass generated for, so the Worker started next is the
|
|
109
|
+
* one its output matches. Reading `target` again after this resolves would leave
|
|
110
|
+
* a window in which an edit to `lunora.config.*` starts a Worker against output
|
|
111
|
+
* for the other target.
|
|
112
|
+
*/
|
|
113
|
+
generateForDev(): Promise<string>;
|
|
96
114
|
/** Rspack's plugin entry point. */
|
|
97
115
|
apply(compiler: CompilerLike): void;
|
|
98
116
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ResolvedLunoraRspackOptions, L as LunoraRspackOptions } from "./packem_shared/types.d-
|
|
1
|
+
import { R as ResolvedLunoraRspackOptions, L as LunoraRspackOptions } from "./packem_shared/types.d-DCaFxXeH.js";
|
|
2
2
|
import '@lunora/codegen';
|
|
3
3
|
/**
|
|
4
4
|
* The slice of the Rspack compiler this plugin touches, projected structurally.
|
|
@@ -36,6 +36,8 @@ interface CompilationLike {
|
|
|
36
36
|
errors: Error[];
|
|
37
37
|
/** Individual files that invalidate this compilation when they change. */
|
|
38
38
|
fileDependencies: DependencySet;
|
|
39
|
+
/** Files that do not exist yet, and invalidate this compilation when they appear. */
|
|
40
|
+
missingDependencies: DependencySet;
|
|
39
41
|
}
|
|
40
42
|
/** The slice of `Compiler` this plugin taps. */
|
|
41
43
|
interface CompilerLike {
|
|
@@ -93,6 +95,22 @@ declare class LunoraRspackPlugin {
|
|
|
93
95
|
* Idempotent: the pass below sees `#started` and skips its own call.
|
|
94
96
|
*/
|
|
95
97
|
prepareDevSession(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Run a watch-mode codegen pass now, ahead of the first compilation.
|
|
100
|
+
*
|
|
101
|
+
* Public for the same ordering reason as {@link prepareDevSession}: the
|
|
102
|
+
* Worker `@lunora/rspack/rsbuild` spawns is bundled by `wrangler dev` at
|
|
103
|
+
* startup, and it imports `_generated/app` — which, on a fresh clone, only
|
|
104
|
+
* this pass writes. Spawned first, wrangler dies on an unresolvable import
|
|
105
|
+
* before the first compilation ever generates it. The first compilation then
|
|
106
|
+
* finds the fingerprint unchanged and skips its own pass.
|
|
107
|
+
*
|
|
108
|
+
* Returns the target that pass generated for, so the Worker started next is the
|
|
109
|
+
* one its output matches. Reading `target` again after this resolves would leave
|
|
110
|
+
* a window in which an edit to `lunora.config.*` starts a Worker against output
|
|
111
|
+
* for the other target.
|
|
112
|
+
*/
|
|
113
|
+
generateForDev(): Promise<string>;
|
|
96
114
|
/** Rspack's plugin entry point. */
|
|
97
115
|
apply(compiler: CompilerLike): void;
|
|
98
116
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as r}from"node:module";import{
|
|
1
|
+
import{createRequire as r}from"node:module";import{L as e,r as a}from"./packem_shared/plugin-DTSWDf5-.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-DTSWDf5-.mjs";export{r as LunoraRspackPlugin,s as PLUGIN_NAME};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createHash as v}from"node:crypto";import{existsSync as w,readFileSync as S}from"node:fs";import{join as E,resolve as a}from"node:path";import{createCodegenProject as y,refreshCodegenProject as P,runCodegen as D,findTsconfig as d,PROJECT_CONFIG_FILENAMES as u,projectConfigCandidatePaths as p,fingerprintSchemaSources as C}from"@lunora/codegen";import{resolveTargetOrThrow as F,isRunnableTarget as T,runnableTargetIds as k,assertBuildTargetMatches as b,resolveLazyFunctions as I,LUNORA_TAG as g,writeApiSpecMarker as A,reportCodegenFindings as L,blockingFindingsMessage as _,STRICT_ADVISORIES_ENV as N,isCodegenDisabled as $,CODEGEN_ENV as f,lunoraLine as c,runPostCodegenHook as O,ensureDevVariables as M,createConfirm as W,fillDevSecrets as x,ensureDevWorkerEnv as G,detectAgentRules as z,claimAgentRulesHint as H,AGENT_RULES_HINT as U}from"@lunora/config";import{wranglerCodegenInputs as V,reconcileWranglerExtras as B,WRANGLER_FILES as J,warnCloudflareCliConfigOnce as X,findWranglerFile as q,reconcileBindingsSafely as K,assertWranglerSatisfiesSchema as Q}from"@lunora/config/cloudflare";const j=(t,e)=>{const r=F(t,e);if(!T(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: ${k().join(", ")}`);return b(r,t),r},ae=t=>{const e=t??{},r=e.projectRoot??process.cwd();return{apiSpec:e.apiSpec??"openapi",explicitTarget:e.target,lazyFunctions:I(e.lazyFunctions),projectRoot:r,schemaDir:e.schemaDir??"lunora",target:j(r,e.target),validateWrangler:e.validateWrangler??!0}},Y=(t,e,r)=>{const i=E(t.projectRoot,t.schemaDir,"schema.ts");if(!w(i))return e.warn(`${g} no schema found at ${i} — run \`lunora init\` or create it, then rebuild.`),{};const s=D({apiSpec:t.apiSpec,lazyFunctions:t.lazyFunctions,lunoraDirectory:t.schemaDir,project:r,projectRoot:t.projectRoot,target:t.target,...V(t.projectRoot)});B(t.projectRoot,s.cronTriggers,e);let o;try{A(t.projectRoot,t.apiSpec)}catch(h){o=`${g} could not write the API spec marker: ${h instanceof Error?h.message:String(h)}`,e.error(o)}return L(s,e),{blockingMessage:_(s,{strictAdvisories:process.env[N]!=="0"}),markerFailure:o}},Z=t=>{let e;return{drop:()=>{e=void 0},get:()=>(e===void 0?e=y(t):P(e,t),e)}},m="LunoraRspackPlugin",ee=2,l=t=>{try{return S(t,"utf8")}catch{return""}},n={error:t=>{console.error(t)},info:t=>{console.info(t)},warn:t=>{console.warn(t)}},R=async t=>{const e=r=>{n.info(c(r))};await M({confirm:W("[lunora] "),cwd:t.projectRoot,info:e}),x({cwd:t.projectRoot,info:e}),G(t.projectRoot,e),!z(t.projectRoot).installed&&H()&&n.warn(`
|
|
2
|
+
${c(U)}
|
|
3
|
+
`)};class ce{#e;#c;#t;#h;#o;#i=!1;#l=!1;#n;#d;#r=[];#s;#a;constructor(e){this.#e=e,this.#t=a(e.projectRoot,e.schemaDir),this.#h=$(process.env[f]),this.#o=Z(this.#t)}async prepareDevSession(){this.#p(),!this.#i&&(this.#i=!0,await R(this.#e))}async generateForDev(){return await this.#u(!0),this.#c??this.#e.target}apply(e){e.hooks.beforeCompile.tapPromise(m,async()=>{await this.#u(e.watchMode===!0)}),e.hooks.afterCompile.tapPromise(m,r=>{r.contextDependencies.add(this.#t);const i=d(this.#t);i!==void 0&&r.fileDependencies.add(i);const s=[...J.map(o=>a(this.#e.projectRoot,o)),...u.map(o=>a(this.#e.projectRoot,o)),...p(this.#t)];for(const o of new Set(s))w(o)?r.fileDependencies.add(o):r.missingDependencies.add(o);for(const o of this.#r)r.errors.push(o);return Promise.resolve()})}async#u(e){this.#a??=this.#f(e).finally(()=>{this.#a=void 0}),await this.#a}#p(){this.#l||(this.#l=X(this.#e.projectRoot,e=>{n.warn(c(e))}))}async#f(e){if(this.#p(),e&&this.#h){this.#i||(this.#i=!0,n.info(c(`codegen disabled via ${f} — skipping generation and the wrangler checks.`)));return}const r=this.#j();r!==this.#d&&(this.#o.drop(),this.#d=r,this.#n=void 0);const i=this.#R(r);if(!this.#m(i)){this.#r=[];try{!this.#i&&e&&await R(this.#e),this.#i=!0,await this.#w(e),this.#r.length===0?(this.#n=i,this.#s=void 0):this.#g(i)}catch(s){this.#o.drop(),this.#n=void 0,this.#r.push(s instanceof Error?s:new Error(String(s))),this.#g(i),n.error(s instanceof Error?s.message:String(s))}}}#m(e){return e===this.#n?!0:this.#s!==void 0&&this.#s.fingerprint===e&&this.#s.attempts>=ee}#g(e){this.#s=this.#s?.fingerprint===e?{attempts:this.#s.attempts+1,fingerprint:e}:{attempts:1,fingerprint:e}}#R(e){const r=q(this.#e.projectRoot);return[C(this.#t),e,r===void 0?"":l(r)].map(s=>v("sha256").update(s).digest("hex")).join("")}async#w(e){this.#e={...this.#e,target:j(this.#e.projectRoot,this.#e.explicitTarget)},await K(this.#e,n),this.#e.validateWrangler&&Q(this.#e,n.warn,"Update your wrangler.jsonc and rebuild.");const{blockingMessage:r,markerFailure:i}=Y(this.#e,n,this.#o.get());this.#c=this.#e.target;const s=await O({cwd:this.#e.projectRoot,logger:n});s.error!==void 0&&this.#r.push(new Error(s.error)),!e&&r!==void 0&&this.#r.push(new Error(r)),!e&&i!==void 0&&this.#r.push(new Error(i))}#j(){const e=d(this.#t),i=[...new Set([...p(this.#t),...u.map(s=>a(this.#e.projectRoot,s))])].map(s=>`${s}
|
|
4
|
+
${l(s)}`);return[e===void 0?"":l(e),...i].join("\0")}}export{ce as L,m as P,ae as r};
|
|
@@ -3,9 +3,10 @@ import { CodegenOptions } from '@lunora/codegen';
|
|
|
3
3
|
* Options for the `lunoraRspack()` plugin factory.
|
|
4
4
|
*
|
|
5
5
|
* Deliberately a subset of `@lunora/vite`'s. Everything absent here is
|
|
6
|
-
* Vite-dev-server machinery with no Rspack counterpart (`overlay`,
|
|
6
|
+
* Vite-dev-server machinery with no Rspack counterpart (`overlay`,
|
|
7
7
|
* `cloudflare`, `shard`) — see the package README for which of those the
|
|
8
|
-
* wrangler side of the stack covers instead.
|
|
8
|
+
* wrangler side of the stack covers instead. `studio` lives on the Rsbuild
|
|
9
|
+
* options, since it needs a dev server to mount on.
|
|
9
10
|
*/
|
|
10
11
|
interface LunoraRspackOptions {
|
|
11
12
|
/**
|
|
@@ -16,6 +17,8 @@ interface LunoraRspackOptions {
|
|
|
16
17
|
* the value set is derived from `CodegenOptions` so it can't drift.
|
|
17
18
|
*/
|
|
18
19
|
apiSpec?: CodegenOptions["apiSpec"];
|
|
20
|
+
/** Emit a per-module lazy function registry; omitted keeps the eager registry. */
|
|
21
|
+
lazyFunctions?: CodegenOptions["lazyFunctions"];
|
|
19
22
|
/** Project root containing the `lunora/` directory. Defaults to `process.cwd()`. */
|
|
20
23
|
projectRoot?: string;
|
|
21
24
|
/** Directory name (relative to `projectRoot`) containing `schema.ts` and function files. Defaults to `"lunora"`. */
|
|
@@ -35,6 +38,9 @@ interface LunoraRspackOptions {
|
|
|
35
38
|
/** Resolved options after merging defaults. */
|
|
36
39
|
interface ResolvedLunoraRspackOptions {
|
|
37
40
|
apiSpec: NonNullable<CodegenOptions["apiSpec"]>;
|
|
41
|
+
/** The target the caller passed, if any. Kept so a `lunora.config.*` edit can re-resolve `target` in watch mode. */
|
|
42
|
+
explicitTarget: string | undefined;
|
|
43
|
+
lazyFunctions: boolean;
|
|
38
44
|
projectRoot: string;
|
|
39
45
|
schemaDir: string;
|
|
40
46
|
target: string;
|
|
@@ -3,9 +3,10 @@ import { CodegenOptions } from '@lunora/codegen';
|
|
|
3
3
|
* Options for the `lunoraRspack()` plugin factory.
|
|
4
4
|
*
|
|
5
5
|
* Deliberately a subset of `@lunora/vite`'s. Everything absent here is
|
|
6
|
-
* Vite-dev-server machinery with no Rspack counterpart (`overlay`,
|
|
6
|
+
* Vite-dev-server machinery with no Rspack counterpart (`overlay`,
|
|
7
7
|
* `cloudflare`, `shard`) — see the package README for which of those the
|
|
8
|
-
* wrangler side of the stack covers instead.
|
|
8
|
+
* wrangler side of the stack covers instead. `studio` lives on the Rsbuild
|
|
9
|
+
* options, since it needs a dev server to mount on.
|
|
9
10
|
*/
|
|
10
11
|
interface LunoraRspackOptions {
|
|
11
12
|
/**
|
|
@@ -16,6 +17,8 @@ interface LunoraRspackOptions {
|
|
|
16
17
|
* the value set is derived from `CodegenOptions` so it can't drift.
|
|
17
18
|
*/
|
|
18
19
|
apiSpec?: CodegenOptions["apiSpec"];
|
|
20
|
+
/** Emit a per-module lazy function registry; omitted keeps the eager registry. */
|
|
21
|
+
lazyFunctions?: CodegenOptions["lazyFunctions"];
|
|
19
22
|
/** Project root containing the `lunora/` directory. Defaults to `process.cwd()`. */
|
|
20
23
|
projectRoot?: string;
|
|
21
24
|
/** Directory name (relative to `projectRoot`) containing `schema.ts` and function files. Defaults to `"lunora"`. */
|
|
@@ -35,6 +38,9 @@ interface LunoraRspackOptions {
|
|
|
35
38
|
/** Resolved options after merging defaults. */
|
|
36
39
|
interface ResolvedLunoraRspackOptions {
|
|
37
40
|
apiSpec: NonNullable<CodegenOptions["apiSpec"]>;
|
|
41
|
+
/** The target the caller passed, if any. Kept so a `lunora.config.*` edit can re-resolve `target` in watch mode. */
|
|
42
|
+
explicitTarget: string | undefined;
|
|
43
|
+
lazyFunctions: boolean;
|
|
38
44
|
projectRoot: string;
|
|
39
45
|
schemaDir: string;
|
|
40
46
|
target: string;
|
package/dist/rsbuild.d.mts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { L as LunoraRspackOptions } from "./packem_shared/types.d-DCaFxXeH.mjs";
|
|
2
3
|
import '@lunora/codegen';
|
|
3
4
|
/** Path prefix the Lunora Worker serves — RPC, the WebSocket, and the studio. */
|
|
4
5
|
declare const LUNORA_PATH = "/_lunora";
|
|
5
6
|
/** Name Rsbuild lists this plugin under. */
|
|
6
7
|
declare const RSBUILD_PLUGIN_NAME = "lunora:rsbuild";
|
|
7
8
|
interface LunoraRsbuildOptions extends LunoraRspackOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Serve Lunora Studio at `/__lunora` on the dev server — the same URL, and
|
|
11
|
+
* the same app, as `@lunora/vite`. Needs `@lunora/studio` installed.
|
|
12
|
+
* `false` opts out.
|
|
13
|
+
*
|
|
14
|
+
* Defaults to `true`.
|
|
15
|
+
*/
|
|
16
|
+
studio?: boolean;
|
|
8
17
|
/**
|
|
9
18
|
* Run `wrangler dev` alongside the dev server and proxy {@link LUNORA_PATH}
|
|
10
19
|
* to it. `false` opts out — for a project that starts the Worker itself, or
|
|
@@ -27,11 +36,23 @@ interface LunoraRsbuildOptions extends LunoraRspackOptions {
|
|
|
27
36
|
* OPTIONAL peer, so its types must not reach this package's published `.d.ts`.
|
|
28
37
|
*/
|
|
29
38
|
interface RsbuildApiLike {
|
|
39
|
+
getRsbuildConfig: () => Readonly<RsbuildConfigLike>;
|
|
30
40
|
modifyRsbuildConfig: (callback: (config: RsbuildConfigLike) => RsbuildConfigLike) => void;
|
|
31
41
|
modifyRspackConfig: (callback: (config: RspackConfigLike) => RspackConfigLike) => void;
|
|
32
|
-
|
|
42
|
+
onAfterStartDevServer: (callback: (params: {
|
|
43
|
+
port: number;
|
|
44
|
+
}) => Promise<void> | void) => void;
|
|
45
|
+
onBeforeStartDevServer: (callback: (params: {
|
|
46
|
+
server: DevServerLike;
|
|
47
|
+
}) => Promise<void> | void) => void;
|
|
33
48
|
onCloseDevServer: (callback: () => Promise<void> | void) => void;
|
|
34
49
|
}
|
|
50
|
+
/** The slice of Rsbuild's dev server this uses: its Connect middleware stack. */
|
|
51
|
+
interface DevServerLike {
|
|
52
|
+
middlewares: {
|
|
53
|
+
use: (handler: (request: IncomingMessage, response: ServerResponse, next: () => void) => void) => unknown;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
35
56
|
/** A single entry of Rsbuild's array-form `server.proxy`. */
|
|
36
57
|
type ProxyArrayEntry = Record<string, unknown> & {
|
|
37
58
|
pathFilter?: unknown;
|
|
@@ -50,6 +71,8 @@ interface RspackConfigLike {
|
|
|
50
71
|
/** The slice of Rsbuild's config this plugin writes. */
|
|
51
72
|
interface RsbuildConfigLike {
|
|
52
73
|
server?: {
|
|
74
|
+
base?: string;
|
|
75
|
+
host?: string;
|
|
53
76
|
proxy?: ProxyConfigLike;
|
|
54
77
|
};
|
|
55
78
|
}
|
|
@@ -96,4 +119,4 @@ declare const withLunoraProxy: (existing: ProxyConfigLike | undefined, port: num
|
|
|
96
119
|
* misconfigured by hand.
|
|
97
120
|
*/
|
|
98
121
|
declare const lunoraRsbuild: (options?: LunoraRsbuildOptions) => RsbuildPluginLike;
|
|
99
|
-
export { LUNORA_PATH, type LunoraRsbuildOptions, type ProxyConfigLike, RSBUILD_PLUGIN_NAME, type RsbuildApiLike, type RsbuildConfigLike, type RsbuildPluginLike, type RspackConfigLike, lunoraRsbuild, withLunoraProxy };
|
|
122
|
+
export { type DevServerLike, LUNORA_PATH, type LunoraRsbuildOptions, type ProxyConfigLike, RSBUILD_PLUGIN_NAME, type RsbuildApiLike, type RsbuildConfigLike, type RsbuildPluginLike, type RspackConfigLike, lunoraRsbuild, withLunoraProxy };
|
package/dist/rsbuild.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { L as LunoraRspackOptions } from "./packem_shared/types.d-DCaFxXeH.js";
|
|
2
3
|
import '@lunora/codegen';
|
|
3
4
|
/** Path prefix the Lunora Worker serves — RPC, the WebSocket, and the studio. */
|
|
4
5
|
declare const LUNORA_PATH = "/_lunora";
|
|
5
6
|
/** Name Rsbuild lists this plugin under. */
|
|
6
7
|
declare const RSBUILD_PLUGIN_NAME = "lunora:rsbuild";
|
|
7
8
|
interface LunoraRsbuildOptions extends LunoraRspackOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Serve Lunora Studio at `/__lunora` on the dev server — the same URL, and
|
|
11
|
+
* the same app, as `@lunora/vite`. Needs `@lunora/studio` installed.
|
|
12
|
+
* `false` opts out.
|
|
13
|
+
*
|
|
14
|
+
* Defaults to `true`.
|
|
15
|
+
*/
|
|
16
|
+
studio?: boolean;
|
|
8
17
|
/**
|
|
9
18
|
* Run `wrangler dev` alongside the dev server and proxy {@link LUNORA_PATH}
|
|
10
19
|
* to it. `false` opts out — for a project that starts the Worker itself, or
|
|
@@ -27,11 +36,23 @@ interface LunoraRsbuildOptions extends LunoraRspackOptions {
|
|
|
27
36
|
* OPTIONAL peer, so its types must not reach this package's published `.d.ts`.
|
|
28
37
|
*/
|
|
29
38
|
interface RsbuildApiLike {
|
|
39
|
+
getRsbuildConfig: () => Readonly<RsbuildConfigLike>;
|
|
30
40
|
modifyRsbuildConfig: (callback: (config: RsbuildConfigLike) => RsbuildConfigLike) => void;
|
|
31
41
|
modifyRspackConfig: (callback: (config: RspackConfigLike) => RspackConfigLike) => void;
|
|
32
|
-
|
|
42
|
+
onAfterStartDevServer: (callback: (params: {
|
|
43
|
+
port: number;
|
|
44
|
+
}) => Promise<void> | void) => void;
|
|
45
|
+
onBeforeStartDevServer: (callback: (params: {
|
|
46
|
+
server: DevServerLike;
|
|
47
|
+
}) => Promise<void> | void) => void;
|
|
33
48
|
onCloseDevServer: (callback: () => Promise<void> | void) => void;
|
|
34
49
|
}
|
|
50
|
+
/** The slice of Rsbuild's dev server this uses: its Connect middleware stack. */
|
|
51
|
+
interface DevServerLike {
|
|
52
|
+
middlewares: {
|
|
53
|
+
use: (handler: (request: IncomingMessage, response: ServerResponse, next: () => void) => void) => unknown;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
35
56
|
/** A single entry of Rsbuild's array-form `server.proxy`. */
|
|
36
57
|
type ProxyArrayEntry = Record<string, unknown> & {
|
|
37
58
|
pathFilter?: unknown;
|
|
@@ -50,6 +71,8 @@ interface RspackConfigLike {
|
|
|
50
71
|
/** The slice of Rsbuild's config this plugin writes. */
|
|
51
72
|
interface RsbuildConfigLike {
|
|
52
73
|
server?: {
|
|
74
|
+
base?: string;
|
|
75
|
+
host?: string;
|
|
53
76
|
proxy?: ProxyConfigLike;
|
|
54
77
|
};
|
|
55
78
|
}
|
|
@@ -96,4 +119,4 @@ declare const withLunoraProxy: (existing: ProxyConfigLike | undefined, port: num
|
|
|
96
119
|
* misconfigured by hand.
|
|
97
120
|
*/
|
|
98
121
|
declare const lunoraRsbuild: (options?: LunoraRsbuildOptions) => RsbuildPluginLike;
|
|
99
|
-
export { LUNORA_PATH, type LunoraRsbuildOptions, type ProxyConfigLike, RSBUILD_PLUGIN_NAME, type RsbuildApiLike, type RsbuildConfigLike, type RsbuildPluginLike, type RspackConfigLike, lunoraRsbuild, withLunoraProxy };
|
|
122
|
+
export { type DevServerLike, LUNORA_PATH, type LunoraRsbuildOptions, type ProxyConfigLike, RSBUILD_PLUGIN_NAME, type RsbuildApiLike, type RsbuildConfigLike, type RsbuildPluginLike, type RspackConfigLike, lunoraRsbuild, withLunoraProxy };
|
package/dist/rsbuild.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{formatLunoraEvent as h,lunoraLine as
|
|
2
|
-
`);t=e.pop()??"";for(const s of e)d(s)}),r?.once("end",()=>{t!==""&&(d(t),t="")})},O=async r=>{if(await w(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\`.`);const t=["dev","--port",String(r.port),"--var","WORKER_ENV:development",...r.wranglerArgs??[]],o=process.platform==="win32",e=k(o?"wrangler.cmd":"wrangler",t,{cwd:r.projectRoot,shell:o,stdio:["ignore","pipe","pipe"]});u(e.stdout),u(e.stderr);let s;e.once("error",i=>{s=i.code==="ENOENT"?new Error("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."):i});const a=()=>{e.kill("SIGKILL")};process.once("exit",a);const l=async()=>{process.removeListener("exit",a),!(e.exitCode!==null||e.signalCode!==null)&&await new Promise(i=>{const v=setTimeout(()=>{e.kill("SIGKILL")},P);e.once("exit",()=>{clearTimeout(v),i()}),e.kill("SIGTERM")})};let n;e.once("exit",i=>{n??=new Error(`wrangler dev exited with code ${String(i)} before it was ready`)});const f=Date.now()+c;for(;Date.now()<f;){if(s!==void 0)throw s;if(n!==void 0)throw n;if(await w(r.port)){if(e.exitCode!==null||e.signalCode!==null)throw await l(),new Error(`the worker on port ${String(r.port)} is not the one this plugin started — it exited while something else took the port.`);return{port:r.port,stop:l}}await new Promise(i=>{setTimeout(i,A)})}throw await l(),new Error(`wrangler dev did not start listening on port ${String(r.port)} within ${String(c/1e3)}s`)},p="/_lunora",T="lunora:rsbuild",_=(r,t)=>{const o=`http://127.0.0.1:${String(t)}`;return Array.isArray(r)?[...r,{changeOrigin:!0,pathFilter:p,target:o,ws:!0}]:{[p]:{changeOrigin:!0,target:o,ws:!0},...r}},$=r=>{const t=m(r),o=r?.worker!==!1,e=x(t.projectRoot,r?.workerPort),s=new S(t);return{name:T,setup:a=>{if(a.modifyRspackConfig(n=>({...n,plugins:[...Array.isArray(n.plugins)?n.plugins:[],s]})),a.modifyRsbuildConfig(n=>({...n,server:{...n.server,proxy:_(n.server?.proxy,e)}})),!o)return;let l;a.onBeforeStartDevServer(async()=>{await s.prepareDevSession(),console.info(g(`starting the worker on http://127.0.0.1:${String(e)} …`)),l=await O({port:e,projectRoot:t.projectRoot,wranglerArgs:r?.wranglerArgs})}),a.onCloseDevServer(async()=>{await l?.stop(),l=void 0})}}};export{p as LUNORA_PATH,T as RSBUILD_PLUGIN_NAME,$ as lunoraRsbuild,_ as withLunoraProxy};
|
|
1
|
+
import{formatLunoraEvent as h,lunoraLine as c,acceptsConnection as y,startDevProcess as S,targetRunsOwnDevServer as R,startCelldDevSession as k}from"@lunora/config";import{createStudioMiddleware as A,isNonLoopbackHost as D,studioMountPath as b}from"@lunora/config/studio-host";import{r as L,L as P}from"./packem_shared/plugin-DTSWDf5-.mjs";import{existsSync as E,mkdirSync as W}from"node:fs";import{resolve as f,dirname as j}from"node:path";import{findWranglerFile as x,readWranglerJsonc as O}from"@lunora/config/cloudflare";const _=8787,$=3e4,v=(r,e,t)=>{let o;for(const[n,a]of r.entries())a.startsWith(`${e}=`)?o=a.slice(e.length+1):(a===e||a===t)&&n+1<r.length&&(o=r[n+1]);return o},p=(r,e=[])=>{const t=v(e,"--config","-c"),o=t===void 0?x(r):f(r,t);if(o===void 0||!E(o))return;const{parsed:n}=O(o);return n===void 0?void 0:{config:n,env:v(e,"--env","-e"),path:o}},T=(r,e,t)=>{if(e!==void 0)return e;const o=p(r,t)?.config.dev?.port;return typeof o=="number"?o:_},C=(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"&&W(f(j(t.path),n),{recursive:!0})},w=r=>{const e=h(r);if(e===void 0){r.trim()!==""&&console.log(r);return}const t=c(e.text);e.level==="error"?console.error(t):e.level==="warn"?console.warn(t):console.info(t)},F=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\`.`);C(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:$,shell:e});return{port:r.port,stop:t.stop}},g="/_lunora",M="lunora:rsbuild",N=(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}},U=(r,e)=>{r.onBeforeStartDevServer(({server:t})=>{const{base:o,host:n}=r.getRsbuildConfig().server??{};t.middlewares.use(A({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,base:o,isNonLoopbackBind:D(n),projectRoot:e.projectRoot,schemaDirectory:e.schemaDir}))}),r.onAfterStartDevServer(({port:t})=>{console.info(c(`studio on http://localhost:${String(t)}${b(r.getRsbuildConfig().server?.base)}`))})},G=r=>{const e=L(r),t=T(e.projectRoot,r?.workerPort,r?.wranglerArgs),o=new P(e);return{name:M,setup:n=>{if(n.modifyRspackConfig(s=>({...s,plugins:[...Array.isArray(s.plugins)?s.plugins:[],o]})),n.modifyRsbuildConfig(s=>({...s,server:{...s.server,proxy:N(s.server?.proxy,t)}})),r?.studio!==!1&&U(n,e),r?.worker===!1)return;let a,l;n.onBeforeStartDevServer(async()=>{await o.prepareDevSession();const s=await o.generateForDev();if(console.info(c(`starting the worker on http://127.0.0.1:${String(t)} …`)),R(s)){const d=await k({log:(i,{tag:u})=>{w(u==="celld"?i:`[${u}] ${i}`)},port:t,projectRoot:e.projectRoot});l=d;const m=i=>{console.error(c(`the worker on celld exited (code ${String(i)}) — restart \`rsbuild dev\` to bring it back`))};d.exited.then(m).catch(()=>{});return}a=await F({port:t,projectRoot:e.projectRoot,wranglerArgs:r?.wranglerArgs})}),n.onCloseDevServer(async()=>{await a?.stop(),await l?.stop(),a=void 0,l=void 0})}}};export{g as LUNORA_PATH,M as RSBUILD_PLUGIN_NAME,G as lunoraRsbuild,N as withLunoraProxy};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/rspack",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.100",
|
|
4
4
|
"description": "The Lunora Rspack plugin: codegen, binding provisioning, and wrangler validation for Rspack projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -51,14 +51,18 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@lunora/codegen": "1.0.0-alpha.
|
|
55
|
-
"@lunora/config": "1.0.0-alpha.
|
|
54
|
+
"@lunora/codegen": "1.0.0-alpha.351",
|
|
55
|
+
"@lunora/config": "1.0.0-alpha.404"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
+
"@lunora/studio": ">=1.0.0-alpha.50 <2.0.0-0",
|
|
58
59
|
"@rsbuild/core": "^2.0.0",
|
|
59
60
|
"@rspack/core": "^1.5.0 || ^2.0.0"
|
|
60
61
|
},
|
|
61
62
|
"peerDependenciesMeta": {
|
|
63
|
+
"@lunora/studio": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
62
66
|
"@rsbuild/core": {
|
|
63
67
|
"optional": true
|
|
64
68
|
},
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{createHash as g}from"node:crypto";import{existsSync as p,readFileSync as u}from"node:fs";import{join as m,resolve as v}from"node:path";import{createCodegenProject as R,refreshCodegenProject as j,runCodegen as w,findTsconfig as a,fingerprintSchemaSources as S}from"@lunora/codegen";import{LUNORA_TAG as E,reportCodegenFindings as y,blockingFindingsMessage as D,isCodegenDisabled as P,CODEGEN_ENV as c,lunoraLine as n,runPostCodegenHook as b,ensureDevVariables as k,createConfirm as C,fillDevSecrets as F,ensureDevWorkerEnv as A,detectAgentRules as L,claimAgentRulesHint as T,AGENT_RULES_HINT as N}from"@lunora/config";import{collectWranglerSecretVariables as _,reconcileWranglerExtras as W,findWranglerFile as h,reconcileBindingsSafely as x,assertWranglerSatisfiesSchema as M}from"@lunora/config/cloudflare";const G=(t,e,r)=>{const i=m(t.projectRoot,t.schemaDir,"schema.ts");if(!p(i)){e.warn(`${E} no schema found at ${i} — run \`lunora init\` or create it, then rebuild.`);return}const s=w({apiSpec:t.apiSpec,lunoraDirectory:t.schemaDir,project:r,projectRoot:t.projectRoot,target:t.target,wranglerVariables:_(t.projectRoot)});return W(t.projectRoot,s.cronTriggers,e),y(s,e),D(s)},H=t=>{let e;return{drop:()=>{e=void 0},get:()=>(e===void 0?e=R(t):j(e,t),e)}},d="LunoraRspackPlugin",I=2,l=t=>{try{return u(t,"utf8")}catch{return""}},o={error:t=>{console.error(t)},info:t=>{console.info(t)},warn:t=>{console.warn(t)}},f=async t=>{const e=r=>{o.info(n(r))};await k({confirm:C("[lunora] "),cwd:t.projectRoot,info:e}),F({cwd:t.projectRoot,info:e}),A(t.projectRoot,e),!L(t.projectRoot).installed&&T()&&o.warn(`
|
|
2
|
-
${n(N)}
|
|
3
|
-
`)};class q{#e;#r;#c;#o;#i=!1;#n;#h;#s=[];#t;#a;constructor(e){this.#e=e,this.#r=v(e.projectRoot,e.schemaDir),this.#c=P(process.env[c]),this.#o=H(this.#r)}async prepareDevSession(){this.#i||(this.#i=!0,await f(this.#e))}apply(e){e.hooks.beforeCompile.tapPromise(d,async()=>{this.#a??=this.#l(e.watchMode===!0).finally(()=>{this.#a=void 0}),await this.#a}),e.hooks.afterCompile.tapPromise(d,r=>{r.contextDependencies.add(this.#r);for(const i of[a(this.#r),h(this.#e.projectRoot)])i!==void 0&&r.fileDependencies.add(i);for(const i of this.#s)r.errors.push(i);return Promise.resolve()})}async#l(e){if(e&&this.#c){this.#i||(this.#i=!0,o.info(n(`codegen disabled via ${c} — skipping generation and the wrangler checks.`)));return}const r=this.#u();r!==this.#h&&(this.#o.drop(),this.#h=r,this.#n=void 0);const i=this.#g(r);if(!this.#f(i)){this.#s=[];try{!this.#i&&e&&await f(this.#e),this.#i=!0,await this.#p(e),this.#s.length===0?(this.#n=i,this.#t=void 0):this.#d(i)}catch(s){this.#o.drop(),this.#n=void 0,this.#s.push(s instanceof Error?s:new Error(String(s))),this.#d(i),o.error(s instanceof Error?s.message:String(s))}}}#f(e){return e===this.#n?!0:this.#t!==void 0&&this.#t.fingerprint===e&&this.#t.attempts>=I}#d(e){this.#t=this.#t?.fingerprint===e?{attempts:this.#t.attempts+1,fingerprint:e}:{attempts:1,fingerprint:e}}#g(e){const r=h(this.#e.projectRoot);return[S(this.#r),e,r===void 0?"":l(r)].map(s=>g("sha256").update(s).digest("hex")).join("")}async#p(e){await x(this.#e,o),this.#e.validateWrangler&&M(this.#e,o.warn,"Update your wrangler.jsonc and rebuild.");const r=G(this.#e,o,this.#o.get()),i=await b({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))}#u(){const e=a(this.#r);return e===void 0?"":l(e)}}export{q as LunoraRspackPlugin,d as PLUGIN_NAME};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{resolveTargetOrThrow as o,isRunnableTarget as a,runnableTargetIds as n}from"@lunora/config";const i=(t,r)=>{const e=o(t,r);if(!a(e))throw new Error(`target "${e}" has no command-line toolchain, so the Lunora Rspack plugin cannot build for it — it can only generate for it (\`lunora codegen --target ${e}\`). Buildable targets: ${n().join(", ")}`);return e},c=t=>{const r=t??{},e=r.projectRoot??process.cwd();return{apiSpec:r.apiSpec??"openapi",projectRoot:e,schemaDir:r.schemaDir??"lunora",target:i(e,r.target),validateWrangler:r.validateWrangler??!0}};export{c as r};
|