@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.4 → 3.5.0-ultramodern.40

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 (159) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -0
  2. package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +13 -4
  3. package/dist/cjs/builder/shared/lazyCompilation.js +2 -10
  4. package/dist/cjs/commands/index.js +0 -4
  5. package/dist/cjs/index.js +37 -66
  6. package/dist/cjs/plugins/backend-federation/codegen.js +209 -0
  7. package/dist/cjs/plugins/backend-federation/config.js +217 -0
  8. package/dist/cjs/plugins/backend-federation/emit.js +139 -0
  9. package/dist/cjs/plugins/backendFederationBuild.js +53 -0
  10. package/dist/cjs/plugins/deploy/index.js +4 -4
  11. package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
  12. package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
  13. package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +121 -0
  14. package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
  15. package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
  16. package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +205 -0
  17. package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
  18. package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
  19. package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
  20. package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
  21. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
  22. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
  23. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
  24. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
  25. package/dist/cjs/{baseline.js → plugins/deploy/platforms/cloudflare-output-verifier/issues.js} +19 -10
  26. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
  27. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +149 -0
  28. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +131 -0
  29. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  30. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  31. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  32. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  33. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  34. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  35. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +1 -0
  36. package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +13 -4
  37. package/dist/esm/builder/shared/lazyCompilation.mjs +1 -3
  38. package/dist/esm/commands/index.mjs +0 -1
  39. package/dist/esm/index.mjs +3 -4
  40. package/dist/esm/plugins/analyze/getHtmlTemplate.mjs +2 -2
  41. package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +2 -2
  42. package/dist/esm/plugins/backend-federation/codegen.mjs +158 -0
  43. package/dist/esm/plugins/backend-federation/config.mjs +141 -0
  44. package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
  45. package/dist/esm/plugins/backendFederationBuild.mjs +1 -0
  46. package/dist/esm/plugins/deploy/index.mjs +1 -1
  47. package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
  48. package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
  49. package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +70 -0
  50. package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
  51. package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
  52. package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
  53. package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
  54. package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
  55. package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
  56. package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
  57. package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
  58. package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
  59. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
  60. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
  61. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
  62. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
  63. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
  64. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
  65. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  66. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  67. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  68. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  69. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  70. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  71. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +1 -0
  72. package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +13 -4
  73. package/dist/esm-node/builder/shared/lazyCompilation.mjs +1 -3
  74. package/dist/esm-node/commands/index.mjs +0 -1
  75. package/dist/esm-node/index.mjs +3 -4
  76. package/dist/esm-node/plugins/analyze/getHtmlTemplate.mjs +2 -2
  77. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +2 -2
  78. package/dist/esm-node/plugins/backend-federation/codegen.mjs +159 -0
  79. package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
  80. package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
  81. package/dist/esm-node/plugins/backendFederationBuild.mjs +2 -0
  82. package/dist/esm-node/plugins/deploy/index.mjs +1 -1
  83. package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
  84. package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
  85. package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +71 -0
  86. package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
  87. package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
  88. package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
  89. package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
  90. package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
  91. package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
  92. package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
  93. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
  94. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
  95. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
  96. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
  97. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
  98. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
  99. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
  100. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
  101. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  102. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  103. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  104. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  105. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  106. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  107. package/dist/types/builder/generator/createCopyPattern.d.ts +7 -5
  108. package/dist/types/builder/shared/lazyCompilation.d.ts +2 -4
  109. package/dist/types/commands/index.d.ts +0 -1
  110. package/dist/types/index.d.ts +0 -2
  111. package/dist/types/plugins/backend-federation/codegen.d.ts +83 -0
  112. package/dist/types/plugins/backend-federation/config.d.ts +103 -0
  113. package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
  114. package/dist/types/plugins/backendFederationBuild.d.ts +2 -0
  115. package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
  116. package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
  117. package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
  118. package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +22 -0
  119. package/dist/types/plugins/deploy/platforms/{cloudflare.d.ts → cloudflare/index.d.ts} +1 -1
  120. package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +51 -0
  121. package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
  122. package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
  123. package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +113 -0
  124. package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
  125. package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
  126. package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +34 -0
  127. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
  128. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
  129. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
  130. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
  131. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +6 -0
  132. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +15 -0
  133. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
  134. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
  135. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
  136. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
  137. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
  138. package/dist/types/types/config/cloudflareDeploy.d.ts +22 -0
  139. package/dist/types/types/config/deploy.d.ts +15 -2
  140. package/lib/types.d.ts +2 -3
  141. package/package.json +24 -18
  142. package/dist/cjs/commands/runtime.js +0 -196
  143. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +0 -540
  144. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  145. package/dist/cjs/ultramodern/designSystem.js +0 -123
  146. package/dist/esm/baseline.mjs +0 -4
  147. package/dist/esm/commands/runtime.mjs +0 -146
  148. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +0 -492
  149. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  150. package/dist/esm/ultramodern/designSystem.mjs +0 -73
  151. package/dist/esm-node/baseline.mjs +0 -5
  152. package/dist/esm-node/commands/runtime.mjs +0 -147
  153. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +0 -493
  154. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  155. package/dist/esm-node/ultramodern/designSystem.mjs +0 -74
  156. package/dist/types/baseline.d.ts +0 -16
  157. package/dist/types/commands/runtime.d.ts +0 -12
  158. package/dist/types/ultramodern/designSystem.d.ts +0 -54
  159. /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
