1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# Ensure all environment variables are correctly included in cache keys (`no-undeclared-env-vars`)
Ensures that all detectable usage of environment variables are correctly included in cache keys. This ensures build outputs remain correctly cacheable across environments.
## Rule Details
This rule aims to prevent users from forgetting to include an environment variable in their `turbo.json` configuration.
The following examples assume the following code:
```js
const client = MyAPI({ token: process.env.MY_API_TOKEN });
```
Examples of **incorrect** code for this rule:
```json
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {},
"dev": {
"cache": false
}
}
}
```
Examples of **correct** code for this rule:
```json
{
"globalEnv": ["MY_API_TOKEN"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {},
"dev": {
"cache": false
}
}
}
```
```json
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"env": ["MY_API_TOKEN"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {},
"dev": {
"cache": false
}
}
}
```
## Options
| Option | Required | Default | Details | Example |
| ----------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |
| `allowList` | No | [] | An array of strings (or regular expressions) to exclude. NOTE: an env variable should only be excluded if it has no effect on build outputs | `["MY_API_TOKEN", "^MY_ENV_PREFIX_[A-Z]+$"]` |
## Further Reading
- [Altering Caching Based on Environment Variables](https://turbo.build/repo/docs/core-concepts/caching#altering-caching-based-on-environment-variables)
|