@@ -4,21 +4,19 @@ import util from 'util';
44import parseToPostHtml from 'posthtml-parser' ;
55import { match } from 'posthtml/lib/api' ;
66
7-
87const errors = {
98 'EXTENDS_NO_SRC' : '<extends> has no "src"' ,
109 'BLOCK_NO_NAME' : '<block> has no "name"' ,
1110 'UNEXPECTED_BLOCK' : 'Unexpected block "%s"'
1211} ;
1312
14-
1513export default ( options = { } ) => {
1614 return tree => {
1715 options . encoding = options . encoding || 'utf8' ;
1816 options . root = options . root || './' ;
1917 options . plugins = options . plugins || [ ] ;
2018
21- tree = handleExtendsNodes ( tree , options ) ;
19+ tree = handleExtendsNodes ( tree , options , tree . messages ) ;
2220
2321 const blockNodes = getBlockNodes ( tree ) ;
2422 for ( let blockName of Object . keys ( blockNodes ) ) {
@@ -32,19 +30,23 @@ export default (options = {}) => {
3230 } ;
3331} ;
3432
35-
36- function handleExtendsNodes ( tree , options ) {
33+ function handleExtendsNodes ( tree , options , messages ) {
3734 match . call ( applyPluginsToTree ( tree , options . plugins ) , { tag : 'extends' } , extendsNode => {
3835 if ( ! extendsNode . attrs || ! extendsNode . attrs . src ) {
3936 throw getError ( errors . EXTENDS_NO_SRC ) ;
4037 }
4138
4239 const layoutPath = path . resolve ( options . root , extendsNode . attrs . src ) ;
4340 const layoutHtml = fs . readFileSync ( layoutPath , options . encoding ) ;
44- let layoutTree = handleExtendsNodes ( applyPluginsToTree ( parseToPostHtml ( layoutHtml ) , options . plugins ) , options ) ;
41+ let layoutTree = handleExtendsNodes ( applyPluginsToTree ( parseToPostHtml ( layoutHtml ) , options . plugins ) , options , messages ) ;
4542
4643 extendsNode . tag = false ;
4744 extendsNode . content = mergeExtendsAndLayout ( layoutTree , extendsNode ) ;
45+ messages . push ( {
46+ type : 'dependency' ,
47+ file : layoutPath ,
48+ from : options . from
49+ } ) ;
4850
4951 return extendsNode ;
5052 } ) ;
0 commit comments