-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe your idea/feature/enhancement
I'd like better support for NPM/Yarn workspaces.
Currently a package-lock.json or npm-shrinkwrap.json file present in the CodeUri for your Lambda function is expected. When using UseNpmCi it's required and sam build will fail with this cryptic error
Build Failed
Error: NodejsNpmEsbuildBuilder:EsbuildBundle - Esbuild Failed: ✘ [ERROR] Invalid build flag: "--use-npm-ci"
When using an NPM workspace the folder structure might look like this:
.
+-- node_modules
+-- package-lock.json
+-- package.json
`-- lambdas
+-- lambda-a
| `-- handler.ts
| `-- package.json
| `-- template.yaml
+-- lambda-b
| `-- handler.ts
| `-- package.json
| `-- template.yaml
Note that package-lock.json and node_modules are only present in the root.
Proposal
sam-cli should take NPM workspaces into consideration. I'm sure some clever things can be done when multiple lambdas are in a NPM workspace as npm i or npm ci only need to be run once for all node_modules to be installed for all package.json files in the workspace. I believe build can be sped up significantly.
Furthermore the requirement for a package-lock.json or npm-shrinkwrap.json file present in the CodeUri is not true for NPM workspaces. Instead it's required at the NPM workspace root.
Actually running npm i or npm ci in a workspace project, fx ~/<root>/lambdas/lambda-a/> npm ci will do the right thing and install packages in ~/<root>/node_modules/ which is very useful!
This might be a bit of a loose proposal but the goal here is to make it work with NPM workspaces. Not only should it work instead of fail, it should utilize the features of NPM workspaces to speed up build time.