Skip to content

Commit 6122b1e

Browse files
committed
chore: update
1 parent a8747f1 commit 6122b1e

File tree

6 files changed

+27
-49
lines changed

6 files changed

+27
-49
lines changed

packages/core/src/cli/build.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { type RsbuildInstance, createRsbuild } from '@rsbuild/core';
22
import { composeRsbuildEnvironments, pruneEnvironments } from '../config';
33
import type { RslibConfig } from '../types/config';
4-
import { getAbsolutePath } from '../utils/helper';
54
import type { BuildOptions } from './commands';
65

76
export async function build(
87
config: RslibConfig,
9-
options: Pick<BuildOptions, 'root' | 'lib' | 'watch'> = {},
8+
options: Pick<BuildOptions, 'lib' | 'watch'> = {},
109
): Promise<RsbuildInstance> {
11-
const cwd = process.cwd();
12-
const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
13-
14-
const environments = await composeRsbuildEnvironments(config, root);
10+
const environments = await composeRsbuildEnvironments(config);
1511
const rsbuildInstance = await createRsbuild({
1612
rsbuildConfig: {
1713
environments: pruneEnvironments(environments, options.lib),

packages/core/src/cli/commands.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { RsbuildMode } from '@rsbuild/core';
22
import { type Command, program } from 'commander';
33
import { logger } from '../utils/logger';
44
import { build } from './build';
5-
import { getRslibConfig } from './init';
5+
import { loadRslibConfig } from './init';
66
import { inspect } from './inspect';
77
import { startMFDevServer } from './mf';
88

@@ -62,9 +62,8 @@ export function runCli(): void {
6262
.description('build the library for production')
6363
.action(async (options: BuildOptions) => {
6464
try {
65-
const { root, rslibConfig } = await getRslibConfig(options);
65+
const rslibConfig = await loadRslibConfig(options);
6666
await build(rslibConfig, {
67-
root,
6867
lib: options.lib,
6968
watch: options.watch,
7069
});
@@ -91,9 +90,8 @@ export function runCli(): void {
9190
.action(async (options: InspectOptions) => {
9291
try {
9392
// TODO: inspect should output Rslib's config
94-
const { root, rslibConfig } = await getRslibConfig(options);
93+
const rslibConfig = await loadRslibConfig(options);
9594
await inspect(rslibConfig, {
96-
root,
9795
lib: options.lib,
9896
mode: options.mode,
9997
output: options.output,
@@ -110,11 +108,9 @@ export function runCli(): void {
110108
.description('start Rsbuild dev server of Module Federation format')
111109
.action(async (options: CommonOptions) => {
112110
try {
113-
const { root, rslibConfig } = await getRslibConfig(options);
111+
const rslibConfig = await loadRslibConfig(options);
114112
// TODO: support lib option in mf dev server
115-
await startMFDevServer(rslibConfig, {
116-
root,
117-
});
113+
await startMFDevServer(rslibConfig);
118114
} catch (err) {
119115
logger.error('Failed to start mf dev.');
120116
logger.error(err);

packages/core/src/cli/init.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { RslibConfig } from '../types';
33
import { getAbsolutePath } from '../utils/helper';
44
import type { CommonOptions } from './commands';
55

6-
export async function getRslibConfig(
6+
export async function loadRslibConfig(
77
options: CommonOptions,
8-
): Promise<{ root: string; rslibConfig: RslibConfig }> {
8+
): Promise<RslibConfig> {
99
const cwd = process.cwd();
1010
const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
1111

@@ -15,5 +15,5 @@ export async function getRslibConfig(
1515
envMode: options.envMode,
1616
});
1717

18-
return { root, rslibConfig };
18+
return rslibConfig;
1919
}

packages/core/src/cli/inspect.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import { type RsbuildInstance, createRsbuild } from '@rsbuild/core';
22
import { composeRsbuildEnvironments, pruneEnvironments } from '../config';
33
import type { RslibConfig } from '../types/config';
4-
import { getAbsolutePath } from '../utils/helper';
54
import type { InspectOptions } from './commands';
65

76
export async function inspect(
87
config: RslibConfig,
9-
options: Pick<
10-
InspectOptions,
11-
'root' | 'lib' | 'mode' | 'output' | 'verbose'
12-
> = {},
8+
options: Pick<InspectOptions, 'lib' | 'mode' | 'output' | 'verbose'> = {},
139
): Promise<RsbuildInstance> {
14-
const cwd = process.cwd();
15-
const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
16-
17-
const environments = await composeRsbuildEnvironments(config, root);
10+
const environments = await composeRsbuildEnvironments(config);
1811
const rsbuildInstance = await createRsbuild({
1912
rsbuildConfig: {
2013
environments: pruneEnvironments(environments, options.lib),

packages/core/src/cli/mf.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,18 @@ import { createRsbuild, mergeRsbuildConfig } from '@rsbuild/core';
22
import type { RsbuildConfig, RsbuildInstance } from '@rsbuild/core';
33
import { composeCreateRsbuildConfig } from '../config';
44
import type { RslibConfig } from '../types';
5-
import { getAbsolutePath } from '../utils/helper';
6-
import type { CommonOptions } from './commands';
75

86
export async function startMFDevServer(
97
config: RslibConfig,
10-
options: Pick<CommonOptions, 'root'> = {},
118
): Promise<RsbuildInstance | undefined> {
12-
const cwd = process.cwd();
13-
const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
14-
const rsbuildInstance = await initMFRsbuild(config, root);
9+
const rsbuildInstance = await initMFRsbuild(config);
1510
return rsbuildInstance;
1611
}
1712

1813
async function initMFRsbuild(
1914
rslibConfig: RslibConfig,
20-
root: string,
2115
): Promise<RsbuildInstance | undefined> {
22-
const rsbuildConfigObject = await composeCreateRsbuildConfig(
23-
rslibConfig,
24-
root,
25-
);
16+
const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig);
2617
const mfRsbuildConfig = rsbuildConfigObject.find(
2718
(config) => config.format === 'mf',
2819
);

packages/core/src/config.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
calcLongestCommonPath,
5454
checkMFPlugin,
5555
color,
56+
getAbsolutePath,
5657
isEmptyObject,
5758
isObject,
5859
nodeBuiltInModules,
@@ -1084,11 +1085,16 @@ const composeExternalHelpersConfig = (
10841085
return defaultConfig;
10851086
};
10861087

1087-
async function composeLibRsbuildConfig(config: LibConfig, root: string) {
1088+
async function composeLibRsbuildConfig(config: LibConfig) {
10881089
checkMFPlugin(config);
1089-
const pkgJson = readPackageJson(root);
1090+
1091+
// Get the absolute path of the root directory to align with Rsbuild's default behavior
1092+
const rootPath = config.root
1093+
? getAbsolutePath(process.cwd(), config.root)
1094+
: process.cwd();
1095+
const pkgJson = readPackageJson(rootPath);
10901096
const { compilerOptions } = await loadTsconfig(
1091-
root,
1097+
rootPath,
10921098
config.source?.tsconfigPath,
10931099
);
10941100
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
@@ -1147,7 +1153,7 @@ async function composeLibRsbuildConfig(config: LibConfig, root: string) {
11471153
const { entryConfig, lcp } = await composeEntryConfig(
11481154
config.source?.entry,
11491155
config.bundle,
1150-
root,
1156+
rootPath,
11511157
cssModulesAuto,
11521158
);
11531159
const cssConfig = composeCssConfig(lcp, config.bundle);
@@ -1191,7 +1197,6 @@ async function composeLibRsbuildConfig(config: LibConfig, root: string) {
11911197

11921198
export async function composeCreateRsbuildConfig(
11931199
rslibConfig: RslibConfig,
1194-
root: string,
11951200
): Promise<RsbuildConfigWithLibInfo[]> {
11961201
const constantRsbuildConfig = await createConstantRsbuildConfig();
11971202
const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
@@ -1210,7 +1215,7 @@ export async function composeCreateRsbuildConfig(
12101215

12111216
// Merge the configuration of each environment based on the shared Rsbuild
12121217
// configuration and Lib configuration in the settings.
1213-
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, root);
1218+
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig);
12141219

12151220
// Reset certain fields because they will be completely overridden by the upcoming merge.
12161221
// We don't want to retain them in the final configuration.
@@ -1266,12 +1271,9 @@ export async function composeCreateRsbuildConfig(
12661271

12671272
export async function composeRsbuildEnvironments(
12681273
rslibConfig: RslibConfig,
1269-
root: string,
12701274
): Promise<Record<string, EnvironmentConfig>> {
1271-
const rsbuildConfigWithLibInfo = await composeCreateRsbuildConfig(
1272-
rslibConfig,
1273-
root,
1274-
);
1275+
const rsbuildConfigWithLibInfo =
1276+
await composeCreateRsbuildConfig(rslibConfig);
12751277

12761278
// User provided ids should take precedence over generated ids.
12771279
const usedIds = rsbuildConfigWithLibInfo

0 commit comments

Comments
 (0)