@nifrajs/web 2.13.0 → 3.1.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 (69) 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-vite.d.ts.map +1 -1
  6. package/dist/build-vite.js +5 -3
  7. package/dist/build-vite.js.map +1 -1
  8. package/dist/build.d.ts +9 -6
  9. package/dist/build.d.ts.map +1 -1
  10. package/dist/build.js +57 -31
  11. package/dist/build.js.map +1 -1
  12. package/dist/fn.d.ts +2 -2
  13. package/dist/fn.d.ts.map +1 -1
  14. package/dist/fn.js +2 -2
  15. package/dist/fn.js.map +1 -1
  16. package/dist/index.d.ts +30 -20
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +179 -56
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal/fetcher-runtime.d.ts +19 -0
  21. package/dist/internal/fetcher-runtime.d.ts.map +1 -0
  22. package/dist/internal/fetcher-runtime.js +26 -0
  23. package/dist/internal/fetcher-runtime.js.map +1 -0
  24. package/dist/internal/identity-policy.d.ts +51 -0
  25. package/dist/internal/identity-policy.d.ts.map +1 -0
  26. package/dist/internal/identity-policy.js +67 -0
  27. package/dist/internal/identity-policy.js.map +1 -0
  28. package/dist/internal/parity.d.ts +105 -7
  29. package/dist/internal/parity.d.ts.map +1 -1
  30. package/dist/internal/parity.js +303 -56
  31. package/dist/internal/parity.js.map +1 -1
  32. package/dist/internal/query-runtime.d.ts +8 -0
  33. package/dist/internal/query-runtime.d.ts.map +1 -0
  34. package/dist/internal/query-runtime.js +29 -0
  35. package/dist/internal/query-runtime.js.map +1 -0
  36. package/dist/islands.d.ts +2 -2
  37. package/dist/islands.d.ts.map +1 -1
  38. package/dist/islands.js +17 -36
  39. package/dist/islands.js.map +1 -1
  40. package/dist/manifest.d.ts +41 -6
  41. package/dist/manifest.d.ts.map +1 -1
  42. package/dist/manifest.js.map +1 -1
  43. package/dist/render-seam.d.ts +5 -0
  44. package/dist/render-seam.d.ts.map +1 -1
  45. package/dist/render-seam.js +10 -0
  46. package/dist/render-seam.js.map +1 -1
  47. package/dist/router.d.ts +10 -0
  48. package/dist/router.d.ts.map +1 -1
  49. package/dist/router.js +233 -26
  50. package/dist/router.js.map +1 -1
  51. package/dist/vite.d.ts +8 -0
  52. package/dist/vite.d.ts.map +1 -1
  53. package/dist/vite.js +51 -13
  54. package/dist/vite.js.map +1 -1
  55. package/package.json +13 -2
  56. package/src/boundary.ts +407 -0
  57. package/src/build-vite.ts +5 -3
  58. package/src/build.ts +61 -31
  59. package/src/fn.ts +6 -6
  60. package/src/index.ts +255 -54
  61. package/src/internal/fetcher-runtime.ts +36 -0
  62. package/src/internal/identity-policy.ts +94 -0
  63. package/src/internal/parity.ts +447 -70
  64. package/src/internal/query-runtime.ts +31 -0
  65. package/src/islands.ts +22 -41
  66. package/src/manifest.ts +50 -3
  67. package/src/render-seam.ts +6 -0
  68. package/src/router.ts +271 -29
  69. package/src/vite.ts +75 -13
