@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.120 → 3.2.0-ultramodern.121
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/baseline.js +3 -87
- package/dist/cjs/commands/index.js +3 -6
- package/dist/cjs/commands/runtime.js +35 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +20 -4
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +74 -13
- package/dist/cjs/plugins/deploy/utils/index.js +10 -35
- package/dist/cjs/presetUltramodern.js +87 -3
- package/dist/cjs/rsbuild.js +46 -62
- package/dist/cjs/types/config/cloudflareDeploy.js +18 -0
- package/dist/cjs/types/config/precompress.js +18 -0
- package/dist/esm/baseline.mjs +3 -77
- package/dist/esm/commands/index.mjs +2 -5
- package/dist/esm/commands/runtime.mjs +33 -3
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +20 -4
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +74 -13
- package/dist/esm/plugins/deploy/utils/index.mjs +11 -36
- package/dist/esm/presetUltramodern.mjs +77 -3
- package/dist/esm/rsbuild.mjs +1 -8
- package/dist/esm/types/config/cloudflareDeploy.mjs +0 -0
- package/dist/esm/types/config/precompress.mjs +0 -0
- package/dist/esm-node/baseline.mjs +3 -77
- package/dist/esm-node/commands/index.mjs +2 -5
- package/dist/esm-node/commands/runtime.mjs +33 -3
- package/dist/esm-node/index.mjs +2 -2
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +20 -4
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +74 -13
- package/dist/esm-node/plugins/deploy/utils/index.mjs +12 -36
- package/dist/esm-node/presetUltramodern.mjs +77 -3
- package/dist/esm-node/rsbuild.mjs +1 -8
- package/dist/esm-node/types/config/cloudflareDeploy.mjs +1 -0
- package/dist/esm-node/types/config/precompress.mjs +1 -0
- package/dist/types/baseline.d.ts +16 -46
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/runtime.d.ts +1 -0
- package/dist/types/presetUltramodern.d.ts +52 -2
- package/dist/types/types/config/cloudflareDeploy.d.ts +79 -0
- package/dist/types/types/config/deploy.d.ts +2 -56
- package/dist/types/types/config/output.d.ts +4 -20
- package/dist/types/types/config/precompress.d.ts +20 -0
- package/package.json +11 -13
- package/dist/esm/rslib-runtime.mjs +0 -18
- package/dist/esm-node/rslib-runtime.mjs +0 -19
package/dist/cjs/baseline.js
CHANGED
|
@@ -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)=>{
|
|
@@ -40,84 +31,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
31
|
createAppBaselineConfig: ()=>createAppBaselineConfig,
|
|
41
32
|
withAppBaseline: ()=>withAppBaseline
|
|
42
33
|
});
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const cli_namespaceObject = require("@modern-js/plugin/cli");
|
|
47
|
-
const resolveReactRouterPackageDir = ()=>{
|
|
48
|
-
const localRequire = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(process.cwd(), 'package.json'));
|
|
49
|
-
try {
|
|
50
|
-
const reactRouterDomPackageJson = localRequire.resolve('react-router-dom/package.json', {
|
|
51
|
-
paths: [
|
|
52
|
-
process.cwd()
|
|
53
|
-
]
|
|
54
|
-
});
|
|
55
|
-
const reactRouterPackageJson = localRequire.resolve('react-router/package.json', {
|
|
56
|
-
paths: [
|
|
57
|
-
external_node_path_default().dirname(reactRouterDomPackageJson)
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
return external_node_path_default().dirname(reactRouterPackageJson);
|
|
61
|
-
} catch {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const setReactRouterBridgeSafeAliases = (chain)=>{
|
|
66
|
-
const reactRouterPackageDir = resolveReactRouterPackageDir();
|
|
67
|
-
if (!reactRouterPackageDir) return;
|
|
68
|
-
const productionEntry = external_node_path_default().join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
69
|
-
const developmentEntry = external_node_path_default().join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
70
|
-
chain.resolve.alias.set('react-router$', productionEntry);
|
|
71
|
-
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
72
|
-
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
73
|
-
};
|
|
74
|
-
const createAppBaselineConfig = (options = {})=>{
|
|
75
|
-
const { appId = 'app', enableBffRequestId = true, enableTelemetry = true, enableTelemetryExporters = true, otlpEndpoint = process.env.MODERN_TELEMETRY_OTLP_ENDPOINT || 'http://127.0.0.1:4318/v1/logs', victoriaMetricsEndpoint = process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT || 'http://127.0.0.1:8428/api/v1/import/prometheus', telemetryFailLoudStartup = true, enableModuleFederationSSR = true } = options;
|
|
76
|
-
const server = {};
|
|
77
|
-
if (enableTelemetry) {
|
|
78
|
-
server.telemetry = {
|
|
79
|
-
enabled: true,
|
|
80
|
-
failLoudStartup: telemetryFailLoudStartup
|
|
81
|
-
};
|
|
82
|
-
if (enableTelemetryExporters) server.telemetry.exporters = {
|
|
83
|
-
otlp: {
|
|
84
|
-
enabled: true,
|
|
85
|
-
endpoint: otlpEndpoint
|
|
86
|
-
},
|
|
87
|
-
victoriaMetrics: {
|
|
88
|
-
enabled: true,
|
|
89
|
-
endpoint: victoriaMetricsEndpoint
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (enableModuleFederationSSR) server.ssr = {
|
|
94
|
-
mode: 'stream',
|
|
95
|
-
moduleFederationAppSSR: true
|
|
96
|
-
};
|
|
97
|
-
const baselineConfig = {
|
|
98
|
-
output: {
|
|
99
|
-
precompress: true
|
|
100
|
-
},
|
|
101
|
-
performance: {
|
|
102
|
-
rsdoctor: {
|
|
103
|
-
enabled: 'production' === process.env.NODE_ENV,
|
|
104
|
-
disableClientServer: true
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
server,
|
|
108
|
-
tools: {
|
|
109
|
-
bundlerChain: setReactRouterBridgeSafeAliases
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
if (enableBffRequestId) baselineConfig.bff = {
|
|
113
|
-
requestId: appId
|
|
114
|
-
};
|
|
115
|
-
return baselineConfig;
|
|
116
|
-
};
|
|
117
|
-
const withAppBaseline = (config, options = {})=>(0, cli_namespaceObject.mergeConfig)([
|
|
118
|
-
createAppBaselineConfig(options),
|
|
119
|
-
config
|
|
120
|
-
]);
|
|
34
|
+
const external_presetUltramodern_js_namespaceObject = require("./presetUltramodern.js");
|
|
35
|
+
const createAppBaselineConfig = external_presetUltramodern_js_namespaceObject.createPresetUltramodernConfig;
|
|
36
|
+
const withAppBaseline = external_presetUltramodern_js_namespaceObject.presetUltramodern;
|
|
121
37
|
exports.createAppBaselineConfig = __webpack_exports__.createAppBaselineConfig;
|
|
122
38
|
exports.withAppBaseline = __webpack_exports__.withAppBaseline;
|
|
123
39
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -33,7 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
devCommand: ()=>devCommand,
|
|
34
34
|
infoCommand: ()=>infoCommand,
|
|
35
35
|
inspectCommand: ()=>inspectCommand,
|
|
36
|
-
|
|
36
|
+
runtimeCommand: ()=>external_runtime_js_namespaceObject.runtimeCommand,
|
|
37
37
|
serverCommand: ()=>serverCommand
|
|
38
38
|
});
|
|
39
39
|
const index_js_namespaceObject = require("../locale/index.js");
|
|
@@ -79,15 +79,12 @@ const infoCommand = (program, api)=>{
|
|
|
79
79
|
await info(api, options);
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
-
const runtimeOperationsCommand = async (program, api)=>{
|
|
83
|
-
await (0, external_runtime_js_namespaceObject.runtimeCommand)(program, api);
|
|
84
|
-
};
|
|
85
82
|
exports.buildCommand = __webpack_exports__.buildCommand;
|
|
86
83
|
exports.deployCommand = __webpack_exports__.deployCommand;
|
|
87
84
|
exports.devCommand = __webpack_exports__.devCommand;
|
|
88
85
|
exports.infoCommand = __webpack_exports__.infoCommand;
|
|
89
86
|
exports.inspectCommand = __webpack_exports__.inspectCommand;
|
|
90
|
-
exports.
|
|
87
|
+
exports.runtimeCommand = __webpack_exports__.runtimeCommand;
|
|
91
88
|
exports.serverCommand = __webpack_exports__.serverCommand;
|
|
92
89
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
93
90
|
"buildCommand",
|
|
@@ -95,7 +92,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
95
92
|
"devCommand",
|
|
96
93
|
"infoCommand",
|
|
97
94
|
"inspectCommand",
|
|
98
|
-
"
|
|
95
|
+
"runtimeCommand",
|
|
99
96
|
"serverCommand"
|
|
100
97
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
101
98
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -83,9 +83,39 @@ const parseResponseBody = async (response)=>{
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
|
+
const INDENT_STEP = ' ';
|
|
87
|
+
const formatScalar = (value)=>'string' == typeof value ? value : JSON.stringify(value) ?? 'undefined';
|
|
88
|
+
const formatHumanReadableLines = (value, indent)=>{
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
if (0 === value.length) return [
|
|
91
|
+
`${indent}(empty)`
|
|
92
|
+
];
|
|
93
|
+
return value.flatMap((entry)=>null !== entry && 'object' == typeof entry ? [
|
|
94
|
+
`${indent}-`,
|
|
95
|
+
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
96
|
+
] : [
|
|
97
|
+
`${indent}- ${formatScalar(entry)}`
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
if (null !== value && 'object' == typeof value) {
|
|
101
|
+
const entries = Object.entries(value);
|
|
102
|
+
if (0 === entries.length) return [
|
|
103
|
+
`${indent}(empty)`
|
|
104
|
+
];
|
|
105
|
+
return entries.flatMap(([key, entry])=>null !== entry && 'object' == typeof entry ? [
|
|
106
|
+
`${indent}${key}:`,
|
|
107
|
+
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
108
|
+
] : [
|
|
109
|
+
`${indent}${key}: ${formatScalar(entry)}`
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
return [
|
|
113
|
+
`${indent}${formatScalar(value)}`
|
|
114
|
+
];
|
|
115
|
+
};
|
|
116
|
+
const formatRuntimeOutput = (payload, jsonOnly)=>jsonOnly ? JSON.stringify(payload, null, 2) : formatHumanReadableLines(payload, '').join('\n');
|
|
86
117
|
const printOutput = (payload, jsonOnly)=>{
|
|
87
|
-
|
|
88
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
118
|
+
console.log(formatRuntimeOutput(payload, jsonOnly));
|
|
89
119
|
};
|
|
90
120
|
const createRuntimeFallbackSignalPayload = (options)=>{
|
|
91
121
|
const payload = {
|
|
@@ -144,16 +174,19 @@ const runtimeCommand = async (program, _api)=>{
|
|
|
144
174
|
};
|
|
145
175
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
146
176
|
createRuntimeFallbackSignalPayload: createRuntimeFallbackSignalPayload,
|
|
177
|
+
formatRuntimeOutput: formatRuntimeOutput,
|
|
147
178
|
resolveRuntimeEndpoint: resolveRuntimeEndpoint,
|
|
148
179
|
resolveToken: resolveToken,
|
|
149
180
|
runtimeCommand: runtimeCommand
|
|
150
181
|
});
|
|
151
182
|
exports.createRuntimeFallbackSignalPayload = __webpack_exports__.createRuntimeFallbackSignalPayload;
|
|
183
|
+
exports.formatRuntimeOutput = __webpack_exports__.formatRuntimeOutput;
|
|
152
184
|
exports.resolveRuntimeEndpoint = __webpack_exports__.resolveRuntimeEndpoint;
|
|
153
185
|
exports.resolveToken = __webpack_exports__.resolveToken;
|
|
154
186
|
exports.runtimeCommand = __webpack_exports__.runtimeCommand;
|
|
155
187
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
156
188
|
"createRuntimeFallbackSignalPayload",
|
|
189
|
+
"formatRuntimeOutput",
|
|
157
190
|
"resolveRuntimeEndpoint",
|
|
158
191
|
"resolveToken",
|
|
159
192
|
"runtimeCommand"
|
package/dist/cjs/index.js
CHANGED
|
@@ -274,7 +274,7 @@ var __webpack_exports__ = {};
|
|
|
274
274
|
(0, _commands__rspack_import_5.deployCommand)(program, api);
|
|
275
275
|
(0, _commands__rspack_import_5.inspectCommand)(program, api);
|
|
276
276
|
(0, _commands__rspack_import_5.infoCommand)(program, api);
|
|
277
|
-
await (0, _commands__rspack_import_5.
|
|
277
|
+
await (0, _commands__rspack_import_5.runtimeCommand)(program, api);
|
|
278
278
|
(0, _modern_js_utils__rspack_import_3.deprecatedCommands)(program);
|
|
279
279
|
});
|
|
280
280
|
api.onPrepare(async ()=>{
|
|
@@ -61,6 +61,15 @@ const DEFAULT_SECURITY_HEADERS = {
|
|
|
61
61
|
contentTypeOptions: 'nosniff',
|
|
62
62
|
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
63
63
|
};
|
|
64
|
+
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
65
|
+
'GET',
|
|
66
|
+
'HEAD',
|
|
67
|
+
'POST',
|
|
68
|
+
'PUT',
|
|
69
|
+
'PATCH',
|
|
70
|
+
'DELETE',
|
|
71
|
+
'OPTIONS'
|
|
72
|
+
];
|
|
64
73
|
const DEFAULT_CSP_DIRECTIVES = {
|
|
65
74
|
'base-uri': [
|
|
66
75
|
"'self'"
|
|
@@ -198,10 +207,20 @@ const createNoindexPolicy = (noindex)=>{
|
|
|
198
207
|
reason: noindex.reason
|
|
199
208
|
};
|
|
200
209
|
};
|
|
210
|
+
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
211
|
+
assets: cors?.assets ?? true,
|
|
212
|
+
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
213
|
+
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
214
|
+
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
215
|
+
'*'
|
|
216
|
+
],
|
|
217
|
+
reason: cors?.reason
|
|
218
|
+
});
|
|
201
219
|
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
202
220
|
const security = modernConfig.deploy?.worker?.security;
|
|
203
221
|
if (security?.enabled === false) return {
|
|
204
222
|
enabled: false,
|
|
223
|
+
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
205
224
|
reason: security.reason
|
|
206
225
|
};
|
|
207
226
|
return {
|
|
@@ -213,10 +232,7 @@ const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
|
213
232
|
},
|
|
214
233
|
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
215
234
|
noindex: createNoindexPolicy(security?.noindex),
|
|
216
|
-
|
|
217
|
-
mutateSetCookie: false,
|
|
218
|
-
reason: security?.cookies?.reason ?? 'Cloudflare worker does not own application Set-Cookie headers.'
|
|
219
|
-
},
|
|
235
|
+
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
220
236
|
reason: security?.reason
|
|
221
237
|
};
|
|
222
238
|
};
|
|
@@ -3,16 +3,57 @@ const MODERN_WORKER_MANIFEST = p_workerManifest;
|
|
|
3
3
|
const WORKER_MODULE_LOADERS = p_workerModuleLoaders;
|
|
4
4
|
const workerModulePromises = new Map();
|
|
5
5
|
const remoteJsonPromises = new Map();
|
|
6
|
-
const
|
|
6
|
+
const CORS_POLICY = MODERN_WORKER_MANIFEST.security?.cors || {};
|
|
7
|
+
const ASSET_CORS_ENABLED = false !== CORS_POLICY.assets;
|
|
8
|
+
const APP_CORS_ALLOWED_ORIGINS = (CORS_POLICY.allowedOrigins || []).map((origin)=>String(origin).toLowerCase());
|
|
9
|
+
const APP_CORS_ALLOWED_METHODS = (CORS_POLICY.allowedMethods?.length ? CORS_POLICY.allowedMethods : [
|
|
10
|
+
'GET',
|
|
11
|
+
'HEAD',
|
|
12
|
+
'POST',
|
|
13
|
+
'PUT',
|
|
14
|
+
'PATCH',
|
|
15
|
+
'DELETE',
|
|
16
|
+
'OPTIONS'
|
|
17
|
+
]).join(', ');
|
|
18
|
+
const APP_CORS_ALLOWED_HEADERS = (CORS_POLICY.allowedHeaders?.length ? CORS_POLICY.allowedHeaders : [
|
|
19
|
+
'*'
|
|
20
|
+
]).join(', ');
|
|
21
|
+
const ASSET_CORS_HEADERS = {
|
|
7
22
|
'access-control-allow-headers': '*',
|
|
8
23
|
'access-control-allow-methods': 'GET, HEAD, OPTIONS',
|
|
9
24
|
'access-control-allow-origin': '*'
|
|
10
25
|
};
|
|
11
26
|
globalThis.__dirname ??= '/';
|
|
12
27
|
globalThis.__filename ??= '/index.js';
|
|
13
|
-
function
|
|
28
|
+
function getAllowedAppCorsOrigin(request) {
|
|
29
|
+
if (0 === APP_CORS_ALLOWED_ORIGINS.length) return null;
|
|
30
|
+
const origin = request.headers.get('origin');
|
|
31
|
+
if (!origin) return null;
|
|
32
|
+
if (APP_CORS_ALLOWED_ORIGINS.includes('*')) return '*';
|
|
33
|
+
return APP_CORS_ALLOWED_ORIGINS.includes(origin.toLowerCase()) ? origin : null;
|
|
34
|
+
}
|
|
35
|
+
function appendVaryOrigin(headers) {
|
|
36
|
+
const vary = headers.get('vary');
|
|
37
|
+
if (!vary) return void headers.set('vary', 'origin');
|
|
38
|
+
const varyValues = vary.split(',').map((value)=>value.trim().toLowerCase());
|
|
39
|
+
if (!varyValues.includes('origin')) headers.set('vary', `${vary}, origin`);
|
|
40
|
+
}
|
|
41
|
+
function withAppCorsHeaders(response, request) {
|
|
42
|
+
const allowedOrigin = getAllowedAppCorsOrigin(request);
|
|
43
|
+
if (!allowedOrigin) return response;
|
|
14
44
|
const headers = new Headers(response.headers);
|
|
15
|
-
|
|
45
|
+
if (!headers.has('access-control-allow-origin')) headers.set('access-control-allow-origin', allowedOrigin);
|
|
46
|
+
if ('*' !== allowedOrigin) appendVaryOrigin(headers);
|
|
47
|
+
return new Response(response.body, {
|
|
48
|
+
headers,
|
|
49
|
+
status: response.status,
|
|
50
|
+
statusText: response.statusText
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function withAssetCorsHeaders(response) {
|
|
54
|
+
if (!ASSET_CORS_ENABLED) return response;
|
|
55
|
+
const headers = new Headers(response.headers);
|
|
56
|
+
for (const [name, value] of Object.entries(ASSET_CORS_HEADERS))if (!headers.has(name)) headers.set(name, value);
|
|
16
57
|
return new Response(response.body, {
|
|
17
58
|
headers,
|
|
18
59
|
status: response.status,
|
|
@@ -84,7 +125,7 @@ function isFingerprintedAssetPathname(pathname) {
|
|
|
84
125
|
return /(?:^|\/)[^/]+\.[a-f0-9]{8,}\.(?:css|js|mjs|json|svg|png|jpe?g|webp|avif|gif|woff2?|ttf)$/iu.test(pathname);
|
|
85
126
|
}
|
|
86
127
|
function withAssetHeaders(response, request) {
|
|
87
|
-
const corsResponse =
|
|
128
|
+
const corsResponse = withAssetCorsHeaders(response);
|
|
88
129
|
const headers = new Headers(corsResponse.headers);
|
|
89
130
|
const { pathname } = new URL(request.url);
|
|
90
131
|
if (isFingerprintedAssetPathname(pathname)) headers.set('cache-control', 'public, max-age=31536000, immutable');
|
|
@@ -94,10 +135,30 @@ function withAssetHeaders(response, request) {
|
|
|
94
135
|
statusText: corsResponse.statusText
|
|
95
136
|
});
|
|
96
137
|
}
|
|
97
|
-
function createCorsPreflightResponse(request) {
|
|
138
|
+
async function createCorsPreflightResponse(request, env) {
|
|
98
139
|
if ('OPTIONS' !== request.method) return null;
|
|
140
|
+
const allowedOrigin = getAllowedAppCorsOrigin(request);
|
|
141
|
+
if (allowedOrigin) {
|
|
142
|
+
const headers = new Headers({
|
|
143
|
+
'access-control-allow-headers': APP_CORS_ALLOWED_HEADERS,
|
|
144
|
+
'access-control-allow-methods': APP_CORS_ALLOWED_METHODS,
|
|
145
|
+
'access-control-allow-origin': allowedOrigin
|
|
146
|
+
});
|
|
147
|
+
if ('*' !== allowedOrigin) headers.set('vary', 'origin');
|
|
148
|
+
return new Response(null, {
|
|
149
|
+
headers,
|
|
150
|
+
status: 204
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (!ASSET_CORS_ENABLED) return null;
|
|
154
|
+
const assets = env?.[ASSETS_BINDING];
|
|
155
|
+
if (!assets || 'function' != typeof assets.fetch) return null;
|
|
156
|
+
const assetResponse = await assets.fetch(new Request(request.url, {
|
|
157
|
+
method: 'HEAD'
|
|
158
|
+
}));
|
|
159
|
+
if (!assetResponse || 404 === assetResponse.status) return null;
|
|
99
160
|
return new Response(null, {
|
|
100
|
-
headers:
|
|
161
|
+
headers: ASSET_CORS_HEADERS,
|
|
101
162
|
status: 204
|
|
102
163
|
});
|
|
103
164
|
}
|
|
@@ -478,25 +539,25 @@ async function dispatchBffRequest(request, env) {
|
|
|
478
539
|
}
|
|
479
540
|
export default {
|
|
480
541
|
async fetch (request, env, ctx) {
|
|
481
|
-
const corsPreflightResponse = createCorsPreflightResponse(request);
|
|
542
|
+
const corsPreflightResponse = await createCorsPreflightResponse(request, env);
|
|
482
543
|
if (corsPreflightResponse) return finalizeResponseForRequest(corsPreflightResponse, request);
|
|
483
544
|
const assetResponse = await fetchAsset(request, env);
|
|
484
545
|
if (assetResponse) return finalizeResponseForRequest(assetResponse, request);
|
|
485
546
|
const bffResponse = await dispatchBffRequest(request, env);
|
|
486
|
-
if (bffResponse) return finalizeResponseForRequest(
|
|
547
|
+
if (bffResponse) return finalizeResponseForRequest(withAppCorsHeaders(bffResponse, request), request);
|
|
487
548
|
const route = findRoute(request);
|
|
488
549
|
const { pathname } = new URL(request.url);
|
|
489
|
-
if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) return finalizeResponseForRequest(
|
|
550
|
+
if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) return finalizeResponseForRequest(withAppCorsHeaders(new Response('Not found', {
|
|
490
551
|
status: 404
|
|
491
|
-
})), request);
|
|
552
|
+
}), request), request);
|
|
492
553
|
if (route?.worker) {
|
|
493
554
|
const renderableRequest = createRenderableRequest(request);
|
|
494
|
-
return finalizeResponseForRequest(
|
|
555
|
+
return finalizeResponseForRequest(withAppCorsHeaders(await dispatchRouteWorker(route, renderableRequest, env, ctx), request), request);
|
|
495
556
|
}
|
|
496
557
|
const htmlResponse = await fetchRouteHtml(route, request, env);
|
|
497
558
|
if (htmlResponse) return finalizeResponseForRequest(htmlResponse, request);
|
|
498
|
-
return finalizeResponseForRequest(
|
|
559
|
+
return finalizeResponseForRequest(withAppCorsHeaders(new Response('Not found', {
|
|
499
560
|
status: 404
|
|
500
|
-
})), request);
|
|
561
|
+
}), request), request);
|
|
501
562
|
}
|
|
502
563
|
};
|
|
@@ -44,6 +44,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
44
44
|
resolveESMDependency: ()=>resolveESMDependency
|
|
45
45
|
});
|
|
46
46
|
const external_node_module_namespaceObject = require("node:module");
|
|
47
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
47
48
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
48
49
|
const external_path_namespaceObject = require("path");
|
|
49
50
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
@@ -71,43 +72,17 @@ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
|
71
72
|
};
|
|
72
73
|
const getTemplatePath = (file)=>external_path_default().join(__dirname, '../platforms/templates', file);
|
|
73
74
|
const readTemplate = async (file)=>(await utils_namespaceObject.fs.readFile(getTemplatePath(file))).toString();
|
|
74
|
-
const localRequire = (0, external_node_module_namespaceObject.createRequire)(external_path_default().join(__dirname, 'package.json'));
|
|
75
|
-
const findNearestPackageJson = (resolvedEntry)=>{
|
|
76
|
-
let currentDir = external_path_default().dirname(resolvedEntry);
|
|
77
|
-
while(currentDir !== external_path_default().dirname(currentDir)){
|
|
78
|
-
const manifestPath = external_path_default().join(currentDir, 'package.json');
|
|
79
|
-
if (utils_namespaceObject.fs.existsSync(manifestPath)) return manifestPath;
|
|
80
|
-
currentDir = external_path_default().dirname(currentDir);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const splitPackageSpecifier = (entry)=>{
|
|
84
|
-
const segments = entry.split('/');
|
|
85
|
-
if (entry.startsWith('@')) {
|
|
86
|
-
const [scope, name, ...rest] = segments;
|
|
87
|
-
return {
|
|
88
|
-
packageName: `${scope}/${name}`,
|
|
89
|
-
exportKey: rest.length > 0 ? `./${rest.join('/')}` : '.'
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const [name, ...rest] = segments;
|
|
93
|
-
return {
|
|
94
|
-
packageName: name,
|
|
95
|
-
exportKey: rest.length > 0 ? `./${rest.join('/')}` : '.'
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
75
|
const resolveESMDependency = async (entry)=>{
|
|
76
|
+
const conditions = new Set([
|
|
77
|
+
'node',
|
|
78
|
+
'import',
|
|
79
|
+
'module',
|
|
80
|
+
'default'
|
|
81
|
+
]);
|
|
99
82
|
try {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
if (!packageJsonPath) return normalizePath(resolvedEntry);
|
|
104
|
-
const packageDir = external_path_default().dirname(packageJsonPath);
|
|
105
|
-
const packageJson = utils_namespaceObject.fs.readJSONSync(packageJsonPath);
|
|
106
|
-
const exportConfig = packageJson.exports?.[exportKey];
|
|
107
|
-
if ('string' == typeof exportConfig) return normalizePath(external_path_default().join(packageDir, exportConfig));
|
|
108
|
-
const esmExportPath = exportConfig?.node?.import || exportConfig?.import || exportConfig?.default;
|
|
109
|
-
if ('string' == typeof esmExportPath) return normalizePath(external_path_default().join(packageDir, esmExportPath));
|
|
110
|
-
return normalizePath(resolvedEntry);
|
|
83
|
+
const resolverPath = (0, external_node_url_namespaceObject.pathToFileURL)((0, external_node_module_namespaceObject.createRequire)(__filename).resolve('import-meta-resolve')).href;
|
|
84
|
+
const { moduleResolve } = await (0, utils_namespaceObject.dynamicImport)(resolverPath);
|
|
85
|
+
return normalizePath(moduleResolve(entry, (0, external_node_url_namespaceObject.pathToFileURL)(`${__dirname}/`), conditions, false).pathname.replace(/^\/(\w):/, '$1:'));
|
|
111
86
|
} catch (err) {}
|
|
112
87
|
};
|
|
113
88
|
exports.getProjectUsage = __webpack_exports__.getProjectUsage;
|
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
})();
|
|
3
12
|
(()=>{
|
|
4
13
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
14
|
var define = (defs, kind)=>{
|
|
@@ -31,9 +40,84 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
40
|
createPresetUltramodernConfig: ()=>createPresetUltramodernConfig,
|
|
32
41
|
presetUltramodern: ()=>presetUltramodern
|
|
33
42
|
});
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
43
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
44
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
45
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
46
|
+
const cli_namespaceObject = require("@modern-js/plugin/cli");
|
|
47
|
+
const DEFAULT_OTLP_ENDPOINT = 'http://127.0.0.1:4318/v1/logs';
|
|
48
|
+
const DEFAULT_VICTORIA_METRICS_ENDPOINT = 'http://127.0.0.1:8428/api/v1/import/prometheus';
|
|
49
|
+
const resolveReactRouterPackageDir = (appDirectory)=>{
|
|
50
|
+
const localRequire = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(appDirectory, 'package.json'));
|
|
51
|
+
try {
|
|
52
|
+
const reactRouterDomPackageJson = localRequire.resolve('react-router-dom/package.json', {
|
|
53
|
+
paths: [
|
|
54
|
+
appDirectory
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
const reactRouterPackageJson = localRequire.resolve('react-router/package.json', {
|
|
58
|
+
paths: [
|
|
59
|
+
external_node_path_default().dirname(reactRouterDomPackageJson)
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
return external_node_path_default().dirname(reactRouterPackageJson);
|
|
63
|
+
} catch {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const setReactRouterBridgeSafeAliases = (chain, { isProd })=>{
|
|
68
|
+
const chainContext = chain.get('context');
|
|
69
|
+
const appDirectory = 'string' == typeof chainContext && chainContext.length > 0 ? chainContext : process.cwd();
|
|
70
|
+
const reactRouterPackageDir = resolveReactRouterPackageDir(appDirectory);
|
|
71
|
+
if (!reactRouterPackageDir) return;
|
|
72
|
+
const productionEntry = external_node_path_default().join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
73
|
+
const developmentEntry = external_node_path_default().join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
74
|
+
chain.resolve.alias.set('react-router$', isProd ? productionEntry : developmentEntry);
|
|
75
|
+
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
76
|
+
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
77
|
+
};
|
|
78
|
+
const createPresetUltramodernConfig = (options = {})=>{
|
|
79
|
+
const { appId = 'app', enableBffRequestId = true, enableTelemetry = true, enableTelemetryExporters, otlpEndpoint = process.env.MODERN_TELEMETRY_OTLP_ENDPOINT, victoriaMetricsEndpoint = process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT, telemetryFailLoudStartup = true, enableModuleFederationSSR = true } = options;
|
|
80
|
+
const server = {};
|
|
81
|
+
if (enableTelemetry) {
|
|
82
|
+
server.telemetry = {
|
|
83
|
+
enabled: true,
|
|
84
|
+
failLoudStartup: telemetryFailLoudStartup
|
|
85
|
+
};
|
|
86
|
+
if (false !== enableTelemetryExporters) {
|
|
87
|
+
const exporters = {};
|
|
88
|
+
if (true === enableTelemetryExporters || otlpEndpoint) exporters.otlp = {
|
|
89
|
+
enabled: true,
|
|
90
|
+
endpoint: otlpEndpoint || DEFAULT_OTLP_ENDPOINT
|
|
91
|
+
};
|
|
92
|
+
if (true === enableTelemetryExporters || victoriaMetricsEndpoint) exporters.victoriaMetrics = {
|
|
93
|
+
enabled: true,
|
|
94
|
+
endpoint: victoriaMetricsEndpoint || DEFAULT_VICTORIA_METRICS_ENDPOINT
|
|
95
|
+
};
|
|
96
|
+
if (Object.keys(exporters).length > 0) server.telemetry.exporters = exporters;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (enableModuleFederationSSR) server.ssr = {
|
|
100
|
+
mode: 'stream',
|
|
101
|
+
moduleFederationAppSSR: true
|
|
102
|
+
};
|
|
103
|
+
const presetConfig = {
|
|
104
|
+
output: {
|
|
105
|
+
precompress: true
|
|
106
|
+
},
|
|
107
|
+
server,
|
|
108
|
+
tools: {
|
|
109
|
+
bundlerChain: setReactRouterBridgeSafeAliases
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
if (enableBffRequestId) presetConfig.bff = {
|
|
113
|
+
requestId: appId
|
|
114
|
+
};
|
|
115
|
+
return presetConfig;
|
|
116
|
+
};
|
|
117
|
+
const presetUltramodern = (config, options = {})=>(0, cli_namespaceObject.mergeConfig)([
|
|
118
|
+
createPresetUltramodernConfig(options),
|
|
119
|
+
config
|
|
120
|
+
]);
|
|
37
121
|
exports.createPresetUltramodernConfig = __webpack_exports__.createPresetUltramodernConfig;
|
|
38
122
|
exports.presetUltramodern = __webpack_exports__.presetUltramodern;
|
|
39
123
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|