@nifrajs/web 2.9.1 → 2.11.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 (62) hide show
  1. package/dist/client.d.ts +12 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +16 -0
  4. package/dist/client.js.map +1 -1
  5. package/dist/dev-ssr-graph.d.ts +33 -0
  6. package/dist/dev-ssr-graph.d.ts.map +1 -0
  7. package/dist/dev-ssr-graph.js +285 -0
  8. package/dist/dev-ssr-graph.js.map +1 -0
  9. package/dist/dev.d.ts.map +1 -1
  10. package/dist/dev.js +76 -18
  11. package/dist/dev.js.map +1 -1
  12. package/dist/index.d.ts +28 -25
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +53 -79
  15. package/dist/index.js.map +1 -1
  16. package/dist/internal/head-merge.d.ts +27 -0
  17. package/dist/internal/head-merge.d.ts.map +1 -0
  18. package/dist/internal/head-merge.js +65 -0
  19. package/dist/internal/head-merge.js.map +1 -0
  20. package/dist/internal/server-boundary.d.ts +1 -2
  21. package/dist/internal/server-boundary.d.ts.map +1 -1
  22. package/dist/internal/server-boundary.js +1 -2
  23. package/dist/internal/server-boundary.js.map +1 -1
  24. package/dist/isr.d.ts +32 -3
  25. package/dist/isr.d.ts.map +1 -1
  26. package/dist/isr.js +181 -16
  27. package/dist/isr.js.map +1 -1
  28. package/dist/manifest.d.ts +2 -0
  29. package/dist/manifest.d.ts.map +1 -1
  30. package/dist/manifest.js.map +1 -1
  31. package/dist/plugins/css-modules.d.ts +12 -0
  32. package/dist/plugins/css-modules.d.ts.map +1 -1
  33. package/dist/plugins/css-modules.js +0 -0
  34. package/dist/plugins/css-modules.js.map +1 -1
  35. package/dist/plugins/kit.d.ts +54 -0
  36. package/dist/plugins/kit.d.ts.map +1 -1
  37. package/dist/plugins/kit.js +66 -0
  38. package/dist/plugins/kit.js.map +1 -1
  39. package/dist/public-dir.d.ts.map +1 -1
  40. package/dist/public-dir.js +71 -4
  41. package/dist/public-dir.js.map +1 -1
  42. package/dist/route-manifest.d.ts +3 -1
  43. package/dist/route-manifest.d.ts.map +1 -1
  44. package/dist/route-manifest.js +3 -0
  45. package/dist/route-manifest.js.map +1 -1
  46. package/dist/vite.d.ts.map +1 -1
  47. package/dist/vite.js +27 -1
  48. package/dist/vite.js.map +1 -1
  49. package/package.json +3 -3
  50. package/src/client.ts +28 -0
  51. package/src/dev-ssr-graph.ts +311 -0
  52. package/src/dev.ts +81 -20
  53. package/src/index.ts +63 -71
  54. package/src/internal/head-merge.ts +80 -0
  55. package/src/internal/server-boundary.ts +1 -2
  56. package/src/isr.ts +216 -19
  57. package/src/manifest.ts +2 -0
  58. package/src/plugins/css-modules.ts +0 -0
  59. package/src/plugins/kit.ts +71 -0
  60. package/src/public-dir.ts +74 -4
  61. package/src/route-manifest.ts +10 -1
  62. package/src/vite.ts +29 -1
package/src/vite.ts CHANGED
@@ -20,9 +20,11 @@ import { relative, resolve as resolvePath } 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
- import { DEFAULT_DEV_PORT, generateClientEntry } from "./index.ts"
23
+ import { DEFAULT_DEV_PORT, generateClientEntry, setSsrModuleLoader } from "./index.ts"
24
24
  import { vitePublicEnvPrefix } from "./internal/server-boundary.ts"
25
25
  import { importVite } from "./internal/vite-import.ts"
26
+ import { scopedName } from "./plugins/css-modules.ts"
27
+ import { DEV_ROOT_ENV, DEV_ROUTES_ENV, reproduciblePath } from "./plugins/kit.ts"
26
28
  import { viteServerFnStub } from "./plugins/vite-server-fn.ts"
27
29
  import { viteServerOnlyEmpty } from "./plugins/vite-server-only.ts"
28
30
 
@@ -296,6 +298,12 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
296
298
  const routesDir = resolvePath(options.routesDir)
297
299
  const port = options.port ?? DEFAULT_DEV_PORT
298
300
 
301
+ // Which files are the app's own components, for framework plugins that hot-patch at component
302
+ // granularity (`devHotComponent`). Announced in the environment rather than passed, because the
303
+ // plugin that reads it is constructed by the app, in its own config, before this server exists.
304
+ process.env[DEV_ROOT_ENV] = root
305
+ process.env[DEV_ROUTES_ENV] = routesDir
306
+
299
307
  // Codegen the client entry with Vite-servable, root-relative specifiers (e.g. `/routes/index.tsx`).
300
308
  const toUrl = (file: string): string => `/${relative(root, `${routesDir}/${file}`)}`
301
309
  const writeClientEntry = (): void => {
@@ -442,10 +450,26 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
442
450
  externalConditions: ssrConditions,
443
451
  },
444
452
  },
453
+ css: {
454
+ modules: {
455
+ // Vite ships its own CSS-Modules naming (`_name_<base64>`); the Bun pipeline and every
456
+ // `nifra build` use `scopedName`. Left alone, one class is called two different things
457
+ // depending on which pipeline served it, so a selector written against a generated name works
458
+ // in dev and vanishes in production - and the two dev pipelines disagree with each other. The
459
+ // name is defined once, in the plugin, and Vite is handed that definition.
460
+ generateScopedName: (name: string, filename: string): string =>
461
+ scopedName(reproduciblePath(filename), name),
462
+ },
463
+ },
445
464
  ...(options.define ? { define: options.define } : {}),
446
465
  })
447
466
 
448
467
  const ssrLoad = (absolutePath: string): Promise<unknown> => vite.ssrLoadModule(absolutePath)
468
+ // Published so an ADAPTER can reach this graph too. Route modules already load through it; an
469
+ // adapter that has to load a compiled asset of its own on the server (`@nifrajs/web-svelte` and its
470
+ // `Chain.svelte`) would otherwise take it from the runtime, which has no compiler for it and no
471
+ // reason to agree with Vite about which copy of the framework runtime it renders through.
472
+ setSsrModuleLoader(ssrLoad)
449
473
  app = await options.createApp(entryUrl, ssrLoad)
450
474
 
451
475
  // Re-create the app on change so a hard reload picks up a route ADD/REMOVE (the manifest comes
@@ -486,6 +510,10 @@ export async function createViteDevServer(options: ViteDevServerOptions): Promis
486
510
  return {
487
511
  port: typeof address === "object" && address !== null ? address.port : port,
488
512
  stop: async () => {
513
+ // Cleared with the server that owns it: the slot is process-global, so a stopped server leaving
514
+ // its loader behind would hand the next one's adapter a graph that is closed (tests start and
515
+ // stop several dev servers in one process).
516
+ setSsrModuleLoader(undefined)
489
517
  server.close()
490
518
  await vite.close()
491
519
  },