(lambda-nodejs): publishing a construct - package-lock.json dependency workaround
See original GitHub issueI don’t think this is really a bug or feature request as it relates to NPM behaviour.
I stumbled a bit trying to package up a NodejsFunction
as a construct because of these two things in conflict:
- states: "One key detail about package-lock.json is that it cannot be published, and it will be ignored if found in any place other than the toplevel package. It shares a format with npm-shrinkwrap.json, which is essentially the same file, but allows publication. "
- aws-lambda-nodejs has a dependency on package-lock.json being present.
For the construct I’m trying to publish, I have the CDK project at the root, and a lambda folder with it’s own src, test folders and package.json.
It’s all kind of awkward, so I thought documenting the best way of packaging this would be helpful. I’m not sure if the way I am doing it is the best way. (Also why this was put here and not stack overflow).
To support testing locally with npm pack
as well as npm publish / install
this is what I came up with:
cdk package.json snippet:
"scripts": {
~
"prepare_lambda": "cd lambda; npm run prepack",
"prepack": "npm run prepare_lambda",
"prebuild": "cd lambda; npm i", // alternatively move lambda to a sibling of the cdk project to avoid compile failures on a fresh clone.
"postinstall": "cd lambda; npm i install --production" // generates the package-lock.json when someone installs the construct
},
"files": [
~
"/lambda/src/**/*.ts",
"/lambda/*.json",
"/lambda/node_modules/*"
],
lambda package.json snippet:
"scripts": {
~
"prepack": "npm i --production" // packages node_modules - but not required if the post install step in the cdk project is kept.
},
"files": [
"node_modules",
"src",
"*.json"
],
The intent was to not have to ‘npm install’ the lambda - and have it packaged in the constructs NPM package. It would all work but I can’t seem to force packaging of the package-lock.json (other than changing it’s name with a klunkier workflow?).
Is this way simpler than I’m making it? If so - can we document this?
This is a 📕 documentation issue
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Ok I see that in the docs now. I must have been stubborn in how I like to keep infra code and app code separate, and didn’t pick up on that initially. For this case I see that.
Thanks for the assist. 😃. I’ll close this up.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.