@@ -2,57 +2,9 @@ import path from "path";
2
2
3
3
import isEqualLocals from "./runtime/isEqualLocals" ;
4
4
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
16
5
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
-
29
6
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 ) ,
56
8
) ;
57
9
}
58
10
0 commit comments