@decocms/start 2.13.0 → 2.15.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/.agents/skills/deco-to-tanstack-migration/references/post-migration-cleanup.md +132 -6
- package/CLAUDE.md +1 -1
- package/package.json +1 -1
- package/scripts/migrate/post-cleanup/rules.ts +196 -7
- package/scripts/migrate/post-cleanup/runner.test.ts +225 -2
- package/scripts/migrate/post-cleanup/shim-classify.test.ts +352 -0
- package/scripts/migrate/post-cleanup/shim-classify.ts +246 -0
- package/.cursor/skills/deco-to-tanstack-migration/SKILL.md +0 -655
- package/.cursor/skills/deco-to-tanstack-migration/references/codemod-commands.md +0 -174
- package/.cursor/skills/deco-to-tanstack-migration/references/commerce/README.md +0 -78
- package/.cursor/skills/deco-to-tanstack-migration/references/deco-framework/README.md +0 -174
- package/.cursor/skills/deco-to-tanstack-migration/references/gotchas.md +0 -834
- package/.cursor/skills/deco-to-tanstack-migration/references/imports/README.md +0 -70
- package/.cursor/skills/deco-to-tanstack-migration/references/platform-hooks/README.md +0 -121
- package/.cursor/skills/deco-to-tanstack-migration/references/post-migration-cleanup.md +0 -231
- package/.cursor/skills/deco-to-tanstack-migration/references/signals/README.md +0 -220
- package/.cursor/skills/deco-to-tanstack-migration/references/vite-config/README.md +0 -103
- package/.cursor/skills/deco-to-tanstack-migration/templates/package-json.md +0 -75
- package/.cursor/skills/deco-to-tanstack-migration/templates/root-route.md +0 -127
- package/.cursor/skills/deco-to-tanstack-migration/templates/router.md +0 -96
- package/.cursor/skills/deco-to-tanstack-migration/templates/setup-ts.md +0 -148
- package/.cursor/skills/deco-to-tanstack-migration/templates/vite-config.md +0 -197
- package/.cursor/skills/deco-to-tanstack-migration/templates/worker-entry.md +0 -67
- /package/{.cursor → .agents}/skills/deco-to-tanstack-migration/references/server-functions/README.md +0 -0
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
# vite.config.ts Template
|
|
2
|
-
|
|
3
|
-
Battle-tested configuration. Uses the framework's `decoVitePlugin()` for the
|
|
4
|
-
server-only stub layer (rather than re-implementing it inline like older
|
|
5
|
-
sites did).
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { cloudflare } from "@cloudflare/vite-plugin";
|
|
9
|
-
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
|
10
|
-
import { decoVitePlugin } from "@decocms/start/vite";
|
|
11
|
-
import react from "@vitejs/plugin-react";
|
|
12
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
13
|
-
import { defineConfig } from "vite";
|
|
14
|
-
import path from "path";
|
|
15
|
-
|
|
16
|
-
const srcDir = path.resolve(__dirname, "src");
|
|
17
|
-
|
|
18
|
-
// VTEX dev proxy — adjust to your account / commerce backend.
|
|
19
|
-
const VTEX_ACCOUNT = process.env.VTEX_ACCOUNT || "mystore";
|
|
20
|
-
const VTEX_ORIGIN = `https://${VTEX_ACCOUNT}.vtexcommercestable.com.br`;
|
|
21
|
-
|
|
22
|
-
export default defineConfig({
|
|
23
|
-
server: {
|
|
24
|
-
port: parseInt(process.env.PORT ?? "5173", 10),
|
|
25
|
-
// When the deco daemon injects PORT, bind to all interfaces so Deno's
|
|
26
|
-
// TCP connect (127.0.0.1) can reach Vite regardless of IPv4/IPv6.
|
|
27
|
-
host: process.env.PORT ? "0.0.0.0" : undefined,
|
|
28
|
-
headers: {
|
|
29
|
-
// Allow embedding in iframes from trusted admin origins.
|
|
30
|
-
"Content-Security-Policy":
|
|
31
|
-
"frame-ancestors 'self' https://*.deco.studio http://localhost:* https://localhost:* https://admin.deco.cx https://studio.decocms.com",
|
|
32
|
-
},
|
|
33
|
-
proxy: {
|
|
34
|
-
"/api/": {
|
|
35
|
-
target: VTEX_ORIGIN,
|
|
36
|
-
changeOrigin: true,
|
|
37
|
-
cookieDomainRewrite: { "*": "" },
|
|
38
|
-
},
|
|
39
|
-
"/checkout": {
|
|
40
|
-
target: VTEX_ORIGIN,
|
|
41
|
-
changeOrigin: true,
|
|
42
|
-
cookieDomainRewrite: { "*": "" },
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
plugins: [
|
|
47
|
-
cloudflare({ viteEnvironment: { name: "ssr" } }),
|
|
48
|
-
tanstackStart({ server: { entry: "server" } }),
|
|
49
|
-
react({
|
|
50
|
-
babel: {
|
|
51
|
-
plugins: [["babel-plugin-react-compiler", { target: "19" }]],
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
tailwindcss(),
|
|
55
|
-
// Framework plugin — provides server-only stubs (react-dom/server,
|
|
56
|
-
// node:async_hooks, etc.), blocks.gen.ts JSON-fast-path, meta.gen
|
|
57
|
-
// client stub, daemon/tunnel for dev mode, and correct manualChunks
|
|
58
|
-
// (NOT splitting @decocms/start / @decocms/apps which have circular
|
|
59
|
-
// re-exports). Replaces ~80 lines of boilerplate that older sites
|
|
60
|
-
// had inline.
|
|
61
|
-
decoVitePlugin(),
|
|
62
|
-
],
|
|
63
|
-
build: {
|
|
64
|
-
sourcemap: "hidden",
|
|
65
|
-
rollupOptions: {
|
|
66
|
-
onLog(level, log, handler) {
|
|
67
|
-
// Silence harmless "dynamic import will not move module" warning
|
|
68
|
-
// emitted when a module is imported both statically and dynamically.
|
|
69
|
-
if (
|
|
70
|
-
log.code === "PLUGIN_WARNING" &&
|
|
71
|
-
log.plugin === "vite:reporter" &&
|
|
72
|
-
log.message?.includes("dynamic import will not move module")
|
|
73
|
-
) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
handler(level, log);
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
define: {
|
|
81
|
-
// Inject site name at build time, not read at runtime.
|
|
82
|
-
"process.env.DECO_SITE_NAME": JSON.stringify(
|
|
83
|
-
process.env.DECO_SITE_NAME || "my-store",
|
|
84
|
-
),
|
|
85
|
-
},
|
|
86
|
-
esbuild: {
|
|
87
|
-
jsx: "automatic",
|
|
88
|
-
jsxImportSource: "react",
|
|
89
|
-
// Strip console.log in production; keep .warn / .error for debugging.
|
|
90
|
-
pure: ["console.log"],
|
|
91
|
-
},
|
|
92
|
-
resolve: {
|
|
93
|
-
// CRITICAL: without dedupe, multiple React/TanStack instances cause
|
|
94
|
-
// "Invalid hook call" errors at runtime.
|
|
95
|
-
dedupe: [
|
|
96
|
-
"@decocms/start",
|
|
97
|
-
"@decocms/apps",
|
|
98
|
-
"@tanstack/react-start",
|
|
99
|
-
"@tanstack/react-router",
|
|
100
|
-
"@tanstack/react-start-server",
|
|
101
|
-
"@tanstack/start-server-core",
|
|
102
|
-
"@tanstack/start-client-core",
|
|
103
|
-
"@tanstack/start-plugin-core",
|
|
104
|
-
"@tanstack/start-storage-context",
|
|
105
|
-
"react",
|
|
106
|
-
"react-dom",
|
|
107
|
-
],
|
|
108
|
-
alias: {
|
|
109
|
-
"~": srcDir,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Key Points
|
|
116
|
-
|
|
117
|
-
1. **`decoVitePlugin()`** — Required. Replaces ~80 lines of inline boilerplate
|
|
118
|
-
that older sites had to copy. Provides:
|
|
119
|
-
- Client stubs for server-only modules (`react-dom/server`,
|
|
120
|
-
`node:async_hooks`, `node:stream`, etc.)
|
|
121
|
-
- `blocks.gen.ts` JSON fast-path (10-100x parse speedup for large registries)
|
|
122
|
-
- `meta.gen.{json,ts}` client stub (cuts admin schema 0.5-5MB out of
|
|
123
|
-
browser bundle)
|
|
124
|
-
- Daemon/tunnel for dev mode (when `DECO_SITE_NAME` env is set)
|
|
125
|
-
- Production `manualChunks` that does NOT split `@decocms/start` or
|
|
126
|
-
`@decocms/apps` (those have circular re-exports and crash when chunked
|
|
127
|
-
separately)
|
|
128
|
-
- `allowedHosts` for tunnel domains (`.deco.host`, `.decocdn.com`,
|
|
129
|
-
`.deco.studio`)
|
|
130
|
-
- JSX automatic / react import-source defaults
|
|
131
|
-
|
|
132
|
-
2. **`resolve.dedupe`** — Required. Without it, multiple React instances
|
|
133
|
-
cause "Invalid hook call" errors. The list MUST include both
|
|
134
|
-
`@decocms/start` and `@decocms/apps` because they re-export TanStack
|
|
135
|
-
types and registry singletons.
|
|
136
|
-
|
|
137
|
-
3. **`process.env.DECO_SITE_NAME` via `define`** — Must be injected at
|
|
138
|
-
build time, not read at runtime. Workers don't have a Node-style
|
|
139
|
-
`process.env` at runtime.
|
|
140
|
-
|
|
141
|
-
4. **React Compiler** — `babel-plugin-react-compiler` with `target: "19"`
|
|
142
|
-
for automatic memoization. Requires `@vitejs/plugin-react`, not the
|
|
143
|
-
default SWC plugin.
|
|
144
|
-
|
|
145
|
-
5. **`esbuild.jsx: "automatic"` with `jsxImportSource: "react"`** — Without
|
|
146
|
-
it, JSX falls back to `React.createElement` references that may not
|
|
147
|
-
resolve.
|
|
148
|
-
|
|
149
|
-
6. **CSP `frame-ancestors`** — Required for the admin (`*.deco.studio`,
|
|
150
|
-
`admin.deco.cx`, `studio.decocms.com`) to embed previews in iframes.
|
|
151
|
-
|
|
152
|
-
7. **VTEX dev proxy** — Local `/api/`, `/checkout` requests proxied to
|
|
153
|
-
the upstream commerce backend so cookie-based session works in dev
|
|
154
|
-
without CORS gymnastics.
|
|
155
|
-
|
|
156
|
-
## What older site templates inline (and why this template doesn't)
|
|
157
|
-
|
|
158
|
-
Some older guides show two extra inline plugins:
|
|
159
|
-
|
|
160
|
-
```ts
|
|
161
|
-
// site-manual-chunks — overrides framework default chunking
|
|
162
|
-
{ name: "site-manual-chunks", config(_cfg, { command }) { ... } }
|
|
163
|
-
|
|
164
|
-
// deco-stub-meta-gen — stubs admin schema on client
|
|
165
|
-
{ name: "deco-stub-meta-gen", enforce: "pre", resolveId(...), load(...) }
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Both are obsolete after `@decocms/start` >= 2.5.0:
|
|
169
|
-
- The framework's `manualChunks` no longer splits `@decocms/start` /
|
|
170
|
-
`@decocms/apps` (the old split caused circular-dep load-order crashes —
|
|
171
|
-
every site overrode it).
|
|
172
|
-
- The framework now stubs `meta.gen.{json,ts}` on the client by default.
|
|
173
|
-
|
|
174
|
-
If you're on an older version, keep the inline plugins until you can bump.
|
|
175
|
-
|
|
176
|
-
## tsconfig.json (matches the Vite alias)
|
|
177
|
-
|
|
178
|
-
```json
|
|
179
|
-
{
|
|
180
|
-
"compilerOptions": {
|
|
181
|
-
"jsx": "react-jsx",
|
|
182
|
-
"moduleResolution": "bundler",
|
|
183
|
-
"module": "ESNext",
|
|
184
|
-
"target": "ES2022",
|
|
185
|
-
"skipLibCheck": true,
|
|
186
|
-
"strictNullChecks": true,
|
|
187
|
-
"baseUrl": ".",
|
|
188
|
-
"paths": {
|
|
189
|
-
"~/*": ["./src/*"]
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
"include": ["src/**/*", "vite.config.ts"]
|
|
193
|
-
}
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
No `$store/*`, `site/*`, `apps/*`, `preact`, `@preact/signals`,
|
|
197
|
-
`@deco/deco` paths. Those are all dead.
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Worker Entry Templates
|
|
2
|
-
|
|
3
|
-
## src/server.ts
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
// CRITICAL: import "./setup" MUST be the first import.
|
|
7
|
-
// Without it, server functions in Vite split modules have empty state
|
|
8
|
-
// (blocks, registry, commerce loaders) causing 404 on client-side navigation.
|
|
9
|
-
import "./setup";
|
|
10
|
-
import { createStartHandler, defaultStreamHandler } from "@tanstack/react-start/server";
|
|
11
|
-
|
|
12
|
-
export default createStartHandler(defaultStreamHandler);
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## src/worker-entry.ts
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
// CRITICAL: import "./setup" MUST be the first import.
|
|
19
|
-
import "./setup";
|
|
20
|
-
import handler, { createServerEntry } from "@tanstack/react-start/server-entry";
|
|
21
|
-
import { createDecoWorkerEntry } from "@decocms/start/sdk/workerEntry";
|
|
22
|
-
import {
|
|
23
|
-
handleMeta,
|
|
24
|
-
handleDecofileRead,
|
|
25
|
-
handleDecofileReload,
|
|
26
|
-
handleRender,
|
|
27
|
-
corsHeaders,
|
|
28
|
-
} from "@decocms/start/admin";
|
|
29
|
-
// Only if using VTEX:
|
|
30
|
-
import { shouldProxyToVtex, proxyToVtex } from "@decocms/apps/vtex/utils/proxy";
|
|
31
|
-
|
|
32
|
-
const serverEntry = createServerEntry({
|
|
33
|
-
async fetch(request) {
|
|
34
|
-
return await handler.fetch(request);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export default createDecoWorkerEntry(serverEntry, {
|
|
39
|
-
admin: {
|
|
40
|
-
handleMeta,
|
|
41
|
-
handleDecofileRead,
|
|
42
|
-
handleDecofileReload,
|
|
43
|
-
handleRender,
|
|
44
|
-
corsHeaders,
|
|
45
|
-
},
|
|
46
|
-
// VTEX proxy — routes like /api/*, /checkout/*, /arquivos/* go to VTEX
|
|
47
|
-
proxyHandler: (request, url) => {
|
|
48
|
-
if (shouldProxyToVtex(url.pathname)) {
|
|
49
|
-
return proxyToVtex(request);
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Key Rules
|
|
57
|
-
|
|
58
|
-
1. **`import "./setup"` is ALWAYS the first line** — both files. This registers sections, loaders, blocks, and commerce config before any server function executes.
|
|
59
|
-
2. **Admin handlers go in `createDecoWorkerEntry`** — NOT inside `createServerEntry`. TanStack Start's build strips custom fetch logic from `createServerEntry` in production.
|
|
60
|
-
3. **Proxy handler** — Optional. Only needed for platforms (VTEX, Shopify) that require server-side proxying.
|
|
61
|
-
4. **Request flow**: `createDecoWorkerEntry` → admin routes (first) → cache check → proxy check → `serverEntry.fetch()` (TanStack Start).
|
|
62
|
-
|
|
63
|
-
## Why `import "./setup"` Must Be First
|
|
64
|
-
|
|
65
|
-
TanStack Start compiles `createServerFn()` calls into "split modules" — separate Vite module instances. Module-level state (blockData, commerceLoaders, sectionRegistry) initialized in `setup.ts` only exists in the original module instance. Without importing setup first, these split modules execute with empty state.
|
|
66
|
-
|
|
67
|
-
The fix in `@decocms/start` uses `globalThis.__deco` to share state across all module instances. But `setup.ts` must run BEFORE any server function is called — which means it must be imported before `createStartHandler` or `createServerEntry`.
|
/package/{.cursor → .agents}/skills/deco-to-tanstack-migration/references/server-functions/README.md
RENAMED
|
File without changes
|