Skip to content

Commit fc3110e

Browse files
authored
feat: delete runtime and runtimeByEntries config (#7925)
1 parent f217939 commit fc3110e

File tree

65 files changed

+34
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+34
-297
lines changed

benchmark/bundle-diff/modern.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ const isCI = process.env.CI === 'true';
55

66
// https://modernjs.dev/en/configure/app/usage
77
export default defineConfig({
8-
runtime: {
9-
router: true,
10-
},
11-
128
tools: {
139
bundlerChain: chain => {
1410
if (process.env.RSDOCTOR) {

packages/document/docs/en/configure/app/runtime/0-intro.mdx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
Modern.js runtime configuration should be centralized in the `src/modern.runtime.ts` file.
44

5-
:::warning
6-
7-
Using the `src/modern.runtime.ts` configuration approach requires Modern.js version **MAJOR_VERSION.66.0** or higher.
8-
9-
:::
10-
115
:::info
126

137
If this file doesn't exist in your project yet, create it with the following command:
@@ -27,9 +21,6 @@ export default defineRuntimeConfig({
2721
router: {
2822
// Router configuration
2923
},
30-
state: {
31-
// State management configuration
32-
},
3324
// Other runtime modules...
3425
});
3526
```
@@ -47,16 +38,13 @@ export default defineRuntimeConfig(entryName => {
4738
router: {
4839
// Router configuration for "main" entry
4940
},
50-
state: {
51-
// State management configuration for "main" entry
52-
},
5341
};
5442
}
5543

5644
// Configuration for other entries
5745
return {
58-
masterApp: {
59-
// Micro-frontend configuration example
46+
router: {
47+
// Other entry router configuration
6048
},
6149
};
6250
});

packages/document/docs/zh/configure/app/runtime/0-intro.mdx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
Modern.js 的运行时(Runtime)配置需集中在 `src/modern.runtime.ts` 文件中声明。
44

5-
:::warning
6-
7-
使用 `src/modern.runtime.ts` 配置方式需要 Modern.js 版本 **MAJOR_VERSION.66.0** 或更高版本。
8-
9-
:::
10-
115
:::info
126
如果项目中还没有此文件,请执行以下命令创建:
137

@@ -26,9 +20,6 @@ export default defineRuntimeConfig({
2620
router: {
2721
// 路由配置
2822
},
29-
state: {
30-
// 状态管理配置
31-
},
3223
// 其他运行时模块...
3324
});
3425
```
@@ -46,16 +37,13 @@ export default defineRuntimeConfig(entryName => {
4637
router: {
4738
// "main" 入口的路由配置
4839
},
49-
state: {
50-
// "main" 入口的状态管理配置
51-
},
5240
};
5341
}
5442

5543
// 其他入口的配置
5644
return {
57-
masterApp: {
58-
// 微前端配置示例
45+
router: {
46+
// 其他入口的路由配置
5947
},
6048
};
6149
});

packages/runtime/plugin-i18n/src/runtime/context.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ export const useModernI18n = (): UseModernI18nReturn => {
158158
throw new Error('Language must be a non-empty string');
159159
}
160160

161-
await i18nInstance.changeLanguage(newLang);
161+
await i18nInstance?.setLang?.(newLang);
162+
await i18nInstance?.changeLanguage?.(newLang);
162163

163164
if (isBrowser()) {
164165
const detectionOptions = i18nInstance.options?.detection;

packages/runtime/plugin-i18n/src/runtime/i18n/instance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export interface I18nInstance {
55
language: string;
66
isInitialized: boolean;
77
init: (options?: I18nInitOptions) => void | Promise<void>;
8-
changeLanguage: (lang: string) => void | Promise<void>;
8+
changeLanguage?: (lang: string) => void | Promise<void>;
9+
setLang?: (lang: string) => void | Promise<void>;
910
use: (plugin: any) => void;
1011
createInstance: (options?: I18nInitOptions) => I18nInstance;
1112
cloneInstance?: () => I18nInstance; // ssr need

packages/runtime/plugin-i18n/src/runtime/i18n/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export const ensureLanguageMatch = async (
5454
finalLanguage: string,
5555
): Promise<void> => {
5656
if (i18nInstance.language !== finalLanguage) {
57-
await i18nInstance.changeLanguage(finalLanguage);
57+
await i18nInstance.setLang?.(finalLanguage);
58+
await i18nInstance.changeLanguage?.(finalLanguage);
5859
}
5960
};
6061

packages/runtime/plugin-i18n/src/runtime/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
174174
const currentLang = pathDetection.language;
175175
if (currentLang !== lang) {
176176
setLang(currentLang);
177-
i18nInstance.changeLanguage(currentLang);
177+
i18nInstance?.setLang?.(currentLang);
178+
i18nInstance?.changeLanguage?.(currentLang);
178179
if (isBrowser()) {
179180
const detectionOptions = i18nInstance.options?.detection;
180181
cacheUserLanguage(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { I18nInitOptions, I18nInstance } from './runtime/i18n';
2+
3+
declare module '@modern-js/runtime' {
4+
interface RuntimeConfig {
5+
i18n?: {
6+
i18nInstance?: I18nInstance;
7+
changeLanguage?: (lang: string) => void;
8+
setLang?: (lang: string) => void;
9+
initOptions?: I18nInitOptions;
10+
};
11+
}
12+
}

packages/runtime/plugin-runtime/src/cli/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { AppTools, CliPlugin } from '@modern-js/app-tools';
33
import {
44
isReact18 as checkIsReact18,
55
cleanRequireCache,
6-
createRuntimeExportsUtils,
76
} from '@modern-js/utils';
87
import { documentPlugin } from '../document/cli';
98
import { routerPlugin } from '../router/cli';
@@ -76,26 +75,15 @@ export const runtimePlugin = (params?: {
7675
});
7776

7877
api.config(() => {
79-
const { appDirectory, metaName, internalDirectory } = api.getAppContext();
78+
const { appDirectory, metaName } = api.getAppContext();
8079

8180
const isReact18 = checkIsReact18(appDirectory);
8281

8382
process.env.IS_REACT18 = isReact18.toString();
8483

85-
const pluginsExportsUtils = createRuntimeExportsUtils(
86-
internalDirectory,
87-
'plugins',
88-
);
89-
9084
return {
91-
runtime: {},
92-
runtimeByEntries: {},
9385
resolve: {
9486
alias: {
95-
/**
96-
* Compatible with the reference path of the old version of the plugin.
97-
*/
98-
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
9987
'@meta/runtime/browser$': require.resolve(
10088
'@modern-js/runtime/browser',
10189
),

packages/runtime/plugin-runtime/src/cli/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ const getRegisterRuntimePluginCode = (
225225
) => {
226226
return `plugins.push(${configName}Plugin(mergeConfig(${JSON.stringify(
227227
config,
228-
)}, (runtimeConfig || {})['${configName}'], ((runtimeConfig || {})['${configName}ByEntries'] || {})['${entryName}'])));`;
228+
)}, (runtimeConfig || {})['${configName}'])));`;
229229
};
230230

231231
export const runtimeRegister = ({

0 commit comments

Comments
 (0)