@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.120 → 3.2.0-ultramodern.122
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/esm/rsbuild.mjs
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { parseRspackConfig } from "@modern-js/builder";
|
|
2
|
+
import { createConfigOptions } from "@modern-js/plugin/cli";
|
|
2
3
|
import { INTERNAL_RUNTIME_PLUGINS } from "@modern-js/utils";
|
|
3
4
|
import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./builder/shared/builderPlugins/index.mjs";
|
|
4
5
|
import { DEFAULT_CONFIG_FILE } from "./constants.mjs";
|
|
5
6
|
import { getConfigFile } from "./utils/getConfigFile.mjs";
|
|
6
7
|
import { loadInternalPlugins } from "./utils/loadPlugins.mjs";
|
|
7
|
-
import { __webpack_require__ } from "./rslib-runtime.mjs";
|
|
8
|
-
import * as __rspack_external__modern_js_plugin_cli_caa09fa2 from "@modern-js/plugin/cli";
|
|
9
|
-
__webpack_require__.add({
|
|
10
|
-
"@modern-js/plugin/cli?8936" (module) {
|
|
11
|
-
module.exports = __rspack_external__modern_js_plugin_cli_caa09fa2;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
8
|
const MODERN_META_NAME = 'modern-js';
|
|
15
|
-
const { createConfigOptions: createConfigOptions } = __webpack_require__("@modern-js/plugin/cli?8936");
|
|
16
9
|
async function resolveModernRsbuildConfig(options) {
|
|
17
10
|
const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
|
|
18
11
|
const configFile = options.configPath || getConfigFile(void 0, cwd);
|
|
File without changes
|
|
File without changes
|
|
@@ -1,79 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const resolveReactRouterPackageDir = ()=>{
|
|
6
|
-
const localRequire = createRequire(node_path.join(process.cwd(), 'package.json'));
|
|
7
|
-
try {
|
|
8
|
-
const reactRouterDomPackageJson = localRequire.resolve('react-router-dom/package.json', {
|
|
9
|
-
paths: [
|
|
10
|
-
process.cwd()
|
|
11
|
-
]
|
|
12
|
-
});
|
|
13
|
-
const reactRouterPackageJson = localRequire.resolve('react-router/package.json', {
|
|
14
|
-
paths: [
|
|
15
|
-
node_path.dirname(reactRouterDomPackageJson)
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
return node_path.dirname(reactRouterPackageJson);
|
|
19
|
-
} catch {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const setReactRouterBridgeSafeAliases = (chain)=>{
|
|
24
|
-
const reactRouterPackageDir = resolveReactRouterPackageDir();
|
|
25
|
-
if (!reactRouterPackageDir) return;
|
|
26
|
-
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
27
|
-
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
28
|
-
chain.resolve.alias.set('react-router$', productionEntry);
|
|
29
|
-
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
30
|
-
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
31
|
-
};
|
|
32
|
-
const createAppBaselineConfig = (options = {})=>{
|
|
33
|
-
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;
|
|
34
|
-
const server = {};
|
|
35
|
-
if (enableTelemetry) {
|
|
36
|
-
server.telemetry = {
|
|
37
|
-
enabled: true,
|
|
38
|
-
failLoudStartup: telemetryFailLoudStartup
|
|
39
|
-
};
|
|
40
|
-
if (enableTelemetryExporters) server.telemetry.exporters = {
|
|
41
|
-
otlp: {
|
|
42
|
-
enabled: true,
|
|
43
|
-
endpoint: otlpEndpoint
|
|
44
|
-
},
|
|
45
|
-
victoriaMetrics: {
|
|
46
|
-
enabled: true,
|
|
47
|
-
endpoint: victoriaMetricsEndpoint
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
if (enableModuleFederationSSR) server.ssr = {
|
|
52
|
-
mode: 'stream',
|
|
53
|
-
moduleFederationAppSSR: true
|
|
54
|
-
};
|
|
55
|
-
const baselineConfig = {
|
|
56
|
-
output: {
|
|
57
|
-
precompress: true
|
|
58
|
-
},
|
|
59
|
-
performance: {
|
|
60
|
-
rsdoctor: {
|
|
61
|
-
enabled: 'production' === process.env.NODE_ENV,
|
|
62
|
-
disableClientServer: true
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
server,
|
|
66
|
-
tools: {
|
|
67
|
-
bundlerChain: setReactRouterBridgeSafeAliases
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
if (enableBffRequestId) baselineConfig.bff = {
|
|
71
|
-
requestId: appId
|
|
72
|
-
};
|
|
73
|
-
return baselineConfig;
|
|
74
|
-
};
|
|
75
|
-
const withAppBaseline = (config, options = {})=>mergeConfig([
|
|
76
|
-
createAppBaselineConfig(options),
|
|
77
|
-
config
|
|
78
|
-
]);
|
|
2
|
+
import { createPresetUltramodernConfig, presetUltramodern } from "./presetUltramodern.mjs";
|
|
3
|
+
const createAppBaselineConfig = createPresetUltramodernConfig;
|
|
4
|
+
const withAppBaseline = presetUltramodern;
|
|
79
5
|
export { createAppBaselineConfig, withAppBaseline };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { i18n, localeKeys } from "../locale/index.mjs";
|
|
3
|
-
import { runtimeCommand } from "./runtime.mjs";
|
|
4
3
|
const devCommand = async (program, api)=>{
|
|
5
4
|
program.command('dev').alias('start').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).option('--web-only', i18n.t(localeKeys.command.dev.webOnly)).action(async (options)=>{
|
|
6
5
|
const { dev } = await import("./dev.mjs");
|
|
@@ -42,7 +41,5 @@ const infoCommand = (program, api)=>{
|
|
|
42
41
|
await info(api, options);
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
export { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, runtimeOperationsCommand, serverCommand };
|
|
44
|
+
export { runtimeCommand } from "./runtime.mjs";
|
|
45
|
+
export { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, serverCommand };
|
|
@@ -55,9 +55,39 @@ const parseResponseBody = async (response)=>{
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
+
const INDENT_STEP = ' ';
|
|
59
|
+
const formatScalar = (value)=>'string' == typeof value ? value : JSON.stringify(value) ?? 'undefined';
|
|
60
|
+
const formatHumanReadableLines = (value, indent)=>{
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
if (0 === value.length) return [
|
|
63
|
+
`${indent}(empty)`
|
|
64
|
+
];
|
|
65
|
+
return value.flatMap((entry)=>null !== entry && 'object' == typeof entry ? [
|
|
66
|
+
`${indent}-`,
|
|
67
|
+
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
68
|
+
] : [
|
|
69
|
+
`${indent}- ${formatScalar(entry)}`
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
if (null !== value && 'object' == typeof value) {
|
|
73
|
+
const entries = Object.entries(value);
|
|
74
|
+
if (0 === entries.length) return [
|
|
75
|
+
`${indent}(empty)`
|
|
76
|
+
];
|
|
77
|
+
return entries.flatMap(([key, entry])=>null !== entry && 'object' == typeof entry ? [
|
|
78
|
+
`${indent}${key}:`,
|
|
79
|
+
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
80
|
+
] : [
|
|
81
|
+
`${indent}${key}: ${formatScalar(entry)}`
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
return [
|
|
85
|
+
`${indent}${formatScalar(value)}`
|
|
86
|
+
];
|
|
87
|
+
};
|
|
88
|
+
const formatRuntimeOutput = (payload, jsonOnly)=>jsonOnly ? JSON.stringify(payload, null, 2) : formatHumanReadableLines(payload, '').join('\n');
|
|
58
89
|
const printOutput = (payload, jsonOnly)=>{
|
|
59
|
-
|
|
60
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
90
|
+
console.log(formatRuntimeOutput(payload, jsonOnly));
|
|
61
91
|
};
|
|
62
92
|
const createRuntimeFallbackSignalPayload = (options)=>{
|
|
63
93
|
const payload = {
|
|
@@ -114,4 +144,4 @@ const runtimeCommand = async (program, _api)=>{
|
|
|
114
144
|
printOutput(responsePayload, options.json);
|
|
115
145
|
});
|
|
116
146
|
};
|
|
117
|
-
export { createRuntimeFallbackSignalPayload, resolveRuntimeEndpoint, resolveToken, runtimeCommand };
|
|
147
|
+
export { createRuntimeFallbackSignalPayload, formatRuntimeOutput, resolveRuntimeEndpoint, resolveToken, runtimeCommand };
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { getLocaleLanguage } from "@modern-js/i18n-utils/language-detector";
|
|
|
5
5
|
import { createAsyncHook } from "@modern-js/plugin";
|
|
6
6
|
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand,
|
|
8
|
+
import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, runtimeCommand, serverCommand } from "./commands/index.mjs";
|
|
9
9
|
import { compatPlugin } from "./compat/index.mjs";
|
|
10
10
|
import { DEFAULT_RUNTIME_CONFIG_FILE } from "./constants.mjs";
|
|
11
11
|
import { i18n } from "./locale/index.mjs";
|
|
@@ -73,7 +73,7 @@ const appTools = ()=>({
|
|
|
73
73
|
deployCommand(program, api);
|
|
74
74
|
inspectCommand(program, api);
|
|
75
75
|
infoCommand(program, api);
|
|
76
|
-
await
|
|
76
|
+
await runtimeCommand(program, api);
|
|
77
77
|
deprecatedCommands(program);
|
|
78
78
|
});
|
|
79
79
|
api.onPrepare(async ()=>{
|
|
@@ -20,6 +20,15 @@ const DEFAULT_SECURITY_HEADERS = {
|
|
|
20
20
|
contentTypeOptions: 'nosniff',
|
|
21
21
|
permissionsPolicy: 'camera=(), geolocation=(), microphone=(), payment=(), usb=()'
|
|
22
22
|
};
|
|
23
|
+
const DEFAULT_CORS_ALLOWED_METHODS = [
|
|
24
|
+
'GET',
|
|
25
|
+
'HEAD',
|
|
26
|
+
'POST',
|
|
27
|
+
'PUT',
|
|
28
|
+
'PATCH',
|
|
29
|
+
'DELETE',
|
|
30
|
+
'OPTIONS'
|
|
31
|
+
];
|
|
23
32
|
const DEFAULT_CSP_DIRECTIVES = {
|
|
24
33
|
'base-uri': [
|
|
25
34
|
"'self'"
|
|
@@ -157,10 +166,20 @@ const createNoindexPolicy = (noindex)=>{
|
|
|
157
166
|
reason: noindex.reason
|
|
158
167
|
};
|
|
159
168
|
};
|
|
169
|
+
const createCloudflareWorkerCorsPolicy = (cors)=>({
|
|
170
|
+
assets: cors?.assets ?? true,
|
|
171
|
+
allowedOrigins: normalizeDirectiveValues(cors?.allowedOrigins ?? []),
|
|
172
|
+
allowedMethods: cors?.allowedMethods?.length ? normalizeDirectiveValues(cors.allowedMethods.map((method)=>method.toUpperCase())) : DEFAULT_CORS_ALLOWED_METHODS,
|
|
173
|
+
allowedHeaders: cors?.allowedHeaders?.length ? normalizeDirectiveValues(cors.allowedHeaders) : [
|
|
174
|
+
'*'
|
|
175
|
+
],
|
|
176
|
+
reason: cors?.reason
|
|
177
|
+
});
|
|
160
178
|
const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
161
179
|
const security = modernConfig.deploy?.worker?.security;
|
|
162
180
|
if (security?.enabled === false) return {
|
|
163
181
|
enabled: false,
|
|
182
|
+
cors: createCloudflareWorkerCorsPolicy(security.cors),
|
|
164
183
|
reason: security.reason
|
|
165
184
|
};
|
|
166
185
|
return {
|
|
@@ -172,10 +191,7 @@ const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
|
|
|
172
191
|
},
|
|
173
192
|
contentSecurityPolicy: createContentSecurityPolicy(security?.contentSecurityPolicy),
|
|
174
193
|
noindex: createNoindexPolicy(security?.noindex),
|
|
175
|
-
|
|
176
|
-
mutateSetCookie: false,
|
|
177
|
-
reason: security?.cookies?.reason ?? 'Cloudflare worker does not own application Set-Cookie headers.'
|
|
178
|
-
},
|
|
194
|
+
cors: createCloudflareWorkerCorsPolicy(security?.cors),
|
|
179
195
|
reason: security?.reason
|
|
180
196
|
};
|
|
181
197
|
};
|
|
@@ -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
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import {
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { ROUTE_SPEC_FILE, SERVER_DIR, dynamicImport, fs, getMeta } from "@modern-js/utils";
|
|
4
5
|
import path from "path";
|
|
5
6
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
6
7
|
import { dirname as __rspack_dirname } from "node:path";
|
|
7
8
|
var utils_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
9
|
+
var utils_filename = __rspack_fileURLToPath(import.meta.url);
|
|
8
10
|
const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
|
|
9
11
|
const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
10
12
|
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
@@ -29,43 +31,17 @@ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
|
29
31
|
};
|
|
30
32
|
const getTemplatePath = (file)=>path.join(utils_dirname, '../platforms/templates', file);
|
|
31
33
|
const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
|
|
32
|
-
const localRequire = createRequire(path.join(utils_dirname, 'package.json'));
|
|
33
|
-
const findNearestPackageJson = (resolvedEntry)=>{
|
|
34
|
-
let currentDir = path.dirname(resolvedEntry);
|
|
35
|
-
while(currentDir !== path.dirname(currentDir)){
|
|
36
|
-
const manifestPath = path.join(currentDir, 'package.json');
|
|
37
|
-
if (fs.existsSync(manifestPath)) return manifestPath;
|
|
38
|
-
currentDir = path.dirname(currentDir);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const splitPackageSpecifier = (entry)=>{
|
|
42
|
-
const segments = entry.split('/');
|
|
43
|
-
if (entry.startsWith('@')) {
|
|
44
|
-
const [scope, name, ...rest] = segments;
|
|
45
|
-
return {
|
|
46
|
-
packageName: `${scope}/${name}`,
|
|
47
|
-
exportKey: rest.length > 0 ? `./${rest.join('/')}` : '.'
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const [name, ...rest] = segments;
|
|
51
|
-
return {
|
|
52
|
-
packageName: name,
|
|
53
|
-
exportKey: rest.length > 0 ? `./${rest.join('/')}` : '.'
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
34
|
const resolveESMDependency = async (entry)=>{
|
|
35
|
+
const conditions = new Set([
|
|
36
|
+
'node',
|
|
37
|
+
'import',
|
|
38
|
+
'module',
|
|
39
|
+
'default'
|
|
40
|
+
]);
|
|
57
41
|
try {
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
if (!packageJsonPath) return normalizePath(resolvedEntry);
|
|
62
|
-
const packageDir = path.dirname(packageJsonPath);
|
|
63
|
-
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
64
|
-
const exportConfig = packageJson.exports?.[exportKey];
|
|
65
|
-
if ('string' == typeof exportConfig) return normalizePath(path.join(packageDir, exportConfig));
|
|
66
|
-
const esmExportPath = exportConfig?.node?.import || exportConfig?.import || exportConfig?.default;
|
|
67
|
-
if ('string' == typeof esmExportPath) return normalizePath(path.join(packageDir, esmExportPath));
|
|
68
|
-
return normalizePath(resolvedEntry);
|
|
42
|
+
const resolverPath = pathToFileURL(createRequire(utils_filename).resolve('import-meta-resolve')).href;
|
|
43
|
+
const { moduleResolve } = await dynamicImport(resolverPath);
|
|
44
|
+
return normalizePath(moduleResolve(entry, pathToFileURL(`${utils_dirname}/`), conditions, false).pathname.replace(/^\/(\w):/, '$1:'));
|
|
69
45
|
} catch (err) {}
|
|
70
46
|
};
|
|
71
47
|
export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
|
|
@@ -1,5 +1,79 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
5
|
+
const DEFAULT_OTLP_ENDPOINT = 'http://127.0.0.1:4318/v1/logs';
|
|
6
|
+
const DEFAULT_VICTORIA_METRICS_ENDPOINT = 'http://127.0.0.1:8428/api/v1/import/prometheus';
|
|
7
|
+
const resolveReactRouterPackageDir = (appDirectory)=>{
|
|
8
|
+
const localRequire = createRequire(node_path.join(appDirectory, 'package.json'));
|
|
9
|
+
try {
|
|
10
|
+
const reactRouterDomPackageJson = localRequire.resolve('react-router-dom/package.json', {
|
|
11
|
+
paths: [
|
|
12
|
+
appDirectory
|
|
13
|
+
]
|
|
14
|
+
});
|
|
15
|
+
const reactRouterPackageJson = localRequire.resolve('react-router/package.json', {
|
|
16
|
+
paths: [
|
|
17
|
+
node_path.dirname(reactRouterDomPackageJson)
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
return node_path.dirname(reactRouterPackageJson);
|
|
21
|
+
} catch {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const setReactRouterBridgeSafeAliases = (chain, { isProd })=>{
|
|
26
|
+
const chainContext = chain.get('context');
|
|
27
|
+
const appDirectory = 'string' == typeof chainContext && chainContext.length > 0 ? chainContext : process.cwd();
|
|
28
|
+
const reactRouterPackageDir = resolveReactRouterPackageDir(appDirectory);
|
|
29
|
+
if (!reactRouterPackageDir) return;
|
|
30
|
+
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
31
|
+
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
32
|
+
chain.resolve.alias.set('react-router$', isProd ? productionEntry : developmentEntry);
|
|
33
|
+
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
34
|
+
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
35
|
+
};
|
|
36
|
+
const createPresetUltramodernConfig = (options = {})=>{
|
|
37
|
+
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;
|
|
38
|
+
const server = {};
|
|
39
|
+
if (enableTelemetry) {
|
|
40
|
+
server.telemetry = {
|
|
41
|
+
enabled: true,
|
|
42
|
+
failLoudStartup: telemetryFailLoudStartup
|
|
43
|
+
};
|
|
44
|
+
if (false !== enableTelemetryExporters) {
|
|
45
|
+
const exporters = {};
|
|
46
|
+
if (true === enableTelemetryExporters || otlpEndpoint) exporters.otlp = {
|
|
47
|
+
enabled: true,
|
|
48
|
+
endpoint: otlpEndpoint || DEFAULT_OTLP_ENDPOINT
|
|
49
|
+
};
|
|
50
|
+
if (true === enableTelemetryExporters || victoriaMetricsEndpoint) exporters.victoriaMetrics = {
|
|
51
|
+
enabled: true,
|
|
52
|
+
endpoint: victoriaMetricsEndpoint || DEFAULT_VICTORIA_METRICS_ENDPOINT
|
|
53
|
+
};
|
|
54
|
+
if (Object.keys(exporters).length > 0) server.telemetry.exporters = exporters;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (enableModuleFederationSSR) server.ssr = {
|
|
58
|
+
mode: 'stream',
|
|
59
|
+
moduleFederationAppSSR: true
|
|
60
|
+
};
|
|
61
|
+
const presetConfig = {
|
|
62
|
+
output: {
|
|
63
|
+
precompress: true
|
|
64
|
+
},
|
|
65
|
+
server,
|
|
66
|
+
tools: {
|
|
67
|
+
bundlerChain: setReactRouterBridgeSafeAliases
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (enableBffRequestId) presetConfig.bff = {
|
|
71
|
+
requestId: appId
|
|
72
|
+
};
|
|
73
|
+
return presetConfig;
|
|
74
|
+
};
|
|
75
|
+
const presetUltramodern = (config, options = {})=>mergeConfig([
|
|
76
|
+
createPresetUltramodernConfig(options),
|
|
77
|
+
config
|
|
78
|
+
]);
|
|
5
79
|
export { createPresetUltramodernConfig, presetUltramodern };
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { parseRspackConfig } from "@modern-js/builder";
|
|
3
|
+
import { createConfigOptions } from "@modern-js/plugin/cli";
|
|
3
4
|
import { INTERNAL_RUNTIME_PLUGINS } from "@modern-js/utils";
|
|
4
5
|
import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./builder/shared/builderPlugins/index.mjs";
|
|
5
6
|
import { DEFAULT_CONFIG_FILE } from "./constants.mjs";
|
|
6
7
|
import { getConfigFile } from "./utils/getConfigFile.mjs";
|
|
7
8
|
import { loadInternalPlugins } from "./utils/loadPlugins.mjs";
|
|
8
|
-
import { __webpack_require__ } from "./rslib-runtime.mjs";
|
|
9
|
-
import * as __rspack_external__modern_js_plugin_cli_caa09fa2 from "@modern-js/plugin/cli";
|
|
10
|
-
__webpack_require__.add({
|
|
11
|
-
"@modern-js/plugin/cli?8936" (module) {
|
|
12
|
-
module.exports = __rspack_external__modern_js_plugin_cli_caa09fa2;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
9
|
const MODERN_META_NAME = 'modern-js';
|
|
16
|
-
const { createConfigOptions: createConfigOptions } = __webpack_require__("@modern-js/plugin/cli?8936");
|
|
17
10
|
async function resolveModernRsbuildConfig(options) {
|
|
18
11
|
const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
|
|
19
12
|
const configFile = options.configPath || getConfigFile(void 0, cwd);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
package/dist/types/baseline.d.ts
CHANGED
|
@@ -1,46 +1,16 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
enableTelemetry?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Enable telemetry exporters by default.
|
|
21
|
-
* @default true
|
|
22
|
-
*/
|
|
23
|
-
enableTelemetryExporters?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* OTLP exporter endpoint.
|
|
26
|
-
* @default process.env.MODERN_TELEMETRY_OTLP_ENDPOINT || 'http://127.0.0.1:4318/v1/logs'
|
|
27
|
-
*/
|
|
28
|
-
otlpEndpoint?: string;
|
|
29
|
-
/**
|
|
30
|
-
* VictoriaMetrics exporter endpoint.
|
|
31
|
-
* @default process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT || 'http://127.0.0.1:8428/api/v1/import/prometheus'
|
|
32
|
-
*/
|
|
33
|
-
victoriaMetricsEndpoint?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Enable fail-loud startup probing for telemetry exporters.
|
|
36
|
-
* @default true
|
|
37
|
-
*/
|
|
38
|
-
telemetryFailLoudStartup?: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Enable app-level Module Federation SSR handshake by default.
|
|
41
|
-
* @default true
|
|
42
|
-
*/
|
|
43
|
-
enableModuleFederationSSR?: boolean;
|
|
44
|
-
}
|
|
45
|
-
export declare const createAppBaselineConfig: (options?: AppBaselineOptions) => AppUserConfig;
|
|
46
|
-
export declare const withAppBaseline: (config: AppUserConfig, options?: AppBaselineOptions) => AppUserConfig;
|
|
1
|
+
import { type PresetUltramodernOptions } from './presetUltramodern';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use `PresetUltramodernOptions` from `@modern-js/app-tools`
|
|
4
|
+
* instead. This alias will be removed in a future release.
|
|
5
|
+
*/
|
|
6
|
+
export type AppBaselineOptions = PresetUltramodernOptions;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `createPresetUltramodernConfig` from `@modern-js/app-tools`
|
|
9
|
+
* instead. This alias will be removed in a future release.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createAppBaselineConfig: (options?: PresetUltramodernOptions) => import("./types").AppUserConfig;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `presetUltramodern` from `@modern-js/app-tools` instead.
|
|
14
|
+
* This alias will be removed in a future release.
|
|
15
|
+
*/
|
|
16
|
+
export declare const withAppBaseline: (config: import("./types").AppUserConfig, options?: PresetUltramodernOptions) => import("./types").AppUserConfig;
|
|
@@ -7,4 +7,4 @@ export declare const serverCommand: (program: Command, api: CLIPluginAPI<AppTool
|
|
|
7
7
|
export declare const deployCommand: (program: Command, api: CLIPluginAPI<AppTools>) => void;
|
|
8
8
|
export declare const inspectCommand: (program: Command, api: CLIPluginAPI<AppTools>) => void;
|
|
9
9
|
export declare const infoCommand: (program: Command, api: CLIPluginAPI<AppTools>) => void;
|
|
10
|
-
export
|
|
10
|
+
export { runtimeCommand } from './runtime';
|
|
@@ -7,5 +7,6 @@ export declare const resolveToken: ({ token, tokenEnv, }: {
|
|
|
7
7
|
token?: string;
|
|
8
8
|
tokenEnv?: string;
|
|
9
9
|
}) => string | undefined;
|
|
10
|
+
export declare const formatRuntimeOutput: (payload: unknown, jsonOnly?: boolean) => string;
|
|
10
11
|
export declare const createRuntimeFallbackSignalPayload: (options: RuntimeFallbackSignalOptions) => Record<string, unknown>;
|
|
11
12
|
export declare const runtimeCommand: (program: Command, _api: CLIPluginAPI<AppTools>) => Promise<void>;
|