@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.30 → 3.5.0-ultramodern.31

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 (116) hide show
  1. package/dist/cjs/plugins/backend-federation/codegen.js +208 -0
  2. package/dist/cjs/plugins/backend-federation/config.js +217 -0
  3. package/dist/cjs/plugins/backend-federation/emit.js +139 -0
  4. package/dist/cjs/plugins/backendFederationBuild.js +4 -298
  5. package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
  6. package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
  7. package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +118 -0
  8. package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
  9. package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
  10. package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +223 -0
  11. package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
  12. package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
  13. package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
  14. package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
  15. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
  16. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
  17. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/issues.js +54 -0
  18. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
  19. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +158 -0
  20. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +137 -0
  21. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +23 -363
  22. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +2 -745
  23. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  24. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  25. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  26. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  27. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  28. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  29. package/dist/esm/plugins/backend-federation/codegen.mjs +157 -0
  30. package/dist/esm/plugins/backend-federation/config.mjs +141 -0
  31. package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
  32. package/dist/esm/plugins/backendFederationBuild.mjs +1 -296
  33. package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
  34. package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
  35. package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +67 -0
  36. package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
  37. package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
  38. package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
  39. package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
  40. package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
  41. package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
  42. package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
  43. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
  44. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
  45. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
  46. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
  47. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
  48. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
  49. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -347
  50. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +1 -735
  51. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  52. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  53. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  54. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  55. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  56. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  57. package/dist/esm-node/plugins/backend-federation/codegen.mjs +158 -0
  58. package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
  59. package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
  60. package/dist/esm-node/plugins/backendFederationBuild.mjs +1 -296
  61. package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
  62. package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
  63. package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +68 -0
  64. package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
  65. package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
  66. package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
  67. package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
  68. package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
  69. package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
  70. package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
  71. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
  72. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
  73. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
  74. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
  75. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
  76. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
  77. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -347
  78. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +1 -735
  79. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  80. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  81. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  82. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  83. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  84. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  85. package/dist/types/plugins/backend-federation/codegen.d.ts +82 -0
  86. package/dist/types/plugins/backend-federation/config.d.ts +103 -0
  87. package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
  88. package/dist/types/plugins/backendFederationBuild.d.ts +2 -11
  89. package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
  90. package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
  91. package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
  92. package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +21 -0
  93. package/dist/types/plugins/deploy/platforms/cloudflare/index.d.ts +2 -0
  94. package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +88 -0
  95. package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
  96. package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
  97. package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +100 -0
  98. package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
  99. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
  100. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
  101. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
  102. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
  103. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +13 -0
  104. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +16 -0
  105. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +1 -32
  106. package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +1 -2
  107. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
  108. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
  109. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
  110. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
  111. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
  112. package/package.json +11 -11
  113. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
  114. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
  115. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
  116. /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ resolveTopologyDeliveryUnit: ()=>resolveTopologyDeliveryUnit,
