@@ -203,6 +203,19 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
203203 } ) ;
204204 }
205205
206+ private parseYaml < T > ( filename : string ) : Promise < T > {
207+ return this . serverless . yamlParser . parse ( filename ) ;
208+ }
209+
210+ private serverlessFileExists ( filename ) {
211+ const serverlessPath = this . serverless . config . servicePath ;
212+ if ( ! serverlessPath ) {
213+ throw new this . serverless . classes . Error ( 'Could not find serverless manifest' ) ;
214+ }
215+ const fullPath = path . join ( serverlessPath , filename ) ;
216+ return this . serverless . utils . fileExistsSync ( fullPath ) ;
217+ }
218+
206219 async getRawConfig ( ) : Promise < ServerlessWithError [ 'service' ] > {
207220 const serverlessPath = this . serverless . config . servicePath ;
208221 if ( ! serverlessPath ) {
@@ -211,27 +224,24 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
211224
212225 const manifestFilenames = [ 'serverless.yaml' , 'serverless.yml' , 'serverless.json' , 'serverless.js' ] ;
213226
214- const manifestFilename = manifestFilenames
215- . map ( filename => path . join ( serverlessPath , filename ) )
216- . find ( filename => this . serverless . utils . fileExistsSync ( filename ) ) ;
217-
227+ const manifestFilename = manifestFilenames . find ( name => this . serverlessFileExists ( name ) ) ;
218228 if ( ! manifestFilename ) {
219229 throw new this . serverless . classes . Error (
220230 `Could not find serverless manifest at path ${ serverlessPath } . If this path is incorreect you should adjust the 'servicePath' variable`
221231 ) ;
222232 }
233+ const manifestPath = path . join ( serverlessPath , manifestFilename ) ;
223234 let fromFile : ServerlessWithError [ 'service' ] ;
224- if ( / \. j s o n | \. j s $ / . test ( manifestFilename ) ) {
235+ if ( / \. j s o n | \. j s $ / . test ( manifestPath ) ) {
225236 try {
226- fromFile = await import ( manifestFilename ) ;
237+ fromFile = await import ( manifestPath ) ;
227238 return fromFile ;
228239 } catch ( err ) {
229240 console . error ( err ) ;
230- throw new Error ( `Unable to import manifest at: ${ manifestFilename } ` ) ;
241+ throw new Error ( `Unable to import manifest at: ${ manifestPath } ` ) ;
231242 }
232243 }
233-
234- return this . serverless . yamlParser . parse ( manifestFilename ) ;
244+ return this . parseYaml < ServerlessWithError [ 'service' ] > ( manifestPath ) ;
235245 }
236246
237247 parseConfig ( ) : Promise < void > {
0 commit comments