Skip to content

Can node_modules be cached if a Node.js version is supplied? #406

Closed
@joneshf

Description

@joneshf

Description:

As I understand the documentation about caching both in this repo and in the upstream actions/cache repo, the reason node_modules is not recommended to cache is because dependencies can break across versions of Node.js.

If the Node.js version changing is the only reason not to cache node_modules can this action take into account the node-version-file (or maybe even the node-version)? If it doesn't exist, don't cache the node_modules directory. If it does exist, cache the node_modules directory but use the value as part of the primaryKey:

const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;

Maybe as like:

const primaryKey = `node-cache-${platform}-${nodeVersionFileHash}-${packageManager}-${fileHash}`;

If the Node.js version changes, the cache should be invalidated and everything rebuilt. Which seems to address the concern the actions/cache repo points out (as I understand it).

Justification:

The current caching strategy doesn't provide a noticeable improvement for non-trivial projects. It'll shave a couple seconds off of a multiple minute build due to needing to download all of the node_modules directory. Ideally, by caching node_modules when it appears safe to do so, the download of node_modules shouldn't need to happen as frequently and caching can save minutes.

Are you willing to submit a PR?

Yes!

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or request to improve the current logic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions