Skip to content

Commit

Permalink
feat: update rsbuild version (#5848)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: gaoyuan.1226 <[email protected]>
  • Loading branch information
3 people authored Jun 19, 2024
1 parent bf1d59f commit c4018c2
Show file tree
Hide file tree
Showing 32 changed files with 603 additions and 572 deletions.
2 changes: 1 addition & 1 deletion packages/cli/plugin-bff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@swc/helpers": "0.5.3"
},
"devDependencies": {
"@rsbuild/shared": "0.7.8",
"@rsbuild/shared": "0.7.9",
"@modern-js/runtime": "workspace:*",
"@modern-js/core": "workspace:*",
"@modern-js/bff-runtime": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/plugin-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"test": "jest"
},
"dependencies": {
"@rsbuild/core": "0.7.8",
"@rsbuild/plugin-swc": "0.7.8",
"@rsbuild/core": "0.7.9",
"@rsbuild/plugin-swc": "0.7.9",
"@modern-js/utils": "workspace:*",
"@swc/helpers": "0.5.3"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/rsbuild-plugin-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
},
"dependencies": {
"@swc/helpers": "0.5.3",
"@rsbuild/shared": "0.7.8",
"@rsbuild/shared": "0.7.9",
"esbuild": "0.17.19",
"webpack": "^5.92.0"
},
"devDependencies": {
"@scripts/build": "workspace:*",
"@rsbuild/core": "0.7.8",
"@rsbuild/webpack": "0.7.8",
"@rsbuild/core": "0.7.9",
"@rsbuild/webpack": "0.7.9",
"typescript": "^5.4.2"
},
"publishConfig": {
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/rsbuild-plugin-esbuild/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from 'path';
import { JS_REGEX, TS_REGEX, applyScriptCondition } from '@rsbuild/shared';
import { JS_REGEX, applyScriptCondition } from '@rsbuild/shared';
import type { RsbuildPlugin } from '@rsbuild/core';
import type {
LoaderOptions,
MinifyPluginOptions,
} from '../compiled/esbuild-loader';

const TS_REGEX = /\.(?:ts|mts|cts|tsx)$/;

export interface PluginEsbuildOptions {
loader?: false | LoaderOptions;
minimize?: false | MinifyPluginOptions;
Expand Down Expand Up @@ -50,7 +52,7 @@ export function pluginEsbuild(
chain.module
.rule(CHAIN_ID.RULE.JS)
.test(JS_REGEX)
.use(CHAIN_ID.USE.ESBUILD)
.use('esbuild')
.loader(esbuildLoaderPath)
.options({
loader: 'jsx',
Expand All @@ -60,7 +62,7 @@ export function pluginEsbuild(
const rule = chain.module.rule(CHAIN_ID.RULE.TS);
rule
.test(TS_REGEX)
.use(CHAIN_ID.USE.ESBUILD)
.use('esbuild')
.loader(esbuildLoaderPath)
.options({
loader: 'tsx',
Expand All @@ -87,7 +89,7 @@ export function pluginEsbuild(
.delete(CHAIN_ID.MINIMIZER.CSS);

chain.optimization
.minimizer(CHAIN_ID.MINIMIZER.ESBUILD)
.minimizer('js-css')
.use(ESBuildMinifyPlugin)
.init(
() =>
Expand Down
42 changes: 21 additions & 21 deletions packages/cli/uni-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@
"@modern-js/server": "workspace:*",
"@modern-js/prod-server": "workspace:*",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@rsbuild/babel-preset": "0.7.8",
"@rsbuild/core": "0.7.8",
"@rsbuild/plugin-sass": "0.7.8",
"@rsbuild/plugin-less": "0.7.8",
"@rsbuild/plugin-assets-retry": "0.7.8",
"@rsbuild/plugin-babel": "0.7.8",
"@rsbuild/plugin-check-syntax": "0.7.8",
"@rsbuild/plugin-css-minimizer": "0.7.8",
"@rsbuild/plugin-pug": "0.7.8",
"@rsbuild/plugin-react": "0.7.8",
"@rsbuild/plugin-rem": "0.7.8",
"@rsbuild/plugin-source-build": "0.7.8",
"@rsbuild/plugin-styled-components": "0.7.8",
"@rsbuild/plugin-svgr": "0.7.8",
"@rsbuild/plugin-type-check": "0.7.8",
"@rsbuild/plugin-typed-css-modules": "0.7.8",
"@rsbuild/plugin-toml": "0.7.8",
"@rsbuild/plugin-yaml": "0.7.8",
"@rsbuild/shared": "0.7.8",
"@rsbuild/webpack": "0.7.8",
"@rsbuild/babel-preset": "0.7.9",
"@rsbuild/core": "0.7.9",
"@rsbuild/plugin-sass": "0.7.9",
"@rsbuild/plugin-less": "0.7.9",
"@rsbuild/plugin-assets-retry": "0.7.9",
"@rsbuild/plugin-babel": "0.7.9",
"@rsbuild/plugin-check-syntax": "0.7.9",
"@rsbuild/plugin-css-minimizer": "0.7.9",
"@rsbuild/plugin-pug": "0.7.9",
"@rsbuild/plugin-react": "0.7.9",
"@rsbuild/plugin-rem": "0.7.9",
"@rsbuild/plugin-source-build": "0.7.9",
"@rsbuild/plugin-styled-components": "0.7.9",
"@rsbuild/plugin-svgr": "0.7.9",
"@rsbuild/plugin-type-check": "0.7.9",
"@rsbuild/plugin-typed-css-modules": "0.7.9",
"@rsbuild/plugin-toml": "0.7.9",
"@rsbuild/plugin-yaml": "0.7.9",
"@rsbuild/shared": "0.7.9",
"@rsbuild/webpack": "0.7.9",
"@swc/helpers": "0.5.3",
"babel-loader": "9.1.3",
"babel-plugin-import": "1.13.5",
Expand All @@ -80,7 +80,7 @@
"webpack-subresource-integrity": "5.1.0"
},
"devDependencies": {
"@rsbuild/plugin-swc": "0.7.8",
"@rsbuild/plugin-swc": "0.7.9",
"@scripts/build": "workspace:*",
"@scripts/vitest-config": "workspace:*",
"@types/lodash": "^4.14.202",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/uni-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ export {
type RsbuildConfig,
} from '@rsbuild/core';
export type { webpack, WebpackConfig } from '@rsbuild/webpack';
export { RUNTIME_CHUNK_NAME } from './shared/constants';
export { RUNTIME_CHUNK_NAME } from './shared/utils';
3 changes: 1 addition & 2 deletions packages/cli/uni-builder/src/shared/compatLegacyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type {
UniBuilderPluginAPI,
UniBuilderContext,
} from '../types';
import type { RsbuildPlugin } from '@rsbuild/core';
import { logger } from '@rsbuild/shared';
import { type RsbuildPlugin, logger } from '@rsbuild/core';
import { join } from 'path';

function addDeprecatedWarning(
Expand Down
1 change: 0 additions & 1 deletion packages/cli/uni-builder/src/shared/constants.ts

This file was deleted.

9 changes: 4 additions & 5 deletions packages/cli/uni-builder/src/shared/devServer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
StartDevServerOptions as RsbuildStartDevServerOptions,
debug,
deepmerge,
DevConfig,
ServerConfig,
isProd,
} from '@rsbuild/shared';
import { applyOptionsChain } from '@modern-js/utils';

import type { RsbuildInstance } from '@rsbuild/core';
import { type RsbuildInstance, logger } from '@rsbuild/core';

import type { ModernDevServerOptions } from '@modern-js/server';
import type { Server } from 'node:http';
Expand Down Expand Up @@ -158,7 +157,7 @@ export async function startDevServer(
options: StartDevServerOptions = {},
builderConfig: UniBuilderConfig,
) {
debug('create dev server');
logger.debug('create dev server');

if (!options.initProdMiddlewares) {
options.initProdMiddlewares = initProdMiddlewares;
Expand Down Expand Up @@ -209,7 +208,7 @@ export async function startDevServer(
options.initProdMiddlewares,
);

debug('listen dev server');
logger.debug('listen dev server');

return new Promise<UniBuilderStartServerResult>(resolve => {
server.listen(
Expand All @@ -222,7 +221,7 @@ export async function startDevServer(
throw err;
}

debug('listen dev server done');
logger.debug('listen dev server done');

await rsbuildServer.afterListen();

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/uni-builder/src/shared/plugins/antd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isServerTarget, type RsbuildPlugin } from '@rsbuild/shared';
import { type RsbuildPlugin } from '@rsbuild/shared';
import { isServerTarget } from '../utils';

const getAntdMajorVersion = (appDirectory: string) => {
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/uni-builder/src/shared/plugins/arco.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isServerTarget, type RsbuildPlugin } from '@rsbuild/shared';
import { type RsbuildPlugin } from '@rsbuild/shared';
import { isPackageInstalled } from '@modern-js/utils';
import { isServerTarget } from '../../shared/utils';

export const pluginArco = (): RsbuildPlugin => ({
name: 'uni-builder:arco',
Expand Down
28 changes: 13 additions & 15 deletions packages/cli/uni-builder/src/shared/plugins/fallback.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { join } from 'path';
import {
JS_REGEX,
TS_REGEX,
getDistPath,
getFilename,
type Rspack,
} from '@rsbuild/shared';
import { JS_REGEX, type Rspack } from '@rsbuild/shared';
import type { RsbuildPlugin } from '@rsbuild/core';
import { TS_REGEX, getHash } from '../../shared/utils';

const HTML_REGEX = /\.html$/;

Expand Down Expand Up @@ -70,13 +65,15 @@ export const pluginFallback = (): RsbuildPlugin => ({

setup(api) {
if (api.context.bundlerType === 'webpack') {
api.modifyBundlerChain((chain, { isProd }) => {
api.modifyBundlerChain(chain => {
const rsbuildConfig = api.getNormalizedConfig();
const distDir = getDistPath(rsbuildConfig, 'media');
const filename = getFilename(rsbuildConfig, 'media', isProd);
const { distPath, filename } = rsbuildConfig.output;
const distDir = distPath.media;
const mediaFilename =
filename.media ?? `[name]${getHash(rsbuildConfig)}[ext]`;

chain.output.merge({
assetModuleFilename: join(distDir, filename),
assetModuleFilename: join(distDir, mediaFilename),
});
});

Expand All @@ -89,11 +86,12 @@ export const pluginFallback = (): RsbuildPlugin => ({
config.module.rules = resourceRuleFallback(config.module.rules);
});
} else {
api.modifyRspackConfig((config, { isProd }) => {
api.modifyRspackConfig(config => {
const rsbuildConfig = api.getNormalizedConfig();

const distDir = getDistPath(rsbuildConfig, 'media');
const filename = getFilename(rsbuildConfig, 'media', isProd);
const distDir = rsbuildConfig.output.distPath.media;
const filename =
rsbuildConfig.output.filename.media ??
`[name]${getHash(rsbuildConfig)}[ext]`;

config.output ||= {};
config.output.assetModuleFilename = join(distDir, filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import { RUNTIME_CHUNK_NAME } from '../constants';
import { RUNTIME_CHUNK_NAME } from '../utils';

export const pluginRuntimeChunk = (
disableInlineRuntimeChunk?: boolean,
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/uni-builder/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { RsbuildTarget, NormalizedConfig } from '@rsbuild/core';

export const RUNTIME_CHUNK_NAME = 'builder-runtime';

export const TS_REGEX = /\.(?:ts|mts|cts|tsx)$/;

export function isServerTarget(target: RsbuildTarget[]) {
return (Array.isArray(target) ? target : [target]).some(item =>
['node', 'service-worker'].includes(item),
);
}

export const getHash = (config: NormalizedConfig) => {
const { filenameHash } = config.output;

if (typeof filenameHash === 'string') {
return filenameHash ? `.[${filenameHash}]` : '';
}
return filenameHash ? '.[contenthash:8]' : '';
};
3 changes: 2 additions & 1 deletion packages/cli/uni-builder/src/webpack/ModuleScopePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* modified from https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/ModuleScopePlugin.js
*/
import { dirname, relative, resolve } from 'path';
import { color, isRegExp, isString } from '@rsbuild/shared';
import { color } from '@rsbuild/shared';
import { isRegExp, isString } from '@modern-js/utils';

export class ModuleScopePlugin {
scopes: Array<string | RegExp>;
Expand Down
16 changes: 7 additions & 9 deletions packages/cli/uni-builder/src/webpack/plugins/moduleScopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const pluginModuleScopes = (
name: 'uni-builder:module-scopes',

setup(api) {
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
api.modifyBundlerChain(async chain => {
if (!moduleScopes) {
return;
}
Expand All @@ -55,14 +55,12 @@ export const pluginModuleScopes = (
return scope;
});

chain.resolve
.plugin(CHAIN_ID.RESOLVE_PLUGIN.MODULE_SCOPE)
.use(ModuleScopePlugin, [
{
scopes: formattedScopes,
allowedFiles: [rootPackageJson],
},
]);
chain.resolve.plugin('module-scope').use(ModuleScopePlugin, [
{
scopes: formattedScopes,
allowedFiles: [rootPackageJson],
},
]);
});
},
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import { PLUGIN_SWC_NAME } from '@rsbuild/core';
import { isServerTarget, type ConfigChain } from '@rsbuild/shared';
import { type ConfigChain } from '@rsbuild/shared';
import { applyOptionsChain } from '@modern-js/utils';
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
import { isServerTarget } from '../../shared/utils';

const getDefaultStyledComponentsConfig = (isProd: boolean, ssr: boolean) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/uni-builder/src/webpack/plugins/tsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
TS_REGEX,
JS_REGEX,
castArray,
applyScriptCondition,
Expand All @@ -17,6 +16,7 @@ import { getBabelConfigForWeb } from '@rsbuild/babel-preset/web';
import type { RsbuildPlugin } from '@rsbuild/core';
import type { Options as RawTSLoaderOptions } from 'ts-loader';
import { getPresetReact } from './babel';
import { TS_REGEX } from '../../shared/utils';

export type TSLoaderOptions = Partial<RawTSLoaderOptions>;

Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/themes": "^3.0.5",
"@scripts/jest-config": "workspace:*",
"@rsbuild/core": "0.7.8",
"@rsbuild/core": "0.7.9",
"@types/jest": "^29",
"@types/lodash": "^4.14.202",
"@types/node": "~16.11.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@types/ws": "^8.5.5",
"type-fest": "^4.1.0",
"typescript": "^5",
"@rsbuild/core": "0.7.8"
"@rsbuild/core": "0.7.9"
},
"peerDependencies": {
"@modern-js/runtime": "workspace:^2.53.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/review/eslint-config-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/eslint-plugin": "^7.22.10",
"@rsbuild/babel-preset": "0.7.8",
"@rsbuild/core": "0.7.8",
"@rsbuild/babel-preset": "0.7.9",
"@rsbuild/core": "0.7.9",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.28.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/plugin-garfish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"react-dom": ">=17"
},
"devDependencies": {
"@rsbuild/shared": "0.7.8",
"@rsbuild/shared": "0.7.9",
"@modern-js/app-tools": "workspace:*",
"@modern-js/core": "workspace:*",
"@modern-js/plugin-router-v5": "workspace:*",
Expand Down
Loading

0 comments on commit c4018c2

Please sign in to comment.