@@ -194,7 +194,8 @@ exports.main = function main(argv, options, callback) {
194194 if ( ! stderr ) throw Error ( "'options.stderr' must be specified" ) ;
195195
196196 const opts = optionsUtil . parse ( argv , exports . options ) ;
197- const args = opts . options ;
197+ let args = opts . options ;
198+
198199 argv = opts . arguments ;
199200 if ( args . noColors ) {
200201 colorsUtil . stdout . supported =
@@ -270,6 +271,24 @@ exports.main = function main(argv, options, callback) {
270271
271272 // Set up base directory
272273 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+ }
273292
274293 // Set up options
275294 const compilerOptions = assemblyscript . newOptions ( ) ;
@@ -924,6 +943,16 @@ exports.main = function main(argv, options, callback) {
924943 }
925944} ;
926945
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+
927956/** Checks diagnostics emitted so far for errors. */
928957function checkDiagnostics ( program , stderr ) {
929958 var diagnostic ;
0 commit comments