Skip to content

Commit

Permalink
Merge pull request #10 from beforeyoubid/feature/cleanup
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
alice-byb authored Feb 15, 2021
2 parents 59e7868 + a5c707b commit d460d4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beforeyoubid/serverless-step-functions-offline",
"version": "2.4.1",
"version": "2.4.2",
"description": "Serverlesss plugin to support step function offline",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ describe('index.js', () => {
describe('#findState', () => {
it('should throw err - serverless.yml not exists', () => {
// stepFunctionsOfflinePlugin.serverless.config = process.cwd() + '/serverless.test.yml';
expect(stepFunctionsOfflinePlugin.hooks[global['hooks'].findState]).toThrowError(
'Could not find serverless manifest'
stepFunctionsOfflinePlugin.hooks[global['hooks'].findState]().catch(e =>
expect(e.message).toEqual('Could not find serverless manifest')
);
});

Expand Down
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
});
}

getRawConfig(): Promise<any> {
async getRawConfig(): Promise<ServerlessWithError['service']> {
const serverlessPath = this.serverless.config.servicePath;
if (!serverlessPath) {
throw new this.serverless.classes.Error('Could not find serverless manifest');
Expand All @@ -220,9 +220,15 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
`Could not find serverless manifest at path ${serverlessPath}. If this path is incorreect you should adjust the 'servicePath' variable`
);
}

let fromFile: ServerlessWithError['service'];
if (/\.json|\.js$/.test(manifestFilename)) {
return import(manifestFilename);
try {
fromFile = await import(manifestFilename);
return fromFile;
} catch (err) {
console.error(err);
throw new Error(`Unable to import manifest at: ${manifestFilename}`);
}
}

return this.serverless.yamlParser.parse(manifestFilename);
Expand Down Expand Up @@ -288,7 +294,7 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
return { handler: handlerName, filePath };
}

buildStepWorkFlow(): ReturnType<StepFunctionsOfflinePlugin['process']> {
async buildStepWorkFlow(): Promise<ReturnType<StepFunctionsOfflinePlugin['process']>> {
this.cliLog('Building StepWorkFlow');
if (!this.stateDefinition) throw new Error('Missing state definition');
const event = this.loadedEventFile ?? {};
Expand Down Expand Up @@ -359,7 +365,7 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
if (contextObject) {
if (func instanceof Promise) {
return func.then(async mod => {
if (!mod) return;
if (!mod) return contextObject.done(null, {});
let res;
let err;
try {
Expand Down

0 comments on commit d460d4a

Please sign in to comment.