@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.11 → 3.2.0-ultramodern.110

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 (134) hide show
  1. package/bin/modern.js +0 -0
  2. package/dist/cjs/baseline.js +51 -5
  3. package/dist/cjs/builder/builder-rspack/index.js +9 -5
  4. package/dist/cjs/builder/generator/adapterCopy.js +9 -5
  5. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +9 -5
  6. package/dist/cjs/builder/generator/createCopyPattern.js +9 -5
  7. package/dist/cjs/builder/generator/getBuilderEnvironments.js +199 -12
  8. package/dist/cjs/builder/generator/index.js +9 -5
  9. package/dist/cjs/builder/index.js +9 -5
  10. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +50 -10
  11. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +10 -6
  12. package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +9 -5
  13. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -6
  14. package/dist/cjs/builder/shared/builderPlugins/builderHooks.js +12 -8
  15. package/dist/cjs/builder/shared/builderPlugins/index.js +9 -5
  16. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +9 -5
  17. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +12 -8
  18. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +9 -5
  19. package/dist/cjs/builder/shared/bundlerPlugins/index.js +9 -5
  20. package/dist/cjs/builder/shared/createCopyInfo.js +9 -5
  21. package/dist/cjs/builder/shared/index.js +9 -5
  22. package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +12 -8
  23. package/dist/cjs/commands/build.js +9 -5
  24. package/dist/cjs/commands/deploy.js +9 -5
  25. package/dist/cjs/commands/dev.js +9 -5
  26. package/dist/cjs/commands/index.js +9 -5
  27. package/dist/cjs/commands/info.js +9 -5
  28. package/dist/cjs/commands/inspect.js +12 -8
  29. package/dist/cjs/commands/runtime.js +15 -11
  30. package/dist/cjs/commands/serve.js +9 -5
  31. package/dist/cjs/compat/hooks.js +9 -5
  32. package/dist/cjs/compat/index.js +9 -5
  33. package/dist/cjs/compat/utils.js +9 -5
  34. package/dist/cjs/config/default.js +9 -5
  35. package/dist/cjs/config/index.js +9 -5
  36. package/dist/cjs/config/initialize/index.js +9 -5
  37. package/dist/cjs/config/initialize/inits.js +9 -5
  38. package/dist/cjs/constants.js +13 -9
  39. package/dist/cjs/defineConfig.js +12 -8
  40. package/dist/cjs/esm/register-esm.js +12 -8
  41. package/dist/cjs/esm/ts-paths-loader.js +9 -5
  42. package/dist/cjs/index.js +21 -16
  43. package/dist/cjs/locale/en.js +12 -8
  44. package/dist/cjs/locale/index.js +9 -5
  45. package/dist/cjs/locale/zh.js +12 -8
  46. package/dist/cjs/plugins/analyze/constants.js +14 -10
  47. package/dist/cjs/plugins/analyze/getBundleEntry.js +9 -5
  48. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -5
  49. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +9 -5
  50. package/dist/cjs/plugins/analyze/getServerRoutes.js +9 -5
  51. package/dist/cjs/plugins/analyze/index.js +9 -5
  52. package/dist/cjs/plugins/analyze/isDefaultExportFunction.js +9 -5
  53. package/dist/cjs/plugins/analyze/templates.js +12 -8
  54. package/dist/cjs/plugins/analyze/utils.js +9 -5
  55. package/dist/cjs/plugins/deploy/index.js +26 -11
  56. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +384 -0
  57. package/dist/cjs/plugins/deploy/platforms/gh-pages.js +9 -5
  58. package/dist/cjs/plugins/deploy/platforms/netlify.js +9 -5
  59. package/dist/cjs/plugins/deploy/platforms/node.js +9 -5
  60. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +502 -0
  61. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +7 -0
  62. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +185 -0
  63. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +59 -0
  64. package/dist/cjs/plugins/deploy/platforms/vercel.js +9 -5
  65. package/dist/cjs/plugins/deploy/utils/generator.js +9 -5
  66. package/dist/cjs/plugins/deploy/utils/index.js +9 -5
  67. package/dist/cjs/plugins/initialize/index.js +9 -5
  68. package/dist/cjs/plugins/serverBuild.js +9 -5
  69. package/dist/cjs/plugins/serverRuntime.js +12 -8
  70. package/dist/cjs/presetUltramodern.js +9 -5
  71. package/dist/cjs/rsbuild.js +12 -5
  72. package/dist/cjs/run/index.js +9 -5
  73. package/dist/cjs/types/config/index.js +9 -5
  74. package/dist/cjs/types/index.js +9 -5
  75. package/dist/cjs/ultramodern/designSystem.js +16 -12
  76. package/dist/cjs/utils/config.js +9 -5
  77. package/dist/cjs/utils/createServer.js +14 -10
  78. package/dist/cjs/utils/env.js +9 -5
  79. package/dist/cjs/utils/generateWatchFiles.js +9 -5
  80. package/dist/cjs/utils/getConfigFile.js +9 -5
  81. package/dist/cjs/utils/getSelectedEntries.js +9 -5
  82. package/dist/cjs/utils/initAppContext.js +9 -5
  83. package/dist/cjs/utils/loadPlugins.js +9 -5
  84. package/dist/cjs/utils/printInstructions.js +9 -5
  85. package/dist/cjs/utils/register.js +9 -5
  86. package/dist/cjs/utils/restart.js +9 -5
  87. package/dist/cjs/utils/routes.js +9 -5
  88. package/dist/esm/baseline.mjs +33 -1
  89. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +180 -8
  90. package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +41 -5
  91. package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
  92. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +3 -1
  93. package/dist/esm/plugins/deploy/index.mjs +10 -4
  94. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +336 -0
  95. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +502 -0
  96. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +7 -0
  97. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +185 -0
  98. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +59 -0
  99. package/dist/esm/rsbuild.mjs +5 -2
  100. package/dist/esm-node/baseline.mjs +33 -1
  101. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +185 -9
  102. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +41 -5
  103. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
  104. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +3 -1
  105. package/dist/esm-node/plugins/deploy/index.mjs +10 -4
  106. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +337 -0
  107. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +502 -0
  108. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.mjs +7 -0
  109. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.mjs +185 -0
  110. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-path.mjs +59 -0
  111. package/dist/esm-node/rsbuild.mjs +5 -2
  112. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  113. package/dist/types/builder/generator/index.d.ts +1 -1
  114. package/dist/types/builder/shared/createCopyInfo.d.ts +1 -1
  115. package/dist/types/commands/inspect.d.ts +1 -1
  116. package/dist/types/locale/en.d.ts +1 -1
  117. package/dist/types/locale/index.d.ts +89 -2
  118. package/dist/types/locale/zh.d.ts +1 -1
  119. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +2 -2
  120. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  121. package/dist/types/plugins/deploy/index.d.ts +4 -1
  122. package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +2 -0
  123. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.d.mts +4 -0
  124. package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-fs-promises.d.mts +5 -0
  125. package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-loadable-server.d.mts +48 -0
  126. package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-path.d.mts +21 -0
  127. package/dist/types/plugins/deploy/utils/generator.d.ts +2 -2
  128. package/dist/types/plugins/deploy/utils/index.d.ts +1 -1
  129. package/dist/types/rsbuild.d.ts +1 -1
  130. package/dist/types/run/index.d.ts +1 -1
  131. package/dist/types/types/config/deploy.d.ts +56 -0
  132. package/dist/types/utils/getConfigFile.d.ts +1 -1
  133. package/dist/types/utils/loadPlugins.d.ts +2 -2
  134. package/package.json +21 -20
@@ -0,0 +1,384 @@
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 ASSETS_BINDING = 'ASSETS';
49
+ const ROUTE_SPEC_FILE = 'route.json';
50
+ const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
51
+ const LOADABLE_STATS_FILE = 'loadable-stats.json';
52
+ const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
53
+ const PUBLIC_ASSETS_DIRECTORY = 'public';
54
+ const WORKER_BUNDLE_DIRECTORY = 'worker';
55
+ const SERVER_BUNDLE_DIRECTORY = 'bundles';
56
+ const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
57
+ const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
58
+ const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
59
+ const DEFAULT_SECURITY_HEADERS = {
60
+ referrerPolicy: 'strict-origin-when-cross-origin',
61
+ contentTypeOptions: 'nosniff',
62
+ permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
63
+ };
64
+ const DEFAULT_CSP_DIRECTIVES = {
65
+ 'base-uri': [
66
+ "'self'"
67
+ ],
68
+ 'connect-src': [
69
+ "'self'",
70
+ 'https:',
71
+ 'http:',
72
+ 'wss:',
73
+ 'ws:'
74
+ ],
75
+ 'default-src': [
76
+ "'self'"
77
+ ],
78
+ 'font-src': [
79
+ "'self'",
80
+ 'data:',
81
+ 'https:',
82
+ 'http:'
83
+ ],
84
+ 'form-action': [
85
+ "'self'"
86
+ ],
87
+ 'frame-ancestors': [
88
+ "'self'"
89
+ ],
90
+ 'img-src': [
91
+ "'self'",
92
+ 'data:',
93
+ 'blob:',
94
+ 'https:',
95
+ 'http:'
96
+ ],
97
+ 'manifest-src': [
98
+ "'self'",
99
+ 'https:',
100
+ 'http:'
101
+ ],
102
+ 'object-src': [
103
+ "'none'"
104
+ ],
105
+ "script-src": [
106
+ "'self'",
107
+ "'unsafe-inline'",
108
+ "'unsafe-eval'",
109
+ 'https:',
110
+ 'http:',
111
+ 'blob:'
112
+ ],
113
+ 'style-src': [
114
+ "'self'",
115
+ "'unsafe-inline'",
116
+ 'https:',
117
+ 'http:'
118
+ ],
119
+ 'worker-src': [
120
+ "'self'",
121
+ 'blob:'
122
+ ]
123
+ };
124
+ const getCompatibilityDate = (modernConfig)=>{
125
+ const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
126
+ const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
127
+ if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
128
+ return compatibilityDate;
129
+ };
130
+ const getWorkerName = (appDirectory)=>{
131
+ const basename = external_node_path_default().basename(appDirectory);
132
+ return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
133
+ };
134
+ const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
135
+ const configuredName = modernConfig.deploy?.worker?.name?.trim();
136
+ return configuredName || getWorkerName(appDirectory);
137
+ };
138
+ const normalizeDirectiveValues = (value)=>{
139
+ const values = Array.isArray(value) ? value : [
140
+ value
141
+ ];
142
+ return [
143
+ ...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
144
+ ];
145
+ };
146
+ const appendDirectiveValues = (directives, name, values)=>{
147
+ if (!values?.length) return;
148
+ directives[name] = normalizeDirectiveValues([
149
+ ...directives[name] ?? [],
150
+ ...values
151
+ ]);
152
+ };
153
+ const createContentSecurityPolicy = (config)=>{
154
+ const mode = config?.mode ?? 'report-only';
155
+ if ('off' === mode) return {
156
+ mode,
157
+ directives: {},
158
+ reason: config?.reason
159
+ };
160
+ const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
161
+ name,
162
+ [
163
+ ...values
164
+ ]
165
+ ]));
166
+ for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
167
+ else directives[name] = normalizeDirectiveValues(value);
168
+ if (config?.frameAncestors === false) delete directives['frame-ancestors'];
169
+ else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
170
+ appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
171
+ appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
172
+ appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
173
+ appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
174
+ if (config?.reportUri) directives['report-uri'] = [
175
+ config.reportUri
176
+ ];
177
+ return {
178
+ mode,
179
+ directives,
180
+ reason: config?.reason
181
+ };
182
+ };
183
+ const createNoindexPolicy = (noindex)=>{
184
+ if (false === noindex) return {
185
+ workersDev: false,
186
+ localhost: false,
187
+ previewHostnames: []
188
+ };
189
+ if (true === noindex || void 0 === noindex) return {
190
+ workersDev: true,
191
+ localhost: true,
192
+ previewHostnames: []
193
+ };
194
+ return {
195
+ workersDev: noindex.workersDev ?? true,
196
+ localhost: noindex.localhost ?? true,
197
+ previewHostnames: noindex.previewHostnames ?? [],
198
+ reason: noindex.reason
199
+ };
200
+ };
201
+ const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
202
+ const security = modernConfig.deploy?.worker?.security;
203
+ if (security?.enabled === false) return {
204
+ enabled: false,
205
+ reason: security.reason
206
+ };
207
+ return {
208
+ enabled: true,
209
+ headers: {
210
+ referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
211
+ contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
212
+ permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
213
+ },
214
+ contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
215
+ noindex: createNoindexPolicy(security?.noindex),
216
+ cookies: {
217
+ mutateSetCookie: false,
218
+ reason: security?.cookies?.reason ?? 'Cloudflare worker does not own application Set-Cookie headers.'
219
+ },
220
+ reason: security?.reason
221
+ };
222
+ };
223
+ const readRouteSpec = async (outputDirectory)=>{
224
+ const routeSpecPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
225
+ if (!await utils_namespaceObject.fs.pathExists(routeSpecPath)) return {
226
+ routes: []
227
+ };
228
+ const routeSpec = await utils_namespaceObject.fs.readJSON(routeSpecPath);
229
+ return {
230
+ ...routeSpec,
231
+ routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
232
+ };
233
+ };
234
+ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
235
+ const routeSpec = await readRouteSpec(outputDirectory);
236
+ const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
237
+ const worker = 'string' == typeof route.worker ? route.worker : void 0;
238
+ return {
239
+ urlPath: route.urlPath,
240
+ entryName: route.entryName,
241
+ entryPath: route.entryPath,
242
+ isSSR: Boolean(route.isSSR),
243
+ worker,
244
+ workerExists: worker ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, worker)) : false
245
+ };
246
+ }));
247
+ const bffPrefix = modernConfig.bff?.prefix;
248
+ const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
249
+ const isEffectBff = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
250
+ const effectBffWorkerExists = await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
251
+ return {
252
+ version: 1,
253
+ runtime: {
254
+ type: 'cloudflare-module-worker',
255
+ entry: WORKER_ENTRY,
256
+ fetchExport: true,
257
+ nodeListen: false
258
+ },
259
+ assets: {
260
+ binding: ASSETS_BINDING,
261
+ directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
262
+ runWorkerFirst: true
263
+ },
264
+ routeSpec: {
265
+ file: ROUTE_SPEC_OUTPUT,
266
+ routes
267
+ },
268
+ workerBundles: {
269
+ directory: WORKER_BUNDLE_DIRECTORY,
270
+ format: 'commonjs',
271
+ importableFromModuleWorker: true,
272
+ requestHandlerExport: 'requestHandler'
273
+ },
274
+ resources: {
275
+ loadableStats: LOADABLE_STATS_FILE,
276
+ routeManifest: ROUTE_MANIFEST_FILE
277
+ },
278
+ security: createCloudflareWorkerSecurityPolicy(modernConfig),
279
+ bff: isEffectBff && primaryBffPrefix && effectBffWorkerExists ? {
280
+ runtimeFramework: 'effect',
281
+ prefix: primaryBffPrefix,
282
+ worker: BFF_EFFECT_WORKER_ENTRY
283
+ } : void 0
284
+ };
285
+ };
286
+ const createWorkerModuleLoaders = (manifest)=>{
287
+ const imports = new Map();
288
+ for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
289
+ const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
290
+ imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
291
+ }
292
+ if (manifest.bff?.worker) {
293
+ const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
294
+ imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
295
+ }
296
+ if (0 === imports.size) return '{}';
297
+ const loaders = [
298
+ ...imports.entries()
299
+ ].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
300
+ return `{\n${loaders.join(',\n')}\n}`;
301
+ };
302
+ const shouldCopyToPublicAssets = (src, distDirectory)=>{
303
+ const relativePath = external_node_path_default().relative(distDirectory, src);
304
+ if (!relativePath) return true;
305
+ const normalizedRelativePath = relativePath.replace(/\\/g, '/');
306
+ const [topLevelDirectory] = normalizedRelativePath.split('/');
307
+ return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY;
308
+ };
309
+ const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
310
+ const relativePath = external_node_path_default().relative(workerBundleDirectory, src);
311
+ if (!relativePath) return true;
312
+ const normalizedRelativePath = relativePath.replace(/\\/g, '/');
313
+ const basename = external_node_path_default().basename(normalizedRelativePath);
314
+ if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
315
+ if (utils_namespaceObject.fs.statSync(src).isDirectory()) return true;
316
+ return [
317
+ '.cjs',
318
+ '.js',
319
+ '.mjs'
320
+ ].includes(external_node_path_default().extname(normalizedRelativePath));
321
+ };
322
+ const createCloudflarePreset = ({ appContext, modernConfig })=>{
323
+ const { appDirectory, distDirectory } = appContext;
324
+ const outputDirectory = external_node_path_default().join(appDirectory, '.output');
325
+ const publicDirectory = external_node_path_default().join(outputDirectory, PUBLIC_ASSETS_DIRECTORY);
326
+ const workerEntryPath = external_node_path_default().join(outputDirectory, WORKER_ENTRY);
327
+ const workerManifestPath = external_node_path_default().join(outputDirectory, WORKER_MANIFEST);
328
+ const routeSpecOutputPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
329
+ const wranglerConfigPath = external_node_path_default().join(outputDirectory, 'wrangler.json');
330
+ const workerName = getConfiguredWorkerName(appDirectory, modernConfig);
331
+ return {
332
+ async prepare () {
333
+ await utils_namespaceObject.fs.remove(outputDirectory);
334
+ },
335
+ async writeOutput () {
336
+ await utils_namespaceObject.fs.copy(distDirectory, publicDirectory, {
337
+ filter: (src)=>shouldCopyToPublicAssets(src, distDirectory)
338
+ });
339
+ await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerEntryPath));
340
+ await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerManifestPath));
341
+ const routeSpecSourcePath = external_node_path_default().join(distDirectory, ROUTE_SPEC_FILE);
342
+ if (await utils_namespaceObject.fs.pathExists(routeSpecSourcePath)) await utils_namespaceObject.fs.copy(routeSpecSourcePath, routeSpecOutputPath);
343
+ const workerBundleSourceDirectory = external_node_path_default().join(distDirectory, WORKER_BUNDLE_DIRECTORY);
344
+ if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, external_node_path_default().join(outputDirectory, WORKER_BUNDLE_DIRECTORY), {
345
+ filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
346
+ });
347
+ await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, {
348
+ $schema: 'node_modules/wrangler/config-schema.json',
349
+ name: workerName,
350
+ main: WORKER_ENTRY,
351
+ compatibility_date: getCompatibilityDate(modernConfig),
352
+ compatibility_flags: [
353
+ 'nodejs_compat',
354
+ 'global_fetch_strictly_public'
355
+ ],
356
+ assets: {
357
+ directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
358
+ binding: ASSETS_BINDING,
359
+ run_worker_first: true
360
+ }
361
+ }, {
362
+ spaces: 2
363
+ });
364
+ await utils_namespaceObject.fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig), {
365
+ spaces: 2
366
+ });
367
+ await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, 'package.json'), {
368
+ type: 'commonjs'
369
+ });
370
+ },
371
+ async genEntry () {
372
+ const template = await (0, index_js_namespaceObject.readTemplate)('cloudflare-entry.mjs');
373
+ const manifest = await utils_namespaceObject.fs.readJSON(workerManifestPath);
374
+ await utils_namespaceObject.fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
375
+ }
376
+ };
377
+ };
378
+ exports.createCloudflarePreset = __webpack_exports__.createCloudflarePreset;
379
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
380
+ "createCloudflarePreset"
381
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
382
+ Object.defineProperty(exports, '__esModule', {
383
+ value: true
384
+ });
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
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");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
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");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
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");
18
22
  };
19
23
  })();
20
24
  (()=>{