@@ -93,108 +93,61 @@ export default {
9393 ) ;
9494 }
9595
96- private getConfigPathsFromPossiblePaths ( paths : {
97- [ key : string ] : string [ ] ;
98- } ) : any {
99- const {
100- possibleTSConfigPaths,
101- possibleJSConfigPaths,
102- possibleNSConfigPaths,
103- } = paths ;
104-
105- let TSConfigPath ;
106- let JSConfigPath ;
107- let NSConfigPath ;
108-
109- // look up a ts config first
110- TSConfigPath = possibleTSConfigPaths
111- . filter ( Boolean )
112- . find ( ( path ) => this . $fs . exists ( path ) ) ;
113-
114- // if not found, look up a JS config
115- if ( ! TSConfigPath ) {
116- JSConfigPath = possibleJSConfigPaths
117- . filter ( Boolean )
118- . find ( ( path ) => this . $fs . exists ( path ) ) ;
119- }
120-
121- // lastly look for nsconfig/json config
122- if ( ! TSConfigPath && ! JSConfigPath ) {
123- NSConfigPath = possibleNSConfigPaths
124- . filter ( Boolean )
125- . find ( ( path ) => this . $fs . exists ( path ) ) ;
126- }
127-
128- return {
129- TSConfigPath,
130- JSConfigPath,
131- NSConfigPath,
132- found : TSConfigPath || JSConfigPath || NSConfigPath ,
133- } ;
134- }
135-
13696 public detectProjectConfigs ( projectDir ?: string ) : IProjectConfigInformation {
137- const possibleTSConfigPaths = [ ] ;
138- const possibleJSConfigPaths = [ ] ;
139- const possibleNSConfigPaths = [ ] ;
140- let paths ;
141-
14297 // allow overriding config name with env variable or --config (or -c)
143- const configFilename =
98+ let configName : string | boolean =
14499 process . env . NATIVESCRIPT_CONFIG_NAME ?? this . $options . config ;
145- if ( configFilename ) {
146- const fullPath = this . $fs . isRelativePath ( configFilename )
147- ? path . join ( projectDir || this . projectHelper . projectDir , configFilename )
148- : configFilename ;
149100
150- possibleTSConfigPaths . unshift (
151- fullPath . endsWith ( ".ts" ) ? fullPath : `${ fullPath } .ts`
152- ) ;
153- possibleJSConfigPaths . unshift (
154- fullPath . endsWith ( ".js" ) ? fullPath : `${ fullPath } .js`
155- ) ;
156- possibleNSConfigPaths . unshift (
157- fullPath . endsWith ( ".json" ) ? fullPath : `${ fullPath } .json`
158- ) ;
159-
160- paths = this . getConfigPathsFromPossiblePaths ( {
161- possibleTSConfigPaths,
162- possibleJSConfigPaths,
163- possibleNSConfigPaths,
164- } ) ;
101+ if ( configName === "false" ) {
102+ configName = false ;
165103 }
166104
167- // look up default paths if no path found yet
168- if ( ! paths ?. found ) {
169- possibleTSConfigPaths . push (
170- path . join (
171- projectDir || this . projectHelper . projectDir ,
172- CONFIG_FILE_NAME_TS
173- )
174- ) ;
175- possibleJSConfigPaths . push (
176- path . join (
177- projectDir || this . projectHelper . projectDir ,
178- CONFIG_FILE_NAME_JS
179- )
180- ) ;
181- possibleNSConfigPaths . push (
182- path . join (
183- projectDir || this . projectHelper . projectDir ,
184- CONFIG_NS_FILE_NAME
185- )
186- ) ;
105+ const possibleConfigPaths = [
106+ configName &&
107+ ( configName ?. endsWith ( ".ts" ) ? configName : `${ configName } .ts` ) ,
108+ configName &&
109+ ( configName ?. endsWith ( ".js" ) ? configName : `${ configName } .js` ) ,
110+ configName &&
111+ ( configName ?. endsWith ( ".json" ) ? configName : `${ configName } .json` ) ,
112+ CONFIG_FILE_NAME_TS ,
113+ CONFIG_FILE_NAME_JS ,
114+ CONFIG_NS_FILE_NAME ,
115+ ]
116+ . filter ( Boolean )
117+ . map ( ( c ) => {
118+ if ( this . $fs . isRelativePath ( c ) ) {
119+ return path . join ( projectDir || this . projectHelper . projectDir , c ) ;
120+ }
187121
188- paths = this . getConfigPathsFromPossiblePaths ( {
189- possibleTSConfigPaths,
190- possibleJSConfigPaths,
191- possibleNSConfigPaths,
122+ return c ;
192123 } ) ;
124+
125+ const existingConfigs = possibleConfigPaths . filter ( ( path ) => {
126+ return this . $fs . exists ( path ) ;
127+ } ) ;
128+
129+ // push the first possible config into the "existing" list
130+ const hasExistingConfig = ! ! existingConfigs . length ;
131+ if ( ! hasExistingConfig ) {
132+ this . $logger . trace (
133+ `No config file found - falling back to ${ possibleConfigPaths [ 0 ] } .`
134+ ) ;
135+ existingConfigs . push ( possibleConfigPaths [ 0 ] ) ;
193136 }
194137
195- const hasTSConfig = ! ! paths . TSConfigPath ;
196- const hasJSConfig = ! ! paths . JSConfigPath ;
197- const hasNSConfig = ! ! paths . NSConfigPath ;
138+ const TSConfigPath = existingConfigs . find ( ( config ) =>
139+ config . endsWith ( ".ts" )
140+ ) ;
141+ const JSConfigPath = existingConfigs . find ( ( config ) =>
142+ config . endsWith ( ".js" )
143+ ) ;
144+ const NSConfigPath = existingConfigs . find ( ( config ) =>
145+ config . endsWith ( ".json" )
146+ ) ;
147+
148+ const hasTSConfig = ! ! TSConfigPath && hasExistingConfig ;
149+ const hasJSConfig = ! ! JSConfigPath && hasExistingConfig ;
150+ const hasNSConfig = ! ! NSConfigPath && hasExistingConfig ;
198151 const usingNSConfig = ! ( hasTSConfig || hasJSConfig ) ;
199152
200153 if ( hasTSConfig && hasJSConfig ) {
@@ -208,9 +161,9 @@ export default {
208161 hasJSConfig,
209162 hasNSConfig,
210163 usingNSConfig,
211- TSConfigPath : paths . TSConfigPath ,
212- JSConfigPath : paths . JSConfigPath ,
213- NSConfigPath : paths . NSConfigPath ,
164+ TSConfigPath,
165+ JSConfigPath,
166+ NSConfigPath,
214167 } ;
215168 }
216169
0 commit comments