@decocms/tanstack 8.1.0-next.0 → 8.5.1
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/README.md +79 -0
- package/dist/draft.d.ts +33 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +41 -0
- package/dist/draft.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/react/DecoDocument.d.ts +61 -0
- package/dist/react/DecoDocument.d.ts.map +1 -0
- package/dist/react/DecoDocument.js +96 -0
- package/dist/react/DecoDocument.js.map +1 -0
- package/dist/react/Image.d.ts +96 -0
- package/dist/react/Image.d.ts.map +1 -0
- package/dist/react/Image.js +79 -0
- package/dist/react/Image.js.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/pageValues.d.ts +10 -0
- package/dist/react/pageValues.d.ts.map +1 -0
- package/dist/react/pageValues.js +29 -0
- package/dist/react/pageValues.js.map +1 -0
- package/dist/react/scripts.d.ts +14 -0
- package/dist/react/scripts.d.ts.map +1 -0
- package/dist/react/scripts.js +96 -0
- package/dist/react/scripts.js.map +1 -0
- package/dist/router/index.d.ts +38 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +60 -0
- package/dist/router/index.js.map +1 -0
- package/dist/scope/browser.d.ts +11 -0
- package/dist/scope/browser.d.ts.map +1 -0
- package/dist/scope/browser.js +8 -0
- package/dist/scope/browser.js.map +1 -0
- package/dist/scope/server.d.ts +13 -0
- package/dist/scope/server.d.ts.map +1 -0
- package/dist/scope/server.js +26 -0
- package/dist/scope/server.js.map +1 -0
- package/dist/server/index.d.ts +27 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +31 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared.d.ts +26 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +26 -0
- package/dist/shared.js.map +1 -0
- package/dist/start/index.d.ts +9 -0
- package/dist/start/index.d.ts.map +1 -0
- package/dist/start/index.js +33 -0
- package/dist/start/index.js.map +1 -0
- package/dist/studio.d.ts +28 -0
- package/dist/studio.d.ts.map +1 -0
- package/dist/studio.js +53 -0
- package/dist/studio.js.map +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +95 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/worker/cacheProfiles.d.ts +43 -0
- package/dist/worker/cacheProfiles.d.ts.map +1 -0
- package/dist/worker/cacheProfiles.js +162 -0
- package/dist/worker/cacheProfiles.js.map +1 -0
- package/dist/worker/cookies.d.ts +20 -0
- package/dist/worker/cookies.d.ts.map +1 -0
- package/dist/worker/cookies.js +69 -0
- package/dist/worker/cookies.js.map +1 -0
- package/dist/worker/drafts.d.ts +59 -0
- package/dist/worker/drafts.d.ts.map +1 -0
- package/dist/worker/drafts.js +140 -0
- package/dist/worker/drafts.js.map +1 -0
- package/dist/worker/index.d.ts +111 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +618 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/security.d.ts +14 -0
- package/dist/worker/security.d.ts.map +1 -0
- package/dist/worker/security.js +48 -0
- package/dist/worker/security.js.map +1 -0
- package/dist/worker/segment.d.ts +21 -0
- package/dist/worker/segment.d.ts.map +1 -0
- package/dist/worker/segment.js +43 -0
- package/dist/worker/segment.js.map +1 -0
- package/package.json +85 -37
- package/src/draft.ts +43 -0
- package/src/index.ts +8 -61
- package/src/react/DecoDocument.tsx +234 -0
- package/src/react/Image.tsx +213 -0
- package/src/react/index.ts +24 -0
- package/src/react/pageValues.ts +35 -0
- package/src/react/scripts.ts +98 -0
- package/src/router/index.ts +80 -0
- package/src/scope/browser.ts +18 -0
- package/src/scope/server.ts +37 -0
- package/src/server/index.ts +43 -0
- package/src/shared.ts +29 -0
- package/src/start/index.ts +31 -0
- package/src/studio.ts +52 -0
- package/src/vite/index.ts +105 -0
- package/src/worker/cacheProfiles.ts +180 -0
- package/src/worker/cookies.ts +65 -0
- package/src/worker/drafts.ts +157 -0
- package/src/worker/index.ts +784 -0
- package/src/worker/security.ts +63 -0
- package/src/worker/segment.ts +49 -0
- package/src/__conformance__/observability.test.ts +0 -221
- package/src/cms/kvBlockSource.test.ts +0 -82
- package/src/cms/kvBlockSource.ts +0 -68
- package/src/daemon/auth.ts +0 -204
- package/src/daemon/fs.ts +0 -238
- package/src/daemon/index.ts +0 -8
- package/src/daemon/middleware.ts +0 -156
- package/src/daemon/tunnel.ts +0 -129
- package/src/daemon/volumes.ts +0 -366
- package/src/daemon/watch.ts +0 -272
- package/src/hooks/CdnSegmentMarker.tsx +0 -38
- package/src/hooks/DecoPageRenderer.tsx +0 -750
- package/src/hooks/DecoRootLayout.tsx +0 -192
- package/src/hooks/DraftPreviewIndicator.test.tsx +0 -60
- package/src/hooks/DraftPreviewIndicator.tsx +0 -64
- package/src/hooks/NavigationProgress.test.tsx +0 -58
- package/src/hooks/NavigationProgress.tsx +0 -63
- package/src/hooks/PreviewProviders.test.tsx +0 -42
- package/src/hooks/PreviewProviders.tsx +0 -45
- package/src/hooks/StableOutlet.tsx +0 -30
- package/src/hooks/deferredObserverTiming.test.tsx +0 -91
- package/src/hooks/index.ts +0 -10
- package/src/routes/adminRoutes.test.ts +0 -99
- package/src/routes/adminRoutes.ts +0 -153
- package/src/routes/cmsRoute.test.ts +0 -267
- package/src/routes/cmsRoute.ts +0 -1053
- package/src/routes/components.tsx +0 -57
- package/src/routes/index.ts +0 -24
- package/src/routes/pageUrl.test.ts +0 -70
- package/src/routes/pageUrl.ts +0 -55
- package/src/routes/withSiteGlobals.test.ts +0 -243
- package/src/routes/withSiteGlobals.ts +0 -243
- package/src/sdk/backgroundTasks.test.ts +0 -68
- package/src/sdk/backgroundTasks.ts +0 -38
- package/src/sdk/cdnSegment.test.ts +0 -67
- package/src/sdk/cdnSegment.ts +0 -71
- package/src/sdk/cookiePassthrough.ts +0 -58
- package/src/sdk/createInvoke.ts +0 -77
- package/src/sdk/deferredSectionLoader.test.ts +0 -94
- package/src/sdk/deferredSectionLoader.ts +0 -46
- package/src/sdk/draft.test.ts +0 -341
- package/src/sdk/draft.ts +0 -277
- package/src/sdk/draftShared.ts +0 -16
- package/src/sdk/kvHydration.test.ts +0 -371
- package/src/sdk/kvHydration.ts +0 -263
- package/src/sdk/kvRedirects.test.ts +0 -132
- package/src/sdk/kvRedirects.ts +0 -125
- package/src/sdk/outboundHeaders.test.ts +0 -113
- package/src/sdk/outboundHeaders.ts +0 -81
- package/src/sdk/router.ts +0 -101
- package/src/sdk/serverFnFetch.ts +0 -59
- package/src/sdk/speculationRules.test.ts +0 -82
- package/src/sdk/speculationRules.ts +0 -136
- package/src/sdk/startEntry.ts +0 -31
- package/src/sdk/useHydrated.ts +0 -19
- package/src/sdk/workerEntry.cacheStorage.test.ts +0 -147
- package/src/sdk/workerEntry.test.ts +0 -1033
- package/src/sdk/workerEntry.trackingCache.test.ts +0 -328
- package/src/sdk/workerEntry.ts +0 -3154
- package/src/setupFastDeploy.ts +0 -13
- package/src/v8/__conformance__/delivery.test.ts +0 -100
- package/src/v8/binding.ts +0 -70
- package/src/v8/kvLoader.bundle.test.ts +0 -42
- package/src/v8/kvLoader.test.ts +0 -74
- package/src/v8/kvLoader.ts +0 -43
- package/src/vite/plugin-scaffold-gen.test.js +0 -106
- package/src/vite/plugin.js +0 -1022
- package/src/vite/plugin.test.js +0 -238
- package/src/vite/plugin.test.ts +0 -176
- package/tsconfig.json +0 -7
package/src/vite/plugin.test.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
import { decoVitePlugin, generateSchemaArgs } from "./plugin.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The Vite plugin's `resolveId` / `load` hooks are pure functions over their
|
|
9
|
-
* inputs, so we can exercise them without spinning up a Vite environment.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function getPlugin() {
|
|
13
|
-
const result = decoVitePlugin();
|
|
14
|
-
// decoVitePlugin returns a single plugin object today, but the type is
|
|
15
|
-
// `PluginOption` which permits arrays — handle both.
|
|
16
|
-
return Array.isArray(result) ? result[0] : result;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe("decoVitePlugin SSR stubs", () => {
|
|
20
|
-
it("rewrites bare `fs` to a virtual module on SSR", () => {
|
|
21
|
-
const p = getPlugin();
|
|
22
|
-
const id = p.resolveId.call({}, "fs", undefined, { ssr: true });
|
|
23
|
-
expect(id).toBe("\0stub:bare-fs");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("does NOT rewrite bare `fs` on client (browser builds don't import fs)", () => {
|
|
27
|
-
const p = getPlugin();
|
|
28
|
-
const id = p.resolveId.call({}, "fs", undefined, { ssr: false });
|
|
29
|
-
expect(id).toBeUndefined();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("loads an empty surface for the bare-fs virtual module", () => {
|
|
33
|
-
const p = getPlugin();
|
|
34
|
-
const src = p.load.call({}, "\0stub:bare-fs", { ssr: true });
|
|
35
|
-
expect(src).toContain("export const promises = {}");
|
|
36
|
-
expect(src).toContain("export default");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("does not interfere with real SSR modules", () => {
|
|
40
|
-
const p = getPlugin();
|
|
41
|
-
expect(p.resolveId.call({}, "@decocms/start/cms", undefined, { ssr: true })).toBeUndefined();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("decoVitePlugin client stubs (regression guard)", () => {
|
|
46
|
-
it("still rewrites node:async_hooks on the client build", () => {
|
|
47
|
-
const p = getPlugin();
|
|
48
|
-
const id = p.resolveId.call({}, "node:async_hooks", undefined, { ssr: false });
|
|
49
|
-
expect(id).toBe("\0stub:node-async-hooks");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("does not rewrite client stubs on SSR", () => {
|
|
53
|
-
const p = getPlugin();
|
|
54
|
-
const id = p.resolveId.call({}, "react-dom/server", undefined, { ssr: true });
|
|
55
|
-
expect(id).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe("generateSchemaArgs (regression: meta.gen.json must be composed)", () => {
|
|
60
|
-
// Both generate-schema.ts invocations in configureServer (watch regen + cold
|
|
61
|
-
// start) derive their args from this helper. generate-schema always composes
|
|
62
|
-
// before writing, so the manifest carries every framework website/* block
|
|
63
|
-
// (matchers/Page/Resolvable) that Studio — which reads meta.gen.json as-is —
|
|
64
|
-
// needs, e.g. the variant date matcher. See a production storefront regression.
|
|
65
|
-
it("targets the given site", () => {
|
|
66
|
-
expect(generateSchemaArgs("my-site")).toEqual(["--site", "my-site"]);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe("decoVitePlugin __DECO_BUILD_HASH__ injection", () => {
|
|
71
|
-
let originalEnv;
|
|
72
|
-
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
originalEnv = { ...process.env };
|
|
75
|
-
delete process.env.WORKERS_CI_COMMIT_SHA;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
process.env = originalEnv;
|
|
80
|
-
vi.restoreAllMocks();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
function callConfig(command) {
|
|
84
|
-
const p = getPlugin();
|
|
85
|
-
return p.config({}, { command });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
it("injects the literal 'dev' for non-build commands", () => {
|
|
89
|
-
const cfg = callConfig("serve");
|
|
90
|
-
expect(cfg.define.__DECO_BUILD_HASH__).toBe(JSON.stringify("dev"));
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("uses WORKERS_CI_COMMIT_SHA (sliced to 12 chars) when set on a build", () => {
|
|
94
|
-
process.env.WORKERS_CI_COMMIT_SHA = "abcdef1234567890fedcba";
|
|
95
|
-
const cfg = callConfig("build");
|
|
96
|
-
expect(cfg.define.__DECO_BUILD_HASH__).toBe(JSON.stringify("abcdef123456"));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("falls back to git rev-parse when WORKERS_CI_COMMIT_SHA is unset", async () => {
|
|
100
|
-
// The plugin module imports execFileSync at top-level, so we can't easily
|
|
101
|
-
// mock it after the fact. Instead, exercise the real git binary against
|
|
102
|
-
// this repo (CI runs in the repo working tree). Assert the value is a
|
|
103
|
-
// 12-char lowercase hex SHA — that proves git was consulted, not that
|
|
104
|
-
// the time-based fallback was hit.
|
|
105
|
-
const cfg = callConfig("build");
|
|
106
|
-
const value = JSON.parse(cfg.define.__DECO_BUILD_HASH__);
|
|
107
|
-
// Either git produced a SHA (CI / dev machine inside a repo) or the
|
|
108
|
-
// time-based fallback ran. Both are acceptable; we just assert non-empty
|
|
109
|
-
// and length sanity.
|
|
110
|
-
expect(typeof value).toBe("string");
|
|
111
|
-
expect(value.length).toBeGreaterThan(0);
|
|
112
|
-
// Time-based fallback produces base36 characters; git short SHAs are
|
|
113
|
-
// 12 hex chars. Both fit in this superset regex.
|
|
114
|
-
expect(value).toMatch(/^[0-9a-z]+$/);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("preserves allowedHosts behaviour (regression: define is additive, not replacing)", () => {
|
|
118
|
-
process.env.DECO_SITE_NAME = "test-site";
|
|
119
|
-
try {
|
|
120
|
-
const cfg = callConfig("serve");
|
|
121
|
-
expect(cfg.server?.allowedHosts).toContain(".deco.studio");
|
|
122
|
-
expect(cfg.define.__DECO_BUILD_HASH__).toBeDefined();
|
|
123
|
-
} finally {
|
|
124
|
-
delete process.env.DECO_SITE_NAME;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe("decoVitePlugin meta.gen.json on SSR (regression: vite:json double-parse)", () => {
|
|
130
|
-
// Vite's json plugin transforms every `.json` id — even when another plugin
|
|
131
|
-
// already loaded it as JS — so the virtual id must not end in `.json`.
|
|
132
|
-
let dir;
|
|
133
|
-
|
|
134
|
-
beforeEach(() => {
|
|
135
|
-
dir = mkdtempSync(path.join(tmpdir(), "deco-meta-"));
|
|
136
|
-
mkdirSync(path.join(dir, ".deco"));
|
|
137
|
-
mkdirSync(path.join(dir, "src"));
|
|
138
|
-
writeFileSync(path.join(dir, ".deco", "meta.gen.json"), '{"major":1,"schema":{}}');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
afterEach(() => {
|
|
142
|
-
rmSync(dir, { recursive: true, force: true });
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("resolves to a virtual id vite:json does not transform, and loads it as JSON.parse", () => {
|
|
146
|
-
const p = getPlugin();
|
|
147
|
-
const importer = path.join(dir, "src", "setup.ts");
|
|
148
|
-
const id = p.resolveId.call({}, "../.deco/meta.gen.json", importer, { ssr: true });
|
|
149
|
-
expect(id).toBeTypeOf("string");
|
|
150
|
-
expect(id.endsWith(".json")).toBe(false);
|
|
151
|
-
|
|
152
|
-
const watched = [];
|
|
153
|
-
const code = p.load.call({ addWatchFile: (f) => watched.push(f) }, id, { ssr: true });
|
|
154
|
-
expect(code).toBe(`export default JSON.parse(${JSON.stringify('{"major":1,"schema":{}}')});`);
|
|
155
|
-
expect(watched).toEqual([path.join(dir, ".deco", "meta.gen.json")]);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("gives each meta.gen.json its own module id (no shared state)", () => {
|
|
159
|
-
const p = getPlugin();
|
|
160
|
-
const other = mkdtempSync(path.join(tmpdir(), "deco-meta-other-"));
|
|
161
|
-
try {
|
|
162
|
-
writeFileSync(path.join(other, "meta.gen.json"), '{"major":2}');
|
|
163
|
-
const a = p.resolveId.call({}, "../.deco/meta.gen.json", path.join(dir, "src", "setup.ts"), {
|
|
164
|
-
ssr: true,
|
|
165
|
-
});
|
|
166
|
-
const b = p.resolveId.call({}, path.join(other, "meta.gen.json"), path.join(dir, "x.ts"), {
|
|
167
|
-
ssr: true,
|
|
168
|
-
});
|
|
169
|
-
expect(a).not.toBe(b);
|
|
170
|
-
// Loading in reverse order still returns each file's own content.
|
|
171
|
-
expect(p.load.call({}, b, { ssr: true })).toContain('\\"major\\":2');
|
|
172
|
-
expect(p.load.call({}, a, { ssr: true })).toContain('\\"major\\":1');
|
|
173
|
-
} finally {
|
|
174
|
-
rmSync(other, { recursive: true, force: true });
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("wraps aliased imports after the rest of the pipeline resolves them", async () => {
|
|
179
|
-
const p = getPlugin();
|
|
180
|
-
const file = path.join(dir, ".deco", "meta.gen.json");
|
|
181
|
-
const seen = [];
|
|
182
|
-
const ctx = {
|
|
183
|
-
resolve: async (spec, imp, opts) => {
|
|
184
|
-
seen.push([spec, opts.skipSelf]);
|
|
185
|
-
return { id: file };
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
const id = await p.resolveId.call(
|
|
189
|
-
ctx,
|
|
190
|
-
"~/.deco/meta.gen.json",
|
|
191
|
-
path.join(dir, "src", "setup.ts"),
|
|
192
|
-
{
|
|
193
|
-
ssr: true,
|
|
194
|
-
},
|
|
195
|
-
);
|
|
196
|
-
expect(id.endsWith(".json")).toBe(false);
|
|
197
|
-
expect(seen).toEqual([["~/.deco/meta.gen.json", true]]);
|
|
198
|
-
expect(p.load.call({}, id, { ssr: true })).toContain("JSON.parse(");
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("leaves an aliased import alone when it doesn't resolve to an existing file", async () => {
|
|
202
|
-
const p = getPlugin();
|
|
203
|
-
const ctx = { resolve: async () => null };
|
|
204
|
-
const id = await p.resolveId.call(ctx, "~/missing/meta.gen.json", path.join(dir, "x.ts"), {
|
|
205
|
-
ssr: true,
|
|
206
|
-
});
|
|
207
|
-
expect(id).toBeUndefined();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it("falls through when a resolver in the chain throws for the alias", async () => {
|
|
211
|
-
const p = getPlugin();
|
|
212
|
-
const ctx = {
|
|
213
|
-
resolve: async () => {
|
|
214
|
-
throw new Error("exports map error");
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
const id = await p.resolveId.call(ctx, "~/x/meta.gen.json", path.join(dir, "x.ts"), {
|
|
218
|
-
ssr: true,
|
|
219
|
-
});
|
|
220
|
-
expect(id).toBeUndefined();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("falls through to Vite when meta.gen.json does not exist yet", () => {
|
|
224
|
-
const p = getPlugin();
|
|
225
|
-
const importer = path.join(dir, "src", "setup.ts");
|
|
226
|
-
expect(
|
|
227
|
-
p.resolveId.call({}, "../missing/meta.gen.json", importer, { ssr: true }),
|
|
228
|
-
).toBeUndefined();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("still stubs meta.gen.json on the client", () => {
|
|
232
|
-
const p = getPlugin();
|
|
233
|
-
const importer = path.join(dir, "src", "setup.ts");
|
|
234
|
-
expect(p.resolveId.call({}, "../.deco/meta.gen.json", importer, { ssr: false })).toBe(
|
|
235
|
-
"\0stub:meta-gen",
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
});
|
package/src/vite/plugin.test.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { decoVitePlugin } from "./plugin.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Permanent regression test for the site-action/loader bundle leak.
|
|
6
|
-
*
|
|
7
|
-
* `.deco/loaders.gen.ts` registers every site loader/action behind a dynamic
|
|
8
|
-
* `import()` and is reachable from the CLIENT entry (router -> setup ->
|
|
9
|
-
* commerce-loaders -> loaders.gen). Without the client stub, Vite emits each
|
|
10
|
-
* loader/action module as a public client chunk, leaking the module source
|
|
11
|
-
* (including any hardcoded credential in it) into the browser assets.
|
|
12
|
-
*
|
|
13
|
-
* The load() hook must replace loaders.gen.ts with an empty `siteLoaders` on
|
|
14
|
-
* the client so those dynamic imports vanish from the client graph, while SSR
|
|
15
|
-
* keeps the real module (invoke runs server-side only). If this ever regresses,
|
|
16
|
-
* a token hardcoded in a site action becomes publicly downloadable again.
|
|
17
|
-
*/
|
|
18
|
-
describe("decoVitePlugin — loaders.gen client stub", () => {
|
|
19
|
-
// The plugin's load hook is a plain function that uses no `this`.
|
|
20
|
-
const plugin = decoVitePlugin() as {
|
|
21
|
-
load: (id: string, options?: { ssr?: boolean }) => string | undefined;
|
|
22
|
-
};
|
|
23
|
-
const id = "/repo/.deco/loaders.gen.ts";
|
|
24
|
-
|
|
25
|
-
it("stubs loaders.gen.ts to an empty siteLoaders in the CLIENT build", () => {
|
|
26
|
-
const out = plugin.load(id, { ssr: false });
|
|
27
|
-
expect(out).toBe("export const siteLoaders = {};");
|
|
28
|
-
// The stub must carry no dynamic import — that's the whole point.
|
|
29
|
-
expect(out).not.toMatch(/import\s*\(/);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("leaves loaders.gen.ts untouched in the SSR build (real registry)", () => {
|
|
33
|
-
expect(plugin.load(id, { ssr: true })).toBeUndefined();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("defaults to the client (stubbed) behavior when ssr is unset", () => {
|
|
37
|
-
// Rollup/Vite may call load() without an options.ssr flag; the guard is
|
|
38
|
-
// `!options?.ssr`, so an absent flag must be treated as client.
|
|
39
|
-
expect(plugin.load(id)).toBe("export const siteLoaders = {};");
|
|
40
|
-
expect(plugin.load(id, {})).toBe("export const siteLoaders = {};");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("still stubs blocks.gen.ts on the client (existing behavior intact)", () => {
|
|
44
|
-
const out = plugin.load("/repo/.deco/blocks.gen.ts", { ssr: false });
|
|
45
|
-
expect(out).toBe("export const blocks = {};");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("does not touch unrelated modules", () => {
|
|
49
|
-
expect(plugin.load("/repo/src/sections/Hero.tsx", { ssr: false })).toBeUndefined();
|
|
50
|
-
expect(plugin.load("/repo/src/actions/foo.ts", { ssr: false })).toBeUndefined();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* `fastDeploy: true` must stub blocks.gen out of the SERVER bundle — but only
|
|
56
|
-
* for production builds.
|
|
57
|
-
*
|
|
58
|
-
* Without the stub, a fast-deploy site holds the decofile twice: the bundled
|
|
59
|
-
* JSON.parse(...) graph stays reachable via the site's `import { blocks }`
|
|
60
|
-
* binding for the isolate's whole life, and ensureBlocksHydrated adds a second
|
|
61
|
-
* graph. Measured at 13.6 MB + 13.4 MB for a 9.2 MB decofile.
|
|
62
|
-
*
|
|
63
|
-
* In `vite dev` there is no KV to hydrate from, and the dev bootstrap relies on
|
|
64
|
-
* reading the `.json` sibling the stub bypasses — so stubbing there would blank
|
|
65
|
-
* the local site.
|
|
66
|
-
*/
|
|
67
|
-
describe("decoVitePlugin — fastDeploy server stub", () => {
|
|
68
|
-
const id = "/repo/.deco/blocks.gen.ts";
|
|
69
|
-
const STUB = "export const blocks = {};";
|
|
70
|
-
|
|
71
|
-
// The default is "auto", which reads DECO_SEEDED_DEPLOY. Pin it off so the
|
|
72
|
-
// "default does not stub" assertions below can't be silently satisfied (or
|
|
73
|
-
// broken) by an ambient env var.
|
|
74
|
-
vi.stubEnv("DECO_SEEDED_DEPLOY", "");
|
|
75
|
-
afterEach(() => vi.stubEnv("DECO_SEEDED_DEPLOY", ""));
|
|
76
|
-
|
|
77
|
-
/** @param {{fastDeploy?: boolean}} opts @param {"build"|"serve"} command */
|
|
78
|
-
const make = (opts, command) => {
|
|
79
|
-
const p = /** @type {any} */ (decoVitePlugin(opts));
|
|
80
|
-
p.config({}, { command }); // Vite always runs config() before load()
|
|
81
|
-
return p;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
it("stubs blocks.gen on SSR for a production build", () => {
|
|
85
|
-
expect(make({ fastDeploy: true }, "build").load(id, { ssr: true })).toBe(STUB);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("does NOT stub on SSR in dev, where there is no KV to hydrate from", () => {
|
|
89
|
-
expect(make({ fastDeploy: true }, "serve").load(id, { ssr: true })).not.toBe(STUB);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("keeps stubbing the client bundle regardless", () => {
|
|
93
|
-
expect(make({ fastDeploy: true }, "build").load(id, { ssr: false })).toBe(STUB);
|
|
94
|
-
expect(make({ fastDeploy: true }, "serve").load(id, { ssr: false })).toBe(STUB);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("does NOT stub blocks.gen on SSR by default (bundled fallback preserved)", () => {
|
|
98
|
-
// No .json sibling on disk for this synthetic path, so the hook falls
|
|
99
|
-
// through to Vite (undefined). The point is it never returns the stub.
|
|
100
|
-
expect(make({}, "build").load(id, { ssr: true })).not.toBe(STUB);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("leaves unrelated modules alone", () => {
|
|
104
|
-
expect(make({ fastDeploy: true }, "build").load("/repo/src/x.tsx", { ssr: true })).toBeUndefined();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("defines __DECO_BLOCKS_STUBBED__ so the runtime knows whether it has a fallback", () => {
|
|
108
|
-
const build = /** @type {any} */ (decoVitePlugin({ fastDeploy: true })).config({}, { command: "build" });
|
|
109
|
-
expect(build.define.__DECO_BLOCKS_STUBBED__).toBe("true");
|
|
110
|
-
|
|
111
|
-
// Dev and the default must both report "no, you still have a decofile",
|
|
112
|
-
// otherwise ensureBlocksHydrated would start failing requests.
|
|
113
|
-
const dev = /** @type {any} */ (decoVitePlugin({ fastDeploy: true })).config({}, { command: "serve" });
|
|
114
|
-
expect(dev.define.__DECO_BLOCKS_STUBBED__).toBe("false");
|
|
115
|
-
const def = /** @type {any} */ (decoVitePlugin()).config({}, { command: "build" });
|
|
116
|
-
expect(def.define.__DECO_BLOCKS_STUBBED__).toBe("false");
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The `"auto"` default: stub only when the deploy pipeline declares it seeds
|
|
122
|
-
* `decofile:<deployment-id>` into KV BEFORE activating the new version.
|
|
123
|
-
*
|
|
124
|
-
* Stubbing without that guarantee is a hard outage, not a degraded mode — the
|
|
125
|
-
* bundle has no decofile, so `ensureBlocksHydrated` 5xxs on purpose rather than
|
|
126
|
-
* serving an empty site the edge would cache. Cloudflare Workers Builds and a
|
|
127
|
-
* manual `wrangler deploy` do not seed, and they never set the env.
|
|
128
|
-
*/
|
|
129
|
-
describe("decoVitePlugin — fastDeploy auto gate", () => {
|
|
130
|
-
const id = "/repo/.deco/blocks.gen.ts";
|
|
131
|
-
const STUB = "export const blocks = {};";
|
|
132
|
-
|
|
133
|
-
afterEach(() => vi.unstubAllEnvs());
|
|
134
|
-
|
|
135
|
-
/** @param {"build"|"serve"} command */
|
|
136
|
-
const makeDefault = (command) => {
|
|
137
|
-
const p = /** @type {any} */ (decoVitePlugin());
|
|
138
|
-
const cfg = p.config({}, { command });
|
|
139
|
-
return { plugin: p, cfg };
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
it("does not stub when the pipeline does not declare a seed step", () => {
|
|
143
|
-
vi.stubEnv("DECO_SEEDED_DEPLOY", "");
|
|
144
|
-
const { plugin, cfg } = makeDefault("build");
|
|
145
|
-
expect(plugin.load(id, { ssr: true })).not.toBe(STUB);
|
|
146
|
-
expect(cfg.define.__DECO_BLOCKS_STUBBED__).toBe("false");
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("stubs on a production build when the pipeline declares it seeds", () => {
|
|
150
|
-
vi.stubEnv("DECO_SEEDED_DEPLOY", "1");
|
|
151
|
-
const { plugin, cfg } = makeDefault("build");
|
|
152
|
-
expect(plugin.load(id, { ssr: true })).toBe(STUB);
|
|
153
|
-
expect(cfg.define.__DECO_BLOCKS_STUBBED__).toBe("true");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("still never stubs SSR in dev, even inside a seeding pipeline", () => {
|
|
157
|
-
vi.stubEnv("DECO_SEEDED_DEPLOY", "1");
|
|
158
|
-
const { plugin, cfg } = makeDefault("serve");
|
|
159
|
-
expect(plugin.load(id, { ssr: true })).not.toBe(STUB);
|
|
160
|
-
expect(cfg.define.__DECO_BLOCKS_STUBBED__).toBe("false");
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("explicit false wins over a seeding pipeline", () => {
|
|
164
|
-
vi.stubEnv("DECO_SEEDED_DEPLOY", "1");
|
|
165
|
-
const p = /** @type {any} */ (decoVitePlugin({ fastDeploy: false }));
|
|
166
|
-
const cfg = p.config({}, { command: "build" });
|
|
167
|
-
expect(p.load(id, { ssr: true })).not.toBe(STUB);
|
|
168
|
-
expect(cfg.define.__DECO_BLOCKS_STUBBED__).toBe("false");
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("explicit true wins over a non-seeding pipeline", () => {
|
|
172
|
-
vi.stubEnv("DECO_SEEDED_DEPLOY", "");
|
|
173
|
-
const p = /** @type {any} */ (decoVitePlugin({ fastDeploy: true }));
|
|
174
|
-
expect(p.config({}, { command: "build" }).define.__DECO_BLOCKS_STUBBED__).toBe("true");
|
|
175
|
-
});
|
|
176
|
-
});
|