@conloca/astro-cms 0.1.16 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -301
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/{src → ts/src}/cms-handler.js +11 -131
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +161 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +178 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/hydration.js +1 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +13 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +45 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.js +33 -15
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.js +13 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/withHydration.js +1 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/{src → ts/src}/loader.js +33 -4
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/{src → ts/src}/locales-helpers.js +1 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/{src → ts/src}/mime-types.js +1 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/{src → ts/src}/path-validation.js +1 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.js +301 -88
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +16 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +117 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/{src → ts/src}/types.d.ts +26 -110
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +12 -93
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +161 -73
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +11 -0
- package/src/cms-handler.ts +281 -0
- package/src/collections.ts +271 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +53 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
- package/src/loader.ts +145 -0
- package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1496 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +134 -0
- package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections-Bd7EME4b.mjs +0 -129
- package/dist/collections-Bd7EME4b.mjs.map +0 -1
- package/dist/collections.d.mts +0 -35
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -2
- package/dist/components.d.mts +0 -41
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -223
- package/dist/components.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -2
- package/dist/index.d.mts +0 -108
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -67
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -25
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -314
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts +0 -30
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -84
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
- package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
- package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -18
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.d.ts +0 -3
- package/dist/node/content.d.ts.map +0 -1
- package/dist/node/content.js +0 -2
- package/dist/node/content.mjs +0 -2
- package/dist/node/index.d.mts +0 -200
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts +0 -4
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.js +0 -3
- package/dist/node/index.mjs +0 -2513
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-BHoNpzH6.mjs +0 -72
- package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
- package/dist/src/cms-handler.d.ts.map +0 -1
- package/dist/src/collections.d.ts +0 -32
- package/dist/src/collections.d.ts.map +0 -1
- package/dist/src/collections.js +0 -50
- package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.js +0 -129
- package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
- package/dist/src/components.d.ts +0 -4
- package/dist/src/components.d.ts.map +0 -1
- package/dist/src/components.js +0 -3
- package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
- package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
- package/dist/src/discovery/merge-registry.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.d.ts +0 -42
- package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.js +0 -81
- package/dist/src/discovery/scan-components.d.ts.map +0 -1
- package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
- package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
- package/dist/src/hydration.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -25
- package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
- package/dist/src/lib/hydration-script.d.ts.map +0 -1
- package/dist/src/lib/hydration-utils.d.ts.map +0 -1
- package/dist/src/lib/page-api.d.ts +0 -77
- package/dist/src/lib/page-api.d.ts.map +0 -1
- package/dist/src/lib/page-api.js +0 -121
- package/dist/src/lib/route-utils.d.ts.map +0 -1
- package/dist/src/lib/routing-config.d.ts.map +0 -1
- package/dist/src/lib/serialize-props.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.js +0 -263
- package/dist/src/lib/withHydration.d.ts.map +0 -1
- package/dist/src/loader.d.ts +0 -14
- package/dist/src/loader.d.ts.map +0 -1
- package/dist/src/locales-helpers.d.ts.map +0 -1
- package/dist/src/mime-types.d.ts.map +0 -1
- package/dist/src/path-validation.d.ts.map +0 -1
- package/dist/src/plugin-spa.d.ts.map +0 -1
- package/dist/src/safe-json-stringify.d.ts.map +0 -1
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -1
- package/dist/types-CS9neadI.d.mts.map +0 -1
- package/dist/withHydration-C256ox_6.mjs +0 -49
- package/dist/withHydration-C256ox_6.mjs.map +0 -1
- package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
- /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
- /package/dist/{src → ts/src}/hydration.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
- /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
- /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
- /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
- /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
|
@@ -0,0 +1,1496 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import type { UIConfig } from '@conloca/cms-spa';
|
|
5
|
+
import { readSitesConfig } from '@conloca/content-api/node';
|
|
6
|
+
import viteReact from '@vitejs/plugin-react';
|
|
7
|
+
import type { AstroIntegration } from 'astro';
|
|
8
|
+
import { type HotPayload, type InferCustomEventPayload, type NormalizedHotChannel, searchForWorkspaceRoot } from 'vite';
|
|
9
|
+
import { deriveAssetRefBase } from './asset-ref-base.js';
|
|
10
|
+
import type { MdxRegistryScanOptions } from './discovery/discover.js';
|
|
11
|
+
import { createRegistryEndpoint } from './discovery/registry-endpoint.js';
|
|
12
|
+
import { EDITOR_DESCRIPTORS_ENV_VAR, type EditorDescriptorChannel } from './editor-descriptors.js';
|
|
13
|
+
import { CONTENT_CONFIG_SNIPPET, findContentConfigProblem } from './lib/content-config-guard.js';
|
|
14
|
+
import { deriveComponentPaths, type HydrationDiscovery, scanForHydratableComponents } from './lib/hydration-scanner.js';
|
|
15
|
+
import { resolveLocale } from './lib/resolve-locale.js';
|
|
16
|
+
import { resolveSiteName } from './lib/resolve-site-name.js';
|
|
17
|
+
import { normalizeRoutingConfig, resolveRouteConfig, toEditorDataBindings } from './lib/routing-config.js';
|
|
18
|
+
import type { ConlocaLocales } from './locales-helpers.js';
|
|
19
|
+
import { createComponentsEndpoint, endpointReaderOptions } from './puck-manifest/components-endpoint.js';
|
|
20
|
+
import { createContentWrapperEndpoint } from './site-styles/content-wrapper-endpoint.js';
|
|
21
|
+
import { createRenderEndpoint } from './site-styles/render-endpoint.js';
|
|
22
|
+
import { createStylesEndpoint } from './site-styles/styles-endpoint.js';
|
|
23
|
+
|
|
24
|
+
// FRAGILE: viteReact.preambleCode is an undocumented internal API of @vitejs/plugin-react.
|
|
25
|
+
// It provides the React Fast Refresh preamble script needed for HMR in virtual modules.
|
|
26
|
+
// If @vitejs/plugin-react removes or renames this property, the assertion below will
|
|
27
|
+
// fail immediately at dev startup. Test after any @vitejs/plugin-react update.
|
|
28
|
+
if (typeof viteReact.preambleCode !== 'string') {
|
|
29
|
+
throw new Error(
|
|
30
|
+
'@vitejs/plugin-react internal API changed: viteReact.preambleCode is no longer a string. ' +
|
|
31
|
+
'This is an undocumented API used by @conloca/astro-cms for React Fast Refresh in virtual modules. ' +
|
|
32
|
+
'Check @vitejs/plugin-react release notes and update the preamble injection logic.',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const reactRefreshPreamble = viteReact.preambleCode.replace('__BASE__', '/');
|
|
37
|
+
|
|
38
|
+
// The preamble is served as a module of its own rather than pasted into each
|
|
39
|
+
// dev virtual module below. A module's static imports all evaluate before its
|
|
40
|
+
// own body runs, so inlined preamble statements always lose to the cms-spa
|
|
41
|
+
// import underneath them — and cms-spa's built entries are plain `.js`, which
|
|
42
|
+
// Vite's React plugin rewrites with Fast Refresh, throwing on evaluation while
|
|
43
|
+
// `window.$RefreshReg$` is still unset. Imported first, the preamble wins.
|
|
44
|
+
const VIRTUAL_REFRESH_PREAMBLE = 'virtual:conloca-react-refresh-preamble';
|
|
45
|
+
const RESOLVED_REFRESH_PREAMBLE = `\0${VIRTUAL_REFRESH_PREAMBLE}`;
|
|
46
|
+
|
|
47
|
+
// Get the directory of this module to resolve the copied handler assets.
|
|
48
|
+
// Compiled, this file sits in dist/ts/src/, the copied Astro handler in
|
|
49
|
+
// dist/internal/, and the emitted handler modules right next to this file.
|
|
50
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
51
|
+
const PAGE_HANDLER_PATH = join(__dirname, '..', '..', 'internal', 'page-handler.astro');
|
|
52
|
+
const CMS_HANDLER_PATH = join(__dirname, 'cms-handler.js');
|
|
53
|
+
const SANDBOX_FRAME_HANDLER_PATH = join(__dirname, 'sandbox-frame-handler.js');
|
|
54
|
+
const ACORN_DEFAULT_SHIM_PATH = join(__dirname, '..', '..', 'internal', 'acorn-default.mjs');
|
|
55
|
+
const TIPTAP_HTML_SHIM_PATH = join(__dirname, 'tiptap-html-static.js');
|
|
56
|
+
|
|
57
|
+
import {
|
|
58
|
+
generateLayoutModule,
|
|
59
|
+
generatePuckConfigModule,
|
|
60
|
+
generateRoutingConfigModule,
|
|
61
|
+
} from './lib/virtual-module-generators.js';
|
|
62
|
+
import type { EditorDataBindings, ResolvedRoutingConfig, RoutingConfigInput, TemplateConfig } from './types.js';
|
|
63
|
+
|
|
64
|
+
// Virtual module for passing config from plugin to route handler
|
|
65
|
+
const VIRTUAL_CONFIG_MODULE = 'virtual:conloca-config';
|
|
66
|
+
const RESOLVED_VIRTUAL_CONFIG = `\0${VIRTUAL_CONFIG_MODULE}`;
|
|
67
|
+
|
|
68
|
+
// Virtual module IDs for routing system
|
|
69
|
+
const VIRTUAL_ROUTING_CONFIG = 'virtual:conloca-routing-config';
|
|
70
|
+
const VIRTUAL_LAYOUT = 'virtual:conloca-layout';
|
|
71
|
+
const VIRTUAL_PUCK_CONFIG = 'virtual:conloca-puck-config';
|
|
72
|
+
|
|
73
|
+
// Resolved IDs (with \0 prefix to prevent file resolution)
|
|
74
|
+
const RESOLVED_ROUTING_CONFIG = `\0${VIRTUAL_ROUTING_CONFIG}`;
|
|
75
|
+
const RESOLVED_LAYOUT = `\0${VIRTUAL_LAYOUT}`;
|
|
76
|
+
const RESOLVED_PUCK_CONFIG = `\0${VIRTUAL_PUCK_CONFIG}`;
|
|
77
|
+
|
|
78
|
+
// Virtual modules for hydration system
|
|
79
|
+
const VIRTUAL_HYDRATION_REGISTRY = 'virtual:conloca-hydration-registry';
|
|
80
|
+
const VIRTUAL_HYDRATION_ENTRY = 'virtual:conloca-hydration-entry';
|
|
81
|
+
const RESOLVED_HYDRATION_REGISTRY = `\0${VIRTUAL_HYDRATION_REGISTRY}`;
|
|
82
|
+
const RESOLVED_HYDRATION_ENTRY = `\0${VIRTUAL_HYDRATION_ENTRY}`;
|
|
83
|
+
|
|
84
|
+
/** Vite payloads whose browser-side effects would overwrite the editor's own save update. */
|
|
85
|
+
function dropsEditorSaveUpdate(payload: HotPayload): boolean {
|
|
86
|
+
if (payload.type === 'full-reload') return true;
|
|
87
|
+
return payload.type === 'custom' && payload.event === 'conloca:content-update';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Virtual module for CMS SPA source loading (dev only)
|
|
91
|
+
const VIRTUAL_CMS_SPA_ENTRY = 'virtual:conloca-cms-spa-entry';
|
|
92
|
+
const RESOLVED_CMS_SPA_ENTRY = `\0${VIRTUAL_CMS_SPA_ENTRY}`;
|
|
93
|
+
|
|
94
|
+
async function loadContentApiNode() {
|
|
95
|
+
return import('@conloca/content-api/node');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ConlocaCMSOptions extends Omit<UIConfig, 'basename'> {
|
|
99
|
+
/**
|
|
100
|
+
* Path to the content root directory. The single source of truth: the
|
|
101
|
+
* integration publishes it (via process.env.CONLOCA_CONTENT_ROOT) to
|
|
102
|
+
* createConlocaCollections(), so the content config needs no copy.
|
|
103
|
+
*/
|
|
104
|
+
contentRoot: string;
|
|
105
|
+
canvasDir?: string;
|
|
106
|
+
route?: string; // Default: /__cms
|
|
107
|
+
puckConfigPath: string; // Path to the puck config module (should be .tsx file with React components)
|
|
108
|
+
schemasPath?: string; // Path to the schemas module (exports { dataSchemas, pageSchemas, mdxComponents })
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Default layout for content pages.
|
|
112
|
+
* When provided without routing config, enables routing with catch-all pattern.
|
|
113
|
+
* For multi-route setups, use routing.routes.{name}.layout instead.
|
|
114
|
+
*
|
|
115
|
+
* @example './src/layouts/Layout.astro'
|
|
116
|
+
*/
|
|
117
|
+
layout?: string;
|
|
118
|
+
|
|
119
|
+
routing?: RoutingConfigInput; // Content page routing configuration
|
|
120
|
+
templates?: Record<string, TemplateConfig>; // Page creation templates
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Paths to scan for hydratable components.
|
|
124
|
+
* Components using withHydration() in these directories are auto-discovered.
|
|
125
|
+
*
|
|
126
|
+
* @example ['src/components/puck']
|
|
127
|
+
*/
|
|
128
|
+
componentPaths?: string[];
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Folders to scan for locally-authored MDX components. Their
|
|
132
|
+
* `interface Props { ... }` is parsed into the editor's prop
|
|
133
|
+
* panel automatically — no hand-written descriptors needed.
|
|
134
|
+
*
|
|
135
|
+
* Combined with the MDX usage scan (which picks up imports from
|
|
136
|
+
* npm packages like `@astrojs/starlight/components`), this powers
|
|
137
|
+
* the auto-discover registry served at `/__cms/api/registry`.
|
|
138
|
+
*
|
|
139
|
+
* Paths are project-relative. Defaults to `['src/components/mdx']`.
|
|
140
|
+
*
|
|
141
|
+
* @example ['src/components/mdx', 'src/components/prose']
|
|
142
|
+
*/
|
|
143
|
+
mdxComponentFolders?: string[];
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Path to the assets directory for image uploads.
|
|
147
|
+
* When provided, enables the Media Library and asset upload API routes.
|
|
148
|
+
* The editor stores links under the public URL derived from this folder.
|
|
149
|
+
* The site must serve the folder from its publicDir, directly or through a link, or dev and build fail.
|
|
150
|
+
|
|
151
|
+
*
|
|
152
|
+
* @example './public/assets'
|
|
153
|
+
*/
|
|
154
|
+
assetsPath?: string;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* CSS files to load in the CMS editor for component preview styling.
|
|
158
|
+
*
|
|
159
|
+
* Each file is processed by Vite (Tailwind, PostCSS, etc.) and injected
|
|
160
|
+
* directly into Puck's preview iframe `<head>`. Site CSS never enters the
|
|
161
|
+
* CMS admin's parent document, so host-site styles cannot bleed into the
|
|
162
|
+
* CMS chrome (drawer, sidebar, etc.).
|
|
163
|
+
*
|
|
164
|
+
* @example './src/styles/global.css'
|
|
165
|
+
* @example ['./src/styles/global.css', './src/styles/theme.css']
|
|
166
|
+
*/
|
|
167
|
+
siteStyles?: string | string[];
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Narrow CSS path injected into the MDX editor's admin document while the
|
|
171
|
+
* editor is mounted. Use this to ship host-component styling
|
|
172
|
+
* (`.conloca-aside`, `.conloca-card`, etc.) so the editor preview matches
|
|
173
|
+
* the published surface, WITHOUT pulling in host Tailwind utilities or
|
|
174
|
+
* `:root` token overrides that would collide with admin chrome.
|
|
175
|
+
*
|
|
176
|
+
* What belongs here: stylesheets that target only host-component class
|
|
177
|
+
* selectors. Examples: `./src/styles/asides.css`,
|
|
178
|
+
* `./src/styles/starlight-components.css`, `./src/styles/code-blocks.css`.
|
|
179
|
+
*
|
|
180
|
+
* What does NOT belong: the host's `global.css` (Tailwind base, theme,
|
|
181
|
+
* utilities) or any
|
|
182
|
+
* stylesheet with `body`, `:root`, or `*` rules that would override
|
|
183
|
+
* admin chrome. Those go in `siteStyles` instead — that path is only
|
|
184
|
+
* injected into the Puck iframe, never the admin shell.
|
|
185
|
+
*
|
|
186
|
+
* @example ['./src/styles/asides.css', './src/styles/starlight-components.css']
|
|
187
|
+
*/
|
|
188
|
+
editorStyles?: string | string[];
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Route URL whose styles + content-wrapper shape get applied when
|
|
192
|
+
* editing a standalone FRAGMENT (not a page). Fragments aren't tied to a
|
|
193
|
+
* specific route, but they're consumed inside pages — so the
|
|
194
|
+
* authoring experience should look like the user's actual site. The
|
|
195
|
+
* editor fetches this route's CSS (via `/api/styles?url=…`) and its
|
|
196
|
+
* content-root wrapper (via `/api/content-wrapper?url=…`) the same
|
|
197
|
+
* way it does for pages, then renders the fragment inside that frame.
|
|
198
|
+
*
|
|
199
|
+
* Pick a representative content page on your site — typically the
|
|
200
|
+
* site root or a docs landing page. Hosts that ship rich typography
|
|
201
|
+
* benefit most; for hosts whose body bg matches the editor chrome,
|
|
202
|
+
* the value barely matters. Defaults to `/` (site root).
|
|
203
|
+
*
|
|
204
|
+
* Per-fragment overrides via fragment frontmatter remain on the roadmap
|
|
205
|
+
* for cases where one fragment ships only inside a specific layout.
|
|
206
|
+
*
|
|
207
|
+
* @example '/getting-started/'
|
|
208
|
+
*/
|
|
209
|
+
fragmentPreviewRoute?: string;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Inline CSS to inject into the editor's `conloca-host-preview`
|
|
213
|
+
* layer, applied AFTER auto-discovered host stylesheets. The
|
|
214
|
+
* editor's content surround, prose card, and individual MDX
|
|
215
|
+
* components all surface here; anything you write at this layer
|
|
216
|
+
* wins on cascade order against the auto-discovery output (same
|
|
217
|
+
* specificity, later layer position).
|
|
218
|
+
*
|
|
219
|
+
* Use for one-off overrides when:
|
|
220
|
+
* - Your host body bg doesn't read well behind the editor chrome
|
|
221
|
+
* and you want a specific color regardless.
|
|
222
|
+
* - You want a different prose surface only inside the editor
|
|
223
|
+
* (eg lighter for accessibility while authoring).
|
|
224
|
+
* - A component renders correctly on the published page but
|
|
225
|
+
* needs a small visual tweak in the editor — toolbar gutter,
|
|
226
|
+
* focus ring, etc.
|
|
227
|
+
*
|
|
228
|
+
* Pure raw CSS. Conloca does no scoping or transformation, so any
|
|
229
|
+
* selector you write needs to be specific enough not to leak into
|
|
230
|
+
* the admin chrome (the chrome's selectors live in the `cms-admin`
|
|
231
|
+
* layer, which sits LOWER in the cascade — so without explicitly
|
|
232
|
+
* naming admin selectors, your CSS only reaches host components
|
|
233
|
+
* and the content surround).
|
|
234
|
+
*
|
|
235
|
+
* @example `
|
|
236
|
+
* /* Force a darker editor body even though the live page is light. *\/
|
|
237
|
+
* body { background-color: #0a0a0f; }
|
|
238
|
+
* /* Custom focus ring for the prose surface. *\/
|
|
239
|
+
* .conloca-prose--editor:focus-within { outline: 2px solid hotpink; }
|
|
240
|
+
* `
|
|
241
|
+
*/
|
|
242
|
+
editorCSS?: string;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The site's supported locales and default locale.
|
|
246
|
+
*
|
|
247
|
+
* When set, Conloca uses this list as the single source of truth for
|
|
248
|
+
* locale detection — folders or filename suffixes that don't match
|
|
249
|
+
* one of these locales are left in the slug rather than silently
|
|
250
|
+
* classified as a language. When omitted, falls back to the
|
|
251
|
+
* `globalLocales` field in `<contentRoot>/sites.json` (the existing
|
|
252
|
+
* behavior; preserved for backwards compatibility).
|
|
253
|
+
*
|
|
254
|
+
* Use one of the framework-bridge helpers exported from
|
|
255
|
+
* `@conloca/astro-cms/node` to keep the declaration in a single spot:
|
|
256
|
+
*
|
|
257
|
+
* @example Pass Astro's i18n config directly:
|
|
258
|
+
* ```ts
|
|
259
|
+
* import { conlocaCMS, localesFromAstroI18n } from '@conloca/astro-cms/node';
|
|
260
|
+
* const i18n = { defaultLocale: 'en', locales: ['en', 'de'] };
|
|
261
|
+
* defineConfig({
|
|
262
|
+
* i18n,
|
|
263
|
+
* integrations: [conlocaCMS({ locales: localesFromAstroI18n(i18n) })],
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @example Pass a literal list:
|
|
268
|
+
* ```ts
|
|
269
|
+
* conlocaCMS({ locales: { list: ['en', 'de'], defaultLocale: 'en' } });
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
locales?: ConlocaLocales;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Template for content change listener virtual module
|
|
276
|
+
const contentChangeListener = () => {
|
|
277
|
+
return `
|
|
278
|
+
// Content change listener that uses Vite HMR
|
|
279
|
+
if (import.meta.hot) {
|
|
280
|
+
import.meta.hot.on('conloca:content-update', (data) => {
|
|
281
|
+
console.log('[Conloca CMS] Content updated, invalidating cache:', data);
|
|
282
|
+
|
|
283
|
+
// Get the query client from the global scope and invalidate
|
|
284
|
+
if (window.__QUERY_CLIENT__) {
|
|
285
|
+
window.__QUERY_CLIENT__.invalidateQueries();
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export default {};
|
|
291
|
+
`;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// Template for the puck config loader virtual module
|
|
295
|
+
const puckConfigLoader = (absolutePuckPath: string, cmsSpaDistDir?: string) => {
|
|
296
|
+
// We need to ensure the preamble executes before ANY module evaluation
|
|
297
|
+
// So we'll use a dynamic import after the preamble is set up
|
|
298
|
+
const puckConfigImport = cmsSpaDistDir ? `${cmsSpaDistDir}/ts/puck-config.js` : '@conloca/cms-spa/puck-config';
|
|
299
|
+
return `
|
|
300
|
+
// React refresh preamble first — it must be the first import, see its module
|
|
301
|
+
import '${VIRTUAL_REFRESH_PREAMBLE}';
|
|
302
|
+
|
|
303
|
+
// Import the setPuckConfig function from cms-spa
|
|
304
|
+
import { setPuckConfig } from '${puckConfigImport}';
|
|
305
|
+
|
|
306
|
+
// Now dynamically import the config after preamble is ready
|
|
307
|
+
const puckConfigPromise = import('${absolutePuckPath}');
|
|
308
|
+
|
|
309
|
+
// Handle the initial load
|
|
310
|
+
puckConfigPromise.then(module => {
|
|
311
|
+
const puckConfig = module.default;
|
|
312
|
+
setPuckConfig(puckConfig);
|
|
313
|
+
|
|
314
|
+
// Hook into React Fast Refresh to detect component updates
|
|
315
|
+
if (window.__registerBeforePerformReactRefresh) {
|
|
316
|
+
window.__registerBeforePerformReactRefresh(async () => {
|
|
317
|
+
// Re-import the config module to get updated components
|
|
318
|
+
const newModule = await import('${absolutePuckPath}');
|
|
319
|
+
setPuckConfig(newModule.default);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Accept HMR for this module itself
|
|
325
|
+
if (import.meta.hot) {
|
|
326
|
+
import.meta.hot.accept();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Export the promise so the module has a default export
|
|
330
|
+
export default puckConfigPromise.then(m => m.default);
|
|
331
|
+
`;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// Template for the schemas loader virtual module
|
|
335
|
+
const schemasLoader = (absoluteSchemasPath: string, cmsSpaDistDir?: string) => {
|
|
336
|
+
const pageSchemasImport = cmsSpaDistDir ? `${cmsSpaDistDir}/ts/page-schemas.js` : '@conloca/cms-spa/page-schemas';
|
|
337
|
+
const mdxComponentsImport = cmsSpaDistDir
|
|
338
|
+
? `${cmsSpaDistDir}/ts/mdx-components.js`
|
|
339
|
+
: '@conloca/cms-spa/mdx-components';
|
|
340
|
+
const dataSchemasImport = cmsSpaDistDir ? `${cmsSpaDistDir}/ts/data-schemas.js` : '@conloca/cms-spa/data-schemas';
|
|
341
|
+
// The host's schemas file may transitively import React components (the
|
|
342
|
+
// `Editor` field on an MdxComponentDescriptor can be a JSX/TSX
|
|
343
|
+
// component), and so does cms-spa's own mdx-components entry. Vite's React
|
|
344
|
+
// plugin requires the Fast Refresh preamble to run before any such module
|
|
345
|
+
// is evaluated, so we import it first and then dynamically import the
|
|
346
|
+
// schemas file — matching the pattern used by the Puck config loader above.
|
|
347
|
+
return `
|
|
348
|
+
import '${VIRTUAL_REFRESH_PREAMBLE}';
|
|
349
|
+
|
|
350
|
+
import { setPageSchemas } from '${pageSchemasImport}';
|
|
351
|
+
import { installHostAuthoredMdxComponents } from '${mdxComponentsImport}';
|
|
352
|
+
import { setDataSchemas } from '${dataSchemasImport}';
|
|
353
|
+
|
|
354
|
+
const schemasPromise = import('${absoluteSchemasPath}');
|
|
355
|
+
|
|
356
|
+
schemasPromise.then((schemas) => {
|
|
357
|
+
if (schemas.pageSchemas) {
|
|
358
|
+
setPageSchemas(schemas.pageSchemas);
|
|
359
|
+
}
|
|
360
|
+
if (schemas.mdxComponents) {
|
|
361
|
+
// Slotted installer, not setMdxComponents: this module and the SPA's
|
|
362
|
+
// /api/registry fetch settle in either order, and a bare set from the
|
|
363
|
+
// late one would overwrite the other's components.
|
|
364
|
+
installHostAuthoredMdxComponents(schemas.mdxComponents);
|
|
365
|
+
}
|
|
366
|
+
if (schemas.dataSchemas) {
|
|
367
|
+
setDataSchemas(schemas.dataSchemas);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
if (import.meta.hot) {
|
|
372
|
+
import.meta.hot.accept('${absoluteSchemasPath}', async (newModule) => {
|
|
373
|
+
if (newModule?.pageSchemas) {
|
|
374
|
+
setPageSchemas(newModule.pageSchemas);
|
|
375
|
+
}
|
|
376
|
+
if (newModule?.mdxComponents) {
|
|
377
|
+
installHostAuthoredMdxComponents(newModule.mdxComponents);
|
|
378
|
+
}
|
|
379
|
+
if (newModule?.dataSchemas) {
|
|
380
|
+
setDataSchemas(newModule.dataSchemas);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export default schemasPromise;
|
|
386
|
+
`;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// Template for the site styles loader virtual module.
|
|
390
|
+
//
|
|
391
|
+
// Each CSS file is imported with Vite's `?inline` query so the full CSS
|
|
392
|
+
// pipeline (Tailwind, PostCSS, etc.) runs and returns the processed stylesheet
|
|
393
|
+
// as a string — no `<style>` tag is injected into the CMS admin's parent
|
|
394
|
+
// `<head>`. The strings are handed to `@conloca/cms-spa`'s site-styles
|
|
395
|
+
// registry; the editor's iframe bridge then injects them directly into
|
|
396
|
+
// Puck's preview iframe `<head>`. This keeps host-site CSS out of the CMS
|
|
397
|
+
// chrome and confines it to the intended consumer (the preview).
|
|
398
|
+
const siteStylesLoader = (cssPaths: string[], cmsSpaDistDir?: string) => {
|
|
399
|
+
const imports = cssPaths
|
|
400
|
+
.map((p, i) => {
|
|
401
|
+
const absolutePath = p.startsWith('./') ? `/${p.slice(2)}` : p;
|
|
402
|
+
return `import css${i} from '${absolutePath}?inline';`;
|
|
403
|
+
})
|
|
404
|
+
.join('\n');
|
|
405
|
+
const vars = cssPaths.map((_, i) => `css${i}`).join(', ');
|
|
406
|
+
const siteStylesImport = cmsSpaDistDir ? `${cmsSpaDistDir}/ts/site-styles.js` : '@conloca/cms-spa/site-styles';
|
|
407
|
+
|
|
408
|
+
return `
|
|
409
|
+
import '${VIRTUAL_REFRESH_PREAMBLE}';
|
|
410
|
+
${imports}
|
|
411
|
+
import { setSiteStyles } from '${siteStylesImport}';
|
|
412
|
+
|
|
413
|
+
setSiteStyles([${vars}]);
|
|
414
|
+
|
|
415
|
+
if (import.meta.hot) {
|
|
416
|
+
import.meta.hot.accept();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export default {};
|
|
420
|
+
`;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// Template for the editor styles loader virtual module — same shape as
|
|
424
|
+
// siteStylesLoader but feeds a different registry (`setEditorStyles`),
|
|
425
|
+
// consumed by the MDX editor's `useInjectHostStyles` call. Kept separate
|
|
426
|
+
// from `siteStyles` because the two surfaces have opposite cascade needs;
|
|
427
|
+
// see `packages/cms-spa/src/site-styles.ts` for the rationale.
|
|
428
|
+
const editorStylesLoader = (cssPaths: string[], cmsSpaDistDir?: string) => {
|
|
429
|
+
const imports = cssPaths
|
|
430
|
+
.map((p, i) => {
|
|
431
|
+
const absolutePath = p.startsWith('./') ? `/${p.slice(2)}` : p;
|
|
432
|
+
return `import css${i} from '${absolutePath}?inline';`;
|
|
433
|
+
})
|
|
434
|
+
.join('\n');
|
|
435
|
+
const vars = cssPaths.map((_, i) => `css${i}`).join(', ');
|
|
436
|
+
const siteStylesImport = cmsSpaDistDir ? `${cmsSpaDistDir}/ts/site-styles.js` : '@conloca/cms-spa/site-styles';
|
|
437
|
+
|
|
438
|
+
return `
|
|
439
|
+
import '${VIRTUAL_REFRESH_PREAMBLE}';
|
|
440
|
+
${imports}
|
|
441
|
+
import { setEditorStyles } from '${siteStylesImport}';
|
|
442
|
+
|
|
443
|
+
setEditorStyles([${vars}]);
|
|
444
|
+
|
|
445
|
+
if (import.meta.hot) {
|
|
446
|
+
import.meta.hot.accept();
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export default {};
|
|
450
|
+
`;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Whether a resolved package directory came from the registry rather than from
|
|
455
|
+
* a workspace. @conloca/cms-spa ships its sources so source maps resolve, so
|
|
456
|
+
* the files on disk no longer tell the two apart — the location does. Node
|
|
457
|
+
* resolves symlinks, so a registry install always sits under a node_modules
|
|
458
|
+
* directory (hoisted `<consumer>/node_modules/@conloca/cms-spa`, or isolated
|
|
459
|
+
* `…/node_modules/.bun/…/node_modules/@conloca/cms-spa`), while a workspace
|
|
460
|
+
* package or a cross-repo `bun link` resolves to its own checkout.
|
|
461
|
+
*/
|
|
462
|
+
export function isRegistryInstall(packageDir: string): boolean {
|
|
463
|
+
return packageDir.split(/[\\/]/).includes('node_modules');
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export function conlocaCMS(options: ConlocaCMSOptions): AstroIntegration {
|
|
467
|
+
const cmsRoute = options.route || '/__cms';
|
|
468
|
+
|
|
469
|
+
// Resolve @conloca/cms-spa package directory for absolute imports in virtual
|
|
470
|
+
// module templates. Bare specifiers like '@conloca/cms-spa/puck-config'
|
|
471
|
+
// resolve from the Vite project root, which works when deps are hoisted
|
|
472
|
+
// (npm consumers) but fails with isolated linkers (e.g. bun). Using the
|
|
473
|
+
// resolved absolute path bypasses the project-root lookup entirely.
|
|
474
|
+
let cmsSpaDir: string | undefined;
|
|
475
|
+
try {
|
|
476
|
+
const pkgUrl = import.meta.resolve('@conloca/cms-spa/package.json');
|
|
477
|
+
cmsSpaDir = dirname(pkgUrl.startsWith('file://') ? fileURLToPath(pkgUrl) : pkgUrl);
|
|
478
|
+
} catch {
|
|
479
|
+
// Package not resolvable — virtual modules will fall back to bare specifiers
|
|
480
|
+
}
|
|
481
|
+
const cmsSpaDistDir = cmsSpaDir ? join(cmsSpaDir, 'dist') : undefined;
|
|
482
|
+
|
|
483
|
+
// Normalize routing config and resolve defaults
|
|
484
|
+
// Pass top-level layout to enable routing when layout provided without explicit routing config
|
|
485
|
+
const routingConfig = normalizeRoutingConfig(options.routing, options.layout);
|
|
486
|
+
|
|
487
|
+
// Always derive component paths - auto-discover from puckConfigPath + extend with explicit paths
|
|
488
|
+
// Scanner handles missing directories gracefully (fast-glob returns empty array)
|
|
489
|
+
const componentPaths = deriveComponentPaths(options.puckConfigPath, options.componentPaths);
|
|
490
|
+
|
|
491
|
+
// Scan for hydratable components - this promise is awaited in the virtual module loader
|
|
492
|
+
const hydrationDiscoveriesPromise: Promise<HydrationDiscovery[]> = scanForHydratableComponents(
|
|
493
|
+
componentPaths,
|
|
494
|
+
process.cwd(),
|
|
495
|
+
).then((discoveries) => {
|
|
496
|
+
if (discoveries.length > 0) {
|
|
497
|
+
console.log(`[Conloca] Found ${discoveries.length} hydratable component(s)`);
|
|
498
|
+
}
|
|
499
|
+
return discoveries;
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// Build resolved routing config with all defaults applied
|
|
503
|
+
let resolvedRoutingConfig: ResolvedRoutingConfig | undefined;
|
|
504
|
+
// The site's final output mode, read at config:done because integrations
|
|
505
|
+
// that run after this one may still switch it. The duplicate-route-name check
|
|
506
|
+
// below keys on it.
|
|
507
|
+
let outputMode: 'static' | 'server' | undefined;
|
|
508
|
+
if (routingConfig?.enabled !== false && routingConfig) {
|
|
509
|
+
const resolvedRoutes: Record<string, Required<import('./types.js').RouteConfig>> = {};
|
|
510
|
+
for (const [name, config] of Object.entries(routingConfig.routes || {})) {
|
|
511
|
+
resolvedRoutes[name] = resolveRouteConfig(config);
|
|
512
|
+
}
|
|
513
|
+
resolvedRoutingConfig = {
|
|
514
|
+
enabled: routingConfig.enabled ?? true,
|
|
515
|
+
routes: resolvedRoutes,
|
|
516
|
+
fallback: routingConfig.fallback ?? '404',
|
|
517
|
+
onConflict: routingConfig.onConflict ?? 'warn',
|
|
518
|
+
// Both provisional. sites.json cannot be read here — integration
|
|
519
|
+
// construction is synchronous — so `astro:config:setup` below
|
|
520
|
+
// re-resolves them against the declared sites before any consumer
|
|
521
|
+
// loads. See `resolveSiteName` and `resolveLocale`.
|
|
522
|
+
siteName: routingConfig.siteName ?? 'default',
|
|
523
|
+
locale: routingConfig.locale ?? 'en',
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// SPA config passed to route handler via virtual module
|
|
528
|
+
// This is only served in dev mode (CMS admin is dev-only), so enableDevtools defaults to true
|
|
529
|
+
// `mdxPagesEnabled` and `resolvedMdxPages` start uninitialized; the
|
|
530
|
+
// `astro:config:setup` hook reads sites.json (the canonical home for
|
|
531
|
+
// per-site `mdxPages` paths) and mutates them before any virtual
|
|
532
|
+
// module load fires — `load(id)` runs at request time, after the
|
|
533
|
+
// hook completes.
|
|
534
|
+
const spaConfig: {
|
|
535
|
+
basename: string;
|
|
536
|
+
apiBaseUrl: string;
|
|
537
|
+
siteBaseUrl?: string;
|
|
538
|
+
enableDevtools: boolean;
|
|
539
|
+
queryClientOptions: unknown;
|
|
540
|
+
schemasPath?: string;
|
|
541
|
+
projectRoot: string;
|
|
542
|
+
templates?: unknown;
|
|
543
|
+
mdxPagesEnabled: boolean;
|
|
544
|
+
locales?: { list: string[]; defaultLocale: string };
|
|
545
|
+
assetsBasePath: string;
|
|
546
|
+
assetRefBase?: string;
|
|
547
|
+
dataBindings?: EditorDataBindings;
|
|
548
|
+
} = {
|
|
549
|
+
basename: cmsRoute,
|
|
550
|
+
apiBaseUrl: `${cmsRoute}/api`,
|
|
551
|
+
// The media surfaces' thumbnails, served by the content API under the
|
|
552
|
+
// same route; the editor's own default only covers a CMS at /__cms.
|
|
553
|
+
assetsBasePath: `${cmsRoute}/api/assets/serve`,
|
|
554
|
+
siteBaseUrl: options.siteBaseUrl,
|
|
555
|
+
enableDevtools: options.enableDevtools ?? true,
|
|
556
|
+
queryClientOptions: options.queryClientOptions,
|
|
557
|
+
schemasPath: options.schemasPath,
|
|
558
|
+
projectRoot: process.cwd(),
|
|
559
|
+
templates: options.templates,
|
|
560
|
+
// True when at least one site in sites.json declares an `mdxPages`
|
|
561
|
+
// path. Drives the "Document page" option in the create-page dialog.
|
|
562
|
+
// Initialized in the `astro:config:setup` hook below.
|
|
563
|
+
mdxPagesEnabled: false,
|
|
564
|
+
// Forward the locale list so the SPA stops hardcoding en/nl/fr in
|
|
565
|
+
// the create-page dialog. The integration receives this from the
|
|
566
|
+
// top-level `locales` option, which can in turn be produced by
|
|
567
|
+
// `localesFromAstroI18n` / `localesFromStarlight`; without it the
|
|
568
|
+
// `astro:config:setup` hook fills it from sites.json.
|
|
569
|
+
locales: options.locales ? { list: options.locales.list, defaultLocale: options.locales.defaultLocale } : undefined,
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// Resolved mdxPages path, populated from sites.json in the
|
|
573
|
+
// config:setup hook. Used by the registry endpoint and content
|
|
574
|
+
// watcher. `null` means no site declares an `mdxPages` path — .mdx
|
|
575
|
+
// files (if any) fall back to living alongside Puck pages.
|
|
576
|
+
let resolvedMdxPages: string | null = null;
|
|
577
|
+
|
|
578
|
+
// One root for every path this plugin resolves against, so a scan and an
|
|
579
|
+
// endpoint can never disagree about where the project is.
|
|
580
|
+
const projectRoot = process.cwd();
|
|
581
|
+
|
|
582
|
+
// Registry scan inputs, resolved ONCE: the dev endpoint below and anything
|
|
583
|
+
// that reads them off the descriptor channel must never disagree about which
|
|
584
|
+
// folders and content root were scanned.
|
|
585
|
+
// `contentRoot` is re-pointed at sites.json's `mdxPages` in config:setup,
|
|
586
|
+
// once that file has been read.
|
|
587
|
+
let registryScan: MdxRegistryScanOptions = {
|
|
588
|
+
contentRoot: options.contentRoot,
|
|
589
|
+
componentFolders: options.mdxComponentFolders ?? ['src/components/mdx'],
|
|
590
|
+
projectRoot,
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
let refreshConlocaContent: (() => Promise<void>) | undefined;
|
|
594
|
+
|
|
595
|
+
return {
|
|
596
|
+
name: '@conloca/astro-cms',
|
|
597
|
+
hooks: {
|
|
598
|
+
'astro:config:setup': async ({ config, updateConfig, injectRoute, command, logger }) => {
|
|
599
|
+
// Publish the content root for createConlocaCollections(): the
|
|
600
|
+
// content config loads later in this same process, so the contentRoot
|
|
601
|
+
// configured here is the single source of truth. Raw on purpose —
|
|
602
|
+
// FileSystemContentAPI keys its process-wide index cache on the
|
|
603
|
+
// string as-passed, and the dev content watcher uses the raw option;
|
|
604
|
+
// resolving here would split one cache into two and dev refreshes
|
|
605
|
+
// would read stale content.
|
|
606
|
+
process.env.CONLOCA_CONTENT_ROOT = options.contentRoot;
|
|
607
|
+
// Read sites.json — the canonical home for per-site config
|
|
608
|
+
// including the optional `mdxPages` field. Reading it here (once,
|
|
609
|
+
// at integration setup) gives us a single source of truth for
|
|
610
|
+
// the rest of the hook. `readSitesConfig` returns a safe default
|
|
611
|
+
// when the file is missing or malformed.
|
|
612
|
+
const sitesConfig = await readSitesConfig(options.contentRoot);
|
|
613
|
+
// Now that sites.json is known, replace the provisional site name and
|
|
614
|
+
// locale built at construction time. Resolving from the raw options
|
|
615
|
+
// (not the already-defaulted resolved config) is what makes the
|
|
616
|
+
// sites.json fallbacks reachable. Every consumer — the routing
|
|
617
|
+
// virtual module, the editor's data bindings below, and
|
|
618
|
+
// `astro:routes:resolved` — reads them after this, so they all
|
|
619
|
+
// observe the resolved values.
|
|
620
|
+
const siteName = resolveSiteName(routingConfig?.siteName, sitesConfig.sites);
|
|
621
|
+
const locale = resolveLocale(routingConfig?.locale, options.locales?.defaultLocale, siteName, sitesConfig);
|
|
622
|
+
if (resolvedRoutingConfig) {
|
|
623
|
+
resolvedRoutingConfig.siteName = siteName;
|
|
624
|
+
resolvedRoutingConfig.locale = locale;
|
|
625
|
+
}
|
|
626
|
+
// Without the `locales` option the editor offers the site's own
|
|
627
|
+
// languages from sites.json — the list the server checks a new page
|
|
628
|
+
// against — starting from the locale the site renders. Left unset, the
|
|
629
|
+
// editor guessed English: a site in any other language could not
|
|
630
|
+
// create a page, and its new fragments were never rendered.
|
|
631
|
+
if (!options.locales) {
|
|
632
|
+
spaConfig.locales = {
|
|
633
|
+
list: sitesConfig.sites[siteName]?.locales ?? sitesConfig.globalLocales,
|
|
634
|
+
defaultLocale: locale,
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
// Pick the first site that declares an `mdxPages` path. Today's
|
|
638
|
+
// integration supports a single `mdxPages` per project;
|
|
639
|
+
// multi-site `mdxPages` is a future expansion (would require
|
|
640
|
+
// fanning the watcher and registry scanner across all roots).
|
|
641
|
+
const firstSiteWithMdxPages = Object.values(sitesConfig.sites).find((s) => s?.mdxPages);
|
|
642
|
+
resolvedMdxPages = firstSiteWithMdxPages?.mdxPages ?? null;
|
|
643
|
+
spaConfig.mdxPagesEnabled = Boolean(resolvedMdxPages);
|
|
644
|
+
// The editor builds each page's data context in the browser from
|
|
645
|
+
// these, the same bindings the published page resolves with.
|
|
646
|
+
spaConfig.dataBindings = resolvedRoutingConfig?.enabled
|
|
647
|
+
? toEditorDataBindings(resolvedRoutingConfig)
|
|
648
|
+
: undefined;
|
|
649
|
+
|
|
650
|
+
registryScan = { ...registryScan, contentRoot: resolvedMdxPages ?? options.contentRoot };
|
|
651
|
+
// Publish the resolved editor descriptors for other integrations in
|
|
652
|
+
// this build (see EDITOR_DESCRIPTORS_ENV_VAR): they read the same
|
|
653
|
+
// descriptors dev loads from `schemasPath`, `/api/registry` and
|
|
654
|
+
// `virtual:conloca-config` instead of taking these options again.
|
|
655
|
+
// schemasPath is absolutized because a reader may use it as an import
|
|
656
|
+
// specifier.
|
|
657
|
+
const editorDescriptors: EditorDescriptorChannel = {
|
|
658
|
+
...(options.schemasPath ? { schemasPath: resolve(options.schemasPath) } : {}),
|
|
659
|
+
registry: registryScan,
|
|
660
|
+
...(options.templates ? { templates: options.templates } : {}),
|
|
661
|
+
...(spaConfig.dataBindings ? { dataBindings: spaConfig.dataBindings } : {}),
|
|
662
|
+
};
|
|
663
|
+
process.env[EDITOR_DESCRIPTORS_ENV_VAR] = JSON.stringify(editorDescriptors);
|
|
664
|
+
|
|
665
|
+
// Auto-inject fs.allow for external contentRoot (dev mode only)
|
|
666
|
+
const astroRoot = process.cwd();
|
|
667
|
+
const contentAbsolute = resolve(options.contentRoot);
|
|
668
|
+
|
|
669
|
+
// A missing content root used to produce an empty site that 404'd
|
|
670
|
+
// every page with no hint. Fail the build loudly; in dev (and sync)
|
|
671
|
+
// only warn — a brand-new project boots with an empty site and the
|
|
672
|
+
// CMS creates the directory on first save.
|
|
673
|
+
if (!existsSync(contentAbsolute)) {
|
|
674
|
+
const hint =
|
|
675
|
+
`Content root not found: ${contentAbsolute}. Create the directory ` +
|
|
676
|
+
'(git cannot track empty folders — add a .gitkeep) or fix contentRoot in conlocaCMS().';
|
|
677
|
+
if (command === 'build') {
|
|
678
|
+
throw new Error(`[Conloca] ${hint}`);
|
|
679
|
+
}
|
|
680
|
+
logger.warn(`${hint} Starting with an empty site.`);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// A content config that never declares Conloca collections yields
|
|
684
|
+
// an empty Astro collection, so the injected route resolves nothing
|
|
685
|
+
// and every page 404s with no other symptom. Astro exposes no hook
|
|
686
|
+
// that reveals resolved collections, so check the file itself.
|
|
687
|
+
const contentConfigProblem = findContentConfigProblem(astroRoot);
|
|
688
|
+
if (contentConfigProblem) {
|
|
689
|
+
const cause =
|
|
690
|
+
contentConfigProblem === 'missing'
|
|
691
|
+
? 'No content config found.'
|
|
692
|
+
: 'Your content config does not declare Conloca collections.';
|
|
693
|
+
const hint = `${cause} Conloca pages will 404 until it does. Add this:\n\n${CONTENT_CONFIG_SNIPPET}\n`;
|
|
694
|
+
if (command === 'build') {
|
|
695
|
+
throw new Error(`[Conloca] ${hint}`);
|
|
696
|
+
}
|
|
697
|
+
logger.warn(hint);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// Every image the editor picks is stored under this base and served
|
|
701
|
+
// as-is by the published site. Derived in build too, so a media
|
|
702
|
+
// folder the site cannot serve fails there as well as in dev.
|
|
703
|
+
if (options.assetsPath) {
|
|
704
|
+
spaConfig.assetRefBase = deriveAssetRefBase(options.assetsPath, config.publicDir, config.base);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
if (command === 'dev' && !contentAbsolute.startsWith(astroRoot)) {
|
|
708
|
+
logger.info(`Auto-allowing contentRoot in Vite fs.allow: ${options.contentRoot}`);
|
|
709
|
+
|
|
710
|
+
updateConfig({
|
|
711
|
+
vite: {
|
|
712
|
+
server: {
|
|
713
|
+
fs: {
|
|
714
|
+
allow: [
|
|
715
|
+
searchForWorkspaceRoot(process.cwd()), // Preserve Vite default
|
|
716
|
+
contentAbsolute,
|
|
717
|
+
],
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// @puckeditor/core (and its zustand dependency) must always go through Vite's
|
|
725
|
+
// SSR resolver, in dev AND build. SSR-external modules are require()'d directly
|
|
726
|
+
// by Node, bypassing Vite's resolver — and `resolve.dedupe` below — entirely,
|
|
727
|
+
// which risks pulling in a stray React copy from outside the workspace.
|
|
728
|
+
const alwaysSsrNoExternal = ['@puckeditor/core'];
|
|
729
|
+
// In dev, linked workspace packages also need to be bundled so React resolves
|
|
730
|
+
// through Vite and HMR works from source (build mode uses their compiled dist output).
|
|
731
|
+
const devOnlySsrNoExternal = [/^@conloca\//];
|
|
732
|
+
const serverOnlyExternal = [
|
|
733
|
+
'@conloca/content-api',
|
|
734
|
+
'@conloca/content-api/node',
|
|
735
|
+
'@conloca/content-api/reader',
|
|
736
|
+
'@conloca/content-api/schemas',
|
|
737
|
+
'@conloca/mdx',
|
|
738
|
+
'@conloca/mdx/node',
|
|
739
|
+
];
|
|
740
|
+
updateConfig({
|
|
741
|
+
vite: {
|
|
742
|
+
ssr: {
|
|
743
|
+
noExternal: command === 'dev' ? [...devOnlySsrNoExternal, ...alwaysSsrNoExternal] : alwaysSsrNoExternal,
|
|
744
|
+
// Keep Node-only content packages (content-api, mdx) external so SSR
|
|
745
|
+
// builds do not try to bundle their server-only surfaces.
|
|
746
|
+
external: serverOnlyExternal,
|
|
747
|
+
},
|
|
748
|
+
resolve: {
|
|
749
|
+
// Dedupe React to avoid multiple instances when CMS SPA source is
|
|
750
|
+
// loaded from a workspace sibling package. Only list packages the
|
|
751
|
+
// consumer project declares directly — with bun's isolated linker,
|
|
752
|
+
// transitive deps (e.g. @tanstack/react-query) live in the owning
|
|
753
|
+
// package's node_modules and must NOT be forced to resolve from the
|
|
754
|
+
// consumer root (which would fail).
|
|
755
|
+
dedupe: ['react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime'],
|
|
756
|
+
alias: [
|
|
757
|
+
// Puck's richtext field render imports @tiptap/html. Its browser
|
|
758
|
+
// build throws off-browser ("generateHTML can only be used in a
|
|
759
|
+
// browser environment"), and its /server build fakes a browser
|
|
760
|
+
// with happy-dom — whose Window constructor reaches for
|
|
761
|
+
// node:vm's Script.runInContext, a stub on workerd, so every
|
|
762
|
+
// richtext section died there with "The 'contextifiedObject'
|
|
763
|
+
// argument must be an vm.Context". Both specifiers resolve to a
|
|
764
|
+
// shim that writes the markup as a string, with no DOM and no
|
|
765
|
+
// vm, so the same output comes out on every engine. The alias
|
|
766
|
+
// reaches the editor in the browser too, and the field stores
|
|
767
|
+
// HTML, so the shim also reads it back: with the browser's own
|
|
768
|
+
// parser there, with linkedom on the server.
|
|
769
|
+
{ find: /^@tiptap\/html(\/server)?$/, replacement: TIPTAP_HTML_SHIM_PATH },
|
|
770
|
+
],
|
|
771
|
+
},
|
|
772
|
+
// react-dom@19 ships ./server as CJS under the workerd exports
|
|
773
|
+
// condition; without pre-bundling, the Cloudflare adapter's type-gen
|
|
774
|
+
// phase evaluates it raw in workerd ("require is not defined").
|
|
775
|
+
// Inert for Node builds.
|
|
776
|
+
optimizeDeps: { include: ['react-dom/server'] },
|
|
777
|
+
// Virtual modules for routing - needed in both dev and build
|
|
778
|
+
plugins: [
|
|
779
|
+
// Public page rendering should use Puck's server entry, not the full editor.
|
|
780
|
+
// The full editor pulls client-only store code into Astro prerendering.
|
|
781
|
+
{
|
|
782
|
+
name: 'conloca-puck-ssr-render-alias',
|
|
783
|
+
enforce: 'pre' as const,
|
|
784
|
+
async resolveId(id, importer, options) {
|
|
785
|
+
if (id === '@puckeditor/core' && options?.ssr) {
|
|
786
|
+
return this.resolve('@puckeditor/core/rsc', importer, { ...options, skipSelf: true });
|
|
787
|
+
}
|
|
788
|
+
return null;
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
// Alias acorn to a default+named shim only during SSR (page
|
|
792
|
+
// builds). Must NOT apply to the browser bundle, and must NOT
|
|
793
|
+
// apply to the shim's own `import ... from 'acorn'` — that
|
|
794
|
+
// static import has to reach the real package, not recurse.
|
|
795
|
+
{
|
|
796
|
+
name: 'conloca-acorn-ssr-alias',
|
|
797
|
+
enforce: 'pre' as const,
|
|
798
|
+
resolveId(id, importer, options) {
|
|
799
|
+
if (id === 'acorn' && options?.ssr && !importer?.endsWith('acorn-default.mjs')) {
|
|
800
|
+
return ACORN_DEFAULT_SHIM_PATH;
|
|
801
|
+
}
|
|
802
|
+
return null;
|
|
803
|
+
},
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
name: 'conloca-routing-virtual-modules',
|
|
807
|
+
resolveId(id) {
|
|
808
|
+
// Routing virtual modules (work in both dev and build)
|
|
809
|
+
if (id === VIRTUAL_ROUTING_CONFIG) {
|
|
810
|
+
return RESOLVED_ROUTING_CONFIG;
|
|
811
|
+
}
|
|
812
|
+
if (id === VIRTUAL_LAYOUT) {
|
|
813
|
+
return RESOLVED_LAYOUT;
|
|
814
|
+
}
|
|
815
|
+
if (id === VIRTUAL_PUCK_CONFIG) {
|
|
816
|
+
return RESOLVED_PUCK_CONFIG;
|
|
817
|
+
}
|
|
818
|
+
// Hydration virtual modules
|
|
819
|
+
if (id === VIRTUAL_HYDRATION_REGISTRY) {
|
|
820
|
+
return RESOLVED_HYDRATION_REGISTRY;
|
|
821
|
+
}
|
|
822
|
+
if (id === VIRTUAL_HYDRATION_ENTRY) {
|
|
823
|
+
return RESOLVED_HYDRATION_ENTRY;
|
|
824
|
+
}
|
|
825
|
+
return null;
|
|
826
|
+
},
|
|
827
|
+
async load(id) {
|
|
828
|
+
// Routing virtual modules
|
|
829
|
+
if (id === RESOLVED_ROUTING_CONFIG) {
|
|
830
|
+
if (resolvedRoutingConfig) {
|
|
831
|
+
return generateRoutingConfigModule(resolvedRoutingConfig);
|
|
832
|
+
}
|
|
833
|
+
// Return disabled config if routing not configured
|
|
834
|
+
return 'export default { enabled: false, routes: {}, fallback: "404", onConflict: "warn" };';
|
|
835
|
+
}
|
|
836
|
+
if (id === RESOLVED_LAYOUT) {
|
|
837
|
+
return generateLayoutModule(routingConfig);
|
|
838
|
+
}
|
|
839
|
+
if (id === RESOLVED_PUCK_CONFIG) {
|
|
840
|
+
return generatePuckConfigModule(options.puckConfigPath);
|
|
841
|
+
}
|
|
842
|
+
// Hydration virtual modules
|
|
843
|
+
if (id === RESOLVED_HYDRATION_REGISTRY) {
|
|
844
|
+
// Always scan - paths are auto-derived from puckConfigPath
|
|
845
|
+
const discoveries = await hydrationDiscoveriesPromise;
|
|
846
|
+
if (discoveries.length > 0) {
|
|
847
|
+
const entries = discoveries.map((d) => {
|
|
848
|
+
// Convert absolute path to Vite-friendly path
|
|
849
|
+
const relativePath = d.filePath.replace(process.cwd(), '');
|
|
850
|
+
return ` '${d.componentName}': {
|
|
851
|
+
loader: () => import('${relativePath}').then(m => m.${d.componentName}.render),
|
|
852
|
+
strategy: '${d.strategy}',
|
|
853
|
+
}`;
|
|
854
|
+
});
|
|
855
|
+
return `// Generated by @conloca/astro-cms scanner
|
|
856
|
+
export const componentRegistry = {
|
|
857
|
+
${entries.join(',\n')}
|
|
858
|
+
};`;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// No hydratable components found - return empty registry
|
|
862
|
+
return 'export const componentRegistry = {};';
|
|
863
|
+
}
|
|
864
|
+
if (id === RESOLVED_HYDRATION_ENTRY) {
|
|
865
|
+
// Generate entry point that imports registry and calls initHydration
|
|
866
|
+
return `import { initHydration } from '@conloca/astro-cms/lib/hydration-script'
|
|
867
|
+
import { componentRegistry } from 'virtual:conloca-hydration-registry'
|
|
868
|
+
|
|
869
|
+
// Auto-initialize hydration when this module loads
|
|
870
|
+
initHydration(componentRegistry)
|
|
871
|
+
`;
|
|
872
|
+
}
|
|
873
|
+
return null;
|
|
874
|
+
},
|
|
875
|
+
},
|
|
876
|
+
],
|
|
877
|
+
},
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// Content page routes - works in both dev and build
|
|
881
|
+
if (resolvedRoutingConfig?.enabled) {
|
|
882
|
+
for (const [routeName, routeConfig] of Object.entries(resolvedRoutingConfig.routes)) {
|
|
883
|
+
logger.info(`Injecting content route: ${routeConfig.pattern} (${routeName})`);
|
|
884
|
+
injectRoute({
|
|
885
|
+
pattern: routeConfig.pattern,
|
|
886
|
+
entrypoint: PAGE_HANDLER_PATH,
|
|
887
|
+
prerender: routeConfig.prerender,
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// The sandbox frame document ContentSandbox loads for MDX previews.
|
|
893
|
+
// Root-absolute by contract (SANDBOX_FRAME_PATH in @conloca/mdx) and
|
|
894
|
+
// needed wherever the editor runs — anything that serves the editor
|
|
895
|
+
// serves the same path. Injected outside the dev-only block: a
|
|
896
|
+
// production editor build needs the frame too.
|
|
897
|
+
//
|
|
898
|
+
// On-demand by necessity — the response carries the sandbox CSP, which
|
|
899
|
+
// a prerendered file cannot — so injecting it into a fully static site
|
|
900
|
+
// fails that build with NoAdapterInstalled. Such a site has no runtime
|
|
901
|
+
// editor to serve it to; dev serves it whatever the output mode.
|
|
902
|
+
if (command === 'dev' || config.output !== 'static') {
|
|
903
|
+
injectRoute({
|
|
904
|
+
pattern: '/api/v1/mdx/sandbox-frame',
|
|
905
|
+
entrypoint: SANDBOX_FRAME_HANDLER_PATH,
|
|
906
|
+
prerender: false,
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// Only inject CMS admin routes and dev-specific config in dev mode
|
|
911
|
+
if (command !== 'dev') return;
|
|
912
|
+
|
|
913
|
+
// Pass options via Vite define for API routes
|
|
914
|
+
updateConfig({
|
|
915
|
+
vite: {
|
|
916
|
+
define: {
|
|
917
|
+
'import.meta.env.CONLOCA_CONTENT_ROOT': JSON.stringify(options.contentRoot),
|
|
918
|
+
'import.meta.env.CONLOCA_CANVAS_DIR': JSON.stringify(options.canvasDir || './canvas'),
|
|
919
|
+
'import.meta.env.CONLOCA_PUCK_CONFIG_PATH': JSON.stringify(options.puckConfigPath),
|
|
920
|
+
'import.meta.env.CONLOCA_ASSETS_PATH': JSON.stringify(options.assetsPath || ''),
|
|
921
|
+
// mdxPages / mdxPagesSite / mdxPagesDefaultLocale are no
|
|
922
|
+
// longer surfaced as env vars — the content-api reads them
|
|
923
|
+
// directly from sites.json under `contentRoot` at request
|
|
924
|
+
// time. See `readSitesConfig()` and `SitesConfig.sites[name].mdxPages`.
|
|
925
|
+
// Default route URL the fragment editor uses for style /
|
|
926
|
+
// wrapper discovery. See `fragmentPreviewRoute` option doc
|
|
927
|
+
// above. `/` is a sane fallback for most layouts.
|
|
928
|
+
'import.meta.env.CONLOCA_FRAGMENT_PREVIEW_ROUTE': JSON.stringify(options.fragmentPreviewRoute || '/'),
|
|
929
|
+
// Raw CSS the host wants injected into the editor's
|
|
930
|
+
// `conloca-host-preview` layer for visual overrides.
|
|
931
|
+
// See `editorCSS` option doc above for use cases.
|
|
932
|
+
'import.meta.env.CONLOCA_EDITOR_CSS': JSON.stringify(options.editorCSS || ''),
|
|
933
|
+
// Top-level locales. Vite `define` does literal text
|
|
934
|
+
// substitution, so this inlines as either a JS array or `null`.
|
|
935
|
+
// The runtime handler reads it as-is — no JSON.parse needed.
|
|
936
|
+
'import.meta.env.CONLOCA_LOCALES': JSON.stringify(options.locales?.list ?? null),
|
|
937
|
+
'import.meta.env.CONLOCA_DEFAULT_LOCALE': JSON.stringify(options.locales?.defaultLocale || ''),
|
|
938
|
+
},
|
|
939
|
+
optimizeDeps: {
|
|
940
|
+
// Exclude the puck config from optimization to avoid the outdated dep error
|
|
941
|
+
exclude: [options.puckConfigPath],
|
|
942
|
+
// Pre-bundle ALL CMS dependencies upfront to prevent mid-session re-optimization
|
|
943
|
+
// which causes React dual-instance issues when Vite discovers new deps dynamically
|
|
944
|
+
include: [
|
|
945
|
+
// React core - must be pre-bundled together
|
|
946
|
+
'react',
|
|
947
|
+
'react-dom',
|
|
948
|
+
'react-dom/client',
|
|
949
|
+
'react/jsx-runtime',
|
|
950
|
+
'react/jsx-dev-runtime',
|
|
951
|
+
// CMS dependencies
|
|
952
|
+
'@mdxeditor/editor',
|
|
953
|
+
'@puckeditor/core',
|
|
954
|
+
'@tanstack/react-query',
|
|
955
|
+
'@tanstack/react-query-devtools',
|
|
956
|
+
'react-router-dom',
|
|
957
|
+
'@radix-ui/react-dialog',
|
|
958
|
+
'@radix-ui/react-select',
|
|
959
|
+
'lucide-react',
|
|
960
|
+
'clsx',
|
|
961
|
+
'tailwind-merge',
|
|
962
|
+
// Content processing
|
|
963
|
+
'zod',
|
|
964
|
+
'yaml',
|
|
965
|
+
'nanoid',
|
|
966
|
+
'sort-keys',
|
|
967
|
+
// MDX processing
|
|
968
|
+
'@mdx-js/mdx',
|
|
969
|
+
'remark-frontmatter',
|
|
970
|
+
'remark-gfm',
|
|
971
|
+
'remark-mdx-frontmatter',
|
|
972
|
+
],
|
|
973
|
+
},
|
|
974
|
+
plugins: [
|
|
975
|
+
// Normalize @conloca/* imports from symlinked source files (bun link).
|
|
976
|
+
// When main.tsx is loaded via /@fs/<real-path>, its @conloca/* imports
|
|
977
|
+
// resolve relative to the real filesystem location, creating duplicate
|
|
978
|
+
// module instances. This plugin re-resolves them from the consumer
|
|
979
|
+
// project root so all @conloca packages use the same module identity.
|
|
980
|
+
{
|
|
981
|
+
name: 'conloca-resolve-normalizer',
|
|
982
|
+
enforce: 'pre' as const,
|
|
983
|
+
async resolveId(source, importer) {
|
|
984
|
+
// Only normalize @conloca/* bare specifiers
|
|
985
|
+
if (!source.startsWith('@conloca/')) return null;
|
|
986
|
+
// Only when imported from outside the project (symlinked source files)
|
|
987
|
+
if (!importer || importer.startsWith(astroRoot)) return null;
|
|
988
|
+
// Skip virtual modules (prefixed with \0)
|
|
989
|
+
if (importer.startsWith('\0')) return null;
|
|
990
|
+
// Re-resolve from project root to ensure consumer's node_modules is used
|
|
991
|
+
const resolved = await this.resolve(source, join(astroRoot, '_resolveAnchor.js'), { skipSelf: true });
|
|
992
|
+
return resolved;
|
|
993
|
+
},
|
|
994
|
+
},
|
|
995
|
+
{
|
|
996
|
+
name: 'conloca-dev-virtual-modules',
|
|
997
|
+
resolveId(id) {
|
|
998
|
+
// Dev-only config module for cms-handler.ts
|
|
999
|
+
if (id === VIRTUAL_CONFIG_MODULE) {
|
|
1000
|
+
return RESOLVED_VIRTUAL_CONFIG;
|
|
1001
|
+
}
|
|
1002
|
+
if (id === VIRTUAL_REFRESH_PREAMBLE) {
|
|
1003
|
+
return RESOLVED_REFRESH_PREAMBLE;
|
|
1004
|
+
}
|
|
1005
|
+
if (id === `${cmsRoute}/puck-entry.js`) {
|
|
1006
|
+
return id;
|
|
1007
|
+
}
|
|
1008
|
+
if (id === `${cmsRoute}/content-listener.js`) {
|
|
1009
|
+
return id;
|
|
1010
|
+
}
|
|
1011
|
+
if (id === `${cmsRoute}/schemas-entry.js`) {
|
|
1012
|
+
return id;
|
|
1013
|
+
}
|
|
1014
|
+
if (id === `${cmsRoute}/site-styles.js`) {
|
|
1015
|
+
return id;
|
|
1016
|
+
}
|
|
1017
|
+
if (id === `${cmsRoute}/editor-styles.js`) {
|
|
1018
|
+
return id;
|
|
1019
|
+
}
|
|
1020
|
+
if (id === VIRTUAL_CMS_SPA_ENTRY) {
|
|
1021
|
+
return RESOLVED_CMS_SPA_ENTRY;
|
|
1022
|
+
}
|
|
1023
|
+
if (id === `${cmsRoute}/cms-spa-entry.js`) {
|
|
1024
|
+
return RESOLVED_CMS_SPA_ENTRY;
|
|
1025
|
+
}
|
|
1026
|
+
return null;
|
|
1027
|
+
},
|
|
1028
|
+
load(id) {
|
|
1029
|
+
// Dev-only config module for cms-handler.ts
|
|
1030
|
+
if (id === RESOLVED_VIRTUAL_CONFIG) {
|
|
1031
|
+
return `export default ${JSON.stringify(spaConfig)};`;
|
|
1032
|
+
}
|
|
1033
|
+
if (id === RESOLVED_REFRESH_PREAMBLE) {
|
|
1034
|
+
return reactRefreshPreamble;
|
|
1035
|
+
}
|
|
1036
|
+
if (id === `${cmsRoute}/puck-entry.js`) {
|
|
1037
|
+
const absolutePuckPath = options.puckConfigPath.startsWith('.')
|
|
1038
|
+
? `/${options.puckConfigPath.slice(2)}`
|
|
1039
|
+
: options.puckConfigPath;
|
|
1040
|
+
|
|
1041
|
+
return puckConfigLoader(absolutePuckPath, cmsSpaDistDir);
|
|
1042
|
+
}
|
|
1043
|
+
if (id === `${cmsRoute}/content-listener.js`) {
|
|
1044
|
+
return contentChangeListener();
|
|
1045
|
+
}
|
|
1046
|
+
if (id === `${cmsRoute}/schemas-entry.js`) {
|
|
1047
|
+
if (options.schemasPath) {
|
|
1048
|
+
const absoluteSchemasPath = options.schemasPath.startsWith('.')
|
|
1049
|
+
? `/${options.schemasPath.slice(2)}`
|
|
1050
|
+
: options.schemasPath;
|
|
1051
|
+
return schemasLoader(absoluteSchemasPath, cmsSpaDistDir);
|
|
1052
|
+
}
|
|
1053
|
+
return 'export default {};';
|
|
1054
|
+
}
|
|
1055
|
+
if (id === `${cmsRoute}/site-styles.js`) {
|
|
1056
|
+
if (options.siteStyles) {
|
|
1057
|
+
const paths = Array.isArray(options.siteStyles) ? options.siteStyles : [options.siteStyles];
|
|
1058
|
+
return siteStylesLoader(paths, cmsSpaDistDir);
|
|
1059
|
+
}
|
|
1060
|
+
return 'export default {};';
|
|
1061
|
+
}
|
|
1062
|
+
if (id === `${cmsRoute}/editor-styles.js`) {
|
|
1063
|
+
if (options.editorStyles) {
|
|
1064
|
+
const paths = Array.isArray(options.editorStyles) ? options.editorStyles : [options.editorStyles];
|
|
1065
|
+
return editorStylesLoader(paths, cmsSpaDistDir);
|
|
1066
|
+
}
|
|
1067
|
+
return 'export default {};';
|
|
1068
|
+
}
|
|
1069
|
+
if (id === RESOLVED_CMS_SPA_ENTRY) {
|
|
1070
|
+
// Detect whether cms-spa is a workspace checkout (import its
|
|
1071
|
+
// source for HMR) or a registry install (import its built
|
|
1072
|
+
// entry). Reuses `cmsSpaDir` resolved at plugin setup time.
|
|
1073
|
+
let cmsSpaImport: string;
|
|
1074
|
+
if (cmsSpaDir && !isRegistryInstall(cmsSpaDir)) {
|
|
1075
|
+
const realSrcMainPath = join(cmsSpaDir, 'src', 'main.tsx');
|
|
1076
|
+
// Prefer the consumer-side symlink path when @conloca/cms-spa is
|
|
1077
|
+
// linked in from another workspace (e.g. cross-repo `bun link`).
|
|
1078
|
+
// Importing via the symlink path keeps `react`/`react-dom`
|
|
1079
|
+
// resolving through the consumer's node_modules walk, which
|
|
1080
|
+
// prevents duplicate React instances inside the CMS SPA.
|
|
1081
|
+
// Same-workspace installs either don't expose this path or
|
|
1082
|
+
// point at the same underlying file, so behavior and HMR
|
|
1083
|
+
// are preserved.
|
|
1084
|
+
const linkedSrcMainPath = join(
|
|
1085
|
+
astroRoot,
|
|
1086
|
+
'node_modules',
|
|
1087
|
+
'@conloca',
|
|
1088
|
+
'cms-spa',
|
|
1089
|
+
'src',
|
|
1090
|
+
'main.tsx',
|
|
1091
|
+
);
|
|
1092
|
+
|
|
1093
|
+
// Workspace mode: import source for HMR
|
|
1094
|
+
cmsSpaImport = `import '${existsSync(linkedSrcMainPath) ? linkedSrcMainPath : realSrcMainPath}';`;
|
|
1095
|
+
} else {
|
|
1096
|
+
// npm mode, and the fallback when the package cannot be
|
|
1097
|
+
// resolved: import the pre-built SPA mounting entry
|
|
1098
|
+
cmsSpaImport = "import '@conloca/cms-spa/main';";
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
return `
|
|
1102
|
+
// React refresh preamble first — it must be the first import, see its module
|
|
1103
|
+
import '${VIRTUAL_REFRESH_PREAMBLE}';
|
|
1104
|
+
|
|
1105
|
+
// Import cms-spa through Vite
|
|
1106
|
+
// Vite will resolve React from its pre-bundled deps (same instance as puck.config.tsx)
|
|
1107
|
+
${cmsSpaImport}
|
|
1108
|
+
|
|
1109
|
+
// Accept HMR
|
|
1110
|
+
if (import.meta.hot) {
|
|
1111
|
+
import.meta.hot.accept();
|
|
1112
|
+
}
|
|
1113
|
+
`;
|
|
1114
|
+
}
|
|
1115
|
+
return null;
|
|
1116
|
+
},
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
// Per-page styles endpoint. Fetches the live HTML for the
|
|
1120
|
+
// route and returns every `<style>` block and `<link
|
|
1121
|
+
// rel="stylesheet">` it lists — the same set of stylesheets
|
|
1122
|
+
// the browser paints with.
|
|
1123
|
+
name: 'conloca-styles-endpoint',
|
|
1124
|
+
apply: 'serve' as const,
|
|
1125
|
+
configureServer(server) {
|
|
1126
|
+
server.middlewares.use(`${cmsRoute}/api/styles`, createStylesEndpoint());
|
|
1127
|
+
},
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
// Per-route content-wrapper endpoint. Fetches the live page
|
|
1131
|
+
// HTML and returns the host's content-root element shape
|
|
1132
|
+
// (`{ tagName, className }`) so the editor can render its
|
|
1133
|
+
// contenteditable inside a clone of that wrapper — letting
|
|
1134
|
+
// the host's CSS (eg `article.card { background: … }`) paint
|
|
1135
|
+
// the editor's content surface naturally, with no per-color
|
|
1136
|
+
// bridging.
|
|
1137
|
+
name: 'conloca-content-wrapper-endpoint',
|
|
1138
|
+
apply: 'serve' as const,
|
|
1139
|
+
configureServer(server) {
|
|
1140
|
+
server.middlewares.use(`${cmsRoute}/api/content-wrapper`, createContentWrapperEndpoint());
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
// Registry + render endpoints are paired: the registry
|
|
1145
|
+
// builds the list of legal component sources, and the
|
|
1146
|
+
// render endpoint validates every incoming `source`
|
|
1147
|
+
// against that list before passing it to ssrLoadModule.
|
|
1148
|
+
// Constructing both in one configureServer hook means
|
|
1149
|
+
// they share the same memoized scan — no cross-plugin
|
|
1150
|
+
// state, no startup-order race.
|
|
1151
|
+
//
|
|
1152
|
+
// - Registry: scans MDX content for imports + usages and
|
|
1153
|
+
// the configured local component folders for
|
|
1154
|
+
// `interface Props { ... }`, merges into a single
|
|
1155
|
+
// descriptor list, returns it as JSON. The SPA fetches
|
|
1156
|
+
// this on mount and seeds `setMdxComponents`,
|
|
1157
|
+
// replacing the hand-written `mdx-components.tsx` flow.
|
|
1158
|
+
// - Render: renders a single MDX component (Aside,
|
|
1159
|
+
// Card, …) via Astro's Container API so the CMS editor
|
|
1160
|
+
// can display the real framework markup, paired with
|
|
1161
|
+
// the per-page CSS from the styles endpoint above.
|
|
1162
|
+
name: 'conloca-registry-and-render-endpoints',
|
|
1163
|
+
apply: 'serve' as const,
|
|
1164
|
+
configureServer(server) {
|
|
1165
|
+
const registry = createRegistryEndpoint(registryScan);
|
|
1166
|
+
server.middlewares.use(`${cmsRoute}/api/registry`, registry.handler);
|
|
1167
|
+
server.middlewares.use(
|
|
1168
|
+
`${cmsRoute}/api/render`,
|
|
1169
|
+
createRenderEndpoint(server, registry.getAllowedSources),
|
|
1170
|
+
);
|
|
1171
|
+
|
|
1172
|
+
// Invalidate the cached scan whenever an .mdx file or
|
|
1173
|
+
// any component file changes. Coarse for now — every
|
|
1174
|
+
// change re-scans everything; cheap enough for typical
|
|
1175
|
+
// project sizes. `.cms.json` sidecars also trigger
|
|
1176
|
+
// invalidation so host overrides apply live without a
|
|
1177
|
+
// dev-server restart.
|
|
1178
|
+
const onFsChange = (filepath: string) => {
|
|
1179
|
+
if (/\.(mdx|astro|tsx|d\.ts|cms\.json)$/.test(filepath)) registry.invalidate();
|
|
1180
|
+
};
|
|
1181
|
+
server.watcher.on('add', onFsChange);
|
|
1182
|
+
server.watcher.on('change', onFsChange);
|
|
1183
|
+
server.watcher.on('unlink', onFsChange);
|
|
1184
|
+
},
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
// The Puck component vocabulary: every component the config
|
|
1188
|
+
// declares, with its fields, read from source and never
|
|
1189
|
+
// executed — so an agent editing a page can find out what it
|
|
1190
|
+
// may compose with. A build that publishes the vocabulary
|
|
1191
|
+
// reads the same config through the same entry
|
|
1192
|
+
// (`./puck-manifest`), never describing components a second
|
|
1193
|
+
// way.
|
|
1194
|
+
name: 'conloca-components-endpoint',
|
|
1195
|
+
apply: 'serve' as const,
|
|
1196
|
+
configureServer(server) {
|
|
1197
|
+
server.middlewares.use(
|
|
1198
|
+
`${cmsRoute}/api/components`,
|
|
1199
|
+
createComponentsEndpoint(
|
|
1200
|
+
endpointReaderOptions({ puckConfigPath: options.puckConfigPath, projectRoot }),
|
|
1201
|
+
),
|
|
1202
|
+
);
|
|
1203
|
+
},
|
|
1204
|
+
},
|
|
1205
|
+
{
|
|
1206
|
+
name: 'conloca-content-watcher',
|
|
1207
|
+
async configureServer(server) {
|
|
1208
|
+
const { createContentAPI, createContentWatchHandlers } = await loadContentApiNode();
|
|
1209
|
+
|
|
1210
|
+
// Initialize content API using the extracted function.
|
|
1211
|
+
// mdxPages / mdxPagesSite / mdxPagesDefaultLocale are
|
|
1212
|
+
// read from sites.json by the content-api itself; we
|
|
1213
|
+
// don't pass them here.
|
|
1214
|
+
const contentApi = await createContentAPI({
|
|
1215
|
+
contentRoot: options.contentRoot,
|
|
1216
|
+
canvasDir: options.canvasDir || './canvas',
|
|
1217
|
+
...(options.locales && {
|
|
1218
|
+
availableLocales: options.locales.list,
|
|
1219
|
+
defaultLocale: options.locales.defaultLocale,
|
|
1220
|
+
}),
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
// Only add explicit watchers if content is outside the Astro project
|
|
1224
|
+
const { resolve } = await import('node:path');
|
|
1225
|
+
const astroRoot = process.cwd();
|
|
1226
|
+
const contentAbsolute = resolve(options.contentRoot);
|
|
1227
|
+
const canvasAbsolute = resolve(options.canvasDir || './canvas');
|
|
1228
|
+
|
|
1229
|
+
const foldersToWatch = [];
|
|
1230
|
+
|
|
1231
|
+
if (!contentAbsolute.startsWith(astroRoot)) {
|
|
1232
|
+
console.log(
|
|
1233
|
+
`[Astro Integration] Content outside project, adding to watcher: ${options.contentRoot}`,
|
|
1234
|
+
);
|
|
1235
|
+
foldersToWatch.push(options.contentRoot);
|
|
1236
|
+
} else {
|
|
1237
|
+
console.log(
|
|
1238
|
+
`[Astro Integration] Content inside project, Vite will watch automatically: ${options.contentRoot}`,
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
if (!canvasAbsolute.startsWith(astroRoot)) {
|
|
1243
|
+
console.log(
|
|
1244
|
+
`[Astro Integration] Canvas outside project, adding to watcher: ${options.canvasDir || './canvas'}`,
|
|
1245
|
+
);
|
|
1246
|
+
foldersToWatch.push(options.canvasDir || './canvas');
|
|
1247
|
+
} else {
|
|
1248
|
+
console.log(
|
|
1249
|
+
`[Astro Integration] Canvas inside project, Vite will watch automatically: ${options.canvasDir || './canvas'}`,
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
if (foldersToWatch.length > 0) {
|
|
1254
|
+
server.watcher.add(foldersToWatch);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// Set up HMR for content changes using extracted handlers.
|
|
1258
|
+
// The watcher uses `mdxPagesRoot` to flag events under
|
|
1259
|
+
// the mdx tree (so docs-loader can refresh). The value
|
|
1260
|
+
// comes from sites.json via `resolvedMdxPages`.
|
|
1261
|
+
const handlers = createContentWatchHandlers(
|
|
1262
|
+
contentApi,
|
|
1263
|
+
{
|
|
1264
|
+
contentRoot: options.contentRoot,
|
|
1265
|
+
canvasDir: options.canvasDir || './canvas',
|
|
1266
|
+
...(resolvedMdxPages && { mdxPagesRoot: resolvedMdxPages }),
|
|
1267
|
+
},
|
|
1268
|
+
server.ws,
|
|
1269
|
+
async (event) => {
|
|
1270
|
+
await refreshConlocaContent?.();
|
|
1271
|
+
|
|
1272
|
+
// Astro 6's content-virtual-mod plugin registers an explicit
|
|
1273
|
+
// file watcher on `.astro/data-store.json` only (see
|
|
1274
|
+
// dist/content/vite-plugin-content-virtual-mod.js: `devServer.watcher.add(dataStoreFile)`).
|
|
1275
|
+
// It does NOT watch the sibling `content-modules.mjs` (file
|
|
1276
|
+
// path → render function map). When Starlight's docsLoader
|
|
1277
|
+
// adds a new MDX entry at runtime, that file IS rewritten on
|
|
1278
|
+
// disk, but Vite's SSR moduleGraph keeps the stale module
|
|
1279
|
+
// and `renderEntry` throws UnknownContentCollectionError.
|
|
1280
|
+
// Force-reload the file ourselves; `reloadModule` is the
|
|
1281
|
+
// Vite API that re-runs the load hook on next SSR import.
|
|
1282
|
+
if (event.inMdxRoot) {
|
|
1283
|
+
const dotAstroModulesFile = resolve(astroRoot, '.astro', 'content-modules.mjs');
|
|
1284
|
+
const dotAstroAssetsFile = resolve(astroRoot, '.astro', 'content-assets.mjs');
|
|
1285
|
+
for (const env of Object.values(server.environments ?? {})) {
|
|
1286
|
+
if (!env?.moduleGraph) continue;
|
|
1287
|
+
for (const filePath of [dotAstroModulesFile, dotAstroAssetsFile]) {
|
|
1288
|
+
const mod = env.moduleGraph.getModuleById(filePath);
|
|
1289
|
+
if (!mod) continue;
|
|
1290
|
+
const envWithReload = env as unknown as {
|
|
1291
|
+
reloadModule?: (m: unknown) => void | Promise<void>;
|
|
1292
|
+
};
|
|
1293
|
+
if (typeof envWithReload.reloadModule === 'function') {
|
|
1294
|
+
void Promise.resolve(envWithReload.reloadModule(mod)).catch(() => undefined);
|
|
1295
|
+
} else {
|
|
1296
|
+
env.moduleGraph.invalidateModule(mod, undefined, Date.now(), true);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
env.hot?.send('astro:content-changed', {});
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
},
|
|
1303
|
+
);
|
|
1304
|
+
|
|
1305
|
+
server.watcher.on('change', handlers.onChange);
|
|
1306
|
+
server.watcher.on('add', handlers.onAdd);
|
|
1307
|
+
server.watcher.on('unlink', handlers.onUnlink);
|
|
1308
|
+
},
|
|
1309
|
+
},
|
|
1310
|
+
{
|
|
1311
|
+
name: 'conloca-suppress-cms-save-reload',
|
|
1312
|
+
apply: 'serve' as const,
|
|
1313
|
+
configureServer(server) {
|
|
1314
|
+
let suppressUntil = 0;
|
|
1315
|
+
const WINDOW_MS = 2000;
|
|
1316
|
+
const cmsContentPrefix = `${cmsRoute}/api/content`;
|
|
1317
|
+
|
|
1318
|
+
server.middlewares.use((req, _res, next) => {
|
|
1319
|
+
const isWrite =
|
|
1320
|
+
req.method === 'POST' ||
|
|
1321
|
+
req.method === 'PUT' ||
|
|
1322
|
+
req.method === 'PATCH' ||
|
|
1323
|
+
req.method === 'DELETE';
|
|
1324
|
+
if (isWrite && req.url?.startsWith(cmsContentPrefix)) {
|
|
1325
|
+
suppressUntil = Date.now() + WINDOW_MS;
|
|
1326
|
+
}
|
|
1327
|
+
next();
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
// During a CMS save window, drop two server→client signals that
|
|
1331
|
+
// would otherwise stomp on the CMS's own optimistic cache updates:
|
|
1332
|
+
//
|
|
1333
|
+
// 1. Vite `full-reload` — emitted by Astro 6.2.1's invalidateDataStore()
|
|
1334
|
+
// in dist/content/vite-plugin-content-virtual-mod.js. The call site
|
|
1335
|
+
// is in a configureServer watcher callback, outside the
|
|
1336
|
+
// handleHotUpdate pipeline, so wrapping hot.send is the only intercept.
|
|
1337
|
+
//
|
|
1338
|
+
// 2. `conloca:content-update` custom event — emitted by
|
|
1339
|
+
// conloca-content-watcher above. The client listener (template at
|
|
1340
|
+
// `contentChangeListener` in this file) reacts by calling
|
|
1341
|
+
// queryClient.invalidateQueries() with NO args, refetching every
|
|
1342
|
+
// query and visibly blinking lists. CMS mutation hooks already do
|
|
1343
|
+
// optimistic setQueryData, so this event is redundant for
|
|
1344
|
+
// CMS-originated writes. External edits (outside the save window)
|
|
1345
|
+
// still pass through normally.
|
|
1346
|
+
const patchedChannels = new WeakSet();
|
|
1347
|
+
const patchSend = (target: NormalizedHotChannel | undefined) => {
|
|
1348
|
+
if (!target || patchedChannels.has(target)) return;
|
|
1349
|
+
const origSend = target.send.bind(target);
|
|
1350
|
+
|
|
1351
|
+
function send(payload: HotPayload): void;
|
|
1352
|
+
function send<T extends string>(event: T, payload?: InferCustomEventPayload<T>): void;
|
|
1353
|
+
function send(
|
|
1354
|
+
payloadOrEvent: HotPayload | string,
|
|
1355
|
+
payload?: InferCustomEventPayload<string>,
|
|
1356
|
+
): void {
|
|
1357
|
+
if (typeof payloadOrEvent === 'string') {
|
|
1358
|
+
origSend(payloadOrEvent, payload);
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
if (dropsEditorSaveUpdate(payloadOrEvent) && Date.now() < suppressUntil) {
|
|
1362
|
+
server.config.logger.info(
|
|
1363
|
+
`[conloca] suppressed ${payloadOrEvent.type} during CMS save window`,
|
|
1364
|
+
{ timestamp: true },
|
|
1365
|
+
);
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
origSend(payloadOrEvent);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
target.send = send;
|
|
1372
|
+
patchedChannels.add(target);
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
// Astro's content plugin sends `full-reload` via environments.client.hot.
|
|
1376
|
+
// Conloca's content watcher sends custom events via server.ws (legacy API).
|
|
1377
|
+
// Patch both; idempotent per-target via __conlocaPatched.
|
|
1378
|
+
patchSend(server.environments?.client?.hot);
|
|
1379
|
+
patchSend(server.ws);
|
|
1380
|
+
},
|
|
1381
|
+
},
|
|
1382
|
+
],
|
|
1383
|
+
},
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
// Inject unified CMS handler for all CMS routes
|
|
1387
|
+
// Single handler validates auth once, then routes to appropriate sub-handler
|
|
1388
|
+
injectRoute({
|
|
1389
|
+
pattern: `${cmsRoute}/[...path]`,
|
|
1390
|
+
entrypoint: CMS_HANDLER_PATH,
|
|
1391
|
+
prerender: false,
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
// Also handle the root CMS route
|
|
1395
|
+
injectRoute({
|
|
1396
|
+
pattern: cmsRoute,
|
|
1397
|
+
entrypoint: CMS_HANDLER_PATH,
|
|
1398
|
+
prerender: false,
|
|
1399
|
+
});
|
|
1400
|
+
},
|
|
1401
|
+
|
|
1402
|
+
'astro:config:done': ({ config }) => {
|
|
1403
|
+
outputMode = config.output;
|
|
1404
|
+
},
|
|
1405
|
+
|
|
1406
|
+
'astro:server:setup': ({ logger, refreshContent }) => {
|
|
1407
|
+
logger.info(`Conloca CMS available at ${cmsRoute}`);
|
|
1408
|
+
|
|
1409
|
+
let refreshChain = Promise.resolve();
|
|
1410
|
+
|
|
1411
|
+
refreshConlocaContent = async () => {
|
|
1412
|
+
if (!refreshContent) {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
refreshChain = refreshChain
|
|
1417
|
+
.catch(() => undefined)
|
|
1418
|
+
.then(async () => {
|
|
1419
|
+
await refreshContent({ loaders: ['conloca-loader'] });
|
|
1420
|
+
});
|
|
1421
|
+
|
|
1422
|
+
await refreshChain;
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
// Register dev-time content refresh after the Vite server exists.
|
|
1426
|
+
// This keeps Astro collections in sync with Conloca's own file watcher.
|
|
1427
|
+
logger.debug('Registering Conloca content refresh handler');
|
|
1428
|
+
},
|
|
1429
|
+
|
|
1430
|
+
'astro:routes:resolved': ({ routes, logger }) => {
|
|
1431
|
+
// Check for route conflicts when routing is enabled
|
|
1432
|
+
if (!resolvedRoutingConfig?.enabled) return;
|
|
1433
|
+
|
|
1434
|
+
const injectedPatterns = new Set(Object.values(resolvedRoutingConfig.routes).map((r) => r.pattern));
|
|
1435
|
+
|
|
1436
|
+
// Another integration's route with the SAME NAME as a Conloca route is
|
|
1437
|
+
// fatal, whatever `onConflict` says: routing copes (Astro falls through
|
|
1438
|
+
// a prerendered match to the on-demand twin), but Astro's runtime app
|
|
1439
|
+
// resolves a page's stylesheets by route name and takes the first
|
|
1440
|
+
// match, so the twins swap or lose their styles — silently, and only
|
|
1441
|
+
// in the built site. That app renders every page of a server-output
|
|
1442
|
+
// build (prerendering included) and the on-demand pages of a static
|
|
1443
|
+
// one; fully static generation resolves by route and component, where
|
|
1444
|
+
// twins are harmless, so such a site is left alone. Starlight's docs
|
|
1445
|
+
// route is the usual twin: it is named /[...slug] too. The fix is a
|
|
1446
|
+
// different parameter name.
|
|
1447
|
+
const isConlocaHandler = (route: { entrypoint?: string }) =>
|
|
1448
|
+
route.entrypoint?.endsWith('/internal/page-handler.astro') ?? false;
|
|
1449
|
+
const ownRoutes = routes.filter(isConlocaHandler);
|
|
1450
|
+
for (const route of routes) {
|
|
1451
|
+
if (route.origin !== 'external' || !injectedPatterns.has(route.pattern) || isConlocaHandler(route)) continue;
|
|
1452
|
+
const own = ownRoutes.find((candidate) => candidate.pattern === route.pattern);
|
|
1453
|
+
const stylesResolvedByName = outputMode === 'server' || !route.isPrerendered || own?.isPrerendered === false;
|
|
1454
|
+
if (!stylesResolvedByName) continue;
|
|
1455
|
+
throw new Error(
|
|
1456
|
+
`[Conloca] Route '${route.pattern}' is registered by Conloca routing and by ${route.entrypoint}. ` +
|
|
1457
|
+
'Astro resolves stylesheets by route name, so two routes with the same name lose their styles. ' +
|
|
1458
|
+
"Give the Conloca route a parameter name of its own, e.g. '/[...page]'.",
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// Find file-based project routes that conflict with injected routes.
|
|
1463
|
+
const conflicts: { injected: string; fileBased: string }[] = [];
|
|
1464
|
+
|
|
1465
|
+
for (const route of routes) {
|
|
1466
|
+
if (route.origin !== 'project') continue;
|
|
1467
|
+
|
|
1468
|
+
const pattern = route.pattern;
|
|
1469
|
+
if (injectedPatterns.has(pattern)) {
|
|
1470
|
+
conflicts.push({
|
|
1471
|
+
injected: pattern,
|
|
1472
|
+
fileBased: route.entrypoint || pattern,
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
if (conflicts.length === 0) return;
|
|
1478
|
+
|
|
1479
|
+
// Handle conflicts based on onConflict setting
|
|
1480
|
+
const onConflict = resolvedRoutingConfig.onConflict;
|
|
1481
|
+
|
|
1482
|
+
for (const conflict of conflicts) {
|
|
1483
|
+
const message = `Route conflict: '${conflict.injected}' is defined both in ${conflict.fileBased} and injected by Conloca routing. Conloca route will take precedence.`;
|
|
1484
|
+
|
|
1485
|
+
if (onConflict === 'error') {
|
|
1486
|
+
throw new Error(`[Conloca] ${message}`);
|
|
1487
|
+
}
|
|
1488
|
+
if (onConflict === 'warn') {
|
|
1489
|
+
logger.warn(message);
|
|
1490
|
+
}
|
|
1491
|
+
// 'silent' - do nothing
|
|
1492
|
+
}
|
|
1493
|
+
},
|
|
1494
|
+
},
|
|
1495
|
+
};
|
|
1496
|
+
}
|