Enhance caching in setup-node with automatic package manager detection (#1348)

* setup node in local

* Enhance caching in setup-node with package manager filed detection

* updated with array

* update the field
This commit is contained in:
priya-kinthali
2025-08-26 08:10:12 +05:30
committed by GitHub
parent 5e2628c959
commit d7a11313b5
7 changed files with 167 additions and 4 deletions

View File

@@ -135,7 +135,19 @@ It's **always** recommended to commit the lockfile of your package manager for s
## Caching global packages data
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional, and caching is turned off by default.
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional.
Caching is turned on by default when a `packageManager` field is detected in the `package.json` file. The `package-manager-cache` input provides control over this automatic caching behavior. By default, `package-manager-cache` is set to `true`, which enables caching when a valid package manager field is detected in the `package.json` file. To disable this automatic caching, set the `package-manager-cache` input to `false`.
```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
package-manager-cache: false
- run: npm ci
```
> If no valid `packageManager` field is detected in the `package.json` file, caching will remain disabled unless explicitly configured.
The action defaults to search for the dependency file (`package-lock.json`, `npm-shrinkwrap.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories.