@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.6 → 3.5.0-ultramodern.76
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.js +0 -0
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +13 -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/commands/index.js +0 -4
- package/dist/cjs/config/build-environment.js +268 -0
- package/dist/cjs/config/index.js +11 -4
- package/dist/cjs/config/public.js +46 -0
- package/dist/cjs/index.js +39 -62
- package/dist/cjs/plugins/analyze/getServerRoutes.js +19 -0
- package/dist/cjs/plugins/analyze/index.js +20 -12
- 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/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/getBuilderEnvironments.mjs +12 -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/commands/index.mjs +0 -1
- package/dist/esm/config/build-environment.mjs +224 -0
- package/dist/esm/config/index.mjs +1 -0
- package/dist/esm/config/public.mjs +1 -0
- package/dist/esm/index.mjs +5 -4
- 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 +20 -12
- package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +2 -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/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/getBuilderEnvironments.mjs +12 -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/commands/index.mjs +0 -1
- package/dist/esm-node/config/build-environment.mjs +225 -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 +5 -4
- 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 +20 -12
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +2 -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/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/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 +0 -2
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
- 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/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/lib/types.d.ts +2 -3
- package/package.json +38 -23
- 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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
const DEFAULT_SECURITY_HEADERS = {
|
|
3
|
+
referrerPolicy: 'strict-origin-when-cross-origin',
|
|
4
|
+
contentTypeOptions: 'nosniff',
|
|
5
|
+
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
6
|
+
};
|
|
7
|
+
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
8
|
+
'GET',
|
|
9
|
+
'HEAD',
|
|
10
|
+
'POST',
|
|
11
|
+
'PUT',
|
|
12
|
+
'PATCH',
|
|
13
|
+
'DELETE',
|
|
14
|
+
'OPTIONS'
|
|
15
|
+
];
|
|
16
|
+
const DEFAULT_CSP_DIRECTIVES = {
|
|
17
|
+
'base-uri': [
|
|
18
|
+
"'self'"
|
|
19
|
+
],
|
|
20
|
+
'connect-src': [
|
|
21
|
+
"'self'",
|
|
22
|
+
'https:',
|
|
23
|
+
'http:',
|
|
24
|
+
'wss:',
|
|
25
|
+
'ws:'
|
|
26
|
+
],
|
|
27
|
+
'default-src': [
|
|
28
|
+
"'self'"
|
|
29
|
+
],
|
|
30
|
+
'font-src': [
|
|
31
|
+
"'self'",
|
|
32
|
+
'data:',
|
|
33
|
+
'https:',
|
|
34
|
+
'http:'
|
|
35
|
+
],
|
|
36
|
+
'form-action': [
|
|
37
|
+
"'self'"
|
|
38
|
+
],
|
|
39
|
+
'frame-ancestors': [
|
|
40
|
+
"'self'"
|
|
41
|
+
],
|
|
42
|
+
'img-src': [
|
|
43
|
+
"'self'",
|
|
44
|
+
'data:',
|
|
45
|
+
'blob:',
|
|
46
|
+
'https:',
|
|
47
|
+
'http:'
|
|
48
|
+
],
|
|
49
|
+
'manifest-src': [
|
|
50
|
+
"'self'",
|
|
51
|
+
'https:',
|
|
52
|
+
'http:'
|
|
53
|
+
],
|
|
54
|
+
'object-src': [
|
|
55
|
+
"'none'"
|
|
56
|
+
],
|
|
57
|
+
"script-src": [
|
|
58
|
+
"'self'",
|
|
59
|
+
"'unsafe-inline'",
|
|
60
|
+
"'unsafe-eval'",
|
|
61
|
+
'https:',
|
|
62
|
+
'http:',
|
|
63
|
+
'blob:'
|
|
64
|
+
],
|
|
65
|
+
'style-src': [
|
|
66
|
+
"'self'",
|
|
67
|
+
"'unsafe-inline'",
|
|
68
|
+
'https:',
|
|
69
|
+
'http:'
|
|
70
|
+
],
|
|
71
|
+
'worker-src': [
|
|
72
|
+
"'self'",
|
|
73
|
+
'blob:'
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
const normalizeDirectiveValues = (value)=>{
|
|
77
|
+
const values = Array.isArray(value) ? value : [
|
|
78
|
+
value
|
|
79
|
+
];
|
|
80
|
+
return [
|
|
81
|
+
...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
|
|
82
|
+
];
|
|
83
|
+
};
|
|
84
|
+
const appendDirectiveValues = (directives, name, values)=>{
|
|
85
|
+
if (!values?.length) return;
|
|
86
|
+
directives[name] = normalizeDirectiveValues([
|
|
87
|
+
...directives[name] ?? [],
|
|
88
|
+
...values
|
|
89
|
+
]);
|
|
90
|
+
};
|
|
91
|
+
const createContentSecurityPolicy = (config)=>{
|
|
92
|
+
const mode = config?.mode ?? 'report-only';
|
|
93
|
+
if ('off' === mode) return {
|
|
94
|
+
mode,
|
|
95
|
+
directives: {},
|
|
96
|
+
reason: config?.reason
|
|
97
|
+
};
|
|
98
|
+
const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
|
|
99
|
+
name,
|
|
100
|
+
[
|
|
101
|
+
...values
|
|
102
|
+
]
|
|
103
|
+
]));
|
|
104
|
+
for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
|
|
105
|
+
else directives[name] = normalizeDirectiveValues(value);
|
|
106
|
+
if (config?.frameAncestors === false) delete directives['frame-ancestors'];
|
|
107
|
+
else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
|
|
108
|
+
appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
|
|
109
|
+
appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
|
|
110
|
+
appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
|
|
111
|
+
appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
|
|
112
|
+
if (config?.reportUri) directives['report-uri'] = [
|
|
113
|
+
config.reportUri
|
|
114
|
+
];
|
|
115
|
+
return {
|
|
116
|
+
mode,
|
|
117
|
+
directives,
|
|
118
|
+
reason: config?.reason
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const createNoindexPolicy = (noindex)=>{
|
|
122
|
+
if (false === noindex) return {
|
|
123
|
+
workersDev: false,
|
|
124
|
+
localhost: false,
|
|
125
|
+
previewHostnames: []
|
|
126
|
+
};
|
|
127
|
+
if (true === noindex || void 0 === noindex) return {
|
|
128
|
+
workersDev: true,
|
|
129
|
+
localhost: true,
|
|
130
|
+
previewHostnames: []
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
workersDev: noindex.workersDev ?? true,
|
|
134
|
+
localhost: noindex.localhost ?? true,
|
|
135
|
+
previewHostnames: noindex.previewHostnames ?? [],
|
|
136
|
+
reason: noindex.reason
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
140
|
+
assets: cors?.assets ?? true,
|
|
141
|
+
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
142
|
+
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
143
|
+
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
144
|
+
'*'
|
|
145
|
+
],
|
|
146
|
+
reason: cors?.reason
|
|
147
|
+
});
|
|
148
|
+
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
149
|
+
const security = modernConfig.deploy?.worker?.security;
|
|
150
|
+
if (security?.enabled === false) return {
|
|
151
|
+
enabled: false,
|
|
152
|
+
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
153
|
+
reason: security.reason
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
enabled: true,
|
|
157
|
+
headers: {
|
|
158
|
+
referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
|
|
159
|
+
contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
|
|
160
|
+
permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
|
|
161
|
+
},
|
|
162
|
+
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
163
|
+
noindex: createNoindexPolicy(security?.noindex),
|
|
164
|
+
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
165
|
+
reason: security?.reason
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
export { createCloudflareWorkerSecurityPolicy };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
const isRecord = (value)=>null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
4
|
+
const normalizeRelativePath = (value, label, scope = 'app output', options = {})=>{
|
|
5
|
+
if ('string' != typeof value) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
6
|
+
const normalized = value.trim().replace(/\\/g, '/').replace(/^\.\/+/u, '').replace(/\/+$/u, '');
|
|
7
|
+
const segments = normalized.split('/');
|
|
8
|
+
const isRootDestination = '.' === normalized;
|
|
9
|
+
if (!normalized || node_path.isAbsolute(normalized) || !options.allowRoot && isRootDestination || segments.includes('..')) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
10
|
+
return normalized;
|
|
11
|
+
};
|
|
12
|
+
const isJsonRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
13
|
+
export { isJsonRecord, isRecord, normalizeRelativePath };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { fs } from "@modern-js/utils";
|
|
4
|
+
import { readRouteSpec } from "./artifacts.mjs";
|
|
5
|
+
import { ASSETS_BINDING, BFF_EFFECT_WORKER_DISPATCHER_EXPORT, BFF_EFFECT_WORKER_ENTRY, CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_BUNDLE_FORMAT, DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES, EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE, LOADABLE_STATS_FILE, PUBLIC_ASSETS_DIRECTORY, ROUTE_MANIFEST_FILE, ROUTE_SPEC_FILE, ROUTE_SPEC_OUTPUT, SERVER_BUNDLE_DIRECTORY, WORKER_BUNDLE_DIRECTORY, WORKER_ENTRY } from "./constants.mjs";
|
|
6
|
+
import { createI18nWorkerManifest } from "./i18n-worker.mjs";
|
|
7
|
+
import { createCloudflareWorkerSecurityPolicy } from "./security-policies.mjs";
|
|
8
|
+
import { isRecord, normalizeRelativePath } from "./utils.mjs";
|
|
9
|
+
import { createWorkerManifestServiceBindings, createWorkerServiceBindings } from "./wrangler-config.mjs";
|
|
10
|
+
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}`);
|
|
11
|
+
const createModuleFederationWorkerManifest = async (outputDirectory)=>{
|
|
12
|
+
const manifestPath = node_path.join(outputDirectory, PUBLIC_ASSETS_DIRECTORY, 'mf-manifest.json');
|
|
13
|
+
if (!await fs.pathExists(manifestPath)) return;
|
|
14
|
+
const manifest = await fs.readJson(manifestPath);
|
|
15
|
+
const name = isRecord(manifest) && 'string' == typeof manifest.name ? manifest.name : void 0;
|
|
16
|
+
const manifestExposes = isRecord(manifest) && Array.isArray(manifest.exposes) ? manifest.exposes : [];
|
|
17
|
+
const exposes = manifestExposes.filter(isRecord).flatMap((expose)=>{
|
|
18
|
+
if ('string' != typeof expose.path) return [];
|
|
19
|
+
const assets = isRecord(expose.assets) ? expose.assets : void 0;
|
|
20
|
+
const css = assets && isRecord(assets.css) ? assets.css : void 0;
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
path: expose.path,
|
|
24
|
+
css: [
|
|
25
|
+
...css && Array.isArray(css.sync) ? css.sync : [],
|
|
26
|
+
...css && Array.isArray(css.async) ? css.async : []
|
|
27
|
+
].filter((asset)=>'string' == typeof asset && asset.endsWith('.css'))
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
});
|
|
31
|
+
return name && exposes.length > 0 ? {
|
|
32
|
+
name,
|
|
33
|
+
exposes
|
|
34
|
+
} : void 0;
|
|
35
|
+
};
|
|
36
|
+
const createWorkerManifest = async (outputDirectory, modernConfig, appContext, deliveryUnitStamp)=>{
|
|
37
|
+
const routeSpec = await readRouteSpec(outputDirectory);
|
|
38
|
+
const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
|
|
39
|
+
const worker = 'string' == typeof route.worker ? route.worker : void 0;
|
|
40
|
+
return {
|
|
41
|
+
urlPath: route.urlPath,
|
|
42
|
+
entryName: route.entryName,
|
|
43
|
+
entryPath: route.entryPath,
|
|
44
|
+
isSSR: Boolean(route.isSSR),
|
|
45
|
+
worker,
|
|
46
|
+
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false
|
|
47
|
+
};
|
|
48
|
+
}));
|
|
49
|
+
const bffPrefix = modernConfig.bff?.prefix;
|
|
50
|
+
const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
|
|
51
|
+
const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
|
|
52
|
+
const effectApiWorkerExists = await fs.pathExists(node_path.join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
|
|
53
|
+
const serviceBindings = createWorkerManifestServiceBindings(createWorkerServiceBindings(modernConfig, void 0));
|
|
54
|
+
const moduleFederation = await createModuleFederationWorkerManifest(outputDirectory);
|
|
55
|
+
if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
|
|
56
|
+
return {
|
|
57
|
+
version: 1,
|
|
58
|
+
runtime: {
|
|
59
|
+
type: CLOUDFLARE_RUNTIME_TYPE,
|
|
60
|
+
entry: WORKER_ENTRY,
|
|
61
|
+
fetchExport: true,
|
|
62
|
+
nodeListen: false
|
|
63
|
+
},
|
|
64
|
+
assets: {
|
|
65
|
+
binding: ASSETS_BINDING,
|
|
66
|
+
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
67
|
+
runWorkerFirst: true
|
|
68
|
+
},
|
|
69
|
+
routeSpec: {
|
|
70
|
+
file: ROUTE_SPEC_OUTPUT,
|
|
71
|
+
routes
|
|
72
|
+
},
|
|
73
|
+
workerBundles: {
|
|
74
|
+
directory: WORKER_BUNDLE_DIRECTORY,
|
|
75
|
+
format: CLOUDFLARE_WORKER_BUNDLE_FORMAT,
|
|
76
|
+
importableFromModuleWorker: true,
|
|
77
|
+
requestHandlerExport: 'requestHandler'
|
|
78
|
+
},
|
|
79
|
+
resources: {
|
|
80
|
+
loadableStats: LOADABLE_STATS_FILE,
|
|
81
|
+
routeManifest: ROUTE_MANIFEST_FILE
|
|
82
|
+
},
|
|
83
|
+
security: createCloudflareWorkerSecurityPolicy(modernConfig),
|
|
84
|
+
...void 0 === moduleFederation ? {} : {
|
|
85
|
+
moduleFederation
|
|
86
|
+
},
|
|
87
|
+
...deliveryUnitStamp ? {
|
|
88
|
+
deliveryUnit: deliveryUnitStamp
|
|
89
|
+
} : {},
|
|
90
|
+
i18n: createI18nWorkerManifest(routeSpec, appContext),
|
|
91
|
+
bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
|
|
92
|
+
dispatcherExport: BFF_EFFECT_WORKER_DISPATCHER_EXPORT,
|
|
93
|
+
runtimeFramework: 'effect',
|
|
94
|
+
prefix: primaryBffPrefix,
|
|
95
|
+
worker: BFF_EFFECT_WORKER_ENTRY
|
|
96
|
+
} : void 0,
|
|
97
|
+
...void 0 === serviceBindings ? {} : {
|
|
98
|
+
serviceBindings
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const createWorkerModuleLoaders = (manifest)=>{
|
|
103
|
+
const imports = new Map();
|
|
104
|
+
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
105
|
+
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
106
|
+
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
107
|
+
}
|
|
108
|
+
if (manifest.bff?.worker) {
|
|
109
|
+
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
110
|
+
imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
111
|
+
}
|
|
112
|
+
if (0 === imports.size) return '{}';
|
|
113
|
+
const loaders = [
|
|
114
|
+
...imports.entries()
|
|
115
|
+
].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
|
|
116
|
+
return `{\n${loaders.join(',\n')}\n}`;
|
|
117
|
+
};
|
|
118
|
+
const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
|
|
119
|
+
...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
|
|
120
|
+
try {
|
|
121
|
+
return fs.statSync(node_path.join(appDirectory, directory)).isDirectory();
|
|
122
|
+
} catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
|
|
127
|
+
].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
|
|
128
|
+
const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
|
|
129
|
+
const relativePath = node_path.relative(distDirectory, src);
|
|
130
|
+
if (!relativePath) return true;
|
|
131
|
+
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
132
|
+
const [topLevelDirectory] = normalizedRelativePath.split('/');
|
|
133
|
+
const basename = normalizedRelativePath.split('/').pop() ?? '';
|
|
134
|
+
return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY && '.env' !== basename && !basename.startsWith('.env.') && !publicAssetExcludes.some((exclude)=>normalizedRelativePath === exclude || normalizedRelativePath.startsWith(`${exclude}/`));
|
|
135
|
+
};
|
|
136
|
+
const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
|
|
137
|
+
const relativePath = node_path.relative(workerBundleDirectory, src);
|
|
138
|
+
if (!relativePath) return true;
|
|
139
|
+
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
140
|
+
const basename = node_path.basename(normalizedRelativePath);
|
|
141
|
+
if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
|
|
142
|
+
if (fs.statSync(src).isDirectory()) return true;
|
|
143
|
+
return [
|
|
144
|
+
'.cjs',
|
|
145
|
+
'.js',
|
|
146
|
+
'.mjs'
|
|
147
|
+
].includes(node_path.extname(normalizedRelativePath));
|
|
148
|
+
};
|
|
149
|
+
export { createWorkerManifest, createWorkerModuleLoaders, getPublicAssetExcludes, shouldCopyToPublicAssets, shouldCopyToWorkerBundle };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { ASSETS_BINDING, COMPATIBILITY_DATE_PATTERN, DEFAULT_COMPATIBILITY_DATE, PUBLIC_ASSETS_DIRECTORY, REQUIRED_COMPATIBILITY_FLAGS, WORKER_ENTRY } from "./constants.mjs";
|
|
4
|
+
import { isJsonRecord, normalizeRelativePath } from "./utils.mjs";
|
|
5
|
+
const getCompatibilityDate = (modernConfig)=>{
|
|
6
|
+
const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
|
|
7
|
+
const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
|
|
8
|
+
if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
|
|
9
|
+
return compatibilityDate;
|
|
10
|
+
};
|
|
11
|
+
const getWorkerName = (appDirectory)=>{
|
|
12
|
+
const basename = node_path.basename(appDirectory);
|
|
13
|
+
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
14
|
+
};
|
|
15
|
+
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
16
|
+
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
17
|
+
return configuredName || getWorkerName(appDirectory);
|
|
18
|
+
};
|
|
19
|
+
const getConfiguredWrangler = (modernConfig)=>{
|
|
20
|
+
const wrangler = modernConfig.deploy?.worker?.wrangler;
|
|
21
|
+
if (void 0 === wrangler) return {};
|
|
22
|
+
if (!isJsonRecord(wrangler)) throw new Error('deploy.worker.wrangler must be a JSON object.');
|
|
23
|
+
return wrangler;
|
|
24
|
+
};
|
|
25
|
+
const createWranglerCompatibilityFlags = (configuredFlags)=>{
|
|
26
|
+
if (void 0 === configuredFlags) return [
|
|
27
|
+
...REQUIRED_COMPATIBILITY_FLAGS
|
|
28
|
+
];
|
|
29
|
+
if (!Array.isArray(configuredFlags) || configuredFlags.some((flag)=>'string' != typeof flag)) throw new Error('deploy.worker.wrangler.compatibility_flags must be an array of strings.');
|
|
30
|
+
return [
|
|
31
|
+
...new Set([
|
|
32
|
+
...configuredFlags,
|
|
33
|
+
...REQUIRED_COMPATIBILITY_FLAGS
|
|
34
|
+
])
|
|
35
|
+
];
|
|
36
|
+
};
|
|
37
|
+
const createWranglerAssetsConfig = (configuredAssets)=>{
|
|
38
|
+
if (void 0 !== configuredAssets && !isJsonRecord(configuredAssets)) throw new Error('deploy.worker.wrangler.assets must be an object.');
|
|
39
|
+
return {
|
|
40
|
+
...isJsonRecord(configuredAssets) ? configuredAssets : {},
|
|
41
|
+
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
42
|
+
binding: ASSETS_BINDING,
|
|
43
|
+
run_worker_first: true
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const assertNonEmptyString = (value, label)=>{
|
|
47
|
+
if ('string' != typeof value || 0 === value.trim().length) throw new Error(`${label} must be a non-empty string.`);
|
|
48
|
+
return value.trim();
|
|
49
|
+
};
|
|
50
|
+
const normalizeD1Database = (database, index)=>{
|
|
51
|
+
const binding = assertNonEmptyString(database.binding, `deploy.worker.d1Databases[${index}].binding`);
|
|
52
|
+
const databaseName = assertNonEmptyString(database.databaseName, `deploy.worker.d1Databases[${index}].databaseName`);
|
|
53
|
+
const databaseId = assertNonEmptyString(database.databaseId, `deploy.worker.d1Databases[${index}].databaseId`);
|
|
54
|
+
const migrationsDir = void 0 === database.migrationsDir ? void 0 : normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
55
|
+
const previewDatabaseId = void 0 === database.previewDatabaseId ? void 0 : assertNonEmptyString(database.previewDatabaseId, `deploy.worker.d1Databases[${index}].previewDatabaseId`);
|
|
56
|
+
return {
|
|
57
|
+
binding,
|
|
58
|
+
database_name: databaseName,
|
|
59
|
+
database_id: databaseId,
|
|
60
|
+
...void 0 === migrationsDir ? {} : {
|
|
61
|
+
migrations_dir: migrationsDir
|
|
62
|
+
},
|
|
63
|
+
...void 0 === previewDatabaseId ? {} : {
|
|
64
|
+
preview_database_id: previewDatabaseId
|
|
65
|
+
},
|
|
66
|
+
...void 0 === database.remote ? {} : {
|
|
67
|
+
remote: database.remote
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const createWranglerD1Databases = (modernConfig, configuredWranglerD1)=>{
|
|
72
|
+
const d1Databases = modernConfig.deploy?.worker?.d1Databases;
|
|
73
|
+
if (void 0 === d1Databases) return configuredWranglerD1;
|
|
74
|
+
if (void 0 !== configuredWranglerD1) throw new Error('Use deploy.worker.d1Databases or deploy.worker.wrangler.d1_databases, not both.');
|
|
75
|
+
if (!Array.isArray(d1Databases)) throw new Error('deploy.worker.d1Databases must be an array.');
|
|
76
|
+
return d1Databases.map(normalizeD1Database);
|
|
77
|
+
};
|
|
78
|
+
const normalizeServiceBinding = (service, index)=>{
|
|
79
|
+
const binding = assertNonEmptyString(service.binding, `deploy.worker.services[${index}].binding`);
|
|
80
|
+
const serviceName = assertNonEmptyString(service.service, `deploy.worker.services[${index}].service`);
|
|
81
|
+
const prefix = void 0 === service.prefix ? void 0 : assertNonEmptyString(service.prefix, `deploy.worker.services[${index}].prefix`);
|
|
82
|
+
if (void 0 !== service.fragments && !Array.isArray(service.fragments)) throw new Error(`deploy.worker.services[${index}].fragments must be an array.`);
|
|
83
|
+
const fragments = void 0 === service.fragments ? void 0 : service.fragments.map((fragment, fragmentIndex)=>({
|
|
84
|
+
remote: assertNonEmptyString(fragment.remote, `deploy.worker.services[${index}].fragments[${fragmentIndex}].remote`),
|
|
85
|
+
expose: assertNonEmptyString(fragment.expose, `deploy.worker.services[${index}].fragments[${fragmentIndex}].expose`),
|
|
86
|
+
boundaryId: assertNonEmptyString(fragment.boundaryId, `deploy.worker.services[${index}].fragments[${fragmentIndex}].boundaryId`),
|
|
87
|
+
path: assertNonEmptyString(fragment.path, `deploy.worker.services[${index}].fragments[${fragmentIndex}].path`)
|
|
88
|
+
}));
|
|
89
|
+
return {
|
|
90
|
+
binding,
|
|
91
|
+
service: serviceName,
|
|
92
|
+
...void 0 === prefix ? {} : {
|
|
93
|
+
prefix
|
|
94
|
+
},
|
|
95
|
+
...void 0 === fragments ? {} : {
|
|
96
|
+
fragments
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const createWorkerServiceBindings = (modernConfig, configuredWranglerServices)=>{
|
|
101
|
+
const services = modernConfig.deploy?.worker?.services;
|
|
102
|
+
if (void 0 === services) return configuredWranglerServices;
|
|
103
|
+
if (void 0 !== configuredWranglerServices) throw new Error('Use deploy.worker.services or deploy.worker.wrangler.services, not both.');
|
|
104
|
+
if (!Array.isArray(services)) throw new Error('deploy.worker.services must be an array.');
|
|
105
|
+
return services.map(normalizeServiceBinding);
|
|
106
|
+
};
|
|
107
|
+
const createWranglerServices = (serviceBindings)=>{
|
|
108
|
+
if (!Array.isArray(serviceBindings)) return serviceBindings;
|
|
109
|
+
if (!serviceBindings.every(isJsonRecord)) return serviceBindings;
|
|
110
|
+
return serviceBindings.map((service)=>{
|
|
111
|
+
const { prefix, fragments, ...wranglerService } = service;
|
|
112
|
+
return wranglerService;
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const createWorkerManifestServiceBindings = (serviceBindings)=>{
|
|
116
|
+
if (!Array.isArray(serviceBindings)) return;
|
|
117
|
+
const manifestBindings = serviceBindings.filter((service)=>isJsonRecord(service) && 'string' == typeof service.binding && 'string' == typeof service.service && ('string' == typeof service.prefix || Array.isArray(service.fragments) && service.fragments.length > 0)).map((service)=>({
|
|
118
|
+
binding: service.binding,
|
|
119
|
+
service: service.service,
|
|
120
|
+
interface: 'fetch',
|
|
121
|
+
...void 0 === service.prefix ? {} : {
|
|
122
|
+
prefix: service.prefix
|
|
123
|
+
},
|
|
124
|
+
...void 0 === service.fragments ? {} : {
|
|
125
|
+
fragments: service.fragments
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
return manifestBindings.length > 0 ? manifestBindings : void 0;
|
|
129
|
+
};
|
|
130
|
+
const createWranglerConfig = (appDirectory, modernConfig)=>{
|
|
131
|
+
const wrangler = getConfiguredWrangler(modernConfig);
|
|
132
|
+
const d1Databases = createWranglerD1Databases(modernConfig, wrangler.d1_databases);
|
|
133
|
+
const serviceBindings = createWorkerServiceBindings(modernConfig, wrangler.services);
|
|
134
|
+
const wranglerServices = createWranglerServices(serviceBindings);
|
|
135
|
+
return {
|
|
136
|
+
$schema: 'node_modules/wrangler/config-schema.json',
|
|
137
|
+
name: getConfiguredWorkerName(appDirectory, modernConfig),
|
|
138
|
+
compatibility_date: getCompatibilityDate(modernConfig),
|
|
139
|
+
...wrangler,
|
|
140
|
+
main: WORKER_ENTRY,
|
|
141
|
+
compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
|
|
142
|
+
assets: createWranglerAssetsConfig(wrangler.assets),
|
|
143
|
+
...void 0 === d1Databases ? {} : {
|
|
144
|
+
d1_databases: d1Databases
|
|
145
|
+
},
|
|
146
|
+
...void 0 === wranglerServices ? {} : {
|
|
147
|
+
services: wranglerServices
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
export { createWorkerManifestServiceBindings, createWorkerServiceBindings, createWranglerConfig };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
const CLOUDFLARE_WORKER_ENTRY = 'server/index.mjs';
|
|
3
|
+
const CLOUDFLARE_WORKER_MANIFEST = 'server/modern-worker-manifest.json';
|
|
4
|
+
const CLOUDFLARE_WRANGLER_CONFIG_FILE = 'wrangler.json';
|
|
5
|
+
const CLOUDFLARE_OUTPUT_PACKAGE_FILE = 'package.json';
|
|
6
|
+
const CLOUDFLARE_WORKER_PACKAGE_FILE = 'worker/package.json';
|
|
7
|
+
const CLOUDFLARE_ASSETS_BINDING = 'ASSETS';
|
|
8
|
+
const CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY = 'public';
|
|
9
|
+
const CLOUDFLARE_WORKER_BUNDLE_DIRECTORY = 'worker';
|
|
10
|
+
const CLOUDFLARE_RUNTIME_TYPE = 'cloudflare-module-worker';
|
|
11
|
+
const CLOUDFLARE_OUTPUT_PACKAGE_TYPE = 'module';
|
|
12
|
+
const CLOUDFLARE_WORKER_PACKAGE_TYPE = 'commonjs';
|
|
13
|
+
const CLOUDFLARE_WORKER_BUNDLE_FORMAT = 'commonjs';
|
|
14
|
+
const CLOUDFLARE_WORKER_NODE_BUILTINS = [
|
|
15
|
+
'async_hooks',
|
|
16
|
+
'buffer',
|
|
17
|
+
'crypto',
|
|
18
|
+
'events',
|
|
19
|
+
'fs/promises',
|
|
20
|
+
'module',
|
|
21
|
+
'path',
|
|
22
|
+
'process',
|
|
23
|
+
'stream',
|
|
24
|
+
'string_decoder',
|
|
25
|
+
'url',
|
|
26
|
+
'util'
|
|
27
|
+
];
|
|
28
|
+
const CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS = [
|
|
29
|
+
'nodejs_compat',
|
|
30
|
+
'global_fetch_strictly_public'
|
|
31
|
+
];
|
|
32
|
+
export { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_OUTPUT_PACKAGE_FILE, CLOUDFLARE_OUTPUT_PACKAGE_TYPE, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS, CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY, CLOUDFLARE_WORKER_BUNDLE_FORMAT, CLOUDFLARE_WORKER_ENTRY, CLOUDFLARE_WORKER_MANIFEST, CLOUDFLARE_WORKER_NODE_BUILTINS, CLOUDFLARE_WORKER_PACKAGE_FILE, CLOUDFLARE_WORKER_PACKAGE_TYPE, CLOUDFLARE_WRANGLER_CONFIG_FILE };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_OUTPUT_PACKAGE_FILE, CLOUDFLARE_OUTPUT_PACKAGE_TYPE, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY, CLOUDFLARE_WORKER_ENTRY, CLOUDFLARE_WORKER_MANIFEST, CLOUDFLARE_WORKER_PACKAGE_FILE, CLOUDFLARE_WORKER_PACKAGE_TYPE, CLOUDFLARE_WRANGLER_CONFIG_FILE } from "./cloudflare-output-contract.mjs";
|
|
4
|
+
const resolveOutput = (outputDirectory, relativePath)=>node_path.join(outputDirectory, relativePath);
|
|
5
|
+
function createCloudflareOutputPlan(outputDirectory) {
|
|
6
|
+
return {
|
|
7
|
+
outputDirectory,
|
|
8
|
+
requiredFiles: [
|
|
9
|
+
CLOUDFLARE_WORKER_ENTRY,
|
|
10
|
+
CLOUDFLARE_WORKER_MANIFEST,
|
|
11
|
+
CLOUDFLARE_WRANGLER_CONFIG_FILE,
|
|
12
|
+
CLOUDFLARE_OUTPUT_PACKAGE_FILE
|
|
13
|
+
],
|
|
14
|
+
publicLeakDirectories: [
|
|
15
|
+
'server',
|
|
16
|
+
CLOUDFLARE_WORKER_BUNDLE_DIRECTORY
|
|
17
|
+
],
|
|
18
|
+
paths: {
|
|
19
|
+
workerEntry: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_ENTRY),
|
|
20
|
+
workerManifest: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_MANIFEST),
|
|
21
|
+
wranglerConfig: resolveOutput(outputDirectory, CLOUDFLARE_WRANGLER_CONFIG_FILE),
|
|
22
|
+
outputPackage: resolveOutput(outputDirectory, CLOUDFLARE_OUTPUT_PACKAGE_FILE),
|
|
23
|
+
workerPackage: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_PACKAGE_FILE),
|
|
24
|
+
publicAssets: resolveOutput(outputDirectory, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY),
|
|
25
|
+
workerBundle: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY)
|
|
26
|
+
},
|
|
27
|
+
packages: {
|
|
28
|
+
output: {
|
|
29
|
+
type: CLOUDFLARE_OUTPUT_PACKAGE_TYPE
|
|
30
|
+
},
|
|
31
|
+
worker: {
|
|
32
|
+
type: CLOUDFLARE_WORKER_PACKAGE_TYPE
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
wrangler: {
|
|
36
|
+
main: CLOUDFLARE_WORKER_ENTRY,
|
|
37
|
+
assets: {
|
|
38
|
+
binding: CLOUDFLARE_ASSETS_BINDING,
|
|
39
|
+
directory: `./${CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY}`,
|
|
40
|
+
run_worker_first: true
|
|
41
|
+
},
|
|
42
|
+
requiredCompatibilityFlags: CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export { createCloudflareOutputPlan };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { DELIVERY_UNIT_IDENTITY_FIELDS, deliveryUnitIdentityFieldValue } from "@modern-js/utils/universal";
|
|
3
|
+
import { addIssue, assertEqual } from "./issues.mjs";
|
|
4
|
+
const verifyDeliveryUnitIdentity = (issues, manifest, manifestPath, declared)=>{
|
|
5
|
+
const stamped = manifest?.deliveryUnit;
|
|
6
|
+
const hasStamp = Boolean(stamped) && 'object' == typeof stamped;
|
|
7
|
+
if (declared) {
|
|
8
|
+
if (!hasStamp) return void addIssue(issues, {
|
|
9
|
+
code: 'missing-delivery-unit',
|
|
10
|
+
message: `Cloudflare worker manifest is missing the delivery-unit identity declared by the workspace topology (expected unitId ${declared.unitId}, buildMarker ${declared.buildMarker}).`,
|
|
11
|
+
path: manifestPath
|
|
12
|
+
});
|
|
13
|
+
for (const field of DELIVERY_UNIT_IDENTITY_FIELDS){
|
|
14
|
+
const stampedValue = deliveryUnitIdentityFieldValue(stamped, field);
|
|
15
|
+
assertEqual(issues, stampedValue, declared[field], {
|
|
16
|
+
code: 'delivery-unit-drift',
|
|
17
|
+
message: `Cloudflare worker manifest deliveryUnit.${field} must match the topology delivery-unit record (expected ${declared[field]}, received ${stampedValue ?? 'undefined'}).`,
|
|
18
|
+
path: manifestPath
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (hasStamp && stamped.surfaces && 'object' == typeof stamped.surfaces) for (const surface of [
|
|
23
|
+
'ui',
|
|
24
|
+
'api'
|
|
25
|
+
]){
|
|
26
|
+
const marker = stamped.surfaces[surface];
|
|
27
|
+
if (!marker || 'object' != typeof marker) {
|
|
28
|
+
addIssue(issues, {
|
|
29
|
+
code: 'missing-delivery-unit',
|
|
30
|
+
message: `Cloudflare worker manifest is missing the ${surface} delivery-unit surface marker.`,
|
|
31
|
+
path: manifestPath
|
|
32
|
+
});
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
for (const field of DELIVERY_UNIT_IDENTITY_FIELDS){
|
|
36
|
+
const markerValue = deliveryUnitIdentityFieldValue(marker, field);
|
|
37
|
+
const stampedValue = deliveryUnitIdentityFieldValue(stamped, field);
|
|
38
|
+
assertEqual(issues, markerValue, stampedValue, {
|
|
39
|
+
code: 'delivery-unit-drift',
|
|
40
|
+
message: `Cloudflare worker manifest ${surface} surface deliveryUnit.${field} must derive from one delivery-unit record (expected ${stampedValue ?? 'undefined'}, received ${markerValue ?? 'undefined'}).`,
|
|
41
|
+
path: manifestPath
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export { verifyDeliveryUnitIdentity };
|