Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only publish required files #389

Closed
wants to merge 1 commit into from
Closed

Only publish required files #389

wants to merge 1 commit into from

Conversation

willfarrell
Copy link

@willfarrell willfarrell commented Jan 1, 2021

See https://docs.npmjs.com/cli/v6/configuring-npm/package-json#files for details. Every little bit to improve lambda cold start times.

@willfarrell willfarrell mentioned this pull request Jan 1, 2021
63 tasks
Copy link
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All files are required - npm explore foo && npm install && npm test should always work.###

Comment on lines +14 to +17
"files":[
"dist",
"lib"
],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files field is dangerous; it means needed files could be accidentally omitted. The only danger of .npmignore is that an unneeded file is unnecessarily included.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed the npm ignore file.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np, unfortunately npm's own docs recommend "files", but it's the more dangerous approach.

@ljharb
Copy link
Owner

ljharb commented Jan 1, 2021

Duplicate of #356. Duplicate of #250.

The only files that currently show up in npm pack --dry-run that could be excluded are .github/workflows/rebase.yml and .github/FUNDING.yml - every other file is 100% necessary in the published package.

@ljharb ljharb closed this Jan 1, 2021
@ljharb
Copy link
Owner

ljharb commented Jan 1, 2021

Separately, "cold start time" is a runtime concern, and excluding files from the published tarball has no bearing on cold start times - only (imperceptibly) on install times.

@willfarrell
Copy link
Author

Thanks for the quick reply and detailed explanation. Everyone should be bundling their code in which case it doesn't have an impact on cold start time as you stated above. However, this isn't always the case and people package up everything and ship it. Will an extra 1-3kb make a difference, of course not, but when 100s of packages have extra file, they can add up to MB which can impact cold starts in my experience.

I'm mostly trying to micro optimize for those less experienced developers that end up using middy.js v2. Thanks for taking the time to review.

@ljharb
Copy link
Owner

ljharb commented Jan 1, 2021

I'm not talking about bundling - files on disk that are never required hav e zero impact on start time, because they're never touched.

It is, quite simply, impossible for a cold start to be impacted by unused files, unless you're including npm install time, or "upload and extract the deploy artifact" in start time, neither of which is typically included in that metric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants