@@ -268,37 +268,39 @@ const isSpecialModuleImport = /^~[^/]+$/;
268268const isNativeWin32Path = / ^ [ a - z A - Z ] : [ / \\ ] | ^ \\ \\ / i;
269269
270270function getWebpackImporter ( loaderContext , implementation , includePaths ) {
271- function startResolving ( resolutionMap ) {
271+ async function startResolving ( resolutionMap ) {
272272 if ( resolutionMap . length === 0 ) {
273273 return Promise . reject ( ) ;
274274 }
275275
276276 const [ { resolve, context, possibleRequests } ] = resolutionMap ;
277277
278- return resolve ( context , possibleRequests [ 0 ] )
279- . then ( ( result ) => {
280- // Add the result as dependency.
281- // Although we're also using stats.includedFiles, this might come in handy when an error occurs.
282- // In this case, we don't get stats.includedFiles from node-sass/sass.
283- loaderContext . addDependency ( path . normalize ( result ) ) ;
278+ let result ;
284279
285- // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
286- return { file : result . replace ( matchCss , '' ) } ;
287- } )
288- . catch ( ( ) => {
289- const [ , ...tailResult ] = possibleRequests ;
280+ try {
281+ result = await resolve ( context , possibleRequests [ 0 ] ) ;
282+ } catch ( _ignoreError ) {
283+ const [ , ...tailResult ] = possibleRequests ;
290284
291- if ( tailResult . length === 0 ) {
292- const [ , ...tailResolutionMap ] = resolutionMap ;
285+ if ( tailResult . length === 0 ) {
286+ const [ , ...tailResolutionMap ] = resolutionMap ;
293287
294- return startResolving ( tailResolutionMap ) ;
295- }
288+ return startResolving ( tailResolutionMap ) ;
289+ }
296290
297- // eslint-disable-next-line no-param-reassign
298- resolutionMap [ 0 ] . possibleRequests = tailResult ;
291+ // eslint-disable-next-line no-param-reassign
292+ resolutionMap [ 0 ] . possibleRequests = tailResult ;
293+
294+ return startResolving ( resolutionMap ) ;
295+ }
296+
297+ // Add the result as dependency.
298+ // Although we're also using stats.includedFiles, this might come in handy when an error occurs.
299+ // In this case, we don't get stats.includedFiles from node-sass/sass.
300+ loaderContext . addDependency ( path . normalize ( result ) ) ;
299301
300- return startResolving ( resolutionMap ) ;
301- } ) ;
302+ // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
303+ return { file : result . replace ( matchCss , '' ) } ;
302304 }
303305
304306 const sassResolve = loaderContext . getResolve ( {
@@ -394,7 +396,7 @@ function getWebpackImporter(loaderContext, implementation, includePaths) {
394396 startResolving ( resolutionMap )
395397 // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
396398 . catch ( ( ) => ( { file : originalUrl } ) )
397- . then ( done ) ;
399+ . then ( ( result ) => done ( result ) ) ;
398400 } ;
399401}
400402
0 commit comments