@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,46 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_OUTPUT_PACKAGE_FILE, CLOUDFLARE_OUTPUT_PACKAGE_TYPE, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY, CLOUDFLARE_WORKER_ENTRY, CLOUDFLARE_WORKER_MANIFEST, CLOUDFLARE_WORKER_PACKAGE_FILE, CLOUDFLARE_WORKER_PACKAGE_TYPE, CLOUDFLARE_WRANGLER_CONFIG_FILE } from "./cloudflare-output-contract.mjs";
4
+ const resolveOutput = (outputDirectory, relativePath)=>node_path.join(outputDirectory, relativePath);
5
+ function createCloudflareOutputPlan(outputDirectory) {
6
+ return {
7
+ outputDirectory,
8
+ requiredFiles: [
9
+ CLOUDFLARE_WORKER_ENTRY,
10
+ CLOUDFLARE_WORKER_MANIFEST,
11
+ CLOUDFLARE_WRANGLER_CONFIG_FILE,
12
+ CLOUDFLARE_OUTPUT_PACKAGE_FILE
13
+ ],
14
+ publicLeakDirectories: [
15
+ 'server',
16
+ CLOUDFLARE_WORKER_BUNDLE_DIRECTORY
17
+ ],
18
+ paths: {
19
+ workerEntry: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_ENTRY),
20
+ workerManifest: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_MANIFEST),
21
+ wranglerConfig: resolveOutput(outputDirectory, CLOUDFLARE_WRANGLER_CONFIG_FILE),
22
+ outputPackage: resolveOutput(outputDirectory, CLOUDFLARE_OUTPUT_PACKAGE_FILE),
23
+ workerPackage: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_PACKAGE_FILE),
24
+ publicAssets: resolveOutput(outputDirectory, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY),
25
+ workerBundle: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY)
26
+ },
27
+ packages: {
28
+ output: {
29
+ type: CLOUDFLARE_OUTPUT_PACKAGE_TYPE
30
+ },
31
+ worker: {
32
+ type: CLOUDFLARE_WORKER_PACKAGE_TYPE
33
+ }
34
+ },
35
+ wrangler: {
36
+ main: CLOUDFLARE_WORKER_ENTRY,
37
+ assets: {
38
+ binding: CLOUDFLARE_ASSETS_BINDING,
39
+ directory: `./${CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY}`,
40
+ run_worker_first: true
41
+ },
42
+ requiredCompatibilityFlags: CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS
43
+ }
44
+ };
45
+ }
46
+ export { createCloudflareOutputPlan };
@@ -0,0 +1,46 @@
1
+ import "node:module";
2
+ import { DELIVERY_UNIT_IDENTITY_FIELDS, deliveryUnitIdentityFieldValue } from "@modern-js/utils/universal";
3
+ import { addIssue, assertEqual } from "./issues.mjs";
4
+ const verifyDeliveryUnitIdentity = (issues, manifest, manifestPath, declared)=>{
5
+ const stamped = manifest?.deliveryUnit;
6
+ const hasStamp = Boolean(stamped) && 'object' == typeof stamped;
7
+ if (declared) {
8
+ if (!hasStamp) return void addIssue(issues, {
9
+ code: 'missing-delivery-unit',
10
+ message: `Cloudflare worker manifest is missing the delivery-unit identity declared by the workspace topology (expected unitId ${declared.unitId}, buildMarker ${declared.buildMarker}).`,
11
+ path: manifestPath
12
+ });
13
+ for (const field of DELIVERY_UNIT_IDENTITY_FIELDS){
14
+ const stampedValue = deliveryUnitIdentityFieldValue(stamped, field);
15
+ assertEqual(issues, stampedValue, declared[field], {
16
+ code: 'delivery-unit-drift',
17
+ message: `Cloudflare worker manifest deliveryUnit.${field} must match the topology delivery-unit record (expected ${declared[field]}, received ${stampedValue ?? 'undefined'}).`,
18
+ path: manifestPath
19
+ });
20
+ }
21
+ }
22
+ if (hasStamp && stamped.surfaces && 'object' == typeof stamped.surfaces) for (const surface of [
23
+ 'ui',
24
+ 'api'
25
+ ]){
26
+ const marker = stamped.surfaces[surface];
27
+ if (!marker || 'object' != typeof marker) {
28
+ addIssue(issues, {
29
+ code: 'missing-delivery-unit',
30
+ message: `Cloudflare worker manifest is missing the ${surface} delivery-unit surface marker.`,
31
+ path: manifestPath
32
+ });
33
+ continue;
34
+ }
35
+ for (const field of DELIVERY_UNIT_IDENTITY_FIELDS){
36
+ const markerValue = deliveryUnitIdentityFieldValue(marker, field);
37
+ const stampedValue = deliveryUnitIdentityFieldValue(stamped, field);
38
+ assertEqual(issues, markerValue, stampedValue, {
39
+ code: 'delivery-unit-drift',
40
+ message: `Cloudflare worker manifest ${surface} surface deliveryUnit.${field} must derive from one delivery-unit record (expected ${stampedValue ?? 'undefined'}, received ${markerValue ?? 'undefined'}).`,
41
+ path: manifestPath
42
+ });
43
+ }
44
+ }
45
+ };
46
+ export { verifyDeliveryUnitIdentity };
@@ -0,0 +1,130 @@
1
+ import "node:module";
2
+ import promises from "node:fs/promises";
3
+ import node_path from "node:path";
4
+ import { createCloudflareOutputPlan } from "../cloudflare-output-plan.mjs";
5
+ import { verifyDeliveryUnitIdentity } from "./identity.mjs";
6
+ import { addIssue, assertEqual, assertFlag } from "./issues.mjs";
7
+ import { verifyManifestShape } from "./manifest.mjs";
8
+ import { getEffectBffWorker, getWorkerBundleReferences, missingWorkerBundleMessage, resolveWorkerBundleReference, verifyWorkerBundleReferences, verifyWorkerImport } from "./worker-bundles.mjs";
9
+ const pathExists = async (filePath)=>{
10
+ try {
11
+ await promises.access(filePath);
12
+ return true;
13
+ } catch {
14
+ return false;
15
+ }
16
+ };
17
+ const readJson = async (filePath)=>JSON.parse(await promises.readFile(filePath, 'utf-8'));
18
+ const verifyCloudflareOutput = async (options)=>{
19
+ const outputDirectory = node_path.resolve(options.outputDirectory);
20
+ const issues = [];
21
+ const outputPlan = createCloudflareOutputPlan(outputDirectory);
22
+ for (const relativePath of outputPlan.requiredFiles){
23
+ const filePath = node_path.join(outputDirectory, relativePath);
24
+ if (!await pathExists(filePath)) addIssue(issues, {
25
+ code: 'missing-file',
26
+ message: `Cloudflare output is missing ${relativePath}.`,
27
+ path: filePath
28
+ });
29
+ }
30
+ const manifestPath = outputPlan.paths.workerManifest;
31
+ const wranglerPath = outputPlan.paths.wranglerConfig;
32
+ const packagePath = outputPlan.paths.outputPackage;
33
+ const workerPackagePath = outputPlan.paths.workerPackage;
34
+ const manifest = await pathExists(manifestPath) ? await readJson(manifestPath) : void 0;
35
+ const wrangler = await pathExists(wranglerPath) ? await readJson(wranglerPath) : void 0;
36
+ const outputPackage = await pathExists(packagePath) ? await readJson(packagePath) : void 0;
37
+ const workerPackage = await pathExists(workerPackagePath) ? await readJson(workerPackagePath) : void 0;
38
+ if (manifest) {
39
+ verifyManifestShape(issues, manifest, manifestPath);
40
+ verifyDeliveryUnitIdentity(issues, manifest, manifestPath, options.deliveryUnit);
41
+ const workerReferences = getWorkerBundleReferences(manifest);
42
+ if (workerReferences.length > 0 && !await pathExists(workerPackagePath)) addIssue(issues, {
43
+ code: 'missing-file',
44
+ message: 'Cloudflare output is missing worker/package.json for referenced worker bundles.',
45
+ path: workerPackagePath
46
+ });
47
+ if (manifest.bff?.runtimeFramework === 'effect' && !getEffectBffWorker(manifest)) addIssue(issues, {
48
+ code: 'missing-worker-bundle',
49
+ message: 'Cloudflare Effect BFF manifest points to a missing worker bundle.'
50
+ });
51
+ for (const workerReference of workerReferences){
52
+ const resolvedWorker = resolveWorkerBundleReference(issues, outputDirectory, workerReference, manifestPath);
53
+ if (!resolvedWorker) continue;
54
+ const workerExists = await pathExists(resolvedWorker.path);
55
+ if (!workerExists) addIssue(issues, {
56
+ code: 'missing-worker-bundle',
57
+ message: missingWorkerBundleMessage(workerReference),
58
+ path: resolvedWorker.path
59
+ });
60
+ if (workerExists) {
61
+ const workerSource = await promises.readFile(resolvedWorker.path, 'utf-8');
62
+ verifyWorkerBundleReferences(issues, resolvedWorker, workerSource);
63
+ if ('effect-bff' === resolvedWorker.kind && (workerSource.includes(';entityKind;') || workerSource.includes(';entityKind,entityKind;'))) addIssue(issues, {
64
+ code: 'invalid-worker-bundle',
65
+ message: 'Cloudflare Effect BFF worker bundle contains invalid Drizzle entityKind marker references.',
66
+ path: resolvedWorker.path
67
+ });
68
+ }
69
+ }
70
+ }
71
+ if (wrangler) {
72
+ assertEqual(issues, wrangler.main, outputPlan.wrangler.main, {
73
+ code: 'invalid-wrangler',
74
+ message: `wrangler.json main must be ${outputPlan.wrangler.main}.`,
75
+ path: wranglerPath
76
+ });
77
+ assertEqual(issues, wrangler.assets?.binding, outputPlan.wrangler.assets.binding, {
78
+ code: 'invalid-wrangler',
79
+ message: 'wrangler.json assets.binding must be ASSETS.',
80
+ path: wranglerPath
81
+ });
82
+ assertEqual(issues, wrangler.assets?.directory, outputPlan.wrangler.assets.directory, {
83
+ code: 'invalid-wrangler',
84
+ message: 'wrangler.json assets.directory must be ./public.',
85
+ path: wranglerPath
86
+ });
87
+ assertEqual(issues, wrangler.assets?.run_worker_first, outputPlan.wrangler.assets.run_worker_first, {
88
+ code: 'invalid-wrangler',
89
+ message: 'wrangler.json assets.run_worker_first must be true.',
90
+ path: wranglerPath
91
+ });
92
+ for (const flag of outputPlan.wrangler.requiredCompatibilityFlags)assertFlag(issues, wrangler.compatibility_flags, flag, {
93
+ code: 'invalid-wrangler',
94
+ message: `wrangler.json compatibility_flags must include ${flag}.`,
95
+ path: wranglerPath
96
+ });
97
+ }
98
+ if (outputPackage) assertEqual(issues, outputPackage.type, outputPlan.packages.output.type, {
99
+ code: 'invalid-package',
100
+ message: '.output/package.json must declare type module.',
101
+ path: packagePath
102
+ });
103
+ if (workerPackage) assertEqual(issues, workerPackage.type, outputPlan.packages.worker.type, {
104
+ code: 'invalid-package',
105
+ message: '.output/worker/package.json must declare type commonjs.',
106
+ path: workerPackagePath
107
+ });
108
+ for (const leakedPath of outputPlan.publicLeakDirectories){
109
+ const publicPath = node_path.join(outputPlan.paths.publicAssets, leakedPath);
110
+ if (await pathExists(publicPath)) addIssue(issues, {
111
+ code: 'public-output-leak',
112
+ message: `Framework-owned ${leakedPath} output leaked into public assets.`,
113
+ path: publicPath
114
+ });
115
+ }
116
+ if (false !== options.importWorker && await pathExists(outputPlan.paths.workerEntry)) await verifyWorkerImport(issues, outputPlan.paths.workerEntry);
117
+ return {
118
+ ok: 0 === issues.length,
119
+ issues
120
+ };
121
+ };
122
+ const assertCloudflareOutput = async (options)=>{
123
+ const result = await verifyCloudflareOutput(options);
124
+ if (!result.ok) throw new Error([
125
+ 'Cloudflare output verification failed:',
126
+ ...result.issues.map((issue)=>`- ${issue.code}: ${issue.message}${issue.path ? ` (${issue.path})` : ''}`)
127
+ ].join('\n'));
128
+ };
129
+ export { verifyCloudflareOutputMutationPolicy } from "./mutation-policy.mjs";
130
+ export { assertCloudflareOutput, verifyCloudflareOutput };
@@ -0,0 +1,11 @@
1
+ import "node:module";
2
+ const addIssue = (issues, issue)=>{
3
+ issues.push(issue);
4
+ };
5
+ const assertEqual = (issues, actual, expected, issue)=>{
6
+ if (actual !== expected) addIssue(issues, issue);
7
+ };
8
+ const assertFlag = (issues, flags, flag, issue)=>{
9
+ if (!Array.isArray(flags) || !flags.includes(flag)) addIssue(issues, issue);
10
+ };
11
+ export { addIssue, assertEqual, assertFlag };
@@ -0,0 +1,46 @@
1
+ import "node:module";
2
+ import { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_ENTRY } from "../cloudflare-output-contract.mjs";
3
+ import { addIssue, assertEqual } from "./issues.mjs";
4
+ const verifyManifestShape = (issues, manifest, manifestPath)=>{
5
+ assertEqual(issues, manifest.runtime?.type, CLOUDFLARE_RUNTIME_TYPE, {
6
+ code: 'invalid-manifest',
7
+ message: 'Cloudflare output manifest runtime.type must be cloudflare-module-worker.',
8
+ path: manifestPath
9
+ });
10
+ assertEqual(issues, manifest.runtime?.entry, CLOUDFLARE_WORKER_ENTRY, {
11
+ code: 'invalid-manifest',
12
+ message: `Cloudflare output manifest runtime.entry must be ${CLOUDFLARE_WORKER_ENTRY}.`,
13
+ path: manifestPath
14
+ });
15
+ assertEqual(issues, manifest.runtime?.fetchExport, true, {
16
+ code: 'invalid-manifest',
17
+ message: 'Cloudflare output manifest runtime.fetchExport must be true.',
18
+ path: manifestPath
19
+ });
20
+ assertEqual(issues, manifest.runtime?.nodeListen, false, {
21
+ code: 'invalid-manifest',
22
+ message: 'Cloudflare output manifest runtime.nodeListen must be false.',
23
+ path: manifestPath
24
+ });
25
+ assertEqual(issues, manifest.assets?.binding, CLOUDFLARE_ASSETS_BINDING, {
26
+ code: 'invalid-manifest',
27
+ message: 'Cloudflare output manifest assets.binding must be ASSETS.',
28
+ path: manifestPath
29
+ });
30
+ assertEqual(issues, manifest.assets?.directory, `./${CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY}`, {
31
+ code: 'invalid-manifest',
32
+ message: 'Cloudflare output manifest assets.directory must be ./public.',
33
+ path: manifestPath
34
+ });
35
+ assertEqual(issues, manifest.assets?.runWorkerFirst, true, {
36
+ code: 'invalid-manifest',
37
+ message: 'Cloudflare output manifest assets.runWorkerFirst must be true.',
38
+ path: manifestPath
39
+ });
40
+ if (!Array.isArray(manifest.routeSpec?.routes)) addIssue(issues, {
41
+ code: 'invalid-manifest',
42
+ message: 'Cloudflare output manifest routeSpec.routes must be array.',
43
+ path: manifestPath
44
+ });
45
+ };
46
+ export { verifyManifestShape };
@@ -0,0 +1,98 @@
1
+ import "node:module";
2
+ import promises from "node:fs/promises";
3
+ import node_path from "node:path";
4
+ import { addIssue } from "./issues.mjs";
5
+ const SOURCE_SCAN_FILE_PATTERN = /\.(?:[cm]?[jt]s|json)$/u;
6
+ const SOURCE_SCAN_IGNORED_DIRECTORY_NAMES = new Set([
7
+ '.codex',
8
+ '.fastcontext',
9
+ '.git',
10
+ '.mf',
11
+ '.modernjs',
12
+ '.output',
13
+ 'coverage',
14
+ 'dist',
15
+ 'dist-cloudflare',
16
+ 'node_modules',
17
+ 'repos',
18
+ 'topology'
19
+ ]);
20
+ const FORBIDDEN_MUTATION_PATTERNS = [
21
+ {
22
+ code: 'forbidden-mutation-pattern',
23
+ message: "Generated Cloudflare server worker output must not be rewritten by app scripts.",
24
+ pattern: /\.output\/server\/index\.mjs/u
25
+ },
26
+ {
27
+ code: 'forbidden-mutation-pattern',
28
+ message: "Generated Cloudflare server worker output must not be rewritten by app scripts.",
29
+ pattern: /path\.(?:join|resolve)\(\s*['"`]\.output['"`]\s*,\s*['"`]server['"`]\s*,\s*['"`]index\.mjs['"`]\s*\)/u
30
+ },
31
+ {
32
+ code: 'forbidden-mutation-pattern',
33
+ message: "Generated Cloudflare BFF worker bundles must not be rewritten by app scripts.",
34
+ pattern: /\.output\/worker\/[^'"`]*\.(?:mjs|cjs|js)/u
35
+ },
36
+ {
37
+ code: 'forbidden-mutation-pattern',
38
+ message: "Generated Cloudflare BFF worker bundles must not be rewritten by app scripts.",
39
+ pattern: /path\.(?:join|resolve)\(\s*['"`]\.output['"`]\s*,\s*['"`]worker['"`]\s*,\s*['"`][^'"`]+\.(?:mjs|cjs|js)['"`]\s*\)/u
40
+ },
41
+ {
42
+ code: 'forbidden-mutation-pattern',
43
+ message: "Drizzle entityKind worker bundle markers must be fixed in the framework toolchain, not post-build scripts.",
44
+ pattern: /replaceAll\(\s*['"`];entityKind(?:,entityKind)?;/u
45
+ },
46
+ {
47
+ code: 'forbidden-mutation-pattern',
48
+ message: "Effect BFF Cloudflare dispatch must not depend on duck-typed runtime helper probing in app scripts.",
49
+ pattern: /(?:typeof\s+[^;\n]*dispatchEffectBffRequest|['"`]dispatchEffectBffRequest['"`]\s+in\s+|\.dispatchEffectBffRequest\b)/u
50
+ },
51
+ {
52
+ code: 'forbidden-mutation-pattern',
53
+ message: "Effect BFF Cloudflare dispatch must not branch on handler.length in app scripts.",
54
+ pattern: /\bhandler\s*\.\s*length\b/u
55
+ }
56
+ ];
57
+ const pathExists = async (filePath)=>{
58
+ try {
59
+ await promises.access(filePath);
60
+ return true;
61
+ } catch {
62
+ return false;
63
+ }
64
+ };
65
+ const walkFiles = async (root)=>{
66
+ if (!await pathExists(root)) return [];
67
+ const entries = await promises.readdir(root, {
68
+ withFileTypes: true
69
+ });
70
+ const files = [];
71
+ for (const entry of entries){
72
+ if (SOURCE_SCAN_IGNORED_DIRECTORY_NAMES.has(entry.name)) continue;
73
+ const entryPath = node_path.join(root, entry.name);
74
+ if (entry.isDirectory()) {
75
+ files.push(...await walkFiles(entryPath));
76
+ continue;
77
+ }
78
+ if (SOURCE_SCAN_FILE_PATTERN.test(entry.name)) files.push(entryPath);
79
+ }
80
+ return files;
81
+ };
82
+ const verifyCloudflareOutputMutationPolicy = async (options)=>{
83
+ const issues = [];
84
+ const files = (await Promise.all(options.scanRoots.map((scanRoot)=>walkFiles(node_path.resolve(scanRoot))))).flat();
85
+ for (const file of files){
86
+ const source = await promises.readFile(file, 'utf-8');
87
+ for (const forbidden of FORBIDDEN_MUTATION_PATTERNS)if (forbidden.pattern.test(source)) addIssue(issues, {
88
+ code: forbidden.code,
89
+ message: forbidden.message,
90
+ path: file
91
+ });
92
+ }
93
+ return {
94
+ ok: 0 === issues.length,
95
+ issues
96
+ };
97
+ };
98
+ export { verifyCloudflareOutputMutationPolicy, walkFiles };
@@ -0,0 +1,69 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { CLOUDFLARE_WORKER_BUNDLE_DIRECTORY } from "../cloudflare-output-contract.mjs";
5
+ import { addIssue } from "./issues.mjs";
6
+ 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) : [];
7
+ const getEffectBffWorker = (manifest)=>manifest?.bff?.runtimeFramework === 'effect' && 'string' == typeof manifest.bff.worker ? manifest.bff.worker : void 0;
8
+ const getWorkerBundleReferences = (manifest)=>{
9
+ const effectBffWorker = getEffectBffWorker(manifest);
10
+ return [
11
+ ...effectBffWorker ? [
12
+ {
13
+ kind: 'effect-bff',
14
+ reference: effectBffWorker
15
+ }
16
+ ] : [],
17
+ ...getReferencedRouteWorkers(manifest).map((reference)=>({
18
+ kind: 'route',
19
+ reference
20
+ }))
21
+ ];
22
+ };
23
+ const resolveWorkerBundleReference = (issues, outputDirectory, reference, manifestPath)=>{
24
+ const workerRoot = node_path.resolve(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY);
25
+ const workerPath = node_path.resolve(outputDirectory, reference.reference);
26
+ const relativeToWorkerRoot = node_path.relative(workerRoot, workerPath);
27
+ if (node_path.isAbsolute(reference.reference) || relativeToWorkerRoot.startsWith('..') || node_path.isAbsolute(relativeToWorkerRoot)) {
28
+ addIssue(issues, {
29
+ code: 'invalid-manifest',
30
+ message: 'Cloudflare output manifest worker bundle references must stay under worker/.',
31
+ path: manifestPath
32
+ });
33
+ return null;
34
+ }
35
+ return {
36
+ ...reference,
37
+ path: workerPath
38
+ };
39
+ };
40
+ 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.';
41
+ const FORBIDDEN_WORKER_BUNDLE_REFERENCE_PATTERNS = [
42
+ /\.\.\/server\//u,
43
+ /\.output\/server\//u,
44
+ /server\/index\.mjs/u
45
+ ];
46
+ const verifyWorkerBundleReferences = (issues, worker, source)=>{
47
+ if (FORBIDDEN_WORKER_BUNDLE_REFERENCE_PATTERNS.some((pattern)=>pattern.test(source))) addIssue(issues, {
48
+ code: 'invalid-worker-bundle',
49
+ message: 'Cloudflare worker bundles must not reference framework-owned server output paths.',
50
+ path: worker.path
51
+ });
52
+ };
53
+ const verifyWorkerImport = async (issues, entryPath)=>{
54
+ try {
55
+ const worker = (await import(`${pathToFileURL(entryPath).href}?t=${Date.now()}`)).default;
56
+ if (!worker || 'function' != typeof worker.fetch) addIssue(issues, {
57
+ code: 'worker-import-failed',
58
+ message: 'Cloudflare server entry must default-export a Worker with fetch.',
59
+ path: entryPath
60
+ });
61
+ } catch (error) {
62
+ addIssue(issues, {
63
+ code: 'worker-import-failed',
64
+ message: `Cloudflare server entry could not be imported: ${error instanceof Error ? error.message : String(error)}`,
65
+ path: entryPath
66
+ });
67
+ }
68
+ };
69
+ 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
+ };
@@ -1,12 +1,13 @@
1
1
  import type { Rspack, RspackChain } from '@rsbuild/core';
2
2
  import type { AppNormalizedConfig } from '../../types';
3
3
  import type { AppToolsContext } from '../../types/plugin';
4
+ declare const info: (file: {
5
+ sourceFilename: string;
6
+ }) => {
7
+ minimized: boolean;
8
+ };
4
9
  export declare function createPublicPattern(appContext: AppToolsContext, config: AppNormalizedConfig, chain: RspackChain): {
5
- info: (file: {
6
- sourceFilename: string;
7
- }) => {
8
- minimized: boolean;
9
- };
10
+ info: typeof info;
10
11
  from: string;
11
12
  to: string;
12
13
  context: string;
@@ -14,3 +15,4 @@ export declare function createPublicPattern(appContext: AppToolsContext, config:
14
15
  transform: (content: Buffer, absoluteFrom: string) => string | Buffer<ArrayBufferLike>;
15
16
  };
16
17
  export declare function createUploadPattern(appContext: AppToolsContext, config: AppNormalizedConfig): Rspack.CopyRspackPluginOptions['patterns']['0'];
18
+ export {};
@@ -6,7 +6,7 @@ type ModuleLike = {
6
6
  type LazyCompilationTestFn = (m: ModuleLike) => boolean;
7
7
  /** Matches Rspack's `LazyCompilationOptions['test']`. */
8
8
  type LazyCompilationTest = RegExp | LazyCompilationTestFn | undefined;
9
- export type EagerRouteComponentInfo = {
9
+ type EagerRouteComponentInfo = {
10
10
  files: Set<string>;
11
11
  /** Specifiers that could not be resolved, keyed by entry name. */
12
12
  unresolvedByEntry: Map<string, string[]>;
@@ -26,8 +26,7 @@ export declare function aggregateEagerRouteComponentFiles(byEntry: EagerRouteCom
26
26
  * (defaulting to lazy when the user did not provide one).
27
27
  */
28
28
  export declare function buildRouteEagerLazyCompilationTest(eagerRouteFiles: Set<string>, userTest?: LazyCompilationTest): LazyCompilationTestFn;
29
- export declare const buildSSRLazyCompilationTest: typeof buildRouteEagerLazyCompilationTest;
30
- export type SSRLazyPlan = {
29
+ type SSRLazyPlan = {
31
30
  apply: false;
32
31
  unresolvedByEntry?: Map<string, string[]>;
33
32
  } | {
@@ -42,4 +41,3 @@ export type SSRLazyPlan = {
42
41
  * existing `dev.lazyCompilation` value (lazy must be enabled for this to apply).
43
42
  */
44
43
  export declare function planRouteEagerLazyCompilation(current: unknown, info: EagerRouteComponentInfo): SSRLazyPlan;
45
- export declare const planSSRLazyCompilation: typeof planRouteEagerLazyCompilation;
@@ -7,4 +7,3 @@ export declare const serverCommand: (program: Command, api: CLIPluginAPI<AppTool
7
7
  export declare const deployCommand: (program: Command, api: CLIPluginAPI<AppTools>) => void;
8
8
  export declare const inspectCommand: (program: Command, api: CLIPluginAPI<AppTools>) => void;
9
9
  export declare const infoCommand: (program: Command, api: CLIPluginAPI<AppTools>) => void;
10
- export { runtimeCommand } from './runtime';
@@ -1,9 +1,7 @@
1
1
  import type { AppTools, CliPlugin } from './types';
2
2
  import { initAppContext } from './utils/initAppContext';
3
- export * from './baseline';
4
3
  export * from './defineConfig';
5
4
  export * from './presetUltramodern';
6
- export * from './ultramodern/designSystem';
7
5
  export declare const appTools: () => CliPlugin<AppTools>;
8
6
  export { dev } from './commands/dev';
9
7
  export { serve } from './commands/serve';