@@ -46,17 +46,35 @@ function resolveSource(file, source) {
4646 return path . resolve ( path . dirname ( file ) , source ) ;
4747}
4848
49- function prepare ( someDirectives ) {
50- if ( typeof someDirectives === 'string' ) {
51- const { file, directives } = load ( someDirectives ) ;
49+ function getGlobalOptions ( directive ) {
50+ if ( Array . isArray ( directive ) ) {
51+ if ( directive . length > 2 ) {
52+ throw new Error ( `Unexpected directive declaration ${ JSON . stringify ( directive ) } ` ) ;
53+ }
54+
55+ return {
56+ directive : directive [ 0 ] ,
57+ globalOptions : directive [ 1 ] ,
58+ } ;
59+ }
60+
61+ return { directive } ;
62+ }
63+
64+ function prepare ( directiveWithOptions ) {
65+ const { directive : someDirective , globalOptions } = getGlobalOptions ( directiveWithOptions ) ;
66+
67+ if ( typeof someDirective === 'string' ) {
68+ const { file, directives } = load ( someDirective ) ;
5269 return toArray ( directives ) . map ( ( directive ) => {
5370 return Object . assign ( { } , directive , {
5471 source : resolveSource ( file , directive . source ) ,
72+ globalOptions,
5573 } ) ;
5674 } ) ;
5775 }
5876
59- return toArray ( someDirectives ) ;
77+ return [ Object . assign ( { } , { globalOptions } , someDirective ) ] ;
6078}
6179
6280function addDefaults ( directive ) {
@@ -71,8 +89,8 @@ export default function normalizeDirectives(directives) {
7189 return [ ] ;
7290 }
7391
74- return directives . reduce ( ( memo , someDirectives ) => {
75- return memo . concat ( prepare ( someDirectives ) . map ( addDefaults ) ) ;
92+ return directives . reduce ( ( memo , directive ) => {
93+ return memo . concat ( prepare ( directive ) . map ( addDefaults ) ) ;
7694 } , [ ] ) . sort ( ( { priority } , { priority : otherPriority } ) => {
7795 return priority - otherPriority ;
7896 } ) ;
0 commit comments