File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 22
33import { validate } from "schema-utils" ;
44
5- import { getUndoPath } from "webpack/lib/util/identifier" ;
6-
75import schema from "./plugin-options.json" ;
86import {
97 trueFn ,
@@ -12,6 +10,7 @@ import {
1210 ABSOLUTE_PUBLIC_PATH ,
1311 SINGLE_DOT_PATH_SEGMENT ,
1412 compareModulesByIdentifier ,
13+ getUndoPath ,
1514} from "./utils" ;
1615
1716export const pluginName = "mini-css-extract-plugin" ;
Original file line number Diff line number Diff line change @@ -102,6 +102,45 @@ function stringifyRequest(loaderContext, request) {
102102 ) ;
103103}
104104
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+
105144export {
106145 trueFn ,
107146 findModuleById ,
@@ -112,4 +151,5 @@ export {
112151 ABSOLUTE_PUBLIC_PATH ,
113152 SINGLE_DOT_PATH_SEGMENT ,
114153 stringifyRequest ,
154+ getUndoPath ,
115155} ;
You can’t perform that action at this time.
0 commit comments