Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,576
Community Members
 
Community Events
176
Community Groups

Pipelines: cache custom node_modules folder

Do I understand correctly that pre-defined `node` cache only works when node_modules and package.json are located in the root directory of a project? Then how do I configure bitbucket-pipelines.yml to make cache work with node_modules folder located in subfolder (./public/node_modules/)? 

1 answer

1 accepted

6 votes
Answer accepted

Managed to solve it

 

with:

...
- step
caches:
- node-custom
script:
- if [ ! -d "node_modules" ]; then npm install; fi
...

definitions:
caches:
node-custom: public/node_modules

Will that not cause problems if package.json is updated as the node_modules won't be re-generated once cached?

It will. You need to manually delete your cached dependencies using the UI.

There sure must be a way how to delete it automatically when package-lock.json changes?

@Petr Pelleractually, you don't need that line:

- if [ ! -d "node_modules" ]; then npm install; fi

Because the npm knows when to install/remove packages, I just changed this line by simply:

- npm install

And it works fine for me.

Like Roman likes this

I got on this problem while trying to set up a monorepo. And even more - i want to spare the execution of costly npm command. So I generated MD5 hash of the package-lock.json and then cache node_modules AND the MD5 hash. So far looks to be working fine. 

definitions:
caches:
app1: app1/node_modules
app1-cache-key: app1/package-lock.md5

pipelines:
branches:
dev:
- step:
script:
- cd app1
- package-lock.md5
- if [[ $(cat package-lock.md5 || '') != $(md5 package-lock.json) ]]; then npm ci && echo "$(md5 package-lock.json)" > package-lock.md5 ; fi

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events