Skip to content

Commit 6a72546

Browse files
committed
chore: lint
1 parent 6067b85 commit 6a72546

File tree

7 files changed

+70
-74
lines changed

7 files changed

+70
-74
lines changed

examples/react-component-bundle-false/rslib.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default defineConfig({
3232
],
3333
output: {
3434
target: 'web',
35-
assetPrefix: 'auto' // TODO: move this line to packages/core/src/asset/assetConfig.ts
35+
assetPrefix: 'auto', // TODO: move this line to packages/core/src/asset/assetConfig.ts
3636
},
3737
plugins: [pluginReact(), pluginSass()],
3838
});

packages/core/src/asset/assetConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const composeAssetConfig = (
2020
output: {
2121
dataUriLimit: 0, // default: no inline asset
2222
// assetPrefix: 'auto', // TODO: will turn on this with js support together in the future
23-
}
23+
},
2424
};
2525
}
2626

packages/core/src/css/LibCssExtractPlugin.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
import { rspack, type Rspack } from '@rsbuild/core';
1+
import { type Rspack, rspack } from '@rsbuild/core';
2+
import { RSLIB_CSS_ENTRY_FLAG } from './cssConfig';
3+
import {
4+
ABSOLUTE_PUBLIC_PATH,
5+
AUTO_PUBLIC_PATH,
6+
SINGLE_DOT_PATH_SEGMENT,
7+
} from './libCssExtractLoader';
28
import { getUndoPath } from './utils';
3-
import { ABSOLUTE_PUBLIC_PATH, SINGLE_DOT_PATH_SEGMENT, AUTO_PUBLIC_PATH } from './libCssExtractLoader';
49

510
const pluginName = 'LIB_CSS_EXTRACT_PLUGIN';
611

7-
type Options = {
8-
include: RegExp;
9-
};
12+
type Options = Record<string, unknown>;
1013

1114
class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
1215
readonly name: string = pluginName;
1316
options: Options;
14-
constructor(options: Options) {
15-
this.options = options;
17+
constructor(options?: Options) {
18+
this.options = options ?? {};
1619
}
1720

1821
apply(compiler: Rspack.Compiler): void {
19-
const include = this.options.include;
22+
// 1. mark and remove the normal css asset
23+
// 2. preserve CSS Modules asset
2024
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
2125
compilation.hooks.chunkAsset.tap(pluginName, (_chunk, filename) => {
2226
const asset = compilation.getAsset(filename);
23-
console.log(asset);
2427
if (!asset) {
2528
return;
2629
}
27-
const needRemove = Boolean(asset.name.match(include));
30+
const needRemove = Boolean(asset.name.match(RSLIB_CSS_ENTRY_FLAG));
2831
if (needRemove) {
2932
compilation.deleteAsset(filename);
3033
}
3134
});
32-
3335
});
3436

3537
/**
3638
* The following code is modified based on
3739
* https://github.com/webpack-contrib/mini-css-extract-plugin/blob/3effaa0319bad5cc1bf0ae760553bf7abcbc35a4/src/index.js#L1597
38-
*
40+
*
3941
* replace publicPath placeholders of miniCssExtractLoader
4042
*/
4143
compiler.hooks.make.tap(pluginName, (compilation) => {
@@ -50,8 +52,7 @@ class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
5052

5153
function replace(searchValue: string, replaceValue: string) {
5254
let start = oldSource.indexOf(searchValue);
53-
while(start !== -1) {
54-
console.log(start)
55+
while (start !== -1) {
5556
replaceSource.replace(
5657
start,
5758
start + searchValue.length - 1,
@@ -63,13 +64,16 @@ class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
6364

6465
replace(ABSOLUTE_PUBLIC_PATH, '');
6566
replace(SINGLE_DOT_PATH_SEGMENT, '.');
66-
const undoPath = getUndoPath(name, compilation.outputOptions.path!, false);
67-
replace(AUTO_PUBLIC_PATH, undoPath)
67+
const undoPath = getUndoPath(
68+
name,
69+
compilation.outputOptions.path!,
70+
false,
71+
);
72+
replace(AUTO_PUBLIC_PATH, undoPath);
6873

6974
return replaceSource;
7075
});
7176
}
72-
7377
});
7478
});
7579
}

packages/core/src/css/cssConfig.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,7 @@ const pluginLibCss = (rootDir: string): RsbuildPlugin => ({
138138
if (isUsingCssExtract) {
139139
const cssExtract = CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT;
140140
config.plugins.delete(cssExtract);
141-
config
142-
.plugin(LibCssExtractPlugin.name)
143-
.use(LibCssExtractPlugin, [
144-
{
145-
include: new RegExp(`^${RSLIB_CSS_ENTRY_FLAG}`),
146-
},
147-
]);
141+
config.plugin(LibCssExtractPlugin.name).use(LibCssExtractPlugin);
148142
}
149143
});
150144
},

packages/core/src/css/libCssExtractLoader.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import path, { extname } from 'node:path';
99
import type { Rspack } from '@rsbuild/core';
1010

11-
export const BASE_URI = "webpack://";
12-
export const MODULE_TYPE = "css/mini-extract";
13-
export const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
11+
export const BASE_URI = 'webpack://';
12+
export const MODULE_TYPE = 'css/mini-extract';
13+
export const AUTO_PUBLIC_PATH = '__mini_css_extract_plugin_public_path_auto__';
1414
export const ABSOLUTE_PUBLIC_PATH: string = `${BASE_URI}/mini-css-extract-plugin/`;
1515
export const SINGLE_DOT_PATH_SEGMENT =
16-
"__mini_css_extract_plugin_single_dot_path_segment__";
16+
'__mini_css_extract_plugin_single_dot_path_segment__';
1717

