@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.3 → 3.5.0-ultramodern.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -0
  2. package/dist/cjs/index.js +50 -44
  3. package/dist/cjs/plugins/backend-federation/codegen.js +208 -0
  4. package/dist/cjs/plugins/backend-federation/config.js +217 -0
  5. package/dist/cjs/plugins/backend-federation/emit.js +139 -0
  6. package/dist/cjs/plugins/backendFederationBuild.js +53 -0
  7. package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
  8. package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
  9. package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +118 -0
  10. package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
  11. package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
  12. package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +223 -0
  13. package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
  14. package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
  15. package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
  16. package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
  17. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
  18. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
  19. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
  20. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
  21. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/issues.js +54 -0
  22. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
  23. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +158 -0
  24. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +137 -0
  25. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +62 -0
  26. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +2 -502
  27. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  28. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  29. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  30. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  31. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  32. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  33. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +1 -0
  34. package/dist/esm/index.mjs +2 -0
  35. package/dist/esm/plugins/backend-federation/codegen.mjs +157 -0
  36. package/dist/esm/plugins/backend-federation/config.mjs +141 -0
  37. package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
  38. package/dist/esm/plugins/backendFederationBuild.mjs +1 -0
  39. package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
  40. package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
  41. package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +67 -0
  42. package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
  43. package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
  44. package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
  45. package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
  46. package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
  47. package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
  48. package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
  49. package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
  50. package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
  51. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
  52. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
  53. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
  54. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
  55. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
  56. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
  57. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -0
  58. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +1 -492
  59. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  60. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  61. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  62. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  63. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  64. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  65. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +1 -0
  66. package/dist/esm-node/index.mjs +2 -0
  67. package/dist/esm-node/plugins/backend-federation/codegen.mjs +158 -0
  68. package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
  69. package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
  70. package/dist/esm-node/plugins/backendFederationBuild.mjs +2 -0
  71. package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
  72. package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
  73. package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +68 -0
  74. package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
  75. package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
  76. package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
  77. package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
  78. package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
  79. package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
  80. package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
  81. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
  82. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
  83. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
  84. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
  85. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
  86. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
  87. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
  88. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
  89. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +2 -0
  90. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +1 -492
  91. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  92. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  93. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  94. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  95. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  96. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  97. package/dist/types/plugins/backend-federation/codegen.d.ts +82 -0
  98. package/dist/types/plugins/backend-federation/config.d.ts +103 -0
  99. package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
  100. package/dist/types/plugins/backendFederationBuild.d.ts +2 -0
  101. package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
  102. package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
  103. package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
  104. package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +21 -0
  105. package/dist/types/plugins/deploy/platforms/cloudflare/index.d.ts +2 -0
  106. package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +88 -0
  107. package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
  108. package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
  109. package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +100 -0
  110. package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
  111. package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
  112. package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +33 -0
  113. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
  114. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
  115. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
  116. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
  117. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +13 -0
  118. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +16 -0
  119. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +1 -0
  120. package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +1 -2
  121. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
  122. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
  123. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
  124. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
  125. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
  126. package/dist/types/types/config/cloudflareDeploy.d.ts +22 -0
  127. package/dist/types/types/config/deploy.d.ts +15 -2
  128. package/lib/types.d.ts +2 -3
  129. package/package.json +17 -11
  130. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  131. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  132. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  133. /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
