From 1d9b246d2c37375b3868f151060a7071fde40c28 Mon Sep 17 00:00:00 2001
From: 2heal1
Date: Tue, 11 Mar 2025 17:56:37 +0800
Subject: [PATCH 1/3] feat: add mf cli
---
.changeset/config.json | 3 +-
.../docs/en/guide/basic/_meta.json | 2 +-
apps/website-new/docs/en/guide/basic/cli.mdx | 52 ++++++
.../docs/zh/guide/basic/_meta.json | 2 +-
apps/website-new/docs/zh/guide/basic/cli.mdx | 52 ++++++
packages/cli/CHANGELOG.md | 1 +
packages/cli/LICENSE | 21 +++
packages/cli/README.md | 63 +++++++
packages/cli/bin/mf.js | 4 +
packages/cli/package.json | 42 +++++
packages/cli/project.json | 62 +++++++
packages/cli/rollup.config.js | 21 +++
packages/cli/src/cli.ts | 71 +++++++
packages/cli/src/commands/dts.ts | 96 ++++++++++
packages/cli/src/env.d.ts | 1 +
packages/cli/src/index.ts | 1 +
packages/cli/src/types.ts | 23 +++
.../cli/src/utils/apply-common-options.ts | 8 +
packages/cli/src/utils/logger.ts | 8 +
packages/cli/src/utils/prepare.ts | 17 ++
packages/cli/tsconfig.json | 27 +++
.../dts-plugin/src/core/lib/archiveHandler.ts | 4 +
packages/dts-plugin/src/index.ts | 11 +-
.../src/plugins/ConsumeTypesPlugin.ts | 128 ++++++++-----
packages/dts-plugin/src/plugins/DtsPlugin.ts | 54 +++---
.../src/plugins/GenerateTypesPlugin.ts | 173 +++++++++++-------
packages/dts-plugin/src/server/constant.ts | 2 +-
pnpm-lock.yaml | 113 +++++++++---
28 files changed, 889 insertions(+), 173 deletions(-)
create mode 100644 apps/website-new/docs/en/guide/basic/cli.mdx
create mode 100644 apps/website-new/docs/zh/guide/basic/cli.mdx
create mode 100644 packages/cli/CHANGELOG.md
create mode 100644 packages/cli/LICENSE
create mode 100644 packages/cli/README.md
create mode 100755 packages/cli/bin/mf.js
create mode 100644 packages/cli/package.json
create mode 100644 packages/cli/project.json
create mode 100644 packages/cli/rollup.config.js
create mode 100644 packages/cli/src/cli.ts
create mode 100644 packages/cli/src/commands/dts.ts
create mode 100644 packages/cli/src/env.d.ts
create mode 100644 packages/cli/src/index.ts
create mode 100644 packages/cli/src/types.ts
create mode 100644 packages/cli/src/utils/apply-common-options.ts
create mode 100644 packages/cli/src/utils/logger.ts
create mode 100644 packages/cli/src/utils/prepare.ts
create mode 100644 packages/cli/tsconfig.json
diff --git a/.changeset/config.json b/.changeset/config.json
index 48ecd9e0391..6a62d9a7350 100644
--- a/.changeset/config.json
+++ b/.changeset/config.json
@@ -26,7 +26,8 @@
"@module-federation/error-codes",
"@module-federation/inject-external-runtime-core-plugin",
"@module-federation/runtime-core",
- "create-module-federation"
+ "create-module-federation",
+ "@module-federation/cli"
]
],
"ignorePatterns": ["^alpha|^beta"],
diff --git a/apps/website-new/docs/en/guide/basic/_meta.json b/apps/website-new/docs/en/guide/basic/_meta.json
index 0c6e0164841..70b2cb33df2 100644
--- a/apps/website-new/docs/en/guide/basic/_meta.json
+++ b/apps/website-new/docs/en/guide/basic/_meta.json
@@ -1 +1 @@
-["runtime", "rsbuild", "rspack", "webpack", "vite", "chrome-devtool", "type-prompt"]
+["runtime", "rsbuild", "rspack", "webpack", "vite", "chrome-devtool", "type-prompt","cli"]
diff --git a/apps/website-new/docs/en/guide/basic/cli.mdx b/apps/website-new/docs/en/guide/basic/cli.mdx
new file mode 100644
index 00000000000..bc11c3ff2d1
--- /dev/null
+++ b/apps/website-new/docs/en/guide/basic/cli.mdx
@@ -0,0 +1,52 @@
+# CLI
+
+Module Federation provides a lightweight CLI.
+
+## All commands
+
+To view all available CLI commands, run the following command in the project directory:
+
+```bash
+npx @module-federation/cli -h
+```
+
+The output is shown below:
+
+```text
+Usage: mf [options]
+
+Options:
+ -V, --version output the version number
+ -h, --help display help for command
+
+Commands:
+ dts [options] generate or fetch the mf types
+ help [command] display help for command
+```
+
+## Common flags
+
+Module Federation CLI provides several common flags that can be used with all commands:
+
+| Flag | Description |
+| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `-c, --config ` | Specify the configuration file, can be a relative or absolute path, default value is `module-federation.ts` |
+| `-h, --help` | Display help for command |
+
+## mf dts
+
+The `mf dts` command is used to generate or fetch remote types.
+
+```bash
+Usage: mf dts [options]
+
+generate or fetch the mf types
+
+Options:
+ --root specify the project root directory
+ --output
-
-## All commands
-
-To view all available CLI commands, run the following command in the project directory:
-
-```bash
-npx @module-federation/cli -h
-```
-
-The output is shown below:
-
-```bash
-Usage: mf [options]
-
-Options:
- -V, --version output the version number
- -h, --help display help for command
-
-Commands:
- dts [options] generate or fetch the mf types
- help [command] display help for command
-```
-
-### mf dts
-
-The mf dts command is used to generate or fetch remote types.
-
-```bash
-Usage: mf dts [options]
-
-generate or fetch the mf types
-
-Options:
- --root specify the project root directory
- --output specify the generated dts output directory
- --fetch fetch types from remote, default is true (default: true)
- --generate generate types, default is true (default: true)
- -c --config specify the configuration file, can be a relative or absolute path
- -h, --help display help for command
-```
-
-## Documentation
-
-See [Documentation](https://module-federation.io/guide/start/quick-start).
-
-## License
-
-[MIT](https://github.com/module-federation/core/blob/main/LICENSE).
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts
index 46869be23c8..6385bafec29 100644
--- a/packages/cli/src/cli.ts
+++ b/packages/cli/src/cli.ts
@@ -2,15 +2,13 @@ import { program } from 'commander';
import { applyCommonOptions } from './utils/apply-common-options';
import { dts } from './commands/dts';
import { prepareCli } from './utils/prepare';
+import logger, { PREFIX } from './utils/logger';
+import { readConfig } from './utils/readConfig';
import type { DtsOptions, CliOptions } from './types';
-function cli({
- name,
- version,
- applyCommands,
- config,
-}: Required): void {
+function cli(cliOptions: Required): void {
+ const { name, version, applyCommands } = cliOptions;
program.name(name).usage(' [options]').version(version);
const dtsCommand = program.command('dts');
@@ -37,7 +35,7 @@ function cli({
.description('generate or fetch the mf types')
.action(async (options: DtsOptions) => {
try {
- await dts(options, { defaultConfig: config });
+ await dts(options, cliOptions);
} catch (err) {
console.error(err);
process.exit(1);
@@ -53,14 +51,17 @@ function cli({
export function runCli(options: CliOptions) {
const normalizedOptions: Required = {
+ loggerPrefix: PREFIX,
welcomeMsg: `${`Module Federation v${__VERSION__}`}\n`,
name: 'mf',
- config: 'module-federation.config.ts',
+ readConfig,
version: __VERSION__,
applyCommands: () => {},
...options,
};
+ logger.setPrefix(normalizedOptions.loggerPrefix);
+
prepareCli(normalizedOptions);
try {
diff --git a/packages/cli/src/commands/dts.ts b/packages/cli/src/commands/dts.ts
index bfa92df0781..009f3770ea7 100644
--- a/packages/cli/src/commands/dts.ts
+++ b/packages/cli/src/commands/dts.ts
@@ -1,5 +1,3 @@
-import path from 'path';
-import logger from '../utils/logger';
import {
isTSProject,
normalizeDtsOptions,
@@ -8,31 +6,23 @@ import {
normalizeGenerateTypesOptions,
normalizeConsumeTypesOptions,
} from '@module-federation/dts-plugin';
-import { bundle } from '@modern-js/node-bundle-require';
+import logger from '../utils/logger';
-import type { DtsOptions } from '../types';
-import { moduleFederationPlugin } from '@module-federation/sdk';
+import type { CliOptions, DtsOptions } from '../types';
export async function dts(
options: DtsOptions,
- { defaultConfig }: { defaultConfig: string },
+ { readConfig }: Required,
) {
- const defaultPath = path.resolve(process.cwd(), defaultConfig);
const {
fetch = true,
generate = true,
root = process.cwd(),
output,
- config = defaultPath,
+ config,
} = options;
- const configPath = path.isAbsolute(config)
- ? config
- : path.resolve(process.cwd(), config);
-
- const preBundlePath = await bundle(configPath);
- const mfConfig = (await import(preBundlePath)).default
- .default as unknown as moduleFederationPlugin.ModuleFederationPluginOptions;
+ const mfConfig = await readConfig(config);
if (!isTSProject(mfConfig.dts, root)) {
logger.error('dts is only supported for TypeScript projects');
diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts
index 85de8533f65..e187770d4c4 100644
--- a/packages/cli/src/types.ts
+++ b/packages/cli/src/types.ts
@@ -1,7 +1,9 @@
import type { Command } from 'commander';
+import type { moduleFederationPlugin } from '@module-federation/sdk';
export type CommonOptions = {
config?: string;
+ mode?: string;
};
export type DtsOptions = {
@@ -13,9 +15,12 @@ export type DtsOptions = {
export type CliOptions = {
welcomeMsg?: string;
+ loggerPrefix?: string;
name?: string;
version?: string;
- config?: string;
+ readConfig?: (
+ userConfigPath?: string,
+ ) => Promise;
applyCommands?: (
command: Command,
applyCommonOptions: (command: Command) => void,
diff --git a/packages/cli/src/utils/apply-common-options.ts b/packages/cli/src/utils/apply-common-options.ts
index e42994d83cc..0e8be2490f1 100644
--- a/packages/cli/src/utils/apply-common-options.ts
+++ b/packages/cli/src/utils/apply-common-options.ts
@@ -5,4 +5,26 @@ export const applyCommonOptions = (command: Command) => {
'-c --config ',
'specify the configuration file, can be a relative or absolute path',
);
+ command.option(
+ '-m --mode ',
+ 'Specify the runtime environment. You can choose "dev" or "prod". The default value is "dev". After setting, the process.env.NODE_ENV environment variable will be automatically injected with "development" or "production" according to the value.',
+ (value) => {
+ const validChoices = {
+ dev: 'development',
+ prod: 'production',
+ };
+ if (!Object.keys(validChoices).includes(value)) {
+ throw new Error(
+ `Invalid mode: ${value}. Valid choices are: ${Object.keys(validChoices).join(', ')}`,
+ );
+ }
+ const targetEnv = validChoices[value as keyof typeof validChoices];
+ if (process.env.NODE_ENV !== targetEnv) {
+ console.log(`process.env.NODE_ENV is set to ${targetEnv}`);
+ }
+ process.env.NODE_ENV = targetEnv;
+ return value;
+ },
+ 'dev',
+ );
};
diff --git a/packages/cli/src/utils/logger.ts b/packages/cli/src/utils/logger.ts
index abe8d20a4ba..eba6e5c7b5e 100644
--- a/packages/cli/src/utils/logger.ts
+++ b/packages/cli/src/utils/logger.ts
@@ -1,7 +1,7 @@
import { type Logger, createLogger } from '@module-federation/sdk';
import chalk from 'chalk';
-const PREFIX = '[ Module Federation CLI ]';
+export const PREFIX = '[ Module Federation CLI ]';
const logger: Logger = createLogger(chalk`{bold {cyan ${PREFIX}}}`);
diff --git a/packages/cli/src/utils/prepare.ts b/packages/cli/src/utils/prepare.ts
index f9b3ba3045a..6c3791a33bc 100644
--- a/packages/cli/src/utils/prepare.ts
+++ b/packages/cli/src/utils/prepare.ts
@@ -2,6 +2,9 @@ import logger from './logger';
import type { CliOptions } from '../types';
export function prepareCli({ welcomeMsg }: Required): void {
+ if (!process.env.NODE_ENV) {
+ process.env.NODE_ENV = 'development';
+ }
// Print a blank line to keep the greet log nice.
// Some package managers automatically output a blank line, some do not.
const { npm_execpath } = process.env;
diff --git a/packages/cli/src/utils/readConfig.ts b/packages/cli/src/utils/readConfig.ts
new file mode 100644
index 00000000000..ebbcb78e4a8
--- /dev/null
+++ b/packages/cli/src/utils/readConfig.ts
@@ -0,0 +1,21 @@
+import path from 'path';
+import { bundle } from '@modern-js/node-bundle-require';
+import type { moduleFederationPlugin } from '@module-federation/sdk';
+
+const DEFAULT_CONFIG_PATH = 'module-federation.config.ts';
+
+export const getConfigPath = (userConfigPath?: string) => {
+ const defaultPath = path.resolve(process.cwd(), DEFAULT_CONFIG_PATH);
+ const filepath = userConfigPath ?? defaultPath;
+ return path.isAbsolute(filepath)
+ ? filepath
+ : path.resolve(process.cwd(), filepath);
+};
+
+export async function readConfig(userConfigPath?: string) {
+ const configPath = getConfigPath(userConfigPath);
+ const preBundlePath = await bundle(configPath);
+ const mfConfig = (await import(preBundlePath)).default
+ .default as unknown as moduleFederationPlugin.ModuleFederationPluginOptions;
+ return mfConfig;
+}
diff --git a/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts b/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts
index 8027e8bb7ee..e23d9be0f25 100644
--- a/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts
+++ b/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts
@@ -147,5 +147,62 @@ describe('hostPlugin', () => {
},
});
});
+
+ it('correctly resolve remoteTypeUrls', () => {
+ const mfConfigWithRemoteTypeUrls = {
+ ...moduleFederationConfig,
+ remotes: {
+ 'remote1-alias': 'remote1@http://localhost:3001/remoteEntry.js',
+ 'remote2-alias': 'remote2@http://localhost:3002/remoteEntry.js',
+ },
+ };
+
+ const { mapRemotesToDownload } = retrieveHostConfig({
+ moduleFederationConfig: mfConfigWithRemoteTypeUrls,
+ remoteTypeUrls: {
+ remote1: {
+ alias: 'remote1-alias',
+ zip: 'http://localhost:3001/custom-dir/@mf-types.zip',
+ api: 'http://localhost:3001/custom-dir/@mf-types.d.ts',
+ },
+ },
+ });
+
+ expect(mapRemotesToDownload).toStrictEqual({
+ 'remote1-alias': {
+ name: 'remote1',
+ alias: 'remote1-alias',
+ url: '',
+ zipUrl: 'http://localhost:3001/custom-dir/@mf-types.zip',
+ apiTypeUrl: 'http://localhost:3001/custom-dir/@mf-types.d.ts',
+ },
+ 'remote2-alias': {
+ name: 'remote2',
+ alias: 'remote2-alias',
+ url: 'http://localhost:3002/remoteEntry.js',
+ zipUrl: 'http://localhost:3002/@mf-types.zip',
+ apiTypeUrl: 'http://localhost:3002/@mf-types.d.ts',
+ },
+ });
+ });
+
+ it('throw error if typeof remoteTypeUrls is not object', () => {
+ const options = {
+ moduleFederationConfig,
+ remoteTypeUrls: () =>
+ Promise.resolve({
+ remote1: {
+ alias: 'remote1-alias',
+ zip: 'http://localhost:3001/custom-dir/@mf-types.zip',
+ api: 'http://localhost:3001/custom-dir/@mf-types.d.ts',
+ },
+ }),
+ };
+
+ const invokeRetrieve = () => retrieveHostConfig(options);
+ expect(invokeRetrieve).toThrowError(
+ 'remoteTypeUrls must be consumed before resolveRemotes',
+ );
+ });
});
});
diff --git a/packages/dts-plugin/src/core/configurations/hostPlugin.ts b/packages/dts-plugin/src/core/configurations/hostPlugin.ts
index e10406d416f..19510040d87 100644
--- a/packages/dts-plugin/src/core/configurations/hostPlugin.ts
+++ b/packages/dts-plugin/src/core/configurations/hostPlugin.ts
@@ -64,10 +64,13 @@ export const retrieveRemoteInfo = (options: {
let zipUrl = '';
let apiTypeUrl = '';
const name = parsedInfo.name || remoteAlias;
+
+ // for updated remote
if (typeof remoteTypeUrls === 'object' && remoteTypeUrls[name]) {
zipUrl = remoteTypeUrls[name].zip;
apiTypeUrl = remoteTypeUrls[name].api;
}
+
if (!zipUrl && url) {
zipUrl = buildZipUrl(hostOptions, url);
}
@@ -98,18 +101,45 @@ const resolveRemotes = (hostOptions: Required) => {
}),
);
- return parsedOptions.reduce(
- (accumulator, item) => {
- const { key, remote } = item[1];
- accumulator[key] = retrieveRemoteInfo({
- hostOptions,
- remoteAlias: key,
- remote,
- });
- return accumulator;
+ const remoteTypeUrls = hostOptions.remoteTypeUrls ?? {};
+ if (typeof remoteTypeUrls !== 'object') {
+ throw new Error('remoteTypeUrls must be consumed before resolveRemotes');
+ }
+ const remoteInfos = Object.keys(remoteTypeUrls).reduce(
+ (sum, remoteName) => {
+ const { zip, api, alias } = remoteTypeUrls[remoteName];
+ sum[alias] = {
+ name: remoteName,
+ url: '',
+ zipUrl: zip,
+ apiTypeUrl: api,
+ alias: alias || remoteName,
+ };
+ return sum;
},
{} as Record,
);
+
+ return parsedOptions.reduce((accumulator, item) => {
+ const { key, remote } = item[1];
+ const res = retrieveRemoteInfo({
+ hostOptions,
+ remoteAlias: key,
+ remote,
+ });
+
+ if (accumulator[key]) {
+ accumulator[key] = {
+ ...accumulator[key],
+ url: res.url,
+ apiTypeUrl: accumulator[key].apiTypeUrl || res.apiTypeUrl,
+ };
+ return accumulator;
+ }
+
+ accumulator[key] = res;
+ return accumulator;
+ }, remoteInfos);
};
export const retrieveHostConfig = (options: HostOptions) => {
diff --git a/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts b/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
index 95178b6ad53..c014fc29cda 100644
--- a/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
+++ b/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
@@ -82,26 +82,22 @@ export const normalizeGenerateTypesOptions = ({
return finalOptions;
};
-export const generateTypesAPI = async ({
+const getGenerateTypesFn = (dtsManagerOptions: DTSManagerOptions) => {
+ let fn: typeof generateTypes | typeof generateTypesInChildProcess =
+ generateTypes;
+ if (dtsManagerOptions.remote.compileInChildProcess) {
+ fn = generateTypesInChildProcess;
+ }
+ return fn;
+};
+
+export const generateTypesAPI = ({
dtsManagerOptions,
}: {
dtsManagerOptions: DTSManagerOptions;
}) => {
- const isProd = !isDev();
- const getGenerateTypesFn = () => {
- let fn: typeof generateTypes | typeof generateTypesInChildProcess =
- generateTypes;
- let res: ReturnType;
- if (dtsManagerOptions.remote.compileInChildProcess) {
- fn = generateTypesInChildProcess;
- }
- if (isProd) {
- res = fn(dtsManagerOptions);
- return () => res;
- }
- return fn;
- };
- return getGenerateTypesFn();
+ const fn = getGenerateTypesFn(dtsManagerOptions);
+ return fn(dtsManagerOptions);
};
export class GenerateTypesPlugin implements WebpackPluginInstance {
@@ -202,7 +198,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
return err.code == 'EEXIST';
};
if (zipTypesPath) {
- const zipContent = fs.readFileSync(zipTypesPath, 'utf-8');
+ const zipContent = fs.readFileSync(zipTypesPath);
const zipOutputPath = path.join(
compiler.outputPath,
zipPrefix,
@@ -217,6 +213,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
} else {
compiler.outputFileSystem.writeFile(
zipOutputPath,
+ // @ts-ignore
zipContent,
(writeErr) => {
if (writeErr && !isEEXIST(writeErr)) {
@@ -233,7 +230,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
}
if (apiTypesPath) {
- const apiContent = fs.readFileSync(apiTypesPath, 'utf-8');
+ const apiContent = fs.readFileSync(apiTypesPath);
const apiOutputPath = path.join(
compiler.outputPath,
zipPrefix,
@@ -248,6 +245,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
} else {
compiler.outputFileSystem.writeFile(
apiOutputPath,
+ // @ts-ignore
apiContent,
(writeErr) => {
if (writeErr && !isEEXIST(writeErr)) {
diff --git a/packages/enhanced/README.md b/packages/enhanced/README.md
index 9129c2060de..78874298f26 100644
--- a/packages/enhanced/README.md
+++ b/packages/enhanced/README.md
@@ -171,3 +171,43 @@ Once set, the runtime plugin is automatically injected and used at build time.
- Default: `undefined`
Used to modify the actual bundler runtime version. Path with value `@module-federation/runtime-tools`.
+
+## CLI
+
+To view all available CLI commands, run the following command in the project directory:
+
+```bash
+npx mf -h
+```
+
+The output is shown below:
+
+```bash
+Usage: mf [options]
+
+Options:
+ -V, --version output the version number
+ -h, --help display help for command
+
+Commands:
+ dts [options] generate or fetch the mf types
+ help [command] display help for command
+```
+
+### mf dts
+
+The mf dts command is used to generate or fetch remote types.
+
+```bash
+Usage: mf dts [options]
+
+generate or fetch the mf types
+
+Options:
+ --root specify the project root directory
+ --output specify the generated dts output directory
+ --fetch fetch types from remote, default is true (default: true)
+ --generate generate types, default is true (default: true)
+ -c --config specify the configuration file, can be a relative or absolute path
+ -h, --help display help for command
+```
diff --git a/packages/enhanced/bin/mf.js b/packages/enhanced/bin/mf.js
new file mode 100755
index 00000000000..6ac43ef8105
--- /dev/null
+++ b/packages/enhanced/bin/mf.js
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+const { runCli } = require('@module-federation/cli');
+
+runCli();
diff --git a/packages/enhanced/package.json b/packages/enhanced/package.json
index c6bec2cd9e1..eadd24eb0e3 100644
--- a/packages/enhanced/package.json
+++ b/packages/enhanced/package.json
@@ -9,9 +9,13 @@
"directory": "packages/enhanced"
},
"files": [
+ "bin",
"dist/",
"README.md"
],
+ "bin": {
+ "mf": "./bin/mf.js"
+ },
"license": "MIT",
"publishConfig": {
"access": "public"
@@ -96,6 +100,7 @@
"@module-federation/rspack": "workspace:*",
"@module-federation/runtime-tools": "workspace:*",
"@module-federation/sdk": "workspace:*",
+ "@module-federation/cli": "workspace:*",
"btoa": "^1.2.1",
"upath": "2.0.1"
}
diff --git a/packages/enhanced/src/index.ts b/packages/enhanced/src/index.ts
index b383f748dc0..be7892e39fd 100644
--- a/packages/enhanced/src/index.ts
+++ b/packages/enhanced/src/index.ts
@@ -32,3 +32,5 @@ export const createModuleFederationConfig = (
): moduleFederationPlugin.ModuleFederationPluginOptions => {
return options;
};
+
+export type { moduleFederationPlugin };
diff --git a/packages/modernjs/bin/mf.js b/packages/modernjs/bin/mf.js
new file mode 100755
index 00000000000..6ac43ef8105
--- /dev/null
+++ b/packages/modernjs/bin/mf.js
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+const { runCli } = require('@module-federation/cli');
+
+runCli();
diff --git a/packages/modernjs/package.json b/packages/modernjs/package.json
index b073d4a06a7..20ac9d83462 100644
--- a/packages/modernjs/package.json
+++ b/packages/modernjs/package.json
@@ -93,6 +93,7 @@
"@module-federation/enhanced": "workspace:*",
"@module-federation/node": "workspace:*",
"@module-federation/sdk": "workspace:*",
+ "@module-federation/cli": "workspace:*",
"@swc/helpers": "0.5.13",
"node-fetch": "~3.3.0",
"react-error-boundary": "4.1.2"
diff --git a/packages/sdk/src/logger.ts b/packages/sdk/src/logger.ts
index 35db772bdc3..5368eb0f3d1 100644
--- a/packages/sdk/src/logger.ts
+++ b/packages/sdk/src/logger.ts
@@ -7,6 +7,11 @@ class Logger {
constructor(prefix: string) {
this.prefix = prefix;
}
+
+ setPrefix(prefix: string) {
+ this.prefix = prefix;
+ }
+
log(...args: any[]) {
console.log(this.prefix, ...args);
}
diff --git a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
index d8de9623556..6abf771277f 100644
--- a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
+++ b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
@@ -137,6 +137,7 @@ export interface PluginDevOptions {
}
interface RemoteTypeUrl {
+ alias?: string;
api: string;
zip: string;
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ef601488511..320c85c2643 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2244,6 +2244,9 @@ importers:
'@module-federation/bridge-react-webpack-plugin':
specifier: workspace:*
version: link:../bridge/bridge-react-webpack-plugin
+ '@module-federation/cli':
+ specifier: workspace:*
+ version: link:../cli
'@module-federation/data-prefetch':
specifier: workspace:*
version: link:../data-prefetch
@@ -2392,6 +2395,9 @@ importers:
'@modern-js/utils':
specifier: 2.65.1
version: 2.65.1
+ '@module-federation/cli':
+ specifier: workspace:*
+ version: link:../cli
'@module-federation/enhanced':
specifier: workspace:*
version: link:../enhanced
@@ -18715,7 +18721,7 @@ packages:
resolution: {integrity: sha512-FwTm11DP7KxQKT2mWLvwe80O5KpikgMSlqnw9CQhBaIHSYEypdJU9ZotbNsXsHdML3xcqg+S9ae3bpovC7KlwQ==}
dependencies:
'@rspack/core': 0.7.5(@swc/helpers@0.5.3)
- caniuse-lite: 1.0.30001700
+ caniuse-lite: 1.0.30001667
html-webpack-plugin: /html-rspack-plugin@5.7.2(@rspack/core@0.7.5)
postcss: 8.4.47
optionalDependencies:
@@ -20347,33 +20353,6 @@ packages:
- supports-color
dev: true
- /@semantic-release/github@11.0.0(semantic-release@24.2.3):
- resolution: {integrity: sha512-Uon6G6gJD8U1JNvPm7X0j46yxNRJ8Ui6SgK4Zw5Ktu8RgjEft3BGn+l/RX1TTzhhO3/uUcKuqM+/9/ETFxWS/Q==}
- engines: {node: '>=20.8.1'}
- peerDependencies:
- semantic-release: '>=24.1.0'
- dependencies:
- '@octokit/core': 6.1.2
- '@octokit/plugin-paginate-rest': 11.3.5(@octokit/core@6.1.2)
- '@octokit/plugin-retry': 7.1.2(@octokit/core@6.1.2)
- '@octokit/plugin-throttling': 9.3.1(@octokit/core@6.1.2)
- '@semantic-release/error': 4.0.0
- aggregate-error: 5.0.0
- debug: 4.3.7(supports-color@8.1.1)
- dir-glob: 3.0.1
- globby: 14.0.2
- http-proxy-agent: 7.0.2
- https-proxy-agent: 7.0.5
- issue-parser: 7.0.1
- lodash-es: 4.17.21
- mime: 4.0.4
- p-filter: 4.1.0
- semantic-release: 24.2.3(typescript@5.5.2)
- url-join: 5.0.0
- transitivePeerDependencies:
- - supports-color
- dev: true
-
/@semantic-release/github@11.0.1(semantic-release@24.2.3):
resolution: {integrity: sha512-Z9cr0LgU/zgucbT9cksH0/pX9zmVda9hkDPcgIE0uvjMQ8w/mElDivGjx1w1pEQ+MuQJ5CBq3VCF16S6G4VH3A==}
engines: {node: '>=20.8.1'}
@@ -26170,7 +26149,7 @@ packages:
postcss: ^8.1.0
dependencies:
browserslist: 4.24.0
- caniuse-lite: 1.0.30001700
+ caniuse-lite: 1.0.30001668
fraction.js: 4.3.7
normalize-range: 0.1.2
picocolors: 1.1.1
@@ -36305,7 +36284,7 @@ packages:
engines: {node: '>=8.0'}
dependencies:
date-format: 4.0.14
- debug: 4.3.7(supports-color@9.3.1)
+ debug: 4.3.7(supports-color@8.1.1)
flatted: 3.3.1
rfdc: 1.4.1
streamroller: 3.1.5
@@ -48706,7 +48685,7 @@ packages:
'@volar/typescript': 2.4.5
'@vue/language-core': 2.1.6(typescript@5.5.2)
compare-versions: 6.1.1
- debug: 4.3.7(supports-color@9.3.1)
+ debug: 4.3.7(supports-color@8.1.1)
kolorist: 1.8.0
local-pkg: 0.5.0
magic-string: 0.30.17
From 591aba98c0995f1bc1479f4a2d2a7ec2b581169a Mon Sep 17 00:00:00 2001
From: 2heal1
Date: Mon, 24 Mar 2025 21:22:51 +0800
Subject: [PATCH 3/3] fix: dts ut
---
packages/dts-plugin/src/core/configurations/hostPlugin.test.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts b/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts
index e23d9be0f25..c7aa232927f 100644
--- a/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts
+++ b/packages/dts-plugin/src/core/configurations/hostPlugin.test.ts
@@ -172,7 +172,7 @@ describe('hostPlugin', () => {
'remote1-alias': {
name: 'remote1',
alias: 'remote1-alias',
- url: '',
+ url: 'http://localhost:3001/remoteEntry.js',
zipUrl: 'http://localhost:3001/custom-dir/@mf-types.zip',
apiTypeUrl: 'http://localhost:3001/custom-dir/@mf-types.d.ts',
},