Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use pnpm patch instead of custom scripts #4348

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
},
"packageManager": "[email protected]",
Expand Down
27 changes: 0 additions & 27 deletions packages/core/prebundle.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// @ts-check
/**
* Tip: please add the prebundled packages to `tsconfig.json#paths`.
*/
import fs from 'node:fs';
import { join } from 'node:path';

Expand All @@ -13,14 +10,6 @@ function replaceFileContent(filePath, replaceFn) {
}
}

// postcss-loader and css-loader use `semver` to compare PostCSS ast version,
// Rsbuild uses the same PostCSS version and do not need the comparison.
const skipSemver = (task) => {
replaceFileContent(join(task.depPath, 'dist/index.js'), (content) =>
content.replaceAll('require("semver")', '({ satisfies: () => true })'),
);
};

/** @type {import('prebundle').Config} */
export default {
prettier: true,
Expand Down Expand Up @@ -85,9 +74,6 @@ export default {
},
{
name: 'rspack-chain',
externals: {
'@rspack/core': '@rspack/core',
},
ignoreDts: true,
afterBundle(task) {
// copy types to dist because prebundle will break the types
Expand Down Expand Up @@ -131,8 +117,6 @@ export default {
},
},
{
// The webpack-bundle-analyzer version was locked to v4.9.0 to be compatible with Rspack
// If we need to upgrade the version, please check if the chunk detail can be displayed correctly
name: 'webpack-bundle-analyzer',
},
{
Expand Down Expand Up @@ -164,27 +148,16 @@ export default {
name: 'css-loader',
ignoreDts: true,
externals: {
semver: './semver',
postcss: '../postcss',
},
beforeBundle: skipSemver,
},
{
name: 'postcss-loader',
externals: {
jiti: '../jiti',
semver: './semver',
postcss: '../postcss',
},
ignoreDts: true,
beforeBundle(task) {
replaceFileContent(join(task.depPath, 'dist/utils.js'), (content) =>
// Rsbuild uses `postcss-load-config` and no need to use `cosmiconfig`.
// the ralevent code will never be executed, so we can replace it with an empty object.
content.replaceAll('require("cosmiconfig")', '{}'),
);
skipSemver(task);
},
},
{
name: 'postcss-load-config',
Expand Down
34 changes: 34 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# postcss-loader and css-loader use `semver` to compare PostCSS ast version,
# Rsbuild uses the same PostCSS version and do not need the comparison.
diff --git a/dist/index.js b/dist/index.js
index 11afa0f317e59dd940048aa732aa8d3a0c336370..b638b4d7758273ac55654f2b188b780f095dc6fa 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -5,9 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = loader;
var _postcss = _interopRequireDefault(require("postcss"));
-var _package = _interopRequireDefault(require("postcss/package.json"));
-var _semver = require("semver");
-var _options = _interopRequireDefault(require("./options.json"));
var _plugins = require("./plugins");
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -17,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
*/

async function loader(content, map, meta) {
- const rawOptions = this.getOptions(_options.default);
+ const rawOptions = this.getOptions();
const callback = this.async();
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")) {
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).'));
@@ -98,7 +95,7 @@ async function loader(content, map, meta) {
const {
ast
} = meta;
- if (ast && ast.type === "postcss" && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
+ if (ast && ast.type === "postcss" ) {
// eslint-disable-next-line no-param-reassign
content = ast.root;
}
48 changes: 48 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# postcss-loader and css-loader use `semver` to compare PostCSS ast version,
# Rsbuild uses the same PostCSS version and do not need the comparison.
diff --git a/dist/index.js b/dist/index.js
index c71ab296e023491323a8abaff050ca906ae36f0c..fa7679761159a21ce210604d74dc9c34dee7000b 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = loader;
var _path = _interopRequireDefault(require("path"));
-var _package = _interopRequireDefault(require("postcss/package.json"));
-var _options = _interopRequireDefault(require("./options.json"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
let hasExplicitDependencyOnPostCSS = false;
@@ -25,7 +23,7 @@ let hasExplicitDependencyOnPostCSS = false;
* @return {callback} callback Result
*/
async function loader(content, sourceMap, meta) {
- const options = this.getOptions(_options.default);
+ const options = this.getOptions();
const callback = this.async();
const configOption = typeof options.postcssOptions === "undefined" || typeof options.postcssOptions.config === "undefined" ? true : options.postcssOptions.config;
let implementation;
@@ -66,9 +64,7 @@ async function loader(content, sourceMap, meta) {
let root;

// Reuse PostCSS AST from other loaders
- if (meta && meta.ast && meta.ast.type === "postcss" &&
- // eslint-disable-next-line global-require
- require("semver").satisfies(meta.ast.version, `^${_package.default.version}`)) {
+ if (meta && meta.ast && meta.ast.type === "postcss") {
({
root
} = meta.ast);
diff --git a/dist/utils.js b/dist/utils.js
index 218f597ff2220b4381f9df37b1d5377835c631d6..b5a870957098ef0d971a2ff9f6be3cde9a1fbfb5 100644
--- a/dist/utils.js
+++ b/dist/utils.js
@@ -15,7 +15,7 @@ exports.warningFactory = warningFactory;
var _path = _interopRequireDefault(require("path"));
var _url = _interopRequireDefault(require("url"));
var _module = _interopRequireDefault(require("module"));
-var _cosmiconfig = require("cosmiconfig");
+var _cosmiconfig = {};
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const parentModule = module;
const stat = (inputFileSystem, filePath) => new Promise((resolve, reject) => {
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading