Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reproduces the issue where dependsOn does not invalidate cache as expected

License

NotificationsYou must be signed in to change notification settings

rudfoss-rr/nx-cache-dependson-issue

Repository files navigation

This repo demonstrates the issue where a projectsdependsOn chain does not invalidate the upstream cache when changes occur in a downstream project.

The problem occurs if a target defines a dependency on another target in dependencies. Theproject.json inpackages/alpha defines build like this:

"build": {"cache":true,"dependsOn": ["^build"],"inputs": ["project"],"outputs": ["{projectRoot}/built/**"],"executor":"nx:run-commands","options": {"cwd":"{projectRoot}","command":"vite build"  }}

Where the named inputproject defined innx.json is:

"namedInputs": {"project": ["{projectRoot}/**","!{projectRoot}/node_modules/**","!{projectRoot}/built/**"]}

Resulting in this dependency chain:

alpha:build -> bravo:build -> charlie:build

Configured like this I would expect that if the cache key forbravo:build orcharlie:build were to change it would result in an invalidation ofalpha:build as well. Otherwise what would be the point of declaring it as a dependency?

Reproduce the problem

  1. nx reset
  2. Runnx run alpha:build this caches output fromalpha:build,bravo:build andcharlie:build.

First alpha:build run

  1. Runnx run alpha:build again. The cache is used

Cached output used for all build targets

  1. Make a change to charlie:
export const charlie = (message: string) => {+return `Inner wrap changed: ${message}`}
  1. Runnx run alpha:build. Onlycharlie is rebuilt.

Only charlie is rebuilt

This results in a built artifactpackages/alpha/built/alpha.js containing old code.

import*ashttpfrom"node:http";constcharlie=(message)=>{return`Inner wrap:${message}`;// Notice this does not include " changed"};constbravo=(message)=>{returncharlie(`Outer wrap:${message}`);};constport=8088;http.createServer(async(_,res)=>{res.writeHead(200,{"Content-Type":"text/plain","access-control-allow-origin":"*","access-control-allow-methods":"GET, OPTIONS"});res.write(`Hello world @${(/*@__PURE__ */newDate()).toISOString()}From libs:${bravo("Hello from API")}`);res.end();}).listen(port);console.log(`http://localhost:${port}`);

Workaround

I can get the "correct" behaviour by adding^project to the inputs ofbuild inalpha as shown in thealpha:buildChain target, but this would require thatalpha knows what inputs should invalidate all dependent targets up the chain for all projects.

"buildChain": {"cache":true,"dependsOn": ["^build"],"inputs": ["project","^project"],"outputs": ["{projectRoot}/built/**"],"executor":"nx:run-commands","options": {"cwd":"{projectRoot}","command":"vite build"  }}

Using ^projects to depend on chained inputs

This does not seem like a scalable workaround.

About

Reproduces the issue where dependsOn does not invalidate cache as expected

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp