@nifrajs/web 2.14.1 → 3.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.
Files changed (145) hide show
  1. package/dist/boundary.d.ts +158 -0
  2. package/dist/boundary.d.ts.map +1 -0
  3. package/dist/boundary.js +237 -0
  4. package/dist/boundary.js.map +1 -0
  5. package/dist/build-plan.d.ts +228 -0
  6. package/dist/build-plan.d.ts.map +1 -0
  7. package/dist/build-plan.js +514 -0
  8. package/dist/build-plan.js.map +1 -0
  9. package/dist/build-vite.d.ts +2 -1
  10. package/dist/build-vite.d.ts.map +1 -1
  11. package/dist/build-vite.js +5 -3
  12. package/dist/build-vite.js.map +1 -1
  13. package/dist/build.d.ts +2 -197
  14. package/dist/build.d.ts.map +1 -1
  15. package/dist/build.js +92 -515
  16. package/dist/build.js.map +1 -1
  17. package/dist/chunk-names.d.ts.map +1 -1
  18. package/dist/chunk-names.js +3 -2
  19. package/dist/chunk-names.js.map +1 -1
  20. package/dist/dev-ssr-graph.d.ts.map +1 -1
  21. package/dist/dev-ssr-graph.js +63 -28
  22. package/dist/dev-ssr-graph.js.map +1 -1
  23. package/dist/diagnostic.d.ts.map +1 -1
  24. package/dist/diagnostic.js +9 -2
  25. package/dist/diagnostic.js.map +1 -1
  26. package/dist/fonts-google.d.ts.map +1 -1
  27. package/dist/fonts-google.js +3 -1
  28. package/dist/fonts-google.js.map +1 -1
  29. package/dist/fs.d.ts.map +1 -1
  30. package/dist/fs.js +2 -1
  31. package/dist/fs.js.map +1 -1
  32. package/dist/index.d.ts +16 -589
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +23 -1824
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal/codegen.d.ts +68 -0
  37. package/dist/internal/codegen.d.ts.map +1 -0
  38. package/dist/internal/codegen.js +317 -0
  39. package/dist/internal/codegen.js.map +1 -0
  40. package/dist/internal/fetcher-runtime.d.ts +19 -0
  41. package/dist/internal/fetcher-runtime.d.ts.map +1 -0
  42. package/dist/internal/fetcher-runtime.js +26 -0
  43. package/dist/internal/fetcher-runtime.js.map +1 -0
  44. package/dist/internal/head-merge.d.ts +2 -0
  45. package/dist/internal/head-merge.d.ts.map +1 -1
  46. package/dist/internal/head-merge.js +17 -1
  47. package/dist/internal/head-merge.js.map +1 -1
  48. package/dist/internal/identity-policy.d.ts +51 -0
  49. package/dist/internal/identity-policy.d.ts.map +1 -0
  50. package/dist/internal/identity-policy.js +67 -0
  51. package/dist/internal/identity-policy.js.map +1 -0
  52. package/dist/internal/parity.d.ts +104 -8
  53. package/dist/internal/parity.d.ts.map +1 -1
  54. package/dist/internal/parity.js +472 -56
  55. package/dist/internal/parity.js.map +1 -1
  56. package/dist/internal/query-runtime.d.ts +8 -0
  57. package/dist/internal/query-runtime.d.ts.map +1 -0
  58. package/dist/internal/query-runtime.js +29 -0
  59. package/dist/internal/query-runtime.js.map +1 -0
  60. package/dist/internal/render-document.d.ts +372 -0
  61. package/dist/internal/render-document.d.ts.map +1 -0
  62. package/dist/internal/render-document.js +744 -0
  63. package/dist/internal/render-document.js.map +1 -0
  64. package/dist/internal/runtime-contract.d.ts +48 -0
  65. package/dist/internal/runtime-contract.d.ts.map +1 -0
  66. package/dist/internal/runtime-contract.js +27 -0
  67. package/dist/internal/runtime-contract.js.map +1 -0
  68. package/dist/internal/web-app.d.ts +171 -0
  69. package/dist/internal/web-app.d.ts.map +1 -0
  70. package/dist/internal/web-app.js +844 -0
  71. package/dist/internal/web-app.js.map +1 -0
  72. package/dist/islands.d.ts +50 -2
  73. package/dist/islands.d.ts.map +1 -1
  74. package/dist/islands.js +96 -36
  75. package/dist/islands.js.map +1 -1
  76. package/dist/manifest.d.ts +41 -6
  77. package/dist/manifest.d.ts.map +1 -1
  78. package/dist/manifest.js.map +1 -1
  79. package/dist/module-graph.d.ts.map +1 -1
  80. package/dist/module-graph.js +22 -9
  81. package/dist/module-graph.js.map +1 -1
  82. package/dist/nano.d.ts +125 -0
  83. package/dist/nano.d.ts.map +1 -0
  84. package/dist/nano.js +190 -0
  85. package/dist/nano.js.map +1 -0
  86. package/dist/plugins/css-modules.js +2 -2
  87. package/dist/plugins/css-modules.js.map +1 -1
  88. package/dist/plugins/kit.d.ts +12 -0
  89. package/dist/plugins/kit.d.ts.map +1 -1
  90. package/dist/plugins/kit.js +62 -12
  91. package/dist/plugins/kit.js.map +1 -1
  92. package/dist/plugins/postcss.js +2 -2
  93. package/dist/plugins/postcss.js.map +1 -1
  94. package/dist/plugins/scss.js +2 -2
  95. package/dist/plugins/scss.js.map +1 -1
  96. package/dist/plugins/stylex.d.ts +70 -0
  97. package/dist/plugins/stylex.d.ts.map +1 -0
  98. package/dist/plugins/stylex.js +166 -0
  99. package/dist/plugins/stylex.js.map +1 -0
  100. package/dist/plugins/svg.js +2 -2
  101. package/dist/plugins/svg.js.map +1 -1
  102. package/dist/render-seam.d.ts +5 -0
  103. package/dist/render-seam.d.ts.map +1 -1
  104. package/dist/render-seam.js +10 -0
  105. package/dist/render-seam.js.map +1 -1
  106. package/dist/router.d.ts +11 -1
  107. package/dist/router.d.ts.map +1 -1
  108. package/dist/router.js +254 -47
  109. package/dist/router.js.map +1 -1
  110. package/dist/vite.d.ts.map +1 -1
  111. package/dist/vite.js +34 -16
  112. package/dist/vite.js.map +1 -1
  113. package/package.json +49 -2
  114. package/src/boundary.ts +407 -0
  115. package/src/build-plan.ts +741 -0
  116. package/src/build-vite.ts +6 -7
  117. package/src/build.ts +120 -730
  118. package/src/chunk-names.ts +3 -2
  119. package/src/dev-ssr-graph.ts +63 -28
  120. package/src/diagnostic.ts +14 -2
  121. package/src/fonts-google.ts +3 -1
  122. package/src/fs.ts +2 -1
  123. package/src/index.ts +107 -2553
  124. package/src/internal/codegen.ts +400 -0
  125. package/src/internal/fetcher-runtime.ts +36 -0
  126. package/src/internal/head-merge.ts +19 -1
  127. package/src/internal/identity-policy.ts +94 -0
  128. package/src/internal/parity.ts +603 -71
  129. package/src/internal/query-runtime.ts +31 -0
  130. package/src/internal/render-document.ts +1116 -0
  131. package/src/internal/runtime-contract.ts +54 -0
  132. package/src/internal/web-app.ts +1114 -0
  133. package/src/islands.ts +106 -40
  134. package/src/manifest.ts +50 -3
  135. package/src/module-graph.ts +23 -9
  136. package/src/nano.ts +246 -0
  137. package/src/plugins/css-modules.ts +2 -2
  138. package/src/plugins/kit.ts +65 -12
  139. package/src/plugins/postcss.ts +2 -2
  140. package/src/plugins/scss.ts +2 -2
  141. package/src/plugins/stylex.ts +298 -0
  142. package/src/plugins/svg.ts +2 -2
  143. package/src/render-seam.ts +6 -0
  144. package/src/router.ts +293 -51
  145. package/src/vite.ts +41 -15
