@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.10 → 3.5.0-ultramodern.101
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/bin/modern-bundle-docs.js +7 -0
- package/bin/modern.js +0 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +20 -16
- package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +13 -4
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +14 -11
- package/dist/cjs/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.js +72 -0
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +28 -11
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +13 -6
- package/dist/cjs/builder/shared/lazyCompilation.js +2 -10
- package/dist/cjs/bundleDocs.js +114 -0
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/deploy.js +4 -2
- package/dist/cjs/commands/index.js +0 -8
- package/dist/cjs/config/build-environment.js +268 -0
- package/dist/cjs/config/default.js +2 -0
- package/dist/cjs/config/index.js +11 -4
- package/dist/cjs/config/public.js +46 -0
- package/dist/cjs/index.js +93 -75
- package/dist/cjs/plugins/analyze/getServerRoutes.js +19 -0
- package/dist/cjs/plugins/analyze/index.js +22 -14
- package/dist/cjs/plugins/analyze/utils.js +3 -2
- package/dist/cjs/plugins/backend-federation/codegen.js +255 -0
- package/dist/cjs/plugins/backend-federation/config.js +204 -0
- package/dist/cjs/plugins/backend-federation/emit.js +148 -0
- package/dist/cjs/plugins/backendFederationBuild.js +53 -0
- package/dist/cjs/plugins/deploy/index.js +4 -4
- package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +141 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +139 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +150 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +205 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +208 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +204 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +108 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +188 -0
- package/dist/cjs/{baseline.js → plugins/deploy/platforms/cloudflare-output-verifier/issues.js} +19 -10
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +89 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +151 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +302 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +20 -2
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +250 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +1012 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +363 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +8 -4
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +251 -155
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +78 -39
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +62 -41
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.mjs +63 -41
- package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +52 -35
- package/dist/cjs/plugins/deploy/platforms/templates/node-entry.mjs +53 -35
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.cjs +61 -41
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.mjs +61 -40
- package/dist/cjs/plugins/deploy/utils/npmAliases.js +226 -0
- package/dist/cjs/plugins/initialize/index.js +4 -3
- package/dist/cjs/plugins/serverBuild.js +3 -2
- package/dist/cjs/plugins/ultramodernReleaseEnvelope.js +100 -0
- package/dist/cjs/presetUltramodern.js +33 -2
- package/dist/cjs/ultramodern-release-envelope/canonical.js +68 -0
- package/dist/cjs/ultramodern-release-envelope/framework-output.js +597 -0
- package/dist/cjs/ultramodern-release-envelope/index.js +399 -0
- package/dist/cjs/ultramodern-release-envelope/types.js +51 -0
- package/dist/cjs/ultramodern-release-identity.js +110 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +19 -15
- package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +13 -4
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +15 -12
- package/dist/esm/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.mjs +30 -0
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.mjs +24 -10
- package/dist/esm/builder/shared/bundlerPlugins/index.mjs +1 -0
- package/dist/esm/builder/shared/lazyCompilation.mjs +1 -3
- package/dist/esm/bundleDocs.mjs +62 -0
- package/dist/esm/commands/build.mjs +2 -1
- package/dist/esm/commands/deploy.mjs +4 -2
- package/dist/esm/commands/index.mjs +0 -5
- package/dist/esm/config/build-environment.mjs +224 -0
- package/dist/esm/config/default.mjs +2 -0
- package/dist/esm/config/index.mjs +1 -0
- package/dist/esm/config/public.mjs +1 -0
- package/dist/esm/index.mjs +20 -5
- package/dist/esm/plugins/analyze/getHtmlTemplate.mjs +2 -2
- package/dist/esm/plugins/analyze/getServerRoutes.mjs +17 -1
- package/dist/esm/plugins/analyze/index.mjs +22 -14
- package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +3 -2
- package/dist/esm/plugins/backend-federation/codegen.mjs +204 -0
- package/dist/esm/plugins/backend-federation/config.mjs +128 -0
- package/dist/esm/plugins/backend-federation/emit.mjs +97 -0
- package/dist/esm/plugins/backendFederationBuild.mjs +1 -0
- package/dist/esm/plugins/deploy/index.mjs +1 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +88 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +102 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +148 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +150 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +31 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +133 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +51 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +99 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +238 -0
- package/dist/esm/plugins/deploy/platforms/node.mjs +20 -2
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +250 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +1012 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +363 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +8 -4
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +251 -155
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +78 -39
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +62 -41
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.mjs +63 -41
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +52 -35
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +53 -35
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.cjs +61 -41
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.mjs +61 -40
- package/dist/esm/plugins/deploy/utils/npmAliases.mjs +174 -0
- package/dist/esm/plugins/initialize/index.mjs +4 -3
- package/dist/esm/plugins/serverBuild.mjs +3 -2
- package/dist/esm/plugins/ultramodernReleaseEnvelope.mjs +52 -0
- package/dist/esm/presetUltramodern.mjs +33 -2
- package/dist/esm/ultramodern-release-envelope/canonical.mjs +21 -0
- package/dist/esm/ultramodern-release-envelope/framework-output.mjs +524 -0
- package/dist/esm/ultramodern-release-envelope/index.mjs +335 -0
- package/dist/esm/ultramodern-release-envelope/types.mjs +7 -0
- package/dist/esm/ultramodern-release-identity.mjs +66 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +19 -15
- package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +13 -4
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +15 -12
- package/dist/esm-node/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.mjs +31 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.mjs +24 -10
- package/dist/esm-node/builder/shared/bundlerPlugins/index.mjs +1 -0
- package/dist/esm-node/builder/shared/lazyCompilation.mjs +1 -3
- package/dist/esm-node/bundleDocs.mjs +63 -0
- package/dist/esm-node/commands/build.mjs +2 -1
- package/dist/esm-node/commands/deploy.mjs +4 -2
- package/dist/esm-node/commands/index.mjs +0 -5
- package/dist/esm-node/config/build-environment.mjs +225 -0
- package/dist/esm-node/config/default.mjs +2 -0
- package/dist/esm-node/config/index.mjs +1 -0
- package/dist/esm-node/config/public.mjs +2 -0
- package/dist/esm-node/index.mjs +20 -5
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.mjs +2 -2
- package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +17 -1
- package/dist/esm-node/plugins/analyze/index.mjs +22 -14
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +205 -0
- package/dist/esm-node/plugins/backend-federation/config.mjs +129 -0
- package/dist/esm-node/plugins/backend-federation/emit.mjs +98 -0
- package/dist/esm-node/plugins/backendFederationBuild.mjs +2 -0
- package/dist/esm-node/plugins/deploy/index.mjs +1 -1
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +35 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +89 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +103 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +149 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +151 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +32 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +134 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +52 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +100 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +239 -0
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +20 -2
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +250 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +191 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +514 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +1012 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +363 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +93 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +8 -4
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +251 -155
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +78 -39
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +62 -41
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.mjs +63 -41
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +52 -35
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +53 -35
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.cjs +61 -41
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.mjs +61 -40
- package/dist/esm-node/plugins/deploy/utils/npmAliases.mjs +175 -0
- package/dist/esm-node/plugins/initialize/index.mjs +4 -3
- package/dist/esm-node/plugins/serverBuild.mjs +3 -2
- package/dist/esm-node/plugins/ultramodernReleaseEnvelope.mjs +53 -0
- package/dist/esm-node/presetUltramodern.mjs +33 -2
- package/dist/esm-node/ultramodern-release-envelope/canonical.mjs +22 -0
- package/dist/esm-node/ultramodern-release-envelope/framework-output.mjs +525 -0
- package/dist/esm-node/ultramodern-release-envelope/index.mjs +336 -0
- package/dist/esm-node/ultramodern-release-envelope/types.mjs +8 -0
- package/dist/esm-node/ultramodern-release-identity.mjs +67 -0
- package/dist/types/builder/generator/createCopyPattern.d.ts +7 -5
- package/dist/types/builder/shared/bundlerPlugins/CssExtractRuntimePlugin.d.ts +6 -0
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -0
- package/dist/types/builder/shared/bundlerPlugins/index.d.ts +1 -0
- package/dist/types/builder/shared/lazyCompilation.d.ts +2 -4
- package/dist/types/bundleDocs.d.ts +20 -0
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/index.d.ts +0 -1
- package/dist/types/config/build-environment.d.ts +22 -0
- package/dist/types/config/index.d.ts +1 -0
- package/dist/types/config/public.d.ts +2 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/plugins/backend-federation/codegen.d.ts +83 -0
- package/dist/types/plugins/backend-federation/config.d.ts +103 -0
- package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
- package/dist/types/plugins/backendFederationBuild.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +24 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +22 -0
- package/dist/types/plugins/deploy/platforms/{cloudflare.d.ts → cloudflare/index.d.ts} +1 -1
- package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +51 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +122 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +46 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +14 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +34 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +14 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +20 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
- package/dist/types/plugins/deploy/utils/npmAliases.d.ts +14 -0
- package/dist/types/plugins/ultramodernReleaseEnvelope.d.ts +3 -0
- package/dist/types/presetUltramodern.d.ts +10 -0
- package/dist/types/run/index.d.ts +1 -1
- package/dist/types/types/config/cloudflareDeploy.d.ts +41 -0
- package/dist/types/types/config/deploy.d.ts +15 -2
- package/dist/types/types/config/dev.d.ts +6 -0
- package/dist/types/ultramodern-release-envelope/canonical.d.ts +5 -0
- package/dist/types/ultramodern-release-envelope/framework-output.d.ts +31 -0
- package/dist/types/ultramodern-release-envelope/index.d.ts +6 -0
- package/dist/types/ultramodern-release-envelope/types.d.ts +62 -0
- package/dist/types/ultramodern-release-identity.d.ts +16 -0
- package/docs/apis/app/commands.md +231 -0
- package/docs/apis/app/hooks/api/lambda.md +9 -0
- package/docs/apis/app/hooks/config/favicon.md +24 -0
- package/docs/apis/app/hooks/config/html.md +5 -0
- package/docs/apis/app/hooks/config/icon.md +24 -0
- package/docs/apis/app/hooks/config/mock.md +6 -0
- package/docs/apis/app/hooks/config/public.md +26 -0
- package/docs/apis/app/hooks/config/upload.md +50 -0
- package/docs/apis/app/hooks/modern-config.md +5 -0
- package/docs/apis/app/hooks/server/server.md +5 -0
- package/docs/apis/app/hooks/shared.md +3 -0
- package/docs/apis/app/hooks/src/app.md +30 -0
- package/docs/apis/app/hooks/src/entry.md +34 -0
- package/docs/apis/app/hooks/src/entry.server.md +51 -0
- package/docs/apis/app/hooks/src/modern.runtime.md +5 -0
- package/docs/apis/app/hooks/src/routes.md +86 -0
- package/docs/apis/app/hooks/src/server.md +3 -0
- package/docs/apis/app/runtime/bff/use-backend-context.md +27 -0
- package/docs/apis/app/runtime/core/create-root.md +19 -0
- package/docs/apis/app/runtime/core/render.md +39 -0
- package/docs/apis/app/runtime/core/runtime-context.md +156 -0
- package/docs/apis/app/runtime/router/router.md +283 -0
- package/docs/apis/app/runtime/ssr/no-ssr.md +35 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.md +67 -0
- package/docs/apis/app/runtime/ssr/renderString.md +60 -0
- package/docs/apis/app/runtime/ssr/requestHandler.md +44 -0
- package/docs/apis/app/runtime/utility/css-in-js.md +40 -0
- package/docs/apis/app/runtime/utility/head.md +35 -0
- package/docs/apis/app/runtime/utility/loadable.md +82 -0
- package/docs/community/blog/2022-0708-updates.md +91 -0
- package/docs/community/blog/2022-0910-updates.md +76 -0
- package/docs/community/blog/overview.md +63 -0
- package/docs/community/blog/v2-release-note.md +238 -0
- package/docs/community/blog/v3-release-note.md +622 -0
- package/docs/community/contributing-guide.md +252 -0
- package/docs/community/releases.md +23 -0
- package/docs/community/showcase.md +24 -0
- package/docs/community/team.md +14 -0
- package/docs/configure/app/bff/cross-project.md +20 -0
- package/docs/configure/app/bff/effect.md +315 -0
- package/docs/configure/app/bff/prefix.md +29 -0
- package/docs/configure/app/bff/runtime-framework.md +26 -0
- package/docs/configure/app/builder-plugins.md +66 -0
- package/docs/configure/app/dev/asset-prefix.md +13 -0
- package/docs/configure/app/dev/before-start-url.md +17 -0
- package/docs/configure/app/dev/client.md +41 -0
- package/docs/configure/app/dev/hmr.md +10 -0
- package/docs/configure/app/dev/host.md +18 -0
- package/docs/configure/app/dev/https.md +77 -0
- package/docs/configure/app/dev/lazy-compilation.md +39 -0
- package/docs/configure/app/dev/live-reload.md +10 -0
- package/docs/configure/app/dev/mock-dir.md +31 -0
- package/docs/configure/app/dev/progress-bar.md +19 -0
- package/docs/configure/app/dev/server.md +124 -0
- package/docs/configure/app/dev/setup-middlewares.md +32 -0
- package/docs/configure/app/dev/start-url.md +48 -0
- package/docs/configure/app/dev/watch-files.md +27 -0
- package/docs/configure/app/dev/write-to-disk.md +10 -0
- package/docs/configure/app/experiments/source-build.md +31 -0
- package/docs/configure/app/html/app-icon.md +28 -0
- package/docs/configure/app/html/crossorigin.md +10 -0
- package/docs/configure/app/html/favicon.md +16 -0
- package/docs/configure/app/html/inject.md +10 -0
- package/docs/configure/app/html/meta.md +24 -0
- package/docs/configure/app/html/mount-id.md +10 -0
- package/docs/configure/app/html/output-structure.md +10 -0
- package/docs/configure/app/html/script-loading.md +10 -0
- package/docs/configure/app/html/tags.md +15 -0
- package/docs/configure/app/html/template-parameters.md +33 -0
- package/docs/configure/app/html/template.md +10 -0
- package/docs/configure/app/html/title.md +18 -0
- package/docs/configure/app/output/asset-prefix.md +11 -0
- package/docs/configure/app/output/assets-retry.md +77 -0
- package/docs/configure/app/output/charset.md +10 -0
- package/docs/configure/app/output/clean-dist-path.md +16 -0
- package/docs/configure/app/output/convert-to-rem.md +79 -0
- package/docs/configure/app/output/copy.md +10 -0
- package/docs/configure/app/output/css-modules.md +48 -0
- package/docs/configure/app/output/data-uri-limit.md +26 -0
- package/docs/configure/app/output/disable-css-module-extension.md +55 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.md +41 -0
- package/docs/configure/app/output/disable-svgr.md +18 -0
- package/docs/configure/app/output/disable-ts-checker.md +49 -0
- package/docs/configure/app/output/dist-path.md +43 -0
- package/docs/configure/app/output/enable-asset-manifest.md +36 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.md +28 -0
- package/docs/configure/app/output/enable-inline-route-manifests.md +16 -0
- package/docs/configure/app/output/externals.md +20 -0
- package/docs/configure/app/output/filename-hash.md +10 -0
- package/docs/configure/app/output/filename.md +55 -0
- package/docs/configure/app/output/inject-styles.md +10 -0
- package/docs/configure/app/output/inline-scripts.md +29 -0
- package/docs/configure/app/output/inline-styles.md +29 -0
- package/docs/configure/app/output/legal-comments.md +18 -0
- package/docs/configure/app/output/minify.md +22 -0
- package/docs/configure/app/output/override-browserslist.md +22 -0
- package/docs/configure/app/output/polyfill.md +12 -0
- package/docs/configure/app/output/source-map.md +30 -0
- package/docs/configure/app/output/split-route-chunks.md +16 -0
- package/docs/configure/app/output/ssg.md +81 -0
- package/docs/configure/app/output/ssgByEntries.md +90 -0
- package/docs/configure/app/output/svg-default-export.md +30 -0
- package/docs/configure/app/output/temp-dir.md +20 -0
- package/docs/configure/app/performance/build-cache.md +44 -0
- package/docs/configure/app/performance/chunk-split.md +40 -0
- package/docs/configure/app/performance/dns-prefetch.md +15 -0
- package/docs/configure/app/performance/preconnect.md +16 -0
- package/docs/configure/app/performance/prefetch.md +21 -0
- package/docs/configure/app/performance/preload.md +23 -0
- package/docs/configure/app/performance/print-file-size.md +40 -0
- package/docs/configure/app/performance/profile.md +10 -0
- package/docs/configure/app/performance/remove-console.md +10 -0
- package/docs/configure/app/performance/remove-moment-locale.md +10 -0
- package/docs/configure/app/performance/rsdoctor.md +38 -0
- package/docs/configure/app/plugins.md +59 -0
- package/docs/configure/app/resolve/alias-strategy.md +10 -0
- package/docs/configure/app/resolve/alias.md +9 -0
- package/docs/configure/app/resolve/condition-names.md +13 -0
- package/docs/configure/app/resolve/dedupe.md +9 -0
- package/docs/configure/app/resolve/extensions.md +13 -0
- package/docs/configure/app/runtime/0-intro.md +58 -0
- package/docs/configure/app/runtime/plugins.md +58 -0
- package/docs/configure/app/runtime/router.md +35 -0
- package/docs/configure/app/security/check-syntax.md +69 -0
- package/docs/configure/app/security/nonce.md +15 -0
- package/docs/configure/app/security/sri.md +20 -0
- package/docs/configure/app/server/base-url.md +26 -0
- package/docs/configure/app/server/port.md +18 -0
- package/docs/configure/app/server/public-routes.md +22 -0
- package/docs/configure/app/server/routes.md +86 -0
- package/docs/configure/app/server/rsc.md +26 -0
- package/docs/configure/app/server/ssr-by-entries.md +25 -0
- package/docs/configure/app/server/ssr.md +80 -0
- package/docs/configure/app/server/tsconfig-path.md +59 -0
- package/docs/configure/app/source/alias-strategy.md +14 -0
- package/docs/configure/app/source/alias.md +23 -0
- package/docs/configure/app/source/config-dir.md +20 -0
- package/docs/configure/app/source/decorators.md +25 -0
- package/docs/configure/app/source/define.md +16 -0
- package/docs/configure/app/source/disable-default-entries.md +28 -0
- package/docs/configure/app/source/enable-async-entry.md +54 -0
- package/docs/configure/app/source/enable-async-pre-entry.md +26 -0
- package/docs/configure/app/source/entries-dir.md +35 -0
- package/docs/configure/app/source/entries.md +179 -0
- package/docs/configure/app/source/exclude.md +10 -0
- package/docs/configure/app/source/global-vars.md +106 -0
- package/docs/configure/app/source/include.md +36 -0
- package/docs/configure/app/source/main-entry-name.md +24 -0
- package/docs/configure/app/source/pre-entry.md +10 -0
- package/docs/configure/app/source/react-compiler.md +68 -0
- package/docs/configure/app/source/transform-import.md +27 -0
- package/docs/configure/app/split-chunks.md +17 -0
- package/docs/configure/app/tools/autoprefixer.md +44 -0
- package/docs/configure/app/tools/bundler-chain.md +26 -0
- package/docs/configure/app/tools/css-extract.md +33 -0
- package/docs/configure/app/tools/css-loader.md +17 -0
- package/docs/configure/app/tools/dev-server.md +113 -0
- package/docs/configure/app/tools/html-plugin.md +41 -0
- package/docs/configure/app/tools/less.md +81 -0
- package/docs/configure/app/tools/lightningcss-loader.md +35 -0
- package/docs/configure/app/tools/minify-css.md +53 -0
- package/docs/configure/app/tools/postcss.md +34 -0
- package/docs/configure/app/tools/rspack.md +10 -0
- package/docs/configure/app/tools/sass.md +78 -0
- package/docs/configure/app/tools/style-loader.md +10 -0
- package/docs/configure/app/tools/swc.md +65 -0
- package/docs/configure/app/tools/ts-checker.md +116 -0
- package/docs/configure/app/usage.md +276 -0
- package/docs/guides/advanced-features/bff/cross-project.md +109 -0
- package/docs/guides/advanced-features/bff/data-platform.md +116 -0
- package/docs/guides/advanced-features/bff/extend-server.md +120 -0
- package/docs/guides/advanced-features/bff/frameworks.md +243 -0
- package/docs/guides/advanced-features/bff/function.md +318 -0
- package/docs/guides/advanced-features/bff/operators.md +554 -0
- package/docs/guides/advanced-features/bff/sdk.md +116 -0
- package/docs/guides/advanced-features/bff/upload.md +101 -0
- package/docs/guides/advanced-features/bff.md +18 -0
- package/docs/guides/advanced-features/build-performance.md +130 -0
- package/docs/guides/advanced-features/compatibility.md +120 -0
- package/docs/guides/advanced-features/international/advanced.md +128 -0
- package/docs/guides/advanced-features/international/api.md +267 -0
- package/docs/guides/advanced-features/international/best-practices.md +286 -0
- package/docs/guides/advanced-features/international/configuration.md +228 -0
- package/docs/guides/advanced-features/international/locale-detection.md +126 -0
- package/docs/guides/advanced-features/international/quick-start.md +128 -0
- package/docs/guides/advanced-features/international/resource-loading.md +154 -0
- package/docs/guides/advanced-features/international/routing.md +173 -0
- package/docs/guides/advanced-features/international.md +27 -0
- package/docs/guides/advanced-features/low-level.md +46 -0
- package/docs/guides/advanced-features/page-performance/code-split.md +77 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.md +159 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.md +97 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.md +51 -0
- package/docs/guides/advanced-features/server-monitor/logger.md +41 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
- package/docs/guides/advanced-features/server-monitor/monitors.md +242 -0
- package/docs/guides/advanced-features/source-build.md +164 -0
- package/docs/guides/advanced-features/web-server.md +288 -0
- package/docs/guides/basic-features/alias.md +102 -0
- package/docs/guides/basic-features/css/css-in-js.md +72 -0
- package/docs/guides/basic-features/css/css-modules.md +212 -0
- package/docs/guides/basic-features/css/css.md +27 -0
- package/docs/guides/basic-features/css/tailwindcss.md +27 -0
- package/docs/guides/basic-features/data/data-cache.md +510 -0
- package/docs/guides/basic-features/data/data-fetch.md +415 -0
- package/docs/guides/basic-features/data/data-write.md +227 -0
- package/docs/guides/basic-features/debug/mock.md +109 -0
- package/docs/guides/basic-features/debug/proxy.md +21 -0
- package/docs/guides/basic-features/debug/rsdoctor.md +47 -0
- package/docs/guides/basic-features/debug/using-storybook.md +112 -0
- package/docs/guides/basic-features/deploy.md +458 -0
- package/docs/guides/basic-features/env-vars.md +177 -0
- package/docs/guides/basic-features/html.md +255 -0
- package/docs/guides/basic-features/output-files.md +141 -0
- package/docs/guides/basic-features/render/before-render.md +108 -0
- package/docs/guides/basic-features/render/overview.md +47 -0
- package/docs/guides/basic-features/render/rsc.md +525 -0
- package/docs/guides/basic-features/render/ssg.md +228 -0
- package/docs/guides/basic-features/render/ssr-cache.md +201 -0
- package/docs/guides/basic-features/render/ssr.md +321 -0
- package/docs/guides/basic-features/render/streaming-ssr.md +264 -0
- package/docs/guides/basic-features/routes/config-routes.md +426 -0
- package/docs/guides/basic-features/routes/routes.md +524 -0
- package/docs/guides/basic-features/static-assets/json-files.md +120 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +168 -0
- package/docs/guides/basic-features/static-assets/wasm-assets.md +62 -0
- package/docs/guides/basic-features/static-assets.md +160 -0
- package/docs/guides/basic-features/testing/playwright.md +120 -0
- package/docs/guides/basic-features/testing/rstest.md +251 -0
- package/docs/guides/concept/builder.md +37 -0
- package/docs/guides/concept/entries.md +319 -0
- package/docs/guides/concept/server.md +35 -0
- package/docs/guides/get-started/ai-coding-agents.md +58 -0
- package/docs/guides/get-started/glossary.md +63 -0
- package/docs/guides/get-started/introduction.md +40 -0
- package/docs/guides/get-started/quick-start.md +269 -0
- package/docs/guides/get-started/tech-stack.md +91 -0
- package/docs/guides/get-started/ultramodern.md +428 -0
- package/docs/guides/get-started/upgrade.md +123 -0
- package/docs/guides/topic-detail/module-federation/application.md +116 -0
- package/docs/guides/topic-detail/module-federation/deploy.md +104 -0
- package/docs/guides/topic-detail/module-federation/i18n.md +670 -0
- package/docs/guides/topic-detail/module-federation/introduce.md +35 -0
- package/docs/guides/topic-detail/module-federation/ssr.md +182 -0
- package/docs/guides/topic-detail/module-federation/usage.md +219 -0
- package/docs/guides/troubleshooting/builder.md +110 -0
- package/docs/guides/troubleshooting/cli.md +35 -0
- package/docs/guides/troubleshooting/dependencies.md +119 -0
- package/docs/guides/troubleshooting/hmr.md +144 -0
- package/docs/guides/upgrade/config.md +954 -0
- package/docs/guides/upgrade/entry.md +463 -0
- package/docs/guides/upgrade/other.md +183 -0
- package/docs/guides/upgrade/overview.md +33 -0
- package/docs/guides/upgrade/tailwindcss.md +91 -0
- package/docs/guides/upgrade/web-server.md +109 -0
- package/docs/index.md +33 -0
- package/docs/llms.txt +290 -0
- package/docs/plugin/cli-plugins/api.md +573 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +152 -0
- package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
- package/docs/plugin/official/cli-plugins.md +4 -0
- package/docs/plugin/plugin-system.md +238 -0
- package/docs/plugin/runtime-plugins/api.md +194 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +209 -0
- package/docs/plugin/server-plugins/life-cycle.md +13 -0
- package/docs/tutorials/examples/csr-auth.md +9 -0
- package/docs/tutorials/foundations/introduction.md +16 -0
- package/lib/types.d.ts +2 -3
- package/package.json +88 -32
- package/rslib.config.mts +11 -12
- package/dist/cjs/commands/runtime.js +0 -196
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +0 -540
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
- package/dist/cjs/ultramodern/designSystem.js +0 -123
- package/dist/esm/baseline.mjs +0 -4
- package/dist/esm/commands/runtime.mjs +0 -146
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +0 -492
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
- package/dist/esm/ultramodern/designSystem.mjs +0 -73
- package/dist/esm-node/baseline.mjs +0 -5
- package/dist/esm-node/commands/runtime.mjs +0 -147
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +0 -493
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
- package/dist/esm-node/ultramodern/designSystem.mjs +0 -74
- package/dist/types/baseline.d.ts +0 -16
- package/dist/types/commands/runtime.d.ts +0 -12
- package/dist/types/ultramodern/designSystem.d.ts +0 -54
- /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const DEFAULT_RUNTIME_HOST = 'http://127.0.0.1:8080';
|
|
3
|
-
const DEFAULT_RUNTIME_STATUS_PATH = '/_modern/runtime/status';
|
|
4
|
-
const DEFAULT_RUNTIME_FALLBACK_SIGNAL_PATH = '/_modern/contract-gates/runtime-fallback';
|
|
5
|
-
const DEFAULT_RUNTIME_TOKEN_HEADER = 'x-modernjs-runtime-signal-token';
|
|
6
|
-
const DEFAULT_TIMEOUT_MS = 5000;
|
|
7
|
-
const resolveRuntimeEndpoint = (input, defaultPath)=>{
|
|
8
|
-
const rawInput = input?.trim();
|
|
9
|
-
if (!rawInput) return `${DEFAULT_RUNTIME_HOST}${defaultPath}`;
|
|
10
|
-
if (rawInput.startsWith('http://') || rawInput.startsWith('https://')) return rawInput;
|
|
11
|
-
const normalized = rawInput.startsWith('/') ? rawInput : `/${rawInput}`;
|
|
12
|
-
return `${DEFAULT_RUNTIME_HOST}${normalized}`;
|
|
13
|
-
};
|
|
14
|
-
const resolveToken = ({ token, tokenEnv })=>{
|
|
15
|
-
if ('string' == typeof token && token.trim().length > 0) return token.trim();
|
|
16
|
-
if ('string' == typeof tokenEnv && tokenEnv.trim().length > 0) {
|
|
17
|
-
const value = process.env[tokenEnv.trim()];
|
|
18
|
-
if ('string' == typeof value && value.trim().length > 0) return value.trim();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const parseTimeoutMs = (value)=>{
|
|
22
|
-
if ('string' != typeof value || 0 === value.trim().length) return DEFAULT_TIMEOUT_MS;
|
|
23
|
-
const parsed = Number.parseInt(value, 10);
|
|
24
|
-
if (!Number.isFinite(parsed) || parsed <= 0) return DEFAULT_TIMEOUT_MS;
|
|
25
|
-
return parsed;
|
|
26
|
-
};
|
|
27
|
-
const parseMetadata = (metadata)=>{
|
|
28
|
-
if ('string' != typeof metadata || 0 === metadata.trim().length) return;
|
|
29
|
-
const parsed = JSON.parse(metadata);
|
|
30
|
-
if (!parsed || 'object' != typeof parsed || Array.isArray(parsed)) throw new Error('metadata must be a JSON object');
|
|
31
|
-
return parsed;
|
|
32
|
-
};
|
|
33
|
-
const fetchWithTimeout = async (url, init, timeoutMs)=>{
|
|
34
|
-
const controller = new AbortController();
|
|
35
|
-
const timeout = setTimeout(()=>{
|
|
36
|
-
controller.abort();
|
|
37
|
-
}, timeoutMs);
|
|
38
|
-
try {
|
|
39
|
-
return await fetch(url, {
|
|
40
|
-
...init,
|
|
41
|
-
signal: controller.signal
|
|
42
|
-
});
|
|
43
|
-
} finally{
|
|
44
|
-
clearTimeout(timeout);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const parseResponseBody = async (response)=>{
|
|
48
|
-
const text = await response.text();
|
|
49
|
-
if (!text) return {};
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(text);
|
|
52
|
-
} catch (_error) {
|
|
53
|
-
return {
|
|
54
|
-
raw: text
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const INDENT_STEP = ' ';
|
|
59
|
-
const formatScalar = (value)=>'string' == typeof value ? value : JSON.stringify(value) ?? 'undefined';
|
|
60
|
-
const formatHumanReadableLines = (value, indent)=>{
|
|
61
|
-
if (Array.isArray(value)) {
|
|
62
|
-
if (0 === value.length) return [
|
|
63
|
-
`${indent}(empty)`
|
|
64
|
-
];
|
|
65
|
-
return value.flatMap((entry)=>null !== entry && 'object' == typeof entry ? [
|
|
66
|
-
`${indent}-`,
|
|
67
|
-
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
68
|
-
] : [
|
|
69
|
-
`${indent}- ${formatScalar(entry)}`
|
|
70
|
-
]);
|
|
71
|
-
}
|
|
72
|
-
if (null !== value && 'object' == typeof value) {
|
|
73
|
-
const entries = Object.entries(value);
|
|
74
|
-
if (0 === entries.length) return [
|
|
75
|
-
`${indent}(empty)`
|
|
76
|
-
];
|
|
77
|
-
return entries.flatMap(([key, entry])=>null !== entry && 'object' == typeof entry ? [
|
|
78
|
-
`${indent}${key}:`,
|
|
79
|
-
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
80
|
-
] : [
|
|
81
|
-
`${indent}${key}: ${formatScalar(entry)}`
|
|
82
|
-
]);
|
|
83
|
-
}
|
|
84
|
-
return [
|
|
85
|
-
`${indent}${formatScalar(value)}`
|
|
86
|
-
];
|
|
87
|
-
};
|
|
88
|
-
const formatRuntimeOutput = (payload, jsonOnly)=>jsonOnly ? JSON.stringify(payload, null, 2) : formatHumanReadableLines(payload, '').join('\n');
|
|
89
|
-
const printOutput = (payload, jsonOnly)=>{
|
|
90
|
-
console.log(formatRuntimeOutput(payload, jsonOnly));
|
|
91
|
-
};
|
|
92
|
-
const createRuntimeFallbackSignalPayload = (options)=>{
|
|
93
|
-
const payload = {
|
|
94
|
-
appName: options.app,
|
|
95
|
-
reason: options.reason || 'runtime_fallback',
|
|
96
|
-
phase: options.phase || 'load'
|
|
97
|
-
};
|
|
98
|
-
if (options.entry) payload.entry = options.entry;
|
|
99
|
-
if (options.runtimeDigest) payload.runtimeDigest = options.runtimeDigest;
|
|
100
|
-
const metadata = parseMetadata(options.metadata);
|
|
101
|
-
if (metadata) payload.metadata = metadata;
|
|
102
|
-
return payload;
|
|
103
|
-
};
|
|
104
|
-
const runtimeCommand = async (program, _api)=>{
|
|
105
|
-
const runtime = program.command('runtime').description('runtime operations');
|
|
106
|
-
runtime.command('status').description('read runtime status snapshot').option('--endpoint <endpoint>', 'runtime status endpoint URL or path').option('--token <token>', 'runtime status auth token').option('--token-env <name>', 'environment variable name that stores runtime status auth token', 'MODERN_RUNTIME_SIGNAL_TOKEN').option('--header-name <name>', 'auth header name', DEFAULT_RUNTIME_TOKEN_HEADER).option('--timeout <ms>', 'request timeout in milliseconds', '5000').option('--json', 'output as JSON format for machine reading').action(async (options)=>{
|
|
107
|
-
const endpoint = resolveRuntimeEndpoint(options.endpoint, DEFAULT_RUNTIME_STATUS_PATH);
|
|
108
|
-
const timeoutMs = parseTimeoutMs(options.timeout);
|
|
109
|
-
const token = resolveToken({
|
|
110
|
-
token: options.token,
|
|
111
|
-
tokenEnv: options.tokenEnv
|
|
112
|
-
});
|
|
113
|
-
const headerName = options.headerName?.trim() || DEFAULT_RUNTIME_TOKEN_HEADER;
|
|
114
|
-
const headers = new Headers();
|
|
115
|
-
if (token) headers.set(headerName, token);
|
|
116
|
-
const response = await fetchWithTimeout(endpoint, {
|
|
117
|
-
method: 'GET',
|
|
118
|
-
headers
|
|
119
|
-
}, timeoutMs);
|
|
120
|
-
const payload = await parseResponseBody(response);
|
|
121
|
-
if (!response.ok) throw new Error(`runtime status request failed with ${response.status}: ${JSON.stringify(payload)}`);
|
|
122
|
-
printOutput(payload, options.json);
|
|
123
|
-
});
|
|
124
|
-
runtime.command('fallback-signal').description('emit runtime fallback signal for canary gate mutation').requiredOption('--app <appName>', 'remote app name').option('--endpoint <endpoint>', 'runtime fallback signal endpoint URL or path').option('--reason <reason>', 'fallback reason', 'runtime_fallback').option('--phase <phase>', 'fallback phase', 'load').option('--entry <entry>', 'remote entry URL').option('--runtime-digest <digest>', 'runtime digest value').option('--metadata <json>', 'metadata JSON object string').option('--token <token>', 'runtime signal auth token').option('--token-env <name>', 'environment variable name that stores runtime signal auth token', 'MODERN_RUNTIME_SIGNAL_TOKEN').option('--header-name <name>', 'auth header name', DEFAULT_RUNTIME_TOKEN_HEADER).option('--timeout <ms>', 'request timeout in milliseconds', '5000').option('--json', 'output as JSON format for machine reading').action(async (options)=>{
|
|
125
|
-
const endpoint = resolveRuntimeEndpoint(options.endpoint, DEFAULT_RUNTIME_FALLBACK_SIGNAL_PATH);
|
|
126
|
-
const timeoutMs = parseTimeoutMs(options.timeout);
|
|
127
|
-
const token = resolveToken({
|
|
128
|
-
token: options.token,
|
|
129
|
-
tokenEnv: options.tokenEnv
|
|
130
|
-
});
|
|
131
|
-
const headerName = options.headerName?.trim() || DEFAULT_RUNTIME_TOKEN_HEADER;
|
|
132
|
-
const payload = createRuntimeFallbackSignalPayload(options);
|
|
133
|
-
const headers = new Headers({
|
|
134
|
-
'content-type': 'application/json'
|
|
135
|
-
});
|
|
136
|
-
if (token) headers.set(headerName, token);
|
|
137
|
-
const response = await fetchWithTimeout(endpoint, {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
headers,
|
|
140
|
-
body: JSON.stringify(payload)
|
|
141
|
-
}, timeoutMs);
|
|
142
|
-
const responsePayload = await parseResponseBody(response);
|
|
143
|
-
if (!response.ok) throw new Error(`runtime fallback signal request failed with ${response.status}: ${JSON.stringify(responsePayload)}`);
|
|
144
|
-
printOutput(responsePayload, options.json);
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
export { createRuntimeFallbackSignalPayload, formatRuntimeOutput, resolveRuntimeEndpoint, resolveToken, runtimeCommand };
|
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
import { fs } from "@modern-js/utils";
|
|
4
|
-
import { readTemplate } from "../utils/index.mjs";
|
|
5
|
-
const WORKER_ENTRY = 'server/index.mjs';
|
|
6
|
-
const WORKER_MANIFEST = 'server/modern-worker-manifest.json';
|
|
7
|
-
const WRANGLER_CONFIG_FILE = 'wrangler.json';
|
|
8
|
-
const OUTPUT_PACKAGE_FILE = 'package.json';
|
|
9
|
-
const ASSETS_BINDING = 'ASSETS';
|
|
10
|
-
const ROUTE_SPEC_FILE = 'route.json';
|
|
11
|
-
const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
|
|
12
|
-
const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
|
13
|
-
const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
|
|
14
|
-
const PUBLIC_ASSETS_DIRECTORY = 'public';
|
|
15
|
-
const WORKER_BUNDLE_DIRECTORY = 'worker';
|
|
16
|
-
const SERVER_BUNDLE_DIRECTORY = 'bundles';
|
|
17
|
-
const SERVER_OUTPUT_DIRECTORY = 'server';
|
|
18
|
-
const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
|
|
19
|
-
'api',
|
|
20
|
-
'shared'
|
|
21
|
-
];
|
|
22
|
-
const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
|
|
23
|
-
const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
|
|
24
|
-
const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
|
|
25
|
-
const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
|
|
26
|
-
const REQUIRED_COMPATIBILITY_FLAGS = [
|
|
27
|
-
'nodejs_compat',
|
|
28
|
-
'global_fetch_strictly_public'
|
|
29
|
-
];
|
|
30
|
-
const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
|
|
31
|
-
WRANGLER_CONFIG_FILE,
|
|
32
|
-
OUTPUT_PACKAGE_FILE
|
|
33
|
-
]);
|
|
34
|
-
const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
|
|
35
|
-
PUBLIC_ASSETS_DIRECTORY,
|
|
36
|
-
SERVER_OUTPUT_DIRECTORY,
|
|
37
|
-
WORKER_BUNDLE_DIRECTORY
|
|
38
|
-
]);
|
|
39
|
-
const DEFAULT_SECURITY_HEADERS = {
|
|
40
|
-
referrerPolicy: 'strict-origin-when-cross-origin',
|
|
41
|
-
contentTypeOptions: 'nosniff',
|
|
42
|
-
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
43
|
-
};
|
|
44
|
-
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
45
|
-
'GET',
|
|
46
|
-
'HEAD',
|
|
47
|
-
'POST',
|
|
48
|
-
'PUT',
|
|
49
|
-
'PATCH',
|
|
50
|
-
'DELETE',
|
|
51
|
-
'OPTIONS'
|
|
52
|
-
];
|
|
53
|
-
const DEFAULT_CSP_DIRECTIVES = {
|
|
54
|
-
'base-uri': [
|
|
55
|
-
"'self'"
|
|
56
|
-
],
|
|
57
|
-
'connect-src': [
|
|
58
|
-
"'self'",
|
|
59
|
-
'https:',
|
|
60
|
-
'http:',
|
|
61
|
-
'wss:',
|
|
62
|
-
'ws:'
|
|
63
|
-
],
|
|
64
|
-
'default-src': [
|
|
65
|
-
"'self'"
|
|
66
|
-
],
|
|
67
|
-
'font-src': [
|
|
68
|
-
"'self'",
|
|
69
|
-
'data:',
|
|
70
|
-
'https:',
|
|
71
|
-
'http:'
|
|
72
|
-
],
|
|
73
|
-
'form-action': [
|
|
74
|
-
"'self'"
|
|
75
|
-
],
|
|
76
|
-
'frame-ancestors': [
|
|
77
|
-
"'self'"
|
|
78
|
-
],
|
|
79
|
-
'img-src': [
|
|
80
|
-
"'self'",
|
|
81
|
-
'data:',
|
|
82
|
-
'blob:',
|
|
83
|
-
'https:',
|
|
84
|
-
'http:'
|
|
85
|
-
],
|
|
86
|
-
'manifest-src': [
|
|
87
|
-
"'self'",
|
|
88
|
-
'https:',
|
|
89
|
-
'http:'
|
|
90
|
-
],
|
|
91
|
-
'object-src': [
|
|
92
|
-
"'none'"
|
|
93
|
-
],
|
|
94
|
-
"script-src": [
|
|
95
|
-
"'self'",
|
|
96
|
-
"'unsafe-inline'",
|
|
97
|
-
"'unsafe-eval'",
|
|
98
|
-
'https:',
|
|
99
|
-
'http:',
|
|
100
|
-
'blob:'
|
|
101
|
-
],
|
|
102
|
-
'style-src': [
|
|
103
|
-
"'self'",
|
|
104
|
-
"'unsafe-inline'",
|
|
105
|
-
'https:',
|
|
106
|
-
'http:'
|
|
107
|
-
],
|
|
108
|
-
'worker-src': [
|
|
109
|
-
"'self'",
|
|
110
|
-
'blob:'
|
|
111
|
-
]
|
|
112
|
-
};
|
|
113
|
-
const getCompatibilityDate = (modernConfig)=>{
|
|
114
|
-
const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
|
|
115
|
-
const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
|
|
116
|
-
if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
|
|
117
|
-
return compatibilityDate;
|
|
118
|
-
};
|
|
119
|
-
const getWorkerName = (appDirectory)=>{
|
|
120
|
-
const basename = node_path.basename(appDirectory);
|
|
121
|
-
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
122
|
-
};
|
|
123
|
-
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
124
|
-
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
125
|
-
return configuredName || getWorkerName(appDirectory);
|
|
126
|
-
};
|
|
127
|
-
const normalizeRelativePath = (value, label, scope = 'app output')=>{
|
|
128
|
-
if ('string' != typeof value) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
129
|
-
const normalized = value.trim().replace(/\\/g, '/').replace(/^\.\/+/u, '').replace(/\/+$/u, '');
|
|
130
|
-
const segments = normalized.split('/');
|
|
131
|
-
if (!normalized || node_path.isAbsolute(normalized) || '.' === normalized || segments.includes('..')) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
132
|
-
return normalized;
|
|
133
|
-
};
|
|
134
|
-
const normalizeDirectiveValues = (value)=>{
|
|
135
|
-
const values = Array.isArray(value) ? value : [
|
|
136
|
-
value
|
|
137
|
-
];
|
|
138
|
-
return [
|
|
139
|
-
...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
|
|
140
|
-
];
|
|
141
|
-
};
|
|
142
|
-
const appendDirectiveValues = (directives, name, values)=>{
|
|
143
|
-
if (!values?.length) return;
|
|
144
|
-
directives[name] = normalizeDirectiveValues([
|
|
145
|
-
...directives[name] ?? [],
|
|
146
|
-
...values
|
|
147
|
-
]);
|
|
148
|
-
};
|
|
149
|
-
const createContentSecurityPolicy = (config)=>{
|
|
150
|
-
const mode = config?.mode ?? 'report-only';
|
|
151
|
-
if ('off' === mode) return {
|
|
152
|
-
mode,
|
|
153
|
-
directives: {},
|
|
154
|
-
reason: config?.reason
|
|
155
|
-
};
|
|
156
|
-
const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
|
|
157
|
-
name,
|
|
158
|
-
[
|
|
159
|
-
...values
|
|
160
|
-
]
|
|
161
|
-
]));
|
|
162
|
-
for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
|
|
163
|
-
else directives[name] = normalizeDirectiveValues(value);
|
|
164
|
-
if (config?.frameAncestors === false) delete directives['frame-ancestors'];
|
|
165
|
-
else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
|
|
166
|
-
appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
|
|
167
|
-
appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
|
|
168
|
-
appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
|
|
169
|
-
appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
|
|
170
|
-
if (config?.reportUri) directives['report-uri'] = [
|
|
171
|
-
config.reportUri
|
|
172
|
-
];
|
|
173
|
-
return {
|
|
174
|
-
mode,
|
|
175
|
-
directives,
|
|
176
|
-
reason: config?.reason
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
const createNoindexPolicy = (noindex)=>{
|
|
180
|
-
if (false === noindex) return {
|
|
181
|
-
workersDev: false,
|
|
182
|
-
localhost: false,
|
|
183
|
-
previewHostnames: []
|
|
184
|
-
};
|
|
185
|
-
if (true === noindex || void 0 === noindex) return {
|
|
186
|
-
workersDev: true,
|
|
187
|
-
localhost: true,
|
|
188
|
-
previewHostnames: []
|
|
189
|
-
};
|
|
190
|
-
return {
|
|
191
|
-
workersDev: noindex.workersDev ?? true,
|
|
192
|
-
localhost: noindex.localhost ?? true,
|
|
193
|
-
previewHostnames: noindex.previewHostnames ?? [],
|
|
194
|
-
reason: noindex.reason
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
198
|
-
assets: cors?.assets ?? true,
|
|
199
|
-
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
200
|
-
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
201
|
-
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
202
|
-
'*'
|
|
203
|
-
],
|
|
204
|
-
reason: cors?.reason
|
|
205
|
-
});
|
|
206
|
-
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
207
|
-
const security = modernConfig.deploy?.worker?.security;
|
|
208
|
-
if (security?.enabled === false) return {
|
|
209
|
-
enabled: false,
|
|
210
|
-
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
211
|
-
reason: security.reason
|
|
212
|
-
};
|
|
213
|
-
return {
|
|
214
|
-
enabled: true,
|
|
215
|
-
headers: {
|
|
216
|
-
referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
|
|
217
|
-
contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
|
|
218
|
-
permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
|
|
219
|
-
},
|
|
220
|
-
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
221
|
-
noindex: createNoindexPolicy(security?.noindex),
|
|
222
|
-
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
223
|
-
reason: security?.reason
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
const isJsonRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
227
|
-
const getConfiguredWrangler = (modernConfig)=>{
|
|
228
|
-
const wrangler = modernConfig.deploy?.worker?.wrangler;
|
|
229
|
-
if (void 0 === wrangler) return {};
|
|
230
|
-
if (!isJsonRecord(wrangler)) throw new Error('deploy.worker.wrangler must be a JSON object.');
|
|
231
|
-
return wrangler;
|
|
232
|
-
};
|
|
233
|
-
const createWranglerCompatibilityFlags = (configuredFlags)=>{
|
|
234
|
-
if (void 0 === configuredFlags) return [
|
|
235
|
-
...REQUIRED_COMPATIBILITY_FLAGS
|
|
236
|
-
];
|
|
237
|
-
if (!Array.isArray(configuredFlags) || configuredFlags.some((flag)=>'string' != typeof flag)) throw new Error('deploy.worker.wrangler.compatibility_flags must be an array of strings.');
|
|
238
|
-
return [
|
|
239
|
-
...new Set([
|
|
240
|
-
...configuredFlags,
|
|
241
|
-
...REQUIRED_COMPATIBILITY_FLAGS
|
|
242
|
-
])
|
|
243
|
-
];
|
|
244
|
-
};
|
|
245
|
-
const createWranglerAssetsConfig = (configuredAssets)=>{
|
|
246
|
-
if (void 0 !== configuredAssets && !isJsonRecord(configuredAssets)) throw new Error('deploy.worker.wrangler.assets must be an object.');
|
|
247
|
-
return {
|
|
248
|
-
...isJsonRecord(configuredAssets) ? configuredAssets : {},
|
|
249
|
-
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
250
|
-
binding: ASSETS_BINDING,
|
|
251
|
-
run_worker_first: true
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
const assertNonEmptyString = (value, label)=>{
|
|
255
|
-
if ('string' != typeof value || 0 === value.trim().length) throw new Error(`${label} must be a non-empty string.`);
|
|
256
|
-
return value.trim();
|
|
257
|
-
};
|
|
258
|
-
const normalizeD1Database = (database, index)=>{
|
|
259
|
-
const binding = assertNonEmptyString(database.binding, `deploy.worker.d1Databases[${index}].binding`);
|
|
260
|
-
const databaseName = assertNonEmptyString(database.databaseName, `deploy.worker.d1Databases[${index}].databaseName`);
|
|
261
|
-
const databaseId = assertNonEmptyString(database.databaseId, `deploy.worker.d1Databases[${index}].databaseId`);
|
|
262
|
-
const migrationsDir = void 0 === database.migrationsDir ? void 0 : normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
263
|
-
const previewDatabaseId = void 0 === database.previewDatabaseId ? void 0 : assertNonEmptyString(database.previewDatabaseId, `deploy.worker.d1Databases[${index}].previewDatabaseId`);
|
|
264
|
-
return {
|
|
265
|
-
binding,
|
|
266
|
-
database_name: databaseName,
|
|
267
|
-
database_id: databaseId,
|
|
268
|
-
...void 0 === migrationsDir ? {} : {
|
|
269
|
-
migrations_dir: migrationsDir
|
|
270
|
-
},
|
|
271
|
-
...void 0 === previewDatabaseId ? {} : {
|
|
272
|
-
preview_database_id: previewDatabaseId
|
|
273
|
-
},
|
|
274
|
-
...void 0 === database.remote ? {} : {
|
|
275
|
-
remote: database.remote
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
const createWranglerD1Databases = (modernConfig, configuredWranglerD1)=>{
|
|
280
|
-
const d1Databases = modernConfig.deploy?.worker?.d1Databases;
|
|
281
|
-
if (void 0 === d1Databases) return configuredWranglerD1;
|
|
282
|
-
if (void 0 !== configuredWranglerD1) throw new Error('Use deploy.worker.d1Databases or deploy.worker.wrangler.d1_databases, not both.');
|
|
283
|
-
if (!Array.isArray(d1Databases)) throw new Error('deploy.worker.d1Databases must be an array.');
|
|
284
|
-
return d1Databases.map(normalizeD1Database);
|
|
285
|
-
};
|
|
286
|
-
const createWranglerConfig = (appDirectory, modernConfig)=>{
|
|
287
|
-
const wrangler = getConfiguredWrangler(modernConfig);
|
|
288
|
-
const d1Databases = createWranglerD1Databases(modernConfig, wrangler.d1_databases);
|
|
289
|
-
return {
|
|
290
|
-
$schema: 'node_modules/wrangler/config-schema.json',
|
|
291
|
-
name: getConfiguredWorkerName(appDirectory, modernConfig),
|
|
292
|
-
compatibility_date: getCompatibilityDate(modernConfig),
|
|
293
|
-
...wrangler,
|
|
294
|
-
main: WORKER_ENTRY,
|
|
295
|
-
compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
|
|
296
|
-
assets: createWranglerAssetsConfig(wrangler.assets),
|
|
297
|
-
...void 0 === d1Databases ? {} : {
|
|
298
|
-
d1_databases: d1Databases
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
};
|
|
302
|
-
const normalizeCloudflareArtifact = (artifact, index)=>{
|
|
303
|
-
const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
|
|
304
|
-
const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
|
|
305
|
-
const [topLevelDestination] = to.split('/');
|
|
306
|
-
const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
|
|
307
|
-
if (RESERVED_ARTIFACT_DESTINATION_FILES.has(to) || RESERVED_ARTIFACT_DESTINATION_DIRECTORIES.has(topLevelDestination)) throw new Error(`deploy.worker.artifacts[${index}].to must not target generated Cloudflare output path ${JSON.stringify(reservedDestination)}.`);
|
|
308
|
-
return {
|
|
309
|
-
from,
|
|
310
|
-
to,
|
|
311
|
-
index
|
|
312
|
-
};
|
|
313
|
-
};
|
|
314
|
-
const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
|
|
315
|
-
const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
|
|
316
|
-
for (const artifact of artifacts){
|
|
317
|
-
const sourcePath = node_path.join(appDirectory, artifact.from);
|
|
318
|
-
if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
|
|
319
|
-
await fs.copy(sourcePath, node_path.join(outputDirectory, artifact.to));
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
const copyCloudflareD1Migrations = async (appDirectory, outputDirectory, modernConfig)=>{
|
|
323
|
-
for (const [index, database] of (modernConfig.deploy?.worker?.d1Databases ?? []).entries()){
|
|
324
|
-
if (!database.migrationsDir) continue;
|
|
325
|
-
const migrationsDir = normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
326
|
-
const sourcePath = node_path.join(appDirectory, migrationsDir);
|
|
327
|
-
if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.d1Databases[${index}].migrationsDir does not exist: ${migrationsDir}`);
|
|
328
|
-
await fs.copy(sourcePath, node_path.join(outputDirectory, migrationsDir));
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
const readRouteSpec = async (outputDirectory)=>{
|
|
332
|
-
const routeSpecPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
333
|
-
if (!await fs.pathExists(routeSpecPath)) return {
|
|
334
|
-
routes: []
|
|
335
|
-
};
|
|
336
|
-
const routeSpec = await fs.readJSON(routeSpecPath);
|
|
337
|
-
return {
|
|
338
|
-
...routeSpec,
|
|
339
|
-
routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
|
|
340
|
-
};
|
|
341
|
-
};
|
|
342
|
-
const createMissingEffectBffWorkerError = (outputDirectory, worker)=>new Error(`Cloudflare Effect API runtime is configured, but the BFF worker bundle is missing: ${node_path.join(outputDirectory, worker)}. ${EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE}`);
|
|
343
|
-
const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
344
|
-
const routeSpec = await readRouteSpec(outputDirectory);
|
|
345
|
-
const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
|
|
346
|
-
const worker = 'string' == typeof route.worker ? route.worker : void 0;
|
|
347
|
-
return {
|
|
348
|
-
urlPath: route.urlPath,
|
|
349
|
-
entryName: route.entryName,
|
|
350
|
-
entryPath: route.entryPath,
|
|
351
|
-
isSSR: Boolean(route.isSSR),
|
|
352
|
-
worker,
|
|
353
|
-
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false
|
|
354
|
-
};
|
|
355
|
-
}));
|
|
356
|
-
const bffPrefix = modernConfig.bff?.prefix;
|
|
357
|
-
const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
|
|
358
|
-
const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
|
|
359
|
-
const effectApiWorkerExists = await fs.pathExists(node_path.join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
|
|
360
|
-
if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
|
|
361
|
-
return {
|
|
362
|
-
version: 1,
|
|
363
|
-
runtime: {
|
|
364
|
-
type: 'cloudflare-module-worker',
|
|
365
|
-
entry: WORKER_ENTRY,
|
|
366
|
-
fetchExport: true,
|
|
367
|
-
nodeListen: false
|
|
368
|
-
},
|
|
369
|
-
assets: {
|
|
370
|
-
binding: ASSETS_BINDING,
|
|
371
|
-
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
372
|
-
runWorkerFirst: true
|
|
373
|
-
},
|
|
374
|
-
routeSpec: {
|
|
375
|
-
file: ROUTE_SPEC_OUTPUT,
|
|
376
|
-
routes
|
|
377
|
-
},
|
|
378
|
-
workerBundles: {
|
|
379
|
-
directory: WORKER_BUNDLE_DIRECTORY,
|
|
380
|
-
format: 'commonjs',
|
|
381
|
-
importableFromModuleWorker: true,
|
|
382
|
-
requestHandlerExport: 'requestHandler'
|
|
383
|
-
},
|
|
384
|
-
resources: {
|
|
385
|
-
loadableStats: LOADABLE_STATS_FILE,
|
|
386
|
-
routeManifest: ROUTE_MANIFEST_FILE
|
|
387
|
-
},
|
|
388
|
-
security: createCloudflareWorkerSecurityPolicy(modernConfig),
|
|
389
|
-
bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
|
|
390
|
-
runtimeFramework: 'effect',
|
|
391
|
-
prefix: primaryBffPrefix,
|
|
392
|
-
worker: BFF_EFFECT_WORKER_ENTRY
|
|
393
|
-
} : void 0
|
|
394
|
-
};
|
|
395
|
-
};
|
|
396
|
-
const createWorkerModuleLoaders = (manifest)=>{
|
|
397
|
-
const imports = new Map();
|
|
398
|
-
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
399
|
-
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
400
|
-
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
401
|
-
}
|
|
402
|
-
if (manifest.bff?.worker) {
|
|
403
|
-
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
404
|
-
imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
405
|
-
}
|
|
406
|
-
if (0 === imports.size) return '{}';
|
|
407
|
-
const loaders = [
|
|
408
|
-
...imports.entries()
|
|
409
|
-
].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
|
|
410
|
-
return `{\n${loaders.join(',\n')}\n}`;
|
|
411
|
-
};
|
|
412
|
-
const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
|
|
413
|
-
...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
|
|
414
|
-
try {
|
|
415
|
-
return fs.statSync(node_path.join(appDirectory, directory)).isDirectory();
|
|
416
|
-
} catch {
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
}),
|
|
420
|
-
...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
|
|
421
|
-
].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
|
|
422
|
-
const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
|
|
423
|
-
const relativePath = node_path.relative(distDirectory, src);
|
|
424
|
-
if (!relativePath) return true;
|
|
425
|
-
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
426
|
-
const [topLevelDirectory] = normalizedRelativePath.split('/');
|
|
427
|
-
return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY && !publicAssetExcludes.some((exclude)=>normalizedRelativePath === exclude || normalizedRelativePath.startsWith(`${exclude}/`));
|
|
428
|
-
};
|
|
429
|
-
const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
|
|
430
|
-
const relativePath = node_path.relative(workerBundleDirectory, src);
|
|
431
|
-
if (!relativePath) return true;
|
|
432
|
-
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
433
|
-
const basename = node_path.basename(normalizedRelativePath);
|
|
434
|
-
if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
|
|
435
|
-
if (fs.statSync(src).isDirectory()) return true;
|
|
436
|
-
return [
|
|
437
|
-
'.cjs',
|
|
438
|
-
'.js',
|
|
439
|
-
'.mjs'
|
|
440
|
-
].includes(node_path.extname(normalizedRelativePath));
|
|
441
|
-
};
|
|
442
|
-
const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
443
|
-
const { appDirectory, distDirectory } = appContext;
|
|
444
|
-
const outputDirectory = node_path.join(appDirectory, '.output');
|
|
445
|
-
const publicDirectory = node_path.join(outputDirectory, PUBLIC_ASSETS_DIRECTORY);
|
|
446
|
-
const workerEntryPath = node_path.join(outputDirectory, WORKER_ENTRY);
|
|
447
|
-
const workerManifestPath = node_path.join(outputDirectory, WORKER_MANIFEST);
|
|
448
|
-
const routeSpecOutputPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
449
|
-
const wranglerConfigPath = node_path.join(outputDirectory, WRANGLER_CONFIG_FILE);
|
|
450
|
-
const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
|
|
451
|
-
const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
|
|
452
|
-
return {
|
|
453
|
-
async prepare () {
|
|
454
|
-
await fs.remove(outputDirectory);
|
|
455
|
-
},
|
|
456
|
-
async writeOutput () {
|
|
457
|
-
await fs.copy(distDirectory, publicDirectory, {
|
|
458
|
-
filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
|
|
459
|
-
});
|
|
460
|
-
await fs.ensureDir(node_path.dirname(workerEntryPath));
|
|
461
|
-
await fs.ensureDir(node_path.dirname(workerManifestPath));
|
|
462
|
-
const routeSpecSourcePath = node_path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
463
|
-
if (await fs.pathExists(routeSpecSourcePath)) await fs.copy(routeSpecSourcePath, routeSpecOutputPath);
|
|
464
|
-
const workerBundleSourceDirectory = node_path.join(distDirectory, WORKER_BUNDLE_DIRECTORY);
|
|
465
|
-
const workerBundleOutputDirectory = node_path.join(outputDirectory, WORKER_BUNDLE_DIRECTORY);
|
|
466
|
-
if (await fs.pathExists(workerBundleSourceDirectory)) {
|
|
467
|
-
await fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
|
|
468
|
-
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
469
|
-
});
|
|
470
|
-
await fs.writeJSON(node_path.join(workerBundleOutputDirectory, 'package.json'), {
|
|
471
|
-
type: 'commonjs'
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
|
|
475
|
-
await copyCloudflareD1Migrations(appDirectory, outputDirectory, modernConfig);
|
|
476
|
-
await fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
|
|
477
|
-
spaces: 2
|
|
478
|
-
});
|
|
479
|
-
await fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig), {
|
|
480
|
-
spaces: 2
|
|
481
|
-
});
|
|
482
|
-
await fs.writeJSON(node_path.join(outputDirectory, OUTPUT_PACKAGE_FILE), {
|
|
483
|
-
type: 'module'
|
|
484
|
-
});
|
|
485
|
-
},
|
|
486
|
-
async genEntry () {
|
|
487
|
-
const template = await readTemplate('cloudflare-entry.mjs');
|
|
488
|
-
const manifest = await fs.readJSON(workerManifestPath);
|
|
489
|
-
await fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
};
|
|
493
|
-
export { createCloudflarePreset };
|