@conloca/cloud-astro 0.2.5 → 0.2.6
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 +69 -22
- package/dist/.build-inputs.json +36 -23
- package/dist/src/constants.d.ts +4 -4
- package/dist/src/constants.js +4 -4
- package/dist/src/d3-build.d.ts +6 -2
- package/dist/src/d3-build.d.ts.map +1 -1
- package/dist/src/d3-build.js +15 -11
- package/dist/src/d3-build.js.map +1 -1
- package/dist/src/d8-adapters.d.ts +10 -0
- package/dist/src/d8-adapters.d.ts.map +1 -0
- package/dist/src/d8-adapters.js +19 -0
- package/dist/src/d8-adapters.js.map +1 -0
- package/dist/src/d8-build.d.ts +99 -0
- package/dist/src/d8-build.d.ts.map +1 -0
- package/dist/src/d8-build.js +265 -0
- package/dist/src/d8-build.js.map +1 -0
- package/dist/src/d8-guards.d.ts +29 -0
- package/dist/src/d8-guards.d.ts.map +1 -0
- package/dist/src/d8-guards.js +145 -0
- package/dist/src/d8-guards.js.map +1 -0
- package/dist/src/d8-middleware.d.ts +7 -0
- package/dist/src/d8-middleware.d.ts.map +1 -0
- package/dist/src/d8-middleware.js +15 -0
- package/dist/src/d8-middleware.js.map +1 -0
- package/dist/src/d8-render.d.ts +9 -0
- package/dist/src/d8-render.d.ts.map +1 -0
- package/dist/src/d8-render.js +52 -0
- package/dist/src/d8-render.js.map +1 -0
- package/dist/src/doctor/checks-d8.d.ts +7 -0
- package/dist/src/doctor/checks-d8.d.ts.map +1 -0
- package/dist/src/doctor/checks-d8.js +240 -0
- package/dist/src/doctor/checks-d8.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +3 -5
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +2 -0
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +17 -8
- package/dist/src/doctor/checks-offline.js.map +1 -1
- package/dist/src/doctor/checks-preview-live.d.ts +7 -2
- package/dist/src/doctor/checks-preview-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-preview-live.js +107 -7
- package/dist/src/doctor/checks-preview-live.js.map +1 -1
- package/dist/src/doctor/checks-preview.d.ts.map +1 -1
- package/dist/src/doctor/checks-preview.js +9 -4
- package/dist/src/doctor/checks-preview.js.map +1 -1
- package/dist/src/doctor/config-scan.d.ts +24 -6
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +89 -18
- 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 +2 -0
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +7 -0
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +7 -0
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/emit.d.ts +4 -3
- package/dist/src/editor-page/emit.d.ts.map +1 -1
- package/dist/src/editor-page/emit.js +9 -9
- package/dist/src/editor-page/emit.js.map +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +228 -124
- package/dist/src/integration.js.map +1 -1
- package/dist/src/node.d.ts +2 -0
- package/dist/src/node.d.ts.map +1 -1
- package/dist/src/node.js +4 -0
- package/dist/src/node.js.map +1 -1
- package/dist/src/preview/_resolve-opts.d.ts +26 -1
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js.map +1 -1
- package/dist/src/preview/content-api.d.ts +15 -0
- package/dist/src/preview/content-api.d.ts.map +1 -1
- package/dist/src/preview/content-api.js +57 -6
- package/dist/src/preview/content-api.js.map +1 -1
- package/dist/src/preview/d8-middleware.d.ts +25 -0
- package/dist/src/preview/d8-middleware.d.ts.map +1 -0
- package/dist/src/preview/d8-middleware.js +94 -0
- package/dist/src/preview/d8-middleware.js.map +1 -0
- package/dist/src/preview/dispatcher.d.ts +3 -16
- package/dist/src/preview/dispatcher.d.ts.map +1 -1
- package/dist/src/preview/dispatcher.js +46 -134
- package/dist/src/preview/dispatcher.js.map +1 -1
- package/dist/src/preview/headers.d.ts +3 -0
- package/dist/src/preview/headers.d.ts.map +1 -1
- package/dist/src/preview/headers.js +10 -1
- package/dist/src/preview/headers.js.map +1 -1
- package/dist/src/preview/links.d.ts +23 -0
- package/dist/src/preview/links.d.ts.map +1 -0
- package/dist/src/preview/links.js +168 -0
- package/dist/src/preview/links.js.map +1 -0
- package/dist/src/preview/middleware.d.ts +9 -3
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +36 -16
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/prefix-router.d.ts +67 -0
- package/dist/src/preview/prefix-router.d.ts.map +1 -0
- package/dist/src/preview/prefix-router.js +153 -0
- package/dist/src/preview/prefix-router.js.map +1 -0
- package/dist/src/preview/preview-path.d.ts +8 -3
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +16 -4
- package/dist/src/preview/preview-path.js.map +1 -1
- package/dist/src/preview/site-middleware.d.ts +8 -2
- package/dist/src/preview/site-middleware.d.ts.map +1 -1
- package/dist/src/preview/site-middleware.js +90 -31
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview/site-page-sources.d.ts +21 -0
- package/dist/src/preview/site-page-sources.d.ts.map +1 -0
- package/dist/src/preview/site-page-sources.js +129 -0
- package/dist/src/preview/site-page-sources.js.map +1 -0
- package/dist/src/preview/site-pages.d.ts +18 -0
- package/dist/src/preview/site-pages.d.ts.map +1 -0
- package/dist/src/preview/site-pages.js +7 -0
- package/dist/src/preview/site-pages.js.map +1 -0
- package/dist/src/preview-build.d.ts +17 -16
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +37 -40
- package/dist/src/preview-build.js.map +1 -1
- package/dist/src/preview-image-endpoint.d.ts +8 -0
- package/dist/src/preview-image-endpoint.d.ts.map +1 -0
- package/dist/src/preview-image-endpoint.js +34 -0
- package/dist/src/preview-image-endpoint.js.map +1 -0
- package/dist/src/preview-render-seams.d.ts +7 -0
- package/dist/src/preview-render-seams.d.ts.map +1 -0
- package/dist/src/preview-render-seams.js +27 -0
- package/dist/src/preview-render-seams.js.map +1 -0
- package/dist/src/site-middleware.d.ts +2 -4
- package/dist/src/site-middleware.d.ts.map +1 -1
- package/dist/src/site-middleware.js +6 -22
- package/dist/src/site-middleware.js.map +1 -1
- package/dist/src/types.d.ts +15 -16
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +138 -6
- package/src/constants.ts +4 -4
- package/src/d3-build.ts +20 -14
- package/src/d8-adapters.ts +19 -0
- package/src/d8-build.ts +356 -0
- package/src/d8-guards.ts +177 -0
- package/src/d8-middleware.ts +17 -0
- package/src/d8-render.ts +61 -0
- package/src/doctor/checks-d8.ts +256 -0
- package/src/doctor/checks-live.ts +3 -4
- package/src/doctor/checks-offline.ts +21 -8
- package/src/doctor/checks-preview-live.ts +114 -8
- package/src/doctor/checks-preview.ts +9 -4
- package/src/doctor/config-scan.ts +86 -15
- package/src/doctor/run.ts +2 -0
- package/src/doctor/types.ts +8 -0
- package/src/editor-page/emit.ts +23 -14
- package/src/integration.ts +274 -135
- package/src/node.ts +4 -0
- package/src/preview/_resolve-opts.ts +17 -1
- package/src/preview/content-api.ts +60 -5
- package/src/preview/d8-middleware.ts +124 -0
- package/src/preview/dispatcher.ts +55 -150
- package/src/preview/headers.ts +10 -1
- package/src/preview/links.ts +175 -0
- package/src/preview/middleware.ts +41 -19
- package/src/preview/prefix-router.ts +197 -0
- package/src/preview/preview-path.ts +24 -6
- package/src/preview/site-middleware.ts +109 -38
- package/src/preview/site-page-sources.ts +146 -0
- package/src/preview/site-pages.ts +22 -0
- package/src/preview-build.ts +43 -42
- package/src/preview-image-endpoint.ts +35 -0
- package/src/preview-render-seams.ts +31 -0
- package/src/site-middleware.ts +6 -24
- package/src/skill/SKILL.md +19 -1
- package/src/types.ts +15 -16
- package/src/virtual-modules.d.ts +17 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
import { REFUSED_PREVIEW_ADAPTERS } from '../constants.js';
|
|
2
3
|
import type { DoctorDeps } from './types.js';
|
|
3
4
|
|
|
4
5
|
const ASTRO_CONFIG_NAMES = ['astro.config.mjs', 'astro.config.ts', 'astro.config.js'] as const;
|
|
@@ -23,7 +24,7 @@ function skipString(text: string, index: number): number {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** Blank out comments, keeping strings and offsets intact, so a commented-out option never counts as set. */
|
|
26
|
-
function stripComments(source: string): string {
|
|
27
|
+
export function stripComments(source: string): string {
|
|
27
28
|
const chars = source.split('');
|
|
28
29
|
let i = 0;
|
|
29
30
|
while (i < chars.length) {
|
|
@@ -49,7 +50,7 @@ function stripComments(source: string): string {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/** The balanced bracket slice starting at openIndex, or null when it never closes. */
|
|
52
|
-
function balancedSlice(text: string, openIndex: number): string | null {
|
|
53
|
+
export function balancedSlice(text: string, openIndex: number): string | null {
|
|
53
54
|
const closer = OPENERS[text[openIndex]];
|
|
54
55
|
let depth = 0;
|
|
55
56
|
let i = openIndex;
|
|
@@ -71,7 +72,7 @@ function balancedSlice(text: string, openIndex: number): string | null {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
/** True when `needle` appears in the text outside string literals. */
|
|
74
|
-
function containsOutsideStrings(text: string, needle: string): boolean {
|
|
75
|
+
export function containsOutsideStrings(text: string, needle: string): boolean {
|
|
75
76
|
let i = 0;
|
|
76
77
|
while (i < text.length) {
|
|
77
78
|
if (QUOTES.has(text[i])) {
|
|
@@ -139,6 +140,8 @@ interface ScannedConfig {
|
|
|
139
140
|
conlocaCloud: CallArgs;
|
|
140
141
|
conlocaCMS: CallArgs;
|
|
141
142
|
site: SiteSettings;
|
|
143
|
+
/** The whole config, comments blanked. */
|
|
144
|
+
text: string;
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
/** Astro's own settings, read without conlocaCloud's options: their previewBuild.adapter is not the site's. */
|
|
@@ -185,7 +188,13 @@ export function scanAstroConfig(projectDir: string, fs: ScanFs): ConfigScan {
|
|
|
185
188
|
const conlocaCloud = callArgs(text, 'conlocaCloud');
|
|
186
189
|
return {
|
|
187
190
|
kind: 'read',
|
|
188
|
-
config: {
|
|
191
|
+
config: {
|
|
192
|
+
path,
|
|
193
|
+
conlocaCloud,
|
|
194
|
+
conlocaCMS: callArgs(text, 'conlocaCMS'),
|
|
195
|
+
site: siteSettings(text, conlocaCloud),
|
|
196
|
+
text,
|
|
197
|
+
},
|
|
189
198
|
};
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -203,8 +212,9 @@ export function hasOption(scan: ConfigScan, key: string): boolean {
|
|
|
203
212
|
|
|
204
213
|
/**
|
|
205
214
|
* conlocaCloud's previewBuild as the text shows it: 'off' when absent or written as false (the preview build is
|
|
206
|
-
* opt-in), 'adapter' when
|
|
207
|
-
* an options object without one, and 'unknown' when computed or when a
|
|
215
|
+
* opt-in), 'adapter' when previewBuild's own object names an adapter (written out or as shorthand; one nested in
|
|
216
|
+
* `config` is not previewBuild's), 'on' for an options object without one, and 'unknown' when computed or when a
|
|
217
|
+
* spread could set it.
|
|
208
218
|
*/
|
|
209
219
|
export function previewBuildSetting(scan: ConfigScan): 'off' | 'adapter' | 'on' | 'unknown' {
|
|
210
220
|
if (scan.kind !== 'read' || typeof scan.config.conlocaCloud === 'string') return 'unknown';
|
|
@@ -212,20 +222,81 @@ export function previewBuildSetting(scan: ConfigScan): 'off' | 'adapter' | 'on'
|
|
|
212
222
|
const value = /\bpreviewBuild\s*:\s*(false\b|\{)?/.exec(text);
|
|
213
223
|
if (value === null) return spread || containsOutsideStrings(text, 'previewBuild') ? 'unknown' : 'off';
|
|
214
224
|
if (value[1] === 'false') return 'off';
|
|
215
|
-
if (
|
|
216
|
-
|
|
225
|
+
if (value[1] !== '{') return 'unknown';
|
|
226
|
+
const options = balancedSlice(text, value.index + value[0].length - 1);
|
|
227
|
+
if (options === null) return 'unknown';
|
|
228
|
+
return hasTopLevelKey(options, 'adapter') ? 'adapter' : 'on';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Whether the object literal `objectText` has `key` at its own top level, written out or as shorthand. */
|
|
232
|
+
function hasTopLevelKey(objectText: string, key: string): boolean {
|
|
233
|
+
let depth = 0;
|
|
234
|
+
let i = 0;
|
|
235
|
+
while (i < objectText.length) {
|
|
236
|
+
const ch = objectText[i];
|
|
237
|
+
if (QUOTES.has(ch)) {
|
|
238
|
+
i = skipString(objectText, i);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (OPENERS[ch]) depth += 1;
|
|
242
|
+
else if (CLOSERS.has(ch)) depth -= 1;
|
|
243
|
+
else if (
|
|
244
|
+
depth === 1 &&
|
|
245
|
+
objectText.startsWith(key, i) &&
|
|
246
|
+
/[{,]\s*$/u.test(objectText.slice(0, i)) &&
|
|
247
|
+
/^\s*[:,}]/u.test(objectText.slice(i + key.length))
|
|
248
|
+
) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
i += 1;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
217
254
|
}
|
|
218
255
|
|
|
219
256
|
/**
|
|
220
|
-
* How the preview build serves, as the config text shows it (the rule of `previewBuildMode`):
|
|
221
|
-
*
|
|
222
|
-
* tell.
|
|
257
|
+
* How the preview build serves, as the config text shows it (the rule of `previewBuildMode`): previewBuild.adapter
|
|
258
|
+
* turns preview off ('unknown' here, CC26 names it), `separate: true` is D4, the site's own adapter is d8, a static
|
|
259
|
+
* site is D3; 'unknown' when the text cannot tell.
|
|
223
260
|
*/
|
|
224
|
-
export function previewServeSetting(scan: ConfigScan): 'off' | '
|
|
261
|
+
export function previewServeSetting(scan: ConfigScan): 'off' | 'd3' | 'd4' | 'd8' | 'unknown' {
|
|
225
262
|
const setting = previewBuildSetting(scan);
|
|
226
|
-
if (setting === 'off'
|
|
263
|
+
if (setting === 'off') return 'off';
|
|
264
|
+
if (setting !== 'on') return 'unknown';
|
|
227
265
|
if (scan.kind !== 'read' || typeof scan.config.conlocaCloud === 'string') return 'unknown';
|
|
228
|
-
|
|
229
|
-
if (
|
|
266
|
+
// The build refuses separate: true under an adapter that deploys from the project root, so no D4 runs.
|
|
267
|
+
if (/\bseparate\s*:\s*true\b/u.test(scan.config.conlocaCloud.text)) {
|
|
268
|
+
return separateRefused(scan) === undefined ? 'd4' : 'unknown';
|
|
269
|
+
}
|
|
270
|
+
if (scan.config.site.adapter) return 'd8';
|
|
230
271
|
return scan.config.site.output === 'unknown' ? 'unknown' : 'd3';
|
|
231
272
|
}
|
|
273
|
+
|
|
274
|
+
/** The site's adapter when previewBuild asks for `separate: true` under one the build refuses it for; else undefined. */
|
|
275
|
+
export function separateRefused(scan: ConfigScan): string | undefined {
|
|
276
|
+
if (scan.kind !== 'read' || typeof scan.config.conlocaCloud === 'string') return undefined;
|
|
277
|
+
if (!/\bseparate\s*:\s*true\b/u.test(scan.config.conlocaCloud.text)) return undefined;
|
|
278
|
+
const adapter = siteAdapter(scan);
|
|
279
|
+
return adapter && REFUSED_PREVIEW_ADAPTERS.includes(adapter) ? adapter : undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The package of the site's adapter, from `adapter: <name>(...)` and the default import of `<name>`; null when the
|
|
284
|
+
* text names an adapter it does not show that way (a variable, a named import), undefined when there is none.
|
|
285
|
+
*/
|
|
286
|
+
export function siteAdapter(scan: ReadScan): string | null | undefined {
|
|
287
|
+
if (!scan.config.site.adapter) return undefined;
|
|
288
|
+
const { text, conlocaCloud } = scan.config;
|
|
289
|
+
const own = typeof conlocaCloud === 'string' ? text : text.replace(conlocaCloud.text, '');
|
|
290
|
+
const call = /\badapter\s*:\s*([$A-Za-z_][$\w]*)\s*\(/u.exec(own)?.[1];
|
|
291
|
+
if (call === undefined) return null;
|
|
292
|
+
const from = new RegExp(`\\bimport\\s+${call.replaceAll('$', '\\$')}\\s+from\\s+['"]([^'"]+)['"]`, 'u').exec(text);
|
|
293
|
+
return from?.[1] ?? null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** previewBuild's object literal as written, or undefined when it is absent or not an object. */
|
|
297
|
+
export function previewBuildText(scan: ReadScan): string | undefined {
|
|
298
|
+
const { conlocaCloud } = scan.config;
|
|
299
|
+
if (typeof conlocaCloud === 'string') return undefined;
|
|
300
|
+
const key = /\bpreviewBuild\s*:\s*\{/u.exec(conlocaCloud.text);
|
|
301
|
+
return key === null ? undefined : (balancedSlice(conlocaCloud.text, key.index + key[0].length - 1) ?? undefined);
|
|
302
|
+
}
|
package/src/doctor/run.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { gitOutput, resolveRepositoryUri } from '../git.js';
|
|
3
3
|
import { checkFramingHeaders, checkKeyLeftovers, checkSiteAddress } from './checks-address.js';
|
|
4
|
+
import { runD8Checks } from './checks-d8.js';
|
|
4
5
|
import { runLiveChecks } from './checks-live.js';
|
|
5
6
|
import { checkPreviewBuildAdapter, checkWiring, suppliedEndpoint } from './checks-offline.js';
|
|
6
7
|
import { runPreviewChecks } from './checks-preview.js';
|
|
@@ -35,6 +36,7 @@ export async function runDoctor(
|
|
|
35
36
|
checkPreviewBuildAdapter(scan),
|
|
36
37
|
...runPreviewChecks(scan, context.projectDir, deps),
|
|
37
38
|
...runPreviewLimitChecks(scan, context.projectDir, deps),
|
|
39
|
+
...runD8Checks(scan, context.projectDir, deps),
|
|
38
40
|
...(await runLiveChecks({ context, deps, scan, address: site.address, repoUri })),
|
|
39
41
|
];
|
|
40
42
|
return { contractVersion: 1, checks };
|
package/src/doctor/types.ts
CHANGED
|
@@ -63,15 +63,23 @@ const CHECK_LABELS = {
|
|
|
63
63
|
CC21: 'no tag manager runs on draft pages',
|
|
64
64
|
CC22: "the preview route's rate limit fits the plan",
|
|
65
65
|
CC23: 'the recorded Cloudflare plan fits draft previews',
|
|
66
|
+
CC25: 'the adapter is one draft preview supports',
|
|
67
|
+
CC26: 'nothing in astro.config turns draft preview off',
|
|
68
|
+
CC27: 'the host routes the preview as d8 needs',
|
|
69
|
+
CC28: 'the Node server allows the site domains',
|
|
66
70
|
CC11: 'the deployed editor page answers',
|
|
67
71
|
CC12: 'the deployed editor page may be framed',
|
|
68
72
|
CC13: "the editor speaks this page's protocol",
|
|
69
73
|
CC24: 'the separate preview deploy runs this release',
|
|
74
|
+
CC29: "the site's preview route answers, uncached",
|
|
70
75
|
} as const;
|
|
71
76
|
|
|
72
77
|
/** A typo in a check id fails tsc here; the CLI would otherwise drop a label-less outcome silently. */
|
|
73
78
|
export type CheckId = keyof typeof CHECK_LABELS;
|
|
74
79
|
|
|
80
|
+
/** Every doctor request is bounded: a hanging host must never hang `conloca doctor` (the CLI seam has no timer of its own). */
|
|
81
|
+
export const REQUEST_TIMEOUT_MS = 10_000;
|
|
82
|
+
|
|
75
83
|
export function outcomeOf(id: CheckId): CheckOutcome {
|
|
76
84
|
return { id, label: CHECK_LABELS[id], problems: [] };
|
|
77
85
|
}
|
package/src/editor-page/emit.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
-
import {
|
|
3
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
5
5
|
import {
|
|
6
6
|
type AstroI18nLocales,
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
branchDeploysOf,
|
|
16
16
|
CONLOCA_JSON_MAX_BYTES,
|
|
17
17
|
contentPathsOf,
|
|
18
|
+
type DeployHost,
|
|
19
|
+
deployHostFromEnv,
|
|
18
20
|
EDITOR_HOST_PROTOCOL,
|
|
19
21
|
EDITOR_PAGE_INFO_FORMATS,
|
|
20
22
|
type EditorMedia,
|
|
@@ -160,13 +162,16 @@ export async function emitEditorPage(input: EmitEditorPageInput): Promise<void>
|
|
|
160
162
|
}
|
|
161
163
|
const branchDeploys = branchDeploysFromEnv(process.env);
|
|
162
164
|
const preview: PreviewSignal = { mode: input.previewMode, protocol: PREVIEW_PROTOCOL };
|
|
163
|
-
const written
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
const written = withDeployHost(
|
|
166
|
+
{
|
|
167
|
+
...info,
|
|
168
|
+
preview,
|
|
169
|
+
...(branchDeploys === undefined ? {} : { branchDeploys }),
|
|
170
|
+
...(contentPaths === undefined ? {} : { contentPaths }),
|
|
171
|
+
...(media === undefined ? {} : { media }),
|
|
172
|
+
},
|
|
173
|
+
process.env,
|
|
174
|
+
);
|
|
170
175
|
const collected = await collectStaticPageRoutes({
|
|
171
176
|
pagesDir: input.pagesDir,
|
|
172
177
|
serverOutput: input.serverOutput,
|
|
@@ -198,12 +203,6 @@ export async function emitEditorPage(input: EmitEditorPageInput): Promise<void>
|
|
|
198
203
|
logger.info(`editor page written: ${base}${EDITOR_DIR}/`);
|
|
199
204
|
}
|
|
200
205
|
|
|
201
|
-
/** Copies <from>/_conloca/editor into <to>, for a preview child whose client folder serves the site. */
|
|
202
|
-
export async function mirrorEditorPage(fromDir: string, toDir: string): Promise<void> {
|
|
203
|
-
await mkdir(join(toDir, '_conloca'), { recursive: true });
|
|
204
|
-
await cp(join(fromDir, EDITOR_DIR), join(toDir, EDITOR_DIR), { recursive: true });
|
|
205
|
-
}
|
|
206
|
-
|
|
207
206
|
/**
|
|
208
207
|
* A separate preview deploy (D4) serves no editor page, but it answers its own conloca.json: its release, protocol
|
|
209
208
|
* and mode, read next to the site's to tell when the two deploys run different releases.
|
|
@@ -242,6 +241,15 @@ export function branchDeploysFromEnv(env: Record<string, string | undefined>): B
|
|
|
242
241
|
return project === undefined ? undefined : branchDeploysOf({ branchDeploys: { host: 'cloudflare-pages', project } });
|
|
243
242
|
}
|
|
244
243
|
|
|
244
|
+
/** `written` with the host whose CI runs this build, so a local build writes no `host`. */
|
|
245
|
+
export function withDeployHost(
|
|
246
|
+
written: WrittenConlocaJson,
|
|
247
|
+
env: Record<string, string | undefined>,
|
|
248
|
+
): WrittenConlocaJson {
|
|
249
|
+
const host = deployHostFromEnv(env);
|
|
250
|
+
return host === undefined ? written : { ...written, host };
|
|
251
|
+
}
|
|
252
|
+
|
|
245
253
|
/** Each content path under the repository root, written from that root ('' for the root itself); others are dropped. */
|
|
246
254
|
export function contentPathsFromBuild(paths: readonly string[], repoRoot: string | undefined): string[] | undefined {
|
|
247
255
|
if (repoRoot === undefined) return undefined;
|
|
@@ -258,6 +266,7 @@ export function contentPathsFromBuild(paths: readonly string[], repoRoot: string
|
|
|
258
266
|
export interface WrittenConlocaJson extends EditorPageInfo {
|
|
259
267
|
preview: PreviewSignal;
|
|
260
268
|
branchDeploys?: BranchDeploys;
|
|
269
|
+
host?: DeployHost;
|
|
261
270
|
contentPaths?: string[];
|
|
262
271
|
media?: EditorMedia;
|
|
263
272
|
}
|