@nifrajs/web 2.14.1 → 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.
- package/dist/boundary.d.ts +158 -0
- package/dist/boundary.d.ts.map +1 -0
- package/dist/boundary.js +237 -0
- package/dist/boundary.js.map +1 -0
- package/dist/build-vite.d.ts.map +1 -1
- package/dist/build-vite.js +5 -3
- package/dist/build-vite.js.map +1 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +31 -13
- package/dist/build.js.map +1 -1
- package/dist/index.d.ts +30 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +163 -51
- package/dist/index.js.map +1 -1
- package/dist/internal/fetcher-runtime.d.ts +19 -0
- package/dist/internal/fetcher-runtime.d.ts.map +1 -0
- package/dist/internal/fetcher-runtime.js +26 -0
- package/dist/internal/fetcher-runtime.js.map +1 -0
- package/dist/internal/identity-policy.d.ts +51 -0
- package/dist/internal/identity-policy.d.ts.map +1 -0
- package/dist/internal/identity-policy.js +67 -0
- package/dist/internal/identity-policy.js.map +1 -0
- package/dist/internal/parity.d.ts +97 -8
- package/dist/internal/parity.d.ts.map +1 -1
- package/dist/internal/parity.js +281 -47
- package/dist/internal/parity.js.map +1 -1
- package/dist/internal/query-runtime.d.ts +8 -0
- package/dist/internal/query-runtime.d.ts.map +1 -0
- package/dist/internal/query-runtime.js +29 -0
- package/dist/internal/query-runtime.js.map +1 -0
- package/dist/islands.d.ts +2 -2
- package/dist/islands.d.ts.map +1 -1
- package/dist/islands.js +17 -36
- package/dist/islands.js.map +1 -1
- package/dist/manifest.d.ts +41 -6
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js.map +1 -1
- package/dist/render-seam.d.ts +5 -0
- package/dist/render-seam.d.ts.map +1 -1
- package/dist/render-seam.js +10 -0
- package/dist/render-seam.js.map +1 -1
- package/dist/router.d.ts +10 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +233 -26
- package/dist/router.js.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +8 -6
- package/dist/vite.js.map +1 -1
- package/package.json +13 -2
- package/src/boundary.ts +407 -0
- package/src/build-vite.ts +5 -3
- package/src/build.ts +36 -14
- package/src/index.ts +235 -49
- package/src/internal/fetcher-runtime.ts +36 -0
- package/src/internal/identity-policy.ts +94 -0
- package/src/internal/parity.ts +409 -57
- package/src/internal/query-runtime.ts +31 -0
- package/src/islands.ts +22 -41
- package/src/manifest.ts +50 -3
- package/src/render-seam.ts +6 -0
- package/src/router.ts +271 -29
- package/src/vite.ts +8 -6
|
@@ -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
|
+
]
|