diff --git a/e2e/cases/javascript-api/custom-logger/index.test.ts b/e2e/cases/javascript-api/custom-logger/index.test.ts index 5cb959dae8..170ea5eb8b 100644 --- a/e2e/cases/javascript-api/custom-logger/index.test.ts +++ b/e2e/cases/javascript-api/custom-logger/index.test.ts @@ -9,7 +9,7 @@ rspackOnlyTest('should allow to customize logger', async () => { }); expect( - logs.find((item) => item.includes('[READY] Client compiled in')), + logs.find((item) => item.includes('[READY] Compiled in')), ).toBeTruthy(); restore(); diff --git a/e2e/cases/progress/index.test.ts b/e2e/cases/progress/index.test.ts index 5208b88e9e..8ac1a5780b 100644 --- a/e2e/cases/progress/index.test.ts +++ b/e2e/cases/progress/index.test.ts @@ -26,10 +26,10 @@ webpackOnlyTest('should emit progress log in non-TTY environment', async () => { }); expect( - infoMsgs.some((message) => message.includes('Client compile progress')), + infoMsgs.some((message) => message.includes('Compile progress')), ).toBeTruthy(); expect( - readyMsgs.some((message) => message.includes('Client compiled')), + readyMsgs.some((message) => message.includes('Compiled')), ).toBeTruthy(); process.stdout.isTTY = true; diff --git a/packages/compat/webpack/src/plugin.ts b/packages/compat/webpack/src/plugin.ts index ae56bda69e..f03acee8c2 100644 --- a/packages/compat/webpack/src/plugin.ts +++ b/packages/compat/webpack/src/plugin.ts @@ -6,7 +6,6 @@ import type { RspackChain, } from '@rsbuild/core'; import { type CopyPluginOptions, castArray } from '@rsbuild/shared'; -import { TARGET_ID_MAP } from './shared'; async function applyTsConfigPathsPlugin({ chain, @@ -83,7 +82,7 @@ export const pluginAdaptor = (): RsbuildPlugin => ({ const { ProgressPlugin } = await import('./progress/ProgressPlugin'); chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [ { - id: TARGET_ID_MAP[target], + id: environment, ...(progress === true ? {} : progress), }, ]); diff --git a/packages/compat/webpack/src/progress/ProgressPlugin.ts b/packages/compat/webpack/src/progress/ProgressPlugin.ts index 47ed9f2120..b6c3d03405 100644 --- a/packages/compat/webpack/src/progress/ProgressPlugin.ts +++ b/packages/compat/webpack/src/progress/ProgressPlugin.ts @@ -1,4 +1,5 @@ import { logger } from '@rsbuild/core'; +import { color } from '@rsbuild/shared'; import webpack from 'webpack'; import { prettyTime } from '../shared'; import { bus, createFriendlyPercentage } from './helpers'; @@ -81,7 +82,8 @@ export class ProgressPlugin extends webpack.ProgressPlugin { startTime = null; if (!this.hasCompileErrors) { - logger.ready(`${this.id} compiled in ${this.compileTime}`); + const suffix = this.id ? color.gray(` (${this.id})`) : ''; + logger.ready(`Compiled in ${this.compileTime} ${suffix}`); } } }); diff --git a/packages/compat/webpack/src/progress/helpers/nonTty.ts b/packages/compat/webpack/src/progress/helpers/nonTty.ts index bd7b3660c0..672fee4ab3 100644 --- a/packages/compat/webpack/src/progress/helpers/nonTty.ts +++ b/packages/compat/webpack/src/progress/helpers/nonTty.ts @@ -1,4 +1,5 @@ import { logger } from '@rsbuild/core'; +import { color } from '@rsbuild/shared'; export function createNonTTYLogger() { let prevPercentage = 0; @@ -16,6 +17,8 @@ export function createNonTTYLogger() { hasErrors: boolean; compileTime: string | null; }) => { + const suffix = color.gray(`(${id})`); + if (done) { // avoid printing done twice if (prevPercentage === 100) { @@ -24,16 +27,16 @@ export function createNonTTYLogger() { prevPercentage = 100; if (hasErrors) { - logger.error(`${id} compile failed in ${compileTime}`); + logger.error(`Compile failed in ${compileTime} ${suffix}`); } else { - logger.ready(`${id} compiled in ${compileTime}`); + logger.ready(`Compiled in ${compileTime} ${suffix}`); } } // print progress when percentage increased by more than 10% // because we don't want to spam the console else if (current - prevPercentage > 10) { prevPercentage = current; - logger.info(`${id} compile progress: ${current.toFixed(0)}%`); + logger.info(`Compile progress: ${current.toFixed(0)}% ${suffix}`); } }; diff --git a/packages/compat/webpack/src/shared.ts b/packages/compat/webpack/src/shared.ts index fd69909cf9..499111b9ca 100644 --- a/packages/compat/webpack/src/shared.ts +++ b/packages/compat/webpack/src/shared.ts @@ -13,7 +13,6 @@ const { modifyBundlerChain, onCompileDone, prettyTime, - TARGET_ID_MAP, } = __internalHelper; export { @@ -29,7 +28,6 @@ export { modifyBundlerChain, onCompileDone, prettyTime, - TARGET_ID_MAP, }; export type InternalContext = __internalHelper.InternalContext; diff --git a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap index d869ecf176..ff5a3c7f01 100644 --- a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap @@ -348,7 +348,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "dependenciesCount": 10000, "handler": [Function], "hasCompileErrors": false, - "id": "Client", + "id": "web", "modulesCount": 5000, "name": "ProgressPlugin", "percentBy": null, @@ -779,7 +779,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ "dependenciesCount": 10000, "handler": [Function], "hasCompileErrors": false, - "id": "Client", + "id": "web", "modulesCount": 5000, "name": "ProgressPlugin", "percentBy": null, @@ -1059,7 +1059,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "dependenciesCount": 10000, "handler": [Function], "hasCompileErrors": false, - "id": "Server", + "id": "node", "modulesCount": 5000, "name": "ProgressPlugin", "percentBy": null, @@ -1322,7 +1322,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "dependenciesCount": 10000, "handler": [Function], "hasCompileErrors": false, - "id": "Web Worker", + "id": "webWorker", "modulesCount": 5000, "name": "ProgressPlugin", "percentBy": null, diff --git a/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap index 31262db977..b344c86804 100644 --- a/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap @@ -96,7 +96,7 @@ exports[`webpackConfig > should allow to append and prepend plugins 1`] = ` "dependenciesCount": 10000, "handler": [Function], "hasCompileErrors": false, - "id": "Client", + "id": "web", "modulesCount": 5000, "name": "ProgressPlugin", "percentBy": null, diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index d968ea0a60..b94e0f561d 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -1,5 +1,4 @@ import { join } from 'node:path'; -import type { RsbuildTarget } from '@rsbuild/shared'; // Paths // loaders will be emitted to the same folder of the main bundle @@ -53,9 +52,3 @@ export const IMAGE_EXTENSIONS = [ ]; export const VIDEO_EXTENSIONS = ['mp4', 'webm', 'ogg', 'mov']; export const AUDIO_EXTENSIONS = ['mp3', 'wav', 'flac', 'aac', 'm4a', 'opus']; - -export const TARGET_ID_MAP: Record = { - web: 'Client', - node: 'Server', - 'web-worker': 'Web Worker', -}; diff --git a/packages/core/src/internal.ts b/packages/core/src/internal.ts index d556b73ba7..1b95ab8b81 100644 --- a/packages/core/src/internal.ts +++ b/packages/core/src/internal.ts @@ -24,4 +24,3 @@ export { applySwcDecoratorConfig } from './plugins/swc'; export { getSwcMinimizerOptions } from './plugins/minimize'; export { getDevMiddleware } from './server/devMiddleware'; export { createDevServer } from './server/devServer'; -export { TARGET_ID_MAP } from './constants'; diff --git a/packages/core/src/plugins/progress.ts b/packages/core/src/plugins/progress.ts index 1b4d9a9688..d2db06235a 100644 --- a/packages/core/src/plugins/progress.ts +++ b/packages/core/src/plugins/progress.ts @@ -1,5 +1,4 @@ import { rspack } from '@rspack/core'; -import { TARGET_ID_MAP } from '../constants'; import { isProd } from '../helpers'; import type { RsbuildPlugin } from '../types'; @@ -12,7 +11,7 @@ export const pluginProgress = (): RsbuildPlugin => ({ return; } - api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => { + api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => { const config = api.getNormalizedConfig(); const options = config.dev.progressBar ?? @@ -24,9 +23,7 @@ export const pluginProgress = (): RsbuildPlugin => ({ } const prefix = - options !== true && options.id !== undefined - ? options.id - : TARGET_ID_MAP[target]; + options !== true && options.id !== undefined ? options.id : environment; chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(rspack.ProgressPlugin, [ { diff --git a/packages/core/src/provider/createCompiler.ts b/packages/core/src/provider/createCompiler.ts index a650635f78..fcbd727304 100644 --- a/packages/core/src/provider/createCompiler.ts +++ b/packages/core/src/provider/createCompiler.ts @@ -7,7 +7,6 @@ import { } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; import type { StatsCompilation } from '@rspack/core'; -import { TARGET_ID_MAP } from '../constants'; import { formatStats, getStatsOptions, @@ -72,7 +71,7 @@ export async function createCompiler({ } const done = async (stats: Stats | MultiStats) => { - const obj = stats.toJson({ + const statsJson = stats.toJson({ all: false, timings: true, }); @@ -80,19 +79,19 @@ export async function createCompiler({ const printTime = (c: StatsCompilation, index: number) => { if (c.time) { const time = prettyTime(c.time / 1000); - const target = context.targets[index]; - const name = TARGET_ID_MAP[target || 'web']; - logger.ready(`${name} compiled in ${time}`); + const { name } = rspackConfigs[index]; + const suffix = name ? color.gray(` (${name})`) : ''; + logger.ready(`Compiled in ${time}${suffix}`); } }; if (!stats.hasErrors()) { - if (obj.children) { - obj.children.forEach((c, index) => { + if (statsJson.children) { + statsJson.children.forEach((c, index) => { printTime(c, index); }); } else { - printTime(obj, 0); + printTime(statsJson, 0); } } diff --git a/packages/core/tests/__snapshots__/default.test.ts.snap b/packages/core/tests/__snapshots__/default.test.ts.snap index b78448f6e7..ebf7c2310a 100644 --- a/packages/core/tests/__snapshots__/default.test.ts.snap +++ b/packages/core/tests/__snapshots__/default.test.ts.snap @@ -931,7 +931,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, ProgressPlugin { "_options": { - "prefix": "Client", + "prefix": "web", "profile": false, "progressChars": "━━", "template": "● {prefix:.bold} {bar:25.green/white.dim} ({percent}%) {wide_msg:.dim}",