Skip to content

Commit d460d4a

Browse files
author
Alice
authored
Merge pull request #10 from beforeyoubid/feature/cleanup
code cleanup
2 parents 59e7868 + a5c707b commit d460d4a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beforeyoubid/serverless-step-functions-offline",
3-
"version": "2.4.1",
3+
"version": "2.4.2",
44
"description": "Serverlesss plugin to support step function offline",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/__tests__/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ describe('index.js', () => {
8686
describe('#findState', () => {
8787
it('should throw err - serverless.yml not exists', () => {
8888
// stepFunctionsOfflinePlugin.serverless.config = process.cwd() + '/serverless.test.yml';
89-
expect(stepFunctionsOfflinePlugin.hooks[global['hooks'].findState]).toThrowError(
90-
'Could not find serverless manifest'
89+
stepFunctionsOfflinePlugin.hooks[global['hooks'].findState]().catch(e =>
90+
expect(e.message).toEqual('Could not find serverless manifest')
9191
);
9292
});
9393

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
203203
});
204204
}
205205

206-
getRawConfig(): Promise<any> {
206+
async getRawConfig(): Promise<ServerlessWithError['service']> {
207207
const serverlessPath = this.serverless.config.servicePath;
208208
if (!serverlessPath) {
209209
throw new this.serverless.classes.Error('Could not find serverless manifest');
@@ -220,9 +220,15 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
220220
`Could not find serverless manifest at path ${serverlessPath}. If this path is incorreect you should adjust the 'servicePath' variable`
221221
);
222222
}
223-
223+
let fromFile: ServerlessWithError['service'];
224224
if (/\.json|\.js$/.test(manifestFilename)) {
225-
return import(manifestFilename);
225+
try {
226+
fromFile = await import(manifestFilename);
227+
return fromFile;
228+
} catch (err) {
229+
console.error(err);
230+
throw new Error(`Unable to import manifest at: ${manifestFilename}`);
231+
}
226232
}
227233

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

291-
buildStepWorkFlow(): ReturnType<StepFunctionsOfflinePlugin['process']> {
297+
async buildStepWorkFlow(): Promise<ReturnType<StepFunctionsOfflinePlugin['process']>> {
292298
this.cliLog('Building StepWorkFlow');
293299
if (!this.stateDefinition) throw new Error('Missing state definition');
294300
const event = this.loadedEventFile ?? {};
@@ -359,7 +365,7 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
359365
if (contextObject) {
360366
if (func instanceof Promise) {
361367
return func.then(async mod => {
362-
if (!mod) return;
368+
if (!mod) return contextObject.done(null, {});
363369
let res;
364370
let err;
365371
try {

0 commit comments

Comments
 (0)