Skip to content

Commit 977bb71

Browse files
refactor!: minimum supported webpack version is 5.27.0
1 parent a70555a commit 977bb71

File tree

1 file changed

+1
-49
lines changed

1 file changed

+1
-49
lines changed

src/utils.js

+1-49
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,9 @@ import path from "path";
22

33
import isEqualLocals from "./runtime/isEqualLocals";
44

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

0 commit comments

Comments
 (0)