@decocms/blocks-cli 7.10.0 → 7.11.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.
|
|
3
|
+
"version": "7.11.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": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:unused": "knip"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@decocms/blocks": "7.
|
|
39
|
+
"@decocms/blocks": "7.11.0",
|
|
40
40
|
"ts-morph": "^27.0.0",
|
|
41
41
|
"tsx": "^4.22.5"
|
|
42
42
|
},
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { MigrationContext } from "../types";
|
|
3
|
+
import { createContext } from "../types";
|
|
4
|
+
import { generateRoutes } from "./routes";
|
|
5
|
+
|
|
6
|
+
function makeCtx(platform: MigrationContext["platform"]): MigrationContext {
|
|
7
|
+
const ctx = createContext("/tmp/routes-template-fixture-site");
|
|
8
|
+
ctx.siteName = "acme-storefront";
|
|
9
|
+
ctx.platform = platform;
|
|
10
|
+
ctx.vtexAccount = platform === "vtex" ? "acme" : null;
|
|
11
|
+
return ctx;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Regression guard: the scaffolded deco admin route files must use the
|
|
16
|
+
* dev-HMR-safe `*RouteConfig()` factories — the only form @decocms/tanstack
|
|
17
|
+
* exports since 7.10.0 — never the removed pre-7.10.0 module-scope literals
|
|
18
|
+
* passed by reference. router-core's `update()` mutates the options object it
|
|
19
|
+
* receives (injects id/path); a shared literal got polluted on first
|
|
20
|
+
* execution, and any dev-HMR re-execution of the route file then threw
|
|
21
|
+
* "Route cannot have both an 'id' and a 'path' option", 500ing every route
|
|
22
|
+
* until the dev server restarted.
|
|
23
|
+
*/
|
|
24
|
+
describe("scaffolded deco admin routes use HMR-safe factories", () => {
|
|
25
|
+
const routeCases = [
|
|
26
|
+
{ file: "src/routes/deco/meta.ts", factory: "decoMetaRouteConfig", literal: "decoMetaRoute" },
|
|
27
|
+
{
|
|
28
|
+
file: "src/routes/deco/render.ts",
|
|
29
|
+
factory: "decoRenderRouteConfig",
|
|
30
|
+
literal: "decoRenderRoute",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
file: "src/routes/deco/invoke.$.ts",
|
|
34
|
+
factory: "decoInvokeRouteConfig",
|
|
35
|
+
literal: "decoInvokeRoute",
|
|
36
|
+
},
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
for (const platform of ["vtex", "custom"] as const) {
|
|
40
|
+
describe(`platform: ${platform}`, () => {
|
|
41
|
+
const files = generateRoutes(makeCtx(platform));
|
|
42
|
+
|
|
43
|
+
for (const { file, factory, literal } of routeCases) {
|
|
44
|
+
it(`${file} calls ${factory}() and never passes ${literal} by reference`, () => {
|
|
45
|
+
const content = files[file];
|
|
46
|
+
expect(content, `${file} must be emitted`).toBeTypeOf("string");
|
|
47
|
+
|
|
48
|
+
// Factory form: createFileRoute("...")(decoXRouteConfig())
|
|
49
|
+
expect(content).toContain(`${factory}()`);
|
|
50
|
+
expect(content).toContain(`import { ${factory} } from "@decocms/tanstack"`);
|
|
51
|
+
|
|
52
|
+
// Forbidden form: createFileRoute("...")(decoXRoute) — shared
|
|
53
|
+
// literal by reference. `(?!Config)` keeps the factory call legal.
|
|
54
|
+
expect(content).not.toMatch(new RegExp(`\\)\\(${literal}(?!Config)\\s*\\)`));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
@@ -210,26 +210,34 @@ function NotFoundPage() {
|
|
|
210
210
|
`;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
// The deco admin routes use the `*RouteConfig()` factories — the only form
|
|
214
|
+
// @decocms/tanstack exports since 7.10.0. The pre-7.10.0 module-scope
|
|
215
|
+
// literals (decoMetaRoute/decoRenderRoute/decoInvokeRoute) were removed:
|
|
216
|
+
// passed by reference, router-core's update() mutated the shared object
|
|
217
|
+
// (injecting id/path), and any dev-HMR re-execution of the route file then
|
|
218
|
+
// threw "Route cannot have both an 'id' and a 'path' option", 500ing every
|
|
219
|
+
// route until dev restart.
|
|
220
|
+
|
|
213
221
|
function generateDecoMeta(): string {
|
|
214
222
|
return `import { createFileRoute } from "@tanstack/react-router";
|
|
215
|
-
import {
|
|
223
|
+
import { decoMetaRouteConfig } from "@decocms/tanstack";
|
|
216
224
|
|
|
217
|
-
export const Route = createFileRoute("/deco/meta")(
|
|
225
|
+
export const Route = createFileRoute("/deco/meta")(decoMetaRouteConfig());
|
|
218
226
|
`;
|
|
219
227
|
}
|
|
220
228
|
|
|
221
229
|
function generateDecoInvoke(): string {
|
|
222
230
|
return `import { createFileRoute } from "@tanstack/react-router";
|
|
223
|
-
import {
|
|
231
|
+
import { decoInvokeRouteConfig } from "@decocms/tanstack";
|
|
224
232
|
|
|
225
|
-
export const Route = createFileRoute("/deco/invoke/$")(
|
|
233
|
+
export const Route = createFileRoute("/deco/invoke/$")(decoInvokeRouteConfig());
|
|
226
234
|
`;
|
|
227
235
|
}
|
|
228
236
|
|
|
229
237
|
function generateDecoRender(): string {
|
|
230
238
|
return `import { createFileRoute } from "@tanstack/react-router";
|
|
231
|
-
import {
|
|
239
|
+
import { decoRenderRouteConfig } from "@decocms/tanstack";
|
|
232
240
|
|
|
233
|
-
export const Route = createFileRoute("/deco/render")(
|
|
241
|
+
export const Route = createFileRoute("/deco/render")(decoRenderRouteConfig());
|
|
234
242
|
`;
|
|
235
243
|
}
|