Circle ci restore/save cache for multiple node_modules

nodejs
docker
config

#1

Hi, I am currently working on a monorepo and attempting to get it set up with circleci. it has the following structure

src/
| package.json
| node_modules
| packages/
| – package1
| ---- package.json
| ---- node_modules
| – package2
| ---- package.json
| ---- node_modules
… (repeated 2 more time)

What I want to be able to do is store each node_modules folder individually in the cache, however whenever my restore cache runs at the moment it is just hanging and doing nothing.

my config.yml looks like this

  - restore_cache:
          keys:
            - '{{ checksum  "/src/package.json" }}'
      - restore_cache:
          keys:
            - '{{ checksum "/src/packages/package1/package.json" }}'
      - restore_cache:
          keys:
            - '{{ checksum "/src/packages/package2/package.json" }}'
      - restore_cache:
          keys:
            - '{{ checksum "/src/packages/package3/package.json" }}'
      - restore_cache:
          keys:
            - '{{ checksum "/src/packages/package4/package.json" }}'

     - run: npm install (... installs all node_modules for each package)

      - save_cache:
          key: '{{ checksum  "package.json" }}'
          paths:
            - /src/node_modules
      - save_cache:
          key: '{{ checksum "/src/packages/package1/package.json" }}'
          paths:
            - /src/packages/package1/node_modules
      - save_cache:
          key: '{{ checksum "/src/packages/package2/package.json" }}'
          paths:
            - /src/packages/package2/node_modules
      - save_cache:
          key: '{{ checksum "/src/packages/package3/package.json" }}'
          paths:
            - /src/packages/package3/node_modules
      - save_cache:
          key: '{{ checksum "/src/packages/package4/package.json" }}'
          paths:
            - /src/packages/package4/node_modules

any help would be great, I’m not entirely sure what the issue is, however I suspect it could be something to do with the checksum not working as intended


#2

I hope this could help you, did the same without any other commands:

dependencies:
  cache_directories:
    - node_modules
    - packages/package1/node_modules
    - packages/package2/node_modules
    - packages/package3/node_modules
    - packages/package4/node_modules

unfortunately didn’t find a solution with wildcard something like that didn’t work for me:

dependencies:
  cache_directories:
    - **/node_modules/**
    #or 
    - node_modules/**
    #or etc.

#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.