11import { Context , ServerlessIac } from '../types' ;
22import path from 'node:path' ;
3+ import fs from 'node:fs' ;
34import { ProviderEnum } from './providerEnum' ;
45import { AsyncLocalStorage } from 'node:async_hooks' ;
56import { getIamInfo } from './imsClient' ;
@@ -8,12 +9,31 @@ const asyncLocalStorage = new AsyncLocalStorage<Context>();
89
910export const getIacLocation = ( location ?: string ) : string => {
1011 const projectRoot = path . resolve ( process . cwd ( ) ) ;
11- return location
12- ? path . resolve ( projectRoot , location )
13- : path . resolve ( projectRoot , 'serverlessinsight.yml' ) ||
14- path . resolve ( projectRoot , 'serverlessInsight.yml' ) ||
15- path . resolve ( projectRoot , 'ServerlessInsight.yml' ) ||
16- path . resolve ( projectRoot , 'serverless-insight.yml' ) ;
12+ if ( location ) {
13+ const candidate = path . isAbsolute ( location ) ? location : path . resolve ( projectRoot , location ) ;
14+ if ( fs . existsSync ( candidate ) ) {
15+ return candidate ;
16+ }
17+ throw new Error ( `IaC file not found at '${ candidate } '` ) ;
18+ }
19+
20+ const candidates = [
21+ 'serverlessinsight.yml' ,
22+ 'serverlessInsight.yml' ,
23+ 'ServerlessInsight.yml' ,
24+ 'serverless-insight.yml' ,
25+ ] ;
26+
27+ for ( const name of candidates ) {
28+ const candidate = path . resolve ( projectRoot , name ) ;
29+ if ( fs . existsSync ( candidate ) ) {
30+ return candidate ;
31+ }
32+ }
33+
34+ throw new Error (
35+ `No IaC file found. Tried: ${ candidates . map ( ( n ) => `'${ path . resolve ( projectRoot , n ) } '` ) . join ( ', ' ) } ` ,
36+ ) ;
1737} ;
1838
1939export const setContext = async (
0 commit comments