@conloca/cloud-astro 0.2.2 → 0.2.4
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 +378 -207
- package/dist/.build-inputs.json +69 -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 +14 -13
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +14 -13
- package/dist/src/constants.js.map +1 -1
- package/dist/src/d3-build.d.ts +70 -0
- package/dist/src/d3-build.d.ts.map +1 -0
- package/dist/src/d3-build.js +272 -0
- package/dist/src/d3-build.js.map +1 -0
- package/dist/src/descriptors.d.ts +2 -2
- package/dist/src/descriptors.d.ts.map +1 -1
- package/dist/src/descriptors.js +4 -2
- package/dist/src/descriptors.js.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 +226 -188
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +6 -25
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +30 -259
- package/dist/src/doctor/checks-offline.js.map +1 -1
- package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
- package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
- package/dist/src/doctor/checks-preview-limits.js +133 -0
- package/dist/src/doctor/checks-preview-limits.js.map +1 -0
- package/dist/src/doctor/checks-preview-live.d.ts +14 -0
- package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
- package/dist/src/doctor/checks-preview-live.js +72 -0
- package/dist/src/doctor/checks-preview-live.js.map +1 -0
- package/dist/src/doctor/checks-preview.d.ts +7 -0
- package/dist/src/doctor/checks-preview.d.ts.map +1 -0
- package/dist/src/doctor/checks-preview.js +287 -0
- package/dist/src/doctor/checks-preview.js.map +1 -0
- package/dist/src/doctor/config-scan.d.ts +12 -3
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +38 -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 +16 -10
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +17 -7
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +17 -7
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +90 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -0
- package/dist/src/editor-page/bundle.js +373 -0
- package/dist/src/editor-page/bundle.js.map +1 -0
- package/dist/src/editor-page/data-schemas.d.ts +16 -0
- package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
- package/dist/src/editor-page/data-schemas.js +39 -0
- package/dist/src/editor-page/data-schemas.js.map +1 -0
- package/dist/src/editor-page/emit.d.ts +69 -0
- package/dist/src/editor-page/emit.d.ts.map +1 -0
- package/dist/src/editor-page/emit.js +254 -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 +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -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 +377 -416
- 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/_dispatch.d.ts +12 -0
- package/dist/src/preview/_dispatch.d.ts.map +1 -1
- package/dist/src/preview/_dispatch.js +31 -0
- package/dist/src/preview/_dispatch.js.map +1 -1
- package/dist/src/preview/_resolve-opts.d.ts +19 -10
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +24 -11
- package/dist/src/preview/_resolve-opts.js.map +1 -1
- package/dist/src/preview/banner.d.ts +12 -9
- package/dist/src/preview/banner.d.ts.map +1 -1
- package/dist/src/preview/banner.js +46 -43
- package/dist/src/preview/banner.js.map +1 -1
- package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
- package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
- package/dist/src/preview/cloudflare-adapter.js +92 -0
- package/dist/src/preview/cloudflare-adapter.js.map +1 -0
- package/dist/src/preview/cookie.d.ts +13 -14
- package/dist/src/preview/cookie.d.ts.map +1 -1
- package/dist/src/preview/cookie.js +19 -26
- package/dist/src/preview/cookie.js.map +1 -1
- package/dist/src/preview/dispatcher.d.ts +73 -0
- package/dist/src/preview/dispatcher.d.ts.map +1 -0
- package/dist/src/preview/dispatcher.js +329 -0
- package/dist/src/preview/dispatcher.js.map +1 -0
- package/dist/src/preview/entry-code.d.ts +33 -0
- package/dist/src/preview/entry-code.d.ts.map +1 -0
- package/dist/src/preview/entry-code.js +33 -0
- package/dist/src/preview/entry-code.js.map +1 -0
- package/dist/src/preview/headers.d.ts +24 -4
- package/dist/src/preview/headers.d.ts.map +1 -1
- package/dist/src/preview/headers.js +35 -7
- package/dist/src/preview/headers.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 +23 -2
- package/dist/src/preview/landing.d.ts.map +1 -1
- package/dist/src/preview/landing.js +105 -37
- package/dist/src/preview/landing.js.map +1 -1
- package/dist/src/preview/middleware.d.ts +49 -22
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +259 -100
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/preview-path.d.ts +47 -5
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +65 -8
- package/dist/src/preview/preview-path.js.map +1 -1
- package/dist/src/preview/redeem-url.d.ts +7 -0
- package/dist/src/preview/redeem-url.d.ts.map +1 -0
- package/dist/src/preview/redeem-url.js +14 -0
- package/dist/src/preview/redeem-url.js.map +1 -0
- 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 +53 -26
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview-build.d.ts +29 -15
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +66 -25
- 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/skill.d.ts +11 -0
- package/dist/src/skill.d.ts.map +1 -1
- package/dist/src/skill.js +32 -9
- package/dist/src/skill.js.map +1 -1
- package/dist/src/types.d.ts +33 -78
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +63 -13
- package/src/component-manifest.ts +11 -8
- package/src/constants.ts +15 -13
- package/src/d3-build.ts +315 -0
- package/src/descriptors.ts +6 -4
- package/src/doctor/checks-address.ts +190 -0
- package/src/doctor/checks-live.ts +262 -268
- package/src/doctor/checks-offline.ts +32 -279
- package/src/doctor/checks-preview-limits.ts +137 -0
- package/src/doctor/checks-preview-live.ts +77 -0
- package/src/doctor/checks-preview.ts +302 -0
- package/src/doctor/config-scan.ts +35 -9
- package/src/doctor/run.ts +18 -16
- package/src/doctor/types.ts +17 -7
- package/src/editor-page/bundle.ts +487 -0
- package/src/editor-page/data-schemas.ts +47 -0
- package/src/editor-page/emit.ts +362 -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 +22 -6
- package/src/integration.ts +399 -469
- package/src/node.ts +18 -2
- package/src/preview/_dispatch.ts +36 -1
- package/src/preview/_resolve-opts.ts +35 -12
- package/src/preview/banner.ts +61 -43
- package/src/preview/cloudflare-adapter.ts +103 -0
- package/src/preview/cookie.ts +18 -24
- package/src/preview/dispatcher.ts +407 -0
- package/src/preview/entry-code.ts +51 -0
- package/src/preview/headers.ts +35 -7
- package/src/preview/label.ts +12 -0
- package/src/preview/landing.ts +117 -39
- package/src/preview/middleware.ts +302 -115
- package/src/preview/preview-path.ts +83 -8
- package/src/preview/redeem-url.ts +14 -0
- package/src/preview/site-middleware.ts +60 -30
- package/src/preview-build.ts +85 -26
- package/src/preview-handler.astro +12 -9
- 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 +63 -55
- package/src/skill.ts +36 -8
- package/src/types.ts +33 -79
- 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
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
2
|
+
import { isRecord } from '@conloca/content-api/component-vocabulary';
|
|
3
|
+
import { parseWranglerConfig } from '../preview/cloudflare-adapter.js';
|
|
4
|
+
import { previewOwnEntries, previewRoutePrefix } from '../preview/preview-path.js';
|
|
5
|
+
import { INTEGRATION_NOT_CALLED } from './checks-offline.js';
|
|
6
|
+
import { type ConfigScan, previewServeSetting } from './config-scan.js';
|
|
7
|
+
import { type CheckId, type CheckOutcome, type DoctorDeps, outcomeOf, skipped } from './types.js';
|
|
8
|
+
|
|
9
|
+
type PreviewDeps = Pick<DoctorDeps, 'exists' | 'readFile' | 'git'>;
|
|
10
|
+
const IDS: readonly CheckId[] = ['CC15', 'CC16', 'CC17', 'CC18', 'CC19', 'CC20', 'CC21'];
|
|
11
|
+
const DISPATCHER_MAIN = '.conloca/dispatcher/index.mjs';
|
|
12
|
+
const UPDATE = '— run `conloca connect --update --yes`';
|
|
13
|
+
/** Cloudflare's cap on `run_worker_first` entries. */
|
|
14
|
+
const MAX_WORKER_FIRST = 100;
|
|
15
|
+
/** Script hosts and snippets of tag managers and analytics loaders. */
|
|
16
|
+
const TAG_MANAGERS =
|
|
17
|
+
/googletagmanager\.com|gtag\(|cdn\.segment\.com|connect\.facebook\.net|static\.hotjar\.com|js\.hs-scripts\.com|plausible\.io\/js|@builder\.io\/partytown/u;
|
|
18
|
+
const SOURCE = /\.(astro|html|[cm]?[jt]sx?|mdx?)$/u;
|
|
19
|
+
const MIDDLEWARE_FILES = ['src/middleware.ts', 'src/middleware.js', 'src/middleware.mjs'];
|
|
20
|
+
|
|
21
|
+
function read(deps: PreviewDeps, path: string): string | undefined {
|
|
22
|
+
try {
|
|
23
|
+
return deps.readFile(path);
|
|
24
|
+
} catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A JSON file's object, or undefined; the return type is `isRecord`'s narrowing, never written out. */
|
|
30
|
+
function jsonRecord(deps: PreviewDeps, path: string) {
|
|
31
|
+
const text = read(deps, path);
|
|
32
|
+
if (text === undefined) return undefined;
|
|
33
|
+
try {
|
|
34
|
+
const value: unknown = JSON.parse(text);
|
|
35
|
+
return isRecord(value) ? value : undefined;
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A JSON file's array of strings, or undefined. */
|
|
42
|
+
function jsonStrings(deps: PreviewDeps, path: string): string[] | undefined {
|
|
43
|
+
const text = read(deps, path);
|
|
44
|
+
if (text === undefined) return undefined;
|
|
45
|
+
try {
|
|
46
|
+
const value: unknown = JSON.parse(text);
|
|
47
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : undefined;
|
|
48
|
+
} catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A heuristic: the site's middleware reads `Accept`, or answers a 404 body of its own. Doctor only warns on it. */
|
|
54
|
+
function middlewareNegotiates(deps: PreviewDeps, projectDir: string): boolean {
|
|
55
|
+
const text = MIDDLEWARE_FILES.map((name) => read(deps, join(projectDir, name))).find((found) => found !== undefined);
|
|
56
|
+
return (
|
|
57
|
+
text !== undefined && (/\.get\(\s*['"`]accept['"`]\s*\)/iu.test(text) || /\bstatus\s*={2,3}\s*404\b/u.test(text))
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const onlyD3 = (id: CheckId) => skipped(id, 'a separate preview deploy (D4) runs no dispatcher');
|
|
62
|
+
|
|
63
|
+
/** CC15–CC21: the settings a D3 or D4 preview deploy needs, read from the project's files. Never networks. */
|
|
64
|
+
export function runPreviewChecks(scan: ConfigScan, projectDir: string, deps: PreviewDeps): CheckOutcome[] {
|
|
65
|
+
const mode = previewServeSetting(scan);
|
|
66
|
+
if (mode !== 'd3' && mode !== 'd4') {
|
|
67
|
+
const reason =
|
|
68
|
+
scan.kind === 'read' && scan.config.conlocaCloud === 'absent'
|
|
69
|
+
? INTEGRATION_NOT_CALLED
|
|
70
|
+
: mode === 'unknown'
|
|
71
|
+
? 'doctor cannot read previewBuild from the config text'
|
|
72
|
+
: 'only a static site previewing next to itself (D3) or on a separate deploy (D4) needs these';
|
|
73
|
+
return IDS.map((id) => skipped(id, reason));
|
|
74
|
+
}
|
|
75
|
+
const base = scan.kind === 'read' ? (scan.config.site.base ?? '/') : '/';
|
|
76
|
+
const prefix = previewRoutePrefix(base);
|
|
77
|
+
const path = ['wrangler.jsonc', 'wrangler.json'].map((name) => join(projectDir, name)).find((p) => deps.exists(p));
|
|
78
|
+
const text = path === undefined ? undefined : read(deps, path);
|
|
79
|
+
const config = text === undefined ? undefined : parseWranglerConfig(text);
|
|
80
|
+
const assets = isRecord(config?.assets) ? config.assets : {};
|
|
81
|
+
const everything = assets.run_worker_first === true;
|
|
82
|
+
const listed: unknown[] = Array.isArray(assets.run_worker_first) ? assets.run_worker_first : [];
|
|
83
|
+
|
|
84
|
+
// CC15
|
|
85
|
+
const deployTarget = outcomeOf('CC15');
|
|
86
|
+
if (config === undefined && deps.exists(join(projectDir, 'wrangler.toml'))) {
|
|
87
|
+
deployTarget.problems.push({
|
|
88
|
+
check: 'CC15',
|
|
89
|
+
level: 'error',
|
|
90
|
+
message:
|
|
91
|
+
"wrangler.toml can't carry the preview settings: convert it to wrangler.jsonc, then run `conloca connect --update --yes`",
|
|
92
|
+
});
|
|
93
|
+
} else if (config === undefined) {
|
|
94
|
+
deployTarget.problems.push({
|
|
95
|
+
check: 'CC15',
|
|
96
|
+
level: 'error',
|
|
97
|
+
message:
|
|
98
|
+
'no wrangler.jsonc: draft previews of a static site deploy to Cloudflare Workers — run `conloca connect --yes`',
|
|
99
|
+
});
|
|
100
|
+
} else if (config.pages_build_output_dir !== undefined) {
|
|
101
|
+
deployTarget.problems.push({
|
|
102
|
+
check: 'CC15',
|
|
103
|
+
level: 'error',
|
|
104
|
+
message:
|
|
105
|
+
'wrangler.jsonc configures Cloudflare Pages (pages_build_output_dir); draft previews need Cloudflare Workers with static assets',
|
|
106
|
+
path,
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
deployTarget.detail = 'Cloudflare Workers';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// CC16: array run_worker_first needs 4.20, the ratelimits binding 4.36; D4 uses neither.
|
|
113
|
+
let version: CheckOutcome;
|
|
114
|
+
if (mode === 'd4') version = onlyD3('CC16');
|
|
115
|
+
else {
|
|
116
|
+
version = outcomeOf('CC16');
|
|
117
|
+
const manifest = [projectDir, join(projectDir, '..'), join(projectDir, '..', '..')]
|
|
118
|
+
.map((dir) => jsonRecord(deps, join(dir, 'node_modules', 'wrangler', 'package.json')))
|
|
119
|
+
.find((found) => found !== undefined);
|
|
120
|
+
const installed = typeof manifest?.version === 'string' ? manifest.version : undefined;
|
|
121
|
+
const [major = 0, minor = 0] = (installed ?? '').split('.').map(Number);
|
|
122
|
+
if (installed === undefined) {
|
|
123
|
+
version.problems.push({
|
|
124
|
+
check: 'CC16',
|
|
125
|
+
level: 'warn',
|
|
126
|
+
message:
|
|
127
|
+
'wrangler is not installed in this project: the deploy uses whichever wrangler it finds, and the preview settings need 4.36 or newer',
|
|
128
|
+
});
|
|
129
|
+
} else if (major < 4 || (major === 4 && minor < 36)) {
|
|
130
|
+
version.problems.push({
|
|
131
|
+
check: 'CC16',
|
|
132
|
+
level: 'error',
|
|
133
|
+
message: `wrangler ${installed} cannot deploy the preview settings: run_worker_first patterns and the ratelimits binding need wrangler 4.36 or newer`,
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
version.detail = `wrangler ${installed}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// CC17
|
|
141
|
+
const dispatcher = {
|
|
142
|
+
...(config === undefined ? skipped('CC17', 'no wrangler.jsonc (see CC15)') : outcomeOf('CC17')),
|
|
143
|
+
...(mode === 'd4' ? { label: 'wrangler.jsonc keeps no D3 dispatcher settings' } : {}),
|
|
144
|
+
};
|
|
145
|
+
const add = (message: string) => dispatcher.problems.push({ check: 'CC17', level: 'error', message, path });
|
|
146
|
+
if (mode === 'd4' && config?.main === DISPATCHER_MAIN) {
|
|
147
|
+
add(
|
|
148
|
+
`main is the D3 dispatcher, which a separate preview deploy (D4) inherits and its main deploy no longer builds ${UPDATE}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
// An assets-only deploy: Wrangler refuses both settings without a script to run.
|
|
152
|
+
if (mode === 'd4' && config !== undefined && config.main === undefined) {
|
|
153
|
+
// `conloca connect --update` removes only what the D3 dispatcher left: an ASSETS binding and the preview's own entries.
|
|
154
|
+
const own = previewOwnEntries(base);
|
|
155
|
+
if (assets.binding !== undefined) {
|
|
156
|
+
const fix = assets.binding === 'ASSETS' ? UPDATE : '— remove assets.binding';
|
|
157
|
+
add(`assets.binding without main: Wrangler refuses an assets binding on a deploy with no script ${fix}`);
|
|
158
|
+
}
|
|
159
|
+
if (assets.run_worker_first !== undefined) {
|
|
160
|
+
const ours = listed.length > 0 && listed.every((entry) => typeof entry === 'string' && own.includes(entry));
|
|
161
|
+
const fix = ours ? UPDATE : '— remove it, or set main to a script of your own';
|
|
162
|
+
add(`run_worker_first without main: Wrangler refuses it on a deploy with no script ${fix}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (mode === 'd3' && config !== undefined) {
|
|
166
|
+
if (config.main !== DISPATCHER_MAIN) add(`main is not ${DISPATCHER_MAIN} ${UPDATE}`);
|
|
167
|
+
if (!(Array.isArray(config.compatibility_flags) && config.compatibility_flags.includes('nodejs_compat'))) {
|
|
168
|
+
add(`compatibility_flags lacks nodejs_compat ${UPDATE}`);
|
|
169
|
+
}
|
|
170
|
+
if (assets.binding !== 'ASSETS') add(`assets.binding is not ASSETS ${UPDATE}`);
|
|
171
|
+
const missing = everything ? [] : [prefix, `${prefix}/*`].filter((entry) => !listed.includes(entry));
|
|
172
|
+
if (missing.length > 0) add(`run_worker_first lacks ${missing.join(', ')} ${UPDATE}`);
|
|
173
|
+
if (assets.not_found_handling === 'single-page-application') {
|
|
174
|
+
add(`not_found_handling is single-page-application; previews need "404-page" or "none" ${UPDATE}`);
|
|
175
|
+
}
|
|
176
|
+
for (const [envName, block] of Object.entries(isRecord(config.env) ? config.env : {})) {
|
|
177
|
+
if (isRecord(block) && (block.main !== undefined || block.assets !== undefined)) {
|
|
178
|
+
add(`env.${envName} sets main or assets, which replaces the dispatcher's — remove them from the env block`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const excluded = listed.find(
|
|
182
|
+
(entry) => typeof entry === 'string' && entry.startsWith('!') && entry.slice(1).startsWith(prefix),
|
|
183
|
+
);
|
|
184
|
+
if (typeof excluded === 'string') {
|
|
185
|
+
add(`run_worker_first excludes the preview route (${excluded}) — remove that entry`);
|
|
186
|
+
}
|
|
187
|
+
if (listed.length > MAX_WORKER_FIRST) {
|
|
188
|
+
add(
|
|
189
|
+
`run_worker_first has ${listed.length} entries, past Cloudflare's cap of ${MAX_WORKER_FIRST} — merge some into wider patterns`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// CC18
|
|
195
|
+
const reported = jsonStrings(deps, join(projectDir, '.conloca', 'dispatcher', 'run_worker_first.json'));
|
|
196
|
+
let routes: CheckOutcome;
|
|
197
|
+
if (mode === 'd4') routes = onlyD3('CC18');
|
|
198
|
+
else if (reported === undefined) routes = skipped('CC18', 'no build yet: build the site, then run doctor');
|
|
199
|
+
else {
|
|
200
|
+
routes = outcomeOf('CC18');
|
|
201
|
+
const missing = everything ? [] : reported.filter((entry) => !listed.includes(entry) && !entry.startsWith(prefix));
|
|
202
|
+
if (missing.length > 0) {
|
|
203
|
+
routes.problems.push({
|
|
204
|
+
check: 'CC18',
|
|
205
|
+
level: 'error',
|
|
206
|
+
message: `run_worker_first lacks ${missing.join(', ')}, which the last build renders on demand ${UPDATE}`,
|
|
207
|
+
path,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// CC19
|
|
213
|
+
const redirectPath = join(projectDir, '.wrangler', 'deploy', 'config.json');
|
|
214
|
+
const redirect = jsonRecord(deps, redirectPath);
|
|
215
|
+
const ships = mode === 'd4' ? onlyD3('CC19') : outcomeOf('CC19');
|
|
216
|
+
const target =
|
|
217
|
+
typeof redirect?.configPath === 'string' ? resolve(dirname(redirectPath), redirect.configPath) : undefined;
|
|
218
|
+
if (
|
|
219
|
+
mode === 'd3' &&
|
|
220
|
+
target !== undefined &&
|
|
221
|
+
target.startsWith(`${resolve(projectDir, '.conloca', 'preview-server')}${sep}`)
|
|
222
|
+
) {
|
|
223
|
+
ships.problems.push({
|
|
224
|
+
check: 'CC19',
|
|
225
|
+
level: 'error',
|
|
226
|
+
message:
|
|
227
|
+
'a plain `wrangler deploy` would ship the preview server as the site: delete .wrangler/deploy/config.json and build again with this release',
|
|
228
|
+
path: redirectPath,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// CC20: a heuristic, so a warning. The detection of middleware negotiation lives here too.
|
|
233
|
+
let misses: CheckOutcome;
|
|
234
|
+
const negotiates = middlewareNegotiates(deps, projectDir);
|
|
235
|
+
if (mode === 'd4') misses = onlyD3('CC20');
|
|
236
|
+
else if (assets.not_found_handling === 'none') {
|
|
237
|
+
misses = {
|
|
238
|
+
...outcomeOf('CC20'),
|
|
239
|
+
detail: negotiates
|
|
240
|
+
? 'not_found_handling is "none": every miss reaches the dispatcher, so the middleware negotiates them; its negotiated pages need run_worker_first entries too'
|
|
241
|
+
: 'not_found_handling is "none": every miss reaches the dispatcher, which answers it',
|
|
242
|
+
};
|
|
243
|
+
} else {
|
|
244
|
+
misses = outcomeOf('CC20');
|
|
245
|
+
// A build holds the 404 page however it is made (a CMS page, src/pages/404.ts, [lang]/404.astro); before one, the
|
|
246
|
+
// source files.
|
|
247
|
+
const built = deps.exists(join(projectDir, 'dist', 'index.html'));
|
|
248
|
+
const sources = [
|
|
249
|
+
'src/pages/404.astro',
|
|
250
|
+
'src/pages/404.md',
|
|
251
|
+
'src/pages/404.mdx',
|
|
252
|
+
'src/pages/404.html',
|
|
253
|
+
'src/pages/404.ts',
|
|
254
|
+
'public/404.html',
|
|
255
|
+
];
|
|
256
|
+
// shortcut: a Starlight site counts as having its own 404 page before a build; the build's dist/404.html settles it.
|
|
257
|
+
const starlight = scan.kind === 'read' && /\bstarlight\s*\(/u.test(read(deps, scan.config.path) ?? '');
|
|
258
|
+
const hasPage = built
|
|
259
|
+
? deps.exists(join(projectDir, 'dist', '404.html'))
|
|
260
|
+
: starlight || sources.some((page) => deps.exists(join(projectDir, page)));
|
|
261
|
+
if (!hasPage) {
|
|
262
|
+
misses.problems.push({
|
|
263
|
+
check: 'CC20',
|
|
264
|
+
level: 'warn',
|
|
265
|
+
message:
|
|
266
|
+
'no 404 page: with not_found_handling "404-page" Cloudflare answers a miss with an empty 404 and never starts the dispatcher — add src/pages/404.astro',
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
if (negotiates) {
|
|
270
|
+
misses.problems.push({
|
|
271
|
+
check: 'CC20',
|
|
272
|
+
level: 'warn',
|
|
273
|
+
// A heuristic, so only a warning naming the flag: connect never switches "none" on its own.
|
|
274
|
+
message:
|
|
275
|
+
'the middleware negotiates responses: either (a) run `conloca connect --update --yes --negotiate-404` (not_found_handling "none") and list the negotiated paths in run_worker_first, or (b) keep "404-page" and accept static responses',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// CC21
|
|
281
|
+
let tags: CheckOutcome;
|
|
282
|
+
if (mode === 'd4') tags = skipped('CC21', 'a separate preview deploy (D4) serves no visitors');
|
|
283
|
+
else {
|
|
284
|
+
tags = outcomeOf('CC21');
|
|
285
|
+
const files = (deps.git(['ls-files', '--', 'src', 'public'], projectDir) ?? '')
|
|
286
|
+
.split('\n')
|
|
287
|
+
.filter((file) => SOURCE.test(file));
|
|
288
|
+
for (const file of files) {
|
|
289
|
+
const match = TAG_MANAGERS.exec(read(deps, join(projectDir, file)) ?? '');
|
|
290
|
+
if (match === null) continue;
|
|
291
|
+
tags.problems.push({
|
|
292
|
+
check: 'CC21',
|
|
293
|
+
level: 'warn',
|
|
294
|
+
message: `${file} loads a tag manager (${match[0]}): it runs on draft pages and can read them — previewBuild: { separate: true } keeps drafts on a deploy no tag reads`,
|
|
295
|
+
path: join(projectDir, file),
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return [deployTarget, version, dispatcher, routes, ships, misses, tags];
|
|
302
|
+
}
|
|
@@ -129,6 +129,9 @@ function callArgs(configText: string, name: string): CallArgs {
|
|
|
129
129
|
interface SiteSettings {
|
|
130
130
|
output: 'static' | 'server' | 'unknown';
|
|
131
131
|
adapter: boolean;
|
|
132
|
+
/** Astro's `site` and `base` as plain string literals: undefined when absent, null when computed or spread in. */
|
|
133
|
+
url: string | null | undefined;
|
|
134
|
+
base: string | null | undefined;
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
interface ScannedConfig {
|
|
@@ -138,15 +141,24 @@ interface ScannedConfig {
|
|
|
138
141
|
site: SiteSettings;
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
/** Astro's
|
|
144
|
+
/** Astro's own settings, read without conlocaCloud's options: their previewBuild.adapter is not the site's. */
|
|
142
145
|
function siteSettings(configText: string, conlocaCloud: CallArgs): SiteSettings {
|
|
143
146
|
const text = typeof conlocaCloud === 'string' ? configText : configText.replace(conlocaCloud.text, '');
|
|
144
147
|
const adapter = containsOutsideStrings(text, 'adapter');
|
|
145
|
-
|
|
148
|
+
const spread = containsOutsideStrings(text, '...');
|
|
149
|
+
// shortcut: the first `site:`/`base:` outside conlocaCloud's options counts, so a nested `vite: { base }` would read
|
|
150
|
+
// as Astro's; parse the top-level object if a real config trips it.
|
|
151
|
+
const setting = (key: string) => {
|
|
152
|
+
const match = new RegExp(`\\b${key}\\s*:\\s*(?:'([^'\\\\]*)'|"([^"\\\\]*)")?`).exec(text);
|
|
153
|
+
if (match === null) return spread ? null : undefined;
|
|
154
|
+
return match[1] ?? match[2] ?? null;
|
|
155
|
+
};
|
|
156
|
+
const strings = { url: setting('site'), base: setting('base') };
|
|
157
|
+
if (spread) return { output: 'unknown', adapter, ...strings };
|
|
146
158
|
const key = /\boutput\s*:/.exec(text);
|
|
147
|
-
if (key === null) return { output: 'static', adapter };
|
|
159
|
+
if (key === null) return { output: 'static', adapter, ...strings };
|
|
148
160
|
const value = /^(['"])(static|server)\1/.exec(text.slice(key.index + key[0].length).trimStart())?.[2];
|
|
149
|
-
return { output: value === 'static' || value === 'server' ? value : 'unknown', adapter };
|
|
161
|
+
return { output: value === 'static' || value === 'server' ? value : 'unknown', adapter, ...strings };
|
|
150
162
|
}
|
|
151
163
|
|
|
152
164
|
export type ConfigScan =
|
|
@@ -190,16 +202,30 @@ export function hasOption(scan: ConfigScan, key: string): boolean {
|
|
|
190
202
|
}
|
|
191
203
|
|
|
192
204
|
/**
|
|
193
|
-
* conlocaCloud's previewBuild as the text shows it: 'off' when written as false
|
|
194
|
-
* adapter (previewBuild.adapter, written out or as shorthand), 'on'
|
|
195
|
-
* and 'unknown' when computed or when a spread could set it.
|
|
205
|
+
* conlocaCloud's previewBuild as the text shows it: 'off' when absent or written as false (the preview build is
|
|
206
|
+
* opt-in), 'adapter' when the options name an adapter (previewBuild.adapter, written out or as shorthand), 'on' for
|
|
207
|
+
* an options object without one, and 'unknown' when computed or when a spread could set it.
|
|
196
208
|
*/
|
|
197
209
|
export function previewBuildSetting(scan: ConfigScan): 'off' | 'adapter' | 'on' | 'unknown' {
|
|
198
210
|
if (scan.kind !== 'read' || typeof scan.config.conlocaCloud === 'string') return 'unknown';
|
|
199
211
|
const { text, spread } = scan.config.conlocaCloud;
|
|
200
212
|
const value = /\bpreviewBuild\s*:\s*(false\b|\{)?/.exec(text);
|
|
201
|
-
if (value
|
|
213
|
+
if (value === null) return spread || containsOutsideStrings(text, 'previewBuild') ? 'unknown' : 'off';
|
|
214
|
+
if (value[1] === 'false') return 'off';
|
|
202
215
|
if (containsOutsideStrings(text, 'adapter')) return 'adapter';
|
|
203
|
-
if (value === null) return spread || containsOutsideStrings(text, 'previewBuild') ? 'unknown' : 'on';
|
|
204
216
|
return value[1] === '{' ? 'on' : 'unknown';
|
|
205
217
|
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* How the preview build serves, as the config text shows it (the rule of `previewBuildMode`): `separate: true` is D4,
|
|
221
|
+
* an adapter named anywhere (the site's or previewBuild's) is D2, a static site is D3; 'unknown' when the text cannot
|
|
222
|
+
* tell.
|
|
223
|
+
*/
|
|
224
|
+
export function previewServeSetting(scan: ConfigScan): 'off' | 'd2' | 'd3' | 'd4' | 'unknown' {
|
|
225
|
+
const setting = previewBuildSetting(scan);
|
|
226
|
+
if (setting === 'off' || setting === 'unknown') return setting;
|
|
227
|
+
if (scan.kind !== 'read' || typeof scan.config.conlocaCloud === 'string') return 'unknown';
|
|
228
|
+
if (/\bseparate\s*:\s*true\b/u.test(scan.config.conlocaCloud.text)) return 'd4';
|
|
229
|
+
if (setting === 'adapter' || scan.config.site.adapter) return 'd2';
|
|
230
|
+
return scan.config.site.output === 'unknown' ? 'unknown' : 'd3';
|
|
231
|
+
}
|
package/src/doctor/run.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { gitOutput } from '../git.js';
|
|
2
|
+
import { gitOutput, resolveRepositoryUri } from '../git.js';
|
|
3
|
+
import { checkFramingHeaders, checkKeyLeftovers, checkSiteAddress } from './checks-address.js';
|
|
3
4
|
import { runLiveChecks } from './checks-live.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
checkPreviewBuildAdapter,
|
|
9
|
-
checkWiring,
|
|
10
|
-
} from './checks-offline.js';
|
|
11
|
-
import { scanAstroConfig } from './config-scan.js';
|
|
5
|
+
import { checkPreviewBuildAdapter, checkWiring, suppliedEndpoint } from './checks-offline.js';
|
|
6
|
+
import { runPreviewChecks } from './checks-preview.js';
|
|
7
|
+
import { runPreviewLimitChecks } from './checks-preview-limits.js';
|
|
8
|
+
import { optionLiteral, scanAstroConfig } from './config-scan.js';
|
|
12
9
|
import type { CloudDoctorContext, CloudDoctorResult, DoctorDeps } from './types.js';
|
|
13
10
|
|
|
14
11
|
/** The doctor extension: offline checks always, live ones only under --live. Every side effect rides `deps`. */
|
|
@@ -25,15 +22,20 @@ export async function runDoctor(
|
|
|
25
22
|
...overrides,
|
|
26
23
|
};
|
|
27
24
|
const scan = scanAstroConfig(context.projectDir, deps);
|
|
28
|
-
|
|
29
|
-
const
|
|
25
|
+
// The doctor diagnoses the project it was handed, not whatever checkout the CLI happens to be standing in.
|
|
26
|
+
const repoUri = resolveRepositoryUri(optionLiteral(scan, 'repoUri'), deps.env, (args) =>
|
|
27
|
+
deps.git(args, context.projectDir),
|
|
28
|
+
);
|
|
29
|
+
const site = checkSiteAddress(scan, context.contentRoot, deps);
|
|
30
30
|
const checks = [
|
|
31
|
-
checkWiring(scan),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
...(await runLiveChecks({ context, deps, scan, token: token.token, endpoint: endpoints.endpoint })),
|
|
31
|
+
checkWiring(scan, repoUri),
|
|
32
|
+
site.outcome,
|
|
33
|
+
await checkFramingHeaders(scan, context.projectDir, suppliedEndpoint(scan, deps.env), deps),
|
|
34
|
+
checkKeyLeftovers(scan, context.projectDir, deps),
|
|
36
35
|
checkPreviewBuildAdapter(scan),
|
|
36
|
+
...runPreviewChecks(scan, context.projectDir, deps),
|
|
37
|
+
...runPreviewLimitChecks(scan, context.projectDir, deps),
|
|
38
|
+
...(await runLiveChecks({ context, deps, scan, address: site.address, repoUri })),
|
|
37
39
|
];
|
|
38
40
|
return { contractVersion: 1, checks };
|
|
39
41
|
}
|
package/src/doctor/types.ts
CHANGED
|
@@ -50,13 +50,23 @@ export interface DoctorDeps {
|
|
|
50
50
|
/** Insertion order is the report order. */
|
|
51
51
|
const CHECK_LABELS = {
|
|
52
52
|
CC1: 'conlocaCloud is wired next to conlocaCMS',
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
CC9: 'the site domain is declared in sites.json',
|
|
54
|
+
CC10: 'committed headers allow framing the editor page',
|
|
55
|
+
CC14: 'no build key leftovers',
|
|
56
|
+
CC8: 'how the preview build serves drafts',
|
|
57
|
+
CC15: 'the preview deploys to Cloudflare Workers',
|
|
58
|
+
CC16: 'Wrangler is 4.36 or newer',
|
|
59
|
+
CC17: 'wrangler.jsonc runs the preview dispatcher',
|
|
60
|
+
CC18: 'run_worker_first lists every on-demand route',
|
|
61
|
+
CC19: 'a plain wrangler deploy ships the site',
|
|
62
|
+
CC20: 'misses and negotiated pages reach the right place',
|
|
63
|
+
CC21: 'no tag manager runs on draft pages',
|
|
64
|
+
CC22: "the preview route's rate limit fits the plan",
|
|
65
|
+
CC23: 'the recorded Cloudflare plan fits draft previews',
|
|
66
|
+
CC11: 'the deployed editor page answers',
|
|
67
|
+
CC12: 'the deployed editor page may be framed',
|
|
68
|
+
CC13: "the editor speaks this page's protocol",
|
|
69
|
+
CC24: 'the separate preview deploy runs this release',
|
|
60
70
|
} as const;
|
|
61
71
|
|
|
62
72
|
/** A typo in a check id fails tsc here; the CLI would otherwise drop a label-less outcome silently. */
|