@@ -194,7 +194,8 @@ exports.main = function main(argv, options, callback) {
194
194
if ( ! stderr ) throw Error ( "'options.stderr' must be specified" ) ;
195
195
196
196
const opts = optionsUtil . parse ( argv , exports . options ) ;
197
- const args = opts . options ;
197
+ let args = opts . options ;
198
+
198
199
argv = opts . arguments ;
199
200
if ( args . noColors ) {
200
201
colorsUtil . stdout . supported =
@@ -270,6 +271,24 @@ exports.main = function main(argv, options, callback) {
270
271
271
272
// Set up base directory
272
273
const baseDir = args . baseDir ? path . resolve ( args . baseDir ) : "." ;
274
+ const target = args . target ;
275
+
276
+ // Once the basedir is calculated, we can resolve the config, and it's extensions
277
+ let asconfig = getAsconfig ( opts . config , baseDir , readFile ) ;
278
+ while ( asconfig ) {
279
+ if ( asconfig . targets && asconfig . targets [ target ] ) {
280
+ optionsUtil . merge ( exports . options , args , asconfig . targets [ target ] )
281
+ }
282
+ if ( asconfig . options ) {
283
+ optionsUtil . merge ( exports . options , args , asconfig . options ) ;
284
+ }
285
+ if ( asconfig . extends ) {
286
+ const dirname = path . dirname ( path . join ( baseDir , options . config ) ) ;
287
+ asconfig = getAsconfig ( asconfig . extends , dirname , readFile ) ;
288
+ } else {
289
+ asconfig = null ; // finished resolving the configuration
290
+ }
291
+ }
273
292
274
293
// Set up options
275
294
const compilerOptions = assemblyscript . newOptions ( ) ;
@@ -924,6 +943,16 @@ exports.main = function main(argv, options, callback) {
924
943
}
925
944
} ;
926
945
946
+ function getAsconfig ( file , baseDir , readFile ) {
947
+ const contents = readFile ( file , baseDir ) ;
948
+ if ( ! contents ) return null ;
949
+ const config = JSON . parse ( contents ) ;
950
+ // TODO: validate configuration shape
951
+ // TODO: wrap JSON.parse() in try catch to obtain a more descriptive error
952
+ return config ;
953
+ }
954
+ exports . getAsconfig = getAsconfig ;
955
+
927
956
/** Checks diagnostics emitted so far for errors. */
928
957
function checkDiagnostics ( program , stderr ) {
929
958
var diagnostic ;
0 commit comments