diff --git a/CHANGELOG.md b/CHANGELOG.md index c8643964..9bc84987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.1.1](https://github.com/serverless/serverless-plugin-typescript/compare/v2.1.0...v2.1.1) (2022-01-28) + +### Bug Fixes + +* Fix resolution of `invoke local` related lifecycle hook ([#258](https://github.com/serverless/serverless-plugin-typescript/pull/258)) ([378f3be](https://github.com/serverless/serverless-plugin-typescript/commit/378f3be96f61b98513b6c704047a64caad56d512)) ([Mariusz Nowak](https://github.com/medikoo)) +* Declare explicitly the `--watch` option on `invoke` ([#257](https://github.com/serverless/serverless-plugin-typescript/pull/257)) ([4a9e3dd](https://github.com/serverless/serverless-plugin-typescript/commit/4a9e3dddb1a0228538fa9d8ac88d4addd4f6840a)) ([Matthieu Napoli](https://github.com/mnapoli)) + +### Maintanace Improvements + +* Mark as Serverless Framework v3 compatible ([#264](https://github.com/serverless/serverless-plugin-typescript/pull/264)) ([d32b657](https://github.com/serverless/serverless-plugin-typescript/commit/d32b6573305a107dc1a8a82afe0014492dbb096c)) ([Mariusz Nowak](https://github.com/medikoo)) + ## [2.1.0](https://github.com/serverless/serverless-plugin-typescript/compare/v2.0.0...v2.1.0) (2021-09-23) diff --git a/package.json b/package.json index 72e0f390..f35b7d33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-plugin-typescript", - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "main": "dist/src/index.js", "files": [ @@ -56,7 +56,7 @@ "jest": "24.5.0", "mock-fs": "4.9.0", "rimraf": "2.6.3", - "standard-version": "^9.3.1", + "standard-version": "^9.3.2", "ts-jest": "24.0.2", "tslint": "5.14.0", "typescript": "^3.9.10" @@ -67,7 +67,7 @@ "lodash": "^4.17.21" }, "peerDependencies": { - "serverless": "2", + "serverless": "2 || 3", "typescript": ">=2.2.2" }, "jest": { diff --git a/src/Serverless.d.ts b/src/Serverless.d.ts index f5096921..7c3e9f2d 100644 --- a/src/Serverless.d.ts +++ b/src/Serverless.d.ts @@ -46,7 +46,24 @@ declare namespace Serverless { individually?: boolean } + type CommandsDefinition = Record< + string, + { + lifecycleEvents?: string[] + commands?: CommandsDefinition + usage?: string + options?: { + [name: string]: { + type: string + usage: string + required?: boolean + shortcut?: string + } + } + } + > + interface PluginManager { spawn(command: string): Promise } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 09ec228b..adafe7a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,11 +16,27 @@ export class TypeScriptPlugin { serverless: Serverless.Instance options: Serverless.Options hooks: { [key: string]: Function } + commands: Serverless.CommandsDefinition constructor(serverless: Serverless.Instance, options: Serverless.Options) { this.serverless = serverless this.options = options + this.commands = { + invoke: { + commands: { + local: { + options: { + watch: { + type: 'boolean', + usage: 'Watch file changes and re-invoke automatically the function' + } + } + } + } + } + } + this.hooks = { 'before:run:run': async () => { await this.compileTs() @@ -66,10 +82,9 @@ export class TypeScriptPlugin { }) } }, - 'after:invoke:local:invoke': () => { + 'after:invoke:local:invoke': async () => { if (this.options.watch) { - this.watchFunction() - this.serverless.cli.log('Waiting for changes...') + await this.watchFunction() } } } @@ -117,10 +132,13 @@ export class TypeScriptPlugin { } this.serverless.cli.log(`Watch function ${this.options.function}...`) + this.serverless.cli.log('Waiting for changes...') this.isWatching = true - watchFiles(this.rootFileNames, this.originalServicePath, () => { - this.serverless.pluginManager.spawn('invoke:local') + await new Promise((resolve, reject) => { + watchFiles(this.rootFileNames, this.originalServicePath, () => { + this.serverless.pluginManager.spawn('invoke:local').catch(reject) + }) }) }