@@ -0,0 +1,94 @@
1
+ /**
2
+ * One source for which packages are identity-sensitive, and how each frontend framework is pinned to a
3
+ * single physical copy in a bundle.
4
+ *
5
+ * The identity-sensitive PACKAGE set lives in `@nifrajs/core` (`IDENTITY_SENSITIVE_PACKAGES`) - it is
6
+ * what single-copy enforcement and `nifra check` read, and it must be the same answer everywhere. This
7
+ * module does not restate it; it re-exports the one predicate every web caller should ask
8
+ * (`isIdentitySensitivePackage`) so a second list can never drift from core's.
9
+ *
10
+ * What this module DOES own is the per-bundler dedupe STRATEGY, which is a web concern (it names Bun and
11
+ * Vite mechanics core knows nothing about). The two client pipelines - `Bun.build` (build.ts) and Vite
12
+ * (build-vite.ts) - used to spell their framework coverage out independently, and they had already
13
+ * drifted: the Bun build pinned react + preact + svelte while the Vite build deduped react alone, so a
14
+ * Vite-built app silently shipped a second Preact or Svelte runtime. Both now read {@link
15
+ * FRONTEND_DEDUPE_POLICIES}, so their coverage cannot diverge again.
16
+ *
17
+ * Not every identity-sensitive framework is name-pinned here. Solid and Vue select their single runtime
18
+ * through export CONDITIONS rather than a resolver override, so they carry no entry - the conformance
19
+ * test allows core's set to be a superset of this table for exactly that reason, and only forbids the
20
+ * reverse (a strategy for a package core does not consider identity-sensitive).
21
+ */
22
+
23
+ import {
24
+ IDENTITY_SENSITIVE_PACKAGES,
25
+ matchesSingleCopyDeclaration,
26
+ } from "@nifrajs/core/single-copy"
27
+
28
+ /**
29
+ * Whether nifra treats a package as identity-sensitive: a second physical copy breaks behaviour (a hook
30
+ * dispatcher, a renderer's options global, a `Server` class identity) rather than merely costing bytes.
31
+ * The single predicate the whole web package asks, delegating to core's canonical declaration.
32
+ */
33
+ export const isIdentitySensitivePackage = (name: string): boolean =>
34
+ matchesSingleCopyDeclaration(IDENTITY_SENSITIVE_PACKAGES, name)
35
+
36
+ /**
37
+ * How one frontend framework's runtime is pinned to a single copy in each client bundler.
38
+ *
39
+ * The two arms differ because the bundlers resolve differently. `Bun.build` needs an `onResolve` hook,
40
+ * fed either a fixed specifier list (each resolved once) or a pattern (resolved per matched import, for
41
+ * a framework with an open-ended subpath surface like `svelte/internal/*`). Vite takes bare package
42
+ * names in `resolve.dedupe` and handles the subpaths itself. A framework declares whichever Bun arm
43
+ * fits plus its Vite names, so both pipelines pin the same framework from this one entry.
44
+ */
45
+ export interface FrontendDedupePolicy {
46
+ readonly framework: string
47
+ /** Exact specifiers the Bun build pins to the app's copy. Mutually exclusive with `bunPattern`. */
48
+ readonly bunSpecs?: readonly string[]
49
+ /** Specifier pattern the Bun build resolves per match, for an open-ended subpath surface. */
50
+ readonly bunPattern?: RegExp
51
+ /** Bare package names the Vite build lists in `resolve.dedupe`. */
52
+ readonly viteDedupe: readonly string[]
53
+ }
54
+
55
+ export const FRONTEND_DEDUPE_POLICIES: readonly FrontendDedupePolicy[] = [
56
+ {
57
+ framework: "react",
58
+ // react-dom is absent on purpose: it imports react, so pinning react's core (and its JSX runtimes)
59
+ // gives it the one dispatcher. Vite dedupes react-dom by name because it collapses by package.
60
+ bunSpecs: ["react", "react/jsx-runtime", "react/jsx-dev-runtime"],
61
+ viteDedupe: ["react", "react-dom"],
62
+ },
63
+ {
64
+ framework: "preact",
65
+ bunSpecs: [
66
+ "preact",
67
+ "preact/hooks",
68
+ "preact/compat",
69
+ "preact/jsx-runtime",
70
+ "preact/jsx-dev-runtime",
71
+ ],
72
+ viteDedupe: ["preact"],
73
+ },
74
+ {
75
+ framework: "svelte",
76
+ // Svelte's client runtime has many internal subpaths, so match the family and resolve each per hit.
77
+ bunPattern: /^svelte($|\/internal\/)/,
78
+ viteDedupe: ["svelte"],
79
+ },
80
+ ]
81
+
82
+ /** Look up one framework's dedupe policy, throwing if a plugin references a framework the table dropped. */
83
+ export const dedupePolicyFor = (framework: string): FrontendDedupePolicy => {
84
+ const policy = FRONTEND_DEDUPE_POLICIES.find((entry) => entry.framework === framework)
85
+ if (policy === undefined) {
86
+ throw new Error(`[nifra/web] no frontend dedupe policy for ${framework}`)
87
+ }
88
+ return policy
89
+ }
90
+
91
+ /** The flat, de-duplicated `resolve.dedupe` list for the Vite client build. */
92
+ export const viteDedupePackages = (): readonly string[] => [
93
+ ...new Set(FRONTEND_DEDUPE_POLICIES.flatMap((policy) => policy.viteDedupe)),
94
+ ]