vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26.39k stars 1.84k forks source link

Cache is not used if process exits with code !== 0 #1746

Closed IPWright83 closed 2 years ago

IPWright83 commented 2 years ago

What version of Turborepo are you using?

1.4.3

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Linux

Describe the Bug

If the process exits with a non 0 exit code then Turborepo doesn't use the cache. While sometimes this is desirable, other times it is not and it would be better to use the cache.

This is particularly relevant when running tools such as linters, that encounter lint errors. As the process exits with a code 1, the linter will have to run manually again each time, where-as if the hash hasn't changed we can use the same output from the linter.

Expected Behavior

Turborepo should use the cached output (if requested).

To Reproduce

A noddy (non linting example):

package.json

{
    "scripts": {
       "hello": "turbo run helloWorld",
    }
}

turbo.json:

    "pipeline": {
        "hello": { outputs: [] },
    }

apps/myApp/package.json:

{
    "scripts": "node helloWorld.js",
}

apps/myApp/helloWorld.js:

console.log("Hello World!");
process.exit(1);

Running pnpm hello at the root will never use the cache.

mehulkar commented 2 years ago

What are you expecting to be cached in this example? If I understand correctly, outputs: [] says there are no cache artifacts (except logs).

IPWright83 commented 2 years ago

@mehulkar yes, that's correct. So in this case I'd expect the logs to be cached - so if we were to re-run the same script the log would just repeat. Not very useful with the reproduction, but very useful if just running a linter again.

It's probably related to us using this flag https://eslint.org/docs/latest/user-guide/command-line-interface#--max-warnings which exits with a 1 if there are any warnings.

gsoltis commented 2 years ago

This is working as intended. turbo intentionally does not cache results from scripts that appear to have failed. If you would like to use something other than the exit code from your lint script, you can wrap it with your own script to determine whether or not it has failed and produce an appropriate exit code.