11import postcss from 'postcss' ;
22import valueParser from 'postcss-value-parser' ;
3- import { isUrlRequest , urlToRequest } from 'loader-utils' ;
43
5- import { normalizeUrl , resolveRequests } from '../utils' ;
4+ import { normalizeUrl , resolveRequests , isUrlRequestable } from '../utils' ;
65
76const pluginName = 'postcss-import-parser' ;
87
@@ -77,23 +76,18 @@ export default postcss.plugin(pluginName, (options) => (css, result) => {
7776 return ;
7877 }
7978
80- let request ;
79+ let normalizedUrl ;
8180
82- // May be url is server-relative url, but not //example.com
83- if ( url . charAt ( 0 ) === '/' && url . charAt ( 1 ) !== '/' ) {
84- request = urlToRequest ( url , options . rootContext ) ;
85- }
86-
87- const isRequestable = isUrlRequest ( url ) ;
81+ const isRequestable = isUrlRequestable ( url ) ;
8882
8983 if ( isRequestable ) {
90- url = normalizeUrl ( url , isStringValue ) ;
84+ normalizedUrl = normalizeUrl ( url , isStringValue , options . rootContext ) ;
9185
9286 // Empty url after normalize - `@import '\
9387 // \
9488 // \
9589 // ';
96- if ( url . trim ( ) . length === 0 ) {
90+ if ( normalizedUrl . trim ( ) . length === 0 ) {
9791 result . warn ( `Unable to find uri in "${ atRule . toString ( ) } "` , {
9892 node : atRule ,
9993 } ) ;
@@ -104,7 +98,10 @@ export default postcss.plugin(pluginName, (options) => (css, result) => {
10498
10599 const media = valueParser . stringify ( nodes . slice ( 1 ) ) . trim ( ) . toLowerCase ( ) ;
106100
107- if ( options . filter && ! options . filter ( { url, media } ) ) {
101+ if (
102+ options . filter &&
103+ ! options . filter ( { url : normalizedUrl || url , media } )
104+ ) {
108105 return ;
109106 }
110107
@@ -114,8 +111,8 @@ export default postcss.plugin(pluginName, (options) => (css, result) => {
114111
115112 tasks . push (
116113 Promise . resolve ( index ) . then ( async ( currentIndex ) => {
117- if ( isRequestable || request ) {
118- const importKey = url ;
114+ if ( isRequestable ) {
115+ const importKey = normalizedUrl ;
119116 let importName = importsMap . get ( importKey ) ;
120117
121118 if ( ! importName ) {
@@ -124,20 +121,13 @@ export default postcss.plugin(pluginName, (options) => (css, result) => {
124121
125122 const { resolver, context } = options ;
126123
127- const possibleRequest = [ url ] ;
128-
129- if ( request ) {
130- possibleRequest . push ( request ) ;
131- }
132-
133124 let resolvedUrl ;
134125
135126 try {
136- resolvedUrl = await resolveRequests (
137- resolver ,
138- context ,
139- possibleRequest
140- ) ;
127+ resolvedUrl = await resolveRequests ( resolver , context , [
128+ normalizedUrl ,
129+ url ,
130+ ] ) ;
141131 } catch ( error ) {
142132 throw error ;
143133 }
0 commit comments