1818
interface DependencyDescription {
1919
identifier: string;
@@ -28,9 +28,7 @@ interface DependencyDescription {
2828
}
2929

3030
// https://github.com/web-infra-dev/rspack/blob/c0986d39b7d647682f10fcef5bbade39fd016eca/packages/rspack/src/config/types.ts#L10
31-
type Filename =
32-
| string
33-
| ((pathData: any, assetInfo?: any) => string);
31+
type Filename = string | ((pathData: any, assetInfo?: any) => string);
3432

3533
export interface CssExtractRspackLoaderOptions {
3634
publicPath?: string | ((resourcePath: string, context: string) => string);
@@ -92,32 +90,31 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
9290

9391
let { publicPath } = this._compilation!.outputOptions;
9492

93+
if (typeof options.publicPath === 'string') {
94+
// eslint-disable-next-line prefer-destructuring
95+
publicPath = options.publicPath;
96+
} else if (typeof options.publicPath === 'function') {
97+
publicPath = options.publicPath(this.resourcePath, this.rootContext);
98+
}
9599

96-
if (typeof options.publicPath === "string") {
97-
// eslint-disable-next-line prefer-destructuring
98-
publicPath = options.publicPath;
99-
} else if (typeof options.publicPath === "function") {
100-
publicPath = options.publicPath(this.resourcePath, this.rootContext);
101-
}
102-
103-
if (publicPath === "auto") {
104-
publicPath = AUTO_PUBLIC_PATH;
105-
}
100+
if (publicPath === 'auto') {
101+
publicPath = AUTO_PUBLIC_PATH;
102+
}
106103

107-
let publicPathForExtract: Filename | undefined;
104+
let publicPathForExtract: Filename | undefined;
108105

109-
if (typeof publicPath === "string") {
110-
const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
106+
if (typeof publicPath === 'string') {
107+
const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
111108

112-
publicPathForExtract = isAbsolutePublicPath
113-
? publicPath
114-
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
115-
/\./g,
116-
SINGLE_DOT_PATH_SEGMENT
117-
)}`;
118-
} else {
119-
publicPathForExtract = publicPath;
120-
}
109+
publicPathForExtract = isAbsolutePublicPath
110+
? publicPath
111+
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
112+
/\./g,
113+
SINGLE_DOT_PATH_SEGMENT,
114+
)}`;
115+
} else {
116+
publicPathForExtract = publicPath;
117+
}
121118

122119
const handleExports = (
123120
originalExports:

packages/core/src/css/utils.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
/**
2-
* This function is copied from
2+
* This function is copied from
33
* https://github.com/webpack-contrib/mini-css-extract-plugin/blob/3effaa0319bad5cc1bf0ae760553bf7abcbc35a4/src/utils.js#L169
4+
* linted by biome
45
*/
5-
function getUndoPath(filename: string, outputPath: string, enforceRelative: boolean): string {
6+
function getUndoPath(
7+
filename: string,
8+
outputPathArg: string,
9+
enforceRelative: boolean,
10+
): string {
611
let depth = -1;
7-
let append = "";
12+
let append = '';
813

9-
// eslint-disable-next-line no-param-reassign
10-
outputPath = outputPath.replace(/[\\/]$/, "");
14+
let outputPath = outputPathArg.replace(/[\\/]$/, '');
1115

1216
for (const part of filename.split(/[/\\]+/)) {
13-
if (part === "..") {
17+
if (part === '..') {
1418
if (depth > -1) {
15-
// eslint-disable-next-line no-plusplus
1619
depth--;
1720
} else {
18-
const i = outputPath.lastIndexOf("/");
19-
const j = outputPath.lastIndexOf("\\");
21+
const i = outputPath.lastIndexOf('/');
22+
const j = outputPath.lastIndexOf('\\');
2023
const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
2124

2225
if (pos < 0) {
@@ -25,20 +28,18 @@ function getUndoPath(filename: string, outputPath: string, enforceRelative: bool
2528

2629
append = `${outputPath.slice(pos + 1)}/${append}`;
2730

28-
// eslint-disable-next-line no-param-reassign
2931
outputPath = outputPath.slice(0, pos);
3032
}
31-
} else if (part !== ".") {
32-
// eslint-disable-next-line no-plusplus
33+
} else if (part !== '.') {
3334
depth++;
3435
}
3536
}
3637

3738
return depth > 0
38-
? `${"../".repeat(depth)}${append}`
39+
? `${'../'.repeat(depth)}${append}`
3940
: enforceRelative
40-
? `./${append}`
41-
: append;
41+
? `./${append}`
42+
: append;
4243
}
4344

44-
export { getUndoPath }
45+
export { getUndoPath };

tests/integration/style/sass/bundle-false/rslib.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
entry: {
1212
index: [
1313
'../__fixtures__/src/**/*.scss',
14-
'../__fixtures__/foundation/logo.svg'
14+
'../__fixtures__/foundation/logo.svg',
1515
],
1616
},
1717
},
@@ -26,7 +26,7 @@ export default defineConfig({
2626
target: 'web',
2727
assetPrefix: 'auto',
2828
dataUriLimit: {
29-
svg: 0
30-
}
29+
svg: 0,
30+
},
3131
},
3232
});

0 commit comments

Comments
 (0)