@conloca/cloud-astro 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +69 -22
  2. package/dist/.build-inputs.json +36 -23
  3. package/dist/src/constants.d.ts +4 -4
  4. package/dist/src/constants.js +4 -4
  5. package/dist/src/d3-build.d.ts +6 -2
  6. package/dist/src/d3-build.d.ts.map +1 -1
  7. package/dist/src/d3-build.js +15 -11
  8. package/dist/src/d3-build.js.map +1 -1
  9. package/dist/src/d8-adapters.d.ts +10 -0
  10. package/dist/src/d8-adapters.d.ts.map +1 -0
  11. package/dist/src/d8-adapters.js +19 -0
  12. package/dist/src/d8-adapters.js.map +1 -0
  13. package/dist/src/d8-build.d.ts +99 -0
  14. package/dist/src/d8-build.d.ts.map +1 -0
  15. package/dist/src/d8-build.js +265 -0
  16. package/dist/src/d8-build.js.map +1 -0
  17. package/dist/src/d8-guards.d.ts +29 -0
  18. package/dist/src/d8-guards.d.ts.map +1 -0
  19. package/dist/src/d8-guards.js +145 -0
  20. package/dist/src/d8-guards.js.map +1 -0
  21. package/dist/src/d8-middleware.d.ts +7 -0
  22. package/dist/src/d8-middleware.d.ts.map +1 -0
  23. package/dist/src/d8-middleware.js +15 -0
  24. package/dist/src/d8-middleware.js.map +1 -0
  25. package/dist/src/d8-render.d.ts +9 -0
  26. package/dist/src/d8-render.d.ts.map +1 -0
  27. package/dist/src/d8-render.js +52 -0
  28. package/dist/src/d8-render.js.map +1 -0
  29. package/dist/src/doctor/checks-d8.d.ts +7 -0
  30. package/dist/src/doctor/checks-d8.d.ts.map +1 -0
  31. package/dist/src/doctor/checks-d8.js +240 -0
  32. package/dist/src/doctor/checks-d8.js.map +1 -0
  33. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  34. package/dist/src/doctor/checks-live.js +3 -5
  35. package/dist/src/doctor/checks-live.js.map +1 -1
  36. package/dist/src/doctor/checks-offline.d.ts +2 -0
  37. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  38. package/dist/src/doctor/checks-offline.js +17 -8
  39. package/dist/src/doctor/checks-offline.js.map +1 -1
  40. package/dist/src/doctor/checks-preview-live.d.ts +7 -2
  41. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -1
  42. package/dist/src/doctor/checks-preview-live.js +107 -7
  43. package/dist/src/doctor/checks-preview-live.js.map +1 -1
  44. package/dist/src/doctor/checks-preview.d.ts.map +1 -1
  45. package/dist/src/doctor/checks-preview.js +9 -4
  46. package/dist/src/doctor/checks-preview.js.map +1 -1
  47. package/dist/src/doctor/config-scan.d.ts +24 -6
  48. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  49. package/dist/src/doctor/config-scan.js +89 -18
  50. package/dist/src/doctor/config-scan.js.map +1 -1
  51. package/dist/src/doctor/run.d.ts.map +1 -1
  52. package/dist/src/doctor/run.js +2 -0
  53. package/dist/src/doctor/run.js.map +1 -1
  54. package/dist/src/doctor/types.d.ts +7 -0
  55. package/dist/src/doctor/types.d.ts.map +1 -1
  56. package/dist/src/doctor/types.js +7 -0
  57. package/dist/src/doctor/types.js.map +1 -1
  58. package/dist/src/editor-page/emit.d.ts +4 -3
  59. package/dist/src/editor-page/emit.d.ts.map +1 -1
  60. package/dist/src/editor-page/emit.js +9 -9
  61. package/dist/src/editor-page/emit.js.map +1 -1
  62. package/dist/src/integration.d.ts.map +1 -1
  63. package/dist/src/integration.js +228 -124
  64. package/dist/src/integration.js.map +1 -1
  65. package/dist/src/node.d.ts +2 -0
  66. package/dist/src/node.d.ts.map +1 -1
  67. package/dist/src/node.js +4 -0
  68. package/dist/src/node.js.map +1 -1
  69. package/dist/src/preview/_resolve-opts.d.ts +26 -1
  70. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  71. package/dist/src/preview/_resolve-opts.js.map +1 -1
  72. package/dist/src/preview/content-api.d.ts +15 -0
  73. package/dist/src/preview/content-api.d.ts.map +1 -1
  74. package/dist/src/preview/content-api.js +57 -6
  75. package/dist/src/preview/content-api.js.map +1 -1
  76. package/dist/src/preview/d8-middleware.d.ts +25 -0
  77. package/dist/src/preview/d8-middleware.d.ts.map +1 -0
  78. package/dist/src/preview/d8-middleware.js +94 -0
  79. package/dist/src/preview/d8-middleware.js.map +1 -0
  80. package/dist/src/preview/dispatcher.d.ts +3 -16
  81. package/dist/src/preview/dispatcher.d.ts.map +1 -1
  82. package/dist/src/preview/dispatcher.js +46 -134
  83. package/dist/src/preview/dispatcher.js.map +1 -1
  84. package/dist/src/preview/headers.d.ts +3 -0
  85. package/dist/src/preview/headers.d.ts.map +1 -1
  86. package/dist/src/preview/headers.js +10 -1
  87. package/dist/src/preview/headers.js.map +1 -1
  88. package/dist/src/preview/links.d.ts +23 -0
  89. package/dist/src/preview/links.d.ts.map +1 -0
  90. package/dist/src/preview/links.js +168 -0
  91. package/dist/src/preview/links.js.map +1 -0
  92. package/dist/src/preview/middleware.d.ts +9 -3
  93. package/dist/src/preview/middleware.d.ts.map +1 -1
  94. package/dist/src/preview/middleware.js +36 -16
  95. package/dist/src/preview/middleware.js.map +1 -1
  96. package/dist/src/preview/prefix-router.d.ts +67 -0
  97. package/dist/src/preview/prefix-router.d.ts.map +1 -0
  98. package/dist/src/preview/prefix-router.js +153 -0
  99. package/dist/src/preview/prefix-router.js.map +1 -0
  100. package/dist/src/preview/preview-path.d.ts +8 -3
  101. package/dist/src/preview/preview-path.d.ts.map +1 -1
  102. package/dist/src/preview/preview-path.js +16 -4
  103. package/dist/src/preview/preview-path.js.map +1 -1
  104. package/dist/src/preview/site-middleware.d.ts +8 -2
  105. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  106. package/dist/src/preview/site-middleware.js +90 -31
  107. package/dist/src/preview/site-middleware.js.map +1 -1
  108. package/dist/src/preview/site-page-sources.d.ts +21 -0
  109. package/dist/src/preview/site-page-sources.d.ts.map +1 -0
  110. package/dist/src/preview/site-page-sources.js +129 -0
  111. package/dist/src/preview/site-page-sources.js.map +1 -0
  112. package/dist/src/preview/site-pages.d.ts +18 -0
  113. package/dist/src/preview/site-pages.d.ts.map +1 -0
  114. package/dist/src/preview/site-pages.js +7 -0
  115. package/dist/src/preview/site-pages.js.map +1 -0
  116. package/dist/src/preview-build.d.ts +17 -16
  117. package/dist/src/preview-build.d.ts.map +1 -1
  118. package/dist/src/preview-build.js +37 -40
  119. package/dist/src/preview-build.js.map +1 -1
  120. package/dist/src/preview-image-endpoint.d.ts +8 -0
  121. package/dist/src/preview-image-endpoint.d.ts.map +1 -0
  122. package/dist/src/preview-image-endpoint.js +34 -0
  123. package/dist/src/preview-image-endpoint.js.map +1 -0
  124. package/dist/src/preview-render-seams.d.ts +7 -0
  125. package/dist/src/preview-render-seams.d.ts.map +1 -0
  126. package/dist/src/preview-render-seams.js +27 -0
  127. package/dist/src/preview-render-seams.js.map +1 -0
  128. package/dist/src/site-middleware.d.ts +2 -4
  129. package/dist/src/site-middleware.d.ts.map +1 -1
  130. package/dist/src/site-middleware.js +6 -22
  131. package/dist/src/site-middleware.js.map +1 -1
  132. package/dist/src/types.d.ts +15 -16
  133. package/dist/src/types.d.ts.map +1 -1
  134. package/package.json +138 -6
  135. package/src/constants.ts +4 -4
  136. package/src/d3-build.ts +20 -14
  137. package/src/d8-adapters.ts +19 -0
  138. package/src/d8-build.ts +356 -0
  139. package/src/d8-guards.ts +177 -0
  140. package/src/d8-middleware.ts +17 -0
  141. package/src/d8-render.ts +61 -0
  142. package/src/doctor/checks-d8.ts +256 -0
  143. package/src/doctor/checks-live.ts +3 -4
  144. package/src/doctor/checks-offline.ts +21 -8
  145. package/src/doctor/checks-preview-live.ts +114 -8
  146. package/src/doctor/checks-preview.ts +9 -4
  147. package/src/doctor/config-scan.ts +86 -15
  148. package/src/doctor/run.ts +2 -0
  149. package/src/doctor/types.ts +8 -0
  150. package/src/editor-page/emit.ts +23 -14
  151. package/src/integration.ts +274 -135
  152. package/src/node.ts +4 -0
  153. package/src/preview/_resolve-opts.ts +17 -1
  154. package/src/preview/content-api.ts +60 -5
  155. package/src/preview/d8-middleware.ts +124 -0
  156. package/src/preview/dispatcher.ts +55 -150
  157. package/src/preview/headers.ts +10 -1
  158. package/src/preview/links.ts +175 -0
  159. package/src/preview/middleware.ts +41 -19
  160. package/src/preview/prefix-router.ts +197 -0
  161. package/src/preview/preview-path.ts +24 -6
  162. package/src/preview/site-middleware.ts +109 -38
  163. package/src/preview/site-page-sources.ts +146 -0
  164. package/src/preview/site-pages.ts +22 -0
  165. package/src/preview-build.ts +43 -42
  166. package/src/preview-image-endpoint.ts +35 -0
  167. package/src/preview-render-seams.ts +31 -0
  168. package/src/site-middleware.ts +6 -24
  169. package/src/skill/SKILL.md +19 -1
  170. package/src/types.ts +15 -16
  171. package/src/virtual-modules.d.ts +17 -2
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The site's build serving d8: the draft preview renders inside the site's own build, at the preview route, with
3
+ * the values every pass is checked against baked in. Also what every preview build bakes.
4
+ */
5
+ import type { AstroConfig, IntegrationResolvedRoute } from 'astro';
6
+ import { onDemandPatterns } from './d3-build.js';
7
+ import type { BakedPreviewOpts } from './preview/_resolve-opts.js';
8
+ import type { ConlocaCloudOptions } from './types.js';
9
+ /**
10
+ * astro-cms's second copy of its page handler, as the site resolves it: a route injected at it is a route of its own,
11
+ * where one at the published handler's file would be taken for that route.
12
+ */
13
+ export declare function previewPageHandlerPath(root: URL): string;
14
+ export interface BakeInput {
15
+ options: ConlocaCloudOptions;
16
+ config: Pick<AstroConfig, 'root' | 'base'>;
17
+ repoUri: string | undefined;
18
+ env: NodeJS.ProcessEnv;
19
+ }
20
+ /**
21
+ * What every preview build bakes into its artifact, so a correctly built preview needs NO env vars on the
22
+ * deployment: the endpoint and audience are integration options; repository, site, branch, base and commit are what
23
+ * this build was made from, and every pass must match the first three. `saasIssuer` stays unbaked unless configured:
24
+ * it is a property of the endpoint, not of the site. Throws without a repository or a branch.
25
+ */
26
+ export declare function bakedIdentity({ options, config, repoUri, env, }: BakeInput): BakedPreviewOpts & {
27
+ repo: string;
28
+ siteId: string;
29
+ branch: string;
30
+ };
31
+ /** What a d8 site build bakes: the identity, plus the routing values the draft render moves links with. */
32
+ export declare function d8Baked(input: BakeInput & {
33
+ config: Pick<AstroConfig, 'root' | 'base' | 'trailingSlash' | 'site'> & SitePagesConfig & {
34
+ build: Pick<AstroConfig['build'], 'format'>;
35
+ };
36
+ }): Promise<BakedPreviewOpts>;
37
+ /**
38
+ * The media folder's link base, from the source conloca.json's `media` uses, and the images in it this build deploys
39
+ * (relative to it): a draft link to any other image is a file committed on the branch, served by the media route.
40
+ * A branch file with a deployed file's name shows the deployed bytes. Symlinked subfolders are not followed. Unbaked
41
+ * (no git repository, an unreadable folder), draft addresses still move; branch-committed images do not.
42
+ * Throws when the folder can't be read.
43
+ */
44
+ export declare function bakedMedia(channel: {
45
+ assetsPath?: string;
46
+ assetRefBase?: string;
47
+ } | undefined, root: URL): BakedPreviewOpts['media'];
48
+ /** Only builds that render drafts from this build's own files bake its media list. */
49
+ export declare function bakesMedia(mode: string | undefined): boolean;
50
+ type SitePagesConfig = Pick<AstroConfig, 'site'> & {
51
+ adapter?: {
52
+ name: string;
53
+ };
54
+ build: Pick<AstroConfig['build'], 'serverEntry'>;
55
+ };
56
+ /** The site's own prerendered pages; `exact` holds those a site route's own output file names. */
57
+ export interface SitePagesList {
58
+ pages: string[];
59
+ exact: string[];
60
+ }
61
+ /**
62
+ * The pages the site prerendered itself, base included, in normalizeTrailingSlash form: every page `astro:build:done`
63
+ * reports but those the CMS route wrote. A page goes to the route whose output files hold it (`pages` names no route);
64
+ * that page is `exact`, since production serves the site route there by route priority. One no route's files hold
65
+ * goes to the first prerendered route that matches it (`routes` is in Astro's priority order), and is not exact.
66
+ */
67
+ export declare function sitePagesOf(pages: readonly {
68
+ pathname: string;
69
+ }[], assets: ReadonlyMap<string, readonly URL[]>, routes: readonly Pick<IntegrationResolvedRoute, 'pattern' | 'patternRegex' | 'entrypoint' | 'isPrerendered' | 'type'>[], dir: URL, base: string): SitePagesList;
70
+ /**
71
+ * Writes `site-pages.json` where the adapter's runtime reads it (`preview/site-page-sources.ts`), none of it needing
72
+ * `site`: beside the Node server entry; beside every copy of the server entry in the Vercel or Netlify function bundle
73
+ * (the adapter's build:done, which runs first, wrote it); in the Cloudflare client build's editor folder. Returns the
74
+ * files written; throws when the function bundle holds no server entry.
75
+ */
76
+ export declare function writeSitePagesList(adapterName: string, config: Pick<AstroConfig, 'root'> & {
77
+ build: Pick<AstroConfig['build'], 'server' | 'client' | 'serverEntry'>;
78
+ }, list: SitePagesList): Promise<string[]>;
79
+ /** The endpoint d8 moves the image route to: Cloudflare's own passthrough there, Conloca's redirect elsewhere. */
80
+ export declare function d8ImageEndpoint(adapterName: string): string;
81
+ /**
82
+ * Astro's own image services, Cloudflare's and Netlify's (whose URLs go to `/.netlify/images`): they serve `<Image>`
83
+ * URLs that do not depend on the endpoint route.
84
+ */
85
+ export declare function knownImageService(entrypoint: string | undefined): boolean;
86
+ /** Whether the site renders anything on demand, as far as astro.config and `src/pages` tell before routes exist. */
87
+ export declare function hasOnDemandRoutes(config: Pick<AstroConfig, 'output' | 'srcDir'>): Promise<boolean>;
88
+ /** Site on-demand routes other than ours and Astro's runtime routes (`/_image`, `/_server-islands/[name]`, default `/404`). */
89
+ export declare function siteOnDemand(routes: Parameters<typeof onDemandPatterns>[0], prefixPattern: string): string[];
90
+ /** The rewritten Vercel config, or null to leave it (with the reason to warn). */
91
+ export declare function narrowVercelCatchAll(config: unknown, siteStaticWithoutPreview: boolean): {
92
+ config: unknown;
93
+ } | {
94
+ leave: string;
95
+ } | null;
96
+ /** Problems in the Cloudflare adapter's dist/server/wrangler.json for a d8 site, each with what it breaks and the edit (empty when fine). */
97
+ export declare function cloudflareD8Problems(wrangler: unknown, expected: readonly string[]): string[];
98
+ export {};
99
+ //# sourceMappingURL=d8-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d8-build.d.ts","sourceRoot":"","sources":["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AE,MAAM,GAAG,MAAM,CAI3D;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAQzE;AAED,oHAAoH;AACpH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAWxG;AAED,+HAA+H;AAC/H,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAS5G;AAMD,kFAAkF;AAClF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,EACf,wBAAwB,EAAE,OAAO,GAChC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiBhD;AAED,6IAA6I;AAC7I,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAa7F"}
@@ -0,0 +1,265 @@
1
+ /**
2
+ * The site's build serving d8: the draft preview renders inside the site's own build, at the preview route, with
3
+ * the values every pass is checked against baked in. Also what every preview build bakes.
4
+ */
5
+ import { existsSync, readdirSync } from 'node:fs';
6
+ import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
7
+ import { createRequire } from 'node:module';
8
+ import { basename, dirname, join, relative, sep } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { isDeepStrictEqual } from 'node:util';
11
+ import { mediaRefPath } from '@conloca/content-api';
12
+ import { isRecord } from '@conloca/content-api/component-vocabulary';
13
+ import { DEFAULT_EDITOR_ENDPOINT } from '@conloca/content-api/editor-host';
14
+ import { PACKAGE_NAME } from './constants.js';
15
+ import { declaredDomains, deployProblems, onDemandPatterns } from './d3-build.js';
16
+ import { mediaFromBuild } from './editor-page/emit.js';
17
+ import { gitOutput, resolveBuildRef } from './git.js';
18
+ import { normalizeTrailingSlash } from './preview/preview-path.js';
19
+ import { resolveBuildSiteId } from './site-id.js';
20
+ /**
21
+ * astro-cms's second copy of its page handler, as the site resolves it: a route injected at it is a route of its own,
22
+ * where one at the published handler's file would be taken for that route.
23
+ */
24
+ export function previewPageHandlerPath(root) {
25
+ const manifest = createRequire(new URL('package.json', root)).resolve('@conloca/astro-cms/package.json');
26
+ const path = join(dirname(manifest), 'dist', 'internal', 'preview-page-handler.astro');
27
+ if (!existsSync(path)) {
28
+ throw new Error(`@conloca/astro-cms is too old for draft preview on this site (no ${path}); upgrade it`);
29
+ }
30
+ return path;
31
+ }
32
+ /**
33
+ * What every preview build bakes into its artifact, so a correctly built preview needs NO env vars on the
34
+ * deployment: the endpoint and audience are integration options; repository, site, branch, base and commit are what
35
+ * this build was made from, and every pass must match the first three. `saasIssuer` stays unbaked unless configured:
36
+ * it is a property of the endpoint, not of the site. Throws without a repository or a branch.
37
+ */
38
+ export function bakedIdentity({ options, config, repoUri, env, }) {
39
+ if (!repoUri) {
40
+ throw new Error(`${PACKAGE_NAME}: could not determine repository identity for the preview build ` +
41
+ '(build in a Git checkout or set repoUri as an advanced override)');
42
+ }
43
+ // The project's own checkout answers git, not the directory the build was started from.
44
+ const projectGit = (args) => gitOutput(args, fileURLToPath(config.root));
45
+ const buildRef = resolveBuildRef(env, projectGit);
46
+ if (!buildRef.branch) {
47
+ throw new Error(`${PACKAGE_NAME}: could not determine the branch the preview build serves (set CF_PAGES_BRANCH, ` +
48
+ 'WORKERS_CI_BRANCH, VERCEL_GIT_COMMIT_REF or GITHUB_REF_NAME, or build in a git checkout on a branch)');
49
+ }
50
+ const siteId = resolveBuildSiteId({ contentRoot: env.CONLOCA_CONTENT_ROOT, override: options.siteId });
51
+ // The commit this build's checkout holds: a PR build may check out a merge commit rather than the commit CI hands
52
+ // over. Page-status compares the branch's latest commit with it, so the endpoint diffs against the content actually
53
+ // serving; a checkout commit the endpoint does not have makes it render from the branch instead.
54
+ const buildCommit = projectGit(['rev-parse', 'HEAD']) ?? buildRef.gitSha;
55
+ return {
56
+ saasEndpoint: options.endpoint ?? DEFAULT_EDITOR_ENDPOINT,
57
+ // The token's `aud` is the repo URI this build resolved.
58
+ saasAudience: repoUri,
59
+ ...(options.saasIssuer ? { saasIssuer: options.saasIssuer } : {}),
60
+ ...(buildCommit ? { buildCommit } : {}),
61
+ repo: repoUri,
62
+ siteId,
63
+ branch: buildRef.branch,
64
+ base: config.base ?? '/',
65
+ };
66
+ }
67
+ /** What a d8 site build bakes: the identity, plus the routing values the draft render moves links with. */
68
+ export async function d8Baked(input) {
69
+ return {
70
+ ...bakedIdentity(input),
71
+ mode: 'd8',
72
+ domains: await declaredDomains(input.env.CONLOCA_CONTENT_ROOT),
73
+ trailingSlash: input.config.trailingSlash,
74
+ buildFormat: input.config.build.format,
75
+ sitePages: bakedSitePages(input.config, input.env),
76
+ };
77
+ }
78
+ /**
79
+ * The media folder's link base, from the source conloca.json's `media` uses, and the images in it this build deploys
80
+ * (relative to it): a draft link to any other image is a file committed on the branch, served by the media route.
81
+ * A branch file with a deployed file's name shows the deployed bytes. Symlinked subfolders are not followed. Unbaked
82
+ * (no git repository, an unreadable folder), draft addresses still move; branch-committed images do not.
83
+ * Throws when the folder can't be read.
84
+ */
85
+ export function bakedMedia(channel, root) {
86
+ const media = mediaFromBuild(channel, gitOutput(['rev-parse', '--show-toplevel'], fileURLToPath(root)));
87
+ if (media === undefined || channel?.assetsPath === undefined)
88
+ return undefined;
89
+ // An empty base is the whole `public/`: the rewrite moves only draft addresses there, so nothing is listed.
90
+ if (media.refBase === '')
91
+ return { refBase: '', deployed: [] };
92
+ const { assetsPath } = channel;
93
+ const entries = existsSync(assetsPath) ? readdirSync(assetsPath, { recursive: true, withFileTypes: true }) : [];
94
+ const deployed = entries
95
+ .filter((entry) => entry.isFile())
96
+ .map((entry) => relative(assetsPath, join(entry.parentPath, entry.name)).split(sep).join('/'))
97
+ .filter((file) => mediaRefPath(`${media.refBase}/${file}`, media.refBase) !== undefined);
98
+ // oxlint-disable-next-line unicorn/no-array-sort -- the target lib predates toSorted; this sorts its own array.
99
+ return { refBase: media.refBase, deployed: deployed.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)) };
100
+ }
101
+ /** Only builds that render drafts from this build's own files bake its media list. */
102
+ export function bakesMedia(mode) {
103
+ return mode === 'd8' || mode === 'd3';
104
+ }
105
+ function bakedSitePages(config, env) {
106
+ const { serverEntry } = config.build;
107
+ switch (config.adapter?.name) {
108
+ case '@astrojs/node':
109
+ return { kind: 'disk', serverEntry };
110
+ case '@astrojs/cloudflare':
111
+ return { kind: 'assets' };
112
+ case '@astrojs/vercel':
113
+ case '@astrojs/netlify': {
114
+ // Only a production deploy's `site` serves this build's pages; a branch deploy's pages live elsewhere.
115
+ const production = env.VERCEL_ENV === 'production' || env.CONTEXT === 'production';
116
+ const origin = production && config.site ? config.site.replace(/\/+$/u, '') : null;
117
+ return { kind: 'function', serverEntry, origin };
118
+ }
119
+ default:
120
+ return { kind: 'none' };
121
+ }
122
+ }
123
+ // astro-cms's published page handler: the CMS route, whose pages render drafts rather than published bytes.
124
+ const CMS_PAGE_HANDLER = '/internal/page-handler.astro';
125
+ /**
126
+ * The pages the site prerendered itself, base included, in normalizeTrailingSlash form: every page `astro:build:done`
127
+ * reports but those the CMS route wrote. A page goes to the route whose output files hold it (`pages` names no route);
128
+ * that page is `exact`, since production serves the site route there by route priority. One no route's files hold
129
+ * goes to the first prerendered route that matches it (`routes` is in Astro's priority order), and is not exact.
130
+ */
131
+ export function sitePagesOf(pages, assets, routes, dir, base) {
132
+ const root = base.replace(/\/+$/u, '');
133
+ // Whether each page Astro lists files for is the CMS route's.
134
+ const ownedByCms = new Map(routes.flatMap((route) => (assets.get(route.pattern) ?? []).map((file) => [
135
+ normalizeTrailingSlash(`${root}/${decodeURI(file.pathname.slice(dir.pathname.length)).replace(/(?:^|\/)index\.html$|\.html$/u, '')}`),
136
+ route.entrypoint.endsWith(CMS_PAGE_HANDLER),
137
+ ])));
138
+ // shortcut: the Cloudflare prerenderer leaves each route only its last file in `assets`, so most pages there fall to
139
+ // the first matching route, which lists a CMS page behind a site getStaticPaths route that does not generate it; such
140
+ // a page is not exact, and the preview middleware renders its draft when page-status is `changed`.
141
+ const list = { pages: [], exact: [] };
142
+ for (const { pathname } of pages) {
143
+ const page = normalizeTrailingSlash(`${root}/${pathname}`);
144
+ const owned = ownedByCms.get(page);
145
+ const matched = owned === undefined
146
+ ? routes.find((route) => route.type === 'page' && route.isPrerendered && route.patternRegex.test(`/${pathname}`))
147
+ : undefined;
148
+ if (owned ?? matched?.entrypoint.endsWith(CMS_PAGE_HANDLER))
149
+ continue;
150
+ list.pages.push(page);
151
+ // A route without parameters has one page, so matching it proves the file is that route's own.
152
+ if (owned === false || (matched !== undefined && !matched.pattern.includes('[')))
153
+ list.exact.push(page);
154
+ }
155
+ return list;
156
+ }
157
+ /**
158
+ * Writes `site-pages.json` where the adapter's runtime reads it (`preview/site-page-sources.ts`), none of it needing
159
+ * `site`: beside the Node server entry; beside every copy of the server entry in the Vercel or Netlify function bundle
160
+ * (the adapter's build:done, which runs first, wrote it); in the Cloudflare client build's editor folder. Returns the
161
+ * files written; throws when the function bundle holds no server entry.
162
+ */
163
+ export async function writeSitePagesList(adapterName, config, list) {
164
+ // Where Vercel and Netlify put the function they deploy, under the project root.
165
+ const functionRoot = adapterName === '@astrojs/vercel'
166
+ ? '.vercel/output/functions/_render.func/'
167
+ : adapterName === '@astrojs/netlify'
168
+ ? '.netlify/v1/functions/ssr/'
169
+ : undefined;
170
+ let dirs = [];
171
+ if (adapterName === '@astrojs/node')
172
+ dirs = [fileURLToPath(config.build.server)];
173
+ if (adapterName === '@astrojs/cloudflare')
174
+ dirs = [join(fileURLToPath(config.build.client), '_conloca', 'editor')];
175
+ if (functionRoot !== undefined) {
176
+ const bundle = fileURLToPath(new URL(functionRoot, config.root));
177
+ const files = await readdir(bundle, { recursive: true }).catch(() => []);
178
+ dirs = files
179
+ .filter((file) => basename(file) === config.build.serverEntry && !file.split(sep).includes('node_modules'))
180
+ .map((file) => join(bundle, dirname(file)));
181
+ if (dirs.length === 0)
182
+ throw new Error(`no ${config.build.serverEntry} in ${bundle} to write site-pages.json beside`);
183
+ }
184
+ const body = `${JSON.stringify(list)}\n`;
185
+ return Promise.all(dirs.map(async (dir) => {
186
+ await mkdir(dir, { recursive: true });
187
+ await writeFile(join(dir, 'site-pages.json'), body);
188
+ return join(dir, 'site-pages.json');
189
+ }));
190
+ }
191
+ /** The endpoint d8 moves the image route to: Cloudflare's own passthrough there, Conloca's redirect elsewhere. */
192
+ export function d8ImageEndpoint(adapterName) {
193
+ return adapterName === '@astrojs/cloudflare'
194
+ ? '@astrojs/cloudflare/image-passthrough-endpoint'
195
+ : '@conloca/cloud-astro/preview-image-endpoint';
196
+ }
197
+ const PAGE_FILE = /\.(?:astro|md|mdx|markdown|html|js|ts|mjs)$/u;
198
+ // Astro's own rule (astro core/routing/prerender.js).
199
+ const PRERENDER_FALSE = /^\s*export\s+const\s+prerender\s*=\s*false/mu;
200
+ /**
201
+ * Astro's own image services, Cloudflare's and Netlify's (whose URLs go to `/.netlify/images`): they serve `<Image>`
202
+ * URLs that do not depend on the endpoint route.
203
+ */
204
+ export function knownImageService(entrypoint) {
205
+ // Unset is Astro's default (sharp).
206
+ return (entrypoint === undefined ||
207
+ entrypoint.startsWith('astro/assets/services/') ||
208
+ entrypoint.startsWith('@astrojs/cloudflare/image-service') ||
209
+ entrypoint.startsWith('@astrojs/netlify/image-service'));
210
+ }
211
+ /** Whether the site renders anything on demand, as far as astro.config and `src/pages` tell before routes exist. */
212
+ export async function hasOnDemandRoutes(config) {
213
+ if (config.output === 'server')
214
+ return true;
215
+ const pages = fileURLToPath(new URL('pages/', config.srcDir));
216
+ const files = await readdir(pages, { recursive: true }).catch(() => []);
217
+ const sources = await Promise.all(files
218
+ // Astro skips `_`-prefixed files and folders.
219
+ .filter((file) => PAGE_FILE.test(file) && !file.split(sep).some((part) => part.startsWith('_')))
220
+ .map((file) => readFile(join(pages, file), 'utf8').catch(() => '')));
221
+ return sources.some((source) => PRERENDER_FALSE.test(source));
222
+ }
223
+ /** Site on-demand routes other than ours and Astro's runtime routes (`/_image`, `/_server-islands/[name]`, default `/404`). */
224
+ export function siteOnDemand(routes, prefixPattern) {
225
+ // onDemandPatterns already drops Astro's other internal routes, the default 404 among them.
226
+ return onDemandPatterns(routes).filter((pattern) => pattern !== prefixPattern &&
227
+ !pattern.startsWith(`${prefixPattern}/`) &&
228
+ pattern !== '/_image' &&
229
+ pattern !== '/_server-islands/[name]');
230
+ }
231
+ const VERCEL_STATIC_404 = { src: '^/.*$', dest: '/404.html', status: 404 };
232
+ // The function's `/404` under any base and trailing-slash setting: `^/404/?$`, `^/404$`, `^/docs/404/?$`.
233
+ const RENDERED_404 = /^\^(?:\/[^/^$]+)*\/404(?:\/\?)?\$$/u;
234
+ /** The rewritten Vercel config, or null to leave it (with the reason to warn). */
235
+ export function narrowVercelCatchAll(config, siteStaticWithoutPreview) {
236
+ // An SSR site's misses reached its function before preview, too.
237
+ if (!siteStaticWithoutPreview)
238
+ return null;
239
+ if (!isRecord(config) || !Array.isArray(config.routes))
240
+ return { leave: 'it has no routes list' };
241
+ const last = config.routes.at(-1);
242
+ // A prerendered 404.astro: the adapter already sends misses to it.
243
+ if (isDeepStrictEqual(last, VERCEL_STATIC_404))
244
+ return null;
245
+ if (!isDeepStrictEqual(last, { src: '^/.*$', dest: '_render' })) {
246
+ return { leave: `its final route is not the adapter's catch-all: ${JSON.stringify(last)}` };
247
+ }
248
+ const kept = config.routes
249
+ .slice(0, -1)
250
+ .filter((route) => !(isRecord(route) && route.dest === '_render' && typeof route.src === 'string' && RENDERED_404.test(route.src)));
251
+ return { config: { ...config, routes: [...kept, VERCEL_STATIC_404] } };
252
+ }
253
+ /** Problems in the Cloudflare adapter's dist/server/wrangler.json for a d8 site, each with what it breaks and the edit (empty when fine). */
254
+ export function cloudflareD8Problems(wrangler, expected) {
255
+ const assets = isRecord(wrangler) && isRecord(wrangler.assets) ? wrangler.assets : {};
256
+ return [
257
+ ...deployProblems(wrangler, expected, false).map((problem) => `${problem}: drafts get a 404 (preview broken); add them to assets.run_worker_first in wrangler.jsonc`),
258
+ ...(assets.not_found_handling === '404-page'
259
+ ? []
260
+ : [
261
+ 'wrangler.jsonc assets.not_found_handling is not "404-page": misses start the Cloudflare Worker; set assets.not_found_handling to "404-page" in wrangler.jsonc',
262
+ ]),
263
+ ];
264
+ }
265
+ //# sourceMappingURL=d8-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d8-build.js","sourceRoot":"","sources":["../../src/d8-build.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAA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jB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAClH,CAAC;IACJ,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,iBAAiB,CAAC,EAAE,EAAE,CAAC;AACzE,CAAC;AAED,6IAA6I;AAC7I,MAAM,UAAU,oBAAoB,CAAC,QAAiB,EAAE,QAA2B;IACjF,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACtF,OAAO;QACL,GAAG,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,CAC9C,CAAC,OAAO,EAAE,EAAE,CACV,GAAG,OAAO,4FAA4F,CACzG;QACD,GAAG,CAAC,MAAM,CAAC,kBAAkB,KAAK,UAAU;YAC1C,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE,+JAA+J;aAChK,CAAC;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { AstroConfig, AstroIntegration } from 'astro';
2
+ export declare const D8_EDGE_REFUSAL: string;
3
+ /** The isr refusal, naming the exclude entry that covers `<base>_conloca/preview(/.*)?`. */
4
+ export declare function d8IsrRefusal(base: string): string;
5
+ /** The text of the astro.config Astro loads from `root` (its own search order), or '' when there is none. */
6
+ export declare function readAstroConfigText(root: URL): string;
7
+ /** The config-text refusal for d8 on this adapter, or null. `text` is the astro.config file Astro loaded. Doctor (Plan 50) reuses it. */
8
+ export declare function d8ConfigRefusal(text: string, adapterName: string, base?: string): string | null;
9
+ /** The adapter's resolved middleware mode, read by calling its own `astro:config:done` with a capturing `setAdapter`; undefined when that yields no `adapterFeatures.middlewareMode`. */
10
+ export declare function adapterMiddlewareMode(adapter: AstroIntegration, config: AstroConfig): Promise<'classic' | 'edge' | undefined>;
11
+ /** The edge refusal for this build, or null: `probed === 'edge'` → edge text; `probed === undefined` on vercel/netlify → `d8ConfigRefusal`'s edge text when the text names edge, else the unreadable text unless the text proves classic. */
12
+ export declare function d8EdgeRefusal(probed: 'classic' | 'edge' | undefined, text: string, adapterName: string): string | null;
13
+ interface VercelRoute {
14
+ src?: unknown;
15
+ dest?: unknown;
16
+ handle?: unknown;
17
+ status?: unknown;
18
+ continue?: unknown;
19
+ }
20
+ /** A `.vercel/output/config.json` after the prefix is darkened: its other keys as the adapter wrote them. */
21
+ interface VercelOutputConfig {
22
+ routes: VercelRoute[];
23
+ }
24
+ /** True when `.vercel/output/config.json` sends the preview route to an `_isr` function. */
25
+ export declare function vercelIsrCatchesPrefix(configJson: unknown, base: string): boolean;
26
+ /** The config with a static 404 for `<prefix>(/.*)?` placed first after `handle: filesystem`, so no route below it (the prefix's own `_isr` route or an `_isr` catch-all) ever serves or caches the prefix. Every other route is unchanged. */
27
+ export declare function darkenIsrPrefix(configJson: unknown, base: string): VercelOutputConfig;
28
+ export {};
29
+ //# sourceMappingURL=d8-guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d8-guards.d.ts","sourceRoot":"","sources":["../../src/d8-guards.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAA0B,MAAM,OAAO,CAAC;AAWnF,eAAO,MAAM,eAAe,QAEuF,CAAC;AAOpH,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,6GAA6G;AAC7G,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAMrD;AAWD,yIAAyI;AACzI,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,GAAG,IAAI,CAS5F;AAeD,yLAAyL;AACzL,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC,CAgBzC;AAED,6OAA6O;AAC7O,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,EACtC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CAkBf;AAED,UAAU,WAAW;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,6GAA6G;AAC7G,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAoBD,4FAA4F;AAC5F,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAajF;AAED,+OAA+O;AAC/O,wBAAgB,eAAe,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAQrF"}
@@ -0,0 +1,145 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { balancedSlice, containsOutsideStrings, stripComments } from './doctor/config-scan.js';
3
+ import { PREVIEW_ROUTE_SEGMENT } from './preview/preview-path.js';
4
+ /** The adapters whose middleware can run at the edge, and the call that names each in astro.config. */
5
+ const EDGE_ADAPTER_CALLS = new Map([
6
+ ['@astrojs/vercel', 'vercel'],
7
+ ['@astrojs/netlify', 'netlify'],
8
+ ]);
9
+ const EDGE_OPTION = /middlewareMode\s*:\s*['"]edge['"]|edgeMiddleware\s*:\s*true/;
10
+ export const D8_EDGE_REFUSAL = "draft preview does not run in edge middleware (middlewareMode: 'edge' / edgeMiddleware): its middleware does not " +
11
+ 'bundle into the edge function, and the adapter serializes locals to JSON. Remove the option to turn preview on.';
12
+ /** Astro's preview prefix under `base`, as served. */
13
+ function previewPrefix(base) {
14
+ return `${base.replace(/\/+$/u, '')}${PREVIEW_ROUTE_SEGMENT}`;
15
+ }
16
+ /** The isr refusal, naming the exclude entry that covers `<base>_conloca/preview(/.*)?`. */
17
+ export function d8IsrRefusal(base) {
18
+ const prefix = previewPrefix(base);
19
+ return (`@astrojs/vercel isr caches ${prefix}/ by path, ignoring the preview cookie, so drafts could be served to anyone. ` +
20
+ `Add the prefix to isr.exclude in astro.config: isr: { exclude: [/^${prefix.replaceAll('/', '\\/')}(\\/.*)?$/] }`);
21
+ }
22
+ /** The text of the astro.config Astro loads from `root` (its own search order), or '' when there is none. */
23
+ export function readAstroConfigText(root) {
24
+ // shortcut: a config passed with `astro build --config <file>` is not seen; the probe and the build:done backstop still run.
25
+ const file = ['mjs', 'js', 'ts', 'mts']
26
+ .map((ext) => new URL(`astro.config.${ext}`, root))
27
+ .find((url) => existsSync(url));
28
+ return file === undefined ? '' : readFileSync(file, 'utf8');
29
+ }
30
+ /** The parenthesized arguments of the adapter's call in comment-stripped config text, or null without one. */
31
+ function adapterArgs(text, adapterName) {
32
+ const name = EDGE_ADAPTER_CALLS.get(adapterName);
33
+ if (name === undefined)
34
+ return null;
35
+ const code = stripComments(text);
36
+ const call = new RegExp(`\\b${name}\\s*\\(`).exec(code);
37
+ return call === null ? null : balancedSlice(code, call.index + call[0].length - 1);
38
+ }
39
+ /** The config-text refusal for d8 on this adapter, or null. `text` is the astro.config file Astro loaded. Doctor (Plan 50) reuses it. */
40
+ export function d8ConfigRefusal(text, adapterName, base = '/') {
41
+ const args = adapterArgs(text, adapterName);
42
+ if (args === null)
43
+ return null;
44
+ if (adapterName === '@astrojs/vercel' && /\bisr\s*:(?!\s*false\b)/.test(args)) {
45
+ const exclude = /\bexclude\s*:\s*\[/.exec(args);
46
+ const list = exclude === null ? null : balancedSlice(args, exclude.index + exclude[0].length - 1);
47
+ if (!(list?.includes('_conloca') && list.includes('preview')))
48
+ return d8IsrRefusal(base);
49
+ }
50
+ return EDGE_OPTION.test(args) ? D8_EDGE_REFUSAL : null;
51
+ }
52
+ /** A logger that drops everything: the probe's adapter hook must not log twice. */
53
+ const silentLogger = {
54
+ options: { destination: { write: () => undefined }, level: 'silent' },
55
+ label: 'probe',
56
+ fork: () => silentLogger,
57
+ info: () => undefined,
58
+ warn: () => undefined,
59
+ error: () => undefined,
60
+ debug: () => undefined,
61
+ flush: () => undefined,
62
+ close: () => undefined,
63
+ };
64
+ /** The adapter's resolved middleware mode, read by calling its own `astro:config:done` with a capturing `setAdapter`; undefined when that yields no `adapterFeatures.middlewareMode`. */
65
+ export async function adapterMiddlewareMode(adapter, config) {
66
+ let mode;
67
+ try {
68
+ await adapter.hooks['astro:config:done']?.({
69
+ config,
70
+ buildOutput: 'static',
71
+ setAdapter: (resolved) => {
72
+ mode = resolved.adapterFeatures?.middlewareMode;
73
+ },
74
+ injectTypes: () => new URL('noop', config.root),
75
+ logger: silentLogger,
76
+ });
77
+ }
78
+ catch {
79
+ return undefined;
80
+ }
81
+ return mode;
82
+ }
83
+ /** The edge refusal for this build, or null: `probed === 'edge'` → edge text; `probed === undefined` on vercel/netlify → `d8ConfigRefusal`'s edge text when the text names edge, else the unreadable text unless the text proves classic. */
84
+ export function d8EdgeRefusal(probed, text, adapterName) {
85
+ if (probed === 'edge')
86
+ return D8_EDGE_REFUSAL;
87
+ if (probed === 'classic' || !EDGE_ADAPTER_CALLS.has(adapterName))
88
+ return null;
89
+ const args = adapterArgs(text, adapterName);
90
+ if (args !== null && EDGE_OPTION.test(args))
91
+ return D8_EDGE_REFUSAL;
92
+ const inner = args?.slice(1, -1).trim();
93
+ // Classic is proven by no argument, or one spread-free object literal whose mode keys are absent or literally classic.
94
+ const classic = inner === '' ||
95
+ (inner?.startsWith('{') === true &&
96
+ balancedSlice(inner, 0) === inner &&
97
+ !containsOutsideStrings(inner, '...') &&
98
+ !/\b(?:middlewareMode|edgeMiddleware)\b/.test(inner.replace(/\bmiddlewareMode\s*:\s*(['"])classic\1|\bedgeMiddleware\s*:\s*false\b/g, '')));
99
+ return classic
100
+ ? null
101
+ : `couldn't read middlewareMode from astro.config; write the ${adapterName} options literally to turn preview on.`;
102
+ }
103
+ /** The routes of a `.vercel/output/config.json`, or [] when it holds none. */
104
+ function vercelRoutes(configJson) {
105
+ if (typeof configJson !== 'object' || configJson === null || !('routes' in configJson))
106
+ return [];
107
+ return Array.isArray(configJson.routes)
108
+ ? configJson.routes.filter((route) => typeof route === 'object' && route !== null)
109
+ : [];
110
+ }
111
+ /** Whether a Vercel route src matches the path. Srcs are PCRE: compiled without 'u', and one JS can't read matches nothing. */
112
+ function srcMatches(src, path) {
113
+ if (typeof src !== 'string')
114
+ return false;
115
+ try {
116
+ return new RegExp(src).test(path);
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ /** True when `.vercel/output/config.json` sends the preview route to an `_isr` function. */
123
+ export function vercelIsrCatchesPrefix(configJson, base) {
124
+ const routes = vercelRoutes(configJson);
125
+ const prefix = previewPrefix(base);
126
+ const after = routes.slice(routes.findIndex((route) => route.handle === 'filesystem') + 1);
127
+ const end = after.findIndex((route) => route.handle !== undefined);
128
+ // Only the filesystem phase's routes that serve: a dest without `continue` ends the lookup.
129
+ const serving = (end < 0 ? after : after.slice(0, end)).filter((route) => typeof route.dest === 'string' && route.continue !== true);
130
+ return [prefix, `${prefix}/`, `${prefix}/slug/page`].some((sample) => {
131
+ const served = serving.find((route) => srcMatches(route.src, sample));
132
+ return typeof served?.dest === 'string' && served.dest.startsWith('/_isr');
133
+ });
134
+ }
135
+ /** The config with a static 404 for `<prefix>(/.*)?` placed first after `handle: filesystem`, so no route below it (the prefix's own `_isr` route or an `_isr` catch-all) ever serves or caches the prefix. Every other route is unchanged. */
136
+ export function darkenIsrPrefix(configJson, base) {
137
+ const src = `^${previewPrefix(base).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:/.*)?$`;
138
+ const routes = vercelRoutes(configJson);
139
+ const at = routes.findIndex((route) => route.handle === 'filesystem') + 1;
140
+ const darkened = [...routes.slice(0, at), { src, dest: '/404.html', status: 404 }, ...routes.slice(at)];
141
+ return typeof configJson === 'object' && configJson !== null
142
+ ? { ...configJson, routes: darkened }
143
+ : { routes: darkened };
144
+ }
145
+ //# sourceMappingURL=d8-guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d8-guards.js","sourceRoot":"","sources":["../../src/d8-guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,uGAAuG;AACvG,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,CAAC,iBAAiB,EAAE,QAAQ,CAAC;IAC7B,CAAC,kBAAkB,EAAE,SAAS,CAAC;CAChC,CAAC,CAAC;AACH,MAAM,WAAW,GAAG,6DAA6D,CAAC;AAElF,MAAM,CAAC,MAAM,eAAe,GAC1B,mHAAmH;IACnH,iHAAiH,CAAC;AAEpH,sDAAsD;AACtD,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,qBAAqB,EAAE,CAAC;AAChE,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,CACL,8BAA8B,MAAM,+EAA+E;QACnH,qEAAqE,MAAM,C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,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACxG,OAAO,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI;QAC1D,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE;QACrC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Astro middleware entrypoint for a d8 site: `addMiddleware({ entrypoint: '@conloca/cloud-astro/d8-middleware' })`
3
+ * resolves here, so it exports `onRequest`. No static import of `astro:content`: the draft render (`./d8-render.ts`)
4
+ * loads only when a request needs it, so every other request runs nothing but the prefix check.
5
+ */
6
+ export declare const onRequest: (context: import("./preview/d8-middleware.js").D8Context, next: () => Promise<Response>) => Promise<Response>;
7
+ //# sourceMappingURL=d8-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d8-middleware.d.ts","sourceRoot":"","sources":["../../src/d8-middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,eAAO,MAAM,SAAS,+GAGpB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Astro middleware entrypoint for a d8 site: `addMiddleware({ entrypoint: '@conloca/cloud-astro/d8-middleware' })`
3
+ * resolves here, so it exports `onRequest`. No static import of `astro:content`: the draft render (`./d8-render.ts`)
4
+ * loads only when a request needs it, so every other request runs nothing but the prefix check.
5
+ */
6
+ import baked from 'virtual:conloca-preview-opts';
7
+ import { createD8Middleware } from './preview/d8-middleware.js';
8
+ import { untagWorkerdProcess } from './preview/workerd-shim.js';
9
+ // Before any render on Cloudflare Workers: see the shim's doc.
10
+ untagWorkerdProcess();
11
+ export const onRequest = createD8Middleware(baked, {
12
+ loadRender: () => import('./d8-render.js'),
13
+ env: (name) => process.env[name],
14
+ });
15
+ //# sourceMappingURL=d8-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d8-middleware.js","sourceRoot":"","sources":["../../src/d8-middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,8BAA8B,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,+DAA+D;AAC/D,mBAAmB,EAAE,CAAC;AAEtB,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAkB,CAAC,KAAK,EAAE;IACjD,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC;IAC1C,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;CACjC,CAAC,CAAC"}