41
+ resolveWorkerDeliveryUnitStamp: ()=>resolveWorkerDeliveryUnitStamp
42
+ });
43
+ const external_node_path_namespaceObject = require("node:path");
44
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
+ const utils_namespaceObject = require("@modern-js/utils");
46
+ const universal_namespaceObject = require("@modern-js/utils/universal");
47
+ const external_utils_js_namespaceObject = require("./utils.js");
48
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
49
+ const findWorkspaceRoot = async (appDirectory)=>{
50
+ let current = external_node_path_default().resolve(appDirectory);
51
+ for(;;){
52
+ if (await utils_namespaceObject.fs.pathExists(external_node_path_default().join(current, COMPACT_CONFIG_PATH))) return current;
53
+ const parent = external_node_path_default().dirname(current);
54
+ if (parent === current) return;
55
+ current = parent;
56
+ }
57
+ };
58
+ const resolveTopologyDeliveryUnit = async (appDirectory)=>{
59
+ const workspaceRoot = await findWorkspaceRoot(appDirectory);
60
+ if (!workspaceRoot) return;
61
+ let compactConfig;
62
+ try {
63
+ compactConfig = await utils_namespaceObject.fs.readJSON(external_node_path_default().join(workspaceRoot, COMPACT_CONFIG_PATH));
64
+ } catch {
65
+ return;
66
+ }
67
+ if (!(0, external_utils_js_namespaceObject.isRecord)(compactConfig)) return;
68
+ const topology = (0, external_utils_js_namespaceObject.isRecord)(compactConfig.topology) ? compactConfig.topology : void 0;
69
+ const apps = Array.isArray(topology?.apps) ? topology.apps : [];
70
+ const resolvedAppDirectory = external_node_path_default().resolve(appDirectory);
71
+ for (const app of apps){
72
+ if (!(0, external_utils_js_namespaceObject.isRecord)(app)) continue;
73
+ const appPath = (0, universal_namespaceObject.nonEmptyString)(app.path);
74
+ if (appPath && external_node_path_default().resolve(workspaceRoot, appPath.replace(/^\.\/+/u, '')) === resolvedAppDirectory) return (0, universal_namespaceObject.toDeliveryUnitIdentity)(app.deliveryUnit);
75
+ }
76
+ return (0, universal_namespaceObject.toDeliveryUnitIdentity)(compactConfig.deliveryUnit);
77
+ };
78
+ const resolveWorkerDeliveryUnitStamp = async (appDirectory)=>{
79
+ const buildArtifactPath = external_node_path_default().join(appDirectory, universal_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_PATH);
80
+ const buildModulePath = external_node_path_default().join(appDirectory, universal_namespaceObject.ULTRAMODERN_BUILD_MODULE_PATH);
81
+ let identity;
82
+ if (await utils_namespaceObject.fs.pathExists(buildArtifactPath)) {
83
+ const artifact = await utils_namespaceObject.fs.readJSON(buildArtifactPath);
84
+ if (!(0, universal_namespaceObject.isUltramodernBuildArtifact)(artifact)) return;
85
+ identity = (0, universal_namespaceObject.toDeliveryUnitIdentity)(artifact.deliveryUnit);
86
+ } else if (await utils_namespaceObject.fs.pathExists(buildModulePath)) {
87
+ console.warn(`[cloudflare] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ultramodern-build.json.`);
88
+ const source = await utils_namespaceObject.fs.readFile(buildModulePath, 'utf8');
89
+ identity = (0, universal_namespaceObject.toDeliveryUnitIdentity)({
90
+ buildMarker: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
91
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
92
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
93
+ });
94
+ }
95
+ if (!identity) return;
96
+ return {
97
+ ...identity,
98
+ surfaces: {
99
+ ui: {
100
+ ...identity,
101
+ surface: 'ui'
102
+ },
103
+ api: {
104
+ ...identity,
105
+ surface: 'api'
106
+ }
107
+ }
108
+ };
109
+ };
110
+ exports.resolveTopologyDeliveryUnit = __webpack_exports__.resolveTopologyDeliveryUnit;
111
+ exports.resolveWorkerDeliveryUnitStamp = __webpack_exports__.resolveWorkerDeliveryUnitStamp;
112
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
113
+ "resolveTopologyDeliveryUnit",
114
+ "resolveWorkerDeliveryUnitStamp"
115
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
116
+ Object.defineProperty(exports, '__esModule', {
117
+ value: true
118
+ });
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ createI18nWorkerManifest: ()=>createI18nWorkerManifest
32
+ });
33
+ const external_utils_js_namespaceObject = require("./utils.js");
34
+ const I18N_SERVER_PLUGIN_NAME = 'plugin-i18n/server';
35
+ const DEFAULT_I18NEXT_DETECTION_OPTIONS = {
36
+ order: [
37
+ 'querystring',
38
+ 'cookie',
39
+ 'localStorage',
40
+ 'header',
41
+ 'navigator',
42
+ 'htmlTag',
43
+ 'path',
44
+ 'subdomain'
45
+ ],
46
+ lookupQuerystring: 'lng',
47
+ lookupCookie: 'i18next',
48
+ lookupHeader: 'accept-language'
49
+ };
50
+ const SERVER_SIDE_I18N_DETECTORS = new Set([
51
+ 'querystring',
52
+ 'cookie',
53
+ 'header'
54
+ ]);
55
+ const toStringArray = (value)=>Array.isArray(value) ? value.filter((entry)=>'string' == typeof entry) : [];
56
+ const getI18nServerPlugin = (appContext)=>appContext.serverPlugins?.find((plugin)=>plugin.name.includes(I18N_SERVER_PLUGIN_NAME));
57
+ const removeLocaleDetectionByEntry = (config)=>{
58
+ const { localeDetectionByEntry: _localeDetectionByEntry, ...rest } = config;
59
+ return rest;
60
+ };
61
+ const getEntryLocaleDetection = (entryName, localeDetection)=>{
62
+ const byEntry = (0, external_utils_js_namespaceObject.isRecord)(localeDetection.localeDetectionByEntry) ? localeDetection.localeDetectionByEntry : void 0;
63
+ const entryConfig = byEntry?.[entryName];
64
+ const globalConfig = removeLocaleDetectionByEntry(localeDetection);
65
+ return (0, external_utils_js_namespaceObject.isRecord)(entryConfig) ? {
66
+ ...globalConfig,
67
+ ...entryConfig
68
+ } : globalConfig;
69
+ };
70
+ const normalizeI18nDetection = (detection)=>{
71
+ const configured = (0, external_utils_js_namespaceObject.isRecord)(detection) ? detection : {};
72
+ const rawOrder = Array.isArray(configured.order) ? configured.order : DEFAULT_I18NEXT_DETECTION_OPTIONS.order;
73
+ const order = rawOrder.filter((entry)=>'string' == typeof entry && SERVER_SIDE_I18N_DETECTORS.has(entry));
74
+ return {
75
+ order: order.length > 0 ? order : [
76
+ 'querystring',
77
+ 'cookie',
78
+ 'header'
79
+ ],
80
+ lookupQuerystring: 'string' == typeof configured.lookupQuerystring && configured.lookupQuerystring ? configured.lookupQuerystring : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupQuerystring,
81
+ lookupCookie: 'string' == typeof configured.lookupCookie && configured.lookupCookie ? configured.lookupCookie : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupCookie,
82
+ lookupHeader: 'string' == typeof configured.lookupHeader && configured.lookupHeader ? configured.lookupHeader : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupHeader
83
+ };
84
+ };
85
+ const normalizeLocalisedUrls = (localisedUrls)=>{
86
+ if (!(0, external_utils_js_namespaceObject.isRecord)(localisedUrls) || 0 === Object.keys(localisedUrls).length) return;
87
+ const normalized = {};
88
+ for (const [canonicalPath, languageMap] of Object.entries(localisedUrls)){
89
+ if (!(0, external_utils_js_namespaceObject.isRecord)(languageMap)) continue;
90
+ const normalizedLanguageMap = Object.fromEntries(Object.entries(languageMap).filter((entry)=>'string' == typeof entry[1] && entry[1].length > 0));
91
+ if (Object.keys(normalizedLanguageMap).length > 0) normalized[canonicalPath] = normalizedLanguageMap;
92
+ }
93
+ return Object.keys(normalized).length > 0 ? normalized : void 0;
94
+ };
95
+ const normalizeWorkerI18nEntry = (entryName, localeDetection, staticRoutePrefixes)=>{
96
+ const entryConfig = getEntryLocaleDetection(entryName, localeDetection);
97
+ const languages = toStringArray(entryConfig.languages);
98
+ if (true !== entryConfig.localePathRedirect || 0 === languages.length) return;
99
+ const fallbackLanguage = 'string' == typeof entryConfig.fallbackLanguage && entryConfig.fallbackLanguage ? entryConfig.fallbackLanguage : 'en';
100
+ const ignoreRedirectRoutes = Array.isArray(entryConfig.ignoreRedirectRoutes) ? toStringArray(entryConfig.ignoreRedirectRoutes) : [];
101
+ const localisedUrls = normalizeLocalisedUrls(entryConfig.localisedUrls);
102
+ return {
103
+ i18nextDetector: false !== entryConfig.i18nextDetector,
104
+ languages,
105
+ fallbackLanguage,
106
+ detection: normalizeI18nDetection(entryConfig.detection),
107
+ ignoreRedirectRoutes,
108
+ staticRoutePrefixes,
109
+ ...localisedUrls ? {
110
+ localisedUrls
111
+ } : {}
112
+ };
113
+ };
114
+ const createI18nWorkerManifest = (routeSpec, appContext)=>{
115
+ const i18nServerPlugin = getI18nServerPlugin(appContext);
116
+ const localeDetection = i18nServerPlugin?.options?.localeDetection;
117
+ if (!(0, external_utils_js_namespaceObject.isRecord)(localeDetection)) return;
118
+ const staticRoutePrefixes = toStringArray(i18nServerPlugin?.options?.staticRoutePrefixes);
119
+ const entries = {};
120
+ for (const route of routeSpec.routes){
121
+ if ('string' != typeof route.entryName || entries[route.entryName]) continue;
122
+ const entry = normalizeWorkerI18nEntry(route.entryName, localeDetection, staticRoutePrefixes);
123
+ if (entry) entries[route.entryName] = entry;
124
+ }
125
+ return Object.keys(entries).length > 0 ? {
126
+ entries
127
+ } : void 0;
128
+ };
129
+ exports.createI18nWorkerManifest = __webpack_exports__.createI18nWorkerManifest;
130
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
131
+ "createI18nWorkerManifest"
132
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
133
+ Object.defineProperty(exports, '__esModule', {
134
+ value: true
135
+ });
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ createCloudflarePreset: ()=>createCloudflarePreset
41
+ });
42
+ const external_node_path_namespaceObject = require("node:path");
43
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
44
+ const utils_namespaceObject = require("@modern-js/utils");
45
+ const index_js_namespaceObject = require("../../utils/index.js");
46
+ const external_cloudflare_output_plan_js_namespaceObject = require("../cloudflare-output-plan.js");
47
+ const external_cloudflare_output_verifier_js_namespaceObject = require("../cloudflare-output-verifier.js");
48
+ const external_artifacts_js_namespaceObject = require("./artifacts.js");
49
+ const external_constants_js_namespaceObject = require("./constants.js");
50
+ const external_delivery_unit_js_namespaceObject = require("./delivery-unit.js");
51
+ const external_worker_manifest_js_namespaceObject = require("./worker-manifest.js");
52
+ const external_wrangler_config_js_namespaceObject = require("./wrangler-config.js");
53
+ const CLOUDFLARE_ENTRY_TEMPLATE_FRAGMENTS = [
54
+ 'cloudflare-entry.001-bootstrap-security.mjs',
55
+ 'cloudflare-entry.002-assets-routes.mjs',
56
+ 'cloudflare-entry.003-i18n-locales.mjs',
57
+ 'cloudflare-entry.004-rendering-css.mjs',
58
+ 'cloudflare-entry.005-worker-dispatch.mjs',
59
+ 'cloudflare-entry.006-fetch-handler.mjs'
60
+ ];
61
+ const readCloudflareEntryTemplate = async ()=>(await Promise.all(CLOUDFLARE_ENTRY_TEMPLATE_FRAGMENTS.map((fragment)=>(0, index_js_namespaceObject.readTemplate)(fragment)))).join('');
62
+ const createCloudflarePreset = ({ appContext, modernConfig })=>{
63
+ const { appDirectory, distDirectory } = appContext;
64
+ const outputDirectory = external_node_path_default().join(appDirectory, '.output');
65
+ const outputPlan = (0, external_cloudflare_output_plan_js_namespaceObject.createCloudflareOutputPlan)(outputDirectory);
66
+ const publicDirectory = outputPlan.paths.publicAssets;
67
+ const workerEntryPath = outputPlan.paths.workerEntry;
68
+ const workerManifestPath = outputPlan.paths.workerManifest;
69
+ const routeSpecOutputPath = external_node_path_default().join(outputDirectory, external_constants_js_namespaceObject.ROUTE_SPEC_OUTPUT);
70
+ const wranglerConfigPath = outputPlan.paths.wranglerConfig;
71
+ const cloudflareArtifacts = (0, external_artifacts_js_namespaceObject.getCloudflareArtifacts)(modernConfig);
72
+ const publicAssetExcludes = (0, external_worker_manifest_js_namespaceObject.getPublicAssetExcludes)(appDirectory, modernConfig);
73
+ return {
74
+ async prepare () {
75
+ await utils_namespaceObject.fs.remove(outputDirectory);
76
+ },
77
+ async writeOutput () {
78
+ await utils_namespaceObject.fs.copy(distDirectory, publicDirectory, {
79
+ filter: (src)=>(0, external_worker_manifest_js_namespaceObject.shouldCopyToPublicAssets)(src, distDirectory, publicAssetExcludes)
80
+ });
81
+ await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerEntryPath));
82
+ await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerManifestPath));
83
+ const routeSpecSourcePath = external_node_path_default().join(distDirectory, external_constants_js_namespaceObject.ROUTE_SPEC_FILE);
84
+ if (await utils_namespaceObject.fs.pathExists(routeSpecSourcePath)) await utils_namespaceObject.fs.copy(routeSpecSourcePath, routeSpecOutputPath);
85
+ const workerBundleSourceDirectory = external_node_path_default().join(distDirectory, external_constants_js_namespaceObject.WORKER_BUNDLE_DIRECTORY);
86
+ const workerBundleOutputDirectory = outputPlan.paths.workerBundle;
87
+ if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) {
88
+ await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
89
+ filter: (src)=>(0, external_worker_manifest_js_namespaceObject.shouldCopyToWorkerBundle)(src, workerBundleSourceDirectory)
90
+ });
91
+ await utils_namespaceObject.fs.writeJSON(outputPlan.paths.workerPackage, outputPlan.packages.worker);
92
+ }
93
+ await (0, external_artifacts_js_namespaceObject.copyCloudflareArtifacts)(appDirectory, outputDirectory, cloudflareArtifacts);
94
+ await (0, external_artifacts_js_namespaceObject.copyCloudflarePublicAssets)(appDirectory, publicDirectory, (0, external_artifacts_js_namespaceObject.getCloudflarePublicAssets)(modernConfig));
95
+ await (0, external_artifacts_js_namespaceObject.copyCloudflareD1Migrations)(appDirectory, outputDirectory, modernConfig);
96
+ await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, (0, external_wrangler_config_js_namespaceObject.createWranglerConfig)(appDirectory, modernConfig), {
97
+ spaces: 2
98
+ });
99
+ const deliveryUnitStamp = await (0, external_delivery_unit_js_namespaceObject.resolveWorkerDeliveryUnitStamp)(appDirectory);
100
+ await utils_namespaceObject.fs.writeJSON(workerManifestPath, await (0, external_worker_manifest_js_namespaceObject.createWorkerManifest)(outputDirectory, modernConfig, appContext, deliveryUnitStamp), {
101
+ spaces: 2
102
+ });
103
+ await utils_namespaceObject.fs.writeJSON(outputPlan.paths.outputPackage, outputPlan.packages.output);
104
+ },
105
+ async genEntry () {
106
+ const template = await readCloudflareEntryTemplate();
107
+ const manifest = await utils_namespaceObject.fs.readJSON(workerManifestPath);
108
+ await utils_namespaceObject.fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', (0, external_worker_manifest_js_namespaceObject.createWorkerModuleLoaders)(manifest)));
109
+ const topologyDeliveryUnit = await (0, external_delivery_unit_js_namespaceObject.resolveTopologyDeliveryUnit)(appDirectory);
110
+ await (0, external_cloudflare_output_verifier_js_namespaceObject.assertCloudflareOutput)({
111
+ outputDirectory,
112
+ importWorker: false,
113
+ ...topologyDeliveryUnit ? {
114
+ deliveryUnit: topologyDeliveryUnit
115
+ } : {}
116
+ });
117
+ }
118
+ };
119
+ };
120
+ exports.createCloudflarePreset = __webpack_exports__.createCloudflarePreset;
121
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
122
+ "createCloudflarePreset"
123
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
124
+ Object.defineProperty(exports, '__esModule', {
125
+ value: true
126
+ });
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const DEFAULT_SECURITY_HEADERS = {
31
+ referrerPolicy: 'strict-origin-when-cross-origin',
32
+ contentTypeOptions: 'nosniff',
33
+ permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
34
+ };
35
+ const DEFAULT_CORS_ALLOWED_METHODS = [
36
+ 'GET',
37
+ 'HEAD',
38
+ 'POST',
39
+ 'PUT',
40
+ 'PATCH',
41
+ 'DELETE',
42
+ 'OPTIONS'
43
+ ];
44
+ const DEFAULT_CSP_DIRECTIVES = {
45
+ 'base-uri': [
46
+ "'self'"
47
+ ],
48
+ 'connect-src': [
49
+ "'self'",
50
+ 'https:',
51
+ 'http:',
52
+ 'wss:',
53
+ 'ws:'
54
+ ],
55
+ 'default-src': [
56
+ "'self'"
57
+ ],
58
+ 'font-src': [
59
+ "'self'",
60
+ 'data:',
61
+ 'https:',
62
+ 'http:'
63
+ ],
64
+ 'form-action': [
65
+ "'self'"
66
+ ],
67
+ 'frame-ancestors': [
68
+ "'self'"
69
+ ],
70
+ 'img-src': [
71
+ "'self'",
72
+ 'data:',
73
+ 'blob:',
74
+ 'https:',
75
+ 'http:'
76
+ ],
77
+ 'manifest-src': [
78
+ "'self'",
79
+ 'https:',
80
+ 'http:'
81
+ ],
82
+ 'object-src': [
83
+ "'none'"
84
+ ],
85
+ "script-src": [
86
+ "'self'",
87
+ "'unsafe-inline'",
88
+ "'unsafe-eval'",
89
+ 'https:',
90
+ 'http:',
91
+ 'blob:'
92
+ ],
93
+ 'style-src': [
94
+ "'self'",
95
+ "'unsafe-inline'",
96
+ 'https:',
97
+ 'http:'
98
+ ],
99
+ 'worker-src': [
100
+ "'self'",
101
+ 'blob:'
102
+ ]
103
+ };
104
+ const normalizeDirectiveValues = (value)=>{
105
+ const values = Array.isArray(value) ? value : [
106
+ value
107
+ ];
108
+ return [
109
+ ...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
110
+ ];
111
+ };
112
+ const appendDirectiveValues = (directives, name, values)=>{
113
+ if (!values?.length) return;
114
+ directives[name] = normalizeDirectiveValues([
115
+ ...directives[name] ?? [],
116
+ ...values
117
+ ]);
118
+ };
119
+ const createContentSecurityPolicy = (config)=>{
120
+ const mode = config?.mode ?? 'report-only';
121
+ if ('off' === mode) return {
122
+ mode,
123
+ directives: {},
124
+ reason: config?.reason
125
+ };
126
+ const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
127
+ name,
128
+ [
129
+ ...values
130
+ ]
131
+ ]));
132
+ for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
133
+ else directives[name] = normalizeDirectiveValues(value);
134
+ if (config?.frameAncestors === false) delete directives['frame-ancestors'];
135
+ else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
136
+ appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
137
+ appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
138
+ appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
139
+ appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
140
+ if (config?.reportUri) directives['report-uri'] = [
141
+ config.reportUri
142
+ ];
143
+ return {
144
+ mode,
145
+ directives,
146
+ reason: config?.reason
147
+ };
148
+ };
149
+ const createNoindexPolicy = (noindex)=>{
150
+ if (false === noindex) return {
151
+ workersDev: false,
152
+ localhost: false,
153
+ previewHostnames: []
154
+ };
155
+ if (true === noindex || void 0 === noindex) return {
156
+ workersDev: true,
157
+ localhost: true,
158
+ previewHostnames: []
159
+ };
160
+ return {
161
+ workersDev: noindex.workersDev ?? true,
162
+ localhost: noindex.localhost ?? true,
163
+ previewHostnames: noindex.previewHostnames ?? [],
164
+ reason: noindex.reason
165
+ };
166
+ };
167
+ const createCloudflareWorkerCorsPolicy = (cors)=>({
168
+ assets: cors?.assets ?? true,
169
+ allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
170
+ allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
171
+ allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
172
+ '*'
173
+ ],
174
+ reason: cors?.reason
175
+ });
176
+ const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
177
+ const security = modernConfig.deploy?.worker?.security;
178
+ if (security?.enabled === false) return {
179
+ enabled: false,
180
+ cors: createCloudflareWorkerCorsPolicy(security.cors),
181
+ reason: security.reason
182
+ };
183
+ return {
184
+ enabled: true,
185
+ headers: {
186
+ referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
187
+ contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
188
+ permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
189
+ },
190
+ contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
191
+ noindex: createNoindexPolicy(security?.noindex),
192
+ cors: createCloudflareWorkerCorsPolicy(security?.cors),
193
+ reason: security?.reason
194
+ };
195
+ };
196
+ __webpack_require__.d(__webpack_exports__, {}, {
197
+ DEFAULT_CORS_ALLOWED_METHODS: DEFAULT_CORS_ALLOWED_METHODS,
198
+ DEFAULT_CSP_DIRECTIVES: DEFAULT_CSP_DIRECTIVES,
199
+ DEFAULT_SECURITY_HEADERS: DEFAULT_SECURITY_HEADERS,
200
+ createCloudflareWorkerCorsPolicy: createCloudflareWorkerCorsPolicy,
201
+ createCloudflareWorkerSecurityPolicy: createCloudflareWorkerSecurityPolicy,
202
+ createContentSecurityPolicy: createContentSecurityPolicy,
203
+ createNoindexPolicy: createNoindexPolicy
204
+ });
205
+ exports.DEFAULT_CORS_ALLOWED_METHODS = __webpack_exports__.DEFAULT_CORS_ALLOWED_METHODS;
206
+ exports.DEFAULT_CSP_DIRECTIVES = __webpack_exports__.DEFAULT_CSP_DIRECTIVES;
207
+ exports.DEFAULT_SECURITY_HEADERS = __webpack_exports__.DEFAULT_SECURITY_HEADERS;
208
+ exports.createCloudflareWorkerCorsPolicy = __webpack_exports__.createCloudflareWorkerCorsPolicy;
209
+ exports.createCloudflareWorkerSecurityPolicy = __webpack_exports__.createCloudflareWorkerSecurityPolicy;
210
+ exports.createContentSecurityPolicy = __webpack_exports__.createContentSecurityPolicy;
211
+ exports.createNoindexPolicy = __webpack_exports__.createNoindexPolicy;
212
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
213
+ "DEFAULT_CORS_ALLOWED_METHODS",
214
+ "DEFAULT_CSP_DIRECTIVES",
215
+ "DEFAULT_SECURITY_HEADERS",
216
+ "createCloudflareWorkerCorsPolicy",
217
+ "createCloudflareWorkerSecurityPolicy",
218
+ "createContentSecurityPolicy",
219
+ "createNoindexPolicy"
220
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
221
+ Object.defineProperty(exports, '__esModule', {
222
+ value: true
223
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });