@@ -255,23 +255,31 @@ function readAtImport(
255
255
addInputToPath ( options )
256
256
257
257
return Promise . resolve ( ) . then ( function ( ) {
258
- if ( options . resolve ) {
259
- return options . resolve ( parsedAtImport . uri , dir , options )
260
- }
261
- return resolveId ( parsedAtImport . uri , dir , options . path )
258
+ var resolver = options . resolve ? options . resolve : resolveId
259
+ return resolver ( parsedAtImport . uri , dir , options )
262
260
} ) . then ( function ( resolved ) {
263
- parsedAtImport . file = resolved
264
- return readImportedContent (
265
- result ,
266
- parsedAtImport ,
267
- assign ( { } , options ) ,
268
- state ,
269
- media ,
270
- processor
271
- )
261
+ if ( ! Array . isArray ( resolved ) ) {
262
+ resolved = [ resolved ]
263
+ }
264
+ return Promise . all ( resolved . map ( function ( file ) {
265
+ return readImportedContent (
266
+ result ,
267
+ parsedAtImport ,
268
+ file ,
269
+ assign ( { } , options ) ,
270
+ state ,
271
+ media ,
272
+ processor
273
+ )
274
+ } ) )
272
275
} ) . then ( function ( ignored ) {
273
276
compoundInstance ( parsedAtImport )
274
- return ignored
277
+ return ignored . reduce ( function ( ignored , instance ) {
278
+ if ( instance ) {
279
+ return ignored . concat ( instance )
280
+ }
281
+ return ignored
282
+ } , [ ] )
275
283
} ) . catch ( function ( err ) {
276
284
result . warn ( err . message , { node : atRule } )
277
285
} )
@@ -288,12 +296,12 @@ function readAtImport(
288
296
function readImportedContent (
289
297
result ,
290
298
parsedAtImport ,
299
+ resolvedFilename ,
291
300
options ,
292
301
state ,
293
302
media ,
294
303
processor
295
304
) {
296
- var resolvedFilename = parsedAtImport . file
297
305
var atRule = parsedAtImport . node
298
306
if ( options . skipDuplicates ) {
299
307
// skip files already imported at the same scope
@@ -366,7 +374,15 @@ function readImportedContent(
366
374
) . then ( function ( ignored ) {
367
375
return processor . process ( newStyles ) . then ( function ( newResult ) {
368
376
result . messages = result . messages . concat ( newResult . messages )
369
- parsedAtImport . styles = newStyles
377
+ var nodes = parsedAtImport . importedNodes
378
+ var importedNodes = newStyles . nodes
379
+ if ( ! nodes ) {
380
+ parsedAtImport . importedNodes = importedNodes
381
+ }
382
+ else if ( importedNodes . length ) {
383
+ importedNodes [ 0 ] . raws . before = importedNodes [ 0 ] . raws . before || "\n"
384
+ parsedAtImport . importedNodes = nodes . concat ( importedNodes )
385
+ }
370
386
return ignored
371
387
} )
372
388
} )
@@ -380,17 +396,13 @@ function readImportedContent(
380
396
* @param {Object } newStyles
381
397
*/
382
398
function compoundInstance ( instance ) {
383
- if (
384
- ! instance . styles ||
385
- ! instance . styles . nodes ||
386
- ! instance . styles . nodes . length
387
- ) {
399
+ var nodes = instance . importedNodes
400
+
401
+ if ( ! nodes || ! nodes . length ) {
388
402
instance . node . remove ( )
389
403
return
390
404
}
391
405
392
- var nodes = instance . styles . nodes
393
-
394
406
// save styles
395
407
nodes . forEach ( function ( node ) {
396
408
node . parent = undefined
0 commit comments