Handling platforms
Node.js versions
To account for Node.js versions, use the engines key in package.json. Turborepo will account for changes to this field and miss cache accordingly.
Operating systems, architecture, and other arbitrary conditions
For advanced use cases, you may want the operating system (OS), architecture, or other external factors to contribute to your hash.
1. Write an arbitrary file to disk
First, create a script that accounts for the hash contributors that you are interested in. For example, here is a Node.js script that identifies platform and architecture and writes those details to a file (turbo-cache-key.json
):
2. Add the file to your .gitignore
You won't want to commit this file to source control since it's dependent on environment. Add it to your .gitignore
:
3. Add the file to the hash
Now, make sure that turbo
is aware of the file by adding it to task inputs. You can do this two ways:
- For specific tasks: Include the file in the
inputs
array of the task(s):
- For all tasks: Add the file to
globalDependencies
4. Generate the file before running turbo
Last, you'll want to ensure that you run the script before running turbo
. For example:
turbo run build
will now take into account the contents of turbo-cache-key.json
when calculating the hash for the build
task.
Was this helpful?