Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

node cache bitbucket pipeline on new modules

alexwonguhuru
Contributor
June 27, 2018

Let's say I have cache enabled in bitbucket pipeline.

I have an npm module called `some-module@1.0.0` cached in it.

If I update the module to `some-module@2.0.0` and push it to bitbucket, will bitbucket pipeline ignore it and use the cached build of `some-module@1.0.0`?

 

Thanks

1 answer

1 vote
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 23, 2018

Hi Alex,

I don't use npm frequently, so it's possibly I've made a mistake somewhere here.

npm has some different behaviours depending on what command you run.

But in general npm follows the dependency rules set in your package.json.

Here's a reference of how the rules work: https://docs.npmjs.com/files/package.json#dependencies

tl;dir:

  • Having a package-lock.json will set the versions to always match whatever is defined in the file. If the version is updated in the lock, then it'll be updated in your pipeline.
    • If the package-lock.json is updated to have 2.0.0 then that will be installed.
  • 'npm install' will not install any packages already present in the node_modules cache. 
    • If the 1.0.0 dependency is downloaded in the cache, it will not be replaced with 2.0.0
  • 'npm update' will install the latest versions of packages that fit the semantic versioning rules defined in your package.json
    • If the semantic versioning rules support a 1.0.0 -> 2.0.0 update, then 2.0.0 will be used. Otherwise the dependency will stay as 1.0.0.

 

The following information assumes you don't have a package-lock.json file.

 

npm install:

If you are using 'npm install', then you will always use the local node_modules if it is retrieved via the cache exists. If a package is not present in the node_modules directory, then it will be installed. Otherwise it will follow the same rules I mention in the "npm update" section.

npm update:

npm will install the latest package based on the dependency rules set in your package.json.

For example:

  • If you have a dependency with the rule 
    • "some-module" : ">=1.0.0"
    • Then the dependency that is used will be 2.0.0 when running npm update.
  • If you have a dependency with the rule
    • "some-module" : "^1.0.0
    • Then the dependency will not be 2.0.0 (and will remain as 1.0.0 in your case) when running npm update.

Using npm update is good if you don't want to use dependencies that may break your pipeline.

List of references, if you'd like to do more reading:

 

You can test out this behaviour locally, as Pipelines will follow the same rules as in a local bash environment.

It's also worth noting that Pipelines caches expire after a week.

Thanks,

Phil

alexwonguhuru
Contributor
July 24, 2018

Hello Phil,

Thank you very much for the detailed answer. I will test it out when I update my modules next time.

Cheers,

Alex

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events