@decocms/tanstack 7.0.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/package.json +48 -0
- package/src/cms/kvBlockSource.test.ts +67 -0
- package/src/cms/kvBlockSource.ts +54 -0
- package/src/daemon/auth.ts +204 -0
- package/src/daemon/fs.ts +238 -0
- package/src/daemon/index.ts +8 -0
- package/src/daemon/middleware.ts +156 -0
- package/src/daemon/tunnel.ts +129 -0
- package/src/daemon/volumes.ts +366 -0
- package/src/daemon/watch.ts +272 -0
- package/src/hooks/DecoPageRenderer.tsx +685 -0
- package/src/hooks/DecoRootLayout.tsx +111 -0
- package/src/hooks/NavigationProgress.tsx +21 -0
- package/src/hooks/PreviewProviders.tsx +26 -0
- package/src/hooks/StableOutlet.tsx +30 -0
- package/src/hooks/index.ts +9 -0
- package/src/index.ts +30 -0
- package/src/routes/adminRoutes.ts +114 -0
- package/src/routes/cmsRoute.ts +706 -0
- package/src/routes/components.tsx +57 -0
- package/src/routes/index.ts +24 -0
- package/src/routes/pageUrl.test.ts +70 -0
- package/src/routes/pageUrl.ts +54 -0
- package/src/routes/withSiteGlobals.test.ts +206 -0
- package/src/routes/withSiteGlobals.ts +222 -0
- package/src/sdk/cookiePassthrough.ts +58 -0
- package/src/sdk/createInvoke.ts +57 -0
- package/src/sdk/kvHydration.test.ts +171 -0
- package/src/sdk/kvHydration.ts +176 -0
- package/src/sdk/router.ts +92 -0
- package/src/sdk/useHydrated.ts +19 -0
- package/src/sdk/workerEntry.test.ts +106 -0
- package/src/sdk/workerEntry.ts +1967 -0
- package/src/setupFastDeploy.ts +13 -0
- package/src/vite/plugin.js +646 -0
- package/src/vite/plugin.test.js +113 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { decoVitePlugin } from "./plugin.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The Vite plugin's `resolveId` / `load` hooks are pure functions over their
|
|
6
|
+
* inputs, so we can exercise them without spinning up a Vite environment.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function getPlugin() {
|
|
10
|
+
const result = decoVitePlugin();
|
|
11
|
+
// decoVitePlugin returns a single plugin object today, but the type is
|
|
12
|
+
// `PluginOption` which permits arrays — handle both.
|
|
13
|
+
return Array.isArray(result) ? result[0] : result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("decoVitePlugin SSR stubs", () => {
|
|
17
|
+
it("rewrites bare `fs` to a virtual module on SSR", () => {
|
|
18
|
+
const p = getPlugin();
|
|
19
|
+
const id = p.resolveId.call({}, "fs", undefined, { ssr: true });
|
|
20
|
+
expect(id).toBe("\0stub:bare-fs");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("does NOT rewrite bare `fs` on client (browser builds don't import fs)", () => {
|
|
24
|
+
const p = getPlugin();
|
|
25
|
+
const id = p.resolveId.call({}, "fs", undefined, { ssr: false });
|
|
26
|
+
expect(id).toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("loads an empty surface for the bare-fs virtual module", () => {
|
|
30
|
+
const p = getPlugin();
|
|
31
|
+
const src = p.load.call({}, "\0stub:bare-fs", { ssr: true });
|
|
32
|
+
expect(src).toContain("export const promises = {}");
|
|
33
|
+
expect(src).toContain("export default");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("does not interfere with real SSR modules", () => {
|
|
37
|
+
const p = getPlugin();
|
|
38
|
+
expect(p.resolveId.call({}, "@decocms/start/cms", undefined, { ssr: true })).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("decoVitePlugin client stubs (regression guard)", () => {
|
|
43
|
+
it("still rewrites node:async_hooks on the client build", () => {
|
|
44
|
+
const p = getPlugin();
|
|
45
|
+
const id = p.resolveId.call({}, "node:async_hooks", undefined, { ssr: false });
|
|
46
|
+
expect(id).toBe("\0stub:node-async-hooks");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("does not rewrite client stubs on SSR", () => {
|
|
50
|
+
const p = getPlugin();
|
|
51
|
+
const id = p.resolveId.call({}, "react-dom/server", undefined, { ssr: true });
|
|
52
|
+
expect(id).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("decoVitePlugin __DECO_BUILD_HASH__ injection", () => {
|
|
57
|
+
let originalEnv;
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
originalEnv = { ...process.env };
|
|
61
|
+
delete process.env.WORKERS_CI_COMMIT_SHA;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
process.env = originalEnv;
|
|
66
|
+
vi.restoreAllMocks();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function callConfig(command) {
|
|
70
|
+
const p = getPlugin();
|
|
71
|
+
return p.config({}, { command });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it("injects the literal 'dev' for non-build commands", () => {
|
|
75
|
+
const cfg = callConfig("serve");
|
|
76
|
+
expect(cfg.define.__DECO_BUILD_HASH__).toBe(JSON.stringify("dev"));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("uses WORKERS_CI_COMMIT_SHA (sliced to 12 chars) when set on a build", () => {
|
|
80
|
+
process.env.WORKERS_CI_COMMIT_SHA = "abcdef1234567890fedcba";
|
|
81
|
+
const cfg = callConfig("build");
|
|
82
|
+
expect(cfg.define.__DECO_BUILD_HASH__).toBe(JSON.stringify("abcdef123456"));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("falls back to git rev-parse when WORKERS_CI_COMMIT_SHA is unset", async () => {
|
|
86
|
+
// The plugin module imports execFileSync at top-level, so we can't easily
|
|
87
|
+
// mock it after the fact. Instead, exercise the real git binary against
|
|
88
|
+
// this repo (CI runs in the repo working tree). Assert the value is a
|
|
89
|
+
// 12-char lowercase hex SHA — that proves git was consulted, not that
|
|
90
|
+
// the time-based fallback was hit.
|
|
91
|
+
const cfg = callConfig("build");
|
|
92
|
+
const value = JSON.parse(cfg.define.__DECO_BUILD_HASH__);
|
|
93
|
+
// Either git produced a SHA (CI / dev machine inside a repo) or the
|
|
94
|
+
// time-based fallback ran. Both are acceptable; we just assert non-empty
|
|
95
|
+
// and length sanity.
|
|
96
|
+
expect(typeof value).toBe("string");
|
|
97
|
+
expect(value.length).toBeGreaterThan(0);
|
|
98
|
+
// Time-based fallback produces base36 characters; git short SHAs are
|
|
99
|
+
// 12 hex chars. Both fit in this superset regex.
|
|
100
|
+
expect(value).toMatch(/^[0-9a-z]+$/);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("preserves allowedHosts behaviour (regression: define is additive, not replacing)", () => {
|
|
104
|
+
process.env.DECO_SITE_NAME = "test-site";
|
|
105
|
+
try {
|
|
106
|
+
const cfg = callConfig("serve");
|
|
107
|
+
expect(cfg.server?.allowedHosts).toContain(".deco.studio");
|
|
108
|
+
expect(cfg.define.__DECO_BUILD_HASH__).toBeDefined();
|
|
109
|
+
} finally {
|
|
110
|
+
delete process.env.DECO_SITE_NAME;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|