@nifrajs/web 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2970 -0
- package/dist/build-plan.d.ts +7 -0
- package/dist/build-plan.d.ts.map +1 -1
- package/dist/build-plan.js +19 -0
- package/dist/build-plan.js.map +1 -1
- package/dist/build-vite.d.ts +1 -0
- package/dist/build-vite.d.ts.map +1 -1
- package/dist/build-vite.js +51 -3
- package/dist/build-vite.js.map +1 -1
- package/dist/build.d.ts +12 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +43 -6
- package/dist/build.js.map +1 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +14 -7
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/codegen.d.ts +6 -0
- package/dist/internal/codegen.d.ts.map +1 -1
- package/dist/internal/codegen.js +23 -5
- package/dist/internal/codegen.js.map +1 -1
- package/dist/internal/copy-split.d.ts +27 -0
- package/dist/internal/copy-split.d.ts.map +1 -0
- package/dist/internal/copy-split.js +173 -0
- package/dist/internal/copy-split.js.map +1 -0
- package/dist/internal/page-execution.d.ts +19 -1
- package/dist/internal/page-execution.d.ts.map +1 -1
- package/dist/internal/page-execution.js +63 -8
- package/dist/internal/page-execution.js.map +1 -1
- package/dist/internal/render-document.d.ts +11 -2
- package/dist/internal/render-document.d.ts.map +1 -1
- package/dist/internal/render-document.js +38 -6
- package/dist/internal/render-document.js.map +1 -1
- package/dist/internal/typescript-api.d.ts +4 -0
- package/dist/internal/typescript-api.d.ts.map +1 -0
- package/dist/internal/typescript-api.js +8 -0
- package/dist/internal/typescript-api.js.map +1 -0
- package/dist/internal/vite-plugin-compat.d.ts +28 -0
- package/dist/internal/vite-plugin-compat.d.ts.map +1 -0
- package/dist/internal/vite-plugin-compat.js +82 -0
- package/dist/internal/vite-plugin-compat.js.map +1 -0
- package/dist/internal/web-app.d.ts +34 -0
- package/dist/internal/web-app.d.ts.map +1 -1
- package/dist/internal/web-app.js +22 -0
- package/dist/internal/web-app.js.map +1 -1
- package/dist/plugins/import-glob.d.ts +20 -0
- package/dist/plugins/import-glob.d.ts.map +1 -0
- package/dist/plugins/import-glob.js +401 -0
- package/dist/plugins/import-glob.js.map +1 -0
- package/dist/plugins/kit.d.ts +11 -0
- package/dist/plugins/kit.d.ts.map +1 -1
- package/dist/plugins/kit.js +32 -0
- package/dist/plugins/kit.js.map +1 -1
- package/dist/plugins/stylex.d.ts.map +1 -1
- package/dist/plugins/stylex.js +2 -2
- package/dist/plugins/stylex.js.map +1 -1
- package/dist/render-seam.d.ts +37 -0
- package/dist/render-seam.d.ts.map +1 -1
- package/dist/render-seam.js +33 -0
- package/dist/render-seam.js.map +1 -1
- package/dist/router.d.ts +3 -2
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +4 -4
- package/dist/router.js.map +1 -1
- package/dist/server-components/typescript.d.ts.map +1 -1
- package/dist/server-components/typescript.js +2 -7
- package/dist/server-components/typescript.js.map +1 -1
- package/dist/vite.d.ts +1 -28
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +3 -69
- package/dist/vite.js.map +1 -1
- package/package.json +5 -4
- package/src/build-plan.ts +21 -0
- package/src/build-vite.ts +60 -3
- package/src/build.ts +57 -4
- package/src/client.ts +15 -7
- package/src/index.ts +6 -0
- package/src/internal/codegen.ts +32 -3
- package/src/internal/copy-split.ts +220 -0
- package/src/internal/page-execution.ts +83 -7
- package/src/internal/render-document.ts +63 -6
- package/src/internal/typescript-api.ts +11 -0
- package/src/internal/vite-plugin-compat.ts +81 -0
- package/src/internal/web-app.ts +61 -1
- package/src/plugins/import-glob.ts +392 -0
- package/src/plugins/kit.ts +36 -0
- package/src/plugins/stylex.ts +2 -1
- package/src/render-seam.ts +60 -0
- package/src/router.ts +7 -6
- package/src/server-components/typescript.ts +2 -10
- package/src/vite.ts +3 -81
package/src/vite.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
} from "./internal/parity.ts"
|
|
36
36
|
import { vitePublicEnvPrefix } from "./internal/server-boundary.ts"
|
|
37
37
|
import { importVite } from "./internal/vite-import.ts"
|
|
38
|
+
import { normalizeRolldownPlugins } from "./internal/vite-plugin-compat.ts"
|
|
38
39
|
import { scopedName } from "./plugins/css-modules.ts"
|
|
39
40
|
import {
|
|
40
41
|
DEV_ROOT_ENV,
|
|
@@ -168,6 +169,7 @@ export interface ViteDevServer {
|
|
|
168
169
|
|
|
169
170
|
export type { DevAppHooks } from "./dev-session.ts"
|
|
170
171
|
export { LAST_ERROR_PATH } from "./diagnostic.ts"
|
|
172
|
+
export { normalizeRolldownPlugins } from "./internal/vite-plugin-compat.ts"
|
|
171
173
|
|
|
172
174
|
// The codegen'd client entry is written here (at the Vite root) so Vite serves + HMRs it.
|
|
173
175
|
const DEV_ENTRY = ".nifra-vite-entry.tsx"
|
|
@@ -247,19 +249,6 @@ function toWebRequest(req: IncomingMessage, body: Buffer | undefined): Request {
|
|
|
247
249
|
return new Request(url, init as unknown as ConstructorParameters<typeof Request>[1])
|
|
248
250
|
}
|
|
249
251
|
|
|
250
|
-
// A Vite `config` hook: a plain function, OR the object form `{ handler, order }` Vite accepts for hook
|
|
251
|
-
// ordering (`order: "pre" | "post"`). We wrap the handler in either shape - see normalizeRolldownPlugins.
|
|
252
|
-
type ConfigFn = (config: unknown, env: unknown) => unknown
|
|
253
|
-
type ConfigHook = ConfigFn | { readonly handler: ConfigFn; readonly order?: unknown }
|
|
254
|
-
|
|
255
|
-
// A Vite plugin - the only hook we wrap is `config`. Typed structurally (no `vite` type dep). Everything
|
|
256
|
-
// else on the plugin object is preserved by spread, so wrapping is transparent to Vite.
|
|
257
|
-
interface VitePluginLike {
|
|
258
|
-
readonly name?: string
|
|
259
|
-
config?: ConfigHook
|
|
260
|
-
readonly [key: string]: unknown
|
|
261
|
-
}
|
|
262
|
-
|
|
263
252
|
/** The bits of a Node ServerResponse `pipeWebBodyToNode` touches - structural, to avoid a node:http dep here. */
|
|
264
253
|
interface NodeResLike {
|
|
265
254
|
flushHeaders?(): void
|
|
@@ -317,72 +306,6 @@ export async function pipeWebBodyToNode(
|
|
|
317
306
|
res.end()
|
|
318
307
|
}
|
|
319
308
|
|
|
320
|
-
/**
|
|
321
|
-
* Strip `optimizeDeps.rollupOptions.jsx` from a plugin's `config` hook output when running under
|
|
322
|
-
* rolldown-vite - the source of the scary, harmless `Warning: Invalid input options … "jsx" Invalid
|
|
323
|
-
* key: Expected never but received "jsx"` on `nifra dev`.
|
|
324
|
-
*
|
|
325
|
-
* Why it happens: `@vitejs/plugin-react@4.x` (and peers) target an *older* rolldown-vite optimizeDeps
|
|
326
|
-
* API - they inject `optimizeDeps.rollupOptions.jsx` to tell the dep pre-bundler to transform JSX. Vite
|
|
327
|
-
* 8's rolldown dep-optimizer renamed that surface to `optimizeDeps.rolldownOptions` (and moved jsx under
|
|
328
|
-
* `transform.jsx`), so the stale `rollupOptions.jsx` is an unrecognized input option → the warning. It's
|
|
329
|
-
* a version-skew artifact, not a real misconfig: the route source JSX transform runs through the
|
|
330
|
-
* plugin's own `transform` hook (untouched here), and node_modules deps that get pre-bundled almost
|
|
331
|
-
* never contain raw JSX - so dropping the dead key changes no behavior and keeps HMR/Fast Refresh
|
|
332
|
-
* intact. We *strip* (rather than translate to `rolldownOptions`) so the fix is version-agnostic: a
|
|
333
|
-
* plugin already emitting the correct `rolldownOptions` is left untouched, and a future plugin bump that
|
|
334
|
-
* stops emitting `rollupOptions.jsx` makes this a no-op.
|
|
335
|
-
*
|
|
336
|
-
* Scoped narrowly: only the `optimizeDeps.rollupOptions.jsx` key is removed, only under rolldown-vite,
|
|
337
|
-
* and only from the value a plugin's `config` hook returns. Non-rolldown Vite is passed through verbatim.
|
|
338
|
-
*
|
|
339
|
-
* FLATTEN FIRST: a Vite plugin factory may return an ARRAY of plugins - `@vitejs/plugin-react`'s `react()`
|
|
340
|
-
* returns `[vite:react-babel, vite:react-refresh]`, and it's `react:react-babel`'s `config` hook that emits
|
|
341
|
-
* the offending `optimizeDeps.rollupOptions.jsx`. `nifra.config.ts` writes `vitePlugins = [react()]`, so the
|
|
342
|
-
* plugin list arrives NESTED (`[[babel, refresh]]`). Without flattening, `.map` sees the inner array (which
|
|
343
|
-
* has no `config`), leaves it untouched, and Vite - which flattens plugin arrays itself before running them
|
|
344
|
-
* - then executes the un-stripped babel hook, so the warning survives. Flattening here (Vite accepts a flat
|
|
345
|
-
* list identically) is what lets the strip reach every real plugin.
|
|
346
|
-
*/
|
|
347
|
-
export function normalizeRolldownPlugins(
|
|
348
|
-
plugins: readonly unknown[],
|
|
349
|
-
isRolldown: boolean,
|
|
350
|
-
): readonly unknown[] {
|
|
351
|
-
if (!isRolldown) return plugins
|
|
352
|
-
const stripJsxKey = (returned: unknown): unknown => {
|
|
353
|
-
// Only touch a plain-object config carrying optimizeDeps.rollupOptions.jsx; leave anything else as-is.
|
|
354
|
-
if (returned === null || typeof returned !== "object") return returned
|
|
355
|
-
const cfg = returned as { optimizeDeps?: { rollupOptions?: Record<string, unknown> } }
|
|
356
|
-
const rollupOptions = cfg.optimizeDeps?.rollupOptions
|
|
357
|
-
if (rollupOptions === undefined || !("jsx" in rollupOptions)) return returned
|
|
358
|
-
// Clone the affected branch (never mutate the plugin's own return value) and drop the dead key.
|
|
359
|
-
const { jsx: _dropped, ...restRollup } = rollupOptions
|
|
360
|
-
return {
|
|
361
|
-
...cfg,
|
|
362
|
-
optimizeDeps: { ...cfg.optimizeDeps, rollupOptions: restRollup },
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return plugins.flat(Number.POSITIVE_INFINITY).map((plugin) => {
|
|
366
|
-
if (plugin === null || typeof plugin !== "object") return plugin
|
|
367
|
-
const p = plugin as VitePluginLike
|
|
368
|
-
// `config` may be a plain function or the object form `{ handler, order }`. Wrap the handler either way.
|
|
369
|
-
const hook = p.config
|
|
370
|
-
const handler = typeof hook === "function" ? hook : hook?.handler
|
|
371
|
-
if (typeof handler !== "function") return plugin
|
|
372
|
-
const wrappedHandler: ConfigFn = (config, env) => {
|
|
373
|
-
const returned = handler(config, env)
|
|
374
|
-
// The hook may return a promise - normalize both shapes.
|
|
375
|
-
return returned instanceof Promise ? returned.then(stripJsxKey) : stripJsxKey(returned)
|
|
376
|
-
}
|
|
377
|
-
// Preserve the ORIGINAL shape: a function stays a function; the object form keeps its `order`
|
|
378
|
-
// (collapsing `{ handler, order }` to a bare function would silently drop the hook ordering).
|
|
379
|
-
return {
|
|
380
|
-
...p,
|
|
381
|
-
config: typeof hook === "function" ? wrappedHandler : { ...hook, handler: wrappedHandler },
|
|
382
|
-
}
|
|
383
|
-
})
|
|
384
|
-
}
|
|
385
|
-
|
|
386
309
|
/**
|
|
387
310
|
* The npm package a bare module specifier belongs to (`@nifrajs/web-react/client` →
|
|
388
311
|
* `@nifrajs/web-react`, `some-adapter/client` → `some-adapter`), or `undefined` for a path-shaped
|
|
@@ -614,8 +537,7 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
|
|
|
614
537
|
// server importing vite unguarded is precisely what poisoned the module for the whole process.
|
|
615
538
|
const viteModule = await importVite<ViteModule>()
|
|
616
539
|
const { createServer } = viteModule
|
|
617
|
-
// Under rolldown-vite (Vite 8+),
|
|
618
|
-
// plugins still emit - it triggers a noisy "Invalid key … jsx" warning but does nothing useful here.
|
|
540
|
+
// Under rolldown-vite (Vite 8+), framework plugins' stale `optimizeDeps.rollupOptions` warns on every start.
|
|
619
541
|
const plugins = normalizeRolldownPlugins(
|
|
620
542
|
options.plugins ?? [],
|
|
621
543
|
viteModule.rolldownVersion !== undefined,
|