@conloca/cloud-astro 0.2.2 → 0.2.3
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 +261 -208
- package/dist/.build-inputs.json +60 -0
- package/dist/src/component-manifest.d.ts +5 -3
- package/dist/src/component-manifest.d.ts.map +1 -1
- package/dist/src/component-manifest.js +7 -7
- package/dist/src/component-manifest.js.map +1 -1
- package/dist/src/constants.d.ts +5 -13
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +5 -13
- package/dist/src/constants.js.map +1 -1
- package/dist/src/descriptors.d.ts +2 -2
- package/dist/src/descriptors.d.ts.map +1 -1
- package/dist/src/doctor/checks-address.d.ts +18 -0
- package/dist/src/doctor/checks-address.d.ts.map +1 -0
- package/dist/src/doctor/checks-address.js +163 -0
- package/dist/src/doctor/checks-address.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts +8 -5
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +220 -188
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +8 -23
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +22 -239
- package/dist/src/doctor/checks-offline.js.map +1 -1
- package/dist/src/doctor/config-scan.d.ts +6 -3
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +21 -11
- package/dist/src/doctor/config-scan.js.map +1 -1
- package/dist/src/doctor/run.d.ts.map +1 -1
- package/dist/src/doctor/run.js +12 -10
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +7 -7
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +7 -7
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +88 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -0
- package/dist/src/editor-page/bundle.js +370 -0
- package/dist/src/editor-page/bundle.js.map +1 -0
- package/dist/src/editor-page/emit.d.ts +33 -0
- package/dist/src/editor-page/emit.d.ts.map +1 -0
- package/dist/src/editor-page/emit.js +183 -0
- package/dist/src/editor-page/emit.js.map +1 -0
- package/dist/src/editor-page/framing.d.ts +23 -0
- package/dist/src/editor-page/framing.d.ts.map +1 -0
- package/dist/src/editor-page/framing.js +39 -0
- package/dist/src/editor-page/framing.js.map +1 -0
- package/dist/src/editor-page/page.d.ts +9 -0
- package/dist/src/editor-page/page.d.ts.map +1 -0
- package/dist/src/editor-page/page.js +31 -0
- package/dist/src/editor-page/page.js.map +1 -0
- package/dist/src/editor-page/site-base.d.ts +4 -0
- package/dist/src/editor-page/site-base.d.ts.map +1 -0
- package/dist/src/editor-page/site-base.js +13 -0
- package/dist/src/editor-page/site-base.js.map +1 -0
- package/dist/src/git.d.ts +11 -8
- package/dist/src/git.d.ts.map +1 -1
- package/dist/src/git.js +25 -8
- package/dist/src/git.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/integration.d.ts +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +245 -408
- package/dist/src/integration.js.map +1 -1
- package/dist/src/node.d.ts +3 -1
- package/dist/src/node.d.ts.map +1 -1
- package/dist/src/node.js +7 -2
- package/dist/src/node.js.map +1 -1
- package/dist/src/preview/_resolve-opts.d.ts +16 -10
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +21 -10
- package/dist/src/preview/_resolve-opts.js.map +1 -1
- package/dist/src/preview/banner.d.ts.map +1 -1
- package/dist/src/preview/banner.js +2 -4
- package/dist/src/preview/banner.js.map +1 -1
- package/dist/src/preview/cookie.d.ts +5 -2
- package/dist/src/preview/cookie.d.ts.map +1 -1
- package/dist/src/preview/cookie.js +5 -2
- package/dist/src/preview/cookie.js.map +1 -1
- package/dist/src/preview/label.d.ts +8 -0
- package/dist/src/preview/label.d.ts.map +1 -0
- package/dist/src/preview/label.js +14 -0
- package/dist/src/preview/label.js.map +1 -0
- package/dist/src/preview/landing.d.ts +2 -2
- package/dist/src/preview/landing.js +2 -2
- package/dist/src/preview/middleware.d.ts +25 -20
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +56 -51
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/preview-path.d.ts +18 -5
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +24 -8
- package/dist/src/preview/preview-path.js.map +1 -1
- package/dist/src/preview/site-middleware.d.ts +5 -5
- package/dist/src/preview/site-middleware.d.ts.map +1 -1
- package/dist/src/preview/site-middleware.js +16 -16
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview-build.d.ts +18 -15
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +36 -21
- package/dist/src/preview-build.js.map +1 -1
- package/dist/src/preview.d.ts +1 -1
- package/dist/src/preview.d.ts.map +1 -1
- package/dist/src/preview.js +1 -1
- package/dist/src/preview.js.map +1 -1
- package/dist/src/repository.d.ts +1 -1
- package/dist/src/repository.js +1 -1
- package/dist/src/resolve-options.d.ts +17 -0
- package/dist/src/resolve-options.d.ts.map +1 -0
- package/dist/src/resolve-options.js +21 -0
- package/dist/src/resolve-options.js.map +1 -0
- package/dist/src/site-id.d.ts +0 -2
- package/dist/src/site-id.d.ts.map +1 -1
- package/dist/src/site-id.js +2 -3
- package/dist/src/site-id.js.map +1 -1
- package/dist/src/types.d.ts +21 -69
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +37 -13
- package/src/component-manifest.ts +11 -8
- package/src/constants.ts +5 -14
- package/src/descriptors.ts +2 -2
- package/src/doctor/checks-address.ts +190 -0
- package/src/doctor/checks-live.ts +256 -268
- package/src/doctor/checks-offline.ts +24 -262
- package/src/doctor/config-scan.ts +21 -9
- package/src/doctor/run.ts +14 -16
- package/src/doctor/types.ts +7 -7
- package/src/editor-page/bundle.ts +482 -0
- package/src/editor-page/emit.ts +246 -0
- package/src/editor-page/framing.ts +62 -0
- package/src/editor-page/page.ts +37 -0
- package/src/editor-page/site-base.ts +11 -0
- package/src/git.ts +29 -10
- package/src/index.ts +20 -6
- package/src/integration.ts +255 -461
- package/src/node.ts +18 -2
- package/src/preview/_resolve-opts.ts +29 -11
- package/src/preview/banner.ts +2 -4
- package/src/preview/cookie.ts +5 -2
- package/src/preview/label.ts +12 -0
- package/src/preview/landing.ts +2 -2
- package/src/preview/middleware.ts +77 -66
- package/src/preview/preview-path.ts +26 -8
- package/src/preview/site-middleware.ts +16 -21
- package/src/preview-build.ts +42 -26
- package/src/preview-handler.astro +10 -8
- package/src/preview.ts +0 -1
- package/src/repository.ts +1 -1
- package/src/resolve-options.ts +37 -0
- package/src/site-id.ts +2 -4
- package/src/skill/SKILL.md +51 -55
- package/src/types.ts +21 -70
- package/src/virtual-modules.d.ts +4 -1
- package/dist/src/build-commit.d.ts +0 -19
- package/dist/src/build-commit.d.ts.map +0 -1
- package/dist/src/build-commit.js +0 -6
- package/dist/src/build-commit.js.map +0 -1
- package/dist/src/bundle.d.ts +0 -181
- package/dist/src/bundle.d.ts.map +0 -1
- package/dist/src/bundle.js +0 -413
- package/dist/src/bundle.js.map +0 -1
- package/dist/src/discovery.d.ts +0 -58
- package/dist/src/discovery.d.ts.map +0 -1
- package/dist/src/discovery.js +0 -133
- package/dist/src/discovery.js.map +0 -1
- package/dist/src/register.d.ts +0 -98
- package/dist/src/register.d.ts.map +0 -1
- package/dist/src/register.js +0 -103
- package/dist/src/register.js.map +0 -1
- package/src/build-commit.ts +0 -22
- package/src/bundle.ts +0 -570
- package/src/discovery.ts +0 -183
- package/src/register.ts +0 -180
package/dist/src/integration.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
1
|
import { createRequire } from 'node:module';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
4
3
|
import { readEditorDescriptors } from '@conloca/astro-cms/node';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { BUILD_TOKEN_ENV_VAR, PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG, PREVIEW_SECRET_ENV_FLAG } from './constants.js';
|
|
9
|
-
import { resolveEditorDescriptors } from './descriptors.js';
|
|
10
|
-
import { discoverStyleContext } from './discovery.js';
|
|
4
|
+
import { DEFAULT_EDITOR_ENDPOINT, editorUiOrigin } from '@conloca/content-api/editor-host';
|
|
5
|
+
import { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG } from './constants.js';
|
|
6
|
+
import { emitEditorPage, mirrorEditorPage } from './editor-page/emit.js';
|
|
11
7
|
import { gitOutput, resolveBuildRef, resolveRepositoryUri } from './git.js';
|
|
12
|
-
import {
|
|
13
|
-
import { spawnPreviewBuild } from './preview-build.js';
|
|
14
|
-
import {
|
|
8
|
+
import { PREVIEW_ROUTE_SEGMENT } from './preview/preview-path.js';
|
|
9
|
+
import { previewBuildMode, spawnPreviewBuild } from './preview-build.js';
|
|
10
|
+
import { resolveInheritedOptions } from './resolve-options.js';
|
|
15
11
|
import { resolveBuildSiteId } from './site-id.js';
|
|
16
12
|
import { scaffoldSkill } from './skill.js';
|
|
17
13
|
// Re-export the constants that moved out of this module when the preview
|
|
@@ -20,214 +16,224 @@ import { scaffoldSkill } from './skill.js';
|
|
|
20
16
|
export { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG };
|
|
21
17
|
/**
|
|
22
18
|
* Returns the site's Astro integration that hooks into `astro:build:done`
|
|
23
|
-
* to
|
|
24
|
-
*
|
|
19
|
+
* to write the editor page and, when the site opts in, trigger a recursive
|
|
20
|
+
* preview build.
|
|
25
21
|
*
|
|
26
22
|
* The build:done pipeline:
|
|
27
23
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* endpoint's exact status and body. Only a never-attempted registration (no
|
|
39
|
-
* build token, repo identity, git sha/branch, or public base URL) skips,
|
|
40
|
-
* ending the build with one summary block — or failing it when
|
|
41
|
-
* `requireRegistration` is set.
|
|
42
|
-
* 3. Spawn the recursive preview build with the preview secret
|
|
43
|
-
* returned by registration (or the env override).
|
|
24
|
+
* 0. Write the editor page to `dist/_conloca/editor/`: `index.html`, the
|
|
25
|
+
* site's compiled puck config and styles, the MDX sandbox frame and
|
|
26
|
+
* `conloca.json`. Every build does this; the page carries no credential.
|
|
27
|
+
* 1. Only when `previewBuild` is given as an object and an SSR adapter
|
|
28
|
+
* exists (refused under @astrojs/vercel and @astrojs/netlify, checked
|
|
29
|
+
* already at `astro:config:done`), spawn the recursive preview build
|
|
30
|
+
* and copy the editor page into its
|
|
31
|
+
* client folder. It mounts `/_conloca/preview/` and
|
|
32
|
+
* bakes in the repository, site and branch it serves (every pass must
|
|
33
|
+
* match them), Astro's base and the commit it was built from.
|
|
44
34
|
*/
|
|
45
35
|
const VIRTUAL_PREVIEW_OPTS = 'virtual:conloca-preview-opts';
|
|
46
36
|
const RESOLVED_PREVIEW_OPTS = `\0${VIRTUAL_PREVIEW_OPTS}`;
|
|
47
|
-
export function conlocaCloud(options) {
|
|
37
|
+
export function conlocaCloud(options = {}) {
|
|
48
38
|
validateOptions(options);
|
|
49
39
|
const repoUri = resolveRepositoryUri(options.repoUri, process.env);
|
|
50
40
|
// Populated during the preview build's config:setup and read by the virtual
|
|
51
41
|
// module below. Server-only — never reaches a browser bundle.
|
|
52
42
|
let previewOptsModule;
|
|
43
|
+
// The Astro command, recorded in config:setup: only `astro build` starts
|
|
44
|
+
// the preview build, so only it checks the preview adapter at config:done.
|
|
45
|
+
let astroCommand;
|
|
53
46
|
// The project root, captured in config:setup: astro:build:done only hands
|
|
54
47
|
// over the build's own outDir, but the siteStyles resolve against the root,
|
|
55
|
-
// and locating the CHILD build's client dir (for the editor
|
|
48
|
+
// and locating the CHILD build's client dir (for the editor page mirror)
|
|
56
49
|
// needs the root the child resolves against.
|
|
57
50
|
let projectRoot;
|
|
58
|
-
// Adapter name, finalized only at config:done
|
|
59
|
-
//
|
|
60
|
-
// entry is a plain bootable process (see discovery.ts).
|
|
51
|
+
// Adapter name, finalized only at config:done: the preview build reads it
|
|
52
|
+
// when previewBuild names no adapter of its own.
|
|
61
53
|
let adapterName;
|
|
62
|
-
// The site's Vite config, finalized at config:done: the
|
|
63
|
-
// through it, as they do in conlocaCMS's dev editor.
|
|
54
|
+
// The site's Vite config, finalized at config:done: the editor page and the
|
|
55
|
+
// siteStyles compile through it, as they do in conlocaCMS's dev editor. It
|
|
56
|
+
// holds the site's and integrations' plugins only; Astro adds its own core
|
|
57
|
+
// plugins to a separate config when it builds, so none reach the editor page.
|
|
64
58
|
let viteConfig;
|
|
59
|
+
// Astro's base, as written: the editor page's URLs sit below it.
|
|
60
|
+
let astroBase = '/';
|
|
61
|
+
// The editor options, settled at config:done: conlocaCMS publishes its
|
|
62
|
+
// channel from its own config:setup, which may run after ours.
|
|
63
|
+
let inherited;
|
|
64
|
+
// Whether the parent build starts the preview build, read with the adapter
|
|
65
|
+
// the child will use: previewBuild.adapter, else the project's own.
|
|
66
|
+
const previewMode = () => previewBuildMode(options.previewBuild, (options.previewBuild || undefined)?.adapter?.name ?? adapterName);
|
|
65
67
|
return {
|
|
66
68
|
name: PACKAGE_NAME,
|
|
67
69
|
hooks: {
|
|
68
|
-
'astro:config:setup': ({ logger, injectRoute, updateConfig, config, addMiddleware }) => {
|
|
70
|
+
'astro:config:setup': ({ logger, injectRoute, updateConfig, config, addMiddleware, command }) => {
|
|
69
71
|
// Optional-chained: unit tests drive this hook with a bare { logger }.
|
|
70
72
|
projectRoot = config?.root;
|
|
73
|
+
astroCommand = command;
|
|
71
74
|
// The agent skill: write-if-not-exists, fail-soft, and
|
|
72
75
|
// never from the recursive preview child (it would race the parent).
|
|
73
76
|
if (process.env[PREVIEW_BUILD_ENV_FLAG] !== '1' && config?.root) {
|
|
74
77
|
scaffoldSkill(fileURLToPath(config.root), logger);
|
|
75
78
|
}
|
|
76
|
-
logger.info(`integration registered (endpoint=${options.endpoint
|
|
79
|
+
logger.info(`integration registered (endpoint=${options.endpoint ?? DEFAULT_EDITOR_ENDPOINT})`);
|
|
77
80
|
// Only the recursive preview build (which sets PREVIEW_BUILD_ENV_FLAG)
|
|
78
|
-
// mounts the
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
// auth boundary). Without a secret there is nothing to scope, so skip.
|
|
81
|
+
// mounts the SSR catch-all that renders previews; a site's normal
|
|
82
|
+
// build never exposes it. The route is fixed and public: the signed
|
|
83
|
+
// pass, checked against what this build bakes in, is the lock.
|
|
82
84
|
if (process.env[PREVIEW_BUILD_ENV_FLAG] === '1') {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// artifact bakes the preview secret, so a wholesale static upload
|
|
159
|
-
// of dist/ must never be able to publish it — and Astro clears
|
|
160
|
-
// dist/ at the start of a build, which would wipe a sibling
|
|
161
|
-
// artifact parked inside it.
|
|
162
|
-
const previewOut = new URL(`${previewBuild.outDir ?? '.conloca/preview-server'}/`, config.root);
|
|
163
|
-
// The site's extra config goes through its OWN updateConfig
|
|
164
|
-
// call: Astro deep-merges successive calls (concatenating
|
|
165
|
-
// vite.plugins and integrations), whereas spreading it into the
|
|
166
|
-
// object below would shallow-replace whole keys — a user `vite`
|
|
167
|
-
// entry silently dropped the required virtual-module plugin.
|
|
168
|
-
// Ours comes second so the required scalars (output, outDir,
|
|
169
|
-
// build dirs) always win; previewBuild.outDir is the supported
|
|
170
|
-
// override for the artifact location.
|
|
171
|
-
if (previewBuild.config) {
|
|
172
|
-
updateConfig(previewBuild.config);
|
|
173
|
-
}
|
|
174
|
-
updateConfig({
|
|
175
|
-
output: 'server',
|
|
176
|
-
outDir: previewOut,
|
|
177
|
-
build: { client: new URL('client/', previewOut), server: new URL('server/', previewOut) },
|
|
178
|
-
vite: {
|
|
179
|
-
// The middleware dynamically imports Cloudflare's runtime
|
|
180
|
-
// module (binding transport). The Cloudflare adapter resolves
|
|
181
|
-
// the scheme itself; every other adapter's Rollup pass fails
|
|
182
|
-
// the child build on it unless externalized. Off Cloudflare
|
|
183
|
-
// Workers the runtime import rejects and the middleware falls
|
|
184
|
-
// back to the global fetch.
|
|
185
|
-
build: { rollupOptions: { external: [/^cloudflare:/] } },
|
|
186
|
-
// Starlight renders Steps, Tabs and FileTree with satteri's
|
|
187
|
-
// htmlToHast. On Cloudflare Workers satteri resolves to a
|
|
188
|
-
// binding that can be neither installed nor run on workerd, so the child
|
|
189
|
-
// build fails to resolve it — swap in a stand-in there. The
|
|
190
|
-
// target is an absolute path: a bare name would be looked up
|
|
191
|
-
// from the Starlight file, which cannot see this package in an
|
|
192
|
-
// isolated (non-hoisted) node_modules layout.
|
|
193
|
-
...(adapter.name === '@astrojs/cloudflare'
|
|
194
|
-
? {
|
|
195
|
-
resolve: {
|
|
196
|
-
alias: [
|
|
197
|
-
{
|
|
198
|
-
find: /^satteri$/,
|
|
199
|
-
replacement: resolveSatteriStandIn(),
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
},
|
|
203
|
-
}
|
|
204
|
-
: {}),
|
|
205
|
-
plugins: [
|
|
206
|
-
{
|
|
207
|
-
name: 'conloca-preview-opts',
|
|
208
|
-
resolveId(id) {
|
|
209
|
-
return id === VIRTUAL_PREVIEW_OPTS ? RESOLVED_PREVIEW_OPTS : undefined;
|
|
210
|
-
},
|
|
211
|
-
load(id) {
|
|
212
|
-
if (id !== RESOLVED_PREVIEW_OPTS)
|
|
213
|
-
return undefined;
|
|
214
|
-
// Read lazily so the values assigned above are captured.
|
|
215
|
-
return `export default ${JSON.stringify(previewOptsModule ?? {})};`;
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
},
|
|
220
|
-
// The adapter must ride in BOTH ways: as `adapter` because the
|
|
221
|
-
// build gate checks `config.adapter` before creating the SSR
|
|
222
|
-
// bundle, and as an integration because only the adapter's own
|
|
223
|
-
// astro:config:done hook calls setAdapter — which is what the
|
|
224
|
-
// build pipeline actually renders through. (Astro unshifts
|
|
225
|
-
// config.adapter into the integration list BEFORE any hook runs,
|
|
226
|
-
// so setting `adapter` alone here is too late for the hooks.)
|
|
227
|
-
// A project that is already SSR keeps its own adapter untouched.
|
|
228
|
-
...(previewBuild.adapter ? { adapter: previewBuild.adapter, integrations: [previewBuild.adapter] } : {}),
|
|
229
|
-
});
|
|
85
|
+
if (!repoUri) {
|
|
86
|
+
throw new Error(`${PACKAGE_NAME}: could not determine repository identity for the preview build ` +
|
|
87
|
+
'(build in a Git checkout or set repoUri as an advanced override)');
|
|
88
|
+
}
|
|
89
|
+
// The project's own checkout answers git, not the directory the
|
|
90
|
+
// build was started from.
|
|
91
|
+
const projectGit = (args) => gitOutput(args, fileURLToPath(config.root));
|
|
92
|
+
const buildRef = resolveBuildRef(process.env, projectGit);
|
|
93
|
+
if (!buildRef.branch) {
|
|
94
|
+
throw new Error(`${PACKAGE_NAME}: could not determine the branch the preview build serves (set CF_PAGES_BRANCH, ` +
|
|
95
|
+
'WORKERS_CI_BRANCH, VERCEL_GIT_COMMIT_REF or GITHUB_REF_NAME, or build in a git checkout on a branch)');
|
|
96
|
+
}
|
|
97
|
+
const siteId = resolveBuildSiteId({
|
|
98
|
+
contentRoot: process.env.CONLOCA_CONTENT_ROOT,
|
|
99
|
+
override: options.siteId,
|
|
100
|
+
});
|
|
101
|
+
injectRoute({
|
|
102
|
+
pattern: `${PREVIEW_ROUTE_SEGMENT}/[...path]`,
|
|
103
|
+
entrypoint: '@conloca/cloud-astro/preview-handler',
|
|
104
|
+
prerender: false,
|
|
105
|
+
});
|
|
106
|
+
// The route above is the ENTRY DOOR — the only URL the endpoint can
|
|
107
|
+
// link to before a cookie exists. This interceptor is the serving
|
|
108
|
+
// surface: once the init hop sets the `Path=/` cookie, the browser
|
|
109
|
+
// sends the credential on every same-origin request, so internal
|
|
110
|
+
// links keep rendering drafts instead of silently falling back to
|
|
111
|
+
// published content after one page view. Fail-open — an
|
|
112
|
+
// uncredentialed visitor gets the ordinary page.
|
|
113
|
+
addMiddleware({ entrypoint: '@conloca/cloud-astro/site-middleware', order: 'pre' });
|
|
114
|
+
// The commit this preview build's checkout holds: a PR build may
|
|
115
|
+
// check out a merge commit rather than the commit CI hands over.
|
|
116
|
+
// Page-status compares the branch's latest commit with it, so the
|
|
117
|
+
// endpoint diffs against the content actually serving, not a newer
|
|
118
|
+
// commit whose deploy never landed. A checkout commit the
|
|
119
|
+
// endpoint does not have makes it render from the branch instead.
|
|
120
|
+
const buildCommit = projectGit(['rev-parse', 'HEAD']) ?? buildRef.gitSha;
|
|
121
|
+
// Bake the middleware's configuration into the artifact. Every value
|
|
122
|
+
// is already known here — endpoint and audience are integration
|
|
123
|
+
// options; repository, site, branch, base and commit are what this
|
|
124
|
+
// build was made from, and every pass must match the first three —
|
|
125
|
+
// so a correctly built preview deployment needs NO env vars set on
|
|
126
|
+
// it. `saasIssuer` stays unbaked unless configured: it is a property
|
|
127
|
+
// of the endpoint, not of the site.
|
|
128
|
+
previewOptsModule = {
|
|
129
|
+
saasEndpoint: options.endpoint ?? DEFAULT_EDITOR_ENDPOINT,
|
|
130
|
+
// The token's `aud` is the repo URI this build resolved.
|
|
131
|
+
saasAudience: repoUri,
|
|
132
|
+
...(options.saasIssuer ? { saasIssuer: options.saasIssuer } : {}),
|
|
133
|
+
...(buildCommit ? { buildCommit } : {}),
|
|
134
|
+
repo: repoUri,
|
|
135
|
+
siteId,
|
|
136
|
+
branch: buildRef.branch,
|
|
137
|
+
base: config.base ?? '/',
|
|
138
|
+
};
|
|
139
|
+
// Preview-build path: the child build must emit an SSR
|
|
140
|
+
// artifact even when the primary build is fully static. Switch to
|
|
141
|
+
// server output, apply the preview adapter (the project's own
|
|
142
|
+
// adapter stays in force when it already has one), and write to a
|
|
143
|
+
// SEPARATE outDir so the child never clobbers the primary dist/.
|
|
144
|
+
const previewBuild = options.previewBuild || {};
|
|
145
|
+
const adapter = previewBuild.adapter ?? config.adapter;
|
|
146
|
+
// Throws for a missing adapter, or one the preview build is refused
|
|
147
|
+
// under — the parent already checked, this keeps the child honest.
|
|
148
|
+
previewBuildMode(previewBuild, adapter?.name);
|
|
149
|
+
// Astro allows exactly one deployment integration. Adding
|
|
150
|
+
// previewBuild.adapter next to the project's own would make the
|
|
151
|
+
// child build die on Astro's adapter-conflict error, which names
|
|
152
|
+
// neither this integration nor the option — fail here with the
|
|
153
|
+
// actual cause. The child inherits the project adapter, so the
|
|
154
|
+
// option is unnecessary on SSR projects.
|
|
155
|
+
if (previewBuild.adapter && config.adapter) {
|
|
156
|
+
const projectAdapterName = config.adapter.name;
|
|
157
|
+
throw new Error(`${PACKAGE_NAME}: previewBuild.adapter conflicts with the project's own adapter ` +
|
|
158
|
+
`(${projectAdapterName}) — Astro allows only one deployment integration per build. ` +
|
|
159
|
+
'Remove previewBuild.adapter; the preview build inherits the project adapter.');
|
|
230
160
|
}
|
|
161
|
+
// Trailing slash so URL-joining treats it as a directory. Astro
|
|
162
|
+
// derives build.client/build.server from outDir BEFORE hooks run,
|
|
163
|
+
// so overriding outDir alone still writes into the primary dist/ —
|
|
164
|
+
// all three must move together.
|
|
165
|
+
// OUTSIDE dist/ on purpose, against the original design: a
|
|
166
|
+
// wholesale static upload of dist/ must never publish the preview
|
|
167
|
+
// server — and Astro clears dist/ at the start of a build, which
|
|
168
|
+
// would wipe a sibling artifact parked inside it.
|
|
169
|
+
const previewOut = new URL(`${previewBuild.outDir ?? '.conloca/preview-server'}/`, config.root);
|
|
170
|
+
// The site's extra config goes through its OWN updateConfig
|
|
171
|
+
// call: Astro deep-merges successive calls (concatenating
|
|
172
|
+
// vite.plugins and integrations), whereas spreading it into the
|
|
173
|
+
// object below would shallow-replace whole keys — a user `vite`
|
|
174
|
+
// entry silently dropped the required virtual-module plugin.
|
|
175
|
+
// Ours comes second so the required scalars (output, outDir,
|
|
176
|
+
// build dirs) always win; previewBuild.outDir is the supported
|
|
177
|
+
// override for the artifact location.
|
|
178
|
+
if (previewBuild.config) {
|
|
179
|
+
updateConfig(previewBuild.config);
|
|
180
|
+
}
|
|
181
|
+
updateConfig({
|
|
182
|
+
output: 'server',
|
|
183
|
+
outDir: previewOut,
|
|
184
|
+
build: { client: new URL('client/', previewOut), server: new URL('server/', previewOut) },
|
|
185
|
+
vite: {
|
|
186
|
+
// The middleware dynamically imports Cloudflare's runtime
|
|
187
|
+
// module (binding transport). The Cloudflare adapter resolves
|
|
188
|
+
// the scheme itself; every other adapter's Rollup pass fails
|
|
189
|
+
// the child build on it unless externalized. Off Cloudflare
|
|
190
|
+
// Workers the runtime import rejects and the middleware falls
|
|
191
|
+
// back to the global fetch.
|
|
192
|
+
build: { rollupOptions: { external: [/^cloudflare:/] } },
|
|
193
|
+
// Starlight renders Steps, Tabs and FileTree with satteri's
|
|
194
|
+
// htmlToHast. On Cloudflare Workers satteri resolves to a
|
|
195
|
+
// binding that can be neither installed nor run on workerd, so the child
|
|
196
|
+
// build fails to resolve it — swap in a stand-in there. The
|
|
197
|
+
// target is an absolute path: a bare name would be looked up
|
|
198
|
+
// from the Starlight file, which cannot see this package in an
|
|
199
|
+
// isolated (non-hoisted) node_modules layout.
|
|
200
|
+
...(adapter?.name === '@astrojs/cloudflare'
|
|
201
|
+
? {
|
|
202
|
+
resolve: {
|
|
203
|
+
alias: [
|
|
204
|
+
{
|
|
205
|
+
find: /^satteri$/,
|
|
206
|
+
replacement: resolveSatteriStandIn(),
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
}
|
|
211
|
+
: {}),
|
|
212
|
+
plugins: [
|
|
213
|
+
{
|
|
214
|
+
name: 'conloca-preview-opts',
|
|
215
|
+
resolveId(id) {
|
|
216
|
+
return id === VIRTUAL_PREVIEW_OPTS ? RESOLVED_PREVIEW_OPTS : undefined;
|
|
217
|
+
},
|
|
218
|
+
load(id) {
|
|
219
|
+
if (id !== RESOLVED_PREVIEW_OPTS)
|
|
220
|
+
return undefined;
|
|
221
|
+
// Read lazily so the values assigned above are captured.
|
|
222
|
+
return `export default ${JSON.stringify(previewOptsModule ?? {})};`;
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
// The adapter must ride in BOTH ways: as `adapter` because the
|
|
228
|
+
// build gate checks `config.adapter` before creating the SSR
|
|
229
|
+
// bundle, and as an integration because only the adapter's own
|
|
230
|
+
// astro:config:done hook calls setAdapter — which is what the
|
|
231
|
+
// build pipeline actually renders through. (Astro unshifts
|
|
232
|
+
// config.adapter into the integration list BEFORE any hook runs,
|
|
233
|
+
// so setting `adapter` alone here is too late for the hooks.)
|
|
234
|
+
// A project that is already SSR keeps its own adapter untouched.
|
|
235
|
+
...(previewBuild.adapter ? { adapter: previewBuild.adapter, integrations: [previewBuild.adapter] } : {}),
|
|
236
|
+
});
|
|
231
237
|
}
|
|
232
238
|
},
|
|
233
239
|
/**
|
|
@@ -249,15 +255,12 @@ export function conlocaCloud(options) {
|
|
|
249
255
|
* record, runs AFTER the `export const prerender` source parse, and
|
|
250
256
|
* Astro reads `prerender` back after every integration has run.
|
|
251
257
|
*
|
|
252
|
-
* Gated on the
|
|
253
|
-
*
|
|
254
|
-
* static output would buy nothing.
|
|
258
|
+
* Gated on the flag, as the config hook is: only the preview build
|
|
259
|
+
* mounts the interceptor these routes must reach.
|
|
255
260
|
*/
|
|
256
261
|
'astro:route:setup': ({ route, logger }) => {
|
|
257
262
|
if (process.env[PREVIEW_BUILD_ENV_FLAG] !== '1')
|
|
258
263
|
return;
|
|
259
|
-
if (!process.env[PREVIEW_SECRET_ENV_FLAG])
|
|
260
|
-
return;
|
|
261
264
|
// `type` exists at runtime but is absent from the public RouteOptions
|
|
262
265
|
// type. Endpoints keep their prerendered data files: they emit no HTML
|
|
263
266
|
// to intercept, and one built from getStaticPaths would break on demand.
|
|
@@ -282,107 +285,56 @@ export function conlocaCloud(options) {
|
|
|
282
285
|
'astro:config:done': ({ config }) => {
|
|
283
286
|
adapterName = config.adapter?.name;
|
|
284
287
|
viteConfig = config.vite;
|
|
288
|
+
astroBase = config.base ?? '/';
|
|
289
|
+
inherited = resolveInheritedOptions(options, readEditorDescriptors());
|
|
290
|
+
// A refused or missing preview adapter fails `astro build` here,
|
|
291
|
+
// before the site builds, rather than after it. `astro dev`, `sync`
|
|
292
|
+
// and `preview` never start the preview build, so they are left
|
|
293
|
+
// alone. The child build checks its own.
|
|
294
|
+
if (astroCommand === 'build' && process.env[PREVIEW_BUILD_ENV_FLAG] !== '1')
|
|
295
|
+
previewMode();
|
|
285
296
|
},
|
|
286
297
|
'astro:build:done': async ({ dir, logger }) => {
|
|
287
298
|
if (process.env[PREVIEW_BUILD_ENV_FLAG] === '1') {
|
|
288
299
|
// The recursive preview build sets this flag on the child
|
|
289
|
-
// Astro process.
|
|
290
|
-
//
|
|
291
|
-
logger.info('skipping
|
|
300
|
+
// Astro process. Writing the editor page there again would race
|
|
301
|
+
// the parent, which mirrors its own copy in, so we short-circuit.
|
|
302
|
+
logger.info('skipping the editor page: recursive preview build detected');
|
|
292
303
|
return;
|
|
293
304
|
}
|
|
294
305
|
// Astro always runs the config hooks first. No fallback: compiling
|
|
295
306
|
// against the working directory would build the canvas stylesheet for
|
|
296
307
|
// the wrong project without a word.
|
|
297
|
-
if (projectRoot === undefined || viteConfig === undefined) {
|
|
308
|
+
if (projectRoot === undefined || viteConfig === undefined || inherited === undefined) {
|
|
298
309
|
throw new Error(`${PACKAGE_NAME}: astro:build:done ran before the config hooks recorded the project root and Vite config`);
|
|
299
310
|
}
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
// conlocaCMS and read off its channel. The scan runs here because the
|
|
303
|
-
// editor at the endpoint has no dev server to serve `/api/registry` from.
|
|
304
|
-
const descriptors = await resolveEditorDescriptors(logger);
|
|
305
|
-
const bundle = await bundleEditorAssets({
|
|
311
|
+
// The editor page: every build writes it.
|
|
312
|
+
await emitEditorPage({
|
|
306
313
|
dir: fileURLToPath(dir),
|
|
307
314
|
root: fileURLToPath(projectRoot),
|
|
315
|
+
base: astroBase,
|
|
308
316
|
vite: viteConfig,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
...(descriptors === undefined ? {} : { descriptors }),
|
|
317
|
+
endpoint: options.endpoint,
|
|
318
|
+
inherited,
|
|
319
|
+
repoUri,
|
|
320
|
+
siteIdOverride: options.siteId,
|
|
314
321
|
logger,
|
|
315
322
|
});
|
|
316
|
-
//
|
|
317
|
-
//
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
// not on `descriptors` — that is also undefined for a CMS build with
|
|
321
|
-
// no schemas module, MDX components or templates, which still has a
|
|
322
|
-
// Puck vocabulary. An unreadable channel already warned above.
|
|
323
|
-
const componentManifest = readEditorDescriptors(process.env) === undefined
|
|
324
|
-
? undefined
|
|
325
|
-
: await emitComponentManifest({
|
|
326
|
-
dir: fileURLToPath(dir),
|
|
327
|
-
puckConfigPath: options.puckConfigPath,
|
|
328
|
-
projectRoot: process.cwd(),
|
|
329
|
-
logger,
|
|
330
|
-
});
|
|
331
|
-
// Build-time style discovery: read the discovery
|
|
332
|
-
// route's rendered page, collect its CSS, run the shared wrapper
|
|
333
|
-
// heuristic; results ride registration below. Opt-in via the option —
|
|
334
|
-
// and fail-soft throughout: a build must never die over preview
|
|
335
|
-
// styling.
|
|
336
|
-
let discovery;
|
|
337
|
-
let routeCssArtifact;
|
|
338
|
-
if (options.fragmentPreviewRoute) {
|
|
339
|
-
const clientDir = fileURLToPath(dir);
|
|
340
|
-
const nodeEntry = fileURLToPath(new URL('../server/entry.mjs', dir));
|
|
341
|
-
discovery = await discoverStyleContext({
|
|
342
|
-
clientDir,
|
|
343
|
-
serverEntry: adapterName === '@astrojs/node' && existsSync(nodeEntry) ? nodeEntry : undefined,
|
|
344
|
-
route: options.fragmentPreviewRoute,
|
|
345
|
-
logger,
|
|
346
|
-
});
|
|
347
|
-
if (discovery?.routeCss) {
|
|
348
|
-
routeCssArtifact = await emitRouteCssArtifact(clientDir, discovery.routeCss, resolveDeploymentUrl(options), logger);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
const registration = await registerBuild(options, repoUri, bundle, logger, {
|
|
352
|
-
hostWrappers: discovery?.hostWrappers,
|
|
353
|
-
routeCssArtifact: routeCssArtifact?.stylesheet,
|
|
354
|
-
componentManifest,
|
|
355
|
-
});
|
|
356
|
-
let registeredSecret;
|
|
357
|
-
if ('missing' in registration)
|
|
358
|
-
reportSkippedRegistration(registration.missing, options, logger);
|
|
359
|
-
else
|
|
360
|
-
registeredSecret = registration.previewSecret;
|
|
361
|
-
if (options.previewBuild === false) {
|
|
362
|
-
// The site explicitly opted out of the recursive preview build.
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
// Prefer the secret returned by registration; the env override lets
|
|
366
|
-
// CI smoke-test the recursive build path without a reachable endpoint.
|
|
367
|
-
const previewSecret = registeredSecret ?? process.env[PREVIEW_SECRET_ENV_FLAG];
|
|
368
|
-
if (!previewSecret) {
|
|
323
|
+
// Strict opt-in: only a previewBuild given as an object starts the
|
|
324
|
+
// second build.
|
|
325
|
+
const previewBuild = options.previewBuild || undefined;
|
|
326
|
+
if (previewBuild === undefined || previewMode() === 'off')
|
|
369
327
|
return;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// The child build cannot compile the editor bundle itself (it
|
|
328
|
+
await spawnPreviewBuild(previewBuild);
|
|
329
|
+
// The child build cannot write the editor files itself (it
|
|
373
330
|
// short-circuits this hook — see the recursion guard above), but in
|
|
374
331
|
// a deployment that serves the site and the preview from one
|
|
375
332
|
// Cloudflare Worker its client dir is THE asset set serving the site,
|
|
376
|
-
// so the editor
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
await mirrorEditorAssets(fileURLToPath(dir), fileURLToPath(new URL('client/', previewOut)), [
|
|
382
|
-
...bundle.assetCorsPaths,
|
|
383
|
-
...(routeCssArtifact?.assetCorsPaths ?? []),
|
|
384
|
-
]);
|
|
385
|
-
logger.info('editor assets mirrored into the preview client dir');
|
|
333
|
+
// so the editor files must be there too. Mirror them from this build's dist.
|
|
334
|
+
const previewOut = new URL(`${previewBuild.outDir ?? '.conloca/preview-server'}/`, projectRoot);
|
|
335
|
+
const previewClient = fileURLToPath(new URL('client/', previewOut));
|
|
336
|
+
await mirrorEditorPage(fileURLToPath(dir), previewClient);
|
|
337
|
+
logger.info('editor page mirrored into the preview client dir');
|
|
386
338
|
},
|
|
387
339
|
},
|
|
388
340
|
};
|
|
@@ -397,142 +349,24 @@ function resolveSatteriStandIn() {
|
|
|
397
349
|
'Cloudflare preview build uses in place of satteri — is the package installed and built?', { cause });
|
|
398
350
|
}
|
|
399
351
|
}
|
|
400
|
-
/**
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const previewUrl = new URL(options.previewDomain.includes('://') ? options.previewDomain : `https://${options.previewDomain}`);
|
|
411
|
-
return previewUrl.origin;
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* ONE end-of-build block for a skipped registration — every prerequisite that
|
|
415
|
-
* was missing and what it costs — the last thing the integration prints.
|
|
416
|
-
* With `requireRegistration` it fails the build instead.
|
|
417
|
-
*/
|
|
418
|
-
function reportSkippedRegistration(missing, options, logger) {
|
|
419
|
-
const summary = [
|
|
420
|
-
`editor at ${options.endpoint} NOT updated by this build`,
|
|
421
|
-
...missing.map((prerequisite) => ` missing: ${prerequisite}`),
|
|
422
|
-
" consequence: registration was skipped, so the editor keeps serving the previous build of this branch (or the default branch's, or nothing, if neither was ever registered)",
|
|
423
|
-
' check: conloca doctor --live',
|
|
424
|
-
].join('\n');
|
|
425
|
-
if (options.requireRegistration) {
|
|
426
|
-
throw new Error(`${PACKAGE_NAME}: ${summary}\n requireRegistration is on, so this build fails.`);
|
|
427
|
-
}
|
|
428
|
-
logger.warn(summary);
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Registers the freshly built editor bundle at the endpoint. Soft-skip ONLY
|
|
432
|
-
* when registration was never attempted: the pre-request guards (no build
|
|
433
|
-
* token, no repo identity, no sha/branch, no base URL) each warn, and every
|
|
434
|
-
* missing prerequisite is returned at once, so one build names all that setup
|
|
435
|
-
* still lacks and an unregistered deploy still completes — the hook turns
|
|
436
|
-
* that into one end-of-build summary (or a failure under
|
|
437
|
-
* `requireRegistration`). Once a registration IS attempted, its failure
|
|
438
|
-
* FAILS THE BUILD: postRegistration throws on any
|
|
439
|
-
* deterministic 4xx and after exhausting the ≥500 retry backoff, and that
|
|
440
|
-
* error — carrying the HTTP status and response body — propagates. A green
|
|
441
|
-
* deploy whose registration silently went missing is the "deployed but
|
|
442
|
-
* editor unregistered" class this project exists to kill.
|
|
443
|
-
*/
|
|
444
|
-
async function registerBuild(options, repoUri, bundle, logger, discovery = {}) {
|
|
445
|
-
const missing = [];
|
|
446
|
-
const buildToken = options.buildToken ?? process.env[BUILD_TOKEN_ENV_VAR];
|
|
447
|
-
if (!buildToken) {
|
|
448
|
-
logger.warn(`skipping registration: no build token (set buildToken or ${BUILD_TOKEN_ENV_VAR})`);
|
|
449
|
-
missing.push(`build token (set buildToken or ${BUILD_TOKEN_ENV_VAR})`);
|
|
450
|
-
}
|
|
451
|
-
if (!repoUri) {
|
|
452
|
-
logger.warn('skipping registration: could not determine repository identity ' +
|
|
453
|
-
'(build in a supported CI environment or Git checkout, or set repoUri)');
|
|
454
|
-
missing.push('repository identity (build in a supported CI environment or Git checkout, or set repoUri)');
|
|
455
|
-
}
|
|
456
|
-
const { branch } = resolveBuildRef();
|
|
457
|
-
// CI may hand over the branch's latest commit to register; the checkout is what was built.
|
|
458
|
-
const commits = registrationCommits({
|
|
459
|
-
eventCommitSha: process.env.CF_PAGES_COMMIT_SHA,
|
|
460
|
-
checkoutCommitSha: gitOutput(['rev-parse', 'HEAD']),
|
|
461
|
-
});
|
|
462
|
-
const gitSha = commits.gitSha;
|
|
463
|
-
if (!gitSha || !branch) {
|
|
464
|
-
logger.warn('skipping registration: could not resolve the git sha/branch ' +
|
|
465
|
-
'(set CF_PAGES_COMMIT_SHA and CF_PAGES_BRANCH, or build inside a git checkout)');
|
|
466
|
-
missing.push('git sha/branch (set CF_PAGES_COMMIT_SHA and CF_PAGES_BRANCH, or build inside a git checkout)');
|
|
467
|
-
}
|
|
468
|
-
const deploymentUrl = resolveDeploymentUrl(options);
|
|
469
|
-
const baseUrl = deploymentUrl;
|
|
470
|
-
if (!baseUrl) {
|
|
471
|
-
logger.warn('skipping registration: no public base URL for the editor bundle (set previewDomain, publicBaseUrl, or CF_PAGES_URL)');
|
|
472
|
-
missing.push('public base URL for the editor bundle (set previewDomain, publicBaseUrl, or CF_PAGES_URL)');
|
|
473
|
-
}
|
|
474
|
-
// Restates the guards above, so the values below are typed as set.
|
|
475
|
-
if (!buildToken || !repoUri || !gitSha || !branch || !baseUrl)
|
|
476
|
-
return { missing };
|
|
477
|
-
// Resolve the deployable-site id (STRICT): a throw here FAILS THE BUILD —
|
|
478
|
-
// after the soft skip guards above, so only a build that is actually
|
|
479
|
-
// registering can die on it. A silently mis-attached registration points
|
|
480
|
-
// the editor at the wrong site, which is the same miss as never having
|
|
481
|
-
// registered at all. The channel is CONLOCA_CONTENT_ROOT (published by
|
|
482
|
-
// conlocaCMS); options.siteId is the CMS-less-build override.
|
|
483
|
-
const siteId = resolveBuildSiteId({
|
|
484
|
-
contentRoot: process.env.CONLOCA_CONTENT_ROOT,
|
|
485
|
-
override: options.siteId,
|
|
486
|
-
});
|
|
487
|
-
// NO catch: from here on the registration is ATTEMPTED, and an attempted
|
|
488
|
-
// registration's failure fails the build. postRegistration already retried
|
|
489
|
-
// transient (≥500 / network) failures with backoff; what escapes is either
|
|
490
|
-
// a deterministic 4xx (unknown siteId, bad token — fix and rebuild) or an
|
|
491
|
-
// exhausted retry budget, and the error message carries the HTTP status +
|
|
492
|
-
// response body verbatim.
|
|
493
|
-
logger.info('registering at the endpoint (transient failures retry, with up to ~2.5 minutes of waiting between attempts)');
|
|
494
|
-
const { previewSecret } = await postRegistration({
|
|
495
|
-
endpoint: options.endpoint,
|
|
496
|
-
buildToken,
|
|
497
|
-
repoUri,
|
|
498
|
-
gitSha,
|
|
499
|
-
siteId,
|
|
500
|
-
branch,
|
|
501
|
-
editorBundleUrl: new URL(bundle.url, baseUrl).toString(),
|
|
502
|
-
bundleHash: bundle.hash,
|
|
503
|
-
...(bundle.stylesheet === undefined
|
|
504
|
-
? {}
|
|
505
|
-
: {
|
|
506
|
-
stylesheetUrl: new URL(bundle.stylesheet.url, baseUrl).toString(),
|
|
507
|
-
stylesheetHash: bundle.stylesheet.hash,
|
|
508
|
-
}),
|
|
509
|
-
...(discovery.hostWrappers === undefined ? {} : { hostWrappers: discovery.hostWrappers }),
|
|
510
|
-
...(discovery.routeCssArtifact === undefined
|
|
511
|
-
? {}
|
|
512
|
-
: {
|
|
513
|
-
routeCssUrl: new URL(discovery.routeCssArtifact.url, baseUrl).toString(),
|
|
514
|
-
routeCssHash: discovery.routeCssArtifact.hash,
|
|
515
|
-
}),
|
|
516
|
-
...(discovery.componentManifest === undefined
|
|
517
|
-
? {}
|
|
518
|
-
: {
|
|
519
|
-
componentManifestUrl: new URL(discovery.componentManifest.url, baseUrl).toString(),
|
|
520
|
-
componentManifestHash: discovery.componentManifest.hash,
|
|
521
|
-
}),
|
|
522
|
-
deploymentUrl,
|
|
523
|
-
buildId: commits.buildId,
|
|
524
|
-
clientVersion: packageVersion(),
|
|
525
|
-
});
|
|
526
|
-
logger.info(`registration complete (gitSha=${gitSha}, branch=${branch}, buildId=${commits.buildId})`);
|
|
527
|
-
return { previewSecret };
|
|
528
|
-
}
|
|
352
|
+
/** The options the editor page made obsolete; naming one fails the build so the config gets updated. */
|
|
353
|
+
const REMOVED_OPTIONS = [
|
|
354
|
+
'buildToken',
|
|
355
|
+
'requireRegistration',
|
|
356
|
+
'publicBaseUrl',
|
|
357
|
+
'previewDomain',
|
|
358
|
+
'editorBundlePlugins',
|
|
359
|
+
'fragmentPreviewRoute',
|
|
360
|
+
];
|
|
361
|
+
/** Refuses a removed option, a malformed endpoint, or one that is not an `app.` address, at config load. */
|
|
529
362
|
function validateOptions(options) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
throw new Error(`${PACKAGE_NAME}: puckConfigPath is required`);
|
|
363
|
+
for (const name of REMOVED_OPTIONS) {
|
|
364
|
+
if (name in options) {
|
|
365
|
+
throw new Error(`${PACKAGE_NAME}: option "${name}" was removed — run \`npx @conloca/cli connect\` to update this config`);
|
|
366
|
+
}
|
|
535
367
|
}
|
|
368
|
+
if (options.endpoint === undefined)
|
|
369
|
+
return;
|
|
536
370
|
try {
|
|
537
371
|
// Throws on malformed URLs; we don't keep the parsed value.
|
|
538
372
|
new URL(options.endpoint);
|
|
@@ -540,5 +374,8 @@ function validateOptions(options) {
|
|
|
540
374
|
catch {
|
|
541
375
|
throw new Error(`${PACKAGE_NAME}: endpoint must be a valid URL, got ${options.endpoint}`);
|
|
542
376
|
}
|
|
377
|
+
if (editorUiOrigin(options.endpoint) === null) {
|
|
378
|
+
throw new Error(`${PACKAGE_NAME}: endpoint must be the workspace editor's app. address (for example https://app.conloca.com), got ${options.endpoint}`);
|
|
379
|
+
}
|
|
543
380
|
}
|
|
544
381
|
//# sourceMappingURL=integration.js.map
|