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

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
@@ -0,0 +1,129 @@
1
+ import promises from "node:fs/promises";
2
+ import node_path from "node:path";
3
+ import { createCloudflareOutputPlan } from "../cloudflare-output-plan.mjs";
4
+ import { verifyDeliveryUnitIdentity } from "./identity.mjs";
5
+ import { addIssue, assertEqual, assertFlag } from "./issues.mjs";
6
+ import { verifyManifestShape } from "./manifest.mjs";
7
+ import { getEffectBffWorker, getWorkerBundleReferences, missingWorkerBundleMessage, resolveWorkerBundleReference, verifyWorkerBundleReferences, verifyWorkerImport } from "./worker-bundles.mjs";
8
+ const pathExists = async (filePath)=>{
9
+ try {
10
+ await promises.access(filePath);
11
+ return true;
12
+ } catch {
13
+ return false;
14
+ }
15
+ };
16
+ const readJson = async (filePath)=>JSON.parse(await promises.readFile(filePath, 'utf-8'));
17
+ const verifyCloudflareOutput = async (options)=>{
18
+ const outputDirectory = node_path.resolve(options.outputDirectory);
19
+ const issues = [];
20
+ const outputPlan = createCloudflareOutputPlan(outputDirectory);
21
+ for (const relativePath of outputPlan.requiredFiles){
22
+ const filePath = node_path.join(outputDirectory, relativePath);
23
+ if (!await pathExists(filePath)) addIssue(issues, {
24
+ code: 'missing-file',
25
+ message: `Cloudflare output is missing ${relativePath}.`,
26
+ path: filePath
27
+ });
28
+ }
29
+ const manifestPath = outputPlan.paths.workerManifest;
30
+ const wranglerPath = outputPlan.paths.wranglerConfig;
31
+ const packagePath = outputPlan.paths.outputPackage;
32
+ const workerPackagePath = outputPlan.paths.workerPackage;
33
+ const manifest = await pathExists(manifestPath) ? await readJson(manifestPath) : void 0;
34
+ const wrangler = await pathExists(wranglerPath) ? await readJson(wranglerPath) : void 0;
35
+ const outputPackage = await pathExists(packagePath) ? await readJson(packagePath) : void 0;
36
+ const workerPackage = await pathExists(workerPackagePath) ? await readJson(workerPackagePath) : void 0;
37
+ if (manifest) {
38
+ verifyManifestShape(issues, manifest, manifestPath);
39
+ verifyDeliveryUnitIdentity(issues, manifest, manifestPath, options.deliveryUnit);
40
+ const workerReferences = getWorkerBundleReferences(manifest);
41
+ if (workerReferences.length > 0 && !await pathExists(workerPackagePath)) addIssue(issues, {
42
+ code: 'missing-file',
43
+ message: 'Cloudflare output is missing worker/package.json for referenced worker bundles.',
44
+ path: workerPackagePath
45
+ });
46
+ if (manifest.bff?.runtimeFramework === 'effect' && !getEffectBffWorker(manifest)) addIssue(issues, {
47
+ code: 'missing-worker-bundle',
48
+ message: 'Cloudflare Effect BFF manifest points to a missing worker bundle.'
49
+ });
50
+ for (const workerReference of workerReferences){
51
+ const resolvedWorker = resolveWorkerBundleReference(issues, outputDirectory, workerReference, manifestPath);
52
+ if (!resolvedWorker) continue;
53
+ const workerExists = await pathExists(resolvedWorker.path);
54
+ if (!workerExists) addIssue(issues, {
55
+ code: 'missing-worker-bundle',
56
+ message: missingWorkerBundleMessage(workerReference),
57
+ path: resolvedWorker.path
58
+ });
59
+ if (workerExists) {
60
+ const workerSource = await promises.readFile(resolvedWorker.path, 'utf-8');
61
+ verifyWorkerBundleReferences(issues, resolvedWorker, workerSource);
62
+ if ('effect-bff' === resolvedWorker.kind && (workerSource.includes(';entityKind;') || workerSource.includes(';entityKind,entityKind;'))) addIssue(issues, {
63
+ code: 'invalid-worker-bundle',
64
+ message: 'Cloudflare Effect BFF worker bundle contains invalid Drizzle entityKind marker references.',
65
+ path: resolvedWorker.path
66
+ });
67
+ }
68
+ }
69
+ }
70
+ if (wrangler) {
71
+ assertEqual(issues, wrangler.main, outputPlan.wrangler.main, {
72
+ code: 'invalid-wrangler',
73
+ message: `wrangler.json main must be ${outputPlan.wrangler.main}.`,
74
+ path: wranglerPath
75
+ });
76
+ assertEqual(issues, wrangler.assets?.binding, outputPlan.wrangler.assets.binding, {
77
+ code: 'invalid-wrangler',
78
+ message: 'wrangler.json assets.binding must be ASSETS.',
79
+ path: wranglerPath
80
+ });
81
+ assertEqual(issues, wrangler.assets?.directory, outputPlan.wrangler.assets.directory, {
82
+ code: 'invalid-wrangler',
83
+ message: 'wrangler.json assets.directory must be ./public.',
84
+ path: wranglerPath
85
+ });
86
+ assertEqual(issues, wrangler.assets?.run_worker_first, outputPlan.wrangler.assets.run_worker_first, {
87
+ code: 'invalid-wrangler',
88
+ message: 'wrangler.json assets.run_worker_first must be true.',
89
+ path: wranglerPath
90
+ });
91
+ for (const flag of outputPlan.wrangler.requiredCompatibilityFlags)assertFlag(issues, wrangler.compatibility_flags, flag, {
92
+ code: 'invalid-wrangler',
93
+ message: `wrangler.json compatibility_flags must include ${flag}.`,
94
+ path: wranglerPath
95
+ });
96
+ }
97
+ if (outputPackage) assertEqual(issues, outputPackage.type, outputPlan.packages.output.type, {
98
+ code: 'invalid-package',
99
+ message: '.output/package.json must declare type module.',
100
+ path: packagePath
101
+ });
102
+ if (workerPackage) assertEqual(issues, workerPackage.type, outputPlan.packages.worker.type, {
103
+ code: 'invalid-package',
104
+ message: '.output/worker/package.json must declare type commonjs.',
105
+ path: workerPackagePath
106
+ });
107
+ for (const leakedPath of outputPlan.publicLeakDirectories){
108
+ const publicPath = node_path.join(outputPlan.paths.publicAssets, leakedPath);
109
+ if (await pathExists(publicPath)) addIssue(issues, {
110
+ code: 'public-output-leak',
111
+ message: `Framework-owned ${leakedPath} output leaked into public assets.`,
112
+ path: publicPath
113
+ });
114
+ }
115
+ if (false !== options.importWorker && await pathExists(outputPlan.paths.workerEntry)) await verifyWorkerImport(issues, outputPlan.paths.workerEntry);
116
+ return {
117
+ ok: 0 === issues.length,
118
+ issues
119
+ };
120
+ };
121
+ const assertCloudflareOutput = async (options)=>{
122
+ const result = await verifyCloudflareOutput(options);
123
+ if (!result.ok) throw new Error([
124
+ 'Cloudflare output verification failed:',
125
+ ...result.issues.map((issue)=>`- ${issue.code}: ${issue.message}${issue.path ? ` (${issue.path})` : ''}`)
126
+ ].join('\n'));
127
+ };
128
+ export { verifyCloudflareOutputMutationPolicy } from "./mutation-policy.mjs";
129
+ export { assertCloudflareOutput, verifyCloudflareOutput };
@@ -0,0 +1,10 @@
1
+ const addIssue = (issues, issue)=>{
2
+ issues.push(issue);
3
+ };
4
+ const assertEqual = (issues, actual, expected, issue)=>{
5
+ if (actual !== expected) addIssue(issues, issue);
6
+ };
7
+ const assertFlag = (issues, flags, flag, issue)=>{
8
+ if (!Array.isArray(flags) || !flags.includes(flag)) addIssue(issues, issue);
9
+ };
10
+ export { addIssue, assertEqual, assertFlag };
@@ -0,0 +1,45 @@
1
+ import { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_ENTRY } from "../cloudflare-output-contract.mjs";
2
+ import { addIssue, assertEqual } from "./issues.mjs";
3
+ const verifyManifestShape = (issues, manifest, manifestPath)=>{
4
+ assertEqual(issues, manifest.runtime?.type, CLOUDFLARE_RUNTIME_TYPE, {
5
+ code: 'invalid-manifest',
6
+ message: 'Cloudflare output manifest runtime.type must be cloudflare-module-worker.',
7
+ path: manifestPath
8
+ });
9
+ assertEqual(issues, manifest.runtime?.entry, CLOUDFLARE_WORKER_ENTRY, {
10
+ code: 'invalid-manifest',
11
+ message: `Cloudflare output manifest runtime.entry must be ${CLOUDFLARE_WORKER_ENTRY}.`,
12
+ path: manifestPath
13
+ });
14
+ assertEqual(issues, manifest.runtime?.fetchExport, true, {
15
+ code: 'invalid-manifest',
16
+ message: 'Cloudflare output manifest runtime.fetchExport must be true.',
17
+ path: manifestPath
18
+ });
19
+ assertEqual(issues, manifest.runtime?.nodeListen, false, {
20
+ code: 'invalid-manifest',
21
+ message: 'Cloudflare output manifest runtime.nodeListen must be false.',
22
+ path: manifestPath
23
+ });
24
+ assertEqual(issues, manifest.assets?.binding, CLOUDFLARE_ASSETS_BINDING, {
25
+ code: 'invalid-manifest',
26
+ message: 'Cloudflare output manifest assets.binding must be ASSETS.',
27
+ path: manifestPath
28
+ });
29
+ assertEqual(issues, manifest.assets?.directory, `./${CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY}`, {
30
+ code: 'invalid-manifest',
31
+ message: 'Cloudflare output manifest assets.directory must be ./public.',
32
+ path: manifestPath
33
+ });
34
+ assertEqual(issues, manifest.assets?.runWorkerFirst, true, {
35
+ code: 'invalid-manifest',
36
+ message: 'Cloudflare output manifest assets.runWorkerFirst must be true.',
37
+ path: manifestPath
38
+ });
39
+ if (!Array.isArray(manifest.routeSpec?.routes)) addIssue(issues, {
40
+ code: 'invalid-manifest',
41
+ message: 'Cloudflare output manifest routeSpec.routes must be array.',
42
+ path: manifestPath
43
+ });
44
+ };
45
+ export { verifyManifestShape };
@@ -0,0 +1,97 @@
1
+ import promises from "node:fs/promises";
2
+ import node_path from "node:path";
3
+ import { addIssue } from "./issues.mjs";
4
+ const SOURCE_SCAN_FILE_PATTERN = /\.(?:[cm]?[jt]s|json)$/u;
5
+ const SOURCE_SCAN_IGNORED_DIRECTORY_NAMES = new Set([
6
+ '.codex',
7
+ '.fastcontext',
8
+ '.git',
9
+ '.mf',
10
+ '.modernjs',
11
+ '.output',
12
+ 'coverage',
13
+ 'dist',
14
+ 'dist-cloudflare',
15
+ 'node_modules',
16
+ 'repos',
17
+ 'topology'
18
+ ]);
19
+ const FORBIDDEN_MUTATION_PATTERNS = [
20
+ {
21
+ code: 'forbidden-mutation-pattern',
22
+ message: "Generated Cloudflare server worker output must not be rewritten by app scripts.",
23
+ pattern: /\.output\/server\/index\.mjs/u
24
+ },
25
+ {
26
+ code: 'forbidden-mutation-pattern',
27
+ message: "Generated Cloudflare server worker output must not be rewritten by app scripts.",
28
+ pattern: /path\.(?:join|resolve)\(\s*['"`]\.output['"`]\s*,\s*['"`]server['"`]\s*,\s*['"`]index\.mjs['"`]\s*\)/u
29
+ },
30
+ {
31
+ code: 'forbidden-mutation-pattern',
32
+ message: "Generated Cloudflare BFF worker bundles must not be rewritten by app scripts.",
33
+ pattern: /\.output\/worker\/[^'"`]*\.(?:mjs|cjs|js)/u
34
+ },
35
+ {
36
+ code: 'forbidden-mutation-pattern',
37
+ message: "Generated Cloudflare BFF worker bundles must not be rewritten by app scripts.",
38
+ pattern: /path\.(?:join|resolve)\(\s*['"`]\.output['"`]\s*,\s*['"`]worker['"`]\s*,\s*['"`][^'"`]+\.(?:mjs|cjs|js)['"`]\s*\)/u
39
+ },
40
+ {
41
+ code: 'forbidden-mutation-pattern',
42
+ message: "Drizzle entityKind worker bundle markers must be fixed in the framework toolchain, not post-build scripts.",
43
+ pattern: /replaceAll\(\s*['"`];entityKind(?:,entityKind)?;/u
44
+ },
45
+ {
46
+ code: 'forbidden-mutation-pattern',
47
+ message: "Effect BFF Cloudflare dispatch must not depend on duck-typed runtime helper probing in app scripts.",
48
+ pattern: /(?:typeof\s+[^;\n]*dispatchEffectBffRequest|['"`]dispatchEffectBffRequest['"`]\s+in\s+|\.dispatchEffectBffRequest\b)/u
49
+ },
50
+ {
51
+ code: 'forbidden-mutation-pattern',
52
+ message: "Effect BFF Cloudflare dispatch must not branch on handler.length in app scripts.",
53
+ pattern: /\bhandler\s*\.\s*length\b/u
54
+ }
55
+ ];
56
+ const pathExists = async (filePath)=>{
57
+ try {
58
+ await promises.access(filePath);
59
+ return true;
60
+ } catch {
61
+ return false;
62
+ }
63
+ };
64
+ const walkFiles = async (root)=>{
65
+ if (!await pathExists(root)) return [];
66
+ const entries = await promises.readdir(root, {
67
+ withFileTypes: true
68
+ });
69
+ const files = [];
70
+ for (const entry of entries){
71
+ if (SOURCE_SCAN_IGNORED_DIRECTORY_NAMES.has(entry.name)) continue;
72
+ const entryPath = node_path.join(root, entry.name);
73
+ if (entry.isDirectory()) {
74
+ files.push(...await walkFiles(entryPath));
75
+ continue;
76
+ }
77
+ if (SOURCE_SCAN_FILE_PATTERN.test(entry.name)) files.push(entryPath);
78
+ }
79
+ return files;
80
+ };
81
+ const verifyCloudflareOutputMutationPolicy = async (options)=>{
82
+ const issues = [];
83
+ const files = (await Promise.all(options.scanRoots.map((scanRoot)=>walkFiles(node_path.resolve(scanRoot))))).flat();
84
+ for (const file of files){
85
+ const source = await promises.readFile(file, 'utf-8');
86
+ for (const forbidden of FORBIDDEN_MUTATION_PATTERNS)if (forbidden.pattern.test(source)) addIssue(issues, {
87
+ code: forbidden.code,
88
+ message: forbidden.message,
89
+ path: file
90
+ });
91
+ }
92
+ return {
93
+ ok: 0 === issues.length,
94
+ issues
95
+ };
96
+ };
97
+ export { verifyCloudflareOutputMutationPolicy, walkFiles };
@@ -0,0 +1,68 @@
1
+ import node_path from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ import { CLOUDFLARE_WORKER_BUNDLE_DIRECTORY } from "../cloudflare-output-contract.mjs";
4
+ import { addIssue } from "./issues.mjs";
5
+ const getReferencedRouteWorkers = (manifest)=>Array.isArray(manifest?.routeSpec?.routes) ? manifest.routeSpec.routes.map((route)=>'string' == typeof route?.worker && route.worker.length > 0 ? route.worker : void 0).filter((worker)=>'string' == typeof worker) : [];
6
+ const getEffectBffWorker = (manifest)=>manifest?.bff?.runtimeFramework === 'effect' && 'string' == typeof manifest.bff.worker ? manifest.bff.worker : void 0;
7
+ const getWorkerBundleReferences = (manifest)=>{
8
+ const effectBffWorker = getEffectBffWorker(manifest);
9
+ return [
10
+ ...effectBffWorker ? [
11
+ {
12
+ kind: 'effect-bff',
13
+ reference: effectBffWorker
14
+ }
15
+ ] : [],
16
+ ...getReferencedRouteWorkers(manifest).map((reference)=>({
17
+ kind: 'route',
18
+ reference
19
+ }))
20
+ ];
21
+ };
22
+ const resolveWorkerBundleReference = (issues, outputDirectory, reference, manifestPath)=>{
23
+ const workerRoot = node_path.resolve(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY);
24
+ const workerPath = node_path.resolve(outputDirectory, reference.reference);
25
+ const relativeToWorkerRoot = node_path.relative(workerRoot, workerPath);
26
+ if (node_path.isAbsolute(reference.reference) || relativeToWorkerRoot.startsWith('..') || node_path.isAbsolute(relativeToWorkerRoot)) {
27
+ addIssue(issues, {
28
+ code: 'invalid-manifest',
29
+ message: 'Cloudflare output manifest worker bundle references must stay under worker/.',
30
+ path: manifestPath
31
+ });
32
+ return null;
33
+ }
34
+ return {
35
+ ...reference,
36
+ path: workerPath
37
+ };
38
+ };
39
+ const missingWorkerBundleMessage = (reference)=>'effect-bff' === reference.kind ? 'Cloudflare Effect BFF manifest points to a missing worker bundle.' : 'Cloudflare route worker manifest points to a missing worker bundle.';
40
+ const FORBIDDEN_WORKER_BUNDLE_REFERENCE_PATTERNS = [
41
+ /\.\.\/server\//u,
42
+ /\.output\/server\//u,
43
+ /server\/index\.mjs/u
44
+ ];
45
+ const verifyWorkerBundleReferences = (issues, worker, source)=>{
46
+ if (FORBIDDEN_WORKER_BUNDLE_REFERENCE_PATTERNS.some((pattern)=>pattern.test(source))) addIssue(issues, {
47
+ code: 'invalid-worker-bundle',
48
+ message: 'Cloudflare worker bundles must not reference framework-owned server output paths.',
49
+ path: worker.path
50
+ });
51
+ };
52
+ const verifyWorkerImport = async (issues, entryPath)=>{
53
+ try {
54
+ const worker = (await import(`${pathToFileURL(entryPath).href}?t=${Date.now()}`)).default;
55
+ if (!worker || 'function' != typeof worker.fetch) addIssue(issues, {
56
+ code: 'worker-import-failed',
57
+ message: 'Cloudflare server entry must default-export a Worker with fetch.',
58
+ path: entryPath
59
+ });
60
+ } catch (error) {
61
+ addIssue(issues, {
62
+ code: 'worker-import-failed',
63
+ message: `Cloudflare server entry could not be imported: ${error instanceof Error ? error.message : String(error)}`,
64
+ path: entryPath
65
+ });
66
+ }
67
+ };
68
+ export { getEffectBffWorker, getWorkerBundleReferences, missingWorkerBundleMessage, resolveWorkerBundleReference, verifyWorkerBundleReferences, verifyWorkerImport };
@@ -0,0 +1,22 @@
1
+ const MODERN_WORKER_MANIFEST = p_workerManifest;
2
+ p_workerModuleLoaders;
3
+ new Map();
4
+ new Map();
5
+ new Map();
6
+ const CORS_POLICY = MODERN_WORKER_MANIFEST.security?.cors || {};
7
+ CORS_POLICY.assets;
8
+ (CORS_POLICY.allowedOrigins || []).map((origin)=>String(origin).toLowerCase());
9
+ (CORS_POLICY.allowedMethods?.length ? CORS_POLICY.allowedMethods : [
10
+ 'GET',
11
+ 'HEAD',
12
+ 'POST',
13
+ 'PUT',
14
+ 'PATCH',
15
+ 'DELETE',
16
+ 'OPTIONS'
17
+ ]).join(', ');
18
+ (CORS_POLICY.allowedHeaders?.length ? CORS_POLICY.allowedHeaders : [
19
+ '*'
20
+ ]).join(', ');
21
+ globalThis.__dirname ??= '/';
22
+ globalThis.__filename ??= '/index.js';
@@ -0,0 +1,32 @@
1
+ export default {
2
+ async fetch (request, env, ctx) {
3
+ const corsPreflightResponse = await createCorsPreflightResponse(request, env);
4
+ if (corsPreflightResponse) return finalizeResponseForRequest(corsPreflightResponse, request);
5
+ const bffResponse = await dispatchBffRequest(request, env);
6
+ if (bffResponse) return finalizeResponseForRequest(withAppCorsHeaders(bffResponse, request), request);
7
+ const serviceBindingResponse = await dispatchServiceBindingRequest(request, env);
8
+ if (serviceBindingResponse) return finalizeResponseForRequest(withAppCorsHeaders(serviceBindingResponse, request), request);
9
+ const route = findRoute(request);
10
+ const { pathname } = new URL(request.url);
11
+ if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) {
12
+ const assetResponse = await fetchAsset(request, env);
13
+ if (assetResponse) return finalizeResponseForRequest(assetResponse, request);
14
+ return finalizeResponseForRequest(withAppCorsHeaders(new Response('Not found', {
15
+ status: 404
16
+ }), request), request);
17
+ }
18
+ const localeRedirectResponse = createLocaleRedirectResponseForRequest(route, request);
19
+ if (localeRedirectResponse) return finalizeResponseForRequest(withAppCorsHeaders(localeRedirectResponse, request), request);
20
+ if (route?.worker) {
21
+ const renderableRequest = createRenderableRequest(request);
22
+ return finalizeResponseForRequest(withAppCorsHeaders(await dispatchRouteWorker(route, renderableRequest, env, ctx), request), request);
23
+ }
24
+ const htmlResponse = await fetchRouteHtml(route, request, env);
25
+ if (htmlResponse) return finalizeResponseForRequest(htmlResponse, request);
26
+ const assetResponse = await fetchAsset(request, env);
27
+ if (assetResponse) return finalizeResponseForRequest(assetResponse, request);
28
+ return finalizeResponseForRequest(withAppCorsHeaders(new Response('Not found', {
29
+ status: 404
30
+ }), request), request);
31
+ }
32
+ };
@@ -264,6 +264,7 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
264
264
  chain.output.module(true).library({
265
265
  type: 'module'
266
266
  }).chunkFormat('module').chunkLoading('import').workerChunkLoading('import');
267
+ chain.optimization.usedExports(false).providedExports(true).innerGraph(false).sideEffects(false);
267
268
  chain.plugins.delete('plugin-module-federation');
268
269
  if (tanstackRouterSsrServerFile) {
269
270
  chain.resolve.alias.set('@tanstack/router-core/ssr/server$', tanstackRouterSsrServerFile);
@@ -31,10 +31,19 @@ const mergeCompressionOptions = (base, next)=>{
31
31
  ...base,
32
32
  ...next
33
33
  };
34
- if (base.compressionOptions || next.compressionOptions) merged.compressionOptions = {
35
- ...base.compressionOptions,
36
- ...next.compressionOptions
37
- };
34
+ if (base.compressionOptions || next.compressionOptions) {
35
+ const baseCompressionOptions = base.compressionOptions;
36
+ const nextCompressionOptions = next.compressionOptions;
37
+ const mergedCompressionOptions = {
38
+ ...baseCompressionOptions,
39
+ ...nextCompressionOptions
40
+ };
41
+ if (baseCompressionOptions?.params || nextCompressionOptions?.params) mergedCompressionOptions.params = {
42
+ ...baseCompressionOptions?.params,
43
+ ...nextCompressionOptions?.params
44
+ };
45
+ merged.compressionOptions = mergedCompressionOptions;
46
+ }
38
47
  return merged;
39
48
  };
40
49
  const resolveCodecOptions = (codecConfig, createDefaultOptions)=>{
@@ -21,7 +21,6 @@ function buildRouteEagerLazyCompilationTest(eagerRouteFiles, userTest) {
21
21
  return userTestFn(m);
22
22
  };
23
23
  }
24
- const buildSSRLazyCompilationTest = buildRouteEagerLazyCompilationTest;
25
24
  function planRouteEagerLazyCompilation(current, info) {
26
25
  if (!current) return {
27
26
  apply: false
@@ -43,5 +42,4 @@ function planRouteEagerLazyCompilation(current, info) {
43
42
  }
44
43
  };
45
44
  }
46
- const planSSRLazyCompilation = planRouteEagerLazyCompilation;
47
- export { aggregateEagerRouteComponentFiles, buildRouteEagerLazyCompilationTest, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planRouteEagerLazyCompilation, planSSRLazyCompilation };
45
+ export { aggregateEagerRouteComponentFiles, buildRouteEagerLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planRouteEagerLazyCompilation };
@@ -41,5 +41,4 @@ const infoCommand = (program, api)=>{
41
41
  await info(api, options);
42
42
  });
43
43
  };
44
- export { runtimeCommand } from "./runtime.mjs";
45
44
  export { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, serverCommand };
@@ -5,11 +5,12 @@ import { getLocaleLanguage } from "@modern-js/i18n-utils/language-detector";
5
5
  import { createAsyncHook } from "@modern-js/plugin";
6
6
  import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
7
7
  import path from "path";
8
- import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, runtimeCommand, serverCommand } from "./commands/index.mjs";
8
+ import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, serverCommand } from "./commands/index.mjs";
9
9
  import { compatPlugin } from "./compat/index.mjs";
10
10
  import { DEFAULT_RUNTIME_CONFIG_FILE } from "./constants.mjs";
11
11
  import { i18n } from "./locale/index.mjs";
12
12
  import analyze from "./plugins/analyze/index.mjs";
13
+ import backendFederationBuild from "./plugins/backendFederationBuild.mjs";
13
14
  import deploy from "./plugins/deploy/index.mjs";
14
15
  import initialize from "./plugins/initialize/index.mjs";
15
16
  import serverBuild from "./plugins/serverBuild.mjs";
@@ -17,10 +18,8 @@ import serverRuntime from "./plugins/serverRuntime.mjs";
17
18
  import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
18
19
  import { initAppContext } from "./utils/initAppContext.mjs";
19
20
  import { restart } from "./utils/restart.mjs";
20
- export * from "./baseline.mjs";
21
21
  export * from "./defineConfig.mjs";
22
22
  export * from "./presetUltramodern.mjs";
23
- export * from "./ultramodern/designSystem.mjs";
24
23
  export * from "./types/index.mjs";
25
24
  const appTools = ()=>({
26
25
  name: '@modern-js/app-tools',
@@ -30,6 +29,7 @@ const appTools = ()=>({
30
29
  initialize(),
31
30
  analyze(),
32
31
  serverBuild(),
32
+ backendFederationBuild(),
33
33
  deploy()
34
34
  ],
35
35
  post: [
@@ -74,7 +74,6 @@ const appTools = ()=>({
74
74
  deployCommand(program, api);
75
75
  inspectCommand(program, api);
76
76
  infoCommand(program, api);
77
- await runtimeCommand(program, api);
78
77
  deprecatedCommands(program);
79
78
  });
80
79
  api.onPrepare(async ()=>{
@@ -2,7 +2,7 @@ import "node:module";
2
2
  import { findExists, fs } from "@modern-js/utils";
3
3
  import path from "path";
4
4
  import { HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER } from "./constants.mjs";
5
- import * as __rspack_external__templates_mjs_4da4c6c8 from "./templates.mjs";
5
+ import * as __rspack_external__templates_mjs_ab577925 from "./templates.mjs";
6
6
  const findPartials = (dir, entryName, position)=>{
7
7
  if (fs.existsSync(dir)) {
8
8
  const base = findExists(HTML_PARTIALS_EXTENSIONS.map((ext)=>path.resolve(dir, `${position}${ext}`)));
@@ -83,7 +83,7 @@ const getHtmlTemplate = async (entrypoints, hooks, { appContext, config })=>{
83
83
  partials: getModifyHtmlPartials(partials)
84
84
  });
85
85
  const templatePath = path.resolve(internalDirectory, entryName, 'index.html');
86
- fs.outputFileSync(templatePath, __rspack_external__templates_mjs_4da4c6c8.html(partials), 'utf8');
86
+ fs.outputFileSync(templatePath, __rspack_external__templates_mjs_ab577925.html(partials), 'utf8');
87
87
  htmlTemplates[entryName] = templatePath.replace(/\\/g, '/');
88
88
  partialsByEntrypoint[entryName] = partials;
89
89
  const bottomTemplate = findPartials(htmlDir, name, "bottom");
@@ -2,8 +2,8 @@ import "node:module";
2
2
  import { parse } from "@babel/parser";
3
3
  import traverse from "@babel/traverse";
4
4
  import fs from "fs";
5
- import * as __rspack_external__babel_types_69e65b52 from "@babel/types";
6
- const isFunction = (node)=>__rspack_external__babel_types_69e65b52.isFunctionDeclaration(node) || __rspack_external__babel_types_69e65b52.isFunctionExpression(node) || __rspack_external__babel_types_69e65b52.isArrowFunctionExpression(node);
5
+ import * as __rspack_external__babel_types_6e8337dd from "@babel/types";
6
+ const isFunction = (node)=>__rspack_external__babel_types_6e8337dd.isFunctionDeclaration(node) || __rspack_external__babel_types_6e8337dd.isFunctionExpression(node) || __rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(node);
7
7
  const isDefaultExportFunction = (file)=>{
8
8
  if (!file || !fs.existsSync(file)) return false;
9
9
  const ast = parse(fs.readFileSync(file, 'utf8'), {