Skip to content

Commit 8e4789f

Browse files
authored
Merge pull request #3127 from DouyinFE/solve/issue-3116-1770017038039
【Auto】fix(semi-webpack/semi-rspack): 正则支持匹配 `@douyinfe/semi-ui-19` 等带数字后缀包名
2 parents 80e9b66 + 72ccff0 commit 8e4789f

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

packages/semi-rspack/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The plugin is designed for Semi Design, support rspack, provides two major abili
55
- Custom theme
66
- Replace prefix of CSS selector
77

8+
> Note: The plugin detects Semi related dependencies by package path. It supports both
9+
> `@douyinfe/semi-ui` and version-suffixed packages like `@douyinfe/semi-ui-19` (also for `semi-icons`).
10+
811
## Usage
912

1013
### Install

packages/semi-rspack/src/rule.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { stringifyVariableRecord } from './utils';
55

66
export function createSourceSuffixLoaderRule(_opts?: SemiWebpackPluginOptions) {
77
return {
8-
test: /@douyinfe(\/|\\)+semi-(ui|icons)(\/|\\)+.+\.js$/,
8+
// Support packages like @douyinfe/semi-ui-19, @douyinfe/semi-icons-19
9+
test: /@douyinfe(\/|\\)+semi-(ui|icons)(-\d+)?(\/|\\)+.+\.js$/,
910
use: [{ loader: SOURCE_SUFFIX_LOADER }],
1011
};
1112
}
@@ -27,7 +28,8 @@ export function createThemeLoaderRule(opts?: SemiWebpackPluginOptions) {
2728
cssLayer: opts.cssLayer
2829
};
2930
const loaderInfo = {
30-
test: /@douyinfe(\/|\\)+semi-(ui|icons|foundation)(\/|\\)+lib(\/|\\)+.+\.scss$/,
31+
// Support packages like @douyinfe/semi-ui-19, @douyinfe/semi-foundation-19
32+
test: /@douyinfe(\/|\\)+semi-(ui|icons|foundation)(-\d+)?(\/|\\)+lib(\/|\\)+.+\.scss$/,
3133
use: [{ loader: THEME_LOADER, options }],
3234
};
3335
let commonLoader: any[] = [
@@ -101,4 +103,4 @@ export function applySemiRules(opts?: SemiWebpackPluginOptions) {
101103
rules.push(createWebComponentLoaderRule(opts));
102104
}
103105
return rules;
104-
}
106+
}

packages/semi-webpack/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The plugin is designed for Semi Design, support webpack4 and webpack5, provides
55
- Custom theme
66
- Replace prefix of CSS selector
77

8+
> Note: The plugin detects Semi related dependencies by package path. It supports both
9+
> `@douyinfe/semi-ui` and version-suffixed packages like `@douyinfe/semi-ui-19` (also for `semi-icons`).
10+
811
## Usage
912

1013
### Install
@@ -166,4 +169,4 @@ Type: `(loaderList:any[])=>any[]`
166169
You can customize how webpack process semi related styles by override the loader with this option. The function will receive the loader list of default loaders(include options.extractCssOptions) and you should return your new loader list. The best practice is just only add your loader to the list rather than delete or change the default loaders since some core logic is in there.
167170

168171

169-
In webpack@5, some hooks need to be obtained through api `NormalModule.getCompilationHooks`. But in some scenarios, webpack will not be installed, such as Next.js. Therefore, the user is required to pass in NormalModule as a parameter.
172+
In webpack@5, some hooks need to be obtained through api `NormalModule.getCompilationHooks`. But in some scenarios, webpack will not be installed, such as Next.js. Therefore, the user is required to pass in NormalModule as a parameter.

packages/semi-webpack/src/semi-webpack-plugin.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export interface SemiThemeOptions {
2929
name?: string
3030
}
3131

32+
// Support packages like @douyinfe/semi-ui-19, @douyinfe/semi-icons-19
33+
// Only allow numeric suffix to avoid over-matching non-Semi packages.
34+
const SEMI_LIB_JS_RE = /@douyinfe\/semi-(ui|icons)(-\d+)?\/lib\/.+\.js$/;
35+
const SEMI_LIB_SCSS_RE = /@douyinfe\/semi-(ui|icons|foundation)(-\d+)?\/lib\/.+\.scss$/;
36+
3237
export default class SemiWebpackPlugin {
3338

3439
options: SemiWebpackPluginOptions;
@@ -92,7 +97,7 @@ export default class SemiWebpackPlugin {
9297

9398
omitCss(module: any) {
9499
const compatiblePath = transformPath(module.resource);
95-
if (/@douyinfe\/semi-(ui|icons)\/lib\/.+\.js$/.test(compatiblePath)) {
100+
if (SEMI_LIB_JS_RE.test(compatiblePath)) {
96101
module.loaders = module.loaders || [];
97102
module.loaders.push({
98103
loader: path.join(__dirname, 'semi-omit-css-loader')
@@ -102,13 +107,13 @@ export default class SemiWebpackPlugin {
102107

103108
customTheme(module: any) {
104109
const compatiblePath = transformPath(module.resource);
105-
if (/@douyinfe\/semi-(ui|icons)\/lib\/.+\.js$/.test(compatiblePath)) {
110+
if (SEMI_LIB_JS_RE.test(compatiblePath)) {
106111
module.loaders = module.loaders || [];
107112
module.loaders.push({
108113
loader: path.join(__dirname, 'semi-source-suffix-loader')
109114
});
110115
}
111-
if (/@douyinfe\/semi-(ui|icons|foundation)\/lib\/.+\.scss$/.test(compatiblePath)) {
116+
if (SEMI_LIB_SCSS_RE.test(compatiblePath)) {
112117
const scssLoader = require.resolve('sass-loader');
113118
const cssLoader = require.resolve('css-loader');
114119
const styleLoader = require.resolve('style-loader');
@@ -199,4 +204,3 @@ export default class SemiWebpackPlugin {
199204
}, '');
200205
}
201206
}
202-

0 commit comments

Comments
 (0)