@decocms/blocks-cli 7.69.1 → 7.70.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks-cli",
3
- "version": "7.69.1",
3
+ "version": "7.70.0",
4
4
  "type": "module",
5
5
  "description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:unused": "knip"
34
34
  },
35
35
  "dependencies": {
36
- "@decocms/blocks": "7.69.1",
36
+ "@decocms/blocks": "7.70.0",
37
37
  "ts-morph": "^27.0.0",
38
38
  "tsx": "^4.22.5"
39
39
  },
@@ -0,0 +1,130 @@
1
+ import * as fs from "node:fs";
2
+ import * as os from "node:os";
3
+ import * as path from "node:path";
4
+ import { describe, expect, it } from "vitest";
5
+ import { parseJsonc } from "../lib/jsonc";
6
+ import { generateWranglerConfig } from "./phase-scaffold";
7
+ import { checks } from "./phase-verify";
8
+ import { generateSetup } from "./templates/setup";
9
+ import type { MigrationContext } from "./types";
10
+
11
+ /**
12
+ * Fast Deploy is inert unless THREE things line up: the `DECO_KV` binding,
13
+ * `DECO_FAST_DEPLOY=1`, and `setup.ts` handing the KV resolver to
14
+ * `@decocms/blocks-admin` (which cannot import `@decocms/tanstack` itself).
15
+ *
16
+ * Two of three is the worst state: it looks configured, a Studio publish
17
+ * reports success, and nothing ever reaches KV. These tests pin the scaffold to
18
+ * emit all three and pin the verify check to actually catch a partial config.
19
+ */
20
+
21
+ const FIXTURE: MigrationContext = {
22
+ sourceDir: "",
23
+ siteName: "test-site",
24
+ platform: "custom",
25
+ vtexAccount: null,
26
+ gtmId: null,
27
+ importMap: {},
28
+ discoveredNpmDeps: {},
29
+ themeColors: {},
30
+ tailwindConfig: {
31
+ colors: {},
32
+ fontFamily: {},
33
+ screens: {},
34
+ safelist: [],
35
+ safelistPatterns: [],
36
+ plugins: [],
37
+ reviewItems: [],
38
+ animations: {},
39
+ keyframes: {},
40
+ },
41
+ fontFamily: null,
42
+ googleFonts: [],
43
+ layout: null,
44
+ files: [],
45
+ sectionMetas: [],
46
+ islandClassifications: [],
47
+ loaderInventory: [],
48
+ patterns: {},
49
+ scaffoldedFiles: [],
50
+ transformedFiles: [],
51
+ deletedFiles: [],
52
+ movedFiles: [],
53
+ manualReview: [],
54
+ dryRun: false,
55
+ verbose: false,
56
+ } as unknown as MigrationContext;
57
+
58
+ const fastDeployCheck = checks.find((c) => c.name === "Fast Deploy wired end to end");
59
+
60
+ /** Write a site tree with the given wrangler + setup contents. */
61
+ function makeSite(wrangler: string, setup: string): MigrationContext {
62
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fd-scaffold-"));
63
+ fs.writeFileSync(path.join(dir, "wrangler.jsonc"), wrangler);
64
+ fs.mkdirSync(path.join(dir, "src"), { recursive: true });
65
+ fs.writeFileSync(path.join(dir, "src", "setup.ts"), setup);
66
+ return { ...FIXTURE, sourceDir: dir };
67
+ }
68
+
69
+ describe("scaffolded wrangler.jsonc", () => {
70
+ // Parse it rather than grep it: the template is hand-written JSONC, and a
71
+ // stray comma or comment that breaks parsing silently disables fast-deploy
72
+ // everywhere at once (the builder, the control-plane and the verify check
73
+ // below all read this file through a JSONC parser).
74
+ const cfg = parseJsonc(generateWranglerConfig(FIXTURE)) as {
75
+ kv_namespaces: Array<{ binding: string }>;
76
+ vars: Record<string, string>;
77
+ tail_consumers?: unknown[];
78
+ };
79
+
80
+ it("declares the DECO_KV binding and DECO_FAST_DEPLOY together", () => {
81
+ expect(cfg.kv_namespaces.map((n) => n.binding)).toContain("DECO_KV");
82
+ expect(cfg.vars.DECO_FAST_DEPLOY).toBe("1");
83
+ expect(cfg.vars.DECO_SITE_NAME).toBe("test-site");
84
+ });
85
+
86
+ it("declares a tail consumer, without which exceededMemory is unobservable", () => {
87
+ // Cloudflare kills the isolate over the 128MB cap before any in-worker code
88
+ // could report it — the tail worker is the only channel that sees it.
89
+ expect(cfg.tail_consumers).toBeTruthy();
90
+ });
91
+ });
92
+
93
+ describe("scaffolded setup.ts", () => {
94
+ it("calls setupTanstackFastDeploy, or the Studio publish write-through no-ops", () => {
95
+ const setup = generateSetup(FIXTURE);
96
+ expect(setup).toContain("setupTanstackFastDeploy()");
97
+ expect(setup).toMatch(/import \{[^}]*setupTanstackFastDeploy[^}]*\} from "@decocms\/tanstack"/);
98
+ });
99
+ });
100
+
101
+ describe('verify check "Fast Deploy wired end to end"', () => {
102
+ const FULL_WRANGLER = `{
103
+ // comment + trailing comma: real wrangler.jsonc, not JSON
104
+ "kv_namespaces": [{ "binding": "DECO_KV", "id": "" }],
105
+ "vars": { "DECO_FAST_DEPLOY": "1" },
106
+ }`;
107
+ const FULL_SETUP = "setupTanstackFastDeploy();\n";
108
+
109
+ it("passes on a fully wired site", () => {
110
+ expect(fastDeployCheck?.fn(makeSite(FULL_WRANGLER, FULL_SETUP))).toBe(true);
111
+ });
112
+
113
+ it("fails when the DECO_KV binding is missing", () => {
114
+ const w = '{ "kv_namespaces": [], "vars": { "DECO_FAST_DEPLOY": "1" } }';
115
+ expect(fastDeployCheck?.fn(makeSite(w, FULL_SETUP))).toBe(false);
116
+ });
117
+
118
+ it("fails when DECO_FAST_DEPLOY is not set", () => {
119
+ const w = '{ "kv_namespaces": [{ "binding": "DECO_KV", "id": "" }] }';
120
+ expect(fastDeployCheck?.fn(makeSite(w, FULL_SETUP))).toBe(false);
121
+ });
122
+
123
+ it("fails when setup.ts never hands over the KV resolver", () => {
124
+ expect(fastDeployCheck?.fn(makeSite(FULL_WRANGLER, "// nothing\n"))).toBe(false);
125
+ });
126
+
127
+ it("is an error, not a warning — a silent half-config is the failure mode", () => {
128
+ expect(fastDeployCheck?.severity).toBe("error");
129
+ });
130
+ });
@@ -277,21 +277,48 @@ export { type Font as SiteThemeFont };
277
277
  `;
278
278
  }
279
279
 
280
- function generateWranglerConfig(ctx: MigrationContext): string {
281
- return (
282
- JSON.stringify(
283
- {
284
- name: ctx.siteName,
285
- main: "src/worker-entry.ts",
286
- compatibility_date: "2025-05-01",
287
- compatibility_flags: ["nodejs_compat", "no_handle_cross_request_promise_resolution"],
288
- cache: { enabled: true },
289
- kv_namespaces: [{ binding: "SITES_KV", id: "dev-sites-kv" }],
290
- },
291
- null,
292
- 2,
293
- ) + "\n"
294
- );
280
+ export function generateWranglerConfig(ctx: MigrationContext): string {
281
+ // Emitted as real JSONC (not JSON.stringify) so the comments survive — every
282
+ // field below is load-bearing and the next person to edit this file needs to
283
+ // know why. The ids are placeholders: the control-plane owns them (it
284
+ // provisions the site's OWN namespaces and overrides these at build time),
285
+ // so a wrong id here can never reach production.
286
+ return `{
287
+ "name": "${ctx.siteName}",
288
+ "main": "src/worker-entry.ts",
289
+ "compatibility_date": "2025-05-01",
290
+ // no_handle_cross_request_promise_resolution: the framework's SWR/dedup
291
+ // caches hold in-flight promises across requests; without this flag the
292
+ // worker hangs.
293
+ "compatibility_flags": ["nodejs_compat", "no_handle_cross_request_promise_resolution"],
294
+ // Workers Cache — tiered cache IN FRONT of the worker. On a hit the worker
295
+ // never runs. Per-response cacheability is still driven by Cache-Control.
296
+ "cache": { "enabled": true },
297
+ // Surfaces the build sha as service.version on every span and log line.
298
+ "version_metadata": { "binding": "CF_VERSION_METADATA" },
299
+ // Tail worker. The ONLY channel that can see exceededMemory / exceededCpu:
300
+ // Cloudflare kills the isolate before any in-worker code could report them.
301
+ // Without this a memory incident is invisible — see docs/runbooks/.
302
+ "tail_consumers": [{ "service": "deco-otel-tail" }],
303
+ "kv_namespaces": [
304
+ // Fast Deploy content store. Holds decofile:<deployment-id> + the revision
305
+ // index, so a CMS publish goes live without a code deploy. The id is
306
+ // written by the control-plane at site creation and re-forced from
307
+ // CF_KV_NAMESPACE_ID on every build (per-site KV isolation).
308
+ { "binding": "DECO_KV", "id": "" }
309
+ // No SITES_KV: withABTesting (server-entry) passes through when it is
310
+ // unbound, and nothing provisions it — an empty id would fail deploy.
311
+ // Add it with the shared namespace's real id when starting an A/B test.
312
+ ],
313
+ "vars": {
314
+ "DECO_SITE_NAME": "${ctx.siteName}",
315
+ "DECO_ENV_NAME": "production",
316
+ // Fast Deploy opt-in. Requires BOTH this flag AND the DECO_KV binding
317
+ // above; inert if either is missing. Set to "0" to disable.
318
+ "DECO_FAST_DEPLOY": "1"
319
+ }
320
+ }
321
+ `;
295
322
  }
296
323
 
297
324
  function generateGitignore(): string {
@@ -1,5 +1,6 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
+ import { parseJsonc } from "../lib/jsonc";
3
4
  import type { MigrationContext } from "./types";
4
5
  import { logPhase } from "./types";
5
6
 
@@ -84,6 +85,45 @@ export const checks: Check[] = [
84
85
  return true;
85
86
  },
86
87
  },
88
+ {
89
+ // Fast Deploy needs THREE things and is inert unless all three are present:
90
+ // the DECO_KV binding, DECO_FAST_DEPLOY=1, and setup.ts handing the KV
91
+ // resolver to blocks-admin. Two of three is the worst state — it looks
92
+ // configured, the Studio publish reports success, and nothing reaches KV.
93
+ name: "Fast Deploy wired end to end",
94
+ severity: "error",
95
+ fn: (ctx) => {
96
+ const missing: string[] = [];
97
+ const wranglerPath = path.join(ctx.sourceDir, "wrangler.jsonc");
98
+ try {
99
+ const cfg = parseJsonc(fs.readFileSync(wranglerPath, "utf-8")) as {
100
+ kv_namespaces?: Array<{ binding?: string }>;
101
+ vars?: Record<string, unknown>;
102
+ };
103
+ const flag = cfg.vars?.DECO_FAST_DEPLOY;
104
+ if (!(cfg.kv_namespaces ?? []).some((n) => n?.binding === "DECO_KV")) {
105
+ missing.push("wrangler.jsonc kv_namespaces is missing the DECO_KV binding");
106
+ }
107
+ if (flag !== "1" && flag !== "true") {
108
+ missing.push('wrangler.jsonc vars.DECO_FAST_DEPLOY is not "1"');
109
+ }
110
+ } catch (e) {
111
+ missing.push(`wrangler.jsonc could not be parsed: ${(e as Error).message}`);
112
+ }
113
+
114
+ const setupPath = path.join(ctx.sourceDir, "src", "setup.ts");
115
+ const setup = fs.existsSync(setupPath) ? fs.readFileSync(setupPath, "utf-8") : "";
116
+ if (!setup.includes("setupTanstackFastDeploy()")) {
117
+ missing.push("src/setup.ts does not call setupTanstackFastDeploy()");
118
+ }
119
+
120
+ if (missing.length > 0) {
121
+ for (const m of missing) console.log(` ${m}`);
122
+ return false;
123
+ }
124
+ return true;
125
+ },
126
+ },
87
127
  {
88
128
  name: "Old artifacts removed",
89
129
  severity: "error",
@@ -104,7 +104,7 @@ import { initVtexFromBlocks, setVtexFetch } from "@decocms/apps-vtex";` : ""}${h
104
104
  import { registerLocationMatcher } from "./matchers/location";` : ""}
105
105
  import { blocks as generatedBlocks } from "../.deco/blocks.gen";
106
106
  import { sectionMeta, syncComponents, loadingFallbacks, renderJsons } from "../.deco/sections.gen";
107
- import { PreviewProviders } from "@decocms/tanstack";
107
+ import { PreviewProviders, setupTanstackFastDeploy } from "@decocms/tanstack";
108
108
  // @ts-ignore Vite ?url import
109
109
  import appCss from "./styles/app.css?url";
110
110
 
@@ -131,6 +131,13 @@ createSiteSetup({
131
131
  return null;
132
132
  },
133
133
  });
134
+
135
+ // -- Fast Deploy --
136
+ // Hands the KV binding resolver to @decocms/blocks-admin, which cannot import
137
+ // @decocms/tanstack itself (wrong direction in the package graph). Without this
138
+ // call a Studio publish silently no-ops instead of writing through to KV.
139
+ // Inert unless the worker has DECO_FAST_DEPLOY=1 + a DECO_KV binding.
140
+ setupTanstackFastDeploy();
134
141
  ${isVtex ? `
135
142
  // -- VTEX wiring --
136
143
  setVtexFetch(createInstrumentedFetch("vtex"));