Skip to content

Commit 0f735b3

Browse files
authored
chore: avoid using constructor.name (#4336)
1 parent 1463c99 commit 0f735b3

30 files changed

+309
-110
lines changed

packages/compat/plugin-webpack-swc/tests/__snapshots__/plugin.test.ts.snap

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ exports[`plugin-webpack-swc > output.sourceMap config for swcMinimizerPlugin 1`]
145145
],
146146
},
147147
"plugins": [
148-
RsbuildCorePlugin {},
148+
{
149+
"name": "RsbuildCorePlugin",
150+
},
149151
],
150152
},
151153
]
@@ -265,7 +267,9 @@ exports[`plugin-webpack-swc > should apply multiple environment configs correctl
265267
],
266268
},
267269
"plugins": [
268-
RsbuildCorePlugin {},
270+
{
271+
"name": "RsbuildCorePlugin",
272+
},
269273
],
270274
},
271275
{
@@ -376,7 +380,9 @@ exports[`plugin-webpack-swc > should apply multiple environment configs correctl
376380
],
377381
},
378382
"plugins": [
379-
RsbuildCorePlugin {},
383+
{
384+
"name": "RsbuildCorePlugin",
385+
},
380386
],
381387
},
382388
]
@@ -495,7 +501,9 @@ exports[`plugin-webpack-swc > should apply source.include and source.exclude cor
495501
],
496502
},
497503
"plugins": [
498-
RsbuildCorePlugin {},
504+
{
505+
"name": "RsbuildCorePlugin",
506+
},
499507
],
500508
}
501509
`;
@@ -1326,7 +1334,9 @@ exports[`plugin-webpack-swc > should set swc-loader 1`] = `
13261334
],
13271335
},
13281336
"plugins": [
1329-
RsbuildCorePlugin {},
1337+
{
1338+
"name": "RsbuildCorePlugin",
1339+
},
13301340
],
13311341
}
13321342
`;
@@ -1468,7 +1478,9 @@ exports[`plugin-webpack-swc > should use output config 1`] = `
14681478
],
14691479
},
14701480
"plugins": [
1471-
RsbuildCorePlugin {},
1481+
{
1482+
"name": "RsbuildCorePlugin",
1483+
},
14721484
],
14731485
},
14741486
]

packages/compat/webpack/tests/__snapshots__/default.test.ts.snap

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
247247
"hints": false,
248248
},
249249
"plugins": [
250-
RsbuildCorePlugin {},
250+
{
251+
"name": "RsbuildCorePlugin",
252+
},
251253
HotModuleReplacementPlugin {
252254
"options": {},
253255
},
@@ -657,7 +659,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
657659
"hints": false,
658660
},
659661
"plugins": [
660-
RsbuildCorePlugin {},
662+
{
663+
"name": "RsbuildCorePlugin",
664+
},
661665
MiniCssExtractPlugin {
662666
"_sortedModulesCache": WeakMap {},
663667
"options": {
@@ -1070,7 +1074,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
10701074
"hints": false,
10711075
},
10721076
"plugins": [
1073-
RsbuildCorePlugin {},
1077+
{
1078+
"name": "RsbuildCorePlugin",
1079+
},
10741080
DefinePlugin {
10751081
"definitions": {
10761082
"import.meta.env.ASSET_PREFIX": "\\"\\"",
@@ -1389,7 +1395,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
13891395
"hints": false,
13901396
},
13911397
"plugins": [
1392-
RsbuildCorePlugin {},
1398+
{
1399+
"name": "RsbuildCorePlugin",
1400+
},
13931401
DefinePlugin {
13941402
"definitions": {
13951403
"import.meta.env.ASSET_PREFIX": "\\"\\"",

packages/compat/webpack/tests/__snapshots__/environment.test.ts.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ exports[`environment config > tools.webpack / bundlerChain can be used in enviro
88
"filename": "[name].web.js",
99
},
1010
"plugins": [
11-
RsbuildCorePlugin {},
11+
{
12+
"name": "RsbuildCorePlugin",
13+
},
1214
],
1315
},
1416
{
@@ -17,7 +19,9 @@ exports[`environment config > tools.webpack / bundlerChain can be used in enviro
1719
"filename": "bundle.js",
1820
},
1921
"plugins": [
20-
RsbuildCorePlugin {},
22+
{
23+
"name": "RsbuildCorePlugin",
24+
},
2125
],
2226
},
2327
]

packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ exports[`webpackConfig > should allow to append and prepend plugins 1`] = `
77
"foo": "2",
88
},
99
},
10-
RsbuildCorePlugin {},
10+
{
11+
"name": "RsbuildCorePlugin",
12+
},
1113
MiniCssExtractPlugin {
1214
"_sortedModulesCache": WeakMap {},
1315
"options": {
@@ -124,7 +126,9 @@ exports[`webpackConfig > should allow to use tools.webpackChain to modify config
124126
{
125127
"devtool": "eval",
126128
"plugins": [
127-
RsbuildCorePlugin {},
129+
{
130+
"name": "RsbuildCorePlugin",
131+
},
128132
],
129133
}
130134
`;
@@ -133,7 +137,9 @@ exports[`webpackConfig > should allow tools.webpack to be an array 1`] = `
133137
{
134138
"devtool": "source-map",
135139
"plugins": [
136-
RsbuildCorePlugin {},
140+
{
141+
"name": "RsbuildCorePlugin",
142+
},
137143
],
138144
}
139145
`;
@@ -142,7 +148,9 @@ exports[`webpackConfig > should allow tools.webpack to be an object 1`] = `
142148
{
143149
"devtool": "eval",
144150
"plugins": [
145-
RsbuildCorePlugin {},
151+
{
152+
"name": "RsbuildCorePlugin",
153+
},
146154
],
147155
}
148156
`;
@@ -151,7 +159,9 @@ exports[`webpackConfig > should allow tools.webpack to modify config object 1`]
151159
{
152160
"devtool": "eval-cheap-source-map",
153161
"plugins": [
154-
RsbuildCorePlugin {},
162+
{
163+
"name": "RsbuildCorePlugin",
164+
},
155165
],
156166
}
157167
`;
@@ -160,7 +170,9 @@ exports[`webpackConfig > should allow tools.webpack to return config 1`] = `
160170
{
161171
"devtool": "eval",
162172
"plugins": [
163-
RsbuildCorePlugin {},
173+
{
174+
"name": "RsbuildCorePlugin",
175+
},
164176
],
165177
}
166178
`;
@@ -169,7 +181,9 @@ exports[`webpackConfig > should allow tools.webpackChain to be an array 1`] = `
169181
{
170182
"devtool": "source-map",
171183
"plugins": [
172-
RsbuildCorePlugin {},
184+
{
185+
"name": "RsbuildCorePlugin",
186+
},
173187
],
174188
}
175189
`;
@@ -178,7 +192,9 @@ exports[`webpackConfig > should provide mergeConfig util in tools.webpack functi
178192
{
179193
"devtool": "eval",
180194
"plugins": [
181-
RsbuildCorePlugin {},
195+
{
196+
"name": "RsbuildCorePlugin",
197+
},
182198
],
183199
}
184200
`;

packages/compat/webpack/tests/default.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ describe('bundlerApi', () => {
9595
{
9696
"devtool": "hidden-source-map",
9797
"plugins": [
98-
RsbuildCorePlugin {},
98+
{
99+
"name": "RsbuildCorePlugin",
100+
},
99101
],
100102
"target": "node",
101103
}

packages/core/rslib.config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,4 @@ export default defineConfig({
173173
},
174174
},
175175
],
176-
tools: {
177-
swc: {
178-
jsc: {
179-
keepClassNames: true,
180-
},
181-
},
182-
},
183176
});

packages/core/src/helpers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export const isMultiCompiler = <
333333
>(
334334
compiler: C | M,
335335
): compiler is M => {
336-
return compiler.constructor.name === 'MultiCompiler';
336+
return 'compilers' in compiler && Array.isArray(compiler.compilers);
337337
};
338338

339339
export function pick<T, U extends keyof T>(

packages/core/src/initPlugins.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export function initPluginAPI({
169169
* Transform Rsbuild plugin hooks to Rspack plugin hooks
170170
*/
171171
class RsbuildCorePlugin {
172+
name = pluginName;
173+
172174
apply(compiler: Compiler): void {
173175
compiler.__rsbuildTransformer = transformer;
174176

packages/core/src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ function generateLinks(
167167
export class HtmlPreloadOrPrefetchPlugin implements RspackPluginInstance {
168168
readonly options: PreloadOrPreFetchOption;
169169

170+
name = 'HtmlPreloadOrPrefetchPlugin';
171+
170172
resourceHints: HtmlRspackPlugin.HtmlTagObject[] = [];
171173

172174
type: LinkType;
@@ -187,7 +189,7 @@ export class HtmlPreloadOrPrefetchPlugin implements RspackPluginInstance {
187189
}
188190

189191
apply(compiler: Compiler): void {
190-
compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
192+
compiler.hooks.compilation.tap(this.name, (compilation) => {
191193
getHTMLPlugin()
192194
.getHooks(compilation)
193195
.beforeAssetTagGeneration.tap(

packages/core/tests/__snapshots__/asset.test.ts.snap

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ exports[`plugin-asset > should add image rules correctly 1`] = `
118118
"assetModuleFilename": "static/assets/[name].[contenthash:8][ext]",
119119
},
120120
"plugins": [
121-
RsbuildCorePlugin {},
121+
{
122+
"name": "RsbuildCorePlugin",
123+
},
122124
],
123125
}
124126
`;
@@ -241,7 +243,9 @@ exports[`plugin-asset > should add image rules correctly 2`] = `
241243
"assetModuleFilename": "static/assets/[name].[contenthash:8][ext]",
242244
},
243245
"plugins": [
244-
RsbuildCorePlugin {},
246+
{
247+
"name": "RsbuildCorePlugin",
248+
},
245249
],
246250
}
247251
`;
@@ -364,7 +368,9 @@ exports[`plugin-asset > should allow to use distPath.image to modify dist path 1
364368
"assetModuleFilename": "static/assets/[name].[contenthash:8][ext]",
365369
},
366370
"plugins": [
367-
RsbuildCorePlugin {},
371+
{
372+
"name": "RsbuildCorePlugin",
373+
},
368374
],
369375
}
370376
`;
@@ -487,7 +493,9 @@ exports[`plugin-asset > should allow to use filename.image to modify filename 1`
487493
"assetModuleFilename": "static/assets/[name].[contenthash:8][ext]",
488494
},
489495
"plugins": [
490-
RsbuildCorePlugin {},
496+
{
497+
"name": "RsbuildCorePlugin",
498+
},
491499
],
492500
}
493501
`;

0 commit comments

Comments
 (0)