Skip to content

Commit 6758813

Browse files
committedApr 4, 2024
refactor!: minimum supported webpack version is 5.27.0
1 parent 7590ec3 commit 6758813

File tree

2 files changed

+8
-61
lines changed

2 files changed

+8
-61
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
],
4545
"peerDependencies": {
4646
"@rspack/core": "0.x || 1.x",
47-
"webpack": "^5.0.0"
47+
"webpack": "^5.27.0"
4848
},
4949
"peerDependenciesMeta": {
5050
"@rspack/core": {

‎src/utils.js

+7-60
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,12 @@ import modulesScope from "postcss-modules-scope";
1212

1313
const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
1414

15-
const matchRelativePath = /^\.\.?[/\\]/;
16-
17-
function isAbsolutePath(str) {
18-
return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
19-
}
20-
21-
function isRelativePath(str) {
22-
return matchRelativePath.test(str);
23-
}
24-
25-
// TODO simplify for the next major release
2615
function stringifyRequest(loaderContext, request) {
27-
if (
28-
typeof loaderContext.utils !== "undefined" &&
29-
typeof loaderContext.utils.contextify === "function"
30-
) {
31-
return JSON.stringify(
32-
loaderContext.utils.contextify(
33-
loaderContext.context || loaderContext.rootContext,
34-
request,
35-
),
36-
);
37-
}
38-
39-
const splitted = request.split("!");
40-
const { context } = loaderContext;
41-
4216
return JSON.stringify(
43-
splitted
44-
.map((part) => {
45-
// First, separate singlePath from query, because the query might contain paths again
46-
const splittedPart = part.match(/^(.*?)(\?.*)/);
47-
const query = splittedPart ? splittedPart[2] : "";
48-
let singlePath = splittedPart ? splittedPart[1] : part;
49-
50-
if (isAbsolutePath(singlePath) && context) {
51-
singlePath = path.relative(context, singlePath);
52-
53-
if (isAbsolutePath(singlePath)) {
54-
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
55-
// In this case, we leave the path platform-specific without replacing any separators.
56-
// @see https://github.com/webpack/loader-utils/pull/14
57-
return singlePath + query;
58-
}
59-
60-
if (isRelativePath(singlePath) === false) {
61-
// Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
62-
singlePath = `./${singlePath}`;
63-
}
64-
}
65-
66-
return singlePath.replace(/\\/g, "/") + query;
67-
})
68-
.join("!"),
17+
loaderContext.utils.contextify(
18+
loaderContext.context || loaderContext.rootContext,
19+
request,
20+
),
6921
);
7022
}
7123

@@ -313,7 +265,7 @@ const filenameReservedRegex = /[<>:"/\\|?*]/g;
313265
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
314266

315267
function escapeLocalIdent(localident) {
316-
// TODO simplify in the next major release
268+
// TODO simplify?
317269
return escape(
318270
localident
319271
// For `[hash]` placeholder
@@ -375,13 +327,8 @@ function defaultGetLocalIdent(
375327
let localIdentHash = "";
376328

377329
for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
378-
// TODO remove this in the next major release
379-
const hash =
380-
loaderContext.utils &&
381-
typeof loaderContext.utils.createHash === "function"
382-
? loaderContext.utils.createHash(hashFunction)
383-
: // eslint-disable-next-line no-underscore-dangle
384-
loaderContext._compiler.webpack.util.createHash(hashFunction);
330+
// eslint-disable-next-line no-underscore-dangle
331+
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
385332

386333
if (hashSalt) {
387334
hash.update(hashSalt);

0 commit comments

Comments
 (0)