@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.12 → 3.2.0-ultramodern.120

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