1
+ import { search as searchForConfiguration } from "@css-blocks/config" ;
1
2
import {
2
3
BlockFactory ,
4
+ Configuration ,
3
5
CssBlockError ,
4
6
ErrorWithPosition ,
5
7
Importer ,
@@ -119,7 +121,7 @@ export class CLI {
119
121
* Validate the syntax of a list of block files.
120
122
*/
121
123
async validate ( blockFiles : Array < string > , options : ValidateOptions ) {
122
- let preprocessors : Preprocessors = options . preprocessors ? require ( path . resolve ( options . preprocessors ) ) : { } ;
124
+ let preprocessors : Preprocessors | null = options . preprocessors ? require ( path . resolve ( options . preprocessors ) ) : null ;
123
125
let npm = options . npm || false ;
124
126
let aliases : Aliases = [ ] ;
125
127
let aliasList = options . alias || [ ] ;
@@ -132,7 +134,21 @@ export class CLI {
132
134
if ( npm ) {
133
135
importer = new NodeJsImporter ( aliases ) ;
134
136
}
135
- let factory = new BlockFactory ( { preprocessors, importer} ) ;
137
+ let searchDir : string ;
138
+ let blockOptions : Partial < Configuration > ;
139
+ if ( blockFiles . length > 0 ) {
140
+ searchDir = path . dirname ( path . resolve ( blockFiles [ 0 ] ) ) ;
141
+ } else {
142
+ searchDir = process . cwd ( ) ;
143
+ }
144
+ blockOptions = await searchForConfiguration ( searchDir ) || { } ;
145
+ if ( preprocessors ) {
146
+ blockOptions . preprocessors = preprocessors ;
147
+ }
148
+ if ( importer ) {
149
+ blockOptions . importer = importer ;
150
+ }
151
+ let factory = new BlockFactory ( blockOptions ) ;
136
152
let errorCount = 0 ;
137
153
for ( let blockFile of blockFiles ) {
138
154
let blockFileRelative = path . relative ( process . cwd ( ) , path . resolve ( blockFile ) ) ;
0 commit comments