@decocms/nextjs 7.4.0 → 7.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 +32 -8
- package/package.json +3 -3
- package/src/setup.ts +7 -4
package/README.md
CHANGED
|
@@ -110,15 +110,33 @@ they're safe to import from anywhere, including a route file.
|
|
|
110
110
|
|
|
111
111
|
## 3. `src/deco/setup.ts` — `createNextSetup`
|
|
112
112
|
|
|
113
|
+
The codegen artifacts (`sections.gen.ts`, `meta.gen.json`) are generated into
|
|
114
|
+
`.deco/` at the site root — the same default `@decocms/blocks-cli`'s
|
|
115
|
+
generators use everywhere else (framework artifacts live in the framework's
|
|
116
|
+
folder, not scattered across `src/`). `src/deco/setup.ts` isn't adjacent to
|
|
117
|
+
`.deco/`, so import it through a `deco/*` tsconfig path alias instead of a
|
|
118
|
+
relative path:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
// tsconfig.json
|
|
122
|
+
{
|
|
123
|
+
"compilerOptions": {
|
|
124
|
+
"paths": {
|
|
125
|
+
"deco/*": [".deco/*"]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
113
131
|
```ts
|
|
114
132
|
// src/deco/setup.ts
|
|
115
133
|
import { createNextSetup } from "@decocms/nextjs/setup";
|
|
116
|
-
import { sectionImports, sectionMeta, syncComponents, loadingFallbacks } from "
|
|
134
|
+
import { sectionImports, sectionMeta, syncComponents, loadingFallbacks } from "deco/sections.gen";
|
|
117
135
|
|
|
118
136
|
export const ensureSetup = createNextSetup({
|
|
119
137
|
sections: sectionImports,
|
|
120
138
|
conventions: { meta: sectionMeta, syncComponents, loadingFallbacks },
|
|
121
|
-
meta: () => import("
|
|
139
|
+
meta: () => import("deco/meta.gen.json").then((m) => m.default),
|
|
122
140
|
});
|
|
123
141
|
```
|
|
124
142
|
|
|
@@ -158,7 +176,7 @@ Two call sites need `ensureSetup()`:
|
|
|
158
176
|
| `blocks` | Extra/override blocks, merged **over** the directory's blocks. |
|
|
159
177
|
| `sections` | The lazy section registry — `sectionImports` from `generate-sections --registry` (see below). |
|
|
160
178
|
| `conventions` | `{ meta, syncComponents, loadingFallbacks }` from `sections.gen.ts` — wires the `export const sync/layout/seo/cache/eager/clientOnly` conventions (see below). |
|
|
161
|
-
| `meta` | Lazy admin meta schema loader: `() => import("
|
|
179
|
+
| `meta` | Lazy admin meta schema loader: `() => import("deco/meta.gen.json").then(m => m.default)`. Wire this even with a trivial schema — without it, `/deco/meta` (and its `/live/_meta` alias) 503s with `"Schema not initialized"`. |
|
|
162
180
|
| `renderShell` | Admin preview shell config (`{ css, fonts }`). |
|
|
163
181
|
| `previewWrapper` | Admin preview wrapper component. |
|
|
164
182
|
| `productionOrigins`, `customMatchers`, `onResolveError`, `onDanglingReference` | Passed through to `createSiteSetup`. |
|
|
@@ -174,23 +192,29 @@ depending on script-merge order. Use these names instead:
|
|
|
174
192
|
```json
|
|
175
193
|
{
|
|
176
194
|
"scripts": {
|
|
177
|
-
"generate:deco-meta": "tsx node_modules/@decocms/blocks-cli/scripts/generate-schema.ts
|
|
178
|
-
"generate:deco-sections": "tsx node_modules/@decocms/blocks-cli/scripts/generate-sections.ts --registry
|
|
195
|
+
"generate:deco-meta": "tsx node_modules/@decocms/blocks-cli/scripts/generate-schema.ts",
|
|
196
|
+
"generate:deco-sections": "tsx node_modules/@decocms/blocks-cli/scripts/generate-sections.ts --registry"
|
|
179
197
|
}
|
|
180
198
|
}
|
|
181
199
|
```
|
|
182
200
|
|
|
201
|
+
Neither script needs an `--out`/`--out-file` flag — both generators default
|
|
202
|
+
to `.deco/`, which is exactly where `src/deco/setup.ts` reads them from via
|
|
203
|
+
the `deco/*` path alias (see above). Only pass `--out`/`--out-file` if your
|
|
204
|
+
site has a reason to put the artifact somewhere else.
|
|
205
|
+
|
|
183
206
|
- `generate:deco-meta` runs `blocks-cli`'s `generate-schema.ts`, which scans
|
|
184
207
|
`src/sections/`, `src/loaders/`, and `src/apps/` for `Props` interfaces
|
|
185
|
-
and emits the JSON Schema the admin's `/deco/meta` endpoint serves
|
|
186
|
-
|
|
208
|
+
and emits the JSON Schema the admin's `/deco/meta` endpoint serves, to
|
|
209
|
+
`.deco/meta.gen.json` by default.
|
|
187
210
|
- `generate:deco-sections` runs `generate-sections.ts` **with `--registry`**
|
|
188
211
|
— the flag that additionally emits `sectionImports`, the Next.js/webpack
|
|
189
212
|
equivalent of Vite's `import.meta.glob("./sections/**/*.tsx")` (Next has
|
|
190
213
|
no `import.meta.glob` or Vite plugin, so this is generated instead of
|
|
191
214
|
computed at build time). Without `--registry` you only get
|
|
192
215
|
`sectionMeta`/`syncComponents`/`loadingFallbacks`, not the lazy loader map
|
|
193
|
-
`setup.ts` needs for its `sections` option.
|
|
216
|
+
`setup.ts` needs for its `sections` option. Defaults to
|
|
217
|
+
`.deco/sections.gen.ts`.
|
|
194
218
|
|
|
195
219
|
Run both any time `src/sections/` changes (wire into a `predev`/`prebuild`
|
|
196
220
|
step, or a watch script, as your site prefers).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/nextjs",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco framework binding for Next.js App Router",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"lint:unused": "knip"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@decocms/blocks": "7.
|
|
29
|
-
"@decocms/blocks-admin": "7.
|
|
28
|
+
"@decocms/blocks": "7.5.1",
|
|
29
|
+
"@decocms/blocks-admin": "7.5.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"next": ">=15.0.0",
|
package/src/setup.ts
CHANGED
|
@@ -15,12 +15,15 @@
|
|
|
15
15
|
* @example site's `src/deco/setup.ts`
|
|
16
16
|
* ```ts
|
|
17
17
|
* import { createNextSetup } from "@decocms/nextjs/setup";
|
|
18
|
-
*
|
|
18
|
+
* // Generators default to `.deco/`; `deco/*` is a tsconfig path alias for
|
|
19
|
+
* // `.deco/*` (see the package README) since `src/deco/setup.ts` isn't
|
|
20
|
+
* // adjacent to the site-root `.deco/` directory.
|
|
21
|
+
* import { sectionImports, sectionMeta, syncComponents } from "deco/sections.gen";
|
|
19
22
|
*
|
|
20
23
|
* export const ensureSetup = createNextSetup({
|
|
21
24
|
* sections: sectionImports,
|
|
22
25
|
* conventions: { meta: sectionMeta, syncComponents },
|
|
23
|
-
* meta: () => import("
|
|
26
|
+
* meta: () => import("deco/meta.gen.json").then((m) => m.default),
|
|
24
27
|
* });
|
|
25
28
|
* ```
|
|
26
29
|
*/
|
|
@@ -46,10 +49,10 @@ export interface NextSetupOptions {
|
|
|
46
49
|
*/
|
|
47
50
|
sections: Record<string, () => Promise<any>>;
|
|
48
51
|
|
|
49
|
-
/** `{ meta: sectionMeta, syncComponents, loadingFallbacks }` from sections.gen.ts. */
|
|
52
|
+
/** `{ meta: sectionMeta, syncComponents, loadingFallbacks }` from sections.gen.ts (`.deco/sections.gen.ts` by default). */
|
|
50
53
|
conventions?: Omit<ApplySectionConventionsInput, "sectionGlob">;
|
|
51
54
|
|
|
52
|
-
/** Lazy admin meta schema: `() => import("
|
|
55
|
+
/** Lazy admin meta schema: `() => import("deco/meta.gen.json").then(m => m.default)` (`.deco/meta.gen.json` by default). */
|
|
53
56
|
meta?: () => Promise<unknown>;
|
|
54
57
|
|
|
55
58
|
/** Admin preview shell (CSS/font URLs) — see blocks-admin setRenderShell. */
|