Skip to content

Instantly share code, notes, and snippets.

@stevehanson
Last active February 27, 2019 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevehanson/ff70ca54fc2aadfe67f3e3e730161350 to your computer and use it in GitHub Desktop.
Save stevehanson/ff70ca54fc2aadfe67f3e3e730161350 to your computer and use it in GitHub Desktop.
Circle CI config for Create React App
version: 2
jobs:
build:
docker:
- image: circleci/node:10.11.0
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
- run:
name: Setup Dependencies
command: yarn install
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- run:
name: Run Test
command: yarn test
@SViccari
Copy link

Thanks! In the CircleCI docs, the restore_cache, and save_cache reference the package.json file instead of the yarn.lock file. I imagine we want to rebuild the cache when the yarn.lock file changes but I'm not confident. Do you happen to know when we want to watch the package.json file vs the yarn.lock file?

@stevehanson
Copy link
Author

yarn.lock seems a bit safer to me, just since it represents exactly which dependencies to download.

At least in my case, there are times when the package.json doesn't change, but the yarn.lock does, since we have a dependency on another internal GitHub repo that isn't versioned. When we upgrade that dependency via yarn upgrade ..., the package.json stays unchanged, but the lockfile changes, pointing to the latest git commit of that dependency.

You could always watch both I think with dependency-cache-{{ checksum "yarn.lock" }}-{{ checksum "package.json" }} to be extra safe. Hope that helps!

@SViccari
Copy link

super helpful, thank you! 🌸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment