@@ -187,37 +187,42 @@ export const toCamelCase = (text: string): string => {
187
187
} ;
188
188
189
189
const readBsConfig = ( projDir : p . DocumentUri ) => {
190
- let bsconfigFile = fs . readFileSync (
191
- path . join ( projDir , c . bsconfigPartialPath ) ,
192
- { encoding : "utf-8" }
193
- ) ;
190
+ try {
191
+ let bsconfigFile = fs . readFileSync (
192
+ path . join ( projDir , c . bsconfigPartialPath ) ,
193
+ { encoding : "utf-8" }
194
+ ) ;
194
195
195
- return JSON . parse ( bsconfigFile ) ;
196
+ let result = JSON . parse ( bsconfigFile ) ;
197
+ return result ;
198
+ } catch ( e ) {
199
+ return null ;
200
+ }
196
201
} ;
197
202
198
203
export const getNamespaceNameFromBsConfig = (
199
204
projDir : p . DocumentUri
200
205
) : execResult => {
201
- try {
202
- let bsconfig = readBsConfig ( projDir ) ;
203
- let result = "" ;
204
-
205
- if ( bsconfig . namespace === true ) {
206
- result = toCamelCase ( bsconfig . name ) ;
207
- } else if ( typeof bsconfig . namespace === "string" ) {
208
- result = toCamelCase ( bsconfig . namespace ) ;
209
- }
206
+ let bsconfig = readBsConfig ( projDir ) ;
207
+ let result = "" ;
210
208
211
- return {
212
- kind : "success" ,
213
- result,
214
- } ;
215
- } catch ( e ) {
209
+ if ( ! bsconfig ) {
216
210
return {
217
211
kind : "error" ,
218
- error : e instanceof Error ? e . message : String ( e ) ,
212
+ error : "Could not read bsconfig" ,
219
213
} ;
220
214
}
215
+
216
+ if ( bsconfig . namespace === true ) {
217
+ result = toCamelCase ( bsconfig . name ) ;
218
+ } else if ( typeof bsconfig . namespace === "string" ) {
219
+ result = toCamelCase ( bsconfig . namespace ) ;
220
+ }
221
+
222
+ return {
223
+ kind : "success" ,
224
+ result,
225
+ } ;
221
226
} ;
222
227
223
228
export let createInterfaceFileUsingValidBscExePath = (
@@ -251,54 +256,54 @@ export let getCompiledFilePath = (
251
256
filePath : string ,
252
257
projDir : string
253
258
) : execResult => {
254
- try {
255
- let bsConfig = readBsConfig ( projDir ) ;
256
-
257
- let pkgSpecs = bsConfig [ "package-specs" ] ;
258
- let pathFragment = "" ;
259
- let moduleFormatObj : any = { } ;
260
-
261
- let module = c . bsconfigModuleDefault ;
262
- let suffix = c . bsconfigSuffixDefault ;
263
-
264
- if ( pkgSpecs && pkgSpecs . module ) {
265
- moduleFormatObj = pkgSpecs ;
266
- } else if ( pkgSpecs && pkgSpecs [ 0 ] ) {
267
- if ( typeof pkgSpecs [ 0 ] === "string" ) {
268
- module = pkgSpecs [ 0 ] ;
269
- } else {
270
- moduleFormatObj = pkgSpecs [ 0 ] ;
271
- }
272
- }
259
+ let bsconfig = readBsConfig ( projDir ) ;
273
260
274
- if ( moduleFormatObj [ "module" ] ) {
275
- module = moduleFormatObj [ "module" ] ;
276
- }
261
+ if ( ! bsconfig ) {
262
+ return {
263
+ kind : "error" ,
264
+ error : "Could not read bsconfig" ,
265
+ } ;
266
+ }
277
267
278
- if ( ! moduleFormatObj [ "in-source" ] ) {
279
- pathFragment = "lib/" + module . replace ( "-" , "_" ) ;
280
- }
268
+ let pkgSpecs = bsconfig [ "package-specs" ] ;
269
+ let pathFragment = "" ;
270
+ let moduleFormatObj : any = { } ;
271
+
272
+ let module = c . bsconfigModuleDefault ;
273
+ let suffix = c . bsconfigSuffixDefault ;
281
274
282
- if ( moduleFormatObj . suffix ) {
283
- suffix = moduleFormatObj . suffix ;
284
- } else if ( bsConfig . suffix ) {
285
- suffix = bsConfig . suffix ;
275
+ if ( pkgSpecs && pkgSpecs . module ) {
276
+ moduleFormatObj = pkgSpecs ;
277
+ } else if ( pkgSpecs && pkgSpecs [ 0 ] ) {
278
+ if ( typeof pkgSpecs [ 0 ] === "string" ) {
279
+ module = pkgSpecs [ 0 ] ;
280
+ } else {
281
+ moduleFormatObj = pkgSpecs [ 0 ] ;
286
282
}
283
+ }
287
284
288
- let partialFilePath = filePath . split ( projDir ) [ 1 ] ;
289
- let compiledPartialPath = replaceFileExtension ( partialFilePath , suffix ) ;
290
- let result = path . join ( projDir , pathFragment , compiledPartialPath ) ;
285
+ if ( moduleFormatObj [ "module" ] ) {
286
+ module = moduleFormatObj [ "module" ] ;
287
+ }
291
288
292
- return {
293
- kind : "success" ,
294
- result,
295
- } ;
296
- } catch ( e ) {
297
- return {
298
- kind : "error" ,
299
- error : e instanceof Error ? e . message : String ( e ) ,
300
- } ;
289
+ if ( ! moduleFormatObj [ "in-source" ] ) {
290
+ pathFragment = "lib/" + module . replace ( "-" , "_" ) ;
291
+ }
292
+
293
+ if ( moduleFormatObj . suffix ) {
294
+ suffix = moduleFormatObj . suffix ;
295
+ } else if ( bsconfig . suffix ) {
296
+ suffix = bsconfig . suffix ;
301
297
}
298
+
299
+ let partialFilePath = filePath . split ( projDir ) [ 1 ] ;
300
+ let compiledPartialPath = replaceFileExtension ( partialFilePath , suffix ) ;
301
+ let result = path . join ( projDir , pathFragment , compiledPartialPath ) ;
302
+
303
+ return {
304
+ kind : "success" ,
305
+ result,
306
+ } ;
302
307
} ;
303
308
304
309
export let runBuildWatcherUsingValidBuildPath = (
0 commit comments