Skip to content

Commit 35f6b82

Browse files
authored
chore: use pnpm patch instead of custom scripts (#4348)
1 parent 27a29a3 commit 35f6b82

File tree

5 files changed

+95
-32
lines changed

5 files changed

+95
-32
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
},
5555
"pnpm": {
5656
"patchedDependencies": {
57-
57+
58+
59+
5860
}
5961
},
6062
"packageManager": "[email protected]",

packages/core/prebundle.config.mjs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// @ts-check
2-
/**
3-
* Tip: please add the prebundled packages to `tsconfig.json#paths`.
4-
*/
52
import fs from 'node:fs';
63
import { join } from 'node:path';
74

@@ -13,14 +10,6 @@ function replaceFileContent(filePath, replaceFn) {
1310
}
1411
}
1512

16-
// postcss-loader and css-loader use `semver` to compare PostCSS ast version,
17-
// Rsbuild uses the same PostCSS version and do not need the comparison.
18-
const skipSemver = (task) => {
19-
replaceFileContent(join(task.depPath, 'dist/index.js'), (content) =>
20-
content.replaceAll('require("semver")', '({ satisfies: () => true })'),
21-
);
22-
};
23-
2413
/** @type {import('prebundle').Config} */
2514
export default {
2615
prettier: true,
@@ -85,9 +74,6 @@ export default {
8574
},
8675
{
8776
name: 'rspack-chain',
88-
externals: {
89-
'@rspack/core': '@rspack/core',
90-
},
9177
ignoreDts: true,
9278
afterBundle(task) {
9379
// copy types to dist because prebundle will break the types
@@ -131,8 +117,6 @@ export default {
131117
},
132118
},
133119
{
134-
// The webpack-bundle-analyzer version was locked to v4.9.0 to be compatible with Rspack
135-
// If we need to upgrade the version, please check if the chunk detail can be displayed correctly
136120
name: 'webpack-bundle-analyzer',
137121
},
138122
{
@@ -164,27 +148,16 @@ export default {
164148
name: 'css-loader',
165149
ignoreDts: true,
166150
externals: {
167-
semver: './semver',
168151
postcss: '../postcss',
169152
},
170-
beforeBundle: skipSemver,
171153
},
172154
{
173155
name: 'postcss-loader',
174156
externals: {
175157
jiti: '../jiti',
176-
semver: './semver',
177158
postcss: '../postcss',
178159
},
179160
ignoreDts: true,
180-
beforeBundle(task) {
181-
replaceFileContent(join(task.depPath, 'dist/utils.js'), (content) =>
182-
// Rsbuild uses `postcss-load-config` and no need to use `cosmiconfig`.
183-
// the ralevent code will never be executed, so we can replace it with an empty object.
184-
content.replaceAll('require("cosmiconfig")', '{}'),
185-
);
186-
skipSemver(task);
187-
},
188161
},
189162
{
190163
name: 'postcss-load-config',

patches/[email protected]

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# postcss-loader and css-loader use `semver` to compare PostCSS ast version,
2+
# Rsbuild uses the same PostCSS version and do not need the comparison.
3+
diff --git a/dist/index.js b/dist/index.js
4+
index 11afa0f317e59dd940048aa732aa8d3a0c336370..b638b4d7758273ac55654f2b188b780f095dc6fa 100644
5+
--- a/dist/index.js
6+
+++ b/dist/index.js
7+
@@ -5,9 +5,6 @@ Object.defineProperty(exports, "__esModule", {
8+
});
9+
exports.default = loader;
10+
var _postcss = _interopRequireDefault(require("postcss"));
11+
-var _package = _interopRequireDefault(require("postcss/package.json"));
12+
-var _semver = require("semver");
13+
-var _options = _interopRequireDefault(require("./options.json"));
14+
var _plugins = require("./plugins");
15+
var _utils = require("./utils");
16+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17+
@@ -17,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18+
*/
19+
20+
async function loader(content, map, meta) {
21+
- const rawOptions = this.getOptions(_options.default);
22+
+ const rawOptions = this.getOptions();
23+
const callback = this.async();
24+
if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && (this._module.type === "css" || this._module.type === "css/auto" || this._module.type === "css/global" || this._module.type === "css/module")) {
25+
this.emitWarning(new Error('You can\'t use `experiments.css` (`experiments.futureDefaults` enable built-in CSS support by default) and `css-loader` together, please set `experiments.css` to `false` or set `{ type: "javascript/auto" }` for rules with `css-loader` in your webpack config (now css-loader does nothing).'));
26+
@@ -98,7 +95,7 @@ async function loader(content, map, meta) {
27+
const {
28+
ast
29+
} = meta;
30+
- if (ast && ast.type === "postcss" && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
31+
+ if (ast && ast.type === "postcss" ) {
32+
// eslint-disable-next-line no-param-reassign
33+
content = ast.root;
34+
}

patches/[email protected]

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# postcss-loader and css-loader use `semver` to compare PostCSS ast version,
2+
# Rsbuild uses the same PostCSS version and do not need the comparison.
3+
diff --git a/dist/index.js b/dist/index.js
4+
index c71ab296e023491323a8abaff050ca906ae36f0c..fa7679761159a21ce210604d74dc9c34dee7000b 100644
5+
--- a/dist/index.js
6+
+++ b/dist/index.js
7+
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
8+
});
9+
exports.default = loader;
10+
var _path = _interopRequireDefault(require("path"));
11+
-var _package = _interopRequireDefault(require("postcss/package.json"));
12+
-var _options = _interopRequireDefault(require("./options.json"));
13+
var _utils = require("./utils");
14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
let hasExplicitDependencyOnPostCSS = false;
16+
@@ -25,7 +23,7 @@ let hasExplicitDependencyOnPostCSS = false;
17+
* @return {callback} callback Result
18+
*/
19+
async function loader(content, sourceMap, meta) {
20+
- const options = this.getOptions(_options.default);
21+
+ const options = this.getOptions();
22+
const callback = this.async();
23+
const configOption = typeof options.postcssOptions === "undefined" || typeof options.postcssOptions.config === "undefined" ? true : options.postcssOptions.config;
24+
let implementation;
25+
@@ -66,9 +64,7 @@ async function loader(content, sourceMap, meta) {
26+
let root;
27+
28+
// Reuse PostCSS AST from other loaders
29+
- if (meta && meta.ast && meta.ast.type === "postcss" &&
30+
- // eslint-disable-next-line global-require
31+
- require("semver").satisfies(meta.ast.version, `^${_package.default.version}`)) {
32+
+ if (meta && meta.ast && meta.ast.type === "postcss") {
33+
({
34+
root
35+
} = meta.ast);
36+
diff --git a/dist/utils.js b/dist/utils.js
37+
index 218f597ff2220b4381f9df37b1d5377835c631d6..b5a870957098ef0d971a2ff9f6be3cde9a1fbfb5 100644
38+
--- a/dist/utils.js
39+
+++ b/dist/utils.js
40+
@@ -15,7 +15,7 @@ exports.warningFactory = warningFactory;
41+
var _path = _interopRequireDefault(require("path"));
42+
var _url = _interopRequireDefault(require("url"));
43+
var _module = _interopRequireDefault(require("module"));
44+
-var _cosmiconfig = require("cosmiconfig");
45+
+var _cosmiconfig = {};
46+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47+
const parentModule = module;
48+
const stat = (inputFileSystem, filePath) => new Promise((resolve, reject) => {

pnpm-lock.yaml

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)