package/src/vite.ts CHANGED
@@ -16,11 +16,12 @@ import {
16
16
  type IncomingMessage,
17
17
  type ServerResponse,
18
18
  } from "node:http"
19
- import { relative, resolve as resolvePath } from "node:path"
19
+ import { isAbsolute, join, relative, resolve as resolvePath, sep } from "node:path"
20
20
  import { createDevDiagnostics } from "./dev-diagnostics.ts"
21
21
  import { listenOrExplain } from "./dev-port.ts"
22
22
  import { discoverRoutes } from "./fs.ts"
23
23
  import { DEFAULT_DEV_PORT, generateClientEntry, setSsrModuleLoader } from "./index.ts"
24
+ import { viteDedupePackages } from "./internal/identity-policy.ts"
24
25
  import {
25
26
  assertIdentityParity,
26
27
  collectIdentityParity,
@@ -30,7 +31,13 @@ import {
30
31
  import { vitePublicEnvPrefix } from "./internal/server-boundary.ts"
31
32
  import { importVite } from "./internal/vite-import.ts"
32
33
  import { scopedName } from "./plugins/css-modules.ts"
33
- import { DEV_ROOT_ENV, DEV_ROUTES_ENV, reproduciblePath } from "./plugins/kit.ts"
34
+ import {
35
+ DEV_ROOT_ENV,
36
+ DEV_ROUTES_ENV,
37
+ normalizeFilePath,
38
+ portablePath,
39
+ reproduciblePath,
40
+ } from "./plugins/kit.ts"
34
41
  import { viteServerFnStub } from "./plugins/vite-server-fn.ts"
35
42
  import { viteServerOnlyEmpty } from "./plugins/vite-server-only.ts"
36
43
 
@@ -138,6 +145,19 @@ export { LAST_ERROR_PATH } from "./diagnostic.ts"
138
145
  // The codegen'd client entry is written here (at the Vite root) so Vite serves + HMRs it.
139
146
  const DEV_ENTRY = ".nifra-vite-entry.tsx"
140
147
 
148
+ /** Candidate spellings for Vite's module-graph map. Vite has used native and slash-normalized
149
+ * absolute Windows paths across versions, while watcher events can additionally arrive as a file URL. */
150
+ const modulePathCandidates = (path: string): string[] => {
151
+ const native = normalizeFilePath(path)
152
+ const portable = portablePath(path)
153
+ return [...new Set([path, native, portable])]
154
+ }
155
+
156
+ const pathInside = (root: string, path: string): boolean => {
157
+ const rel = relative(resolvePath(root), resolvePath(normalizeFilePath(path)))
158
+ return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))
159
+ }
160
+
141
161
  const readNodeBody = async (req: IncomingMessage): Promise<Buffer | undefined> => {
142
162
  if (req.method === "GET" || req.method === "HEAD") return undefined
143
163
  const chunks: Buffer[] = []
@@ -343,7 +363,8 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
343
363
  process.env[DEV_ROUTES_ENV] = routesDir
344
364
 
345
365
  // Codegen the client entry with Vite-servable, root-relative specifiers (e.g. `/routes/index.tsx`).
346
- const toUrl = (file: string): string => `/${relative(root, `${routesDir}/${file}`)}`
366
+ const toUrl = (file: string): string =>
367
+ `/${relative(root, join(routesDir, file)).replaceAll("\\", "/")}`
347
368
  const writeClientEntry = (): void => {
348
369
  const manifest = discoverRoutes(routesDir)
349
370
  writeFileSync(
@@ -467,12 +488,13 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
467
488
  plugins: [viteServerFnStub(), viteServerOnlyEmpty(), ...plugins],
468
489
  resolve: {
469
490
  conditions: resolveConditions,
470
- // Dedupe React to ONE copy. In a multi-root workspace a shared package can pull react/react-dom
471
- // from a SIBLING app's node_modules, so the dev server loads two React cores → a second hook
472
- // dispatcher → `resolveDispatcher().useState` null on any hook-using route (the error points at the
473
- // component, not the resolution - brutal to diagnose). Mirrors the build-time reactDedupePlugin so
474
- // dev matches prod. No-op for non-React apps (the package simply isn't present to dedupe).
475
- dedupe: ["react", "react-dom"],
491
+ // Dedupe each framework runtime to ONE copy. In a multi-root workspace a shared package can pull
492
+ // react/react-dom (or preact, or svelte) from a SIBLING app's node_modules, so the dev server
493
+ // loads two cores → a second hook dispatcher/options global → `resolveDispatcher().useState` null
494
+ // on any hook-using route (the error points at the component, not the resolution - brutal to
495
+ // diagnose). Same policy table the production builds read, so dev matches prod. No-op per
496
+ // framework the app does not use (the package simply isn't present to dedupe).
497
+ dedupe: [...viteDedupePackages()],
476
498
  },
477
499
  ssr: {
478
500
  // Explicit listing forces external even for workspace-LINKED packages (Vite's default keeps
@@ -521,10 +543,13 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
521
543
  const invalidateImporterClosure = (path: string): void => {
522
544
  const graph = vite.moduleGraph
523
545
  if (graph === undefined) return
524
- const roots = graph.getModulesByFile(path)
525
- if (roots === undefined) return
526
546
  const seen = new Set<ViteModuleNode>()
527
- const stack = [...roots]
547
+ const stack: ViteModuleNode[] = []
548
+ for (const candidate of modulePathCandidates(path)) {
549
+ const roots = graph.getModulesByFile(candidate)
550
+ if (roots !== undefined) stack.push(...roots)
551
+ }
552
+ if (stack.length === 0) return
528
553
  for (let mod = stack.pop(); mod !== undefined; mod = stack.pop()) {
529
554
  if (seen.has(mod)) continue
530
555
  seen.add(mod)
@@ -547,11 +572,12 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
547
572
  })
548
573
  .catch((err) => console.error("[nifra/web/vite] app re-create failed:", err))
549
574
  }
550
- vite.watcher.on("change", refreshApp)
575
+ vite.watcher.on("change", (path) => refreshApp(normalizeFilePath(path)))
551
576
  for (const event of ["add", "unlink"] as const) {
552
577
  vite.watcher.on(event, (path) => {
553
- if (path.startsWith(`${routesDir}/`) || path.startsWith(`${routesDir}\\`)) writeClientEntry()
554
- refreshApp(path)
578
+ const filePath = normalizeFilePath(path)
579
+ if (pathInside(routesDir, filePath)) writeClientEntry()
580
+ refreshApp(filePath)
555
581
  })
556
582
  }
557
583