@conloca/cloud-astro 0.0.0-stage → 0.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/README.md +328 -2
- package/dist/src/build-commit.d.ts +19 -0
- package/dist/src/build-commit.d.ts.map +1 -0
- package/dist/src/build-commit.js +6 -0
- package/dist/src/build-commit.js.map +1 -0
- package/dist/src/bundle.d.ts +181 -0
- package/dist/src/bundle.d.ts.map +1 -0
- package/dist/src/bundle.js +413 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/component-manifest.d.ts +29 -0
- package/dist/src/component-manifest.d.ts.map +1 -0
- package/dist/src/component-manifest.js +53 -0
- package/dist/src/component-manifest.js.map +1 -0
- package/dist/src/constants.d.ts +26 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +26 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/descriptors.d.ts +25 -0
- package/dist/src/descriptors.d.ts.map +1 -0
- package/dist/src/descriptors.js +65 -0
- package/dist/src/descriptors.js.map +1 -0
- package/dist/src/discovery.d.ts +58 -0
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +133 -0
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts +15 -0
- package/dist/src/doctor/checks-live.d.ts.map +1 -0
- package/dist/src/doctor/checks-live.js +229 -0
- package/dist/src/doctor/checks-live.js.map +1 -0
- package/dist/src/doctor/checks-offline.d.ts +36 -0
- package/dist/src/doctor/checks-offline.d.ts.map +1 -0
- package/dist/src/doctor/checks-offline.js +301 -0
- package/dist/src/doctor/checks-offline.js.map +1 -0
- package/dist/src/doctor/config-scan.d.ts +55 -0
- package/dist/src/doctor/config-scan.d.ts.map +1 -0
- package/dist/src/doctor/config-scan.js +178 -0
- package/dist/src/doctor/config-scan.js.map +1 -0
- package/dist/src/doctor/run.d.ts +4 -0
- package/dist/src/doctor/run.d.ts.map +1 -0
- package/dist/src/doctor/run.js +29 -0
- package/dist/src/doctor/run.js.map +1 -0
- package/dist/src/doctor/types.d.ts +60 -0
- package/dist/src/doctor/types.d.ts.map +1 -0
- package/dist/src/doctor/types.js +18 -0
- package/dist/src/doctor/types.js.map +1 -0
- package/dist/src/doctor.d.ts +9 -0
- package/dist/src/doctor.d.ts.map +1 -0
- package/dist/src/doctor.js +12 -0
- package/dist/src/doctor.js.map +1 -0
- package/dist/src/git.d.ts +38 -0
- package/dist/src/git.d.ts.map +1 -0
- package/dist/src/git.js +43 -0
- package/dist/src/git.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/integration.d.ts +6 -0
- package/dist/src/integration.d.ts.map +1 -0
- package/dist/src/integration.js +544 -0
- package/dist/src/integration.js.map +1 -0
- package/dist/src/message-of.d.ts +3 -0
- package/dist/src/message-of.d.ts.map +1 -0
- package/dist/src/message-of.js +5 -0
- package/dist/src/message-of.js.map +1 -0
- package/dist/src/node.d.ts +3 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/node.js +4 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/package-version.d.ts +7 -0
- package/dist/src/package-version.d.ts.map +1 -0
- package/dist/src/package-version.js +17 -0
- package/dist/src/package-version.js.map +1 -0
- package/dist/src/preview/_dispatch.d.ts +55 -0
- package/dist/src/preview/_dispatch.d.ts.map +1 -0
- package/dist/src/preview/_dispatch.js +72 -0
- package/dist/src/preview/_dispatch.js.map +1 -0
- package/dist/src/preview/_resolve-opts.d.ts +30 -0
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -0
- package/dist/src/preview/_resolve-opts.js +73 -0
- package/dist/src/preview/_resolve-opts.js.map +1 -0
- package/dist/src/preview/banner.d.ts +29 -0
- package/dist/src/preview/banner.d.ts.map +1 -0
- package/dist/src/preview/banner.js +94 -0
- package/dist/src/preview/banner.js.map +1 -0
- package/dist/src/preview/content-api.d.ts +110 -0
- package/dist/src/preview/content-api.d.ts.map +1 -0
- package/dist/src/preview/content-api.js +216 -0
- package/dist/src/preview/content-api.js.map +1 -0
- package/dist/src/preview/cookie.d.ts +36 -0
- package/dist/src/preview/cookie.d.ts.map +1 -0
- package/dist/src/preview/cookie.js +59 -0
- package/dist/src/preview/cookie.js.map +1 -0
- package/dist/src/preview/headers.d.ts +25 -0
- package/dist/src/preview/headers.d.ts.map +1 -0
- package/dist/src/preview/headers.js +31 -0
- package/dist/src/preview/headers.js.map +1 -0
- package/dist/src/preview/landing.d.ts +22 -0
- package/dist/src/preview/landing.d.ts.map +1 -0
- package/dist/src/preview/landing.js +70 -0
- package/dist/src/preview/landing.js.map +1 -0
- package/dist/src/preview/middleware.d.ts +118 -0
- package/dist/src/preview/middleware.d.ts.map +1 -0
- package/dist/src/preview/middleware.js +197 -0
- package/dist/src/preview/middleware.js.map +1 -0
- package/dist/src/preview/preview-path.d.ts +21 -0
- package/dist/src/preview/preview-path.d.ts.map +1 -0
- package/dist/src/preview/preview-path.js +29 -0
- package/dist/src/preview/preview-path.js.map +1 -0
- package/dist/src/preview/satteri-workerd.d.ts +17 -0
- package/dist/src/preview/satteri-workerd.d.ts.map +1 -0
- package/dist/src/preview/satteri-workerd.js +18 -0
- package/dist/src/preview/satteri-workerd.js.map +1 -0
- package/dist/src/preview/site-middleware.d.ts +69 -0
- package/dist/src/preview/site-middleware.d.ts.map +1 -0
- package/dist/src/preview/site-middleware.js +160 -0
- package/dist/src/preview/site-middleware.js.map +1 -0
- package/dist/src/preview/workerd-shim.d.ts +19 -0
- package/dist/src/preview/workerd-shim.d.ts.map +1 -0
- package/dist/src/preview/workerd-shim.js +33 -0
- package/dist/src/preview/workerd-shim.js.map +1 -0
- package/dist/src/preview-build.d.ts +71 -0
- package/dist/src/preview-build.d.ts.map +1 -0
- package/dist/src/preview-build.js +115 -0
- package/dist/src/preview-build.js.map +1 -0
- package/dist/src/preview.d.ts +6 -0
- package/dist/src/preview.d.ts.map +1 -0
- package/dist/src/preview.js +12 -0
- package/dist/src/preview.js.map +1 -0
- package/dist/src/register.d.ts +98 -0
- package/dist/src/register.d.ts.map +1 -0
- package/dist/src/register.js +103 -0
- package/dist/src/register.js.map +1 -0
- package/dist/src/repository.d.ts +18 -0
- package/dist/src/repository.d.ts.map +1 -0
- package/dist/src/repository.js +46 -0
- package/dist/src/repository.js.map +1 -0
- package/dist/src/site-id.d.ts +18 -0
- package/dist/src/site-id.d.ts.map +1 -0
- package/dist/src/site-id.js +70 -0
- package/dist/src/site-id.js.map +1 -0
- package/dist/src/site-middleware.d.ts +18 -0
- package/dist/src/site-middleware.d.ts.map +1 -0
- package/dist/src/site-middleware.js +47 -0
- package/dist/src/site-middleware.js.map +1 -0
- package/dist/src/skill.d.ts +26 -0
- package/dist/src/skill.d.ts.map +1 -0
- package/dist/src/skill.js +67 -0
- package/dist/src/skill.js.map +1 -0
- package/dist/src/types.d.ts +135 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +182 -4
- package/src/build-commit.ts +22 -0
- package/src/bundle.ts +570 -0
- package/src/component-manifest.ts +75 -0
- package/src/constants.ts +28 -0
- package/src/descriptors.ts +92 -0
- package/src/discovery.ts +183 -0
- package/src/doctor/checks-live.ts +324 -0
- package/src/doctor/checks-offline.ts +325 -0
- package/src/doctor/config-scan.ts +205 -0
- package/src/doctor/run.ts +39 -0
- package/src/doctor/types.ts +71 -0
- package/src/doctor.ts +14 -0
- package/src/git.ts +66 -0
- package/src/index.ts +8 -0
- package/src/integration.ts +607 -0
- package/src/message-of.ts +4 -0
- package/src/node.ts +5 -0
- package/src/package-version.ts +16 -0
- package/src/preview/_dispatch.ts +105 -0
- package/src/preview/_resolve-opts.ts +89 -0
- package/src/preview/banner.ts +96 -0
- package/src/preview/content-api.ts +293 -0
- package/src/preview/cookie.ts +54 -0
- package/src/preview/headers.ts +30 -0
- package/src/preview/landing.ts +73 -0
- package/src/preview/middleware.ts +309 -0
- package/src/preview/preview-path.ts +28 -0
- package/src/preview/satteri-workerd.ts +24 -0
- package/src/preview/site-middleware.ts +210 -0
- package/src/preview/workerd-shim.ts +31 -0
- package/src/preview-build.ts +147 -0
- package/src/preview-handler.astro +55 -0
- package/src/preview-handler.d.ts +6 -0
- package/src/preview.ts +22 -0
- package/src/register.ts +180 -0
- package/src/repository.ts +54 -0
- package/src/site-id.ts +86 -0
- package/src/site-middleware.ts +55 -0
- package/src/skill/SKILL.md +69 -0
- package/src/skill.ts +66 -0
- package/src/types.ts +137 -0
- package/src/virtual-modules.d.ts +52 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { build } from 'esbuild';
|
|
5
|
+
import { build as buildWithVite, mergeConfig } from 'vite';
|
|
6
|
+
import { PACKAGE_NAME } from './constants.js';
|
|
7
|
+
import { messageOf } from './message-of.js';
|
|
8
|
+
/**
|
|
9
|
+
* Modules the editor bundle must NEVER contain. The editor (served from
|
|
10
|
+
* `endpoint`) supplies them at runtime so the site's components
|
|
11
|
+
* execute on the editor's own React instance — a second bundled React breaks
|
|
12
|
+
* hooks/context. `@puckeditor/core` is the puck editor package the site's
|
|
13
|
+
* config builds its component definitions against.
|
|
14
|
+
*
|
|
15
|
+
* KEEP IN SYNC with the modules the editor at the endpoint supplies: the two lists
|
|
16
|
+
* are one contract, so every specifier externalized here needs an entry there
|
|
17
|
+
* or the site's bundle fails bare-specifier resolution in the browser. Each side
|
|
18
|
+
* pins the list in its own tests.
|
|
19
|
+
*/
|
|
20
|
+
export const EDITOR_BUNDLE_EXTERNALS = [
|
|
21
|
+
'react',
|
|
22
|
+
'react-dom',
|
|
23
|
+
'react/jsx-runtime',
|
|
24
|
+
'react/jsx-dev-runtime',
|
|
25
|
+
'react-dom/client',
|
|
26
|
+
'@puckeditor/core',
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Asset references inside component stylesheets are never pulled INTO the
|
|
30
|
+
* bundle — inlining would balloon the registered stylesheet and drag binary
|
|
31
|
+
* assets through the hash pipeline. They are instead re-pointed at the
|
|
32
|
+
* deployed site (see `rewriteStylesheetAssetUrls`), because the registered
|
|
33
|
+
* stylesheet is injected as text into the editor's canvas: left as-authored, a
|
|
34
|
+
* root-relative `url(/fonts/x.otf)` would resolve against the EDITOR's origin
|
|
35
|
+
* and 404.
|
|
36
|
+
*/
|
|
37
|
+
const STYLESHEET_ASSET_EXTERNALS = [
|
|
38
|
+
'*.woff',
|
|
39
|
+
'*.woff2',
|
|
40
|
+
'*.ttf',
|
|
41
|
+
'*.otf',
|
|
42
|
+
'*.eot',
|
|
43
|
+
'*.png',
|
|
44
|
+
'*.jpg',
|
|
45
|
+
'*.jpeg',
|
|
46
|
+
'*.gif',
|
|
47
|
+
'*.svg',
|
|
48
|
+
'*.webp',
|
|
49
|
+
'*.avif',
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Cloudflare Pages `_headers` rule that lets the editor load an asset
|
|
53
|
+
* cross-origin. Part of the site-side contract: without it the browser
|
|
54
|
+
* blocks the fetch from the editor's origin. Applied to `/_conloca/*` for the
|
|
55
|
+
* bundle itself, and to the directories the stylesheet's assets live in —
|
|
56
|
+
* webfonts are CORS-gated, so a 200 without this header still renders the
|
|
57
|
+
* fallback face.
|
|
58
|
+
*/
|
|
59
|
+
function corsRule(path) {
|
|
60
|
+
return `${path}\n Access-Control-Allow-Origin: *\n`;
|
|
61
|
+
}
|
|
62
|
+
const BUNDLE_CORS_PATH = '/_conloca/*';
|
|
63
|
+
/**
|
|
64
|
+
* The named exports the bundle re-exports from the host's schemas module
|
|
65
|
+
* (conlocaCMS `schemasPath`). One list drives the virtual entry's re-export
|
|
66
|
+
* lines, the always-undefined warning absorption, and the all-absent check —
|
|
67
|
+
* three places that must never disagree on a name.
|
|
68
|
+
*/
|
|
69
|
+
const SCHEMA_MODULE_EXPORTS = ['pageSchemas', 'dataSchemas', 'mdxComponents'];
|
|
70
|
+
/** esbuild's per-name notice for a schemas-module export the module doesn't declare (absorbed below). */
|
|
71
|
+
const SCHEMA_EXPORT_ABSENCE = new RegExp(`^Import "(${SCHEMA_MODULE_EXPORTS.join('|')})" will always be undefined\\b`);
|
|
72
|
+
/**
|
|
73
|
+
* Bundles the site's puck config into a browser ESM file plus (when the
|
|
74
|
+
* graph carries styles) a companion stylesheet, both under `<dir>/_conloca/`,
|
|
75
|
+
* content-addressed by the first 16 hex chars of their sha-256, and ensures
|
|
76
|
+
* `<dir>/_headers` carries the CORS rule the editor needs to load them
|
|
77
|
+
* cross-origin.
|
|
78
|
+
*
|
|
79
|
+
* The siteStyles compile first, through the site's own Vite pipeline (see
|
|
80
|
+
* `compileSiteStyles`); one that fails to compile fails the build.
|
|
81
|
+
*
|
|
82
|
+
* Component styles compile in the SAME esbuild pass as the JS: CSS-module
|
|
83
|
+
* class names are hashed consistently across both outputs, so `styles.foo` in
|
|
84
|
+
* a component always matches a selector in the emitted stylesheet. SCSS
|
|
85
|
+
* compiles through `sass`; a component stylesheet that fails to compile is
|
|
86
|
+
* stripped with a warning instead of failing the build (one broken component
|
|
87
|
+
* stylesheet must not cost the site its registration).
|
|
88
|
+
*/
|
|
89
|
+
export async function bundleEditorAssets(input) {
|
|
90
|
+
const siteCss = await compileSiteStyles({
|
|
91
|
+
root: input.root,
|
|
92
|
+
vite: input.vite,
|
|
93
|
+
siteStyles: typeof input.siteStyles === 'string' ? [input.siteStyles] : (input.siteStyles ?? []),
|
|
94
|
+
dir: input.dir,
|
|
95
|
+
});
|
|
96
|
+
const entryPath = resolve(input.puckConfigPath);
|
|
97
|
+
const descriptors = input.descriptors;
|
|
98
|
+
const discovered = descriptors?.discoveredMdxComponents ?? [];
|
|
99
|
+
const virtualEntry = [
|
|
100
|
+
`export { default } from ${JSON.stringify(entryPath)};`,
|
|
101
|
+
// Third bundle leg: editor descriptors ride next to the puck
|
|
102
|
+
// config as named exports. The namespace import is deliberate — an
|
|
103
|
+
// `export { x } from` of a name the host's schemas module doesn't
|
|
104
|
+
// declare fails esbuild, so a partial module cannot fail the
|
|
105
|
+
// site's build; missing names just export undefined.
|
|
106
|
+
...(descriptors?.schemasPath
|
|
107
|
+
? [
|
|
108
|
+
`import * as __conlocaSchemas from ${JSON.stringify(resolve(descriptors.schemasPath))};`,
|
|
109
|
+
...SCHEMA_MODULE_EXPORTS.map((name) => `export const ${name} = __conlocaSchemas.${name};`),
|
|
110
|
+
]
|
|
111
|
+
: []),
|
|
112
|
+
...(discovered.length > 0 ? [`export const discoveredMdxComponents = ${JSON.stringify(discovered)};`] : []),
|
|
113
|
+
...(descriptors?.templates ? [`export const templates = ${JSON.stringify(descriptors.templates)};`] : []),
|
|
114
|
+
...(descriptors?.dataBindings ? [`export const dataBindings = ${JSON.stringify(descriptors.dataBindings)};`] : []),
|
|
115
|
+
].join('\n');
|
|
116
|
+
const result = await build({
|
|
117
|
+
stdin: {
|
|
118
|
+
contents: virtualEntry,
|
|
119
|
+
resolveDir: dirname(entryPath),
|
|
120
|
+
sourcefile: 'conloca-canvas-entry.js',
|
|
121
|
+
loader: 'js',
|
|
122
|
+
},
|
|
123
|
+
bundle: true,
|
|
124
|
+
format: 'esm',
|
|
125
|
+
platform: 'browser',
|
|
126
|
+
minify: true,
|
|
127
|
+
treeShaking: true,
|
|
128
|
+
write: false,
|
|
129
|
+
// Never written (write: false) — gives the stdin entry's outputs real
|
|
130
|
+
// .js/.css extensions so they can be told apart.
|
|
131
|
+
outdir: join(input.dir, '_conloca'),
|
|
132
|
+
// Automatic JSX so .tsx configs compile against react/jsx-runtime —
|
|
133
|
+
// which is externalized and supplied by the editor.
|
|
134
|
+
jsx: 'automatic',
|
|
135
|
+
external: [...EDITOR_BUNDLE_EXTERNALS, ...STYLESHEET_ASSET_EXTERNALS],
|
|
136
|
+
plugins: [sassCompiler(input.logger), ...(input.plugins ?? [])],
|
|
137
|
+
// No compiler is wired for these preprocessors in the component graph;
|
|
138
|
+
// strip them like all stylesheets used to be stripped (`{}` module, no
|
|
139
|
+
// rules) rather than failing the site's registration over one exotic
|
|
140
|
+
// import. siteStyles never reach here: the site's Vite pipeline compiles them.
|
|
141
|
+
loader: { '.less': 'empty', '.styl': 'empty' },
|
|
142
|
+
// esbuild would print warnings straight to stderr, outside the build's
|
|
143
|
+
// log stream; silence it and forward them through the Astro logger below.
|
|
144
|
+
logLevel: 'silent',
|
|
145
|
+
});
|
|
146
|
+
// The virtual entry re-exports the three descriptor names through a
|
|
147
|
+
// namespace import so a schemas module that declares only some of them
|
|
148
|
+
// cannot fail the site's build — absent names export undefined by
|
|
149
|
+
// design, and esbuild flags each one with an always-undefined warning on
|
|
150
|
+
// every build. Absence of an OPTIONAL name is the contract working, not a
|
|
151
|
+
// diagnostic; a schemas module yielding NONE of the names is one (a wrong
|
|
152
|
+
// path, or misspelled exports), so exactly that case is reported once, in
|
|
153
|
+
// this package's own words.
|
|
154
|
+
const softContractAbsences = new Set();
|
|
155
|
+
for (const warning of result.warnings) {
|
|
156
|
+
const absentName = warning.location?.file.endsWith('conloca-canvas-entry.js')
|
|
157
|
+
? SCHEMA_EXPORT_ABSENCE.exec(warning.text)?.[1]
|
|
158
|
+
: undefined;
|
|
159
|
+
if (absentName) {
|
|
160
|
+
softContractAbsences.add(absentName);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const location = warning.location;
|
|
164
|
+
input.logger.warn(`esbuild: ${warning.text}${location ? ` (${location.file}:${location.line}:${location.column})` : ''}`);
|
|
165
|
+
}
|
|
166
|
+
if (softContractAbsences.size === SCHEMA_MODULE_EXPORTS.length && descriptors?.schemasPath) {
|
|
167
|
+
input.logger.warn(`${PACKAGE_NAME}: the schemas module at ${descriptors.schemasPath} exports none of ` +
|
|
168
|
+
'pageSchemas, dataSchemas or mdxComponents — check the path and the export names.');
|
|
169
|
+
}
|
|
170
|
+
const jsFiles = result.outputFiles.filter((file) => file.path.endsWith('.js'));
|
|
171
|
+
const cssFiles = result.outputFiles.filter((file) => file.path.endsWith('.css'));
|
|
172
|
+
if (jsFiles.length !== 1 || cssFiles.length > 1 || jsFiles.length + cssFiles.length !== result.outputFiles.length) {
|
|
173
|
+
throw new Error(`${PACKAGE_NAME}: expected the puck config to bundle to one ESM file (plus at most one stylesheet), ` +
|
|
174
|
+
`got ${result.outputFiles.map((file) => file.path).join(', ')}. A non-JS import that esbuild emits ` +
|
|
175
|
+
'as its own asset (e.g. an image or font) is not supported in the editor bundle ' +
|
|
176
|
+
'— keep it out of the puck config graph.');
|
|
177
|
+
}
|
|
178
|
+
const outDir = join(input.dir, '_conloca');
|
|
179
|
+
await mkdir(outDir, { recursive: true });
|
|
180
|
+
const bytes = jsFiles[0].contents;
|
|
181
|
+
const hash = createHash('sha256').update(bytes).digest('hex');
|
|
182
|
+
const filename = `editor-bundle.${hash.slice(0, 16)}.js`;
|
|
183
|
+
await writeFile(join(outDir, filename), bytes);
|
|
184
|
+
let stylesheet;
|
|
185
|
+
let assetCorsPaths = [];
|
|
186
|
+
const componentCss = cssFiles[0] ? new TextDecoder().decode(cssFiles[0].contents) : '';
|
|
187
|
+
// Site styles first, so component rules keep the final word. esbuild emits
|
|
188
|
+
// an empty CSS file when every component stylesheet was stripped, and an
|
|
189
|
+
// empty registered stylesheet would only add a wasted fetch.
|
|
190
|
+
const rawCss = [siteCss, componentCss].filter(Boolean).join('\n');
|
|
191
|
+
if (rawCss !== '') {
|
|
192
|
+
// Asset URLs are rewritten BEFORE hashing: the editor hash-verifies the
|
|
193
|
+
// stylesheet it fetches, so the rewrite has to be part of the bytes that
|
|
194
|
+
// get hashed, written, and registered.
|
|
195
|
+
let css = rawCss;
|
|
196
|
+
if (input.publicBaseUrl) {
|
|
197
|
+
const rewritten = rewriteStylesheetAssetUrls(rawCss, input.publicBaseUrl, input.logger);
|
|
198
|
+
css = rewritten.css;
|
|
199
|
+
assetCorsPaths = rewritten.assetCorsPaths;
|
|
200
|
+
}
|
|
201
|
+
const cssBytes = new TextEncoder().encode(css);
|
|
202
|
+
const cssHash = createHash('sha256').update(cssBytes).digest('hex');
|
|
203
|
+
const cssFilename = `editor-bundle.${cssHash.slice(0, 16)}.css`;
|
|
204
|
+
await writeFile(join(outDir, cssFilename), cssBytes);
|
|
205
|
+
stylesheet = { url: `/_conloca/${cssFilename}`, hash: cssHash, bytes: cssBytes };
|
|
206
|
+
input.logger.info(`editor stylesheet written: ${stylesheet.url} (${cssBytes.byteLength} bytes)`);
|
|
207
|
+
}
|
|
208
|
+
await ensureCorsHeaders(input.dir, assetCorsPaths);
|
|
209
|
+
const url = `/_conloca/${filename}`;
|
|
210
|
+
input.logger.info(`editor bundle written: ${url} (${bytes.byteLength} bytes)`);
|
|
211
|
+
return { url, hash, bytes, stylesheet, assetCorsPaths };
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Compiles the siteStyles through the site's own Vite pipeline (its plugins,
|
|
215
|
+
* PostCSS config and preprocessors), the way conlocaCMS's dev editor compiles
|
|
216
|
+
* the same option, in a CSS-only build. The only files it writes are the
|
|
217
|
+
* assets the stylesheets reference (fonts, images), under `<dir>/_conloca/`.
|
|
218
|
+
* Returns the compiled CSS with the entries in listed order.
|
|
219
|
+
*
|
|
220
|
+
* A failure is rethrown naming the entries: the site's own build fails on the
|
|
221
|
+
* same stylesheet, and a canvas stylesheet silently missing its site styles
|
|
222
|
+
* must not register.
|
|
223
|
+
*/
|
|
224
|
+
async function compileSiteStyles({ root, vite, siteStyles, dir, }) {
|
|
225
|
+
if (siteStyles.length === 0)
|
|
226
|
+
return '';
|
|
227
|
+
const entryNames = siteStyles.map((_, index) => `site-style-${index}`);
|
|
228
|
+
let result;
|
|
229
|
+
try {
|
|
230
|
+
result = await buildWithVite(mergeConfig(vite, {
|
|
231
|
+
configFile: false,
|
|
232
|
+
root,
|
|
233
|
+
// The assets are written under `dir`, which the site serves at its
|
|
234
|
+
// origin root, so the URLs pointing at them must start there too.
|
|
235
|
+
base: '/',
|
|
236
|
+
logLevel: 'warn',
|
|
237
|
+
build: {
|
|
238
|
+
write: false,
|
|
239
|
+
copyPublicDir: false,
|
|
240
|
+
assetsDir: '_conloca',
|
|
241
|
+
rolldownOptions: {
|
|
242
|
+
input: Object.fromEntries(siteStyles.map((entry, index) => [entryNames[index], resolve(root, entry)])),
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
catch (cause) {
|
|
248
|
+
throw new Error(`${PACKAGE_NAME}: siteStyles failed to compile (${siteStyles.join(', ')}): ${messageOf(cause)}`, {
|
|
249
|
+
cause,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
const assets = [result]
|
|
253
|
+
.flat()
|
|
254
|
+
.flatMap((bundle) => ('output' in bundle ? bundle.output : []))
|
|
255
|
+
.filter((file) => file.type === 'asset');
|
|
256
|
+
await Promise.all(assets
|
|
257
|
+
.filter((asset) => !asset.fileName.endsWith('.css'))
|
|
258
|
+
.map(async (asset) => {
|
|
259
|
+
const target = join(dir, asset.fileName);
|
|
260
|
+
await mkdir(dirname(target), { recursive: true });
|
|
261
|
+
await writeFile(target, asset.source);
|
|
262
|
+
}));
|
|
263
|
+
return entryNames
|
|
264
|
+
.map((name) => assets.find((asset) => asset.names.includes(`${name}.css`))?.source)
|
|
265
|
+
.map((source) => (source instanceof Uint8Array ? new TextDecoder().decode(source) : (source ?? '')))
|
|
266
|
+
.filter(Boolean)
|
|
267
|
+
.join('\n');
|
|
268
|
+
}
|
|
269
|
+
/** Matches one `url(…)` token, with or without quotes (esbuild's minifier
|
|
270
|
+
* drops the quotes, but an unminified or quote-requiring value keeps them). */
|
|
271
|
+
const CSS_URL_TOKEN = /url\(\s*(['"]?)([^'")]+)\1\s*\)/g;
|
|
272
|
+
/**
|
|
273
|
+
* Re-points the registered stylesheet's asset references at the deployed site.
|
|
274
|
+
*
|
|
275
|
+
* Only ROOT-relative URLs (`/fonts/x.otf`) are rewritten — those name a path
|
|
276
|
+
* on the site and nothing else. That includes the `/_conloca/` assets the
|
|
277
|
+
* siteStyles build emitted, since Vite resolves their relative references.
|
|
278
|
+
* Path-relative ones (`./x.otf`, `../x.otf`, `x.otf`) cannot be resolved here
|
|
279
|
+
* and are reported instead of guessed: esbuild flattens every component
|
|
280
|
+
* stylesheet into ONE output and copies url() paths through verbatim, so by
|
|
281
|
+
* this point the emitted text no longer records WHICH source directory each
|
|
282
|
+
* one was relative to. Absolute, protocol-relative, `data:` and fragment
|
|
283
|
+
* (`#filter`) refs already resolve correctly and are left alone.
|
|
284
|
+
*
|
|
285
|
+
* Returns the rewritten CSS plus the `_headers` globs its assets need — one
|
|
286
|
+
* per distinct directory rather than one per file, which keeps a font family
|
|
287
|
+
* of forty weights to a single rule.
|
|
288
|
+
*/
|
|
289
|
+
export function rewriteStylesheetAssetUrls(css, publicBaseUrl, logger) {
|
|
290
|
+
const base = publicBaseUrl.replace(/\/+$/, '');
|
|
291
|
+
const dirs = new Set();
|
|
292
|
+
const unresolved = new Set();
|
|
293
|
+
const rewritten = css.replace(CSS_URL_TOKEN, (token, _quote, ref) => {
|
|
294
|
+
const value = ref.trim();
|
|
295
|
+
if (value.startsWith('//') || value.startsWith('#') || /^[a-z][a-z0-9+.-]*:/i.test(value))
|
|
296
|
+
return token;
|
|
297
|
+
if (!value.startsWith('/')) {
|
|
298
|
+
unresolved.add(value);
|
|
299
|
+
return token;
|
|
300
|
+
}
|
|
301
|
+
const dir = value.slice(0, value.lastIndexOf('/'));
|
|
302
|
+
dirs.add(`${dir === '' ? '' : dir}/*`);
|
|
303
|
+
return `url(${base}${value})`;
|
|
304
|
+
});
|
|
305
|
+
if (unresolved.size > 0) {
|
|
306
|
+
logger.warn('path-relative asset URLs in the registered stylesheet cannot be pointed at the deployed ' +
|
|
307
|
+
`site and will not load in the editing canvas — make them root-relative: ${[...unresolved].join(', ')}`);
|
|
308
|
+
}
|
|
309
|
+
return { css: rewritten, assetCorsPaths: [...dirs] };
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Compiles the component graph's `.scss`/`.sass` imports with `sass`, mapping
|
|
313
|
+
* `*.module.*` files to esbuild's local-css semantics (hashed class names
|
|
314
|
+
* exported to the JS side). A file that fails to compile degrades to the
|
|
315
|
+
* pre-styled-canvas behavior — `{}` for a module (classNames become
|
|
316
|
+
* undefined), no rules for a global — with a warning naming the file and the
|
|
317
|
+
* compiler's reason. siteStyles never reach it: the site's Vite pipeline
|
|
318
|
+
* compiles them, and a failure there fails the build.
|
|
319
|
+
*/
|
|
320
|
+
function sassCompiler(logger) {
|
|
321
|
+
return {
|
|
322
|
+
name: 'conloca-sass',
|
|
323
|
+
setup(build) {
|
|
324
|
+
build.onLoad({ filter: /\.(scss|sass)$/ }, async (args) => {
|
|
325
|
+
const isModule = /\.module\.(scss|sass)$/.test(args.path);
|
|
326
|
+
try {
|
|
327
|
+
const sass = await import('sass');
|
|
328
|
+
const compiled = sass.compile(args.path, { style: 'expanded' });
|
|
329
|
+
return { contents: compiled.css, loader: isModule ? 'local-css' : 'css' };
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
logger.warn(`stylesheet stripped from the editor bundle (${args.path}): ` +
|
|
333
|
+
(error instanceof Error ? error.message : String(error)));
|
|
334
|
+
return isModule ? { contents: '', loader: 'empty' } : { contents: '', loader: 'css' };
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Writes the discovery route's collected CSS as a content-addressed artifact
|
|
342
|
+
* next to the editor bundle: `_conloca/route-css.<hash16>.css`.
|
|
343
|
+
* Same serving story as the editor stylesheet — the `/_conloca/*` CORS rule
|
|
344
|
+
* already covers it, and `mirrorEditorAssets` copies the whole dir.
|
|
345
|
+
*/
|
|
346
|
+
export async function emitRouteCssArtifact(dir, css, publicBaseUrl, logger) {
|
|
347
|
+
if (css.trim() === '')
|
|
348
|
+
return undefined;
|
|
349
|
+
// The discovered CSS is the site's FULL page CSS, so it carries the
|
|
350
|
+
// site's asset URLs (fonts especially) as authored — root-relative. Applied
|
|
351
|
+
// in the editor those resolve against the EDITOR's origin and 404, the same
|
|
352
|
+
// failure the editor stylesheet had; same fix, same helper, and the same
|
|
353
|
+
// CORS grant for the directories they live in.
|
|
354
|
+
let assetCorsPaths = [];
|
|
355
|
+
let text = css;
|
|
356
|
+
if (publicBaseUrl) {
|
|
357
|
+
const rewritten = rewriteStylesheetAssetUrls(css, publicBaseUrl, logger);
|
|
358
|
+
text = rewritten.css;
|
|
359
|
+
assetCorsPaths = rewritten.assetCorsPaths;
|
|
360
|
+
}
|
|
361
|
+
const bytes = new TextEncoder().encode(text);
|
|
362
|
+
const outDir = join(dir, '_conloca');
|
|
363
|
+
await mkdir(outDir, { recursive: true });
|
|
364
|
+
const hash = createHash('sha256').update(bytes).digest('hex');
|
|
365
|
+
const filename = `route-css.${hash.slice(0, 16)}.css`;
|
|
366
|
+
await writeFile(join(outDir, filename), bytes);
|
|
367
|
+
await ensureCorsHeaders(dir, assetCorsPaths);
|
|
368
|
+
logger.info(`discovered route CSS written: /_conloca/${filename} (${bytes.byteLength} bytes)`);
|
|
369
|
+
return { stylesheet: { url: `/_conloca/${filename}`, hash, bytes }, assetCorsPaths };
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Mirrors the emitted editor assets (`_conloca/` + the CORS rule) from the
|
|
373
|
+
* primary build's output into another asset directory — the recursive preview
|
|
374
|
+
* build's client dir. The bundle is only ever compiled into the PRIMARY
|
|
375
|
+
* build's dist (the child build short-circuits `astro:build:done` to avoid
|
|
376
|
+
* registration recursion), but in a deployment that serves the site and the
|
|
377
|
+
* preview from one Cloudflare Worker, the child's client dir is the asset set
|
|
378
|
+
* that actually serves the site, so without this mirror the editor at the
|
|
379
|
+
* endpoint cannot load its component bundle.
|
|
380
|
+
*/
|
|
381
|
+
export async function mirrorEditorAssets(fromDir, toDir, assetCorsPaths = []) {
|
|
382
|
+
await cp(join(fromDir, '_conloca'), join(toDir, '_conloca'), { recursive: true });
|
|
383
|
+
await ensureCorsHeaders(toDir, assetCorsPaths);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Adds the bundle's CORS rule — plus one per stylesheet asset directory — to
|
|
387
|
+
* `<dir>/_headers`, appending to an existing file without clobbering other
|
|
388
|
+
* rules and without duplicating any of ours. Each rule is checked
|
|
389
|
+
* individually, so a dist that already carries `/_conloca/*` from an earlier
|
|
390
|
+
* build still picks up newly referenced asset directories.
|
|
391
|
+
*/
|
|
392
|
+
async function ensureCorsHeaders(dir, assetCorsPaths = []) {
|
|
393
|
+
const headersPath = join(dir, '_headers');
|
|
394
|
+
let existing = '';
|
|
395
|
+
try {
|
|
396
|
+
existing = await readFile(headersPath, 'utf8');
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
if (error.code !== 'ENOENT')
|
|
400
|
+
throw error;
|
|
401
|
+
}
|
|
402
|
+
let updated = existing;
|
|
403
|
+
for (const path of [BUNDLE_CORS_PATH, ...assetCorsPaths]) {
|
|
404
|
+
if (updated.includes(`${path}\n`))
|
|
405
|
+
continue;
|
|
406
|
+
const separator = updated === '' || updated.endsWith('\n') ? '' : '\n';
|
|
407
|
+
updated = `${updated}${separator}${corsRule(path)}`;
|
|
408
|
+
}
|
|
409
|
+
if (updated === existing)
|
|
410
|
+
return;
|
|
411
|
+
await writeFile(headersPath, updated);
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAA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W,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** The emitted manifest: its site-relative URL and the full sha-256 hex of its bytes. */
|
|
2
|
+
export interface ComponentManifestArtifact {
|
|
3
|
+
url: string;
|
|
4
|
+
hash: string;
|
|
5
|
+
}
|
|
6
|
+
type Logger = {
|
|
7
|
+
info(message: string): void;
|
|
8
|
+
warn(message: string): void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Writes the site's component vocabulary — every Puck component the config
|
|
12
|
+
* declares and what each accepts, read from source and never executed — as a
|
|
13
|
+
* content-addressed artifact beside the editor bundle:
|
|
14
|
+
* `_conloca/component-manifest.<hash16>.json`. The `/_conloca/*` CORS rule the
|
|
15
|
+
* bundle wrote already covers it, and `mirrorEditorAssets` copies the dir.
|
|
16
|
+
*
|
|
17
|
+
* Fail-soft: the manifest is metadata for agents, so a failure costs the
|
|
18
|
+
* manifest and warns — never the build. A config the reader cannot fully read
|
|
19
|
+
* still ships its manifest, because the admissions are the answer, and the
|
|
20
|
+
* build log names what could not be read, where the developer looks.
|
|
21
|
+
*/
|
|
22
|
+
export declare function emitComponentManifest(input: {
|
|
23
|
+
dir: string;
|
|
24
|
+
puckConfigPath: string;
|
|
25
|
+
projectRoot: string;
|
|
26
|
+
logger: Logger;
|
|
27
|
+
}): Promise<ComponentManifestArtifact | undefined>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=component-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-manifest.d.ts","sourceRoot":"","sources":["../../src/component-manifest.ts"],"names":[],"mappings":"AAMA,yFAAyF;AACzF,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAKD,KAAK,MAAM,GAAG;IAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAC,KAAK,EAAE;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC,CA0BjD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { endpointReaderOptions, readPuckConfig } from '@conloca/astro-cms/puck-manifest';
|
|
5
|
+
import { COMPONENT_MANIFEST_LIMITS, measureJson } from '@conloca/content-api/component-vocabulary';
|
|
6
|
+
/** Metadata transport ceiling; larger metadata must not be registered as a usable artifact. */
|
|
7
|
+
const MAX_MANIFEST_BYTES = COMPONENT_MANIFEST_LIMITS.bytes;
|
|
8
|
+
/**
|
|
9
|
+
* Writes the site's component vocabulary — every Puck component the config
|
|
10
|
+
* declares and what each accepts, read from source and never executed — as a
|
|
11
|
+
* content-addressed artifact beside the editor bundle:
|
|
12
|
+
* `_conloca/component-manifest.<hash16>.json`. The `/_conloca/*` CORS rule the
|
|
13
|
+
* bundle wrote already covers it, and `mirrorEditorAssets` copies the dir.
|
|
14
|
+
*
|
|
15
|
+
* Fail-soft: the manifest is metadata for agents, so a failure costs the
|
|
16
|
+
* manifest and warns — never the build. A config the reader cannot fully read
|
|
17
|
+
* still ships its manifest, because the admissions are the answer, and the
|
|
18
|
+
* build log names what could not be read, where the developer looks.
|
|
19
|
+
*/
|
|
20
|
+
export async function emitComponentManifest(input) {
|
|
21
|
+
try {
|
|
22
|
+
const manifest = readPuckConfig(endpointReaderOptions({ puckConfigPath: input.puckConfigPath, projectRoot: input.projectRoot }));
|
|
23
|
+
const bytes = new TextEncoder().encode(JSON.stringify(manifest));
|
|
24
|
+
if (bytes.byteLength > MAX_MANIFEST_BYTES) {
|
|
25
|
+
input.logger.warn(`component manifest skipped — ${bytes.byteLength} bytes exceeds the metadata limit of ${MAX_MANIFEST_BYTES} bytes`);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
measureJson(manifest, COMPONENT_MANIFEST_LIMITS);
|
|
29
|
+
const hash = createHash('sha256').update(bytes).digest('hex');
|
|
30
|
+
const filename = `component-manifest.${hash.slice(0, 16)}.json`;
|
|
31
|
+
await mkdir(join(input.dir, '_conloca'), { recursive: true });
|
|
32
|
+
await writeFile(join(input.dir, '_conloca', filename), bytes);
|
|
33
|
+
reportManifest(manifest, `/_conloca/${filename}`, input.logger);
|
|
34
|
+
return { url: `/_conloca/${filename}`, hash };
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
input.logger.warn('component manifest skipped — agents get no component vocabulary from this build ' +
|
|
38
|
+
`(${error instanceof Error ? error.message : String(error)})`);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** One info line for the artifact, and a warning for everything the reader could not read. */
|
|
43
|
+
function reportManifest(manifest, url, logger) {
|
|
44
|
+
logger.info(`component manifest written: ${url} (${Object.keys(manifest.components).length} components)`);
|
|
45
|
+
if (manifest.unreadable) {
|
|
46
|
+
logger.warn(`component manifest is incomplete: ${manifest.unreadableReason ?? 'the config could not be fully read'}`);
|
|
47
|
+
}
|
|
48
|
+
for (const name of manifest.unresolved) {
|
|
49
|
+
const reason = manifest.unresolvedReasons?.[name];
|
|
50
|
+
logger.warn(`component ${name} could not be read${reason === undefined ? '' : `: ${reason}`}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=component-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-manifest.js","sourceRoot":"","sources":["../../src/component-manifest.ts"],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;IACjG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable package name used as the Astro integration id, for logger scoping,
|
|
3
|
+
* and in user-facing error messages. Single source of truth.
|
|
4
|
+
*/
|
|
5
|
+
export declare const PACKAGE_NAME = "@conloca/cloud-astro";
|
|
6
|
+
/**
|
|
7
|
+
* Environment variable that the recursive preview build sets on the child
|
|
8
|
+
* Astro process so the integration's own `astro:build:done` hook can detect
|
|
9
|
+
* it and skip re-registration / further recursion.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PREVIEW_BUILD_ENV_FLAG = "CONLOCA_PREVIEW_BUILD";
|
|
12
|
+
/**
|
|
13
|
+
* Environment variable consumed by the recursive preview build to discover
|
|
14
|
+
* the per-branch preview secret needed to construct the secret-scoped Astro
|
|
15
|
+
* route (`/conloca_preview_<secret>/[...path]`).
|
|
16
|
+
*/
|
|
17
|
+
export declare const PREVIEW_SECRET_ENV_FLAG = "CONLOCA_PREVIEW_SECRET";
|
|
18
|
+
/**
|
|
19
|
+
* Environment variable carrying the build token (`cbt_<id>.<secret>`),
|
|
20
|
+
* issued by the endpoint, that authenticates the site's build to the
|
|
21
|
+
* endpoint's registration route.
|
|
22
|
+
* Read when {@link ConlocaCloudOptions.buildToken} is not set, so CI can
|
|
23
|
+
* inject the credential without committing it to `astro.config.mjs`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const BUILD_TOKEN_ENV_VAR = "CONLOCA_BUILD_TOKEN";
|
|
26
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,YAAY,yBAAyB,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable package name used as the Astro integration id, for logger scoping,
|
|
3
|
+
* and in user-facing error messages. Single source of truth.
|
|
4
|
+
*/
|
|
5
|
+
export const PACKAGE_NAME = '@conloca/cloud-astro';
|
|
6
|
+
/**
|
|
7
|
+
* Environment variable that the recursive preview build sets on the child
|
|
8
|
+
* Astro process so the integration's own `astro:build:done` hook can detect
|
|
9
|
+
* it and skip re-registration / further recursion.
|
|
10
|
+
*/
|
|
11
|
+
export const PREVIEW_BUILD_ENV_FLAG = 'CONLOCA_PREVIEW_BUILD';
|
|
12
|
+
/**
|
|
13
|
+
* Environment variable consumed by the recursive preview build to discover
|
|
14
|
+
* the per-branch preview secret needed to construct the secret-scoped Astro
|
|
15
|
+
* route (`/conloca_preview_<secret>/[...path]`).
|
|
16
|
+
*/
|
|
17
|
+
export const PREVIEW_SECRET_ENV_FLAG = 'CONLOCA_PREVIEW_SECRET';
|
|
18
|
+
/**
|
|
19
|
+
* Environment variable carrying the build token (`cbt_<id>.<secret>`),
|
|
20
|
+
* issued by the endpoint, that authenticates the site's build to the
|
|
21
|
+
* endpoint's registration route.
|
|
22
|
+
* Read when {@link ConlocaCloudOptions.buildToken} is not set, so CI can
|
|
23
|
+
* inject the credential without committing it to `astro.config.mjs`.
|
|
24
|
+
*/
|
|
25
|
+
export const BUILD_TOKEN_ENV_VAR = 'CONLOCA_BUILD_TOKEN';
|
|
26
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MdxRegistryScanOptions } from '@conloca/astro-cms/node';
|
|
2
|
+
import type { EditorBundleDescriptors } from './bundle.js';
|
|
3
|
+
/**
|
|
4
|
+
* The MDX discovery seam, so tests can drive the failure path without a
|
|
5
|
+
* fixture project (same convention as `_postRegistrationWith` in register.ts).
|
|
6
|
+
*/
|
|
7
|
+
export type MdxDescriptorScan = (options: MdxRegistryScanOptions) => Promise<readonly unknown[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the editor descriptors for this build from the channel conlocaCMS
|
|
10
|
+
* published — the bundle's third leg, next to the puck config and the styles.
|
|
11
|
+
*
|
|
12
|
+
* The editor at the endpoint has no dev server to serve `/api/registry` from,
|
|
13
|
+
* so the scan runs HERE and its output is compiled into the bundle. Fail-soft throughout: a
|
|
14
|
+
* scan failure costs the auto-discovered half and warns; an absent channel (a
|
|
15
|
+
* CMS-less build) is simply a build with no descriptors; a PRESENT but
|
|
16
|
+
* unreadable channel warns — that is version drift between this package and
|
|
17
|
+
* `@conloca/astro-cms`, not a CMS-less build, and silence would strip every
|
|
18
|
+
* schema from the editor at the endpoint with no diagnostic. The bundle itself stays
|
|
19
|
+
* fail-hard, unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveEditorDescriptors(logger: {
|
|
22
|
+
info(message: string): void;
|
|
23
|
+
warn(message: string): void;
|
|
24
|
+
}, env?: Record<string, string | undefined>, scan?: MdxDescriptorScan): Promise<EditorBundleDescriptors | undefined>;
|
|
25
|
+
//# sourceMappingURL=descriptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptors.d.ts","sourceRoot":"","sources":["../../src/descriptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAOtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,sBAAsB,KAAK,OAAO,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC;AAgBjG;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE;IAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACpE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,EACrD,IAAI,GAAE,iBAAsC,GAC3C,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CA6C9C"}
|