@decocms/blocks 8.9.1 → 8.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol/channel.d.ts +98 -0
- package/dist/protocol/channel.d.ts.map +1 -0
- package/dist/protocol/channel.js +58 -0
- package/dist/protocol/channel.js.map +1 -0
- package/dist/protocol/client.js +2 -2
- package/dist/protocol/client.js.map +1 -1
- package/dist/protocol/conformance/blockMetaVectors.json +214 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
- package/dist/protocol/conformance/contentHashFixtures.js +55 -0
- package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
- package/dist/protocol/conformance/index.d.ts +2 -1
- package/dist/protocol/conformance/index.d.ts.map +1 -1
- package/dist/protocol/conformance/index.js +2 -1
- package/dist/protocol/conformance/index.js.map +1 -1
- package/dist/protocol/conformance/vectors.d.ts +33 -0
- package/dist/protocol/conformance/vectors.d.ts.map +1 -0
- package/dist/protocol/conformance/vectors.js +3 -0
- package/dist/protocol/conformance/vectors.js.map +1 -0
- package/dist/protocol/index.d.ts +11 -1
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +11 -1
- package/dist/protocol/index.js.map +1 -1
- package/dist/protocol/keys.d.ts +1 -1
- package/dist/protocol/keys.js +1 -1
- package/dist/v8/background.d.ts +13 -0
- package/dist/v8/background.d.ts.map +1 -1
- package/dist/v8/background.js +41 -0
- package/dist/v8/background.js.map +1 -1
- package/dist/v8/blockMeta.d.ts +27 -0
- package/dist/v8/blockMeta.d.ts.map +1 -0
- package/dist/v8/blockMeta.js +75 -0
- package/dist/v8/blockMeta.js.map +1 -0
- package/dist/v8/blockStore.d.ts +43 -0
- package/dist/v8/blockStore.d.ts.map +1 -0
- package/dist/v8/blockStore.js +95 -0
- package/dist/v8/blockStore.js.map +1 -0
- package/dist/v8/boundedJson.d.ts +5 -0
- package/dist/v8/boundedJson.d.ts.map +1 -1
- package/dist/v8/boundedJson.js +10 -2
- package/dist/v8/boundedJson.js.map +1 -1
- package/dist/v8/boundedMap.d.ts +19 -0
- package/dist/v8/boundedMap.d.ts.map +1 -0
- package/dist/v8/boundedMap.js +52 -0
- package/dist/v8/boundedMap.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +18 -2
- package/dist/v8/builtins/data.d.ts.map +1 -1
- package/dist/v8/builtins/data.js +17 -1
- package/dist/v8/builtins/data.js.map +1 -1
- package/dist/v8/builtins/index.d.ts.map +1 -1
- package/dist/v8/builtins/index.js +2 -1
- package/dist/v8/builtins/index.js.map +1 -1
- package/dist/v8/builtins/legacy.d.ts +6 -3
- package/dist/v8/builtins/legacy.d.ts.map +1 -1
- package/dist/v8/builtins/legacy.js +6 -3
- package/dist/v8/builtins/legacy.js.map +1 -1
- package/dist/v8/canonical.d.ts +8 -0
- package/dist/v8/canonical.d.ts.map +1 -1
- package/dist/v8/canonical.js +15 -0
- package/dist/v8/canonical.js.map +1 -1
- package/dist/v8/cli/builtins.d.ts.map +1 -1
- package/dist/v8/cli/builtins.js +1 -0
- package/dist/v8/cli/builtins.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts +10 -0
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +91 -7
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/content.d.ts +12 -25
- package/dist/v8/cli/content.d.ts.map +1 -1
- package/dist/v8/cli/content.js +46 -75
- package/dist/v8/cli/content.js.map +1 -1
- package/dist/v8/cli/index.d.ts +2 -2
- package/dist/v8/cli/index.d.ts.map +1 -1
- package/dist/v8/cli/index.js +2 -2
- package/dist/v8/cli/index.js.map +1 -1
- package/dist/v8/cli/remote/commands.d.ts +71 -0
- package/dist/v8/cli/remote/commands.d.ts.map +1 -0
- package/dist/v8/cli/remote/commands.js +644 -0
- package/dist/v8/cli/remote/commands.js.map +1 -0
- package/dist/v8/cli/remote/diff.d.ts +15 -0
- package/dist/v8/cli/remote/diff.d.ts.map +1 -0
- package/dist/v8/cli/remote/diff.js +102 -0
- package/dist/v8/cli/remote/diff.js.map +1 -0
- package/dist/v8/cli/remote/env.d.ts +35 -0
- package/dist/v8/cli/remote/env.d.ts.map +1 -0
- package/dist/v8/cli/remote/env.js +84 -0
- package/dist/v8/cli/remote/env.js.map +1 -0
- package/dist/v8/cli/remote/http.d.ts +149 -0
- package/dist/v8/cli/remote/http.d.ts.map +1 -0
- package/dist/v8/cli/remote/http.js +381 -0
- package/dist/v8/cli/remote/http.js.map +1 -0
- package/dist/v8/cli/remote/local.d.ts +90 -0
- package/dist/v8/cli/remote/local.d.ts.map +1 -0
- package/dist/v8/cli/remote/local.js +309 -0
- package/dist/v8/cli/remote/local.js.map +1 -0
- package/dist/v8/cli/root.d.ts +29 -0
- package/dist/v8/cli/root.d.ts.map +1 -1
- package/dist/v8/cli/root.js +28 -0
- package/dist/v8/cli/root.js.map +1 -1
- package/dist/v8/cli/run.d.ts +13 -1
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +310 -124
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js +28 -10
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
- package/dist/v8/cli/schema/generate.js +1 -1
- package/dist/v8/cli/schema/generate.js.map +1 -1
- package/dist/v8/cli/skills.d.ts +25 -0
- package/dist/v8/cli/skills.d.ts.map +1 -0
- package/dist/v8/cli/skills.js +70 -0
- package/dist/v8/cli/skills.js.map +1 -0
- package/dist/v8/client.d.ts +9 -9
- package/dist/v8/client.d.ts.map +1 -1
- package/dist/v8/client.js +138 -50
- package/dist/v8/client.js.map +1 -1
- package/dist/v8/cms.d.ts +2 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +55 -46
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +39 -78
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +155 -195
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/contentIndex.d.ts +71 -0
- package/dist/v8/contentIndex.d.ts.map +1 -0
- package/dist/v8/contentIndex.js +137 -0
- package/dist/v8/contentIndex.js.map +1 -0
- package/dist/v8/draft.d.ts +7 -7
- package/dist/v8/draft.d.ts.map +1 -1
- package/dist/v8/draft.js +10 -9
- package/dist/v8/draft.js.map +1 -1
- package/dist/v8/draftChanges.d.ts +59 -32
- package/dist/v8/draftChanges.d.ts.map +1 -1
- package/dist/v8/draftChanges.js +139 -75
- package/dist/v8/draftChanges.js.map +1 -1
- package/dist/v8/errors.d.ts +21 -0
- package/dist/v8/errors.d.ts.map +1 -1
- package/dist/v8/errors.js +22 -0
- package/dist/v8/errors.js.map +1 -1
- package/dist/v8/hostedSource.d.ts +57 -0
- package/dist/v8/hostedSource.d.ts.map +1 -0
- package/dist/v8/hostedSource.js +18 -0
- package/dist/v8/hostedSource.js.map +1 -0
- package/dist/v8/identity.d.ts +1 -1
- package/dist/v8/identity.js +1 -1
- package/dist/v8/index.d.ts +1 -0
- package/dist/v8/index.d.ts.map +1 -1
- package/dist/v8/index.js +1 -0
- package/dist/v8/index.js.map +1 -1
- package/dist/v8/matchRoute.js +7 -4
- package/dist/v8/matchRoute.js.map +1 -1
- package/dist/v8/pin.d.ts +34 -0
- package/dist/v8/pin.d.ts.map +1 -0
- package/dist/v8/pin.js +156 -0
- package/dist/v8/pin.js.map +1 -0
- package/dist/v8/preview/StudioBridge.d.ts +8 -8
- package/dist/v8/preview/StudioBridge.d.ts.map +1 -1
- package/dist/v8/preview/StudioBridge.js +8 -10
- package/dist/v8/preview/StudioBridge.js.map +1 -1
- package/dist/v8/preview/StudioChannel.d.ts +51 -0
- package/dist/v8/preview/StudioChannel.d.ts.map +1 -0
- package/dist/v8/preview/StudioChannel.js +104 -0
- package/dist/v8/preview/StudioChannel.js.map +1 -0
- package/dist/v8/preview/index.d.ts +3 -0
- package/dist/v8/preview/index.d.ts.map +1 -1
- package/dist/v8/preview/index.js +3 -0
- package/dist/v8/preview/index.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts +42 -5
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +317 -259
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/resolver.d.ts +22 -8
- package/dist/v8/resolver.d.ts.map +1 -1
- package/dist/v8/resolver.js +37 -32
- package/dist/v8/resolver.js.map +1 -1
- package/dist/v8/revisionId.d.ts +11 -0
- package/dist/v8/revisionId.d.ts.map +1 -0
- package/dist/v8/revisionId.js +13 -0
- package/dist/v8/revisionId.js.map +1 -0
- package/dist/v8/settings.d.ts +6 -6
- package/dist/v8/settings.d.ts.map +1 -1
- package/dist/v8/settings.js +8 -7
- package/dist/v8/settings.js.map +1 -1
- package/dist/v8/telemetry.d.ts +4 -2
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +2 -2
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +52 -40
- package/dist/v8/types.d.ts.map +1 -1
- package/dist/v8/variants.d.ts +7 -2
- package/dist/v8/variants.d.ts.map +1 -1
- package/dist/v8/variants.js +21 -24
- package/dist/v8/variants.js.map +1 -1
- package/dist/v8/vite/index.d.ts +2 -2
- package/dist/v8/vite/index.js +1 -1
- package/dist/v8/vite/index.js.map +1 -1
- package/package.json +3 -2
- package/skills/deco-apps/SKILL.md +82 -0
- package/skills/deco-apps/references/algolia.md +51 -0
- package/skills/deco-apps/references/commerce-types.md +132 -0
- package/skills/deco-apps/references/instrumented-fetch.md +144 -0
- package/skills/deco-apps/references/magento.md +55 -0
- package/skills/deco-apps/references/messaging.md +76 -0
- package/skills/deco-apps/references/shopify.md +69 -0
- package/skills/deco-apps/references/vendored-loaders.md +135 -0
- package/skills/deco-apps/references/vtex-cookies-auth.md +146 -0
- package/skills/deco-apps/references/vtex.md +150 -0
- package/skills/deco-apps/references/wake.md +75 -0
- package/skills/deco-cms-schema/SKILL.md +80 -0
- package/skills/deco-cms-schema/references/annotations.md +147 -0
- package/skills/deco-cms-schema/references/content-hygiene.md +91 -0
- package/skills/deco-cms-schema/references/formats-and-widgets.md +112 -0
- package/skills/deco-cms-schema/references/shapes-that-break-the-form.md +165 -0
- package/skills/deco-cms-schema/references/types-to-fields.md +112 -0
- package/skills/deco-go-live/SKILL.md +127 -0
- package/skills/deco-go-live/references/content-releases.md +90 -0
- package/skills/deco-go-live/references/process.md +106 -0
- package/skills/deco-go-live/references/proxy-headers-checkout.md +139 -0
- package/skills/deco-go-live/references/qa-checklist-template.md +150 -0
- package/skills/deco-go-live/references/qa-inventory.md +120 -0
- package/skills/deco-go-live/references/react-spa.md +183 -0
- package/skills/deco-go-live/references/seo-analytics.md +114 -0
- package/skills/deco-go-live/references/traffic-ramp.md +87 -0
- package/skills/deco-go-live/references/worker-runtime.md +93 -0
- package/skills/deco-go-live/scripts/preflight.sh +221 -0
- package/skills/deco-images-media/SKILL.md +64 -0
- package/skills/deco-images-media/references/asset-upload.md +191 -0
- package/skills/deco-images-media/references/components-per-binding.md +167 -0
- package/skills/deco-images-media/references/providers-and-cdn.md +145 -0
- package/skills/deco-images-media/references/quality-and-lcp.md +93 -0
- package/skills/deco-images-media/references/troubleshooting.md +147 -0
- package/skills/deco-images-media/references/video.md +122 -0
- package/skills/deco-make-editable/SKILL.md +94 -0
- package/skills/deco-make-editable/references/a11y-and-e2e.md +104 -0
- package/skills/deco-make-editable/references/content-shapes.md +198 -0
- package/skills/deco-make-editable/references/from-figma.md +110 -0
- package/skills/deco-make-editable/references/i18n-fields.md +112 -0
- package/skills/deco-make-editable/references/inventory.md +79 -0
- package/skills/deco-make-editable/references/pixel-parity.md +175 -0
- package/skills/deco-make-editable/references/seeding-content.md +119 -0
- package/skills/deco-nextjs-site/SKILL.md +74 -0
- package/skills/deco-nextjs-site/references/caching.md +116 -0
- package/skills/deco-nextjs-site/references/metadata-seo.md +100 -0
- package/skills/deco-nextjs-site/references/proxy-and-drafts.md +177 -0
- package/skills/deco-nextjs-site/references/rendering.md +171 -0
- package/skills/deco-nextjs-site/references/setup.md +190 -0
- package/skills/deco-nextjs-site/references/studio-bridge.md +130 -0
- package/skills/deco-site-authoring/SKILL.md +75 -0
- package/skills/deco-site-authoring/references/lazy-blocks.md +155 -0
- package/skills/deco-site-authoring/references/loaders.md +192 -0
- package/skills/deco-site-authoring/references/pages.md +156 -0
- package/skills/deco-site-authoring/references/review-before-publish.md +95 -0
- package/skills/deco-site-authoring/references/sections.md +158 -0
- package/skills/deco-site-authoring/references/seo.md +116 -0
- package/skills/deco-site-workflow/SKILL.md +92 -0
- package/skills/deco-site-workflow/references/check.md +116 -0
- package/skills/deco-site-workflow/references/cli-reference.md +104 -0
- package/skills/deco-site-workflow/references/content-layout.md +93 -0
- package/skills/deco-site-workflow/references/content-sync.md +146 -0
- package/skills/deco-site-workflow/references/delivery.md +51 -0
- package/skills/deco-site-workflow/references/deploy.md +87 -0
- package/skills/deco-site-workflow/references/schema.md +173 -0
- package/skills/deco-site-workflow/references/serve-and-studio.md +138 -0
- package/skills/deco-storefront-caching/SKILL.md +67 -0
- package/skills/deco-storefront-caching/references/cache-keys.md +129 -0
- package/skills/deco-storefront-caching/references/case-study.md +82 -0
- package/skills/deco-storefront-caching/references/egress-traps.md +153 -0
- package/skills/deco-storefront-caching/references/nextjs.md +60 -0
- package/skills/deco-storefront-caching/references/perf-guardrails-e2e.md +123 -0
- package/skills/deco-storefront-caching/references/verification.md +136 -0
- package/skills/deco-storefront-caching/references/worker-page-cache.md +160 -0
- package/skills/deco-storefront-caching/scripts/html-anatomy.mjs +97 -0
- package/skills/deco-storefront-performance/SKILL.md +81 -0
- package/skills/deco-storefront-performance/references/cls-third-party.md +90 -0
- package/skills/deco-storefront-performance/references/hydration.md +116 -0
- package/skills/deco-storefront-performance/references/loaders-n-plus-1.md +107 -0
- package/skills/deco-storefront-performance/references/navigation-ux.md +130 -0
- package/skills/deco-storefront-performance/references/payload-trim.md +163 -0
- package/skills/deco-storefront-performance/references/render-location.md +152 -0
- package/skills/deco-storefront-performance/references/request-dedupe.md +147 -0
- package/skills/deco-storefront-performance/references/trace-reading.md +79 -0
- package/skills/deco-storefront-performance/references/worker-memory.md +176 -0
- package/skills/deco-tanstack-site/SKILL.md +68 -0
- package/skills/deco-tanstack-site/references/document-and-security.md +155 -0
- package/skills/deco-tanstack-site/references/router-and-navigation.md +137 -0
- package/skills/deco-tanstack-site/references/routes-and-pages.md +183 -0
- package/skills/deco-tanstack-site/references/server-functions.md +123 -0
- package/skills/deco-tanstack-site/references/setup.md +153 -0
- package/skills/deco-tanstack-site/references/worker-entry.md +152 -0
- package/skills/deco-v7-to-v8-migration/SKILL.md +122 -0
- package/skills/deco-v7-to-v8-migration/references/caching-and-privacy.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/content.md +25 -0
- package/skills/deco-v7-to-v8-migration/references/editor-forms.md +27 -0
- package/skills/deco-v7-to-v8-migration/references/faststore.md +40 -0
- package/skills/deco-v7-to-v8-migration/references/framework-code.md +53 -0
- package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +16 -0
- package/skills/deco-v7-to-v8-migration/references/import-map.md +81 -0
- package/skills/deco-v7-to-v8-migration/references/legacy-names.md +33 -0
- package/skills/deco-v7-to-v8-migration/references/manual-steps.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/native-apps.md +43 -0
- package/skills/deco-v7-to-v8-migration/references/nextjs.md +19 -0
- package/skills/deco-v7-to-v8-migration/references/parity.md +66 -0
- package/skills/deco-v7-to-v8-migration/references/rendering.md +13 -0
- package/skills/deco-v7-to-v8-migration/references/running-the-script.md +29 -0
- package/skills/deco-v7-to-v8-migration/references/script-steps.md +13 -0
- package/skills/deco-v7-to-v8-migration/references/server-functions.md +15 -0
- package/skills/deco-v7-to-v8-migration/references/sibling-port.md +11 -0
- package/skills/deco-v7-to-v8-migration/references/site-code.md +15 -0
- package/skills/deco-v7-to-v8-migration/references/telemetry.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/verify.md +20 -0
- package/skills/deco-v7-to-v8-migration/scripts/apps.ts +297 -0
- package/skills/deco-v7-to-v8-migration/scripts/asyncRendering.ts +73 -0
- package/skills/deco-v7-to-v8-migration/scripts/blockMap.ts +584 -0
- package/skills/deco-v7-to-v8-migration/scripts/ciSchemaCheck.ts +145 -0
- package/skills/deco-v7-to-v8-migration/scripts/compat.ts +357 -0
- package/skills/deco-v7-to-v8-migration/scripts/content.ts +121 -0
- package/skills/deco-v7-to-v8-migration/scripts/experiments.ts +81 -0
- package/skills/deco-v7-to-v8-migration/scripts/framework.ts +61 -0
- package/skills/deco-v7-to-v8-migration/scripts/imageCopy.ts +276 -0
- package/skills/deco-v7-to-v8-migration/scripts/imageModule.ts +285 -0
- package/skills/deco-v7-to-v8-migration/scripts/imports.ts +942 -0
- package/skills/deco-v7-to-v8-migration/scripts/invoke.ts +624 -0
- package/skills/deco-v7-to-v8-migration/scripts/legacyNames.ts +45 -0
- package/skills/deco-v7-to-v8-migration/scripts/main.ts +59 -0
- package/skills/deco-v7-to-v8-migration/scripts/matchers.ts +41 -0
- package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +176 -0
- package/skills/deco-v7-to-v8-migration/scripts/redirects.ts +455 -0
- package/skills/deco-v7-to-v8-migration/scripts/report.ts +50 -0
- package/skills/deco-v7-to-v8-migration/scripts/scaffold.ts +1119 -0
- package/skills/deco-v7-to-v8-migration/scripts/secrets.ts +35 -0
- package/skills/deco-v7-to-v8-migration/scripts/sectionLoaders.ts +216 -0
- package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +261 -0
- package/skills/deco-v7-to-v8-migration/scripts/stubs.ts +388 -0
- package/skills/deco-v7-to-v8-migration/scripts/tsconfig.json +7 -0
- package/skills/deco-v7-to-v8-migration/scripts/vendor.ts +249 -0
- package/skills/deco-v7-to-v8-migration/scripts/vtexInvoke.ts +240 -0
- package/skills/deco-v7-to-v8-migration/scripts/walk.ts +30 -0
- package/skills/deco-variants/SKILL.md +57 -0
- package/skills/deco-variants/references/caching-variants.md +63 -0
- package/skills/deco-variants/references/custom-matchers.md +83 -0
- package/skills/deco-variants/references/draft-preview.md +59 -0
- package/skills/deco-variants/references/experiments-and-campaigns.md +104 -0
- package/skills/deco-variants/references/multivariate.md +85 -0
- package/skills/deco-variants/references/v7-matchers.md +71 -0
- package/src/index.ts +2 -0
- package/src/protocol/channel.ts +127 -0
- package/src/protocol/client.ts +2 -2
- package/src/protocol/conformance/blockMetaVectors.json +214 -0
- package/src/protocol/conformance/contentHashFixtures.ts +74 -0
- package/src/protocol/conformance/index.ts +9 -1
- package/src/protocol/conformance/vectors.ts +36 -0
- package/src/protocol/index.ts +32 -0
- package/src/protocol/keys.ts +1 -1
- package/src/v8/background.ts +42 -0
- package/src/v8/blockMeta.ts +100 -0
- package/src/v8/blockStore.ts +124 -0
- package/src/v8/boundedJson.ts +20 -2
- package/src/v8/boundedMap.ts +53 -0
- package/src/v8/builtins/data.ts +26 -2
- package/src/v8/builtins/index.ts +2 -1
- package/src/v8/builtins/legacy.ts +6 -3
- package/src/v8/canonical.ts +15 -0
- package/src/v8/cli/builtins.ts +1 -0
- package/src/v8/cli/check/index.ts +97 -7
- package/src/v8/cli/content.ts +49 -91
- package/src/v8/cli/index.ts +2 -2
- package/src/v8/cli/remote/commands.ts +834 -0
- package/src/v8/cli/remote/diff.ts +100 -0
- package/src/v8/cli/remote/env.ts +107 -0
- package/src/v8/cli/remote/http.ts +484 -0
- package/src/v8/cli/remote/local.ts +343 -0
- package/src/v8/cli/root.ts +40 -0
- package/src/v8/cli/run.ts +366 -135
- package/src/v8/cli/schema/builtinSchemas.ts +29 -10
- package/src/v8/cli/schema/generate.ts +1 -1
- package/src/v8/cli/skills.ts +91 -0
- package/src/v8/client.ts +162 -60
- package/src/v8/cms.ts +62 -53
- package/src/v8/content.ts +179 -229
- package/src/v8/contentIndex.ts +183 -0
- package/src/v8/draft.ts +15 -14
- package/src/v8/draftChanges.ts +151 -85
- package/src/v8/errors.ts +37 -0
- package/src/v8/hostedSource.ts +67 -0
- package/src/v8/identity.ts +1 -1
- package/src/v8/index.ts +1 -0
- package/src/v8/matchRoute.ts +7 -4
- package/src/v8/pin.ts +176 -0
- package/src/v8/preview/StudioBridge.ts +8 -10
- package/src/v8/preview/StudioChannel.ts +116 -0
- package/src/v8/preview/index.ts +3 -0
- package/src/v8/remoteLoader.ts +350 -286
- package/src/v8/resolver.ts +56 -33
- package/src/v8/revisionId.ts +14 -0
- package/src/v8/settings.ts +10 -9
- package/src/v8/telemetry.ts +3 -3
- package/src/v8/types.ts +52 -40
- package/src/v8/variants.ts +30 -26
- package/src/v8/vite/index.ts +3 -3
- package/dist/v8/cli/serve/server.d.ts +0 -29
- package/dist/v8/cli/serve/server.d.ts.map +0 -1
- package/dist/v8/cli/serve/server.js +0 -296
- package/dist/v8/cli/serve/server.js.map +0 -1
- package/src/v8/cli/serve/server.ts +0 -348
|
@@ -0,0 +1,1119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page setup (spec: tanstack-start-descriptors, nextjs): the files that
|
|
3
|
+
* render the block map's pages, written for the site's binding, in place of
|
|
4
|
+
* v7's page routes:
|
|
5
|
+
*
|
|
6
|
+
* - `src/cms.ts`: `createCMS` over the block map and the content module, and
|
|
7
|
+
* the content client each request reads (the binding's `contentClient`, so
|
|
8
|
+
* drafts work);
|
|
9
|
+
* - `src/open-page.server.ts`: the page for a URL, resolved as v7 rendered
|
|
10
|
+
* it: every section, then v7's section loaders (`loadSections`, when the
|
|
11
|
+
* block map has them), with v7's matchers told the page (`matchPage`) on
|
|
12
|
+
* TanStack Start (A/B tests need nothing here: the binding decides the
|
|
13
|
+
* tests and campaigns and `contentClient` builds
|
|
14
|
+
* `cms.client({ version, experiments, campaigns })` from that);
|
|
15
|
+
* - TanStack Start: `src/page.functions.ts`, the page's server function. It
|
|
16
|
+
* takes the page's path and passes the page's URL on, never the request's:
|
|
17
|
+
* on a client-side navigation the request is the server-function call
|
|
18
|
+
* (`/_serverFn/…`), and v7 matched and loaded the page being opened;
|
|
19
|
+
* `src/page-view.tsx` renders the sections through `src/views.ts`; the
|
|
20
|
+
* catch-all route `src/routes/$.tsx` (and v7's home route) load it;
|
|
21
|
+
* - Next.js: the catch-all page `src/app/[[...slug]]/page.tsx` (or v7's own
|
|
22
|
+
* catch-all), which binds the draft, opens the page and renders it.
|
|
23
|
+
*
|
|
24
|
+
* Each section renders in v7's wrapper, `<section id data-manifest-key>` around
|
|
25
|
+
* an error boundary (`src/section-error-boundary.tsx`), and the TanStack routes
|
|
26
|
+
* keep v7's `cmsRouteConfig` behaviour: the options the site passed it (site
|
|
27
|
+
* name, default title, ignored search params, pending times), every other
|
|
28
|
+
* search param reaching the loader, its route cache times and its head (title,
|
|
29
|
+
* description, robots, Open Graph, Twitter Card, canonical, JSON-LD). The
|
|
30
|
+
* router's module-scope QueryClient moves into `getRouter`, one per request.
|
|
31
|
+
*
|
|
32
|
+
* A file that exists is kept and reported, except v7's own page routes
|
|
33
|
+
* (`cmsRouteConfig`, `createDecoPage`, …), which are replaced, and v7's admin
|
|
34
|
+
* routes (`/deco/invoke`, `/deco/meta`, `/deco/render`), which are deleted:
|
|
35
|
+
* v8 serves neither, and git has the old files.
|
|
36
|
+
*/
|
|
37
|
+
import fs from "node:fs";
|
|
38
|
+
import path from "node:path";
|
|
39
|
+
import ts from "typescript";
|
|
40
|
+
import { listSources } from "./compat";
|
|
41
|
+
import { type Framework, siteFramework } from "./framework";
|
|
42
|
+
import type { Report } from "./report";
|
|
43
|
+
import { relativeSpecifier } from "./vendor";
|
|
44
|
+
|
|
45
|
+
/** v7's page-route helpers: a route file that imports one is v7's, and is replaced. */
|
|
46
|
+
const V7_PAGE =
|
|
47
|
+
/\b(cmsRouteConfig|cmsHomeRouteConfig|DecoPageRenderer|loadCmsPage|loadCmsHomePage|withSiteGlobals|createDecoPage)\b/;
|
|
48
|
+
/** v7's admin endpoints: a route file that imports one is deleted. */
|
|
49
|
+
const V7_ADMIN =
|
|
50
|
+
/\b(decoInvokeRoute\w*|decoMetaRoute\w*|decoRenderRoute\w*|createDecoRouteHandlers|createDecoPreviewPage)\b/;
|
|
51
|
+
const IMPORTS_DECO = /from\s+["']@decocms\/(tanstack|nextjs|start|blocks)[^"']*["']/;
|
|
52
|
+
|
|
53
|
+
interface Wiring {
|
|
54
|
+
framework: Framework;
|
|
55
|
+
loadSections: boolean;
|
|
56
|
+
matchPage: boolean;
|
|
57
|
+
device: boolean;
|
|
58
|
+
/** The block map exports v7's PageSeo shape (else open-page.server.ts declares it). */
|
|
59
|
+
pageSeo: boolean;
|
|
60
|
+
/** The saved site block's SEO defaults, which v7 applied to every page. */
|
|
61
|
+
siteSeo: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The options a v7 page route passed `cmsRouteConfig` / `cmsHomeRouteConfig`, as literals. */
|
|
65
|
+
interface RouteOptions {
|
|
66
|
+
siteName?: string;
|
|
67
|
+
defaultTitle?: string;
|
|
68
|
+
defaultDescription?: string;
|
|
69
|
+
ignoreSearchParams?: string[];
|
|
70
|
+
pendingMs?: number;
|
|
71
|
+
pendingMinMs?: number;
|
|
72
|
+
/** The query reaches the loader (v7's catch-all always; a home route only when the site added it). */
|
|
73
|
+
search: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** v7's `routeCacheDefaults` gcTime: the catch-all used the "product" profile, the home "static". */
|
|
77
|
+
const GC_TIME = { "/$": "300_000", "/": "1_800_000" } as const;
|
|
78
|
+
|
|
79
|
+
const HEADER = (what: string) => [
|
|
80
|
+
"/**",
|
|
81
|
+
...what.split("\n").map((l) => ` * ${l}`),
|
|
82
|
+
" * Generated by the deco-v7-to-v8-migration skill; it's your code now.",
|
|
83
|
+
" */",
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
function cmsFile(w: Wiring): string {
|
|
87
|
+
const binding =
|
|
88
|
+
w.framework === "tanstack" ? "@decocms/tanstack/server" : "@decocms/nextjs/server";
|
|
89
|
+
return [
|
|
90
|
+
...HEADER(
|
|
91
|
+
"The CMS, created once at module scope (/next/content#create-the-cms), and the content client each\nrequest reads: the draft the binding accepted, or the release.",
|
|
92
|
+
),
|
|
93
|
+
'import { createCMS } from "@decocms/blocks";',
|
|
94
|
+
`import { contentClient } from "${binding}";`,
|
|
95
|
+
'import blocks from "../.deco";',
|
|
96
|
+
'import content from "../.deco/blocks.gen";',
|
|
97
|
+
"",
|
|
98
|
+
"export const cms = createCMS({ blocks, content });",
|
|
99
|
+
"",
|
|
100
|
+
w.framework === "tanstack"
|
|
101
|
+
? "/** The client for this request: the draft createDecoWorker accepted, or the release. */\nexport const client = async (request: Request) => contentClient(cms, request);"
|
|
102
|
+
: "/** The client for this request: the draft bindDraft bound (the catch-all page), or the release. */\nexport const client = async () => contentClient(cms);",
|
|
103
|
+
"",
|
|
104
|
+
].join("\n");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The part of openPage both frameworks share: route, match, resolve every section, run the loaders. */
|
|
108
|
+
function resolveBody(w: Wiring, request: string): string[] {
|
|
109
|
+
return [
|
|
110
|
+
" // Routing reads the index: the pages' paths, then the redirects block.",
|
|
111
|
+
" const [routes, routesError] = await c.routes();",
|
|
112
|
+
" if (routesError) throw routesError;",
|
|
113
|
+
" const match = matchRoute(url, { routes });",
|
|
114
|
+
" // The page's blocks start downloading with the redirects block, in one wave.",
|
|
115
|
+
' if (match.kind === "match") c.prefetch(match.entry.name);',
|
|
116
|
+
" const [redirects, redirectsError] = await c.redirects();",
|
|
117
|
+
" if (redirectsError) throw redirectsError;",
|
|
118
|
+
" const moved = matchRoute(url, { routes: [], redirects });",
|
|
119
|
+
...(w.framework === "tanstack"
|
|
120
|
+
? [
|
|
121
|
+
' if (moved.kind === "redirect") throw redirect({ href: moved.location, statusCode: moved.status });',
|
|
122
|
+
' if (match.kind !== "match") throw notFound();',
|
|
123
|
+
]
|
|
124
|
+
: [
|
|
125
|
+
' if (moved.kind === "redirect") {',
|
|
126
|
+
" if (moved.status === 301 || moved.status === 308) permanentRedirect(moved.location);",
|
|
127
|
+
" redirect(moved.location);",
|
|
128
|
+
" }",
|
|
129
|
+
' if (match.kind !== "match") notFound();',
|
|
130
|
+
]),
|
|
131
|
+
"",
|
|
132
|
+
" const [page, pageError] = await c.resolve<StoredPage>(match.entry.name, { run: false });",
|
|
133
|
+
" if (pageError) throw pageError;",
|
|
134
|
+
" // Variants of the whole list are one multivariate block: it resolves to the chosen list.",
|
|
135
|
+
" const saved = Array.isArray(page.sections) ? page.sections : page.sections ? [page.sections] : [];",
|
|
136
|
+
" const resolved = await Promise.all(",
|
|
137
|
+
" saved.map(async (block) => {",
|
|
138
|
+
" const [value, error] = await c.resolve<BlockDescriptor | BlockDescriptor[] | undefined>(block);",
|
|
139
|
+
" if (error) console.error(error); // a failed section renders nothing",
|
|
140
|
+
" return value ?? [];",
|
|
141
|
+
" }),",
|
|
142
|
+
" );",
|
|
143
|
+
...(w.loadSections
|
|
144
|
+
? [
|
|
145
|
+
" // v7's section loaders, as v7 ran them once the page resolved, at the page's URL.",
|
|
146
|
+
` const { sections, degraded } = await loadSections(resolved.flat(), ${request}, url);`,
|
|
147
|
+
]
|
|
148
|
+
: [" const sections = resolved.flat();"]),
|
|
149
|
+
"",
|
|
150
|
+
" const [seo, seoError] = await c.resolve<unknown>(page.seo);",
|
|
151
|
+
" if (seoError) throw seoError;",
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function openPageTanstack(w: Wiring): string {
|
|
156
|
+
const deco = [
|
|
157
|
+
"type BlockDescriptor",
|
|
158
|
+
...(w.loadSections ? ["loadSections"] : []),
|
|
159
|
+
...(w.matchPage ? ["matchPage"] : []),
|
|
160
|
+
...(w.pageSeo ? ["type PageSeo"] : []),
|
|
161
|
+
];
|
|
162
|
+
const compat = [...(w.device ? ["requestDevice"] : [])];
|
|
163
|
+
return [
|
|
164
|
+
...HEADER(
|
|
165
|
+
"Finds the page for a URL and resolves it the way v7 rendered it: every section, then v7's\nsection loaders (/next/tanstack-start-descriptors#3-match-the-url-to-a-page).",
|
|
166
|
+
),
|
|
167
|
+
'import { matchRoute, type Route } from "@decocms/blocks";',
|
|
168
|
+
...(compat.length > 0
|
|
169
|
+
? [`import { ${compat.join(", ")} } from "@decocms/compat-v7/tanstack/server";`]
|
|
170
|
+
: []),
|
|
171
|
+
...(w.loadSections ? ['import { DEGRADED_HEADER } from "@decocms/tanstack/server";'] : []),
|
|
172
|
+
'import { notFound, redirect } from "@tanstack/react-router";',
|
|
173
|
+
...(w.loadSections
|
|
174
|
+
? ['import { setResponseHeader } from "@tanstack/react-start/server";']
|
|
175
|
+
: []),
|
|
176
|
+
`import { ${deco.join(", ")} } from "../.deco";`,
|
|
177
|
+
'import { client } from "./cms";',
|
|
178
|
+
"",
|
|
179
|
+
"/** A page as saved: its sections and SEO are still blocks. */",
|
|
180
|
+
"interface StoredPage extends Route {",
|
|
181
|
+
" sections?: unknown;",
|
|
182
|
+
" seo?: unknown;",
|
|
183
|
+
"}",
|
|
184
|
+
"",
|
|
185
|
+
...(w.pageSeo ? [] : [...PAGE_SEO_TYPE, ""]),
|
|
186
|
+
...seoFieldsSource(w.siteSeo, w.framework),
|
|
187
|
+
"",
|
|
188
|
+
"/**",
|
|
189
|
+
" * Opens the page at `href` (a path on this site, with its query) for `request`. Every read uses the",
|
|
190
|
+
" * page's URL, never the request's: on a client-side navigation the request is the server-function",
|
|
191
|
+
" * call (/_serverFn/…), and v7 matched and loaded the page being opened.",
|
|
192
|
+
" */",
|
|
193
|
+
"export async function openPage(href: string, request: Request) {",
|
|
194
|
+
" const url = new URL(href, request.url);",
|
|
195
|
+
" if (url.origin !== new URL(request.url).origin) throw notFound();",
|
|
196
|
+
...(w.matchPage
|
|
197
|
+
? [
|
|
198
|
+
" // v7's matchers read this page, not the server-function call.",
|
|
199
|
+
" matchPage(url, request);",
|
|
200
|
+
]
|
|
201
|
+
: []),
|
|
202
|
+
" const c = await client(request);",
|
|
203
|
+
...resolveBody(w, "request"),
|
|
204
|
+
...(w.loadSections
|
|
205
|
+
? [
|
|
206
|
+
" // A section whose loader failed kept its saved props: v7 sent this header, and the worker never",
|
|
207
|
+
" // caches the page.",
|
|
208
|
+
' if (degraded.length > 0) setResponseHeader(DEGRADED_HEADER, "1");',
|
|
209
|
+
]
|
|
210
|
+
: []),
|
|
211
|
+
` return { name: page.name, seo: seoFields(seo), sections${w.device ? ", device: requestDevice(request)" : ""} };`,
|
|
212
|
+
"}",
|
|
213
|
+
"",
|
|
214
|
+
].join("\n");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const PAGE_FUNCTIONS = [
|
|
218
|
+
...HEADER(
|
|
219
|
+
"The page loader as a server function (/next/tanstack-start-descriptors#4-expose-it-through-a-server-function):\na plain call while the server renders, a fetch from the browser on a client-side navigation.",
|
|
220
|
+
),
|
|
221
|
+
'import { createServerFn } from "@tanstack/react-start";',
|
|
222
|
+
'import { getRequest } from "@tanstack/react-start/server";',
|
|
223
|
+
'import { openPage } from "./open-page.server";',
|
|
224
|
+
"",
|
|
225
|
+
"/** A path on this site: `//host/x` is a protocol-relative URL that would open another origin. */",
|
|
226
|
+
"function localPath(data: { href: string }): { href: string } {",
|
|
227
|
+
" const href = data?.href;",
|
|
228
|
+
' if (typeof href !== "string" || !href.startsWith("/") || href.startsWith("//") || href.startsWith("/\\\\")) {',
|
|
229
|
+
' throw new Error("not a local path");',
|
|
230
|
+
" }",
|
|
231
|
+
" return { href };",
|
|
232
|
+
"}",
|
|
233
|
+
"",
|
|
234
|
+
"/** Opens the page at `href`: the page's path and query, which openPage reads instead of /_serverFn's. */",
|
|
235
|
+
'export const loadPage = createServerFn({ method: "GET" })',
|
|
236
|
+
" .inputValidator(localPath)",
|
|
237
|
+
" .handler(({ data }) => openPage(data.href, getRequest()));",
|
|
238
|
+
"",
|
|
239
|
+
].join("\n");
|
|
240
|
+
|
|
241
|
+
/** v7's id for a section's wrapper: its type name with dashes for slashes, minus `.tsx` and `site-sections-`. */
|
|
242
|
+
const SECTION_ID = [
|
|
243
|
+
"/** v7's id for a section's wrapper: its type name with dashes for slashes, minus .tsx and site-sections-. */",
|
|
244
|
+
"function sectionId(component: string): string {",
|
|
245
|
+
' return component.replace(/\\//g, "-").replace(/\\.tsx$/, "").replace(/^site-sections-/, "");',
|
|
246
|
+
"}",
|
|
247
|
+
];
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* v7's per-section error boundary (@decocms/blocks/hooks' SectionErrorBoundary, 7.x), verbatim: a
|
|
251
|
+
* client component, so Next.js can render it around server-rendered sections.
|
|
252
|
+
*/
|
|
253
|
+
const SECTION_ERROR_BOUNDARY = [
|
|
254
|
+
'"use client";',
|
|
255
|
+
...HEADER(
|
|
256
|
+
"v7's per-section error boundary (SectionErrorBoundary from @decocms/blocks 7.x), as v7 wrapped every\nsection in it: a section that throws while rendering leaves an empty, hidden placeholder instead of\nbreaking the page; in development it shows the error.",
|
|
257
|
+
),
|
|
258
|
+
'import { Component, type ErrorInfo, type ReactNode } from "react";',
|
|
259
|
+
"",
|
|
260
|
+
"// Node's process, where the runtime has one (v7 read NODE_ENV from it); typed here so the site needs no Node types.",
|
|
261
|
+
"declare const process: { env: Record<string, string | undefined> } | undefined;",
|
|
262
|
+
"",
|
|
263
|
+
"interface ErrorBoundaryProps {",
|
|
264
|
+
" sectionKey: string;",
|
|
265
|
+
" fallback?: ReactNode;",
|
|
266
|
+
" children: ReactNode;",
|
|
267
|
+
"}",
|
|
268
|
+
"",
|
|
269
|
+
"interface ErrorBoundaryState {",
|
|
270
|
+
" error: Error | null;",
|
|
271
|
+
"}",
|
|
272
|
+
"",
|
|
273
|
+
"/**",
|
|
274
|
+
" * Per-section error boundary that prevents a single broken section",
|
|
275
|
+
" * from crashing the entire page.",
|
|
276
|
+
" *",
|
|
277
|
+
" * In development, shows the error message + stack trace.",
|
|
278
|
+
" * In production, renders a silent empty placeholder.",
|
|
279
|
+
" */",
|
|
280
|
+
"export class SectionErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {",
|
|
281
|
+
" constructor(props: ErrorBoundaryProps) {",
|
|
282
|
+
" super(props);",
|
|
283
|
+
" this.state = { error: null };",
|
|
284
|
+
" }",
|
|
285
|
+
"",
|
|
286
|
+
" static getDerivedStateFromError(error: Error): ErrorBoundaryState {",
|
|
287
|
+
" return { error };",
|
|
288
|
+
" }",
|
|
289
|
+
"",
|
|
290
|
+
" componentDidCatch(error: Error, info: ErrorInfo) {",
|
|
291
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
292
|
+
' console.error(`[CMS] Section "${this.props.sectionKey}" crashed:`, error, info.componentStack);',
|
|
293
|
+
" }",
|
|
294
|
+
"",
|
|
295
|
+
" render() {",
|
|
296
|
+
" if (this.state.error) {",
|
|
297
|
+
" if (this.props.fallback) return this.props.fallback;",
|
|
298
|
+
" return (",
|
|
299
|
+
" <DefaultSectionErrorFallback error={this.state.error} sectionKey={this.props.sectionKey} />",
|
|
300
|
+
" );",
|
|
301
|
+
" }",
|
|
302
|
+
" return this.props.children;",
|
|
303
|
+
" }",
|
|
304
|
+
"}",
|
|
305
|
+
"",
|
|
306
|
+
"function DefaultSectionErrorFallback({ error, sectionKey }: { error: Error; sectionKey: string }) {",
|
|
307
|
+
' const isDev = typeof process !== "undefined" && process.env.NODE_ENV === "development";',
|
|
308
|
+
"",
|
|
309
|
+
" if (!isDev) {",
|
|
310
|
+
' return <div data-section-error={sectionKey} className="hidden" />;',
|
|
311
|
+
" }",
|
|
312
|
+
"",
|
|
313
|
+
" return (",
|
|
314
|
+
" <div",
|
|
315
|
+
" data-section-error={sectionKey}",
|
|
316
|
+
" style={{",
|
|
317
|
+
' padding: "16px",',
|
|
318
|
+
' margin: "8px 0",',
|
|
319
|
+
' border: "2px solid #ef4444",',
|
|
320
|
+
' borderRadius: "8px",',
|
|
321
|
+
' background: "#fef2f2",',
|
|
322
|
+
' fontFamily: "monospace",',
|
|
323
|
+
' fontSize: "13px",',
|
|
324
|
+
" }}",
|
|
325
|
+
" >",
|
|
326
|
+
' <div style={{ fontWeight: "bold", color: "#dc2626", marginBottom: "8px" }}>',
|
|
327
|
+
" Section Error: {sectionKey}",
|
|
328
|
+
" </div>",
|
|
329
|
+
' <div style={{ color: "#991b1b" }}>{error.message}</div>',
|
|
330
|
+
" {error.stack && (",
|
|
331
|
+
" <pre",
|
|
332
|
+
" style={{",
|
|
333
|
+
' marginTop: "8px",',
|
|
334
|
+
' fontSize: "11px",',
|
|
335
|
+
' color: "#6b7280",',
|
|
336
|
+
' whiteSpace: "pre-wrap",',
|
|
337
|
+
' overflow: "auto",',
|
|
338
|
+
' maxHeight: "200px",',
|
|
339
|
+
" }}",
|
|
340
|
+
" >",
|
|
341
|
+
" {error.stack}",
|
|
342
|
+
" </pre>",
|
|
343
|
+
" )}",
|
|
344
|
+
" </div>",
|
|
345
|
+
" );",
|
|
346
|
+
"}",
|
|
347
|
+
"",
|
|
348
|
+
].join("\n");
|
|
349
|
+
|
|
350
|
+
/** The page's head as v7's cmsRouteConfig built it (buildHead). */
|
|
351
|
+
const PAGE_HEAD = [
|
|
352
|
+
"/** The site's titles, as v7's route passed them to cmsRouteConfig. */",
|
|
353
|
+
"export interface SiteTitles {",
|
|
354
|
+
" siteName: string;",
|
|
355
|
+
" defaultTitle: string;",
|
|
356
|
+
" defaultDescription?: string;",
|
|
357
|
+
"}",
|
|
358
|
+
"",
|
|
359
|
+
"/**",
|
|
360
|
+
" * v7's head (cmsRouteConfig's buildHead): title, description, robots, Open Graph, Twitter Card,",
|
|
361
|
+
" * canonical and JSON-LD.",
|
|
362
|
+
" */",
|
|
363
|
+
"export function pageHead(page: PageData | undefined, site: SiteTitles) {",
|
|
364
|
+
" const seo = page?.seo;",
|
|
365
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
366
|
+
" const title = seo?.title ? seo.title : page?.name ? `${page.name} | ${site.siteName}` : site.defaultTitle;",
|
|
367
|
+
" const description = seo?.description || site.defaultDescription;",
|
|
368
|
+
" const image = seo?.image;",
|
|
369
|
+
" const canonical = seo?.canonical;",
|
|
370
|
+
" const meta: Record<string, string>[] = [{ title }];",
|
|
371
|
+
' if (description) meta.push({ name: "description", content: description });',
|
|
372
|
+
" meta.push({",
|
|
373
|
+
' name: "robots",',
|
|
374
|
+
" content: seo?.noIndexing",
|
|
375
|
+
' ? "noindex, nofollow"',
|
|
376
|
+
' : "index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1",',
|
|
377
|
+
" });",
|
|
378
|
+
' meta.push({ property: "og:title", content: title });',
|
|
379
|
+
' if (description) meta.push({ property: "og:description", content: description });',
|
|
380
|
+
' if (image) meta.push({ property: "og:image", content: image });',
|
|
381
|
+
' meta.push({ property: "og:type", content: seo?.type || "website" });',
|
|
382
|
+
' if (canonical) meta.push({ property: "og:url", content: canonical });',
|
|
383
|
+
' meta.push({ name: "twitter:card", content: image ? "summary_large_image" : "summary" });',
|
|
384
|
+
' meta.push({ name: "twitter:title", content: title });',
|
|
385
|
+
' if (description) meta.push({ name: "twitter:description", content: description });',
|
|
386
|
+
' if (image) meta.push({ name: "twitter:image", content: image });',
|
|
387
|
+
' const links = canonical ? [{ rel: "canonical", href: canonical }] : [];',
|
|
388
|
+
" const scripts = (seo?.jsonLDs ?? []).map((jsonLD) => ({",
|
|
389
|
+
' type: "application/ld+json",',
|
|
390
|
+
" children: JSON.stringify(jsonLD),",
|
|
391
|
+
" }));",
|
|
392
|
+
" return { meta, links, scripts };",
|
|
393
|
+
"}",
|
|
394
|
+
];
|
|
395
|
+
|
|
396
|
+
function pageViewTanstack(w: Wiring): string {
|
|
397
|
+
return [
|
|
398
|
+
...HEADER(
|
|
399
|
+
"Renders an opened page as v7 did: each section through the view registry (src/views.ts), by its v7\ntype name, in v7's wrapper (`<section id data-manifest-key>` around an error boundary), and the\npage's head as v7's cmsRouteConfig built it.",
|
|
400
|
+
),
|
|
401
|
+
...(w.device
|
|
402
|
+
? ['import { type Device, DeviceProvider } from "@decocms/compat-v7/tanstack";']
|
|
403
|
+
: []),
|
|
404
|
+
w.pageSeo
|
|
405
|
+
? 'import type { BlockDescriptor, PageSeo } from "../.deco";'
|
|
406
|
+
: 'import type { BlockDescriptor } from "../.deco";',
|
|
407
|
+
...(w.pageSeo ? [] : ['import type { PageSeo } from "./open-page.server";']),
|
|
408
|
+
'import { SectionErrorBoundary } from "./section-error-boundary";',
|
|
409
|
+
'import { views } from "./views";',
|
|
410
|
+
"",
|
|
411
|
+
"// Node's process, where the runtime has one; typed here so the site needs no Node types.",
|
|
412
|
+
"declare const process: { env: Record<string, string | undefined> } | undefined;",
|
|
413
|
+
"",
|
|
414
|
+
"/** v7's development check for its route cache times (routeCacheDefaults). */",
|
|
415
|
+
"export const DEV =",
|
|
416
|
+
' typeof process !== "undefined" &&',
|
|
417
|
+
' (process.env.DECO_CACHE_DISABLE === "true" || process.env.NODE_ENV === "development");',
|
|
418
|
+
"",
|
|
419
|
+
"export interface PageData {",
|
|
420
|
+
" name?: string;",
|
|
421
|
+
" sections: BlockDescriptor[];",
|
|
422
|
+
" seo: PageSeo;",
|
|
423
|
+
...(w.device ? [" device: Device;"] : []),
|
|
424
|
+
"}",
|
|
425
|
+
"",
|
|
426
|
+
...PAGE_HEAD,
|
|
427
|
+
"",
|
|
428
|
+
...SECTION_ID,
|
|
429
|
+
"",
|
|
430
|
+
"/** One section in v7's wrapper; a type with no view renders nothing, as in v7. */",
|
|
431
|
+
"function Section({ section }: { section: BlockDescriptor }) {",
|
|
432
|
+
" const View = views[section.component]?.default;",
|
|
433
|
+
" if (!View) return null;",
|
|
434
|
+
" return (",
|
|
435
|
+
" <section",
|
|
436
|
+
" id={sectionId(section.component)}",
|
|
437
|
+
" data-manifest-key={section.component}",
|
|
438
|
+
' style={{ animation: "decoFadeIn 0.3s ease-out" }}',
|
|
439
|
+
" >",
|
|
440
|
+
" <SectionErrorBoundary sectionKey={section.component}>",
|
|
441
|
+
" <View {...section.props} />",
|
|
442
|
+
" </SectionErrorBoundary>",
|
|
443
|
+
" </section>",
|
|
444
|
+
" );",
|
|
445
|
+
"}",
|
|
446
|
+
"",
|
|
447
|
+
"export function PageView({ page }: { page: PageData }) {",
|
|
448
|
+
" const sections = page.sections.map((section, index) => (",
|
|
449
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
450
|
+
" <Section key={`${section.component}-${index}`} section={section} />",
|
|
451
|
+
" ));",
|
|
452
|
+
w.device
|
|
453
|
+
? " return <DeviceProvider value={page.device}>{sections}</DeviceProvider>;"
|
|
454
|
+
: " return <>{sections}</>;",
|
|
455
|
+
"}",
|
|
456
|
+
"",
|
|
457
|
+
].join("\n");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** v7's PageSeo, declared here when the block map doesn't export it. */
|
|
461
|
+
const PAGE_SEO_TYPE = [
|
|
462
|
+
"/** v7's page SEO: what the page's head shows. Every field is optional. */",
|
|
463
|
+
"export interface PageSeo {",
|
|
464
|
+
" title?: string;",
|
|
465
|
+
" description?: string;",
|
|
466
|
+
" titleTemplate?: string;",
|
|
467
|
+
" descriptionTemplate?: string;",
|
|
468
|
+
" image?: string;",
|
|
469
|
+
" canonical?: string;",
|
|
470
|
+
" noIndexing?: boolean;",
|
|
471
|
+
" type?: string;",
|
|
472
|
+
" // biome-ignore lint/suspicious/noExplicitAny: JSON-LD objects",
|
|
473
|
+
" jsonLDs?: Record<string, any>[];",
|
|
474
|
+
"}",
|
|
475
|
+
];
|
|
476
|
+
|
|
477
|
+
/** v7's extractSeoFromProps over the page's SEO block, then its title and description templates. */
|
|
478
|
+
/**
|
|
479
|
+
* v7's Next.js page SEO (createDecoPage's buildSeo): the page's SEO block's fields as they are, without
|
|
480
|
+
* the site's defaults or templates, which only v7's TanStack route applied.
|
|
481
|
+
*/
|
|
482
|
+
const NEXT_SEO_FIELDS = [
|
|
483
|
+
"/** The page's SEO as v7's Next.js page read it: the SEO block's fields (or a section descriptor carrying them). */",
|
|
484
|
+
"function seoFields(seo: unknown): PageSeo {",
|
|
485
|
+
' const fields = seo && typeof seo === "object" && "props" in seo ? (seo as { props: unknown }).props : seo;',
|
|
486
|
+
' const props = (fields && typeof fields === "object" ? fields : {}) as Record<string, unknown>;',
|
|
487
|
+
" const out: PageSeo = {};",
|
|
488
|
+
" if (props.title) out.title = props.title as string;",
|
|
489
|
+
" if (props.description) out.description = props.description as string;",
|
|
490
|
+
" if (props.canonical) out.canonical = props.canonical as string;",
|
|
491
|
+
" if (props.image) out.image = props.image as string;",
|
|
492
|
+
" if (props.noIndexing !== undefined) out.noIndexing = props.noIndexing as boolean;",
|
|
493
|
+
" if (props.type) out.type = props.type as string;",
|
|
494
|
+
" if (Array.isArray(props.jsonLDs) && props.jsonLDs.length) out.jsonLDs = props.jsonLDs;",
|
|
495
|
+
" return out;",
|
|
496
|
+
"}",
|
|
497
|
+
];
|
|
498
|
+
|
|
499
|
+
/** The SEO defaults v7 applied to every page: the `seo` of the saved `Site` (or `site`) block (getSiteSeo). */
|
|
500
|
+
export function siteSeo(root: string): Record<string, string> {
|
|
501
|
+
for (const name of ["Site", "site"]) {
|
|
502
|
+
const file = path.join(root, ".deco", "blocks", `${name}.json`);
|
|
503
|
+
if (!fs.existsSync(file)) continue;
|
|
504
|
+
let seo: unknown;
|
|
505
|
+
try {
|
|
506
|
+
seo = (JSON.parse(fs.readFileSync(file, "utf8")) as { seo?: unknown }).seo;
|
|
507
|
+
} catch {
|
|
508
|
+
return {};
|
|
509
|
+
}
|
|
510
|
+
if (!seo || typeof seo !== "object") return {};
|
|
511
|
+
const out: Record<string, string> = {};
|
|
512
|
+
for (const key of ["title", "description", "image", "titleTemplate", "descriptionTemplate"]) {
|
|
513
|
+
const value = (seo as Record<string, unknown>)[key];
|
|
514
|
+
if (typeof value === "string") out[key] = value;
|
|
515
|
+
}
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
return {};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* v7's page SEO (buildPageSeo): the page's SEO block (extractSeoFromProps), the site's defaults for an
|
|
523
|
+
* empty title, description and image, then the block's templates, else the site's.
|
|
524
|
+
*/
|
|
525
|
+
function seoFieldsSource(site: Record<string, string>, framework: Framework): string[] {
|
|
526
|
+
if (framework === "nextjs") return NEXT_SEO_FIELDS;
|
|
527
|
+
const entries = Object.entries(site);
|
|
528
|
+
return [
|
|
529
|
+
"/**",
|
|
530
|
+
entries.length > 0
|
|
531
|
+
? " * The SEO defaults v7 applied to every page: the seo of the saved site block (getSiteSeo). The script"
|
|
532
|
+
: " * The SEO defaults v7 applied to every page, from the seo of a saved Site block: this site had none. The script",
|
|
533
|
+
" * read them once; they are code now.",
|
|
534
|
+
" */",
|
|
535
|
+
entries.length > 0
|
|
536
|
+
? `const SITE_SEO: PageSeo = {\n${entries.map(([k, v]) => ` ${k}: ${JSON.stringify(v)},`).join("\n")}\n};`
|
|
537
|
+
: "const SITE_SEO: PageSeo = {};",
|
|
538
|
+
"",
|
|
539
|
+
'/** v7\'s template rule: blank or "%s" is no template. */',
|
|
540
|
+
"function template(value: unknown): string | undefined {",
|
|
541
|
+
' return typeof value === "string" && value.trim() !== "" && value.trim() !== "%s" ? value : undefined;',
|
|
542
|
+
"}",
|
|
543
|
+
"",
|
|
544
|
+
"/**",
|
|
545
|
+
" * The page's SEO as v7 built it (buildPageSeo): the page's SEO block's fields (or a section descriptor",
|
|
546
|
+
" * carrying them), the site's defaults for an empty title, description and image, then the block's",
|
|
547
|
+
" * title and description templates, else the site's.",
|
|
548
|
+
" */",
|
|
549
|
+
"function seoFields(seo: unknown): PageSeo {",
|
|
550
|
+
' const fields = seo && typeof seo === "object" && "props" in seo ? (seo as { props: unknown }).props : seo;',
|
|
551
|
+
' const props = (fields && typeof fields === "object" ? fields : {}) as Record<string, unknown>;',
|
|
552
|
+
" const out: PageSeo = {};",
|
|
553
|
+
" if (props.title) out.title = props.title as string;",
|
|
554
|
+
" if (props.description) out.description = props.description as string;",
|
|
555
|
+
" if (props.canonical) out.canonical = props.canonical as string;",
|
|
556
|
+
" if (props.image) out.image = props.image as string;",
|
|
557
|
+
" if (props.noIndexing !== undefined) out.noIndexing = props.noIndexing as boolean;",
|
|
558
|
+
" if (props.type) out.type = props.type as string;",
|
|
559
|
+
" if (Array.isArray(props.jsonLDs) && props.jsonLDs.length) out.jsonLDs = props.jsonLDs;",
|
|
560
|
+
" if (!out.title && SITE_SEO.title) out.title = SITE_SEO.title;",
|
|
561
|
+
" if (!out.description && SITE_SEO.description) out.description = SITE_SEO.description;",
|
|
562
|
+
" if (!out.image && SITE_SEO.image) out.image = SITE_SEO.image;",
|
|
563
|
+
" const titleTemplate = template(props.titleTemplate) ?? template(SITE_SEO.titleTemplate);",
|
|
564
|
+
" const descriptionTemplate = template(props.descriptionTemplate) ?? template(SITE_SEO.descriptionTemplate);",
|
|
565
|
+
' if (titleTemplate && out.title) out.title = titleTemplate.replace("%s", out.title);',
|
|
566
|
+
" if (descriptionTemplate && out.description) {",
|
|
567
|
+
' out.description = descriptionTemplate.replace("%s", out.description);',
|
|
568
|
+
" }",
|
|
569
|
+
" return out;",
|
|
570
|
+
"}",
|
|
571
|
+
];
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** Reads the literal options a v7 page route passed cmsRouteConfig or cmsHomeRouteConfig. */
|
|
575
|
+
export function v7RouteOptions(text: string, routePath: "/" | "/$"): RouteOptions {
|
|
576
|
+
const options: RouteOptions = { search: routePath === "/$" || /\bloaderDeps\b/.test(text) };
|
|
577
|
+
const sf = ts.createSourceFile(
|
|
578
|
+
"route.tsx",
|
|
579
|
+
text,
|
|
580
|
+
ts.ScriptTarget.Latest,
|
|
581
|
+
true,
|
|
582
|
+
ts.ScriptKind.TSX,
|
|
583
|
+
);
|
|
584
|
+
const visit = (node: ts.Node) => {
|
|
585
|
+
if (
|
|
586
|
+
ts.isCallExpression(node) &&
|
|
587
|
+
ts.isIdentifier(node.expression) &&
|
|
588
|
+
/^cms(Home)?RouteConfig$/.test(node.expression.text) &&
|
|
589
|
+
node.arguments[0] &&
|
|
590
|
+
ts.isObjectLiteralExpression(node.arguments[0])
|
|
591
|
+
) {
|
|
592
|
+
for (const prop of node.arguments[0].properties) {
|
|
593
|
+
if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name)) continue;
|
|
594
|
+
const name = prop.name.text;
|
|
595
|
+
const value = prop.initializer;
|
|
596
|
+
const str = ts.isStringLiteralLike(value) ? value.text : undefined;
|
|
597
|
+
const num = ts.isNumericLiteral(value) ? Number(value.text.replace(/_/g, "")) : undefined;
|
|
598
|
+
if (
|
|
599
|
+
(name === "siteName" || name === "defaultTitle" || name === "defaultDescription") &&
|
|
600
|
+
str !== undefined
|
|
601
|
+
) {
|
|
602
|
+
options[name] = str;
|
|
603
|
+
} else if ((name === "pendingMs" || name === "pendingMinMs") && num !== undefined) {
|
|
604
|
+
options[name] = num;
|
|
605
|
+
} else if (
|
|
606
|
+
name === "ignoreSearchParams" &&
|
|
607
|
+
ts.isArrayLiteralExpression(value) &&
|
|
608
|
+
value.elements.every(ts.isStringLiteralLike)
|
|
609
|
+
) {
|
|
610
|
+
options.ignoreSearchParams = value.elements.map((e) => (e as ts.StringLiteralLike).text);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
ts.forEachChild(node, visit);
|
|
615
|
+
};
|
|
616
|
+
visit(sf);
|
|
617
|
+
return options;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** A number as source, with v7's digit grouping: 60000 → 60_000. */
|
|
621
|
+
function numeral(n: number): string {
|
|
622
|
+
return Number.isInteger(n) && n >= 10_000
|
|
623
|
+
? String(n).replace(/\B(?=(\d{3})+(?!\d))/g, "_")
|
|
624
|
+
: String(n);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function routeTanstack(routePath: "/" | "/$", fromRoutes: string, o: RouteOptions): string {
|
|
628
|
+
// v7's defaults: cmsHomeRouteConfig's siteName is its defaultTitle; both titles fall back to the other.
|
|
629
|
+
const defaultTitle = o.defaultTitle ?? o.siteName ?? "";
|
|
630
|
+
const siteName = o.siteName ?? defaultTitle;
|
|
631
|
+
const titles = [
|
|
632
|
+
` siteName: ${JSON.stringify(siteName)},`,
|
|
633
|
+
` defaultTitle: ${JSON.stringify(defaultTitle)},`,
|
|
634
|
+
...(o.defaultDescription !== undefined
|
|
635
|
+
? [` defaultDescription: ${JSON.stringify(o.defaultDescription)},`]
|
|
636
|
+
: []),
|
|
637
|
+
];
|
|
638
|
+
const ignored = o.ignoreSearchParams ?? ["skuId"];
|
|
639
|
+
return [
|
|
640
|
+
'import { createFileRoute } from "@tanstack/react-router";',
|
|
641
|
+
`import { DEV, PageView, pageHead, type SiteTitles } from "${fromRoutes}/page-view";`,
|
|
642
|
+
`import { loadPage } from "${fromRoutes}/page.functions";`,
|
|
643
|
+
"",
|
|
644
|
+
"// A CMS page, found by its URL (src/open-page.server.ts), with what v7's",
|
|
645
|
+
`// ${routePath === "/" ? "cmsHomeRouteConfig" : "cmsRouteConfig"} gave the route. Generated by the deco-v7-to-v8-migration skill.`,
|
|
646
|
+
"",
|
|
647
|
+
"/** The titles v7's route passed: the head falls back to them. */",
|
|
648
|
+
"const SITE: SiteTitles = {",
|
|
649
|
+
...titles,
|
|
650
|
+
"};",
|
|
651
|
+
...(o.search
|
|
652
|
+
? [
|
|
653
|
+
"",
|
|
654
|
+
"/** Search params that don't reload the page (v7's ignoreSearchParams): client-side state. */",
|
|
655
|
+
`const IGNORED_SEARCH_PARAMS = new Set(${JSON.stringify(ignored)});`,
|
|
656
|
+
]
|
|
657
|
+
: []),
|
|
658
|
+
"",
|
|
659
|
+
`export const Route = createFileRoute("${routePath}")({`,
|
|
660
|
+
...(o.search
|
|
661
|
+
? [
|
|
662
|
+
" // Every search param reaches the loader (filters, sort, pagination), except the ignored ones.",
|
|
663
|
+
" validateSearch: (search: Record<string, unknown>) => search as Record<string, string>,",
|
|
664
|
+
" loaderDeps: ({ search }) => {",
|
|
665
|
+
" const kept = Object.fromEntries(",
|
|
666
|
+
" Object.entries(search ?? {}).filter(([key]) => !IGNORED_SEARCH_PARAMS.has(key)),",
|
|
667
|
+
" );",
|
|
668
|
+
" return { search: Object.keys(kept).length ? kept : undefined };",
|
|
669
|
+
" },",
|
|
670
|
+
" loader: ({ location, deps }) => {",
|
|
671
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
672
|
+
' const query = deps.search ? `?${new URLSearchParams(deps.search).toString()}` : "";',
|
|
673
|
+
" return loadPage({ data: { href: location.pathname + query } });",
|
|
674
|
+
" },",
|
|
675
|
+
]
|
|
676
|
+
: [" loader: ({ location }) => loadPage({ data: { href: location.pathname } }),"]),
|
|
677
|
+
` pendingMs: ${numeral(o.pendingMs ?? 200)},`,
|
|
678
|
+
` pendingMinMs: ${numeral(o.pendingMinMs ?? 300)},`,
|
|
679
|
+
" // v7's routeCacheDefaults: kept for the session in production, briefly in development.",
|
|
680
|
+
" staleTime: DEV ? 5_000 : Number.POSITIVE_INFINITY,",
|
|
681
|
+
` gcTime: DEV ? 30_000 : ${GC_TIME[routePath]},`,
|
|
682
|
+
" head: ({ loaderData }) => pageHead(loaderData, SITE),",
|
|
683
|
+
" component: CmsPage,",
|
|
684
|
+
"});",
|
|
685
|
+
"",
|
|
686
|
+
"function CmsPage() {",
|
|
687
|
+
" return <PageView page={Route.useLoaderData()} />;",
|
|
688
|
+
"}",
|
|
689
|
+
"",
|
|
690
|
+
].join("\n");
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function openPageNext(w: Wiring): string {
|
|
694
|
+
const deco = [
|
|
695
|
+
"type BlockDescriptor",
|
|
696
|
+
...(w.loadSections ? ["loadSections"] : []),
|
|
697
|
+
...(w.pageSeo ? ["type PageSeo"] : []),
|
|
698
|
+
];
|
|
699
|
+
return [
|
|
700
|
+
...HEADER(
|
|
701
|
+
"Finds the page for a URL and resolves it the way v7 rendered it: every section, then v7's\nsection loaders (/next/nextjs#4-match-the-url-to-a-page). React's cache shares one result between\ngenerateMetadata and the page.",
|
|
702
|
+
),
|
|
703
|
+
'import { matchRoute, type Route } from "@decocms/blocks";',
|
|
704
|
+
...(w.device ? ['import { requestDevice } from "@decocms/compat-v7/nextjs/server";'] : []),
|
|
705
|
+
'import { headers } from "next/headers";',
|
|
706
|
+
'import { notFound, permanentRedirect, redirect } from "next/navigation";',
|
|
707
|
+
'import { cache } from "react";',
|
|
708
|
+
`import { ${deco.join(", ")} } from "../.deco";`,
|
|
709
|
+
'import { client } from "./cms";',
|
|
710
|
+
"",
|
|
711
|
+
"/** A page as saved: its sections and SEO are still blocks. */",
|
|
712
|
+
"interface StoredPage extends Route {",
|
|
713
|
+
" sections?: unknown;",
|
|
714
|
+
" seo?: unknown;",
|
|
715
|
+
"}",
|
|
716
|
+
"",
|
|
717
|
+
...(w.pageSeo ? [] : [...PAGE_SEO_TYPE, ""]),
|
|
718
|
+
"type SearchParams = Record<string, string | string[] | undefined>;",
|
|
719
|
+
"",
|
|
720
|
+
"/** The page's path and query, from the catch-all's segments and search params. */",
|
|
721
|
+
"export function hrefFor(segments: string[] = [], searchParams: SearchParams = {}): string {",
|
|
722
|
+
" const query = new URLSearchParams();",
|
|
723
|
+
" for (const [key, value] of Object.entries(searchParams)) {",
|
|
724
|
+
" for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) query.append(key, v);",
|
|
725
|
+
" }",
|
|
726
|
+
" const search = query.toString();",
|
|
727
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
728
|
+
' return `/${segments.map(encodeURIComponent).join("/")}${search ? `?${search}` : ""}`;',
|
|
729
|
+
"}",
|
|
730
|
+
"",
|
|
731
|
+
...seoFieldsSource(w.siteSeo, w.framework),
|
|
732
|
+
"",
|
|
733
|
+
"/** Opens the page at `href` (a path on this site, with its query). */",
|
|
734
|
+
"export const openPage = cache(async (href: string) => {",
|
|
735
|
+
" const incoming = await headers();",
|
|
736
|
+
' const host = incoming.get("x-forwarded-host") ?? incoming.get("host") ?? "localhost";',
|
|
737
|
+
' const protocol = incoming.get("x-forwarded-proto") ?? "https";',
|
|
738
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
739
|
+
" const url = new URL(href, `${protocol}://${host}`);",
|
|
740
|
+
...(w.loadSections
|
|
741
|
+
? [" const request = new Request(url, { headers: new Headers(incoming) });"]
|
|
742
|
+
: []),
|
|
743
|
+
" const c = await client();",
|
|
744
|
+
...resolveBody(w, "request"),
|
|
745
|
+
` return { name: page.name, seo: seoFields(seo), sections${w.loadSections ? ", degraded" : ""}${w.device ? ", device: await requestDevice()" : ""} };`,
|
|
746
|
+
"});",
|
|
747
|
+
"",
|
|
748
|
+
].join("\n");
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function pageNext(w: Wiring, file: string, root: string, param: string): string {
|
|
752
|
+
const from = (rel: string) => relativeSpecifier(file, path.join(root, "src", rel));
|
|
753
|
+
return [
|
|
754
|
+
...HEADER(
|
|
755
|
+
"Every CMS page: binds the request's draft, opens the page for its URL and renders each section\nthrough the view registry (src/views.ts), by its v7 type name (/next/nextjs#5-render-the-catch-all-route).",
|
|
756
|
+
),
|
|
757
|
+
...(w.device ? ['import { DeviceProvider } from "@decocms/compat-v7/nextjs";'] : []),
|
|
758
|
+
'import { bindDraft } from "@decocms/nextjs/server";',
|
|
759
|
+
'import type { Metadata } from "next";',
|
|
760
|
+
`import { cms } from "${from("cms.ts")}";`,
|
|
761
|
+
`import { hrefFor, openPage } from "${from("open-page.server.ts")}";`,
|
|
762
|
+
`import { SectionErrorBoundary } from "${from("section-error-boundary.tsx")}";`,
|
|
763
|
+
`import { views } from "${from("views.ts")}";`,
|
|
764
|
+
"",
|
|
765
|
+
"type Props = {",
|
|
766
|
+
` params: Promise<{ ${param}?: string[] }>;`,
|
|
767
|
+
" searchParams: Promise<Record<string, string | string[] | undefined>>;",
|
|
768
|
+
"};",
|
|
769
|
+
"",
|
|
770
|
+
"async function pageFor({ params, searchParams }: Props) {",
|
|
771
|
+
" const query = await searchParams;",
|
|
772
|
+
" await bindDraft(cms, { searchParams: query });",
|
|
773
|
+
` return openPage(hrefFor((await params).${param}, query));`,
|
|
774
|
+
"}",
|
|
775
|
+
"",
|
|
776
|
+
"/** v7's page metadata: title, description, canonical and robots. */",
|
|
777
|
+
"export async function generateMetadata(props: Props): Promise<Metadata> {",
|
|
778
|
+
" const seo = (await pageFor(props)).seo;",
|
|
779
|
+
" return {",
|
|
780
|
+
" title: seo.title,",
|
|
781
|
+
" description: seo.description,",
|
|
782
|
+
" alternates: seo.canonical ? { canonical: seo.canonical } : undefined,",
|
|
783
|
+
" robots: seo.noIndexing ? { index: false, follow: false } : undefined,",
|
|
784
|
+
" };",
|
|
785
|
+
"}",
|
|
786
|
+
"",
|
|
787
|
+
...SECTION_ID,
|
|
788
|
+
"",
|
|
789
|
+
"export default async function Page(props: Props) {",
|
|
790
|
+
" const page = await pageFor(props);",
|
|
791
|
+
" // Each section in v7's wrapper, `<section id data-manifest-key>` around an error boundary.",
|
|
792
|
+
" const sections = page.sections.map((section, index) => {",
|
|
793
|
+
" const View = views[section.component]?.default;",
|
|
794
|
+
" if (!View) return null;",
|
|
795
|
+
" return (",
|
|
796
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
|
|
797
|
+
" <section key={`${section.component}-${index}`} id={sectionId(section.component)} data-manifest-key={section.component}>",
|
|
798
|
+
" <SectionErrorBoundary sectionKey={section.component}>",
|
|
799
|
+
" <View {...section.props} />",
|
|
800
|
+
" </SectionErrorBoundary>",
|
|
801
|
+
" </section>",
|
|
802
|
+
" );",
|
|
803
|
+
" });",
|
|
804
|
+
" return (",
|
|
805
|
+
" <>",
|
|
806
|
+
w.device
|
|
807
|
+
? " <DeviceProvider value={page.device}>{sections}</DeviceProvider>"
|
|
808
|
+
: " {sections}",
|
|
809
|
+
" </>",
|
|
810
|
+
" );",
|
|
811
|
+
"}",
|
|
812
|
+
"",
|
|
813
|
+
].join("\n");
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/** The site's app directory on Next.js: `src/app`, else `app`, else a new `src/app`. */
|
|
817
|
+
function appDir(root: string): string {
|
|
818
|
+
for (const dir of [path.join(root, "src", "app"), path.join(root, "app")]) {
|
|
819
|
+
if (fs.existsSync(dir)) return dir;
|
|
820
|
+
}
|
|
821
|
+
return path.join(root, "src", "app");
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/** A catch-all page directly in the app directory or one route group: `[[...x]]` or `[...x]`. */
|
|
825
|
+
function findCatchAll(dir: string): { file: string; param: string } | undefined {
|
|
826
|
+
if (!fs.existsSync(dir)) return undefined;
|
|
827
|
+
const candidates = [dir];
|
|
828
|
+
for (const d of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
829
|
+
if (d.isDirectory() && /^\(.+\)$/.test(d.name)) candidates.push(path.join(dir, d.name));
|
|
830
|
+
}
|
|
831
|
+
for (const base of candidates) {
|
|
832
|
+
for (const d of fs.readdirSync(base, { withFileTypes: true })) {
|
|
833
|
+
const param = /^\[\[?\.\.\.([A-Za-z_$][\w$]*)\]\]?$/.exec(d.name)?.[1];
|
|
834
|
+
if (!d.isDirectory() || !param) continue;
|
|
835
|
+
for (const name of ["page.tsx", "page.ts", "page.jsx"]) {
|
|
836
|
+
const file = path.join(base, d.name, name);
|
|
837
|
+
if (fs.existsSync(file)) return { file, param };
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return undefined;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Moves a router's module-scope `new QueryClient(…)` into `getRouter`. The server creates a router per
|
|
846
|
+
* request, so a client at module scope is shared by every visitor (one visitor's cart or user in
|
|
847
|
+
* another's render); in the browser `getRouter` runs once, so it still keeps one client
|
|
848
|
+
* (references/caching-and-privacy.md).
|
|
849
|
+
*/
|
|
850
|
+
export function scopeQueryClient(root: string, report: Report): void {
|
|
851
|
+
const file = ["router.tsx", "router.ts"]
|
|
852
|
+
.map((f) => path.join(root, "src", f))
|
|
853
|
+
.find(fs.existsSync);
|
|
854
|
+
if (!file) return;
|
|
855
|
+
const text = fs.readFileSync(file, "utf8");
|
|
856
|
+
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
857
|
+
let decl: ts.VariableStatement | undefined;
|
|
858
|
+
let name = "";
|
|
859
|
+
let getRouter: ts.FunctionDeclaration | undefined;
|
|
860
|
+
for (const st of sf.statements) {
|
|
861
|
+
if (ts.isVariableStatement(st) && st.declarationList.declarations.length === 1) {
|
|
862
|
+
const d = st.declarationList.declarations[0];
|
|
863
|
+
if (
|
|
864
|
+
ts.isIdentifier(d.name) &&
|
|
865
|
+
d.initializer &&
|
|
866
|
+
ts.isNewExpression(d.initializer) &&
|
|
867
|
+
ts.isIdentifier(d.initializer.expression) &&
|
|
868
|
+
d.initializer.expression.text === "QueryClient"
|
|
869
|
+
) {
|
|
870
|
+
decl = st;
|
|
871
|
+
name = d.name.text;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (ts.isFunctionDeclaration(st) && st.name?.text === "getRouter" && st.body) getRouter = st;
|
|
875
|
+
}
|
|
876
|
+
if (!decl || !getRouter?.body) return;
|
|
877
|
+
// Used outside getRouter (exported, or read by another module-scope function): leave it, and say so.
|
|
878
|
+
const exported = decl.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
879
|
+
let usedOutside = false;
|
|
880
|
+
const scan = (node: ts.Node) => {
|
|
881
|
+
if (
|
|
882
|
+
ts.isIdentifier(node) &&
|
|
883
|
+
node.text === name &&
|
|
884
|
+
node.parent !== decl!.declarationList.declarations[0]
|
|
885
|
+
) {
|
|
886
|
+
if (node.pos < getRouter!.pos || node.end > getRouter!.end) usedOutside = true;
|
|
887
|
+
}
|
|
888
|
+
ts.forEachChild(node, scan);
|
|
889
|
+
};
|
|
890
|
+
scan(sf);
|
|
891
|
+
const rel = path.relative(root, file).split(path.sep).join("/");
|
|
892
|
+
if (exported || usedOutside) {
|
|
893
|
+
report.manual.push({
|
|
894
|
+
step: "scaffold",
|
|
895
|
+
subject: rel,
|
|
896
|
+
message: `the QueryClient "${name}" is created once at module scope and shared by every request on the server: create it inside getRouter, one per request (references/caching-and-privacy.md)`,
|
|
897
|
+
});
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const statement = text.slice(decl.getStart(sf), decl.end);
|
|
901
|
+
const bodyStart = getRouter.body.getStart(sf) + 1;
|
|
902
|
+
const indented = statement
|
|
903
|
+
.split("\n")
|
|
904
|
+
.map((l) => (l ? ` ${l}` : l))
|
|
905
|
+
.join("\n");
|
|
906
|
+
const comment =
|
|
907
|
+
" // One QueryClient per router: the server creates a router per request, so a visitor's data never\n // reaches another visitor's render. The browser creates one router, so it keeps one client.\n";
|
|
908
|
+
const start = decl.getStart(sf);
|
|
909
|
+
let end = decl.end;
|
|
910
|
+
while (text[end] === "\n" && text[end + 1] === "\n") end++;
|
|
911
|
+
if (text[end] === "\n") end++;
|
|
912
|
+
const out = `${text.slice(0, start)}${text.slice(end, bodyStart)}\n${comment}${indented}${text.slice(bodyStart)}`;
|
|
913
|
+
fs.writeFileSync(file, out);
|
|
914
|
+
report.done.push({
|
|
915
|
+
step: "scaffold",
|
|
916
|
+
subject: rel,
|
|
917
|
+
message: `the QueryClient "${name}" is created in getRouter now, one per request on the server, instead of one shared by every visitor`,
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** Writes the page setup for the site's binding. */
|
|
922
|
+
export function writeScaffold(root: string, report: Report): void {
|
|
923
|
+
const framework = siteFramework(root);
|
|
924
|
+
if (!framework) return;
|
|
925
|
+
const mapFile = path.join(root, ".deco", "index.ts");
|
|
926
|
+
const map = fs.existsSync(mapFile) ? fs.readFileSync(mapFile, "utf8") : "";
|
|
927
|
+
const rel = (file: string) => path.relative(root, file).split(path.sep).join("/");
|
|
928
|
+
if (
|
|
929
|
+
!/export interface BlockDescriptor/.test(map) ||
|
|
930
|
+
!fs.existsSync(path.join(root, "src", "views.ts"))
|
|
931
|
+
) {
|
|
932
|
+
report.manual.push({
|
|
933
|
+
step: "scaffold",
|
|
934
|
+
subject: "page setup",
|
|
935
|
+
message: `the script didn't write the block map or src/views.ts this run, so it wrote no page setup: create src/cms.ts, the page loader and the catch-all route (${framework === "tanstack" ? "/next/tanstack-start-descriptors" : "/next/nextjs"})`,
|
|
936
|
+
});
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const sources = listSources(path.join(root, "src"));
|
|
940
|
+
const device = sources.some((f) => /\buseDevice\s*\(/.test(fs.readFileSync(f, "utf8")));
|
|
941
|
+
const w: Wiring = {
|
|
942
|
+
framework,
|
|
943
|
+
loadSections: /export function loadSections\b/.test(map),
|
|
944
|
+
matchPage: /export function matchPage\b/.test(map),
|
|
945
|
+
device,
|
|
946
|
+
pageSeo: /export interface PageSeo\b/.test(map),
|
|
947
|
+
siteSeo: siteSeo(root),
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
const written: string[] = [];
|
|
951
|
+
const replaced: string[] = [];
|
|
952
|
+
const kept: string[] = [];
|
|
953
|
+
const write = (file: string, text: string, replaceV7 = false) => {
|
|
954
|
+
if (fs.existsSync(file)) {
|
|
955
|
+
const old = fs.readFileSync(file, "utf8");
|
|
956
|
+
if (!(replaceV7 && IMPORTS_DECO.test(old) && V7_PAGE.test(old))) {
|
|
957
|
+
kept.push(rel(file));
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
replaced.push(rel(file));
|
|
961
|
+
} else {
|
|
962
|
+
written.push(rel(file));
|
|
963
|
+
}
|
|
964
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
965
|
+
fs.writeFileSync(file, text);
|
|
966
|
+
};
|
|
967
|
+
const deleted: string[] = [];
|
|
968
|
+
const dropAdmin = (dir: string) => {
|
|
969
|
+
for (const file of listSources(dir)) {
|
|
970
|
+
const text = fs.readFileSync(file, "utf8");
|
|
971
|
+
if (IMPORTS_DECO.test(text) && V7_ADMIN.test(text) && !V7_PAGE.test(text)) {
|
|
972
|
+
fs.rmSync(file);
|
|
973
|
+
deleted.push(rel(file));
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
const src = (f: string) => path.join(root, "src", f);
|
|
979
|
+
write(src("cms.ts"), cmsFile(w));
|
|
980
|
+
write(src("section-error-boundary.tsx"), SECTION_ERROR_BOUNDARY);
|
|
981
|
+
if (framework === "tanstack") {
|
|
982
|
+
write(src("open-page.server.ts"), openPageTanstack(w));
|
|
983
|
+
write(src("page.functions.ts"), PAGE_FUNCTIONS);
|
|
984
|
+
write(src("page-view.tsx"), pageViewTanstack(w));
|
|
985
|
+
const routes = src("routes");
|
|
986
|
+
const v7Options = (file: string, routePath: "/" | "/$") =>
|
|
987
|
+
v7RouteOptions(fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "", routePath);
|
|
988
|
+
const catchAll = path.join(routes, "$.tsx");
|
|
989
|
+
write(catchAll, routeTanstack("/$", "..", v7Options(catchAll, "/$")), true);
|
|
990
|
+
const home = path.join(routes, "index.tsx");
|
|
991
|
+
if (fs.existsSync(home)) write(home, routeTanstack("/", "..", v7Options(home, "/")), true);
|
|
992
|
+
dropAdmin(routes);
|
|
993
|
+
scopeQueryClient(root, report);
|
|
994
|
+
} else {
|
|
995
|
+
write(src("open-page.server.ts"), openPageNext(w));
|
|
996
|
+
const dir = appDir(root);
|
|
997
|
+
const existing = findCatchAll(dir);
|
|
998
|
+
const file = existing?.file ?? path.join(dir, "[[...slug]]", "page.tsx");
|
|
999
|
+
write(file, pageNext(w, file, root, existing?.param ?? "slug"), true);
|
|
1000
|
+
dropAdmin(dir);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (written.length + replaced.length > 0) {
|
|
1004
|
+
report.done.push({
|
|
1005
|
+
step: "scaffold",
|
|
1006
|
+
subject: "page setup",
|
|
1007
|
+
message: `${[...written, ...replaced].join(", ")}: the CMS, the page loader${framework === "tanstack" ? " (a server function that passes the page's URL, not /_serverFn's)" : ""} and the catch-all route, rendering through src/views.ts${w.loadSections ? ", running v7's section loaders" : ""}${w.device ? ", seeding useDevice with the server's device" : ""}`,
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
if (replaced.length > 0) {
|
|
1011
|
+
report.manual.push({
|
|
1012
|
+
step: "scaffold",
|
|
1013
|
+
subject: replaced.join(", "),
|
|
1014
|
+
message:
|
|
1015
|
+
framework === "tanstack"
|
|
1016
|
+
? "v7's page routes, replaced by the v8 page route with the options they passed cmsRouteConfig (titles, ignored search params, pending times) and cmsRouteConfig's search params, cache times and head: carry over what the site added around them (a not-found or pending component, a head or loader of its own, a wrapper such as a <main> landmark around the sections) from git. v7's default error page (CmsPageErrorFallback) is TanStack's own error component now"
|
|
1017
|
+
: "v7's catch-all page, replaced by the v8 page with v7's metadata and section wrapper: carry over what the site added to it (a not-found page, metadata of its own, a wrapper around the sections) from git",
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
if (deleted.length > 0) {
|
|
1021
|
+
report.done.push({
|
|
1022
|
+
step: "scaffold",
|
|
1023
|
+
subject: deleted.join(", "),
|
|
1024
|
+
message:
|
|
1025
|
+
"v7's admin routes (/deco/invoke, /deco/meta, /deco/render): deleted, v8 serves none of them",
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
if (kept.length > 0) {
|
|
1029
|
+
report.manual.push({
|
|
1030
|
+
step: "scaffold",
|
|
1031
|
+
subject: kept.join(", "),
|
|
1032
|
+
message: `already existed, so they were kept: check that they do what the generated page setup would (${framework === "tanstack" ? "/next/tanstack-start-descriptors" : "/next/nextjs"}): open the page at its own URL, run loadSections, and render through src/views.ts`,
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
if (framework === "tanstack" && (replaced.length > 0 || deleted.length > 0)) {
|
|
1036
|
+
report.manual.push({
|
|
1037
|
+
step: "scaffold",
|
|
1038
|
+
subject: "src/routeTree.gen.ts",
|
|
1039
|
+
message:
|
|
1040
|
+
"regenerate it (the router plugin does on vite dev or build) after the route changes",
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** The worker entry with the site-owned page cache that a TanStack site copies (the one copy). */
|
|
1046
|
+
export const WORKER_ENTRY_EXAMPLE =
|
|
1047
|
+
"https://github.com/decocms/blocks/blob/main/examples/tanstack-worker-smoke/src/worker-entry.ts";
|
|
1048
|
+
|
|
1049
|
+
/** Where each v7 `createDecoWorkerEntry` option goes, by hand. */
|
|
1050
|
+
const V7_WORKER_OPTIONS: Record<string, string> = {
|
|
1051
|
+
buildSegment: "the example's buildSegment (return loggedIn: true for a signed-in shopper)",
|
|
1052
|
+
csp: "createDecoWorker's csp ({ reportOnly: [...] } as v7 sent it by default)",
|
|
1053
|
+
securityHeaders: "createDecoWorker's csp",
|
|
1054
|
+
cspMode: "createDecoWorker's csp",
|
|
1055
|
+
proxyHandler: "createDecoWorker's routes",
|
|
1056
|
+
purgeTokenEnv: "the example's env.PURGE_TOKEN",
|
|
1057
|
+
admin: "nothing: the worker answers 404 on v7's admin paths",
|
|
1058
|
+
observability: "nothing: the worker records its own request metric",
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
/** The option names of the file's `createDecoWorkerEntry(serverEntry, { … })` call, or `undefined` with no call. */
|
|
1062
|
+
function v7WorkerOptions(text: string): string[] | undefined {
|
|
1063
|
+
const file = ts.createSourceFile("worker-entry.ts", text, ts.ScriptTarget.Latest, true);
|
|
1064
|
+
let found: string[] | undefined;
|
|
1065
|
+
const visit = (node: ts.Node) => {
|
|
1066
|
+
if (found) return;
|
|
1067
|
+
if (
|
|
1068
|
+
ts.isCallExpression(node) &&
|
|
1069
|
+
ts.isIdentifier(node.expression) &&
|
|
1070
|
+
node.expression.text === "createDecoWorkerEntry"
|
|
1071
|
+
) {
|
|
1072
|
+
const options = node.arguments[1];
|
|
1073
|
+
found = [];
|
|
1074
|
+
if (options && ts.isObjectLiteralExpression(options)) {
|
|
1075
|
+
for (const p of options.properties) {
|
|
1076
|
+
if (p.name && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name))) {
|
|
1077
|
+
found.push(p.name.text);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
node.forEachChild(visit);
|
|
1084
|
+
};
|
|
1085
|
+
visit(file);
|
|
1086
|
+
return found;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* TanStack Start: points the person at the example worker entry, which they
|
|
1091
|
+
* copy, and lists what the site's v7 `createDecoWorkerEntry` call configured,
|
|
1092
|
+
* to carry over by hand. The script writes no worker entry.
|
|
1093
|
+
*/
|
|
1094
|
+
export function reportWorkerEntry(root: string, report: Report): void {
|
|
1095
|
+
let rel = "src/worker-entry.ts";
|
|
1096
|
+
for (const name of ["wrangler.jsonc", "wrangler.json"]) {
|
|
1097
|
+
const file = path.join(root, name);
|
|
1098
|
+
if (!fs.existsSync(file)) continue;
|
|
1099
|
+
const main = fs.readFileSync(file, "utf8").match(/"main"\s*:\s*"([^"]+)"/)?.[1];
|
|
1100
|
+
if (main && /\.(ts|tsx|js|mjs)$/.test(main)) rel = path.posix.normalize(main);
|
|
1101
|
+
}
|
|
1102
|
+
const file = path.join(root, rel);
|
|
1103
|
+
const text = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
|
|
1104
|
+
// Already on v8 (a second run): nothing to copy.
|
|
1105
|
+
if (/\bcreateDecoWorker\s*\(/.test(text)) return;
|
|
1106
|
+
const options = v7WorkerOptions(text);
|
|
1107
|
+
const carry = (options ?? []).map(
|
|
1108
|
+
(name) => `${name} → ${V7_WORKER_OPTIONS[name] ?? "see the import map"}`,
|
|
1109
|
+
);
|
|
1110
|
+
const kept =
|
|
1111
|
+
text && options === undefined
|
|
1112
|
+
? ". The current file has no v7 createDecoWorkerEntry call: move what it still does into the copy by hand"
|
|
1113
|
+
: "";
|
|
1114
|
+
report.manual.push({
|
|
1115
|
+
step: "scaffold",
|
|
1116
|
+
subject: rel,
|
|
1117
|
+
message: `copy ${WORKER_ENTRY_EXAMPLE} here: createDecoWorker behind the site's own page cache (the Cache API, v7's cache profiles, v7's POST /_cache/purge with the PURGE_TOKEN secret), and declare __BUILD_HASH__ once (declare const __BUILD_HASH__: string;)${carry.length ? `. v7's createDecoWorkerEntry set, to carry over by hand from git: ${carry.join("; ")}` : ""}${kept}`,
|
|
1118
|
+
});
|
|
1119
|
+
}
|