File tree 2 files changed +41
-2
lines changed
2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import { validate } from "schema-utils" ;
4
4
5
- import { getUndoPath } from "webpack/lib/util/identifier" ;
6
-
7
5
import schema from "./plugin-options.json" ;
8
6
import {
9
7
trueFn ,
@@ -12,6 +10,7 @@ import {
12
10
ABSOLUTE_PUBLIC_PATH ,
13
11
SINGLE_DOT_PATH_SEGMENT ,
14
12
compareModulesByIdentifier ,
13
+ getUndoPath ,
15
14
} from "./utils" ;
16
15
17
16
export const pluginName = "mini-css-extract-plugin" ;
Original file line number Diff line number Diff line change @@ -102,6 +102,45 @@ function stringifyRequest(loaderContext, request) {
102
102
) ;
103
103
}
104
104
105
+ function getUndoPath ( filename , outputPath , enforceRelative ) {
106
+ let depth = - 1 ;
107
+ let append = "" ;
108
+
109
+ // eslint-disable-next-line no-param-reassign
110
+ outputPath = outputPath . replace ( / [ \\ / ] $ / , "" ) ;
111
+
112
+ for ( const part of filename . split ( / [ / \\ ] + / ) ) {
113
+ if ( part === ".." ) {
114
+ if ( depth > - 1 ) {
115
+ // eslint-disable-next-line no-plusplus
116
+ depth -- ;
117
+ } else {
118
+ const i = outputPath . lastIndexOf ( "/" ) ;
119
+ const j = outputPath . lastIndexOf ( "\\" ) ;
120
+ const pos = i < 0 ? j : j < 0 ? i : Math . max ( i , j ) ;
121
+
122
+ if ( pos < 0 ) {
123
+ return `${ outputPath } /` ;
124
+ }
125
+
126
+ append = `${ outputPath . slice ( pos + 1 ) } /${ append } ` ;
127
+
128
+ // eslint-disable-next-line no-param-reassign
129
+ outputPath = outputPath . slice ( 0 , pos ) ;
130
+ }
131
+ } else if ( part !== "." ) {
132
+ // eslint-disable-next-line no-plusplus
133
+ depth ++ ;
134
+ }
135
+ }
136
+
137
+ return depth > 0
138
+ ? `${ "../" . repeat ( depth ) } ${ append } `
139
+ : enforceRelative
140
+ ? `./${ append } `
141
+ : append ;
142
+ }
143
+
105
144
export {
106
145
trueFn ,
107
146
findModuleById ,
@@ -112,4 +151,5 @@ export {
112
151
ABSOLUTE_PUBLIC_PATH ,
113
152
SINGLE_DOT_PATH_SEGMENT ,
114
153
stringifyRequest ,
154
+ getUndoPath ,
115
155
} ;
You can’t perform that action at this time.
0 commit comments