Skip to content

Commit

Permalink
Merge pull request #96 from tommarien/feat/add-optional-lambda-root-path
Browse files Browse the repository at this point in the history
feat: add handlerRoot plugin config
  • Loading branch information
dougmoscrop authored May 11, 2024
2 parents bac37f0 + dfa1a59 commit 84f52de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion include-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 84f52de

Please sign in to comment.