@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.30 → 3.5.0-ultramodern.32
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.
- package/dist/cjs/plugins/backend-federation/codegen.js +208 -0
- package/dist/cjs/plugins/backend-federation/config.js +217 -0
- package/dist/cjs/plugins/backend-federation/emit.js +139 -0
- package/dist/cjs/plugins/backendFederationBuild.js +4 -298
- package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +118 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +223 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/issues.js +54 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +158 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +137 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +23 -363
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +2 -745
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
- package/dist/esm/plugins/backend-federation/codegen.mjs +157 -0
- package/dist/esm/plugins/backend-federation/config.mjs +141 -0
- package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
- package/dist/esm/plugins/backendFederationBuild.mjs +1 -296
- package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +67 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -347
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +1 -735
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +158 -0
- package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
- package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
- package/dist/esm-node/plugins/backendFederationBuild.mjs +1 -296
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +68 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -347
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +1 -735
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
- package/dist/types/plugins/backend-federation/codegen.d.ts +82 -0
- package/dist/types/plugins/backend-federation/config.d.ts +103 -0
- package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
- package/dist/types/plugins/backendFederationBuild.d.ts +2 -11
- package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +21 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/index.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +88 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +100 -0
- package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +13 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +16 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +1 -32
- package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +1 -2
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
- package/package.json +11 -11
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
- /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
5
|
var define = (defs, kind)=>{
|
|
@@ -37,743 +28,9 @@ var __webpack_require__ = {};
|
|
|
37
28
|
var __webpack_exports__ = {};
|
|
38
29
|
__webpack_require__.r(__webpack_exports__);
|
|
39
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
createCloudflarePreset: ()=>createCloudflarePreset
|
|
31
|
+
createCloudflarePreset: ()=>index_js_namespaceObject.createCloudflarePreset
|
|
41
32
|
});
|
|
42
|
-
const
|
|
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_contract_js_namespaceObject = require("./cloudflare-output-contract.js");
|
|
47
|
-
const external_cloudflare_output_plan_js_namespaceObject = require("./cloudflare-output-plan.js");
|
|
48
|
-
const external_cloudflare_output_verifier_js_namespaceObject = require("./cloudflare-output-verifier.js");
|
|
49
|
-
const WORKER_ENTRY = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_WORKER_ENTRY;
|
|
50
|
-
const WRANGLER_CONFIG_FILE = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_WRANGLER_CONFIG_FILE;
|
|
51
|
-
const OUTPUT_PACKAGE_FILE = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_OUTPUT_PACKAGE_FILE;
|
|
52
|
-
const ASSETS_BINDING = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_ASSETS_BINDING;
|
|
53
|
-
const ROUTE_SPEC_FILE = 'route.json';
|
|
54
|
-
const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
|
|
55
|
-
const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
|
56
|
-
const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
|
|
57
|
-
const PUBLIC_ASSETS_DIRECTORY = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY;
|
|
58
|
-
const WORKER_BUNDLE_DIRECTORY = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_WORKER_BUNDLE_DIRECTORY;
|
|
59
|
-
const SERVER_BUNDLE_DIRECTORY = 'bundles';
|
|
60
|
-
const SERVER_OUTPUT_DIRECTORY = 'server';
|
|
61
|
-
const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
|
|
62
|
-
'api',
|
|
63
|
-
'shared'
|
|
64
|
-
];
|
|
65
|
-
const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
|
|
66
|
-
const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
|
|
67
|
-
const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
|
|
68
|
-
const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
|
|
69
|
-
const REQUIRED_COMPATIBILITY_FLAGS = external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS;
|
|
70
|
-
const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
|
|
71
|
-
WRANGLER_CONFIG_FILE,
|
|
72
|
-
OUTPUT_PACKAGE_FILE
|
|
73
|
-
]);
|
|
74
|
-
const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
|
|
75
|
-
PUBLIC_ASSETS_DIRECTORY,
|
|
76
|
-
SERVER_OUTPUT_DIRECTORY,
|
|
77
|
-
WORKER_BUNDLE_DIRECTORY
|
|
78
|
-
]);
|
|
79
|
-
const DEFAULT_SECURITY_HEADERS = {
|
|
80
|
-
referrerPolicy: 'strict-origin-when-cross-origin',
|
|
81
|
-
contentTypeOptions: 'nosniff',
|
|
82
|
-
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
83
|
-
};
|
|
84
|
-
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
85
|
-
'GET',
|
|
86
|
-
'HEAD',
|
|
87
|
-
'POST',
|
|
88
|
-
'PUT',
|
|
89
|
-
'PATCH',
|
|
90
|
-
'DELETE',
|
|
91
|
-
'OPTIONS'
|
|
92
|
-
];
|
|
93
|
-
const DEFAULT_CSP_DIRECTIVES = {
|
|
94
|
-
'base-uri': [
|
|
95
|
-
"'self'"
|
|
96
|
-
],
|
|
97
|
-
'connect-src': [
|
|
98
|
-
"'self'",
|
|
99
|
-
'https:',
|
|
100
|
-
'http:',
|
|
101
|
-
'wss:',
|
|
102
|
-
'ws:'
|
|
103
|
-
],
|
|
104
|
-
'default-src': [
|
|
105
|
-
"'self'"
|
|
106
|
-
],
|
|
107
|
-
'font-src': [
|
|
108
|
-
"'self'",
|
|
109
|
-
'data:',
|
|
110
|
-
'https:',
|
|
111
|
-
'http:'
|
|
112
|
-
],
|
|
113
|
-
'form-action': [
|
|
114
|
-
"'self'"
|
|
115
|
-
],
|
|
116
|
-
'frame-ancestors': [
|
|
117
|
-
"'self'"
|
|
118
|
-
],
|
|
119
|
-
'img-src': [
|
|
120
|
-
"'self'",
|
|
121
|
-
'data:',
|
|
122
|
-
'blob:',
|
|
123
|
-
'https:',
|
|
124
|
-
'http:'
|
|
125
|
-
],
|
|
126
|
-
'manifest-src': [
|
|
127
|
-
"'self'",
|
|
128
|
-
'https:',
|
|
129
|
-
'http:'
|
|
130
|
-
],
|
|
131
|
-
'object-src': [
|
|
132
|
-
"'none'"
|
|
133
|
-
],
|
|
134
|
-
"script-src": [
|
|
135
|
-
"'self'",
|
|
136
|
-
"'unsafe-inline'",
|
|
137
|
-
"'unsafe-eval'",
|
|
138
|
-
'https:',
|
|
139
|
-
'http:',
|
|
140
|
-
'blob:'
|
|
141
|
-
],
|
|
142
|
-
'style-src': [
|
|
143
|
-
"'self'",
|
|
144
|
-
"'unsafe-inline'",
|
|
145
|
-
'https:',
|
|
146
|
-
'http:'
|
|
147
|
-
],
|
|
148
|
-
'worker-src': [
|
|
149
|
-
"'self'",
|
|
150
|
-
'blob:'
|
|
151
|
-
]
|
|
152
|
-
};
|
|
153
|
-
const I18N_SERVER_PLUGIN_NAME = 'plugin-i18n/server';
|
|
154
|
-
const DEFAULT_I18NEXT_DETECTION_OPTIONS = {
|
|
155
|
-
order: [
|
|
156
|
-
'querystring',
|
|
157
|
-
'cookie',
|
|
158
|
-
'localStorage',
|
|
159
|
-
'header',
|
|
160
|
-
'navigator',
|
|
161
|
-
'htmlTag',
|
|
162
|
-
'path',
|
|
163
|
-
'subdomain'
|
|
164
|
-
],
|
|
165
|
-
lookupQuerystring: 'lng',
|
|
166
|
-
lookupCookie: 'i18next',
|
|
167
|
-
lookupHeader: 'accept-language'
|
|
168
|
-
};
|
|
169
|
-
const SERVER_SIDE_I18N_DETECTORS = new Set([
|
|
170
|
-
'querystring',
|
|
171
|
-
'cookie',
|
|
172
|
-
'header'
|
|
173
|
-
]);
|
|
174
|
-
const isRecord = (value)=>null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
175
|
-
const toStringArray = (value)=>Array.isArray(value) ? value.filter((entry)=>'string' == typeof entry) : [];
|
|
176
|
-
const getI18nServerPlugin = (appContext)=>appContext.serverPlugins?.find((plugin)=>plugin.name.includes(I18N_SERVER_PLUGIN_NAME));
|
|
177
|
-
const removeLocaleDetectionByEntry = (config)=>{
|
|
178
|
-
const { localeDetectionByEntry: _localeDetectionByEntry, ...rest } = config;
|
|
179
|
-
return rest;
|
|
180
|
-
};
|
|
181
|
-
const getEntryLocaleDetection = (entryName, localeDetection)=>{
|
|
182
|
-
const byEntry = isRecord(localeDetection.localeDetectionByEntry) ? localeDetection.localeDetectionByEntry : void 0;
|
|
183
|
-
const entryConfig = byEntry?.[entryName];
|
|
184
|
-
const globalConfig = removeLocaleDetectionByEntry(localeDetection);
|
|
185
|
-
return isRecord(entryConfig) ? {
|
|
186
|
-
...globalConfig,
|
|
187
|
-
...entryConfig
|
|
188
|
-
} : globalConfig;
|
|
189
|
-
};
|
|
190
|
-
const normalizeI18nDetection = (detection)=>{
|
|
191
|
-
const configured = isRecord(detection) ? detection : {};
|
|
192
|
-
const rawOrder = Array.isArray(configured.order) ? configured.order : DEFAULT_I18NEXT_DETECTION_OPTIONS.order;
|
|
193
|
-
const order = rawOrder.filter((entry)=>'string' == typeof entry && SERVER_SIDE_I18N_DETECTORS.has(entry));
|
|
194
|
-
return {
|
|
195
|
-
order: order.length > 0 ? order : [
|
|
196
|
-
'querystring',
|
|
197
|
-
'cookie',
|
|
198
|
-
'header'
|
|
199
|
-
],
|
|
200
|
-
lookupQuerystring: 'string' == typeof configured.lookupQuerystring && configured.lookupQuerystring ? configured.lookupQuerystring : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupQuerystring,
|
|
201
|
-
lookupCookie: 'string' == typeof configured.lookupCookie && configured.lookupCookie ? configured.lookupCookie : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupCookie,
|
|
202
|
-
lookupHeader: 'string' == typeof configured.lookupHeader && configured.lookupHeader ? configured.lookupHeader : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupHeader
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
const normalizeLocalisedUrls = (localisedUrls)=>{
|
|
206
|
-
if (!isRecord(localisedUrls) || 0 === Object.keys(localisedUrls).length) return;
|
|
207
|
-
const normalized = {};
|
|
208
|
-
for (const [canonicalPath, languageMap] of Object.entries(localisedUrls)){
|
|
209
|
-
if (!isRecord(languageMap)) continue;
|
|
210
|
-
const normalizedLanguageMap = Object.fromEntries(Object.entries(languageMap).filter((entry)=>'string' == typeof entry[1] && entry[1].length > 0));
|
|
211
|
-
if (Object.keys(normalizedLanguageMap).length > 0) normalized[canonicalPath] = normalizedLanguageMap;
|
|
212
|
-
}
|
|
213
|
-
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
214
|
-
};
|
|
215
|
-
const normalizeWorkerI18nEntry = (entryName, localeDetection, staticRoutePrefixes)=>{
|
|
216
|
-
const entryConfig = getEntryLocaleDetection(entryName, localeDetection);
|
|
217
|
-
const languages = toStringArray(entryConfig.languages);
|
|
218
|
-
if (true !== entryConfig.localePathRedirect || 0 === languages.length) return;
|
|
219
|
-
const fallbackLanguage = 'string' == typeof entryConfig.fallbackLanguage && entryConfig.fallbackLanguage ? entryConfig.fallbackLanguage : 'en';
|
|
220
|
-
const ignoreRedirectRoutes = Array.isArray(entryConfig.ignoreRedirectRoutes) ? toStringArray(entryConfig.ignoreRedirectRoutes) : [];
|
|
221
|
-
const localisedUrls = normalizeLocalisedUrls(entryConfig.localisedUrls);
|
|
222
|
-
return {
|
|
223
|
-
i18nextDetector: false !== entryConfig.i18nextDetector,
|
|
224
|
-
languages,
|
|
225
|
-
fallbackLanguage,
|
|
226
|
-
detection: normalizeI18nDetection(entryConfig.detection),
|
|
227
|
-
ignoreRedirectRoutes,
|
|
228
|
-
staticRoutePrefixes,
|
|
229
|
-
...localisedUrls ? {
|
|
230
|
-
localisedUrls
|
|
231
|
-
} : {}
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
const createI18nWorkerManifest = (routeSpec, appContext)=>{
|
|
235
|
-
const i18nServerPlugin = getI18nServerPlugin(appContext);
|
|
236
|
-
const localeDetection = i18nServerPlugin?.options?.localeDetection;
|
|
237
|
-
if (!isRecord(localeDetection)) return;
|
|
238
|
-
const staticRoutePrefixes = toStringArray(i18nServerPlugin?.options?.staticRoutePrefixes);
|
|
239
|
-
const entries = {};
|
|
240
|
-
for (const route of routeSpec.routes){
|
|
241
|
-
if ('string' != typeof route.entryName || entries[route.entryName]) continue;
|
|
242
|
-
const entry = normalizeWorkerI18nEntry(route.entryName, localeDetection, staticRoutePrefixes);
|
|
243
|
-
if (entry) entries[route.entryName] = entry;
|
|
244
|
-
}
|
|
245
|
-
return Object.keys(entries).length > 0 ? {
|
|
246
|
-
entries
|
|
247
|
-
} : void 0;
|
|
248
|
-
};
|
|
249
|
-
const getCompatibilityDate = (modernConfig)=>{
|
|
250
|
-
const configuredDate = modernConfig.deploy?.worker?.compatibilityDate?.trim();
|
|
251
|
-
const compatibilityDate = configuredDate || DEFAULT_COMPATIBILITY_DATE;
|
|
252
|
-
if (!COMPATIBILITY_DATE_PATTERN.test(compatibilityDate)) throw new Error(`deploy.worker.compatibilityDate must use YYYY-MM-DD, received ${JSON.stringify(compatibilityDate)}.`);
|
|
253
|
-
return compatibilityDate;
|
|
254
|
-
};
|
|
255
|
-
const getWorkerName = (appDirectory)=>{
|
|
256
|
-
const basename = external_node_path_default().basename(appDirectory);
|
|
257
|
-
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
258
|
-
};
|
|
259
|
-
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
260
|
-
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
261
|
-
return configuredName || getWorkerName(appDirectory);
|
|
262
|
-
};
|
|
263
|
-
const normalizeRelativePath = (value, label, scope = 'app output', options = {})=>{
|
|
264
|
-
if ('string' != typeof value) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
265
|
-
const normalized = value.trim().replace(/\\/g, '/').replace(/^\.\/+/u, '').replace(/\/+$/u, '');
|
|
266
|
-
const segments = normalized.split('/');
|
|
267
|
-
const isRootDestination = '.' === normalized;
|
|
268
|
-
if (!normalized || external_node_path_default().isAbsolute(normalized) || !options.allowRoot && isRootDestination || segments.includes('..')) throw new Error(`${label} must be a relative path inside the ${scope}.`);
|
|
269
|
-
return normalized;
|
|
270
|
-
};
|
|
271
|
-
const normalizeDirectiveValues = (value)=>{
|
|
272
|
-
const values = Array.isArray(value) ? value : [
|
|
273
|
-
value
|
|
274
|
-
];
|
|
275
|
-
return [
|
|
276
|
-
...new Set(values.map((entry)=>entry.trim()).filter(Boolean))
|
|
277
|
-
];
|
|
278
|
-
};
|
|
279
|
-
const appendDirectiveValues = (directives, name, values)=>{
|
|
280
|
-
if (!values?.length) return;
|
|
281
|
-
directives[name] = normalizeDirectiveValues([
|
|
282
|
-
...directives[name] ?? [],
|
|
283
|
-
...values
|
|
284
|
-
]);
|
|
285
|
-
};
|
|
286
|
-
const createContentSecurityPolicy = (config)=>{
|
|
287
|
-
const mode = config?.mode ?? 'report-only';
|
|
288
|
-
if ('off' === mode) return {
|
|
289
|
-
mode,
|
|
290
|
-
directives: {},
|
|
291
|
-
reason: config?.reason
|
|
292
|
-
};
|
|
293
|
-
const directives = Object.fromEntries(Object.entries(DEFAULT_CSP_DIRECTIVES).map(([name, values])=>[
|
|
294
|
-
name,
|
|
295
|
-
[
|
|
296
|
-
...values
|
|
297
|
-
]
|
|
298
|
-
]));
|
|
299
|
-
for (const [name, value] of Object.entries(config?.directives ?? {}))if (false === value) delete directives[name];
|
|
300
|
-
else directives[name] = normalizeDirectiveValues(value);
|
|
301
|
-
if (config?.frameAncestors === false) delete directives['frame-ancestors'];
|
|
302
|
-
else if (config?.frameAncestors) directives['frame-ancestors'] = normalizeDirectiveValues(config.frameAncestors);
|
|
303
|
-
appendDirectiveValues(directives, "script-src", config?.additionalScriptSrc);
|
|
304
|
-
appendDirectiveValues(directives, 'style-src', config?.additionalStyleSrc);
|
|
305
|
-
appendDirectiveValues(directives, 'connect-src', config?.additionalConnectSrc);
|
|
306
|
-
appendDirectiveValues(directives, 'img-src', config?.additionalImgSrc);
|
|
307
|
-
if (config?.reportUri) directives['report-uri'] = [
|
|
308
|
-
config.reportUri
|
|
309
|
-
];
|
|
310
|
-
return {
|
|
311
|
-
mode,
|
|
312
|
-
directives,
|
|
313
|
-
reason: config?.reason
|
|
314
|
-
};
|
|
315
|
-
};
|
|
316
|
-
const createNoindexPolicy = (noindex)=>{
|
|
317
|
-
if (false === noindex) return {
|
|
318
|
-
workersDev: false,
|
|
319
|
-
localhost: false,
|
|
320
|
-
previewHostnames: []
|
|
321
|
-
};
|
|
322
|
-
if (true === noindex || void 0 === noindex) return {
|
|
323
|
-
workersDev: true,
|
|
324
|
-
localhost: true,
|
|
325
|
-
previewHostnames: []
|
|
326
|
-
};
|
|
327
|
-
return {
|
|
328
|
-
workersDev: noindex.workersDev ?? true,
|
|
329
|
-
localhost: noindex.localhost ?? true,
|
|
330
|
-
previewHostnames: noindex.previewHostnames ?? [],
|
|
331
|
-
reason: noindex.reason
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
335
|
-
assets: cors?.assets ?? true,
|
|
336
|
-
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
337
|
-
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
338
|
-
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
339
|
-
'*'
|
|
340
|
-
],
|
|
341
|
-
reason: cors?.reason
|
|
342
|
-
});
|
|
343
|
-
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
344
|
-
const security = modernConfig.deploy?.worker?.security;
|
|
345
|
-
if (security?.enabled === false) return {
|
|
346
|
-
enabled: false,
|
|
347
|
-
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
348
|
-
reason: security.reason
|
|
349
|
-
};
|
|
350
|
-
return {
|
|
351
|
-
enabled: true,
|
|
352
|
-
headers: {
|
|
353
|
-
referrerPolicy: security?.headers?.referrerPolicy ?? DEFAULT_SECURITY_HEADERS.referrerPolicy,
|
|
354
|
-
contentTypeOptions: security?.headers?.contentTypeOptions ?? DEFAULT_SECURITY_HEADERS.contentTypeOptions,
|
|
355
|
-
permissionsPolicy: security?.headers?.permissionsPolicy ?? DEFAULT_SECURITY_HEADERS.permissionsPolicy
|
|
356
|
-
},
|
|
357
|
-
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
358
|
-
noindex: createNoindexPolicy(security?.noindex),
|
|
359
|
-
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
360
|
-
reason: security?.reason
|
|
361
|
-
};
|
|
362
|
-
};
|
|
363
|
-
const isJsonRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
364
|
-
const getConfiguredWrangler = (modernConfig)=>{
|
|
365
|
-
const wrangler = modernConfig.deploy?.worker?.wrangler;
|
|
366
|
-
if (void 0 === wrangler) return {};
|
|
367
|
-
if (!isJsonRecord(wrangler)) throw new Error('deploy.worker.wrangler must be a JSON object.');
|
|
368
|
-
return wrangler;
|
|
369
|
-
};
|
|
370
|
-
const createWranglerCompatibilityFlags = (configuredFlags)=>{
|
|
371
|
-
if (void 0 === configuredFlags) return [
|
|
372
|
-
...REQUIRED_COMPATIBILITY_FLAGS
|
|
373
|
-
];
|
|
374
|
-
if (!Array.isArray(configuredFlags) || configuredFlags.some((flag)=>'string' != typeof flag)) throw new Error('deploy.worker.wrangler.compatibility_flags must be an array of strings.');
|
|
375
|
-
return [
|
|
376
|
-
...new Set([
|
|
377
|
-
...configuredFlags,
|
|
378
|
-
...REQUIRED_COMPATIBILITY_FLAGS
|
|
379
|
-
])
|
|
380
|
-
];
|
|
381
|
-
};
|
|
382
|
-
const createWranglerAssetsConfig = (configuredAssets)=>{
|
|
383
|
-
if (void 0 !== configuredAssets && !isJsonRecord(configuredAssets)) throw new Error('deploy.worker.wrangler.assets must be an object.');
|
|
384
|
-
return {
|
|
385
|
-
...isJsonRecord(configuredAssets) ? configuredAssets : {},
|
|
386
|
-
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
387
|
-
binding: ASSETS_BINDING,
|
|
388
|
-
run_worker_first: true
|
|
389
|
-
};
|
|
390
|
-
};
|
|
391
|
-
const assertNonEmptyString = (value, label)=>{
|
|
392
|
-
if ('string' != typeof value || 0 === value.trim().length) throw new Error(`${label} must be a non-empty string.`);
|
|
393
|
-
return value.trim();
|
|
394
|
-
};
|
|
395
|
-
const normalizeD1Database = (database, index)=>{
|
|
396
|
-
const binding = assertNonEmptyString(database.binding, `deploy.worker.d1Databases[${index}].binding`);
|
|
397
|
-
const databaseName = assertNonEmptyString(database.databaseName, `deploy.worker.d1Databases[${index}].databaseName`);
|
|
398
|
-
const databaseId = assertNonEmptyString(database.databaseId, `deploy.worker.d1Databases[${index}].databaseId`);
|
|
399
|
-
const migrationsDir = void 0 === database.migrationsDir ? void 0 : normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
400
|
-
const previewDatabaseId = void 0 === database.previewDatabaseId ? void 0 : assertNonEmptyString(database.previewDatabaseId, `deploy.worker.d1Databases[${index}].previewDatabaseId`);
|
|
401
|
-
return {
|
|
402
|
-
binding,
|
|
403
|
-
database_name: databaseName,
|
|
404
|
-
database_id: databaseId,
|
|
405
|
-
...void 0 === migrationsDir ? {} : {
|
|
406
|
-
migrations_dir: migrationsDir
|
|
407
|
-
},
|
|
408
|
-
...void 0 === previewDatabaseId ? {} : {
|
|
409
|
-
preview_database_id: previewDatabaseId
|
|
410
|
-
},
|
|
411
|
-
...void 0 === database.remote ? {} : {
|
|
412
|
-
remote: database.remote
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
};
|
|
416
|
-
const createWranglerD1Databases = (modernConfig, configuredWranglerD1)=>{
|
|
417
|
-
const d1Databases = modernConfig.deploy?.worker?.d1Databases;
|
|
418
|
-
if (void 0 === d1Databases) return configuredWranglerD1;
|
|
419
|
-
if (void 0 !== configuredWranglerD1) throw new Error('Use deploy.worker.d1Databases or deploy.worker.wrangler.d1_databases, not both.');
|
|
420
|
-
if (!Array.isArray(d1Databases)) throw new Error('deploy.worker.d1Databases must be an array.');
|
|
421
|
-
return d1Databases.map(normalizeD1Database);
|
|
422
|
-
};
|
|
423
|
-
const normalizeServiceBinding = (service, index)=>{
|
|
424
|
-
const binding = assertNonEmptyString(service.binding, `deploy.worker.services[${index}].binding`);
|
|
425
|
-
const serviceName = assertNonEmptyString(service.service, `deploy.worker.services[${index}].service`);
|
|
426
|
-
const prefix = void 0 === service.prefix ? void 0 : assertNonEmptyString(service.prefix, `deploy.worker.services[${index}].prefix`);
|
|
427
|
-
return {
|
|
428
|
-
binding,
|
|
429
|
-
service: serviceName,
|
|
430
|
-
...void 0 === prefix ? {} : {
|
|
431
|
-
prefix
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
};
|
|
435
|
-
const createWorkerServiceBindings = (modernConfig, configuredWranglerServices)=>{
|
|
436
|
-
const services = modernConfig.deploy?.worker?.services;
|
|
437
|
-
if (void 0 === services) return configuredWranglerServices;
|
|
438
|
-
if (void 0 !== configuredWranglerServices) throw new Error('Use deploy.worker.services or deploy.worker.wrangler.services, not both.');
|
|
439
|
-
if (!Array.isArray(services)) throw new Error('deploy.worker.services must be an array.');
|
|
440
|
-
return services.map(normalizeServiceBinding);
|
|
441
|
-
};
|
|
442
|
-
const createWranglerServices = (serviceBindings)=>{
|
|
443
|
-
if (!Array.isArray(serviceBindings)) return serviceBindings;
|
|
444
|
-
if (!serviceBindings.every(isJsonRecord)) return serviceBindings;
|
|
445
|
-
return serviceBindings.map((service)=>{
|
|
446
|
-
const { prefix, ...wranglerService } = service;
|
|
447
|
-
return wranglerService;
|
|
448
|
-
});
|
|
449
|
-
};
|
|
450
|
-
const createWorkerManifestServiceBindings = (serviceBindings)=>{
|
|
451
|
-
if (!Array.isArray(serviceBindings)) return;
|
|
452
|
-
const dispatchBindings = serviceBindings.filter((service)=>isJsonRecord(service) && 'string' == typeof service.binding && 'string' == typeof service.service && 'string' == typeof service.prefix).map((service)=>({
|
|
453
|
-
binding: service.binding,
|
|
454
|
-
service: service.service,
|
|
455
|
-
prefix: service.prefix,
|
|
456
|
-
interface: 'fetch'
|
|
457
|
-
}));
|
|
458
|
-
return dispatchBindings.length > 0 ? dispatchBindings : void 0;
|
|
459
|
-
};
|
|
460
|
-
const createWranglerConfig = (appDirectory, modernConfig)=>{
|
|
461
|
-
const wrangler = getConfiguredWrangler(modernConfig);
|
|
462
|
-
const d1Databases = createWranglerD1Databases(modernConfig, wrangler.d1_databases);
|
|
463
|
-
const serviceBindings = createWorkerServiceBindings(modernConfig, wrangler.services);
|
|
464
|
-
const wranglerServices = createWranglerServices(serviceBindings);
|
|
465
|
-
return {
|
|
466
|
-
$schema: 'node_modules/wrangler/config-schema.json',
|
|
467
|
-
name: getConfiguredWorkerName(appDirectory, modernConfig),
|
|
468
|
-
compatibility_date: getCompatibilityDate(modernConfig),
|
|
469
|
-
...wrangler,
|
|
470
|
-
main: WORKER_ENTRY,
|
|
471
|
-
compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
|
|
472
|
-
assets: createWranglerAssetsConfig(wrangler.assets),
|
|
473
|
-
...void 0 === d1Databases ? {} : {
|
|
474
|
-
d1_databases: d1Databases
|
|
475
|
-
},
|
|
476
|
-
...void 0 === wranglerServices ? {} : {
|
|
477
|
-
services: wranglerServices
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
};
|
|
481
|
-
const normalizeCloudflareArtifact = (artifact, index)=>{
|
|
482
|
-
const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
|
|
483
|
-
const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
|
|
484
|
-
const [topLevelDestination] = to.split('/');
|
|
485
|
-
const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
|
|
486
|
-
if (RESERVED_ARTIFACT_DESTINATION_FILES.has(to) || RESERVED_ARTIFACT_DESTINATION_DIRECTORIES.has(topLevelDestination)) throw new Error(`deploy.worker.artifacts[${index}].to must not target generated Cloudflare output path ${JSON.stringify(reservedDestination)}.`);
|
|
487
|
-
return {
|
|
488
|
-
from,
|
|
489
|
-
to,
|
|
490
|
-
index
|
|
491
|
-
};
|
|
492
|
-
};
|
|
493
|
-
const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
|
|
494
|
-
const normalizeCloudflarePublicAsset = (asset, index)=>{
|
|
495
|
-
const from = normalizeRelativePath(asset.from, `deploy.worker.publicAssets[${index}].from`, 'app root');
|
|
496
|
-
const to = normalizeRelativePath(asset.to, `deploy.worker.publicAssets[${index}].to`, 'Cloudflare public output', {
|
|
497
|
-
allowRoot: true
|
|
498
|
-
});
|
|
499
|
-
return {
|
|
500
|
-
from,
|
|
501
|
-
to,
|
|
502
|
-
index
|
|
503
|
-
};
|
|
504
|
-
};
|
|
505
|
-
const getCloudflarePublicAssets = (modernConfig)=>(modernConfig.deploy?.worker?.publicAssets ?? []).map(normalizeCloudflarePublicAsset);
|
|
506
|
-
const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
|
|
507
|
-
for (const artifact of artifacts){
|
|
508
|
-
const sourcePath = external_node_path_default().join(appDirectory, artifact.from);
|
|
509
|
-
if (!await utils_namespaceObject.fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
|
|
510
|
-
await utils_namespaceObject.fs.copy(sourcePath, external_node_path_default().join(outputDirectory, artifact.to));
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
const copyCloudflarePublicAssets = async (appDirectory, publicDirectory, publicAssets)=>{
|
|
514
|
-
for (const asset of publicAssets){
|
|
515
|
-
const sourcePath = external_node_path_default().join(appDirectory, asset.from);
|
|
516
|
-
if (!await utils_namespaceObject.fs.pathExists(sourcePath)) throw new Error(`deploy.worker.publicAssets[${asset.index}].from does not exist: ${asset.from}`);
|
|
517
|
-
await utils_namespaceObject.fs.copy(sourcePath, external_node_path_default().join(publicDirectory, asset.to));
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
const copyCloudflareD1Migrations = async (appDirectory, outputDirectory, modernConfig)=>{
|
|
521
|
-
for (const [index, database] of (modernConfig.deploy?.worker?.d1Databases ?? []).entries()){
|
|
522
|
-
if (!database.migrationsDir) continue;
|
|
523
|
-
const migrationsDir = normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
|
|
524
|
-
const sourcePath = external_node_path_default().join(appDirectory, migrationsDir);
|
|
525
|
-
if (!await utils_namespaceObject.fs.pathExists(sourcePath)) throw new Error(`deploy.worker.d1Databases[${index}].migrationsDir does not exist: ${migrationsDir}`);
|
|
526
|
-
await utils_namespaceObject.fs.copy(sourcePath, external_node_path_default().join(outputDirectory, migrationsDir));
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
const readRouteSpec = async (outputDirectory)=>{
|
|
530
|
-
const routeSpecPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
531
|
-
if (!await utils_namespaceObject.fs.pathExists(routeSpecPath)) return {
|
|
532
|
-
routes: []
|
|
533
|
-
};
|
|
534
|
-
const routeSpec = await utils_namespaceObject.fs.readJSON(routeSpecPath);
|
|
535
|
-
return {
|
|
536
|
-
...routeSpec,
|
|
537
|
-
routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
|
|
538
|
-
};
|
|
539
|
-
};
|
|
540
|
-
const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
|
|
541
|
-
const ULTRAMODERN_BUILD_MODULE = 'shared/ultramodern-build.ts';
|
|
542
|
-
const nonEmptyString = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
|
|
543
|
-
const toDeliveryUnitIdentity = (value)=>{
|
|
544
|
-
if (!isRecord(value)) return;
|
|
545
|
-
const unitId = nonEmptyString(value.unitId);
|
|
546
|
-
const buildMarker = nonEmptyString(value.buildMarker);
|
|
547
|
-
const sourceRevision = nonEmptyString(value.sourceRevision);
|
|
548
|
-
if (!unitId || !buildMarker || !sourceRevision) return;
|
|
549
|
-
return {
|
|
550
|
-
unitId,
|
|
551
|
-
buildMarker,
|
|
552
|
-
sourceRevision
|
|
553
|
-
};
|
|
554
|
-
};
|
|
555
|
-
const findWorkspaceRoot = async (appDirectory)=>{
|
|
556
|
-
let current = external_node_path_default().resolve(appDirectory);
|
|
557
|
-
for(;;){
|
|
558
|
-
if (await utils_namespaceObject.fs.pathExists(external_node_path_default().join(current, COMPACT_CONFIG_PATH))) return current;
|
|
559
|
-
const parent = external_node_path_default().dirname(current);
|
|
560
|
-
if (parent === current) return;
|
|
561
|
-
current = parent;
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
const resolveTopologyDeliveryUnit = async (appDirectory)=>{
|
|
565
|
-
const workspaceRoot = await findWorkspaceRoot(appDirectory);
|
|
566
|
-
if (!workspaceRoot) return;
|
|
567
|
-
let compactConfig;
|
|
568
|
-
try {
|
|
569
|
-
compactConfig = await utils_namespaceObject.fs.readJSON(external_node_path_default().join(workspaceRoot, COMPACT_CONFIG_PATH));
|
|
570
|
-
} catch {
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
if (!isRecord(compactConfig)) return;
|
|
574
|
-
const topology = isRecord(compactConfig.topology) ? compactConfig.topology : void 0;
|
|
575
|
-
const apps = Array.isArray(topology?.apps) ? topology.apps : [];
|
|
576
|
-
const resolvedAppDirectory = external_node_path_default().resolve(appDirectory);
|
|
577
|
-
for (const app of apps){
|
|
578
|
-
if (!isRecord(app)) continue;
|
|
579
|
-
const appPath = nonEmptyString(app.path);
|
|
580
|
-
if (appPath && external_node_path_default().resolve(workspaceRoot, appPath.replace(/^\.\/+/u, '')) === resolvedAppDirectory) return toDeliveryUnitIdentity(app.deliveryUnit);
|
|
581
|
-
}
|
|
582
|
-
return toDeliveryUnitIdentity(compactConfig.deliveryUnit);
|
|
583
|
-
};
|
|
584
|
-
const resolveWorkerDeliveryUnitStamp = async (appDirectory)=>{
|
|
585
|
-
const buildModulePath = external_node_path_default().join(appDirectory, ULTRAMODERN_BUILD_MODULE);
|
|
586
|
-
if (!await utils_namespaceObject.fs.pathExists(buildModulePath)) return;
|
|
587
|
-
const source = await utils_namespaceObject.fs.readFile(buildModulePath, 'utf8');
|
|
588
|
-
const buildMarker = source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1];
|
|
589
|
-
const unitId = source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1];
|
|
590
|
-
const sourceRevision = source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1];
|
|
591
|
-
if (!buildMarker || !unitId || !sourceRevision) return;
|
|
592
|
-
const identity = {
|
|
593
|
-
unitId,
|
|
594
|
-
buildMarker,
|
|
595
|
-
sourceRevision
|
|
596
|
-
};
|
|
597
|
-
return {
|
|
598
|
-
...identity,
|
|
599
|
-
surfaces: {
|
|
600
|
-
ui: {
|
|
601
|
-
...identity,
|
|
602
|
-
surface: 'ui'
|
|
603
|
-
},
|
|
604
|
-
api: {
|
|
605
|
-
...identity,
|
|
606
|
-
surface: 'api'
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
};
|
|
611
|
-
const createMissingEffectBffWorkerError = (outputDirectory, worker)=>new Error(`Cloudflare Effect API runtime is configured, but the BFF worker bundle is missing: ${external_node_path_default().join(outputDirectory, worker)}. ${EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE}`);
|
|
612
|
-
const createWorkerManifest = async (outputDirectory, modernConfig, appContext, deliveryUnitStamp)=>{
|
|
613
|
-
const routeSpec = await readRouteSpec(outputDirectory);
|
|
614
|
-
const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
|
|
615
|
-
const worker = 'string' == typeof route.worker ? route.worker : void 0;
|
|
616
|
-
return {
|
|
617
|
-
urlPath: route.urlPath,
|
|
618
|
-
entryName: route.entryName,
|
|
619
|
-
entryPath: route.entryPath,
|
|
620
|
-
isSSR: Boolean(route.isSSR),
|
|
621
|
-
worker,
|
|
622
|
-
workerExists: worker ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, worker)) : false
|
|
623
|
-
};
|
|
624
|
-
}));
|
|
625
|
-
const bffPrefix = modernConfig.bff?.prefix;
|
|
626
|
-
const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
|
|
627
|
-
const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
|
|
628
|
-
const effectApiWorkerExists = await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
|
|
629
|
-
const serviceBindings = createWorkerManifestServiceBindings(createWorkerServiceBindings(modernConfig, void 0));
|
|
630
|
-
if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
|
|
631
|
-
return {
|
|
632
|
-
version: 1,
|
|
633
|
-
runtime: {
|
|
634
|
-
type: external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_RUNTIME_TYPE,
|
|
635
|
-
entry: WORKER_ENTRY,
|
|
636
|
-
fetchExport: true,
|
|
637
|
-
nodeListen: false
|
|
638
|
-
},
|
|
639
|
-
assets: {
|
|
640
|
-
binding: ASSETS_BINDING,
|
|
641
|
-
directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
|
|
642
|
-
runWorkerFirst: true
|
|
643
|
-
},
|
|
644
|
-
routeSpec: {
|
|
645
|
-
file: ROUTE_SPEC_OUTPUT,
|
|
646
|
-
routes
|
|
647
|
-
},
|
|
648
|
-
workerBundles: {
|
|
649
|
-
directory: WORKER_BUNDLE_DIRECTORY,
|
|
650
|
-
format: external_cloudflare_output_contract_js_namespaceObject.CLOUDFLARE_WORKER_BUNDLE_FORMAT,
|
|
651
|
-
importableFromModuleWorker: true,
|
|
652
|
-
requestHandlerExport: 'requestHandler'
|
|
653
|
-
},
|
|
654
|
-
resources: {
|
|
655
|
-
loadableStats: LOADABLE_STATS_FILE,
|
|
656
|
-
routeManifest: ROUTE_MANIFEST_FILE
|
|
657
|
-
},
|
|
658
|
-
security: createCloudflareWorkerSecurityPolicy(modernConfig),
|
|
659
|
-
...deliveryUnitStamp ? {
|
|
660
|
-
deliveryUnit: deliveryUnitStamp
|
|
661
|
-
} : {},
|
|
662
|
-
i18n: createI18nWorkerManifest(routeSpec, appContext),
|
|
663
|
-
bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
|
|
664
|
-
runtimeFramework: 'effect',
|
|
665
|
-
prefix: primaryBffPrefix,
|
|
666
|
-
worker: BFF_EFFECT_WORKER_ENTRY
|
|
667
|
-
} : void 0,
|
|
668
|
-
...void 0 === serviceBindings ? {} : {
|
|
669
|
-
serviceBindings
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
};
|
|
673
|
-
const createWorkerModuleLoaders = (manifest)=>{
|
|
674
|
-
const imports = new Map();
|
|
675
|
-
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
676
|
-
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
677
|
-
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
678
|
-
}
|
|
679
|
-
if (manifest.bff?.worker) {
|
|
680
|
-
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
681
|
-
imports.set(manifest.bff.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
682
|
-
}
|
|
683
|
-
if (0 === imports.size) return '{}';
|
|
684
|
-
const loaders = [
|
|
685
|
-
...imports.entries()
|
|
686
|
-
].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
|
|
687
|
-
return `{\n${loaders.join(',\n')}\n}`;
|
|
688
|
-
};
|
|
689
|
-
const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
|
|
690
|
-
...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
|
|
691
|
-
try {
|
|
692
|
-
return utils_namespaceObject.fs.statSync(external_node_path_default().join(appDirectory, directory)).isDirectory();
|
|
693
|
-
} catch {
|
|
694
|
-
return false;
|
|
695
|
-
}
|
|
696
|
-
}),
|
|
697
|
-
...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
|
|
698
|
-
].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
|
|
699
|
-
const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
|
|
700
|
-
const relativePath = external_node_path_default().relative(distDirectory, src);
|
|
701
|
-
if (!relativePath) return true;
|
|
702
|
-
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
703
|
-
const [topLevelDirectory] = normalizedRelativePath.split('/');
|
|
704
|
-
return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY && !publicAssetExcludes.some((exclude)=>normalizedRelativePath === exclude || normalizedRelativePath.startsWith(`${exclude}/`));
|
|
705
|
-
};
|
|
706
|
-
const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
|
|
707
|
-
const relativePath = external_node_path_default().relative(workerBundleDirectory, src);
|
|
708
|
-
if (!relativePath) return true;
|
|
709
|
-
const normalizedRelativePath = relativePath.replace(/\\/g, '/');
|
|
710
|
-
const basename = external_node_path_default().basename(normalizedRelativePath);
|
|
711
|
-
if (basename.startsWith('.') || normalizedRelativePath.includes('/.')) return false;
|
|
712
|
-
if (utils_namespaceObject.fs.statSync(src).isDirectory()) return true;
|
|
713
|
-
return [
|
|
714
|
-
'.cjs',
|
|
715
|
-
'.js',
|
|
716
|
-
'.mjs'
|
|
717
|
-
].includes(external_node_path_default().extname(normalizedRelativePath));
|
|
718
|
-
};
|
|
719
|
-
const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
720
|
-
const { appDirectory, distDirectory } = appContext;
|
|
721
|
-
const outputDirectory = external_node_path_default().join(appDirectory, '.output');
|
|
722
|
-
const outputPlan = (0, external_cloudflare_output_plan_js_namespaceObject.createCloudflareOutputPlan)(outputDirectory);
|
|
723
|
-
const publicDirectory = outputPlan.paths.publicAssets;
|
|
724
|
-
const workerEntryPath = outputPlan.paths.workerEntry;
|
|
725
|
-
const workerManifestPath = outputPlan.paths.workerManifest;
|
|
726
|
-
const routeSpecOutputPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
727
|
-
const wranglerConfigPath = outputPlan.paths.wranglerConfig;
|
|
728
|
-
const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
|
|
729
|
-
const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
|
|
730
|
-
return {
|
|
731
|
-
async prepare () {
|
|
732
|
-
await utils_namespaceObject.fs.remove(outputDirectory);
|
|
733
|
-
},
|
|
734
|
-
async writeOutput () {
|
|
735
|
-
await utils_namespaceObject.fs.copy(distDirectory, publicDirectory, {
|
|
736
|
-
filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
|
|
737
|
-
});
|
|
738
|
-
await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerEntryPath));
|
|
739
|
-
await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerManifestPath));
|
|
740
|
-
const routeSpecSourcePath = external_node_path_default().join(distDirectory, ROUTE_SPEC_FILE);
|
|
741
|
-
if (await utils_namespaceObject.fs.pathExists(routeSpecSourcePath)) await utils_namespaceObject.fs.copy(routeSpecSourcePath, routeSpecOutputPath);
|
|
742
|
-
const workerBundleSourceDirectory = external_node_path_default().join(distDirectory, WORKER_BUNDLE_DIRECTORY);
|
|
743
|
-
const workerBundleOutputDirectory = outputPlan.paths.workerBundle;
|
|
744
|
-
if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) {
|
|
745
|
-
await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
|
|
746
|
-
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
747
|
-
});
|
|
748
|
-
await utils_namespaceObject.fs.writeJSON(outputPlan.paths.workerPackage, outputPlan.packages.worker);
|
|
749
|
-
}
|
|
750
|
-
await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
|
|
751
|
-
await copyCloudflarePublicAssets(appDirectory, publicDirectory, getCloudflarePublicAssets(modernConfig));
|
|
752
|
-
await copyCloudflareD1Migrations(appDirectory, outputDirectory, modernConfig);
|
|
753
|
-
await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
|
|
754
|
-
spaces: 2
|
|
755
|
-
});
|
|
756
|
-
const deliveryUnitStamp = await resolveWorkerDeliveryUnitStamp(appDirectory);
|
|
757
|
-
await utils_namespaceObject.fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig, appContext, deliveryUnitStamp), {
|
|
758
|
-
spaces: 2
|
|
759
|
-
});
|
|
760
|
-
await utils_namespaceObject.fs.writeJSON(outputPlan.paths.outputPackage, outputPlan.packages.output);
|
|
761
|
-
},
|
|
762
|
-
async genEntry () {
|
|
763
|
-
const template = await (0, index_js_namespaceObject.readTemplate)('cloudflare-entry.mjs');
|
|
764
|
-
const manifest = await utils_namespaceObject.fs.readJSON(workerManifestPath);
|
|
765
|
-
await utils_namespaceObject.fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
|
|
766
|
-
const topologyDeliveryUnit = await resolveTopologyDeliveryUnit(appDirectory);
|
|
767
|
-
await (0, external_cloudflare_output_verifier_js_namespaceObject.assertCloudflareOutput)({
|
|
768
|
-
outputDirectory,
|
|
769
|
-
importWorker: false,
|
|
770
|
-
...topologyDeliveryUnit ? {
|
|
771
|
-
deliveryUnit: topologyDeliveryUnit
|
|
772
|
-
} : {}
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
|
-
};
|
|
776
|
-
};
|
|
33
|
+
const index_js_namespaceObject = require("./cloudflare/index.js");
|
|
777
34
|
exports.createCloudflarePreset = __webpack_exports__.createCloudflarePreset;
|
|
778
35
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
779
36
|
"createCloudflarePreset"
|