Skip to content

Commit

Permalink
chore: remove rspack-chain temporary code (#4460)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 30, 2025
1 parent 7b80999 commit 9606c8e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 66 deletions.
2 changes: 1 addition & 1 deletion packages/compat/webpack/src/webpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function generateWebpackConfig({

const chain = await modifyWebpackChain(context, chainUtils, bundlerChain);

let webpackConfig = helpers.chainToConfig(chain) as WebpackConfig;
let webpackConfig = chain.toConfig() as WebpackConfig;

const configUtils = (await helpers.getConfigUtils(
webpackConfig as Rspack.Configuration,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"reduce-configs": "^1.1.0",
"rsbuild-dev-middleware": "0.1.2",
"rslog": "^1.2.3",
"rspack-chain": "^1.2.0",
"rspack-chain": "^1.2.1",
"rspack-manifest-plugin": "5.0.3",
"sirv": "^3.0.0",
"style-loader": "3.3.4",
Expand Down
58 changes: 2 additions & 56 deletions packages/core/src/configChain.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import RspackChain from '../compiled/rspack-chain/index.js';
import { castArray, isPlainObject } from './helpers';
import { castArray } from './helpers';
import { logger } from './logger';
import type {
InternalContext,
ModifyBundlerChainUtils,
RsbuildEntry,
Rspack,
} from './types';
import type { InternalContext, ModifyBundlerChainUtils } from './types';

export function getBundlerChain(): RspackChain {
const bundlerChain = new RspackChain();
Expand Down Expand Up @@ -39,55 +34,6 @@ export async function modifyBundlerChain(
return modifiedBundlerChain;
}

export function chainToConfig(chain: RspackChain): Rspack.Configuration {
const config = chain.toConfig();
const { entry } = config;

if (!isPlainObject(entry)) {
return config as Rspack.Configuration;
}

const formattedEntry: RsbuildEntry = {};

/**
* rspack-chain can not handle entry description object correctly,
* so we need to format the entry object and correct the entry description object.
*/
for (const [entryName, entryValue] of Object.entries(entry)) {
const entryImport: string[] = [];
let entryDescription: Rspack.EntryDescription | null = null;

for (const item of castArray(entryValue)) {
if (typeof item === 'string') {
entryImport.push(item);
continue;
}

if (item.import) {
entryImport.push(...castArray(item.import));
}

if (entryDescription) {
// merge entry description object
Object.assign(entryDescription, item);
} else {
entryDescription = item;
}
}

formattedEntry[entryName] = entryDescription
? {
...entryDescription,
import: entryImport,
}
: entryImport;
}

config.entry = formattedEntry;

return config as Rspack.Configuration;
}

export const CHAIN_ID = {
/** Predefined rules */
RULE: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/provider/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export { getHTMLPlugin } from '../pluginHelper';
export { formatStats, getStatsOptions, prettyTime } from '../helpers';
export { registerBuildHook, registerDevHook } from '../hooks';
export { getChainUtils, getConfigUtils } from './rspackConfig';
export { chainToConfig, modifyBundlerChain } from '../configChain';
export { modifyBundlerChain } from '../configChain';
export { createDevServer } from '../server/devServer';
4 changes: 2 additions & 2 deletions packages/core/src/provider/rspackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rspack } from '@rspack/core';
import { reduceConfigsAsyncWithContext } from 'reduce-configs';
import { CHAIN_ID, chainToConfig, modifyBundlerChain } from '../configChain';
import { CHAIN_ID, modifyBundlerChain } from '../configChain';
import { castArray, color, getNodeEnv } from '../helpers';
import { logger } from '../logger';
import { getHTMLPlugin } from '../pluginHelper';
Expand Down Expand Up @@ -179,7 +179,7 @@ export async function generateRspackConfig({
},
});

let rspackConfig = chainToConfig(chain);
let rspackConfig = chain.toConfig();

rspackConfig = await modifyRspackConfig(
context,
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9606c8e

Please sign in to comment.