@@ -1,540 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, getters, values)=>{
14
- var define = (defs, kind)=>{
15
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
- enumerable: true,
17
- [kind]: defs[key]
18
- });
19
- };
20
- define(getters, "get");
21
- define(values, "value");
22
- };
23
- })();
24
- (()=>{
25
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
- })();
27
- (()=>{
28
- __webpack_require__.r = (exports1)=>{
29
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
- value: 'Module'
31
- });
32
- Object.defineProperty(exports1, '__esModule', {
33
- value: true
34
- });
35
- };
36
- })();
37
- var __webpack_exports__ = {};
38
- __webpack_require__.r(__webpack_exports__);
39
- __webpack_require__.d(__webpack_exports__, {
40
- createCloudflarePreset: ()=>createCloudflarePreset
41
- });
42
- const external_node_path_namespaceObject = require("node:path");
43
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
44
- const utils_namespaceObject = require("@modern-js/utils");
45
- const index_js_namespaceObject = require("../utils/index.js");
46
- const WORKER_ENTRY = 'server/index.mjs';
47
- const WORKER_MANIFEST = 'server/modern-worker-manifest.json';
48
- const WRANGLER_CONFIG_FILE = 'wrangler.json';
49
- const OUTPUT_PACKAGE_FILE = 'package.json';
50
- const ASSETS_BINDING = 'ASSETS';
51
- const ROUTE_SPEC_FILE = 'route.json';
52
- const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
53
- const LOADABLE_STATS_FILE = 'loadable-stats.json';
54
- const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
55
- const PUBLIC_ASSETS_DIRECTORY = 'public';
56
- const WORKER_BUNDLE_DIRECTORY = 'worker';
57
- const SERVER_BUNDLE_DIRECTORY = 'bundles';
58
- const SERVER_OUTPUT_DIRECTORY = 'server';
59
- const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
60
- 'api',
61
- 'shared'
62
- ];
63
- const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
64
- const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
65
- const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
66
- const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
67
- const REQUIRED_COMPATIBILITY_FLAGS = [
68
- 'nodejs_compat',
69
- 'global_fetch_strictly_public'
70
- ];
71
- const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
72
- WRANGLER_CONFIG_FILE,
73
- OUTPUT_PACKAGE_FILE
74
- ]);
75
- const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
76
- PUBLIC_ASSETS_DIRECTORY,
77
- SERVER_OUTPUT_DIRECTORY,
78
- WORKER_BUNDLE_DIRECTORY
79
- ]);
80
- const DEFAULT_SECURITY_HEADERS = {
81
- referrerPolicy: 'strict-origin-when-cross-origin',
82
- contentTypeOptions: 'nosniff',
83
- permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
84
- };
85
- const DEFAULT_CORS_ALLOWED_METHODS = [
86
- 'GET',
87
- 'HEAD',
88
- 'POST',
89
- 'PUT',
90
- 'PATCH',
91
- 'DELETE',
92
- 'OPTIONS'
93
- ];
94
- const DEFAULT_CSP_DIRECTIVES = {
95
- 'base-uri': [
96
- "'self'"
97
- ],
98
- 'connect-src': [
99
- "'self'",
100
- 'https:',
101
- 'http:',
102
- 'wss:',
103
- 'ws:'
104
- ],
105
- 'default-src': [
106
- "'self'"
107
- ],
108
- 'font-src': [
109
- "'self'",
110
- 'data:',
111
- 'https:',
112
- 'http:'
113
- ],
114
- 'form-action': [
115
- "'self'"
116
- ],
117
- 'frame-ancestors': [
118
- "'self'"
119
- ],
120
- 'img-src': [
121
- "'self'",
122
- 'data:',
123
- 'blob:',
124
- 'https:',
125
- 'http:'
126
- ],
127
- 'manifest-src': [
128
- "'self'",
129
- 'https:',
130
- 'http:'
131
- ],
132
- 'object-src': [
133
- "'none'"
134
- ],
135
- "script-src": [
136
- "'self'",
137
- "'unsafe-inline'",
138
- "'unsafe-eval'",
139
- 'https:',
140
- 'http:',
141
- 'blob:'
142
- ],
143
- 'style-src': [
144
- "'self'",
145
- "'unsafe-inline'",
146
- 'https:',
147
- 'http:'
148
- ],
149
- 'worker-src': [
150
- "'self'",
151
- 'blob:'
152
- ]
153
- };
154
- const getCompatibilityDate = (modernConfig)=>{
155
- const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
156
- const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
157
- if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
158
- return compatibilityDate;
159
- };
160
- const getWorkerName = (appDirectory)=>{
161
- const basename = external_node_path_default().basename(appDirectory);
162
- return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
163
- };
164
- const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
165
- const configuredName = modernConfig.deploy?.worker?.name?.trim();
166
- return configuredName || getWorkerName(appDirectory);
167
- };
168
- const normalizeRelativePath = (value, label, scope = 'app output')=>{
169
- if ('string' != typeof value) throw new Error(`${label} must be a relative path inside the ${scope}.`);
170
- const normalized = value.trim().replace(/\\/g, '/').replace(/^\.\/+/u, '').replace(/\/+$/u, '');
171
- const segments = normalized.split('/');
172
- if (!normalized || external_node_path_default().isAbsolute(normalized) || '.' === normalized || segments.includes('..')) throw new Error(`${label} must be a relative path inside the ${scope}.`);
173
- return normalized;
174
- };
175
- const normalizeDirectiveValues = (value)=>{
176
- const values = Array.isArray(value) ? value : [
177
- value
178
- ];
179
- return [
180
- ...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
181
- ];
182
- };
183
- const appendDirectiveValues = (directives, name, values)=>{
184
- if (!values?.length) return;
185
- directives[name] = normalizeDirectiveValues([
186
- ...directives[name] ?? [],
187
- ...values
188
- ]);
189
- };
190
- const createContentSecurityPolicy = (config)=>{
191
- const mode = config?.mode ?? 'report-only';
192
- if ('off' === mode) return {
193
- mode,
194
- directives: {},
195
- reason: config?.reason
196
- };
197
- const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
198
- name,
199
- [
200
- ...values
201
- ]
202
- ]));
203
- for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
204
- else directives[name] = normalizeDirectiveValues(value);
205
- if (config?.frameAncestors === false) delete directives['frame-ancestors'];
206
- else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
207
- appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
208
- appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
209
- appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
210
- appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
211
- if (config?.reportUri) directives['report-uri'] = [
212
- config.reportUri
213
- ];
214
- return {
215
- mode,
216
- directives,
217
- reason: config?.reason
218
- };
219
- };
220
- const createNoindexPolicy = (noindex)=>{
221
- if (false === noindex) return {
222
- workersDev: false,
223
- localhost: false,
224
- previewHostnames: []
225
- };
226
- if (true === noindex || void 0 === noindex) return {
227
- workersDev: true,
228
- localhost: true,
229
- previewHostnames: []
230
- };
231
- return {
232
- workersDev: noindex.workersDev ?? true,
233
- localhost: noindex.localhost ?? true,
234
- previewHostnames: noindex.previewHostnames ?? [],
235
- reason: noindex.reason
236
- };
237
- };
238
- const createCloudflareWorkerCorsPolicy = (cors)=>({
239
- assets: cors?.assets ?? true,
240
- allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
241
- allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
242
- allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
243
- '*'
244
- ],
245
- reason: cors?.reason
246
- });
247
- const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
248
- const security = modernConfig.deploy?.worker?.security;
249
- if (security?.enabled === false) return {
250
- enabled: false,
251
- cors: createCloudflareWorkerCorsPolicy(security.cors),
252
- reason: security.reason
253
- };
254
- return {
255
- enabled: true,
256
- headers: {
257
- referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
258
- contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
259
- permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
260
- },
261
- contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
262
- noindex: createNoindexPolicy(security?.noindex),
263
- cors: createCloudflareWorkerCorsPolicy(security?.cors),
264
- reason: security?.reason
265
- };
266
- };
267
- const isJsonRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
268
- const getConfiguredWrangler = (modernConfig)=>{
269
- const wrangler = modernConfig.deploy?.worker?.wrangler;
270
- if (void 0 === wrangler) return {};
271
- if (!isJsonRecord(wrangler)) throw new Error('deploy.worker.wrangler must be a JSON object.');
272
- return wrangler;
273
- };
274
- const createWranglerCompatibilityFlags = (configuredFlags)=>{
275
- if (void 0 === configuredFlags) return [
276
- ...REQUIRED_COMPATIBILITY_FLAGS
277
- ];
278
- if (!Array.isArray(configuredFlags) || configuredFlags.some((flag)=>'string' != typeof flag)) throw new Error('deploy.worker.wrangler.compatibility_flags must be an array of strings.');
279
- return [
280
- ...new Set([
281
- ...configuredFlags,
282
- ...REQUIRED_COMPATIBILITY_FLAGS
283
- ])
284
- ];
285
- };
286
- const createWranglerAssetsConfig = (configuredAssets)=>{
287
- if (void 0 !== configuredAssets && !isJsonRecord(configuredAssets)) throw new Error('deploy.worker.wrangler.assets must be an object.');
288
- return {
289
- ...isJsonRecord(configuredAssets) ? configuredAssets : {},
290
- directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
291
- binding: ASSETS_BINDING,
292
- run_worker_first: true
293
- };
294
- };
295
- const assertNonEmptyString = (value, label)=>{
296
- if ('string' != typeof value || 0 === value.trim().length) throw new Error(`${label} must be a non-empty string.`);
297
- return value.trim();
298
- };
299
- const normalizeD1Database = (database, index)=>{
300
- const binding = assertNonEmptyString(database.binding, `deploy.worker.d1Databases[${index}].binding`);
301
- const databaseName = assertNonEmptyString(database.databaseName, `deploy.worker.d1Databases[${index}].databaseName`);
302
- const databaseId = assertNonEmptyString(database.databaseId, `deploy.worker.d1Databases[${index}].databaseId`);
303
- const migrationsDir = void 0 === database.migrationsDir ? void 0 : normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
304
- const previewDatabaseId = void 0 === database.previewDatabaseId ? void 0 : assertNonEmptyString(database.previewDatabaseId, `deploy.worker.d1Databases[${index}].previewDatabaseId`);
305
- return {
306
- binding,
307
- database_name: databaseName,
308
- database_id: databaseId,
309
- ...void 0 === migrationsDir ? {} : {
310
- migrations_dir: migrationsDir
311
- },
312
- ...void 0 === previewDatabaseId ? {} : {
313
- preview_database_id: previewDatabaseId
314
- },
315
- ...void 0 === database.remote ? {} : {
316
- remote: database.remote
317
- }
318
- };
319
- };
320
- const createWranglerD1Databases = (modernConfig, configuredWranglerD1)=>{
321
- const d1Databases = modernConfig.deploy?.worker?.d1Databases;
322
- if (void 0 === d1Databases) return configuredWranglerD1;
323
- if (void 0 !== configuredWranglerD1) throw new Error('Use deploy.worker.d1Databases or deploy.worker.wrangler.d1_databases, not both.');
324
- if (!Array.isArray(d1Databases)) throw new Error('deploy.worker.d1Databases must be an array.');
325
- return d1Databases.map(normalizeD1Database);
326
- };
327
- const createWranglerConfig = (appDirectory, modernConfig)=>{
328
- const wrangler = getConfiguredWrangler(modernConfig);
329
- const d1Databases = createWranglerD1Databases(modernConfig, wrangler.d1_databases);
330
- return {
331
- $schema: 'node_modules/wrangler/config-schema.json',
332
- name: getConfiguredWorkerName(appDirectory, modernConfig),
333
- compatibility_date: getCompatibilityDate(modernConfig),
334
- ...wrangler,
335
- main: WORKER_ENTRY,
336
- compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
337
- assets: createWranglerAssetsConfig(wrangler.assets),
338
- ...void 0 === d1Databases ? {} : {
339
- d1_databases: d1Databases
340
- }
341
- };
342
- };
343
- const normalizeCloudflareArtifact = (artifact, index)=>{
344
- const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
345
- const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
346
- const [topLevelDestination] = to.split('/');
347
- const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
348
- if (RESERVED_ARTIFACT_DESTINATION_FILES.has(to) || RESERVED_ARTIFACT_DESTINATION_DIRECTORIES.has(topLevelDestination)) throw new Error(`deploy.worker.artifacts[${index}].to must not target generated Cloudflare output path ${JSON.stringify(reservedDestination)}.`);
349
- return {
350
- from,
351
- to,
352
- index
353
- };
354
- };
355
- const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
356
- const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
357
- for (const artifact of artifacts){
358
- const sourcePath = external_node_path_default().join(appDirectory, artifact.from);
359
- if (!await utils_namespaceObject.fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
360
- await utils_namespaceObject.fs.copy(sourcePath, external_node_path_default().join(outputDirectory, artifact.to));
361
- }
362
- };
363
- const copyCloudflareD1Migrations = async (appDirectory, outputDirectory, modernConfig)=>{
364
- for (const [index, database] of (modernConfig.deploy?.worker?.d1Databases ?? []).entries()){
365
- if (!database.migrationsDir) continue;
366
- const migrationsDir = normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
367
- const sourcePath = external_node_path_default().join(appDirectory, migrationsDir);
368
- if (!await utils_namespaceObject.fs.pathExists(sourcePath)) throw new Error(`deploy.worker.d1Databases[${index}].migrationsDir does not exist: ${migrationsDir}`);
369
- await utils_namespaceObject.fs.copy(sourcePath, external_node_path_default().join(outputDirectory, migrationsDir));
370
- }
371
- };
372
- const readRouteSpec = async (outputDirectory)=>{
373
- const routeSpecPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
374
- if (!await utils_namespaceObject.fs.pathExists(routeSpecPath)) return {
375
- routes: []
376
- };
377
- const routeSpec = await utils_namespaceObject.fs.readJSON(routeSpecPath);
378
- return {
379
- ...routeSpec,
380
- routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
381
- };
382
- };
383
- const createMissingEffectBffWorkerError = (outputDirectory, worker)=>new Error(`Cloudflare Effect API runtime is configured, but the BFF worker bundle is missing: ${external_node_path_default().join(outputDirectory, worker)}. ${EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE}`);
384
- const createWorkerManifest = async (outputDirectory, modernConfig)=>{
385
- const routeSpec = await readRouteSpec(outputDirectory);
386
- const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
387
- const worker = 'string' == typeof route.worker ? route.worker : void 0;
388
- return {
389
- urlPath: route.urlPath,
390
- entryName: route.entryName,
391
- entryPath: route.entryPath,
392
- isSSR: Boolean(route.isSSR),
393
- worker,
394
- workerExists: worker ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, worker)) : false
395
- };
396
- }));
397
- const bffPrefix = modernConfig.bff?.prefix;
398
- const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
399
- const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
400
- const effectApiWorkerExists = await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
401
- if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
402
- return {
403
- version: 1,
404
- runtime: {
405
- type: 'cloudflare-module-worker',
406
- entry: WORKER_ENTRY,
407
- fetchExport: true,
408
- nodeListen: false
409
- },
410
- assets: {
411
- binding: ASSETS_BINDING,
412
- directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
413
- runWorkerFirst: true
414
- },
415
- routeSpec: {
416
- file: ROUTE_SPEC_OUTPUT,
417
- routes
418
- },
419
- workerBundles: {
420
- directory: WORKER_BUNDLE_DIRECTORY,
421
- format: 'commonjs',
422
- importableFromModuleWorker: true,
423
- requestHandlerExport: 'requestHandler'
424
- },
425
- resources: {
426
- loadableStats: LOADABLE_STATS_FILE,
427
- routeManifest: ROUTE_MANIFEST_FILE
428
- },
429
- security: createCloudflareWorkerSecurityPolicy(modernConfig),
430
- bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
431
- runtimeFramework: 'effect',
432
- prefix: primaryBffPrefix,
433
- worker: BFF_EFFECT_WORKER_ENTRY
434
- } : void 0
435
- };
436
- };
437
- const createWorkerModuleLoaders = (manifest)=>{
438
- const imports = new Map();
439
- for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
440
- const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
441
- imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
442
- }
443
- if (manifest.bff?.worker) {
444
- const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
445
- imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
446
- }
447
- if (0 === imports.size) return '{}';
448
- const loaders = [
449
- ...imports.entries()
450
- ].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
451
- return `{\n${loaders.join(',\n')}\n}`;
452
- };
453
- const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
454
- ...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
455
- try {
456
- return utils_namespaceObject.fs.statSync(external_node_path_default().join(appDirectory, directory)).isDirectory();
457
- } catch {
458
- return false;
459
- }
460
- }),
461
- ...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
462
- ].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
463
- const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
464
- const relativePath = external_node_path_default().relative(distDirectory, src);
465
- if (!relativePath) return true;
466
- const normalizedRelativePath = relativePath.replace(/\\/g, '/');
467
- const [topLevelDirectory] = normalizedRelativePath.split('/');
468
- return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY && !publicAssetExcludes.some((exclude)=>normalizedRelativePath === exclude || normalizedRelativePath.startsWith(`${exclude}/`));
469
- };
470
- const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
471
- const relativePath = external_node_path_default().relative(workerBundleDirectory, src);
472
- if (!relativePath) return true;
473
- const normalizedRelativePath = relativePath.replace(/\\/g, '/');
474
- const basename = external_node_path_default().basename(normalizedRelativePath);
475
- if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
476
- if (utils_namespaceObject.fs.statSync(src).isDirectory()) return true;
477
- return [
478
- '.cjs',
479
- '.js',
480
- '.mjs'
481
- ].includes(external_node_path_default().extname(normalizedRelativePath));
482
- };
483
- const createCloudflarePreset = ({ appContext, modernConfig })=>{
484
- const { appDirectory, distDirectory } = appContext;
485
- const outputDirectory = external_node_path_default().join(appDirectory, '.output');
486
- const publicDirectory = external_node_path_default().join(outputDirectory, PUBLIC_ASSETS_DIRECTORY);
487
- const workerEntryPath = external_node_path_default().join(outputDirectory, WORKER_ENTRY);
488
- const workerManifestPath = external_node_path_default().join(outputDirectory, WORKER_MANIFEST);
489
- const routeSpecOutputPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
490
- const wranglerConfigPath = external_node_path_default().join(outputDirectory, WRANGLER_CONFIG_FILE);
491
- const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
492
- const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
493
- return {
494
- async prepare () {
495
- await utils_namespaceObject.fs.remove(outputDirectory);
496
- },
497
- async writeOutput () {
498
- await utils_namespaceObject.fs.copy(distDirectory, publicDirectory, {
499
- filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
500
- });
501
- await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerEntryPath));
502
- await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerManifestPath));
503
- const routeSpecSourcePath = external_node_path_default().join(distDirectory, ROUTE_SPEC_FILE);
504
- if (await utils_namespaceObject.fs.pathExists(routeSpecSourcePath)) await utils_namespaceObject.fs.copy(routeSpecSourcePath, routeSpecOutputPath);
505
- const workerBundleSourceDirectory = external_node_path_default().join(distDirectory, WORKER_BUNDLE_DIRECTORY);
506
- const workerBundleOutputDirectory = external_node_path_default().join(outputDirectory, WORKER_BUNDLE_DIRECTORY);
507
- if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) {
508
- await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
509
- filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
510
- });
511
- await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(workerBundleOutputDirectory, 'package.json'), {
512
- type: 'commonjs'
513
- });
514
- }
515
- await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
516
- await copyCloudflareD1Migrations(appDirectory, outputDirectory, modernConfig);
517
- await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
518
- spaces: 2
519
- });
520
- await utils_namespaceObject.fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig), {
521
- spaces: 2
522
- });
523
- await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, OUTPUT_PACKAGE_FILE), {
524
- type: 'module'
525
- });
526
- },
527
- async genEntry () {
528
- const template = await (0, index_js_namespaceObject.readTemplate)('cloudflare-entry.mjs');
529
- const manifest = await utils_namespaceObject.fs.readJSON(workerManifestPath);
530
- await utils_namespaceObject.fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
531
- }
532
- };
533
- };
534
- exports.createCloudflarePreset = __webpack_exports__.createCloudflarePreset;
535
- for(var __rspack_i in __webpack_exports__)if (-1 === [
536
- "createCloudflarePreset"
537
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
538
- Object.defineProperty(exports, '__esModule', {
539
- value: true
540
- });