cloudeninc / clouden-cdk-aws-lambda-typescript

TypeScript Build Step for AWS CDK Lambda
MIT License
8 stars 2 forks source link

Excluding Dev Dependencies #3

Open thekevinbrown opened 4 years ago

thekevinbrown commented 4 years ago

Is there any way to exclude dev dependencies from the deployed package when using this?

kennu commented 4 years ago

Hi, sorry for long delay. The default installation method runs npm install --production so it should exclude dev dependencies, although I have note actually tested it. I also just added an option to override the npm install command in case customization is needed.

thekevinbrown commented 4 years ago

In our case it seemed to just take the node_modules folder and push it up. Since this was part of an existing project and I run npm i before I build, this was everything.

Should we be managing our lambdas outside of the folder structure of the project? That seems kind of odd to me.

kennu commented 4 years ago

Hmm.. What is supposed to happen is this sequence:

  1. Your Lambda TypeScript code is in the folder project_dir/lambda (basically any path)
  2. You have a valid project_dir/lambda/tsconfig.json and project_dir/lambda/package.json
  3. You construct the Lambda code asset as TypeScriptCode.asset('project_dir/lambda')
  4. The module will run tsc --project project_dir/lambda --outDir project_dir/lambda/.deploy
  5. The module will copy any copyFiles entries to project_dir/lambda/.deploy
  6. The module will copy package*.json to, and run npm install in, project_dir/lambda/.deploy
  7. At this point project_dir/lambda/.deploy will contain the fully built Lambda function code
  8. The module will pass the asset path project_dir/lambda/.deploy to AWS CDK for deployment
  9. You can verify afterwards that project_dir/lambda/.deploy contains the correct files
thekevinbrown commented 4 years ago

If it runs npm install in step 6, then that'll include dev dependencies, but since you mentioned --production above that's probably not it.

Either way, our experience was that dev dependencies were included. Would a reproduction help here?

kennu commented 4 years ago

It would be most helpful to understand if something is wrong with the command line that is used to run npm install:

https://github.com/cloudeninc/clouden-cdk-aws-lambda-typescript/blob/master/src/typescript-code.ts#L23

Or maybe with some other logic in how the module works?

thekevinbrown commented 4 years ago

Alrighty, I'll make up a repro when I get a chance.