@decocms/blocks 8.2.1 → 8.2.2
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/dist/v8/cms.d.ts +14 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +36 -0
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/vite/hot.d.ts +8 -0
- package/dist/v8/vite/hot.d.ts.map +1 -0
- package/dist/v8/vite/hot.js +8 -0
- package/dist/v8/vite/hot.js.map +1 -0
- package/dist/v8/vite/index.d.ts +52 -0
- package/dist/v8/vite/index.d.ts.map +1 -0
- package/dist/v8/vite/index.js +136 -0
- package/dist/v8/vite/index.js.map +1 -0
- package/package.json +20 -3
- package/src/v8/cms.ts +36 -0
- package/src/v8/vite/hot.ts +7 -0
- package/src/v8/vite/index.ts +170 -0
package/dist/v8/cms.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CMS, CMSConfig } from "./types.ts";
|
|
1
|
+
import type { CMS, CMSConfig, Snapshot } from "./types.ts";
|
|
2
2
|
/** The shared instance behind a `createCMS` result; `undefined` for anything else. */
|
|
3
3
|
export declare function instanceOf(cms: CMS): object | undefined;
|
|
4
4
|
/**
|
|
@@ -7,6 +7,19 @@ export declare function instanceOf(cms: CMS): object | undefined;
|
|
|
7
7
|
* ask it for a client per request.
|
|
8
8
|
*/
|
|
9
9
|
export declare function createCMS(config: CMSConfig): CMS;
|
|
10
|
+
/**
|
|
11
|
+
* Hands a new content module to every CMS created for its `.deco` folder, as
|
|
12
|
+
* a later `createCMS` call with the same content would, but without the
|
|
13
|
+
* site's config: each instance keeps its own options (`site`, `dev`, …).
|
|
14
|
+
* Returns how many instances took it; none when no CMS has been created for
|
|
15
|
+
* that folder yet (the first `createCMS` call then reads the new module) or
|
|
16
|
+
* when the module has no `root` to match on.
|
|
17
|
+
*
|
|
18
|
+
* The dev server's content reload (`@decocms/blocks/vite`) calls it when
|
|
19
|
+
* Vite swaps `.deco/blocks.gen.ts`, so the module that created the CMS never
|
|
20
|
+
* runs again.
|
|
21
|
+
*/
|
|
22
|
+
export declare function adoptContent(content: Snapshot): number;
|
|
10
23
|
/** Clears every stored CMS instance, so a test starts clean. */
|
|
11
24
|
export declare function resetForTests(): void;
|
|
12
25
|
//# sourceMappingURL=cms.d.ts.map
|
package/dist/v8/cms.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../src/v8/cms.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAGV,GAAG,EACH,SAAS,
|
|
1
|
+
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../src/v8/cms.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAGV,GAAG,EACH,SAAS,EAIT,QAAQ,EACT,MAAM,YAAY,CAAC;AAqRpB,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAGvD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,GAAG,CAsBhD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,MAAM,CAsBtD;AAED,gEAAgE;AAChE,wBAAgB,aAAa,IAAI,IAAI,CAIpC"}
|
package/dist/v8/cms.js
CHANGED
|
@@ -289,6 +289,42 @@ export function createCMS(config) {
|
|
|
289
289
|
store[key] = instance;
|
|
290
290
|
return instance.handle(config.blocks);
|
|
291
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Hands a new content module to every CMS created for its `.deco` folder, as
|
|
294
|
+
* a later `createCMS` call with the same content would, but without the
|
|
295
|
+
* site's config: each instance keeps its own options (`site`, `dev`, …).
|
|
296
|
+
* Returns how many instances took it; none when no CMS has been created for
|
|
297
|
+
* that folder yet (the first `createCMS` call then reads the new module) or
|
|
298
|
+
* when the module has no `root` to match on.
|
|
299
|
+
*
|
|
300
|
+
* The dev server's content reload (`@decocms/blocks/vite`) calls it when
|
|
301
|
+
* Vite swaps `.deco/blocks.gen.ts`, so the module that created the CMS never
|
|
302
|
+
* runs again.
|
|
303
|
+
*/
|
|
304
|
+
export function adoptContent(content) {
|
|
305
|
+
if (!isSnapshot(content))
|
|
306
|
+
return 0;
|
|
307
|
+
const identity = contentIdentity(content);
|
|
308
|
+
if (!identity.startsWith("module:"))
|
|
309
|
+
return 0;
|
|
310
|
+
const own = INSTANCE_PREFIX + identity;
|
|
311
|
+
const store = globalThis;
|
|
312
|
+
let adopted = 0;
|
|
313
|
+
for (const symbol of Object.getOwnPropertySymbols(globalThis)) {
|
|
314
|
+
const key = Symbol.keyFor(symbol);
|
|
315
|
+
if (key === undefined || (key !== own && !key.startsWith(`${own}|site:`)))
|
|
316
|
+
continue;
|
|
317
|
+
const instance = store[symbol];
|
|
318
|
+
if (!(instance instanceof Object) ||
|
|
319
|
+
typeof instance.adopt !== "function" ||
|
|
320
|
+
!isPlainObject(instance.config)) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
instance.adopt({ ...instance.config, content });
|
|
324
|
+
adopted++;
|
|
325
|
+
}
|
|
326
|
+
return adopted;
|
|
327
|
+
}
|
|
292
328
|
/** Clears every stored CMS instance, so a test starts clean. */
|
|
293
329
|
export function resetForTests() {
|
|
294
330
|
clearGlobals(INSTANCE_PREFIX);
|
package/dist/v8/cms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms.js","sourceRoot":"","sources":["../../src/v8/cms.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,E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;KAC/C,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAkB,EAAE,IAAiB;IAC3D,MAAM,SAAS,GAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAA2B,CAAC,MAAM,CACpE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CACrC,CAAC;IACF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACnC,OAAO,CAAC,IAAI,CACV,0FAA0F;QACxF,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,0CAA0C,CACrE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACxE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,KAAgC,CAAC;QAChD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aAC3B,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;aACjE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/vite/hot`: the runtime half of the dev server's content
|
|
3
|
+
* reload. In `vite dev`, the `decoContent()` Vite plugin
|
|
4
|
+
* (`@decocms/blocks/vite`) appends a call to it to each module that imports
|
|
5
|
+
* `.deco/blocks.gen.ts`; a site never imports it.
|
|
6
|
+
*/
|
|
7
|
+
export { adoptContent } from "../cms.ts";
|
|
8
|
+
//# sourceMappingURL=hot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hot.d.ts","sourceRoot":"","sources":["../../../src/v8/vite/hot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/vite/hot`: the runtime half of the dev server's content
|
|
3
|
+
* reload. In `vite dev`, the `decoContent()` Vite plugin
|
|
4
|
+
* (`@decocms/blocks/vite`) appends a call to it to each module that imports
|
|
5
|
+
* `.deco/blocks.gen.ts`; a site never imports it.
|
|
6
|
+
*/
|
|
7
|
+
export { adoptContent } from "../cms.js";
|
|
8
|
+
//# sourceMappingURL=hot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hot.js","sourceRoot":"","sources":["../../../src/v8/vite/hot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/vite`: `decoContent()`, the Vite plugin that shows a saved
|
|
3
|
+
* block in open pages during `vite dev`. Vite sites add it to
|
|
4
|
+
* `vite.config.ts`; Next.js sites don't use it.
|
|
5
|
+
*
|
|
6
|
+
* `deco serve` (the site editor's local server) rewrites
|
|
7
|
+
* `.deco/blocks.gen.ts` on every save. In `vite dev`, in the server
|
|
8
|
+
* environments, the plugin makes each module that imports it (usually
|
|
9
|
+
* `src/cms.ts`) accept that import's updates: the new content goes into the
|
|
10
|
+
* CMS already created for its `.deco` folder (`adoptContent`), and only then
|
|
11
|
+
* does the server tell open pages to reload. The importer is the update's
|
|
12
|
+
* boundary, so neither it nor anything that imports it is invalidated or runs
|
|
13
|
+
* again: TanStack Start re-imports its server entry on every request, and a
|
|
14
|
+
* content module that accepted itself still left every module above it stale,
|
|
15
|
+
* so `src/cms.ts` re-ran on every save. Reloading on the file change itself is
|
|
16
|
+
* too early: the page would render the previous save.
|
|
17
|
+
*
|
|
18
|
+
* A module that already accepts the content module's updates itself (the
|
|
19
|
+
* template code sites carried before this plugin) is left as it is.
|
|
20
|
+
*
|
|
21
|
+
* The files on disk are unchanged; `vite build` doesn't use the plugin. It
|
|
22
|
+
* needs Vite 6 or newer (the Environment API) and works with
|
|
23
|
+
* `@cloudflare/vite-plugin` (whatever its worker environment is named) and
|
|
24
|
+
* with plain SSR environments.
|
|
25
|
+
*/
|
|
26
|
+
import type { Plugin } from "vite";
|
|
27
|
+
/** The event an importer of the content module sends from a server environment once the CMS has its new content. */
|
|
28
|
+
export declare const CONTENT_UPDATED_EVENT = "decocms:content-updated";
|
|
29
|
+
/** Whether a module id (possibly with a query) is a site's `.deco/blocks.gen.ts`. */
|
|
30
|
+
export declare function isContentModule(id: string): boolean;
|
|
31
|
+
/** The specifiers of a module's static imports and re-exports, in order, without duplicates. */
|
|
32
|
+
export declare function staticImports(code: string): string[];
|
|
33
|
+
/** The dependency specifiers a module passes to `import.meta.hot.accept`. */
|
|
34
|
+
export declare function acceptedSpecifiers(code: string): string[];
|
|
35
|
+
/**
|
|
36
|
+
* What the plugin appends to a module that imports the content module (as
|
|
37
|
+
* `specifier`) in a server environment: accept that import's next version,
|
|
38
|
+
* hand it to the CMS, then announce it. The same code sites used to write in
|
|
39
|
+
* `src/cms.ts` by hand.
|
|
40
|
+
*/
|
|
41
|
+
export declare function importerFooter(specifier: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* The Vite plugin: in `vite dev`, open pages show a saved block once the
|
|
44
|
+
* server has it. Add it to `plugins` in `vite.config.ts`:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { decoContent } from "@decocms/blocks/vite";
|
|
48
|
+
* export default defineConfig({ plugins: [decoContent(), ...] });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function decoContent(): Plugin;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/v8/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,oHAAoH;AACpH,eAAO,MAAM,qBAAqB,4BAA4B,CAAC;AAwB/D,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAInD;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAIpD;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQzD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAaxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,IAAI,MAAM,CA8DpC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/** The event an importer of the content module sends from a server environment once the CMS has its new content. */
|
|
2
|
+
export const CONTENT_UPDATED_EVENT = "decocms:content-updated";
|
|
3
|
+
/** How long the plugin waits for another update of the same save before reloading open pages. */
|
|
4
|
+
const RELOAD_DELAY_MS = 100;
|
|
5
|
+
/** The module the footer imports `adoptContent` from. */
|
|
6
|
+
const HOT_MODULE = "@decocms/blocks/vite/hot";
|
|
7
|
+
/** The content module `deco content` writes, wherever the `.deco` folder is. */
|
|
8
|
+
const CONTENT_MODULE = /(?:^|[\\/])\.deco[\\/]blocks\.gen\.ts$/;
|
|
9
|
+
/** Source files whose imports the plugin reads. */
|
|
10
|
+
const SOURCE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
11
|
+
/** Static imports and re-exports: `import x from "s"`, `import "s"`, `export { x } from "s"`. */
|
|
12
|
+
const STATIC_IMPORT = /(?:^|[^\w$.])(?:import|export)(?:\s+type)?\s*(?:[\w$*{}\s,]*?\s*from\s*)?(["'])([^"'\r\n]+)\1/g;
|
|
13
|
+
/** `….accept("s", …)` or `….accept(["s", …], …)`: a module accepting a dependency's updates. */
|
|
14
|
+
const ACCEPT_CALL = /\.accept\s*\(\s*(\[[^\]]*\]|(["'`])[^"'`\r\n]+\2)/g;
|
|
15
|
+
/** Specifiers that never name a file of the site. */
|
|
16
|
+
const EXTERNAL = /^(?:node:|virtual:|\0|data:|https?:|cloudflare:)/;
|
|
17
|
+
/** Whether a module id (possibly with a query) is a site's `.deco/blocks.gen.ts`. */
|
|
18
|
+
export function isContentModule(id) {
|
|
19
|
+
const file = id.split("?", 1)[0] ?? id;
|
|
20
|
+
if (/[\\/]node_modules[\\/]/.test(file))
|
|
21
|
+
return false;
|
|
22
|
+
return CONTENT_MODULE.test(file);
|
|
23
|
+
}
|
|
24
|
+
/** The specifiers of a module's static imports and re-exports, in order, without duplicates. */
|
|
25
|
+
export function staticImports(code) {
|
|
26
|
+
const found = new Set();
|
|
27
|
+
for (const match of code.matchAll(STATIC_IMPORT))
|
|
28
|
+
found.add(match[2]);
|
|
29
|
+
return [...found];
|
|
30
|
+
}
|
|
31
|
+
/** The dependency specifiers a module passes to `import.meta.hot.accept`. */
|
|
32
|
+
export function acceptedSpecifiers(code) {
|
|
33
|
+
const found = new Set();
|
|
34
|
+
for (const match of code.matchAll(ACCEPT_CALL)) {
|
|
35
|
+
for (const literal of match[1].matchAll(/(["'`])([^"'`\r\n]+)\1/g)) {
|
|
36
|
+
found.add(literal[2]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [...found];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What the plugin appends to a module that imports the content module (as
|
|
43
|
+
* `specifier`) in a server environment: accept that import's next version,
|
|
44
|
+
* hand it to the CMS, then announce it. The same code sites used to write in
|
|
45
|
+
* `src/cms.ts` by hand.
|
|
46
|
+
*/
|
|
47
|
+
export function importerFooter(specifier) {
|
|
48
|
+
return [
|
|
49
|
+
"",
|
|
50
|
+
"// Added by decoContent() (@decocms/blocks/vite) in vite dev only.",
|
|
51
|
+
`import { adoptContent as __decoAdoptContent } from ${JSON.stringify(HOT_MODULE)};`,
|
|
52
|
+
"if (import.meta.hot) {",
|
|
53
|
+
` import.meta.hot.accept(${JSON.stringify(specifier)}, (next) => {`,
|
|
54
|
+
" if (next) __decoAdoptContent(next.default);",
|
|
55
|
+
` import.meta.hot?.send(${JSON.stringify(CONTENT_UPDATED_EVENT)});`,
|
|
56
|
+
" });",
|
|
57
|
+
"}",
|
|
58
|
+
"",
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The Vite plugin: in `vite dev`, open pages show a saved block once the
|
|
63
|
+
* server has it. Add it to `plugins` in `vite.config.ts`:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { decoContent } from "@decocms/blocks/vite";
|
|
67
|
+
* export default defineConfig({ plugins: [decoContent(), ...] });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function decoContent() {
|
|
71
|
+
return {
|
|
72
|
+
name: "decocms:content",
|
|
73
|
+
apply: "serve",
|
|
74
|
+
configEnvironment(name, config) {
|
|
75
|
+
// The footer's import appears only after this transform, so the dependency
|
|
76
|
+
// scan can't see it: pre-bundle it up front in the server environments.
|
|
77
|
+
// Discovered on the first request instead, the worker re-optimizes its
|
|
78
|
+
// dependencies and reloads the whole program once.
|
|
79
|
+
if (name === "client" || config.consumer === "client")
|
|
80
|
+
return;
|
|
81
|
+
return { optimizeDeps: { include: [HOT_MODULE] } };
|
|
82
|
+
},
|
|
83
|
+
async transform(code, id, options) {
|
|
84
|
+
const file = id.split("?", 1)[0] ?? id;
|
|
85
|
+
if (id.startsWith("\0") || !SOURCE_FILE.test(file) || /[\\/]node_modules[\\/]/.test(file)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (isContentModule(id))
|
|
89
|
+
return null;
|
|
90
|
+
const consumer = this.environment?.config.consumer;
|
|
91
|
+
const server = consumer === undefined ? options?.ssr === true : consumer === "server";
|
|
92
|
+
if (!server)
|
|
93
|
+
return null;
|
|
94
|
+
const imports = staticImports(code).filter((specifier) => !EXTERNAL.test(specifier));
|
|
95
|
+
if (imports.length === 0)
|
|
96
|
+
return null;
|
|
97
|
+
const isContent = async (specifier) => {
|
|
98
|
+
const resolved = await this.resolve(specifier, id);
|
|
99
|
+
return resolved !== null && !resolved.external && isContentModule(resolved.id);
|
|
100
|
+
};
|
|
101
|
+
let content;
|
|
102
|
+
for (const specifier of imports) {
|
|
103
|
+
if (await isContent(specifier)) {
|
|
104
|
+
content = specifier;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (content === undefined)
|
|
109
|
+
return null;
|
|
110
|
+
// A site that still accepts the content module's updates by hand keeps its own code.
|
|
111
|
+
for (const specifier of acceptedSpecifiers(code)) {
|
|
112
|
+
if (await isContent(specifier))
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
// Appended, so no line moves and the incoming source map still holds.
|
|
116
|
+
return { code: code + importerFooter(content), map: null };
|
|
117
|
+
},
|
|
118
|
+
configureServer(server) {
|
|
119
|
+
// A save writes the block's JSON file and then the content module, and
|
|
120
|
+
// each one swaps the module: open pages reload once, after the last.
|
|
121
|
+
let timer;
|
|
122
|
+
const reload = () => {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
timer = setTimeout(() => {
|
|
125
|
+
const client = server.environments?.client?.hot ?? server.hot;
|
|
126
|
+
client.send({ type: "full-reload" });
|
|
127
|
+
}, RELOAD_DELAY_MS);
|
|
128
|
+
};
|
|
129
|
+
const environments = Object.values(server.environments ?? {}).filter((environment) => environment.config.consumer === "server");
|
|
130
|
+
for (const environment of environments) {
|
|
131
|
+
environment.hot.on(CONTENT_UPDATED_EVENT, reload);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v8/vite/index.ts"],"names":[],"mappings":"AA2BA,oHAAoH;AACpH,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAE/D,iGAAiG;AACjG,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,yDAAyD;AACzD,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,gFAAgF;AAChF,MAAM,cAAc,GAAG,wCAAwC,CAAC;AAEhE,mDAAmD;AACnD,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,iGAAiG;AACjG,MAAM,aAAa,GACjB,gGAAgG,CAAC;AAEnG,gGAAgG;AAChG,MAAM,WAAW,GAAG,oDAAoD,CAAC;AAEzE,qDAAqD;AACrD,MAAM,QAAQ,GAAG,kDAAkD,CAAC;AAEpE,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,EAAU;IACxC,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvC,IAAI,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,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,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -53,6 +53,16 @@
|
|
|
53
53
|
"source": "./src/v8/secrets.ts",
|
|
54
54
|
"default": "./dist/v8/secrets.js"
|
|
55
55
|
},
|
|
56
|
+
"./vite": {
|
|
57
|
+
"types": "./dist/v8/vite/index.d.ts",
|
|
58
|
+
"source": "./src/v8/vite/index.ts",
|
|
59
|
+
"default": "./dist/v8/vite/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./vite/hot": {
|
|
62
|
+
"types": "./dist/v8/vite/hot.d.ts",
|
|
63
|
+
"source": "./src/v8/vite/hot.ts",
|
|
64
|
+
"default": "./dist/v8/vite/hot.js"
|
|
65
|
+
},
|
|
56
66
|
"./protocol": {
|
|
57
67
|
"types": "./dist/protocol/index.d.ts",
|
|
58
68
|
"source": "./src/protocol/index.ts",
|
|
@@ -98,14 +108,21 @@
|
|
|
98
108
|
},
|
|
99
109
|
"peerDependencies": {
|
|
100
110
|
"react": "^19.0.0",
|
|
101
|
-
"typescript": "^5.0.0"
|
|
111
|
+
"typescript": "^5.0.0",
|
|
112
|
+
"vite": ">=6.0.0"
|
|
113
|
+
},
|
|
114
|
+
"peerDependenciesMeta": {
|
|
115
|
+
"vite": {
|
|
116
|
+
"optional": true
|
|
117
|
+
}
|
|
102
118
|
},
|
|
103
119
|
"devDependencies": {
|
|
104
120
|
"@opentelemetry/api": "^1.9.1",
|
|
105
121
|
"@types/react": "^19.0.0",
|
|
106
122
|
"@types/react-dom": "^19.0.0",
|
|
107
123
|
"esbuild": "^0.27.3",
|
|
108
|
-
"react-dom": "^19.0.0"
|
|
124
|
+
"react-dom": "^19.0.0",
|
|
125
|
+
"vite": "^8.0.1"
|
|
109
126
|
},
|
|
110
127
|
"publishConfig": {
|
|
111
128
|
"registry": "https://registry.npmjs.org",
|
package/src/v8/cms.ts
CHANGED
|
@@ -352,6 +352,42 @@ export function createCMS(config: CMSConfig): CMS {
|
|
|
352
352
|
return instance.handle(config.blocks);
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Hands a new content module to every CMS created for its `.deco` folder, as
|
|
357
|
+
* a later `createCMS` call with the same content would, but without the
|
|
358
|
+
* site's config: each instance keeps its own options (`site`, `dev`, …).
|
|
359
|
+
* Returns how many instances took it; none when no CMS has been created for
|
|
360
|
+
* that folder yet (the first `createCMS` call then reads the new module) or
|
|
361
|
+
* when the module has no `root` to match on.
|
|
362
|
+
*
|
|
363
|
+
* The dev server's content reload (`@decocms/blocks/vite`) calls it when
|
|
364
|
+
* Vite swaps `.deco/blocks.gen.ts`, so the module that created the CMS never
|
|
365
|
+
* runs again.
|
|
366
|
+
*/
|
|
367
|
+
export function adoptContent(content: Snapshot): number {
|
|
368
|
+
if (!isSnapshot(content)) return 0;
|
|
369
|
+
const identity = contentIdentity(content);
|
|
370
|
+
if (!identity.startsWith("module:")) return 0;
|
|
371
|
+
const own = INSTANCE_PREFIX + identity;
|
|
372
|
+
const store = globalThis as unknown as Record<symbol, unknown>;
|
|
373
|
+
let adopted = 0;
|
|
374
|
+
for (const symbol of Object.getOwnPropertySymbols(globalThis)) {
|
|
375
|
+
const key = Symbol.keyFor(symbol);
|
|
376
|
+
if (key === undefined || (key !== own && !key.startsWith(`${own}|site:`))) continue;
|
|
377
|
+
const instance = store[symbol] as Partial<CMSInstance> | undefined;
|
|
378
|
+
if (
|
|
379
|
+
!(instance instanceof Object) ||
|
|
380
|
+
typeof instance.adopt !== "function" ||
|
|
381
|
+
!isPlainObject(instance.config)
|
|
382
|
+
) {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
instance.adopt({ ...instance.config, content } as CMSConfig);
|
|
386
|
+
adopted++;
|
|
387
|
+
}
|
|
388
|
+
return adopted;
|
|
389
|
+
}
|
|
390
|
+
|
|
355
391
|
/** Clears every stored CMS instance, so a test starts clean. */
|
|
356
392
|
export function resetForTests(): void {
|
|
357
393
|
clearGlobals(INSTANCE_PREFIX);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/vite/hot`: the runtime half of the dev server's content
|
|
3
|
+
* reload. In `vite dev`, the `decoContent()` Vite plugin
|
|
4
|
+
* (`@decocms/blocks/vite`) appends a call to it to each module that imports
|
|
5
|
+
* `.deco/blocks.gen.ts`; a site never imports it.
|
|
6
|
+
*/
|
|
7
|
+
export { adoptContent } from "../cms.ts";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/vite`: `decoContent()`, the Vite plugin that shows a saved
|
|
3
|
+
* block in open pages during `vite dev`. Vite sites add it to
|
|
4
|
+
* `vite.config.ts`; Next.js sites don't use it.
|
|
5
|
+
*
|
|
6
|
+
* `deco serve` (the site editor's local server) rewrites
|
|
7
|
+
* `.deco/blocks.gen.ts` on every save. In `vite dev`, in the server
|
|
8
|
+
* environments, the plugin makes each module that imports it (usually
|
|
9
|
+
* `src/cms.ts`) accept that import's updates: the new content goes into the
|
|
10
|
+
* CMS already created for its `.deco` folder (`adoptContent`), and only then
|
|
11
|
+
* does the server tell open pages to reload. The importer is the update's
|
|
12
|
+
* boundary, so neither it nor anything that imports it is invalidated or runs
|
|
13
|
+
* again: TanStack Start re-imports its server entry on every request, and a
|
|
14
|
+
* content module that accepted itself still left every module above it stale,
|
|
15
|
+
* so `src/cms.ts` re-ran on every save. Reloading on the file change itself is
|
|
16
|
+
* too early: the page would render the previous save.
|
|
17
|
+
*
|
|
18
|
+
* A module that already accepts the content module's updates itself (the
|
|
19
|
+
* template code sites carried before this plugin) is left as it is.
|
|
20
|
+
*
|
|
21
|
+
* The files on disk are unchanged; `vite build` doesn't use the plugin. It
|
|
22
|
+
* needs Vite 6 or newer (the Environment API) and works with
|
|
23
|
+
* `@cloudflare/vite-plugin` (whatever its worker environment is named) and
|
|
24
|
+
* with plain SSR environments.
|
|
25
|
+
*/
|
|
26
|
+
import type { Plugin } from "vite";
|
|
27
|
+
|
|
28
|
+
/** The event an importer of the content module sends from a server environment once the CMS has its new content. */
|
|
29
|
+
export const CONTENT_UPDATED_EVENT = "decocms:content-updated";
|
|
30
|
+
|
|
31
|
+
/** How long the plugin waits for another update of the same save before reloading open pages. */
|
|
32
|
+
const RELOAD_DELAY_MS = 100;
|
|
33
|
+
|
|
34
|
+
/** The module the footer imports `adoptContent` from. */
|
|
35
|
+
const HOT_MODULE = "@decocms/blocks/vite/hot";
|
|
36
|
+
|
|
37
|
+
/** The content module `deco content` writes, wherever the `.deco` folder is. */
|
|
38
|
+
const CONTENT_MODULE = /(?:^|[\\/])\.deco[\\/]blocks\.gen\.ts$/;
|
|
39
|
+
|
|
40
|
+
/** Source files whose imports the plugin reads. */
|
|
41
|
+
const SOURCE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
42
|
+
|
|
43
|
+
/** Static imports and re-exports: `import x from "s"`, `import "s"`, `export { x } from "s"`. */
|
|
44
|
+
const STATIC_IMPORT =
|
|
45
|
+
/(?:^|[^\w$.])(?:import|export)(?:\s+type)?\s*(?:[\w$*{}\s,]*?\s*from\s*)?(["'])([^"'\r\n]+)\1/g;
|
|
46
|
+
|
|
47
|
+
/** `….accept("s", …)` or `….accept(["s", …], …)`: a module accepting a dependency's updates. */
|
|
48
|
+
const ACCEPT_CALL = /\.accept\s*\(\s*(\[[^\]]*\]|(["'`])[^"'`\r\n]+\2)/g;
|
|
49
|
+
|
|
50
|
+
/** Specifiers that never name a file of the site. */
|
|
51
|
+
const EXTERNAL = /^(?:node:|virtual:|\0|data:|https?:|cloudflare:)/;
|
|
52
|
+
|
|
53
|
+
/** Whether a module id (possibly with a query) is a site's `.deco/blocks.gen.ts`. */
|
|
54
|
+
export function isContentModule(id: string): boolean {
|
|
55
|
+
const file = id.split("?", 1)[0] ?? id;
|
|
56
|
+
if (/[\\/]node_modules[\\/]/.test(file)) return false;
|
|
57
|
+
return CONTENT_MODULE.test(file);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The specifiers of a module's static imports and re-exports, in order, without duplicates. */
|
|
61
|
+
export function staticImports(code: string): string[] {
|
|
62
|
+
const found = new Set<string>();
|
|
63
|
+
for (const match of code.matchAll(STATIC_IMPORT)) found.add(match[2] as string);
|
|
64
|
+
return [...found];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The dependency specifiers a module passes to `import.meta.hot.accept`. */
|
|
68
|
+
export function acceptedSpecifiers(code: string): string[] {
|
|
69
|
+
const found = new Set<string>();
|
|
70
|
+
for (const match of code.matchAll(ACCEPT_CALL)) {
|
|
71
|
+
for (const literal of (match[1] as string).matchAll(/(["'`])([^"'`\r\n]+)\1/g)) {
|
|
72
|
+
found.add(literal[2] as string);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [...found];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* What the plugin appends to a module that imports the content module (as
|
|
80
|
+
* `specifier`) in a server environment: accept that import's next version,
|
|
81
|
+
* hand it to the CMS, then announce it. The same code sites used to write in
|
|
82
|
+
* `src/cms.ts` by hand.
|
|
83
|
+
*/
|
|
84
|
+
export function importerFooter(specifier: string): string {
|
|
85
|
+
return [
|
|
86
|
+
"",
|
|
87
|
+
"// Added by decoContent() (@decocms/blocks/vite) in vite dev only.",
|
|
88
|
+
`import { adoptContent as __decoAdoptContent } from ${JSON.stringify(HOT_MODULE)};`,
|
|
89
|
+
"if (import.meta.hot) {",
|
|
90
|
+
` import.meta.hot.accept(${JSON.stringify(specifier)}, (next) => {`,
|
|
91
|
+
" if (next) __decoAdoptContent(next.default);",
|
|
92
|
+
` import.meta.hot?.send(${JSON.stringify(CONTENT_UPDATED_EVENT)});`,
|
|
93
|
+
" });",
|
|
94
|
+
"}",
|
|
95
|
+
"",
|
|
96
|
+
].join("\n");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The Vite plugin: in `vite dev`, open pages show a saved block once the
|
|
101
|
+
* server has it. Add it to `plugins` in `vite.config.ts`:
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { decoContent } from "@decocms/blocks/vite";
|
|
105
|
+
* export default defineConfig({ plugins: [decoContent(), ...] });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function decoContent(): Plugin {
|
|
109
|
+
return {
|
|
110
|
+
name: "decocms:content",
|
|
111
|
+
apply: "serve",
|
|
112
|
+
configEnvironment(name, config) {
|
|
113
|
+
// The footer's import appears only after this transform, so the dependency
|
|
114
|
+
// scan can't see it: pre-bundle it up front in the server environments.
|
|
115
|
+
// Discovered on the first request instead, the worker re-optimizes its
|
|
116
|
+
// dependencies and reloads the whole program once.
|
|
117
|
+
if (name === "client" || config.consumer === "client") return;
|
|
118
|
+
return { optimizeDeps: { include: [HOT_MODULE] } };
|
|
119
|
+
},
|
|
120
|
+
async transform(code, id, options) {
|
|
121
|
+
const file = id.split("?", 1)[0] ?? id;
|
|
122
|
+
if (id.startsWith("\0") || !SOURCE_FILE.test(file) || /[\\/]node_modules[\\/]/.test(file)) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
if (isContentModule(id)) return null;
|
|
126
|
+
const consumer = this.environment?.config.consumer;
|
|
127
|
+
const server = consumer === undefined ? options?.ssr === true : consumer === "server";
|
|
128
|
+
if (!server) return null;
|
|
129
|
+
|
|
130
|
+
const imports = staticImports(code).filter((specifier) => !EXTERNAL.test(specifier));
|
|
131
|
+
if (imports.length === 0) return null;
|
|
132
|
+
const isContent = async (specifier: string) => {
|
|
133
|
+
const resolved = await this.resolve(specifier, id);
|
|
134
|
+
return resolved !== null && !resolved.external && isContentModule(resolved.id);
|
|
135
|
+
};
|
|
136
|
+
let content: string | undefined;
|
|
137
|
+
for (const specifier of imports) {
|
|
138
|
+
if (await isContent(specifier)) {
|
|
139
|
+
content = specifier;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (content === undefined) return null;
|
|
144
|
+
// A site that still accepts the content module's updates by hand keeps its own code.
|
|
145
|
+
for (const specifier of acceptedSpecifiers(code)) {
|
|
146
|
+
if (await isContent(specifier)) return null;
|
|
147
|
+
}
|
|
148
|
+
// Appended, so no line moves and the incoming source map still holds.
|
|
149
|
+
return { code: code + importerFooter(content), map: null };
|
|
150
|
+
},
|
|
151
|
+
configureServer(server) {
|
|
152
|
+
// A save writes the block's JSON file and then the content module, and
|
|
153
|
+
// each one swaps the module: open pages reload once, after the last.
|
|
154
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
155
|
+
const reload = () => {
|
|
156
|
+
clearTimeout(timer);
|
|
157
|
+
timer = setTimeout(() => {
|
|
158
|
+
const client = server.environments?.client?.hot ?? server.hot;
|
|
159
|
+
client.send({ type: "full-reload" });
|
|
160
|
+
}, RELOAD_DELAY_MS);
|
|
161
|
+
};
|
|
162
|
+
const environments = Object.values(server.environments ?? {}).filter(
|
|
163
|
+
(environment) => environment.config.consumer === "server",
|
|
164
|
+
);
|
|
165
|
+
for (const environment of environments) {
|
|
166
|
+
environment.hot.on(CONTENT_UPDATED_EVENT, reload);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|