Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-new-expirement-features-into-nextjs-mf
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy authored Jan 21, 2025
2 parents e0d9f48 + 3d83f9d commit a524027
Show file tree
Hide file tree
Showing 77 changed files with 549 additions and 238 deletions.
7 changes: 7 additions & 0 deletions apps/modernjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @module-federation/modernjsapp

## 0.1.80

### Patch Changes

- Updated dependencies [6e3afc6]
- @module-federation/enhanced@0.8.9

## 0.1.79

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/modernjs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@module-federation/modernjsapp",
"private": true,
"version": "0.1.79",
"version": "0.1.80",
"scripts": {
"reset": "npx rimraf ./**/node_modules",
"dev": "modern dev",
Expand Down
6 changes: 6 additions & 0 deletions apps/website-new/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# website-new

## 1.0.22

### Patch Changes

- @module-federation/error-codes@0.8.9

## 1.0.21

### Patch Changes
Expand Down
8 changes: 8 additions & 0 deletions apps/website-new/docs/en/configure/dts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@ tsconfig configuration file path
- Default value: `undefined`

The working directory to run the compiler

### displayErrorInTerminal

- Type: `boolean`
- Required: No
- Default value: `true`

Whether print error log in terminal
16 changes: 16 additions & 0 deletions apps/website-new/docs/zh/configure/dts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,19 @@ interface DtsHostOptions {
- 默认值:`path.join(process.cwd(),'./tsconfig.json')`

tsconfig 配置文件路径

### cwd

- 类型:`string`
- 是否必填:否
- 默认值:`undefined`

运行 tsc 的路径,默认为项目根目录。

### displayErrorInTerminal

- 类型:`boolean`
- 是否必填:否
- 默认值:`true`

是否在 terminal 输出错误日志
10 changes: 5 additions & 5 deletions apps/website-new/docs/zh/configure/experiments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ new ModuleFederationPlugin({

这些配置可用于下列场景:

- 设置`runtimeChunk: 'single'`
- 避免在应用程序顶部或用户代码入口点使用“import()”,以防止急切消费错误。过去,这通常是强制性的,并且在示例应用程序中通常被视为“import('./bootstrap.js')
- 将模块联合运行时包移动到运行时块中,使它们远离入口点 - 减少代码重复
- 设置 `runtimeChunk: 'single'`
- 避免在应用的顶部或用户代码的入口点使用 import(),以防止 `eager` 的错误。在过去,这通常是强制性的,并且常见的示例应用中会看到 `import('./bootstrap.js')`
- 将模块联邦运行时包移入运行时代码块,将它们从入口点中移出,从而减少代码重复。

下面会详细解释对应的场景。

Expand All @@ -50,7 +50,7 @@ new ModuleFederationPlugin({

2)异步启动

:::警告
:::warning
此模式仍然允许设置异步入口。导出 UMD 库时,它会返回 Promise resolve 导出。
如果您手动 require() Node 中的入口点,它将 module.exports 设置为 Promise.resolve(exports)。
:::
Expand All @@ -61,7 +61,7 @@ new ModuleFederationPlugin({

不再出现共享依赖 `eager consumption` 错误,因为文件本身的初始化表现为异步块。

3) 提升 MF 运行时访问优先级
3提升 MF 运行时访问优先级

与原先在入口挂载 MF runtime 不同,现在将会提升到 bundler runtime 初始化阶段挂载 MF runtime 。

Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "website-new",
"version": "1.0.21",
"version": "1.0.22",
"private": true,
"scripts": {
"dev": "rspress dev",
Expand Down
6 changes: 6 additions & 0 deletions packages/bridge/bridge-react-webpack-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @module-federation/bridge-react-webpack-plugin

## 0.8.9

### Patch Changes

- @module-federation/sdk@0.8.9

## 0.8.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-react-webpack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/bridge-react-webpack-plugin",
"version": "0.8.8",
"version": "0.8.9",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/bridge/bridge-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @module-federation/bridge-react

## 0.8.9

### Patch Changes

- @module-federation/sdk@0.8.9
- @module-federation/bridge-shared@0.8.9

## 0.8.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/bridge-react",
"version": "0.8.8",
"version": "0.8.9",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge/bridge-shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @module-federation/bridge-shared

## 0.8.9

## 0.8.8

## 0.8.7
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/bridge-shared",
"version": "0.8.8",
"version": "0.8.9",
"publishConfig": {
"access": "public"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/bridge/vue3-bridge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @module-federation/bridge-vue3

## 0.8.9

### Patch Changes

- @module-federation/runtime@0.8.9
- @module-federation/sdk@0.8.9
- @module-federation/bridge-shared@0.8.9

## 0.8.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/vue3-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/module-federation/core",
"directory": "packages/vue3-bridge"
},
"version": "0.8.8",
"version": "0.8.9",
"publishConfig": {
"access": "public"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/chrome-devtools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @module-federation/devtools

## 0.8.9

### Patch Changes

- @module-federation/sdk@0.8.9

## 0.8.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/chrome-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/devtools",
"version": "0.8.8",
"version": "0.8.9",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/data-prefetch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @module-federation/data-prefetch

## 0.8.9

### Patch Changes

- @module-federation/runtime@0.8.9
- @module-federation/sdk@0.8.9

## 0.8.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/data-prefetch/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@module-federation/data-prefetch",
"description": "Module Federation Data Prefetch",
"version": "0.8.8",
"version": "0.8.9",
"author": "nieyan <[email protected]>",
"homepage": "https://github.com/module-federation/core",
"license": "MIT",
Expand Down
17 changes: 17 additions & 0 deletions packages/dts-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @module-federation/dts-plugin

## 0.8.9

### Patch Changes

- 6e3afc6: feat(dts-plugin): support pass headers when request types url
- 1be9d62: feat(dts-plugin): add dts.displayErrorInTerminal to help control display error
- 6e3afc6: fix(dts-plugin): set outputDir default value
- 6e3afc6: fix(dts-plugin): use remoteTarPath first to fetch hot types
- 6e3afc6: fix(dts-plugin): only consume types in dev
- 6e3afc6: fix(dts-plugin): throw error while downloading types archive hit historyApiFallback
- 6e3afc6: fix(dts-plugin): generateTypes should after consumeTypes finished
- 6e3afc6: fix(dts-plugin): dev plugin should apply after fetchPromise resolved
- @module-federation/sdk@0.8.9
- @module-federation/managers@0.8.9
- @module-federation/third-party-dts-extractor@0.8.9
- @module-federation/error-codes@0.8.9

## 0.8.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/dts-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/dts-plugin",
"version": "0.8.8",
"version": "0.8.9",
"author": "hanric <[email protected]>",
"main": "./dist/index.js",
"module": "./dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/dts-plugin/src/core/interfaces/DTSManagerOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { moduleFederationPlugin } from '@module-federation/sdk';
import { HostOptions } from './HostOptions';
import { RemoteOptions } from './RemoteOptions';

export interface DTSManagerOptions {
remote?: RemoteOptions;
host?: HostOptions;
extraOptions?: Record<string, any>;
displayErrorInTerminal?: moduleFederationPlugin.PluginDtsOptions['displayErrorInTerminal'];
}
39 changes: 31 additions & 8 deletions packages/dts-plugin/src/core/lib/DTSManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ class DTSManager {
logger.success('Federated types created correctly');
} catch (error) {
if (this.options.remote?.abortOnError === false) {
logger.error(`Unable to compile federated types, ${error}`);
if (this.options.displayErrorInTerminal) {
logger.error(`Unable to compile federated types${error}`);
}
} else {
throw error;
}
Expand Down Expand Up @@ -263,10 +265,11 @@ class DTSManager {
const filePath = path.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
fs.writeFileSync(filePath, apiTypeFile);
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
fileLog(`success`, 'downloadAPITypes', 'info');
} catch (err) {
fileLog(
`Unable to download "${remoteInfo.name}" api types, ${err}`,
'consumeTargetRemotes',
'downloadAPITypes',
'error',
);
}
Expand Down Expand Up @@ -420,17 +423,17 @@ class DTSManager {

async updateTypes(options: UpdateTypesOptions): Promise<void> {
try {
// can use remoteTarPath directly in the future
const {
remoteName,
updateMode,
remoteTarPath,
remoteInfo: updatedRemoteInfo,
once,
} = options;
const hostName = this.options?.host?.moduleFederationConfig?.name;
fileLog(
`updateTypes options:, ${JSON.stringify(options, null, 2)}`,
'consumeTypes',
`options: ${JSON.stringify(options, null, 2)};\nhostName: ${hostName}`,
'updateTypes',
'info',
);
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
Expand All @@ -454,19 +457,39 @@ class DTSManager {
const consumeTypes = async (
requiredRemoteInfo: Required<RemoteInfo>,
) => {
fileLog(`consumeTypes start`, 'updateTypes', 'info');
if (!requiredRemoteInfo.zipUrl) {
throw new Error(
`Can not get ${requiredRemoteInfo.name}'s types archive url!`,
);
}
const [_alias, destinationPath] = await this.consumeTargetRemotes(
hostOptions,
requiredRemoteInfo,
{
...requiredRemoteInfo,
// use remoteTarPath first
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl,
},
);
await this.downloadAPITypes(requiredRemoteInfo, destinationPath);
fileLog(`consumeTypes end`, 'updateTypes', 'info');
};

fileLog(
`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`,
'updateTypes',
'info',
);
if (!loadedRemoteInfo) {
const remoteInfo = Object.values(mapRemotesToDownload).find(
(item) => {
return item.name === remoteName;
},
);
fileLog(
`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`,
'updateTypes',
'info',
);
if (remoteInfo) {
if (!this.remoteAliasMap[remoteInfo.alias]) {
const requiredRemoteInfo =
Expand Down Expand Up @@ -496,7 +519,7 @@ class DTSManager {
null,
2,
)}`,
'consumeTypes',
'updateTypes',
'info',
);
await consumeDynamicRemoteTypes();
Expand Down
13 changes: 13 additions & 0 deletions packages/dts-plugin/src/core/lib/archiveHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export const downloadTypesArchive = (hostOptions: Required<HostOptions>) => {
const response = await axiosGet(url, {
responseType: 'arraybuffer',
}).catch(downloadErrorLogger(destinationFolder, url));
if (
typeof response.headers?.['content-type'] === 'string' &&
response.headers['content-type'].includes('text/html')
) {
throw new Error(
`${url} receives invalid content-type: ${response.headers['content-type']}`,
);
}

try {
if (hostOptions.deleteTypesFolder) {
Expand All @@ -81,6 +89,11 @@ export const downloadTypesArchive = (hostOptions: Required<HostOptions>) => {

const zip = new AdmZip(Buffer.from(response.data));
zip.extractAllTo(destinationPath, true);
fileLog(
`zip.extractAllTo success destinationPath: ${destinationPath}; url: ${url}`,
'downloadTypesArchive',
'info',
);
return [destinationFolder, destinationPath];
} catch (error: any) {
fileLog(
Expand Down
Loading

0 comments on commit a524027

Please sign in to comment.