@conloca/cloud-astro 0.2.5 → 0.3.0
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 +75 -24
- package/dist/.build-inputs.json +47 -29
- package/dist/src/component-manifest.d.ts +11 -0
- package/dist/src/component-manifest.d.ts.map +1 -1
- package/dist/src/component-manifest.js +20 -2
- package/dist/src/component-manifest.js.map +1 -1
- 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/descriptors.d.ts.map +1 -1
- package/dist/src/descriptors.js +6 -2
- package/dist/src/descriptors.js.map +1 -1
- package/dist/src/doctor/ancestor-chain.d.ts +14 -0
- package/dist/src/doctor/ancestor-chain.d.ts.map +1 -0
- package/dist/src/doctor/ancestor-chain.js +57 -0
- package/dist/src/doctor/ancestor-chain.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-frames.d.ts +5 -0
- package/dist/src/doctor/checks-frames.d.ts.map +1 -0
- package/dist/src/doctor/checks-frames.js +78 -0
- package/dist/src/doctor/checks-frames.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts +5 -14
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +9 -21
- 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/request.d.ts +14 -0
- package/dist/src/doctor/request.d.ts.map +1 -0
- package/dist/src/doctor/request.js +17 -0
- package/dist/src/doctor/request.js.map +1 -0
- 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 +8 -0
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +8 -0
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +4 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -1
- package/dist/src/editor-page/bundle.js +55 -7
- package/dist/src/editor-page/bundle.js.map +1 -1
- package/dist/src/editor-page/data-schemas.d.ts +19 -5
- package/dist/src/editor-page/data-schemas.d.ts.map +1 -1
- package/dist/src/editor-page/data-schemas.js +17 -13
- package/dist/src/editor-page/data-schemas.js.map +1 -1
- package/dist/src/editor-page/emit.d.ts +7 -3
- package/dist/src/editor-page/emit.d.ts.map +1 -1
- package/dist/src/editor-page/emit.js +36 -19
- package/dist/src/editor-page/emit.js.map +1 -1
- package/dist/src/editor-page/frame-chains.d.ts +51 -0
- package/dist/src/editor-page/frame-chains.d.ts.map +1 -0
- package/dist/src/editor-page/frame-chains.js +121 -0
- package/dist/src/editor-page/frame-chains.js.map +1 -0
- package/dist/src/editor-page/page.d.ts +1 -3
- package/dist/src/editor-page/page.d.ts.map +1 -1
- package/dist/src/editor-page/page.js +3 -5
- package/dist/src/editor-page/page.js.map +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +231 -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/banner.d.ts +3 -2
- package/dist/src/preview/banner.d.ts.map +1 -1
- package/dist/src/preview/banner.js +15 -6
- package/dist/src/preview/banner.js.map +1 -1
- package/dist/src/preview/content-api.d.ts +23 -1
- package/dist/src/preview/content-api.d.ts.map +1 -1
- package/dist/src/preview/content-api.js +73 -7
- 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 +54 -136
- 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 +95 -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/unready-pages.d.ts +21 -0
- package/dist/src/preview/unready-pages.d.ts.map +1 -0
- package/dist/src/preview/unready-pages.js +54 -0
- package/dist/src/preview/unready-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/component-manifest.ts +30 -4
- 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/descriptors.ts +6 -2
- package/src/doctor/ancestor-chain.ts +58 -0
- package/src/doctor/checks-d8.ts +256 -0
- package/src/doctor/checks-frames.ts +84 -0
- package/src/doctor/checks-live.ts +10 -39
- 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/request.ts +27 -0
- package/src/doctor/run.ts +2 -0
- package/src/doctor/types.ts +9 -0
- package/src/editor-page/bundle.ts +65 -7
- package/src/editor-page/data-schemas.ts +30 -16
- package/src/editor-page/emit.ts +52 -24
- package/src/editor-page/frame-chains.ts +143 -0
- package/src/editor-page/page.ts +3 -4
- package/src/integration.ts +277 -135
- package/src/node.ts +4 -0
- package/src/preview/_resolve-opts.ts +17 -1
- package/src/preview/banner.ts +17 -4
- package/src/preview/content-api.ts +78 -6
- package/src/preview/d8-middleware.ts +124 -0
- package/src/preview/dispatcher.ts +63 -153
- 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 +114 -38
- package/src/preview/site-page-sources.ts +146 -0
- package/src/preview/site-pages.ts +22 -0
- package/src/preview/unready-pages.ts +65 -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 +25 -2
- package/src/types.ts +15 -16
- package/src/virtual-modules.d.ts +17 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isRecord } from '@conloca/content-api/component-vocabulary';
|
|
2
|
+
import { EDITOR_PAGE_PATH } from '@conloca/content-api/editor-host';
|
|
3
|
+
import { type AncestorElement, ancestorChain, formatChain } from './ancestor-chain.js';
|
|
4
|
+
import { type LiveInput, request } from './request.js';
|
|
5
|
+
import { type CheckOutcome, outcomeOf, skipped } from './types.js';
|
|
6
|
+
|
|
7
|
+
const NO_FRAMES = 'no routing entry declares an editor frame';
|
|
8
|
+
|
|
9
|
+
function isAncestorElement(value: unknown): value is AncestorElement {
|
|
10
|
+
return (
|
|
11
|
+
isRecord(value) &&
|
|
12
|
+
typeof value.tag === 'string' &&
|
|
13
|
+
Array.isArray(value.classes) &&
|
|
14
|
+
value.classes.every((c) => typeof c === 'string')
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A frames.json entry this check can read; anything else is dropped. */
|
|
19
|
+
function framedEntries(value: unknown): { route: string; pathname: string; chain: string }[] {
|
|
20
|
+
if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.entries)) return [];
|
|
21
|
+
return value.entries.flatMap((entry: unknown) =>
|
|
22
|
+
isRecord(entry) &&
|
|
23
|
+
typeof entry.route === 'string' &&
|
|
24
|
+
typeof entry.pathname === 'string' &&
|
|
25
|
+
entry.pathname.startsWith('/') &&
|
|
26
|
+
Array.isArray(entry.chain) &&
|
|
27
|
+
entry.chain.every(isAncestorElement)
|
|
28
|
+
? [{ route: entry.route, pathname: entry.pathname, chain: formatChain(entry.chain) }]
|
|
29
|
+
: [],
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** CC30 — each framed route's published page still sits in the elements its editor frame renders. Only warns. */
|
|
34
|
+
export async function checkEditorFrames(input: LiveInput, address: string): Promise<CheckOutcome> {
|
|
35
|
+
const fetchFn = input.deps.fetch;
|
|
36
|
+
const answer = await request(fetchFn, `${address}${EDITOR_PAGE_PATH.slice(1)}frames.json`);
|
|
37
|
+
let file: unknown;
|
|
38
|
+
if (!(answer instanceof Error) && answer.status === 200) {
|
|
39
|
+
try {
|
|
40
|
+
file = await answer.json();
|
|
41
|
+
} catch {
|
|
42
|
+
file = undefined;
|
|
43
|
+
}
|
|
44
|
+
} else if (!(answer instanceof Error)) {
|
|
45
|
+
await answer.body?.cancel().catch(() => {});
|
|
46
|
+
}
|
|
47
|
+
const entries = framedEntries(file);
|
|
48
|
+
if (entries.length === 0) return skipped('CC30', NO_FRAMES);
|
|
49
|
+
const outcome = outcomeOf('CC30');
|
|
50
|
+
const warn = (message: string) => outcome.problems.push({ check: 'CC30', level: 'warn', message });
|
|
51
|
+
// One page at a time: the doctor keeps its load on a live site to a single request.
|
|
52
|
+
/* oxlint-disable no-await-in-loop -- see above. */
|
|
53
|
+
for (const { route, pathname, chain } of entries) {
|
|
54
|
+
const url = `${address}${pathname.slice(1)}`;
|
|
55
|
+
const page = await request(fetchFn, url);
|
|
56
|
+
if (page instanceof Error) {
|
|
57
|
+
warn(`${url} could not be reached (${page.message})`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (page.status >= 300 && page.status < 400) {
|
|
61
|
+
await page.body?.cancel().catch(() => {});
|
|
62
|
+
warn(
|
|
63
|
+
`${url} redirects to ${page.headers.get('location') ?? 'nowhere'}, so the frame of ${route} cannot be compared`,
|
|
64
|
+
);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (!page.ok) {
|
|
68
|
+
await page.body?.cancel().catch(() => {});
|
|
69
|
+
warn(`${url} answered HTTP ${page.status}, so the frame of ${route} cannot be compared`);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const found = ancestorChain(await page.text());
|
|
73
|
+
if (found === undefined) {
|
|
74
|
+
warn(
|
|
75
|
+
`${url} lacks data-conloca-page-root, so the frame of ${route} cannot be compared (an old build, or a page another handler serves)`,
|
|
76
|
+
);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const actual = formatChain(found);
|
|
80
|
+
if (actual !== chain) warn(`${route} (${pathname}): the frame renders ${chain} but the page has ${actual}`);
|
|
81
|
+
}
|
|
82
|
+
/* oxlint-enable no-await-in-loop */
|
|
83
|
+
return outcome;
|
|
84
|
+
}
|
|
@@ -10,53 +10,22 @@ import {
|
|
|
10
10
|
} from '@conloca/content-api/editor-host';
|
|
11
11
|
import { messageOf } from '../message-of.js';
|
|
12
12
|
import { resolveBuildSiteId } from '../site-id.js';
|
|
13
|
+
import { checkEditorFrames } from './checks-frames.js';
|
|
13
14
|
import { INTEGRATION_NOT_CALLED, suppliedEndpoint } from './checks-offline.js';
|
|
14
15
|
import { runPreviewLiveChecks } from './checks-preview-live.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
type CheckOutcome,
|
|
19
|
-
type CloudDoctorContext,
|
|
20
|
-
type DoctorDeps,
|
|
21
|
-
outcomeOf,
|
|
22
|
-
skipped,
|
|
23
|
-
} from './types.js';
|
|
16
|
+
import { optionLiteral } from './config-scan.js';
|
|
17
|
+
import { type LiveInput, request } from './request.js';
|
|
18
|
+
import { type CheckId, type CheckOutcome, type DoctorDeps, outcomeOf, skipped } from './types.js';
|
|
24
19
|
|
|
25
|
-
const LIVE_CHECK_IDS: readonly CheckId[] = ['CC11', 'CC12', 'CC13', 'CC24'];
|
|
20
|
+
const LIVE_CHECK_IDS: readonly CheckId[] = ['CC11', 'CC12', 'CC13', 'CC24', 'CC29', 'CC30'];
|
|
26
21
|
|
|
27
|
-
/** Every doctor request is bounded: a hanging host must never hang `conloca doctor` (the CLI seam has no timer of its own). */
|
|
28
|
-
const REQUEST_TIMEOUT_MS = 10_000;
|
|
29
22
|
/** The server probe's conloca.json cap; a longer answer reads as `invalid` here as there. */
|
|
30
23
|
const CONLOCA_JSON_CAP_BYTES = 16 * 1024;
|
|
31
24
|
/** CC11 judges everything but the protocol; CC13 holds that against the range the editor publishes. */
|
|
32
25
|
const ANY_PROTOCOL = { min: Number.NEGATIVE_INFINITY, max: Number.POSITIVE_INFINITY };
|
|
33
26
|
|
|
34
|
-
interface LiveInput {
|
|
35
|
-
context: CloudDoctorContext;
|
|
36
|
-
deps: DoctorDeps;
|
|
37
|
-
scan: ConfigScan;
|
|
38
|
-
/** CC9's verdict: `https://<host><base>`, undefined when CC9 failed. */
|
|
39
|
-
address: string | undefined;
|
|
40
|
-
/** What the build writes as `repo`, undefined when it cannot tell. */
|
|
41
|
-
repoUri: string | undefined;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
27
|
const skipAll = (reason: string): CheckOutcome[] => LIVE_CHECK_IDS.map((id) => skipped(id, reason));
|
|
45
28
|
|
|
46
|
-
/** GET with no credential and no followed redirect: the answer the server's probe would see. */
|
|
47
|
-
async function request(fetchFn: DoctorDeps['fetch'], url: string): Promise<Response | Error> {
|
|
48
|
-
try {
|
|
49
|
-
return await fetchFn(url, {
|
|
50
|
-
method: 'GET',
|
|
51
|
-
redirect: 'manual',
|
|
52
|
-
credentials: 'omit',
|
|
53
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
54
|
-
});
|
|
55
|
-
} catch (error) {
|
|
56
|
-
return new Error(messageOf(error));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
29
|
/** A 200 body as text when it fits in `CONLOCA_JSON_CAP_BYTES`, else null; reading stops at the cap, as the probe's does. */
|
|
61
30
|
async function cappedText(answer: Response): Promise<string | null> {
|
|
62
31
|
if (answer.status !== 200) {
|
|
@@ -296,8 +265,9 @@ async function checkProtocol(
|
|
|
296
265
|
}
|
|
297
266
|
|
|
298
267
|
/**
|
|
299
|
-
* CC11–CC13 and
|
|
300
|
-
* editor UI's public protocols.json and the site's previewUrl, so it runs anywhere, forks and Dependabot
|
|
268
|
+
* CC11–CC13, CC24, CC29 and CC30. Networks only under --live and sends no credential: it contacts only the site's own
|
|
269
|
+
* domain, the editor UI's public protocols.json and the site's previewUrl, so it runs anywhere, forks and Dependabot
|
|
270
|
+
* included.
|
|
301
271
|
*/
|
|
302
272
|
export async function runLiveChecks(input: LiveInput): Promise<CheckOutcome[]> {
|
|
303
273
|
const { context, deps, scan, address } = input;
|
|
@@ -313,6 +283,7 @@ export async function runLiveChecks(input: LiveInput): Promise<CheckOutcome[]> {
|
|
|
313
283
|
page.outcome,
|
|
314
284
|
frame,
|
|
315
285
|
await checkProtocol(page.info, origin, deps.fetch),
|
|
316
|
-
...(await runPreviewLiveChecks({ context, deps, scan, info: page.info })),
|
|
286
|
+
...(await runPreviewLiveChecks({ context, deps, scan, info: page.info, address })),
|
|
287
|
+
await checkEditorFrames(input, address),
|
|
317
288
|
];
|
|
318
289
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { separateRefusal } from '../preview-build.js';
|
|
1
2
|
import type { RepositoryEnvironment } from '../repository.js';
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type ConfigScan,
|
|
5
|
+
hasOption,
|
|
6
|
+
optionLiteral,
|
|
7
|
+
previewBuildSetting,
|
|
8
|
+
previewServeSetting,
|
|
9
|
+
separateRefused,
|
|
10
|
+
} from './config-scan.js';
|
|
3
11
|
import { type CheckOutcome, outcomeOf, skipped } from './types.js';
|
|
4
12
|
|
|
5
13
|
/** Doctor-only override for an endpoint the config computes (e.g. from an env var). */
|
|
@@ -54,12 +62,15 @@ export function checkWiring(scan: ConfigScan, repoUri: string | undefined): Chec
|
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
const SERVE_DETAIL = {
|
|
57
|
-
|
|
65
|
+
d8: "drafts render in the site's own build, through its adapter (d8)",
|
|
58
66
|
d3: 'the preview server runs next to the static site on Cloudflare Workers (D3)',
|
|
59
67
|
d4: "a separate preview deploy (D4): its address goes in sites.json's previewUrl",
|
|
60
68
|
unknown: 'not verified — doctor cannot read previewBuild, output or the adapter from the config text',
|
|
61
69
|
} as const;
|
|
62
70
|
|
|
71
|
+
/** The build turns preview off for previewBuild.adapter; CC8 and CC26 name it. */
|
|
72
|
+
export const PREVIEW_BUILD_ADAPTER = 'remove previewBuild.adapter; put the adapter in astro.config';
|
|
73
|
+
|
|
63
74
|
/** CC8 — how the preview build serves drafts, read from the config text. */
|
|
64
75
|
export function checkPreviewBuildAdapter(scan: ConfigScan): CheckOutcome {
|
|
65
76
|
if (scan.kind !== 'read') {
|
|
@@ -68,11 +79,13 @@ export function checkPreviewBuildAdapter(scan: ConfigScan): CheckOutcome {
|
|
|
68
79
|
if (scan.config.conlocaCloud === 'absent') return skipped('CC8', INTEGRATION_NOT_CALLED);
|
|
69
80
|
const outcome = outcomeOf('CC8');
|
|
70
81
|
const mode = previewServeSetting(scan);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
const refused = separateRefused(scan);
|
|
83
|
+
if (mode === 'off') {
|
|
84
|
+
outcome.detail = hasOption(scan, 'previewBuild')
|
|
85
|
+
? 'previewBuild: false — no preview build runs'
|
|
86
|
+
: 'previewBuild is not set — no preview build runs';
|
|
87
|
+
} else if (previewBuildSetting(scan) === 'adapter') outcome.detail = PREVIEW_BUILD_ADAPTER;
|
|
88
|
+
else if (refused !== undefined) outcome.detail = separateRefusal(refused);
|
|
89
|
+
else outcome.detail = SERVE_DETAIL[mode];
|
|
77
90
|
return outcome;
|
|
78
91
|
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { isRecord } from '@conloca/content-api/component-vocabulary';
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
5
|
-
import { type
|
|
3
|
+
import { type EditorPageInfo, hostOf } from '@conloca/content-api/editor-host';
|
|
4
|
+
import { PREVIEW_LABEL_HEADER, PREVIEW_MODE_HEADER, previewRoutePrefix } from '../preview/preview-path.js';
|
|
5
|
+
import { type ConfigScan, previewServeSetting, siteAdapter } from './config-scan.js';
|
|
6
|
+
import {
|
|
7
|
+
type CheckOutcome,
|
|
8
|
+
type CloudDoctorContext,
|
|
9
|
+
type DoctorDeps,
|
|
10
|
+
outcomeOf,
|
|
11
|
+
REQUEST_TIMEOUT_MS,
|
|
12
|
+
skipped,
|
|
13
|
+
} from './types.js';
|
|
6
14
|
|
|
7
15
|
interface Input {
|
|
8
16
|
context: CloudDoctorContext;
|
|
@@ -10,6 +18,97 @@ interface Input {
|
|
|
10
18
|
scan: ConfigScan;
|
|
11
19
|
/** The deployed site's conloca.json, when CC11 read it. */
|
|
12
20
|
info: EditorPageInfo | undefined;
|
|
21
|
+
/** The production address with its base, ending in `/` (CC9). */
|
|
22
|
+
address: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Where each host shows the logs of the code that serves the preview route. */
|
|
26
|
+
const LOGS = {
|
|
27
|
+
vercel: 'Project → Logs',
|
|
28
|
+
netlify: 'Logs → Functions',
|
|
29
|
+
cloudflare: 'the Cloudflare dashboard → your site → Observability → Logs',
|
|
30
|
+
node: "your server's own log output",
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
/** The host whose logs to name: the one the production build recorded, else the adapter's, else D3's Cloudflare. */
|
|
34
|
+
function logsOf(input: Input, mode: 'd3' | 'd8'): string {
|
|
35
|
+
const recorded = input.info === undefined ? undefined : hostOf(input.info);
|
|
36
|
+
if (recorded === 'vercel' || recorded === 'netlify' || recorded === 'cloudflare') return LOGS[recorded];
|
|
37
|
+
if (mode === 'd3') return LOGS.cloudflare;
|
|
38
|
+
const adapter = input.scan.kind === 'read' ? siteAdapter(input.scan) : undefined;
|
|
39
|
+
if (adapter === '@astrojs/vercel') return LOGS.vercel;
|
|
40
|
+
if (adapter === '@astrojs/netlify') return LOGS.netlify;
|
|
41
|
+
if (adapter === '@astrojs/cloudflare') return LOGS.cloudflare;
|
|
42
|
+
return LOGS.node;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What is wrong with one exit answer, or null; `mode` is what the config text says the build serves. */
|
|
46
|
+
function exitProblem(answer: Response, url: string, mode: 'd3' | 'd8', prefix: string): string | null {
|
|
47
|
+
const { status, headers } = answer;
|
|
48
|
+
const location = headers.get('location');
|
|
49
|
+
const elsewhere =
|
|
50
|
+
location !== null && status >= 300 && status < 400 && new URL(location, url).host !== new URL(url).host;
|
|
51
|
+
if ([401, 403, 429].includes(status) || headers.has('cf-mitigated') || elsewhere) {
|
|
52
|
+
return `answered ${status}: something in front of the site answered (auth, firewall or bot challenge): let ${prefix}/* through`;
|
|
53
|
+
}
|
|
54
|
+
if (status !== 302 || headers.get(PREVIEW_LABEL_HEADER) === null) {
|
|
55
|
+
const label = headers.get(PREVIEW_LABEL_HEADER) === null ? ' without the conloca-preview label' : '';
|
|
56
|
+
return `answered ${status} (location: ${location ?? 'none'})${label}, not the preview route's 302`;
|
|
57
|
+
}
|
|
58
|
+
const served = headers.get(PREVIEW_MODE_HEADER);
|
|
59
|
+
if (served !== mode) return `serves preview mode ${served ?? 'none'}, but astro.config builds ${mode}`;
|
|
60
|
+
const hit = (name: string) =>
|
|
61
|
+
headers.get(name)?.toUpperCase().includes('HIT') ? `${name}: ${headers.get(name)}` : null;
|
|
62
|
+
const cached = [
|
|
63
|
+
Number(headers.get('age') ?? 0) > 0 ? `age: ${headers.get('age')}` : null,
|
|
64
|
+
hit('cf-cache-status'),
|
|
65
|
+
hit('x-cache'),
|
|
66
|
+
hit('x-vercel-cache'),
|
|
67
|
+
/;\s*hit\b/iu.test(headers.get('cache-status') ?? '') ? `cache-status: ${headers.get('cache-status')}` : null,
|
|
68
|
+
].filter((item) => item !== null);
|
|
69
|
+
if (cached.length > 0) {
|
|
70
|
+
return `a CDN caches the preview route (${cached.join(', ')}): bypass the cache for ${prefix}/*`;
|
|
71
|
+
}
|
|
72
|
+
if (!/\bno-store\b/iu.test(headers.get('cache-control') ?? '') || !/\bcookie\b/iu.test(headers.get('vary') ?? '')) {
|
|
73
|
+
return 'answers without cache-control: no-store and Vary: Cookie, so a CDN may cache drafts';
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** CC29, under --live only: the site's preview route answers its exit as the configured mode, uncached, twice. */
|
|
79
|
+
async function checkPreviewExit(input: Input): Promise<CheckOutcome> {
|
|
80
|
+
const { scan, deps, address } = input;
|
|
81
|
+
const mode = previewServeSetting(scan);
|
|
82
|
+
if (mode !== 'd3' && mode !== 'd8') return skipped('CC29', 'only D3 and d8 serve the preview route on the site');
|
|
83
|
+
const base = (scan.kind === 'read' ? (scan.config.site.base ?? '/') : '/').replace(/\/?$/u, '/');
|
|
84
|
+
const url = `${address}_conloca/preview/__exit?to=${base}`;
|
|
85
|
+
const outcome = outcomeOf('CC29');
|
|
86
|
+
const logs = logsOf(input, mode);
|
|
87
|
+
const probe = async () => {
|
|
88
|
+
const started = Date.now();
|
|
89
|
+
try {
|
|
90
|
+
const answer = await deps.fetch(url, {
|
|
91
|
+
redirect: 'manual',
|
|
92
|
+
credentials: 'omit',
|
|
93
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
94
|
+
});
|
|
95
|
+
return { problem: exitProblem(answer, url, mode, previewRoutePrefix(base)), ms: Date.now() - started };
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
98
|
+
return { problem: `could not be reached (${reason})`, ms: Date.now() - started };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// Twice, one after the other: a CDN that caches the route answers the second from its cache.
|
|
102
|
+
const first = await probe();
|
|
103
|
+
const second = await probe();
|
|
104
|
+
const problem = first.problem ?? second.problem;
|
|
105
|
+
if (problem !== null) {
|
|
106
|
+
const timing = `(${first.ms} ms, ${second.ms} ms)`;
|
|
107
|
+
outcome.problems.push({ check: 'CC29', level: 'error', message: `${url} ${problem} ${timing} — logs: ${logs}` });
|
|
108
|
+
} else {
|
|
109
|
+
outcome.detail = `302 in ${first.ms} ms and ${second.ms} ms`;
|
|
110
|
+
}
|
|
111
|
+
return outcome;
|
|
13
112
|
}
|
|
14
113
|
|
|
15
114
|
/** sites.json's previewUrl for the default site's default locale, when it names one. */
|
|
@@ -28,10 +127,17 @@ function declaredPreviewUrl(contentRoot: string, deps: DoctorDeps): string | und
|
|
|
28
127
|
return typeof value === 'string' ? value : undefined;
|
|
29
128
|
}
|
|
30
129
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
130
|
+
/**
|
|
131
|
+
* CC24 and CC29, under --live only: the separate preview deploy answers its own conloca.json as D4, on the site's
|
|
132
|
+
* release; the site's own preview route answers its exit.
|
|
133
|
+
*/
|
|
134
|
+
export function runPreviewLiveChecks(input: Input): Promise<CheckOutcome[]> {
|
|
135
|
+
return Promise.all([checkSeparateDeploy(input), checkPreviewExit(input)]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function checkSeparateDeploy(input: Input): Promise<CheckOutcome> {
|
|
33
139
|
const { context, deps, scan } = input;
|
|
34
|
-
if (previewServeSetting(scan) !== 'd4') return
|
|
140
|
+
if (previewServeSetting(scan) !== 'd4') return skipped('CC24', 'no separate preview deploy (D4)');
|
|
35
141
|
const base = scan.kind === 'read' ? (scan.config.site.base ?? '/') : '/';
|
|
36
142
|
const release = outcomeOf('CC24');
|
|
37
143
|
const previewUrl = declaredPreviewUrl(context.contentRoot, deps);
|
|
@@ -42,7 +148,7 @@ export async function runPreviewLiveChecks(input: Input): Promise<CheckOutcome[]
|
|
|
42
148
|
message:
|
|
43
149
|
"sites.json names no previewUrl for the default locale: add the separate preview deploy's https:// address",
|
|
44
150
|
});
|
|
45
|
-
return
|
|
151
|
+
return release;
|
|
46
152
|
}
|
|
47
153
|
// A base written without its trailing slash (`/docs`) still needs one before `_conloca`.
|
|
48
154
|
const url = `${previewUrl.replace(/\/+$/u, '')}${base.replace(/\/?$/u, '/')}_conloca/editor/conloca.json`;
|
|
@@ -73,5 +179,5 @@ export async function runPreviewLiveChecks(input: Input): Promise<CheckOutcome[]
|
|
|
73
179
|
} else {
|
|
74
180
|
release.detail = 'the preview deploy answers as D4';
|
|
75
181
|
}
|
|
76
|
-
return
|
|
182
|
+
return release;
|
|
77
183
|
}
|
|
@@ -3,7 +3,7 @@ import { isRecord } from '@conloca/content-api/component-vocabulary';
|
|
|
3
3
|
import { parseWranglerConfig } from '../preview/cloudflare-adapter.js';
|
|
4
4
|
import { previewOwnEntries, previewRoutePrefix } from '../preview/preview-path.js';
|
|
5
5
|
import { INTEGRATION_NOT_CALLED } from './checks-offline.js';
|
|
6
|
-
import { type ConfigScan, previewServeSetting } from './config-scan.js';
|
|
6
|
+
import { type ConfigScan, previewServeSetting, separateRefused } from './config-scan.js';
|
|
7
7
|
import { type CheckId, type CheckOutcome, type DoctorDeps, outcomeOf, skipped } from './types.js';
|
|
8
8
|
|
|
9
9
|
type PreviewDeps = Pick<DoctorDeps, 'exists' | 'readFile' | 'git'>;
|
|
@@ -64,12 +64,17 @@ const onlyD3 = (id: CheckId) => skipped(id, 'a separate preview deploy (D4) runs
|
|
|
64
64
|
export function runPreviewChecks(scan: ConfigScan, projectDir: string, deps: PreviewDeps): CheckOutcome[] {
|
|
65
65
|
const mode = previewServeSetting(scan);
|
|
66
66
|
if (mode !== 'd3' && mode !== 'd4') {
|
|
67
|
+
const refused = separateRefused(scan);
|
|
67
68
|
const reason =
|
|
68
69
|
scan.kind === 'read' && scan.config.conlocaCloud === 'absent'
|
|
69
70
|
? INTEGRATION_NOT_CALLED
|
|
70
|
-
:
|
|
71
|
-
?
|
|
72
|
-
:
|
|
71
|
+
: refused !== undefined
|
|
72
|
+
? `the build refuses separate: true under ${refused} (see CC26)`
|
|
73
|
+
: mode === 'unknown'
|
|
74
|
+
? 'doctor cannot read previewBuild from the config text'
|
|
75
|
+
: mode === 'd8'
|
|
76
|
+
? "drafts render in the site's own build (d8): CC25–CC28 check its adapter and host"
|
|
77
|
+
: 'only a static site previewing next to itself (D3) or on a separate deploy (D4) needs these';
|
|
73
78
|
return IDS.map((id) => skipped(id, reason));
|
|
74
79
|
}
|
|
75
80
|
const base = scan.kind === 'read' ? (scan.config.site.base ?? '/') : '/';
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { messageOf } from '../message-of.js';
|
|
2
|
+
import type { ConfigScan } from './config-scan.js';
|
|
3
|
+
import { type CloudDoctorContext, type DoctorDeps, REQUEST_TIMEOUT_MS } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface LiveInput {
|
|
6
|
+
context: CloudDoctorContext;
|
|
7
|
+
deps: DoctorDeps;
|
|
8
|
+
scan: ConfigScan;
|
|
9
|
+
/** CC9's verdict: `https://<host><base>`, undefined when CC9 failed. */
|
|
10
|
+
address: string | undefined;
|
|
11
|
+
/** What the build writes as `repo`, undefined when it cannot tell. */
|
|
12
|
+
repoUri: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** GET with no credential and no followed redirect: the answer the server's probe would see. */
|
|
16
|
+
export async function request(fetchFn: DoctorDeps['fetch'], url: string): Promise<Response | Error> {
|
|
17
|
+
try {
|
|
18
|
+
return await fetchFn(url, {
|
|
19
|
+
method: 'GET',
|
|
20
|
+
redirect: 'manual',
|
|
21
|
+
credentials: 'omit',
|
|
22
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
23
|
+
});
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return new Error(messageOf(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
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,24 @@ 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",
|
|
75
|
+
CC30: 'editor frames match the published layout',
|
|
70
76
|
} as const;
|
|
71
77
|
|
|
72
78
|
/** A typo in a check id fails tsc here; the CLI would otherwise drop a label-less outcome silently. */
|
|
73
79
|
export type CheckId = keyof typeof CHECK_LABELS;
|
|
74
80
|
|
|
81
|
+
/** Every doctor request is bounded: a hanging host must never hang `conloca doctor` (the CLI seam has no timer of its own). */
|
|
82
|
+
export const REQUEST_TIMEOUT_MS = 10_000;
|
|
83
|
+
|
|
75
84
|
export function outcomeOf(id: CheckId): CheckOutcome {
|
|
76
85
|
return { id, label: CHECK_LABELS[id], problems: [] };
|
|
77
86
|
}
|