-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add alternative command to run npm ci
with cache
#96
base: trunk
Are you sure you want to change the base?
Conversation
@@ -2,13 +2,13 @@ | |||
|
|||
# Ensure package.json is present | |||
if [ ! -f package.json ]; then | |||
echo "No valid package.json file found" | |||
echo "No package.json found!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me being pedantic:
- No validation made on
package.json
- We know that
package.json
is a file
bin/install_npm_packages_clean
Outdated
fi | ||
|
||
# Ensure package-lock.json is present | ||
# TODO: What to do with yarn-based projects? Make the hash on lockfile optional? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess a project using yarn
would not call a command with npm
in the name?
bin/install_npm_packages_clean
Outdated
# TODO: This comes from Studio. Figure out if it's standard in Node or not. | ||
if [ -d patches ]; then | ||
PATCHES_HASH=$(hash_directory patches/) | ||
else | ||
PATCHES_HASH=nopatch | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it isn't a standard approach, it might be worth leaving it here as it adds basically no overhead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI the implementation was inspired by this recommendation: https://www.npmjs.com/package/patch-package#circleci ; so I guess we could consider that "standard" in that regard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice.
I'll add a link to it and remove the todo. Thanks!
LOCAL_NPM_CACHE=./vendor/npm | ||
mkdir -p $LOCAL_NPM_CACHE | ||
echo "--- :npm: Set npm to use $LOCAL_NPM_CACHE for cache" | ||
npm set cache $LOCAL_NPM_CACHE | ||
echo "npm cache set to $(npm get cache)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth making this configurable?
# Default value from npm. | ||
# TODO: Link to source | ||
MAX_SOCKETS=15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code this script was extracted from had the comment about 15 being the default. I had a quick look and couldn't find a reference. Need to look more and document.
See #96 (comment) Co-authored-by: Olivier Halligon <[email protected]>
Mmmm.... 🤔
|
If a project uses `yarn` it should not use the `npm ci` command in CI!
See #96 (comment) Co-authored-by: Olivier Halligon <[email protected]>
Note: I moved the Windows stuff to #100 because there's additional work to be done on that front and I wanted to keep the two streams separated. Sorry for the noise that the rebase created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick / Question: is the goal to keep this new script being called install_npm_packages_clean
? Or is this just for ease of testing the new setup using a temp separate name, but once the PR is ready for review you'll end up removing install_npm_packages
and renaming install_npm_packages_clean
to install_npm_packages
, or alternatively (in case we want to keep the old implementation around for some time, consolidate the two scripts in one and add a --clean
flag or something to allow to switch between the two behaviors?
Asking mostly because I'm not sure I like the naming of …_clean
in that new command… especially since one of its role is to use npm ci
+ save_cache
so us still using the cache doesn't feel like the term "clean" (as in "clean install") is appropriate? Or is it because, while we do use some caching, we only cache the root npm folder with the package downloads… but not the node_modules
, which in a way are clean-installed? Though even if that's the case, it's not completely a clean install since if the cached downloads gets corrupted for some reason that cache will still poison the installed modules and in such case the naming of the helper might be misleadingly make us believe that it couldn't possibly be a case of cache poisoning because the command is named …_clean
…
That being said, I'm not sure I have a suggestion for a better naming that would indicate "clean install of the modules, but still using cache for the downloaded packages"… yet, idk why but even if we keep the "clean" wording, it feels it'd be more logical to have it as a --clean
flag than as a separate command? 🤷
At the moment, I wrote this as a dedicated script to avoid breaking the But like you noticed, it's highly likely the only difference between the two will be whether we call
I wonder if this applies more broadly to our existing naming convention.
|
See #96 (comment) Co-authored-by: Olivier Halligon <[email protected]>
WIP
CHANGELOG.md
if necessary.