From dfa1a59dcc1295e7f6a6805e85abb58bc685ff4b Mon Sep 17 00:00:00 2001 From: Tom Marien Date: Fri, 10 May 2024 15:53:12 +0200 Subject: [PATCH] feat: add handlerRoot plugin config --- README.md | 11 +++++++++++ include-dependencies.js | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 505c145..3559d7a 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,17 @@ custom: includeDependencies: enableCaching: true ``` +## Monorepo + +When building outputs to root directory in a monorepo for instance while using nest-cli, you end up with outputs in `root/dist/app-name`, +this is not how serverless-compose wants it. by default the `this.serverless.config.servicePath` will be the path of app you are building. +Because of that this plugin will not find the handler, you can support this by adding the following + +```yaml +custom: + includeDependencies: + handlerRoot: ../../ +``` ## New In 2.0 - Exclusion Support diff --git a/include-dependencies.js b/include-dependencies.js index bb228bd..ffbe632 100644 --- a/include-dependencies.js +++ b/include-dependencies.js @@ -134,7 +134,10 @@ module.exports = class IncludeDependencies { getHandlerFilename(handler) { const lastDotIndex = handler.lastIndexOf('.'); const handlerPath = lastDotIndex !== -1 ? handler.slice(0, lastDotIndex) : 'index'; - return require.resolve((path.join(this.serverless.config.servicePath, handlerPath))); + + const path = this.getPluginOptions().handlerRoot || this.serverless.config.servicePath; + + return require.resolve((path.join(path, handlerPath))); } getDependencies(fileName, patterns, useCache = false) {