@conloca/cloud-astro 0.2.3 → 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 +155 -37
- package/dist/.build-inputs.json +32 -23
- package/dist/src/constants.d.ts +12 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -3
- 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.map +1 -1
- package/dist/src/descriptors.js +4 -2
- package/dist/src/descriptors.js.map +1 -1
- package/dist/src/doctor/checks-live.d.ts +2 -2
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +10 -4
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +1 -5
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +15 -27
- 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 +6 -0
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +17 -0
- 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 +4 -0
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +11 -1
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +11 -1
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +2 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -1
- package/dist/src/editor-page/bundle.js +3 -0
- package/dist/src/editor-page/bundle.js.map +1 -1
- 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 +37 -1
- package/dist/src/editor-page/emit.d.ts.map +1 -1
- package/dist/src/editor-page/emit.js +75 -4
- package/dist/src/editor-page/emit.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +165 -41
- package/dist/src/integration.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 +3 -0
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +3 -1
- 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 -41
- 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 +9 -13
- package/dist/src/preview/cookie.d.ts.map +1 -1
- package/dist/src/preview/cookie.js +15 -25
- 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/landing.d.ts +21 -0
- package/dist/src/preview/landing.d.ts.map +1 -1
- package/dist/src/preview/landing.js +103 -35
- package/dist/src/preview/landing.js.map +1 -1
- package/dist/src/preview/middleware.d.ts +29 -7
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +238 -84
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/preview-path.d.ts +29 -0
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +41 -0
- 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.map +1 -1
- package/dist/src/preview/site-middleware.js +39 -12
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview-build.d.ts +19 -8
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +47 -21
- package/dist/src/preview-build.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 +15 -12
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +33 -7
- package/src/constants.ts +14 -3
- package/src/d3-build.ts +315 -0
- package/src/descriptors.ts +4 -2
- package/src/doctor/checks-live.ts +10 -4
- package/src/doctor/checks-offline.ts +16 -25
- 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 +14 -0
- package/src/doctor/run.ts +4 -0
- package/src/doctor/types.ts +11 -1
- package/src/editor-page/bundle.ts +5 -0
- package/src/editor-page/data-schemas.ts +47 -0
- package/src/editor-page/emit.ts +124 -8
- package/src/index.ts +2 -0
- package/src/integration.ts +176 -40
- package/src/preview/_dispatch.ts +36 -1
- package/src/preview/_resolve-opts.ts +6 -1
- package/src/preview/banner.ts +61 -41
- package/src/preview/cloudflare-adapter.ts +103 -0
- package/src/preview/cookie.ts +14 -23
- 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/landing.ts +115 -37
- package/src/preview/middleware.ts +264 -88
- package/src/preview/preview-path.ts +57 -0
- package/src/preview/redeem-url.ts +14 -0
- package/src/preview/site-middleware.ts +47 -12
- package/src/preview-build.ts +67 -24
- package/src/preview-handler.astro +2 -1
- package/src/skill/SKILL.md +14 -2
- package/src/skill.ts +36 -8
- package/src/types.ts +15 -12
|
@@ -27,12 +27,19 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import type { ContentAPI } from '@conloca/content-api';
|
|
30
|
-
import { fetchPageStatus, type PageStatus } from './_dispatch.js';
|
|
30
|
+
import { fetchPageStatus, isShareEndedKind, type PageStatus } from './_dispatch.js';
|
|
31
31
|
import { injectPreviewBanner } from './banner.js';
|
|
32
32
|
import { PreviewContentAPI } from './content-api.js';
|
|
33
|
-
import { applyPreviewHeaders } from './headers.js';
|
|
33
|
+
import { applyPreviewHeaders, PREVIEW_CACHE_HEADERS } from './headers.js';
|
|
34
|
+
import { renderPreviewUnavailable, renderShareEnded } from './landing.js';
|
|
34
35
|
import { handlePreviewRequest, type PreviewContext, type PreviewMiddlewareOptions } from './middleware.js';
|
|
35
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
normalizeTrailingSlash,
|
|
38
|
+
PREVIEW_SLUG_HEADER,
|
|
39
|
+
pathUnderBase,
|
|
40
|
+
previewScope,
|
|
41
|
+
stripPreviewPrefix,
|
|
42
|
+
} from './preview-path.js';
|
|
36
43
|
|
|
37
44
|
/** The subset of Astro's middleware context this middleware touches. */
|
|
38
45
|
export interface PreviewMiddlewareContext {
|
|
@@ -91,13 +98,20 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
91
98
|
return next();
|
|
92
99
|
}
|
|
93
100
|
|
|
101
|
+
// Under D3 the dispatcher names the requested branch's slug, after stripping any the browser sent.
|
|
102
|
+
const slug = opts.mode === 'd3' ? (context.request.headers.get(PREVIEW_SLUG_HEADER) ?? undefined) : undefined;
|
|
94
103
|
const verdict = await handlePreviewRequest(context.request, {
|
|
95
104
|
...opts,
|
|
96
|
-
|
|
105
|
+
...(slug === undefined ? {} : { slug }),
|
|
106
|
+
// No silent fallback: under the slug, a pass that doesn't verify gets the landing page, never the
|
|
107
|
+
// published page at the draft URL. Only the live site's own requests (no slug) pass through.
|
|
108
|
+
onMiss: slug === undefined ? 'pass-through' : 'landing',
|
|
97
109
|
fetchFn: opts.fetchFn ?? seams.fetchFn,
|
|
98
110
|
});
|
|
99
111
|
if (verdict.kind === 'response') return verdict.response;
|
|
100
112
|
if (verdict.kind !== 'preview') return next();
|
|
113
|
+
// A preview verdict under D3 means the slug was named, so the scope always resolves.
|
|
114
|
+
const exitPath = `${previewScope(opts.mode ?? 'd2', opts.base, slug).route}/__exit`;
|
|
101
115
|
|
|
102
116
|
// A valid credential on the preview route itself: canonicalize to the
|
|
103
117
|
// clean site path instead of rendering under the route — links, assets
|
|
@@ -107,14 +121,15 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
107
121
|
if (stripPreviewPrefix(rawPath, opts.base) !== rawPath) {
|
|
108
122
|
return new Response(null, {
|
|
109
123
|
status: 302,
|
|
110
|
-
headers: { location: path,
|
|
124
|
+
headers: { location: path, ...PREVIEW_CACHE_HEADERS },
|
|
111
125
|
});
|
|
112
126
|
}
|
|
113
127
|
|
|
114
128
|
context.locals.conlocaPreview = verdict.ctx;
|
|
115
|
-
// An endpoint failure (5xx mid-deploy, auth envelope, network) must
|
|
116
|
-
// the
|
|
117
|
-
//
|
|
129
|
+
// An endpoint failure (5xx mid-deploy, auth envelope, network) must neither
|
|
130
|
+
// 500 the site nor pass published bytes off as the draft: answer with a
|
|
131
|
+
// retry page that also offers Exit, since the visitor can't remove the
|
|
132
|
+
// HttpOnly cookie.
|
|
118
133
|
let status: PageStatus;
|
|
119
134
|
try {
|
|
120
135
|
status = await fetchPageStatus({
|
|
@@ -128,10 +143,21 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
128
143
|
});
|
|
129
144
|
} catch (error) {
|
|
130
145
|
console.warn(
|
|
131
|
-
`[@conloca/cloud-astro] preview page-status failed for ${path} —
|
|
146
|
+
`[@conloca/cloud-astro] preview page-status failed for ${path} — showing the retry page: ` +
|
|
132
147
|
`${error instanceof Error ? error.message : String(error)}`,
|
|
133
148
|
);
|
|
134
|
-
return
|
|
149
|
+
return renderPreviewUnavailable({
|
|
150
|
+
// Collapse leading slashes: `//evil.test/x` would otherwise be a cross-origin link.
|
|
151
|
+
retryHref: `/${rawPath.replace(/^\/+/u, '')}${context.url.search}`,
|
|
152
|
+
exitHref: `${exitPath}?to=${encodeURIComponent(rawPath)}`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (isShareEndedKind(status.kind) && 'sharedBy' in status) {
|
|
157
|
+
return renderShareEnded(status.kind, {
|
|
158
|
+
sharedBy: status.sharedBy,
|
|
159
|
+
liveHref: `${exitPath}?to=${encodeURIComponent(path)}`,
|
|
160
|
+
});
|
|
135
161
|
}
|
|
136
162
|
|
|
137
163
|
if (status.kind === 'unchanged') {
|
|
@@ -146,7 +172,7 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
146
172
|
// redirect can never be cached by intermediaries.
|
|
147
173
|
return new Response(null, {
|
|
148
174
|
status: 302,
|
|
149
|
-
headers: { location: status.target,
|
|
175
|
+
headers: { location: status.target, ...PREVIEW_CACHE_HEADERS },
|
|
150
176
|
});
|
|
151
177
|
}
|
|
152
178
|
|
|
@@ -175,11 +201,20 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
175
201
|
// through with the preview headers only.
|
|
176
202
|
return applyPreviewHeaders(rendered);
|
|
177
203
|
}
|
|
204
|
+
let shareUrl: string | undefined;
|
|
205
|
+
if (verdict.ctx.editorUrl !== undefined) {
|
|
206
|
+
const url = new URL(verdict.ctx.editorUrl);
|
|
207
|
+
url.searchParams.set('share', pathUnderBase(path, opts.base));
|
|
208
|
+
shareUrl = url.toString();
|
|
209
|
+
}
|
|
178
210
|
const html = injectPreviewBanner(
|
|
179
211
|
await rendered.text(),
|
|
180
212
|
verdict.ctx,
|
|
181
213
|
opts.saasEndpoint,
|
|
182
|
-
|
|
214
|
+
exitPath,
|
|
215
|
+
shareUrl,
|
|
216
|
+
// The page's own path: under D3 the address bar holds the route, which Edit and Exit must not carry.
|
|
217
|
+
rawPath,
|
|
183
218
|
);
|
|
184
219
|
return applyPreviewHeaders(new Response(html, { status: rendered.status, headers: rendered.headers }));
|
|
185
220
|
};
|
package/src/preview-build.ts
CHANGED
|
@@ -1,35 +1,64 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
PACKAGE_NAME,
|
|
6
|
+
PREVIEW_BUILD_ENV_FLAG,
|
|
7
|
+
PREVIEW_MODE_ENV,
|
|
8
|
+
PREVIEW_PRERENDERED_ENV,
|
|
9
|
+
REFUSED_PREVIEW_ADAPTERS,
|
|
10
|
+
} from './constants.js';
|
|
11
|
+
import type { PreviewServeMode } from './preview/preview-path.js';
|
|
5
12
|
import type { PreviewBuildOptions } from './types.js';
|
|
6
13
|
|
|
7
14
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* adapter
|
|
15
|
+
* How the preview build serves, from the options and the adapter the preview server would build with
|
|
16
|
+
* (`previewBuild.adapter`, else the project's own): off unless `previewBuild` is given as an object; D4 with
|
|
17
|
+
* `separate: true`; D3 for a static site, whose preview server runs next to it on Cloudflare Workers; D2 when an
|
|
18
|
+
* adapter is named, since the site's own server deploy serves the drafts. Throws for a refused adapter, so the build
|
|
19
|
+
* fails before it deploys anything.
|
|
12
20
|
*/
|
|
13
21
|
export function previewBuildMode(
|
|
14
22
|
previewBuild: PreviewBuildOptions | false | undefined,
|
|
15
23
|
adapterName: string | undefined,
|
|
16
|
-
): 'off' |
|
|
24
|
+
): 'off' | PreviewServeMode {
|
|
17
25
|
if (!previewBuild) return 'off';
|
|
18
|
-
if (adapterName
|
|
19
|
-
throw new Error(
|
|
20
|
-
`${PACKAGE_NAME}: the preview build needs an SSR adapter — the project is static and ` +
|
|
21
|
-
'previewBuild.adapter is not set. Pass one (e.g. previewBuild: { adapter: cloudflare() }) ' +
|
|
22
|
-
'or remove previewBuild.',
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
if (REFUSED_PREVIEW_ADAPTERS.includes(adapterName)) {
|
|
26
|
+
if (adapterName !== undefined && REFUSED_PREVIEW_ADAPTERS.includes(adapterName)) {
|
|
26
27
|
throw new Error(
|
|
27
28
|
`${PACKAGE_NAME}: previewBuild is not supported with ${adapterName} yet: that adapter writes its deployable ` +
|
|
28
29
|
'output at the project root, so the preview build could replace the live site. ' +
|
|
29
30
|
'Remove previewBuild from conlocaCloud(...).',
|
|
30
31
|
);
|
|
31
32
|
}
|
|
32
|
-
return '
|
|
33
|
+
if (previewBuild.separate === true) return 'd4';
|
|
34
|
+
return adapterName === undefined ? 'd3' : 'd2';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The mode a preview build serves in: the site's build names D2 or D3; the flag alone is a separate preview deploy (D4). */
|
|
38
|
+
export function previewChildMode(env: NodeJS.ProcessEnv): PreviewServeMode {
|
|
39
|
+
const named = env[PREVIEW_MODE_ENV];
|
|
40
|
+
return named === 'd2' || named === 'd3' ? named : 'd4';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One route the site's build prerendered, as a D3 child matches it: pattern and component together, since one
|
|
45
|
+
* entrypoint can be injected at two patterns, one published and one only the preview build has.
|
|
46
|
+
*/
|
|
47
|
+
export function prerenderedKey(pattern: string, component: string): string {
|
|
48
|
+
return JSON.stringify([pattern, component]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The routes (`prerenderedKey`) a D3 child's site build prerendered (`buildPreviewChildEnv`); none for any other child. */
|
|
52
|
+
export function previewChildPrerendered(env: NodeJS.ProcessEnv): Set<string> {
|
|
53
|
+
const text = env[PREVIEW_PRERENDERED_ENV];
|
|
54
|
+
if (previewChildMode(env) !== 'd3' || text === undefined) return new Set();
|
|
55
|
+
let value: unknown;
|
|
56
|
+
try {
|
|
57
|
+
value = JSON.parse(text);
|
|
58
|
+
} catch {
|
|
59
|
+
return new Set();
|
|
60
|
+
}
|
|
61
|
+
return new Set(Array.isArray(value) ? value.filter((item) => typeof item === 'string') : []);
|
|
33
62
|
}
|
|
34
63
|
|
|
35
64
|
/**
|
|
@@ -59,11 +88,16 @@ export type PreviewBuildSpawn = (
|
|
|
59
88
|
* build vars (CF_PAGES_*, WORKERS_CI_*, GITHUB_*) reach the child, which reads
|
|
60
89
|
* the branch and commit it serves from them.
|
|
61
90
|
*/
|
|
62
|
-
export function buildPreviewChildEnv(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
91
|
+
export function buildPreviewChildEnv(
|
|
92
|
+
parentEnv: NodeJS.ProcessEnv,
|
|
93
|
+
mode: 'd2' | 'd3' = 'd2',
|
|
94
|
+
prerendered: readonly string[] = [],
|
|
95
|
+
): NodeJS.ProcessEnv {
|
|
96
|
+
const env: NodeJS.ProcessEnv = { ...parentEnv, [PREVIEW_BUILD_ENV_FLAG]: '1', [PREVIEW_MODE_ENV]: mode };
|
|
97
|
+
// Only a D3 child reads it; a stale one from the environment must not reach a D2 child.
|
|
98
|
+
delete env[PREVIEW_PRERENDERED_ENV];
|
|
99
|
+
if (mode === 'd3') env[PREVIEW_PRERENDERED_ENV] = JSON.stringify(prerendered);
|
|
100
|
+
return env;
|
|
67
101
|
}
|
|
68
102
|
|
|
69
103
|
/**
|
|
@@ -111,8 +145,12 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
|
|
|
111
145
|
* - `false` → resolves and logs a warning so onboarding setups can continue
|
|
112
146
|
* when the preview build is not yet wired correctly.
|
|
113
147
|
*/
|
|
114
|
-
export async function spawnPreviewBuild(
|
|
115
|
-
|
|
148
|
+
export async function spawnPreviewBuild(
|
|
149
|
+
opts: PreviewBuildOptions,
|
|
150
|
+
mode: 'd2' | 'd3' = 'd2',
|
|
151
|
+
prerendered: readonly string[] = [],
|
|
152
|
+
): Promise<void> {
|
|
153
|
+
await _spawnPreviewBuildWith(spawn, opts, mode, prerendered);
|
|
116
154
|
}
|
|
117
155
|
|
|
118
156
|
/**
|
|
@@ -124,7 +162,12 @@ export async function spawnPreviewBuild(opts: PreviewBuildOptions): Promise<void
|
|
|
124
162
|
* `src/index.ts` or `src/node.ts`.
|
|
125
163
|
*/
|
|
126
164
|
// oxlint-disable-next-line no-underscore-dangle -- the internal test seam.
|
|
127
|
-
export async function _spawnPreviewBuildWith(
|
|
165
|
+
export async function _spawnPreviewBuildWith(
|
|
166
|
+
spawnFn: PreviewBuildSpawn,
|
|
167
|
+
opts: PreviewBuildOptions,
|
|
168
|
+
mode: 'd2' | 'd3' = 'd2',
|
|
169
|
+
prerendered: readonly string[] = [],
|
|
170
|
+
): Promise<void> {
|
|
128
171
|
// Recursion guard: bail out before doing any work if we're already inside
|
|
129
172
|
// a recursive preview build. This matches the short-circuit in the
|
|
130
173
|
// integration's `astro:build:done` hook.
|
|
@@ -136,7 +179,7 @@ export async function _spawnPreviewBuildWith(spawnFn: PreviewBuildSpawn, opts: P
|
|
|
136
179
|
|
|
137
180
|
const astroBin = resolveAstroBin();
|
|
138
181
|
const child = spawnFn(astroBin, ['build'], {
|
|
139
|
-
env: buildPreviewChildEnv(process.env),
|
|
182
|
+
env: buildPreviewChildEnv(process.env, mode, prerendered),
|
|
140
183
|
stdio: 'inherit',
|
|
141
184
|
});
|
|
142
185
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import bakedPreviewOpts from 'virtual:conloca-preview-opts';
|
|
3
3
|
import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
|
|
4
|
+
import { PREVIEW_CACHE_HEADERS } from './preview/headers.js';
|
|
4
5
|
import { stripPreviewPrefix } from './preview/preview-path.js';
|
|
5
6
|
/**
|
|
6
7
|
* Entry route injected by the recursive preview build at the fixed, public
|
|
@@ -51,7 +52,7 @@ if (verdict.kind === 'pass-through') {
|
|
|
51
52
|
const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname, opts.base);
|
|
52
53
|
const canonical: Response = new Response(null, {
|
|
53
54
|
status: 302,
|
|
54
|
-
headers: { location: cleanPath,
|
|
55
|
+
headers: { location: cleanPath, ...PREVIEW_CACHE_HEADERS },
|
|
55
56
|
});
|
|
56
57
|
return canonical;
|
|
57
58
|
---
|
package/src/skill/SKILL.md
CHANGED
|
@@ -22,7 +22,9 @@ into `sites.json`, adds a framing rule only where a committed header file forbid
|
|
|
22
22
|
editor page, and removes old build key lines from workflows. It shows diffs first, keeps values you set (`differs`), and
|
|
23
23
|
exits `2` with the lines to add when a step needs a person (`--site-url https://…` when `astro.config` has no `site`).
|
|
24
24
|
It never commits, pushes or deploys: commit, push to the default branch, deploy as usual, then open the workspace
|
|
25
|
-
editor. Editing needs the deployed site; before that, `astro dev` serves the local editor at `/__cms`.
|
|
25
|
+
editor. Editing needs the deployed site; before that, `astro dev` serves the local editor at `/__cms`. Package updates
|
|
26
|
+
go through `npx @conloca/cli@latest upgrade` (or the exact version a Conloca prompt gave), never by editing `@conloca/*`
|
|
27
|
+
versions.
|
|
26
28
|
|
|
27
29
|
## First move: `conloca doctor --live`
|
|
28
30
|
|
|
@@ -34,7 +36,7 @@ conloca doctor --live # sends no credential: only your site's host and the e
|
|
|
34
36
|
conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
This package's checks are `CC1` and `CC8`–`
|
|
39
|
+
This package's checks are `CC1` and `CC8`–`CC24`:
|
|
38
40
|
|
|
39
41
|
- **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
|
|
40
42
|
valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
|
|
@@ -47,6 +49,16 @@ This package's checks are `CC1` and `CC8`–`CC14`:
|
|
|
47
49
|
- **CC13** (live) — the page's protocol is in the editor's range; too old → rebuild with a newer `@conloca/cloud-astro`.
|
|
48
50
|
- **CC14** — a workflow or the config still names `CONLOCA_BUILD_TOKEN`, `buildToken`, `publicBaseUrl`, `previewDomain`
|
|
49
51
|
or `requireRegistration`. Remove them; nothing reads them for the editor page.
|
|
52
|
+
- **CC15–CC21** — draft previews on a static site: `wrangler.jsonc` on Cloudflare Workers, wrangler ≥ 4.36, the
|
|
53
|
+
dispatcher `main`, `run_worker_first` covering the preview route and every on-demand route, no deploy redirect into
|
|
54
|
+
`.conloca/preview-server`, a 404 page, middleware negotiation, no tag manager. Fix:
|
|
55
|
+
`npx @conloca/cli connect --update --yes`, then deploy. A `wrangler.toml` must be converted to `wrangler.jsonc` first.
|
|
56
|
+
- **CC22–CC23** — the preview rate-limit binding (`conlocaPreviewLimit`, 60 per 10 s, in every env block) on the Paid
|
|
57
|
+
plan, none on the Free plan, and the Cloudflare plan recorded in `package.json` (`conloca.cfPlan`). Fix:
|
|
58
|
+
`connect --update --yes`; for the plan, ask the site's owner which plan the Cloudflare account is on and run
|
|
59
|
+
`connect --yes --cf-plan paid` (or `free`). On Free with API routes, CC23 warns that previews and those routes share
|
|
60
|
+
one daily request quota; Cloudflare Workers Paid removes the limit.
|
|
61
|
+
- **CC24** (live) — a separate preview deploy's `conloca.json` answers as D4.
|
|
50
62
|
|
|
51
63
|
## Framing: only when the site forbids it
|
|
52
64
|
|
package/src/skill.ts
CHANGED
|
@@ -2,10 +2,18 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { stampSkill } from '@conloca/content-api/skill-stamp';
|
|
5
6
|
import { messageOf } from './message-of.js';
|
|
7
|
+
import { packageVersion } from './package-version.js';
|
|
6
8
|
|
|
7
9
|
export const SKILL_RELATIVE_PATH = join('.claude', 'skills', 'conloca-cloud', 'SKILL.md');
|
|
8
10
|
|
|
11
|
+
/** The sha256 of every unstamped page a release wrote, so an upgrade can tell an untouched old page from an edited one. */
|
|
12
|
+
export const LEGACY_SKILL_CHECKSUMS: readonly string[] = [
|
|
13
|
+
'201dc9a1fe57038c32a46448228ab432cce060b0079225007ec6dec74ba46959', // 0.2.1, 0.2.2
|
|
14
|
+
'82edfffa022797265bee87289a491e7af12d8e13423f541892e281c416f0554a', // 0.2.3
|
|
15
|
+
];
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* The canonical page, located from the package root (through the package's own `./package.json` export) so the
|
|
11
19
|
* built `dist/src/skill.js` and the source `src/skill.ts` reach the same shipped `src/skill/SKILL.md`. Resolved on
|
|
@@ -39,21 +47,41 @@ export function findClaudeHome(projectRoot: string): string | undefined {
|
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Where the site's agent skill page belongs and the text this release writes there, stamped with the release and the
|
|
52
|
+
* template's checksum. Null without a `.claude/` home or a readable package version.
|
|
53
|
+
*/
|
|
54
|
+
export function agentSkill(
|
|
55
|
+
projectRoot: string,
|
|
56
|
+
): { path: string; text: string; legacyChecksums: readonly string[] } | null {
|
|
57
|
+
const home = findClaudeHome(projectRoot);
|
|
58
|
+
const version = packageVersion();
|
|
59
|
+
if (home === undefined || version === undefined) return null;
|
|
60
|
+
return {
|
|
61
|
+
path: join(home, SKILL_RELATIVE_PATH),
|
|
62
|
+
text: stampSkill(readFileSync(skillTemplateUrl(), 'utf8'), version),
|
|
63
|
+
legacyChecksums: LEGACY_SKILL_CHECKSUMS,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
42
67
|
/**
|
|
43
68
|
* Write the skill page once — never overwrite, never throw. A read-only CI
|
|
44
69
|
* checkout must not break a build over documentation.
|
|
45
70
|
*/
|
|
46
71
|
export function scaffoldSkill(projectRoot: string, logger: SkillLogger): 'written' | 'exists' | 'skipped' | 'failed' {
|
|
47
|
-
|
|
48
|
-
if (home === undefined) {
|
|
49
|
-
logger.debug('no .claude/ directory between the project and the git root — agent skill not scaffolded');
|
|
50
|
-
return 'skipped';
|
|
51
|
-
}
|
|
52
|
-
const target = join(home, SKILL_RELATIVE_PATH);
|
|
53
|
-
if (existsSync(target)) return 'exists';
|
|
72
|
+
let target = SKILL_RELATIVE_PATH;
|
|
54
73
|
try {
|
|
74
|
+
const skill = agentSkill(projectRoot);
|
|
75
|
+
if (skill === null) {
|
|
76
|
+
logger.debug(
|
|
77
|
+
'no .claude/ directory between the project and the git root, or no readable package version — agent skill not scaffolded',
|
|
78
|
+
);
|
|
79
|
+
return 'skipped';
|
|
80
|
+
}
|
|
81
|
+
target = skill.path;
|
|
82
|
+
if (existsSync(target)) return 'exists';
|
|
55
83
|
mkdirSync(dirname(target), { recursive: true });
|
|
56
|
-
writeFileSync(target,
|
|
84
|
+
writeFileSync(target, skill.text, { flag: 'wx' });
|
|
57
85
|
logger.info(`agent skill written to ${target}`);
|
|
58
86
|
return 'written';
|
|
59
87
|
} catch (error) {
|
package/src/types.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { AstroIntegration } from 'astro';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Off unless given as an object: the second build that serves draft previews.
|
|
9
|
-
* It needs an SSR adapter (the project's own or `adapter` here) and is refused
|
|
10
|
-
* under `@astrojs/vercel` and `@astrojs/netlify`.
|
|
4
|
+
* The second build that serves draft previews. Off unless given as an object. A static site's preview server runs on
|
|
5
|
+
* Cloudflare Workers under `/_conloca/preview/` next to the site (it needs `@astrojs/cloudflare` installed); a site
|
|
6
|
+
* with an adapter serves drafts from its own server deploy; `separate: true` builds a separate preview deploy.
|
|
7
|
+
* Refused under `@astrojs/vercel` and `@astrojs/netlify`.
|
|
11
8
|
*/
|
|
12
9
|
export interface PreviewBuildOptions {
|
|
13
10
|
/**
|
|
@@ -26,10 +23,17 @@ export interface PreviewBuildOptions {
|
|
|
26
23
|
*/
|
|
27
24
|
outDir?: string;
|
|
28
25
|
/**
|
|
29
|
-
* If true, fail the
|
|
30
|
-
*
|
|
26
|
+
* If true, fail the site's build when a D2 preview build fails. Defaults to true; set false while setting up.
|
|
27
|
+
* A failed D3 preview build fails the site's build only when its server also serves the live site (`run_worker_first`
|
|
28
|
+
* lists routes beyond the preview route, or `not_found_handling` is `"none"`); otherwise the site ships and its
|
|
29
|
+
* preview route answers "preview unavailable". This option changes neither.
|
|
31
30
|
*/
|
|
32
31
|
required?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Serve previews from a separate deploy (D4) instead of next to the site. The site's build then runs no preview
|
|
34
|
+
* build; a second deploy builds with `CONLOCA_PREVIEW_BUILD=1`, and its address goes in sites.json `previewUrl`.
|
|
35
|
+
*/
|
|
36
|
+
separate?: boolean;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
@@ -80,9 +84,8 @@ export interface ConlocaCloudOptions {
|
|
|
80
84
|
*/
|
|
81
85
|
previewBuild?: PreviewBuildOptions | false;
|
|
82
86
|
/**
|
|
83
|
-
* The token issuer (the JWT `iss` the preview
|
|
84
|
-
*
|
|
85
|
-
* deployment must supply `CONLOCA_SAAS_ISSUER` at runtime.
|
|
87
|
+
* The token issuer (the JWT `iss`) every pass must name. Unset, the preview server checks the pass against the
|
|
88
|
+
* endpoint's published keys alone, so a site sets nothing at runtime; set it (or `CONLOCA_SAAS_ISSUER`) to pin it.
|
|
86
89
|
*/
|
|
87
90
|
saasIssuer?: string;
|
|
88
91
|
}
|