@@ -0,0 +1,79 @@
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
+ import { createCloudflareOutputPlan } from "../cloudflare-output-plan.mjs";
6
+ import { assertCloudflareOutput } from "../cloudflare-output-verifier.mjs";
7
+ import { copyCloudflareArtifacts, copyCloudflareD1Migrations, copyCloudflarePublicAssets, getCloudflareArtifacts, getCloudflarePublicAssets } from "./artifacts.mjs";
8
+ import { ROUTE_SPEC_FILE, ROUTE_SPEC_OUTPUT, WORKER_BUNDLE_DIRECTORY } from "./constants.mjs";
9
+ import { resolveTopologyDeliveryUnit, resolveWorkerDeliveryUnitStamp } from "./delivery-unit.mjs";
10
+ import { createWorkerManifest, createWorkerModuleLoaders, getPublicAssetExcludes, shouldCopyToPublicAssets, shouldCopyToWorkerBundle } from "./worker-manifest.mjs";
11
+ import { createWranglerConfig } from "./wrangler-config.mjs";
12
+ const CLOUDFLARE_ENTRY_TEMPLATE_FRAGMENTS = [
13
+ 'cloudflare-entry.001-bootstrap-security.mjs',
14
+ 'cloudflare-entry.002-assets-routes.mjs',
15
+ 'cloudflare-entry.003-i18n-locales.mjs',
16
+ 'cloudflare-entry.004-rendering-css.mjs',
17
+ 'cloudflare-entry.005-worker-dispatch.mjs',
18
+ 'cloudflare-entry.006-fetch-handler.mjs'
19
+ ];
20
+ const readCloudflareEntryTemplate = async ()=>(await Promise.all(CLOUDFLARE_ENTRY_TEMPLATE_FRAGMENTS.map((fragment)=>readTemplate(fragment)))).join('');
21
+ const createCloudflarePreset = ({ appContext, modernConfig })=>{
22
+ const { appDirectory, distDirectory } = appContext;
23
+ const outputDirectory = node_path.join(appDirectory, '.output');
24
+ const outputPlan = createCloudflareOutputPlan(outputDirectory);
25
+ const publicDirectory = outputPlan.paths.publicAssets;
26
+ const workerEntryPath = outputPlan.paths.workerEntry;
27
+ const workerManifestPath = outputPlan.paths.workerManifest;
28
+ const routeSpecOutputPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
29
+ const wranglerConfigPath = outputPlan.paths.wranglerConfig;
30
+ const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
31
+ const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
32
+ return {
33
+ async prepare () {
34
+ await fs.remove(outputDirectory);
35
+ },
36
+ async writeOutput () {
37
+ await fs.copy(distDirectory, publicDirectory, {
38
+ filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
39
+ });
40
+ await fs.ensureDir(node_path.dirname(workerEntryPath));
41
+ await fs.ensureDir(node_path.dirname(workerManifestPath));
42
+ const routeSpecSourcePath = node_path.join(distDirectory, ROUTE_SPEC_FILE);
43
+ if (await fs.pathExists(routeSpecSourcePath)) await fs.copy(routeSpecSourcePath, routeSpecOutputPath);
44
+ const workerBundleSourceDirectory = node_path.join(distDirectory, WORKER_BUNDLE_DIRECTORY);
45
+ const workerBundleOutputDirectory = outputPlan.paths.workerBundle;
46
+ if (await fs.pathExists(workerBundleSourceDirectory)) {
47
+ await fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
48
+ filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
49
+ });
50
+ await fs.writeJSON(outputPlan.paths.workerPackage, outputPlan.packages.worker);
51
+ }
52
+ await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
53
+ await copyCloudflarePublicAssets(appDirectory, publicDirectory, getCloudflarePublicAssets(modernConfig));
54
+ await copyCloudflareD1Migrations(appDirectory, outputDirectory, modernConfig);
55
+ await fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
56
+ spaces: 2
57
+ });
58
+ const deliveryUnitStamp = await resolveWorkerDeliveryUnitStamp(appDirectory);
59
+ await fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig, appContext, deliveryUnitStamp), {
60
+ spaces: 2
61
+ });
62
+ await fs.writeJSON(outputPlan.paths.outputPackage, outputPlan.packages.output);
63
+ },
64
+ async genEntry () {
65
+ const template = await readCloudflareEntryTemplate();
66
+ const manifest = await fs.readJSON(workerManifestPath);
67
+ await fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
68
+ const topologyDeliveryUnit = await resolveTopologyDeliveryUnit(appDirectory);
69
+ await assertCloudflareOutput({
70
+ outputDirectory,
71
+ importWorker: false,
72
+ ...topologyDeliveryUnit ? {
73
+ deliveryUnit: topologyDeliveryUnit
74
+ } : {}
75
+ });
76
+ }
77
+ };
78
+ };
79
+ export { createCloudflarePreset };
@@ -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 { DEFAULT_CORS_ALLOWED_METHODS, DEFAULT_CSP_DIRECTIVES, DEFAULT_SECURITY_HEADERS, createCloudflareWorkerCorsPolicy, createCloudflareWorkerSecurityPolicy, createContentSecurityPolicy, createNoindexPolicy };
@@ -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,119 @@
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_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 { 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 createWorkerManifest = async (outputDirectory, modernConfig, appContext, deliveryUnitStamp)=>{
12
+ const routeSpec = await readRouteSpec(outputDirectory);
13
+ const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
14
+ const worker = 'string' == typeof route.worker ? route.worker : void 0;
15
+ return {
16
+ urlPath: route.urlPath,
17
+ entryName: route.entryName,
18
+ entryPath: route.entryPath,
19
+ isSSR: Boolean(route.isSSR),
20
+ worker,
21
+ workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false
22
+ };
23
+ }));
24
+ const bffPrefix = modernConfig.bff?.prefix;
25
+ const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
26
+ const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
27
+ const effectApiWorkerExists = await fs.pathExists(node_path.join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
28
+ const serviceBindings = createWorkerManifestServiceBindings(createWorkerServiceBindings(modernConfig, void 0));
29
+ if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
30
+ return {
31
+ version: 1,
32
+ runtime: {
33
+ type: CLOUDFLARE_RUNTIME_TYPE,
34
+ entry: WORKER_ENTRY,
35
+ fetchExport: true,
36
+ nodeListen: false
37
+ },
38
+ assets: {
39
+ binding: ASSETS_BINDING,
40
+ directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
41
+ runWorkerFirst: true
42
+ },
43
+ routeSpec: {
44
+ file: ROUTE_SPEC_OUTPUT,
45
+ routes
46
+ },
47
+ workerBundles: {
48
+ directory: WORKER_BUNDLE_DIRECTORY,
49
+ format: CLOUDFLARE_WORKER_BUNDLE_FORMAT,
50
+ importableFromModuleWorker: true,
51
+ requestHandlerExport: 'requestHandler'
52
+ },
53
+ resources: {
54
+ loadableStats: LOADABLE_STATS_FILE,
55
+ routeManifest: ROUTE_MANIFEST_FILE
56
+ },
57
+ security: createCloudflareWorkerSecurityPolicy(modernConfig),
58
+ ...deliveryUnitStamp ? {
59
+ deliveryUnit: deliveryUnitStamp
60
+ } : {},
61
+ i18n: createI18nWorkerManifest(routeSpec, appContext),
62
+ bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
63
+ runtimeFramework: 'effect',
64
+ prefix: primaryBffPrefix,
65
+ worker: BFF_EFFECT_WORKER_ENTRY
66
+ } : void 0,
67
+ ...void 0 === serviceBindings ? {} : {
68
+ serviceBindings
69
+ }
70
+ };
71
+ };
72
+ const createWorkerModuleLoaders = (manifest)=>{
73
+ const imports = new Map();
74
+ for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
75
+ const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
76
+ imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
77
+ }
78
+ if (manifest.bff?.worker) {
79
+ const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
80
+ imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
81
+ }
82
+ if (0 === imports.size) return '{}';
83
+ const loaders = [
84
+ ...imports.entries()
85
+ ].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
86
+ return `{\n${loaders.join(',\n')}\n}`;
87
+ };
88
+ const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
89
+ ...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
90
+ try {
91
+ return fs.statSync(node_path.join(appDirectory, directory)).isDirectory();
92
+ } catch {
93
+ return false;
94
+ }
95
+ }),
96
+ ...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
97
+ ].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
98
+ const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
99
+ const relativePath = node_path.relative(distDirectory, src);
100
+ if (!relativePath) return true;
101
+ const normalizedRelativePath = relativePath.replace(/\\/g, '/');
102
+ const [topLevelDirectory] = normalizedRelativePath.split('/');
103
+ const basename = normalizedRelativePath.split('/').pop() ?? '';
104
+ 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}/`));
105
+ };
106
+ const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
107
+ const relativePath = node_path.relative(workerBundleDirectory, src);
108
+ if (!relativePath) return true;
109
+ const normalizedRelativePath = relativePath.replace(/\\/g, '/');
110
+ const basename = node_path.basename(normalizedRelativePath);
111
+ if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
112
+ if (fs.statSync(src).isDirectory()) return true;
113
+ return [
114
+ '.cjs',
115
+ '.js',
116
+ '.mjs'
117
+ ].includes(node_path.extname(normalizedRelativePath));
118
+ };
119
+ export { createWorkerManifest, createWorkerModuleLoaders, getPublicAssetExcludes, shouldCopyToPublicAssets, shouldCopyToWorkerBundle };
@@ -0,0 +1,136 @@
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
+ return {
83
+ binding,
84
+ service: serviceName,
85
+ ...void 0 === prefix ? {} : {
86
+ prefix
87
+ }
88
+ };
89
+ };
90
+ const createWorkerServiceBindings = (modernConfig, configuredWranglerServices)=>{
91
+ const services = modernConfig.deploy?.worker?.services;
92
+ if (void 0 === services) return configuredWranglerServices;
93
+ if (void 0 !== configuredWranglerServices) throw new Error('Use deploy.worker.services or deploy.worker.wrangler.services, not both.');
94
+ if (!Array.isArray(services)) throw new Error('deploy.worker.services must be an array.');
95
+ return services.map(normalizeServiceBinding);
96
+ };
97
+ const createWranglerServices = (serviceBindings)=>{
98
+ if (!Array.isArray(serviceBindings)) return serviceBindings;
99
+ if (!serviceBindings.every(isJsonRecord)) return serviceBindings;
100
+ return serviceBindings.map((service)=>{
101
+ const { prefix, ...wranglerService } = service;
102
+ return wranglerService;
103
+ });
104
+ };
105
+ const createWorkerManifestServiceBindings = (serviceBindings)=>{
106
+ if (!Array.isArray(serviceBindings)) return;
107
+ const dispatchBindings = serviceBindings.filter((service)=>isJsonRecord(service) && 'string' == typeof service.binding && 'string' == typeof service.service && 'string' == typeof service.prefix).map((service)=>({
108
+ binding: service.binding,
109
+ service: service.service,
110
+ prefix: service.prefix,
111
+ interface: 'fetch'
112
+ }));
113
+ return dispatchBindings.length > 0 ? dispatchBindings : void 0;
114
+ };
115
+ const createWranglerConfig = (appDirectory, modernConfig)=>{
116
+ const wrangler = getConfiguredWrangler(modernConfig);
117
+ const d1Databases = createWranglerD1Databases(modernConfig, wrangler.d1_databases);
118
+ const serviceBindings = createWorkerServiceBindings(modernConfig, wrangler.services);
119
+ const wranglerServices = createWranglerServices(serviceBindings);
120
+ return {
121
+ $schema: 'node_modules/wrangler/config-schema.json',
122
+ name: getConfiguredWorkerName(appDirectory, modernConfig),
123
+ compatibility_date: getCompatibilityDate(modernConfig),
124
+ ...wrangler,
125
+ main: WORKER_ENTRY,
126
+ compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
127
+ assets: createWranglerAssetsConfig(wrangler.assets),
128
+ ...void 0 === d1Databases ? {} : {
129
+ d1_databases: d1Databases
130
+ },
131
+ ...void 0 === wranglerServices ? {} : {
132
+ services: wranglerServices
133
+ }
134
+ };
135
+ };
136
+ export { createWorkerManifestServiceBindings, createWorkerServiceBindings, createWranglerConfig };
@@ -0,0 +1,18 @@
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_REQUIRED_COMPATIBILITY_FLAGS = [
15
+ 'nodejs_compat',
16
+ 'global_fetch_strictly_public'
17
+ ];
18
+ 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_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 };