Skip to content

Commit

Permalink
Merge pull request #690 from pimterry/patch-1
Browse files Browse the repository at this point in the history
Simplify the Node.js NPM caching example
  • Loading branch information
Vipul authored and GitHub committed May 26, 2022
2 parents 455d267 + ccaf2d8 commit 14c4fd4
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
- [Java - Gradle](#java---gradle)
- [Java - Maven](#java---maven)
- [Node - npm](#node---npm)
- [macOS and Ubuntu](#macos-and-ubuntu)
- [Windows](#windows-3)
- [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config)
- [Node - Lerna](#node---lerna)
- [Node - Yarn](#node---yarn)
- [Node - Yarn 2](#node---yarn-2)
Expand Down Expand Up @@ -259,40 +256,12 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba

## Node - npm

For npm, cache files are stored in `~/.npm` on Posix, or `~\AppData\npm-cache` on Windows. See https://docs.npmjs.com/cli/cache#cache
For npm, cache files are stored in `~/.npm` on Posix, or `~\AppData\npm-cache` on Windows, but it's possible to use `npm config get cache` to find the path on any platform. See [the npm docs](https://docs.npmjs.com/cli/cache#cache) for more details.

If using `npm config` to retrieve the cache directory, ensure you run [actions/setup-node](https://github.com/actions/setup-node) first to ensure your `npm` version is correct.

>Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci`

### macOS and Ubuntu

```yaml
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
```

### Windows

```yaml
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
```

### Using multiple systems and `npm config`

```yaml
- name: Get npm cache directory
id: npm-cache-dir
Expand Down

0 comments on commit 14c4fd4

Please sign in to comment.