Skip to content

Commit ab04627

Browse files
chore(config): add undocummented remote types to turbo.json schema (#9073)
### Description There has been an undocumented `remoteCache` field in `turbo.json` for quite awhile (at least since 1.10). This PR adds documentation for the it. ### Testing Instructions Added unit tests to verify that when these are set in `turbo.json` they are respected in the built config.
1 parent c69bb16 commit ab04627

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

crates/turborepo-lib/src/config.rs

+46
Original file line numberDiff line numberDiff line change
@@ -1050,4 +1050,50 @@ mod test {
10501050
assert_eq!(config.token().unwrap(), vercel_artifacts_token);
10511051
assert_eq!(config.spaces_id().unwrap(), "my-spaces-id");
10521052
}
1053+
1054+
#[test]
1055+
fn test_turbo_json_remote_cache() {
1056+
let tmp_dir = TempDir::new().unwrap();
1057+
let repo_root = AbsoluteSystemPathBuf::try_from(tmp_dir.path()).unwrap();
1058+
1059+
let api_url = "url1";
1060+
let login_url = "url2";
1061+
let team_slug = "my-slug";
1062+
let team_id = "an-id";
1063+
let turbo_json_contents = serde_json::to_string_pretty(&serde_json::json!({
1064+
"remoteCache": {
1065+
"enabled": true,
1066+
"apiUrl": api_url,
1067+
"loginUrl": login_url,
1068+
"teamSlug": team_slug,
1069+
"teamId": team_id,
1070+
"signature": true,
1071+
"preflight": false,
1072+
"timeout": 123
1073+
}
1074+
}))
1075+
.unwrap();
1076+
repo_root
1077+
.join_component("turbo.json")
1078+
.create_with_contents(&turbo_json_contents)
1079+
.unwrap();
1080+
1081+
let builder = TurborepoConfigBuilder {
1082+
repo_root,
1083+
override_config: ConfigurationOptions::default(),
1084+
global_config_path: None,
1085+
environment: HashMap::default(),
1086+
};
1087+
1088+
let config = builder.build().unwrap();
1089+
// Directly accessing field to make sure we're not getting the default value
1090+
assert_eq!(config.enabled, Some(true));
1091+
assert_eq!(config.api_url(), api_url);
1092+
assert_eq!(config.login_url(), login_url);
1093+
assert_eq!(config.team_slug(), Some(team_slug));
1094+
assert_eq!(config.team_id(), Some(team_id));
1095+
assert!(config.signature());
1096+
assert!(!config.preflight());
1097+
assert_eq!(config.timeout(), 123);
1098+
}
10531099
}

docs/repo-docs/reference/configuration.mdx

+53
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,56 @@ This task is most useful for scripts that can be manipulated while they are runn
476476
}
477477
}
478478
```
479+
480+
## Remote caching
481+
482+
The global `remoteCache` option has a variety of fields for configuring remote cache usage
483+
484+
```jsonc title="./turbo.json"
485+
{
486+
"remoteCache": {}
487+
}
488+
```
489+
490+
### `enabled`
491+
492+
Default: `true`
493+
494+
Enables remote caching.
495+
496+
When `false`, Turborepo will disable all remote cache operations, even if the repo has a valid token.
497+
If true, remote caching is enabled, but still requires the user to login and link their repo to a remote cache.
498+
499+
### `signature`
500+
501+
Default: `false`
502+
503+
Enables signature verification for requests to the remote cache.
504+
When `true`, Turborepo will sign every uploaded artifact using the value of the environment variable `TURBO_REMOTE_CACHE_SIGNATURE_KEY`.
505+
Turborepo will reject any downloaded artifacts that have an invalid signature or are missing a signature.
506+
507+
### `preflight`
508+
509+
Default: `false`
510+
511+
When enabled, any HTTP request will be preceded by an OPTIONS request to determine if the request is supported by the endpoint.
512+
513+
### `timeout`
514+
515+
Default: `30`
516+
517+
Sets a timeout for remote cache operations.
518+
Value is given in seconds and only whole values are accepted.
519+
If `0` is passed, then there is no timeout for any cache operations.
520+
521+
### `apiUrl`
522+
523+
Default: `"https://vercel.com"`
524+
525+
Set endpoint for API calls to the remote cache.
526+
527+
### `loginUrl`
528+
529+
Default: `"https://vercel.com"`
530+
531+
Set endpoint for requesting tokens during `turbo login`.

packages/turbo-types/schemas/schema.json

+16
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@
171171
"enabled": {
172172
"type": "boolean",
173173
"description": "Indicates if the remote cache is enabled. When `false`, Turborepo will disable all remote cache operations, even if the repo has a valid token. If true, remote caching is enabled, but still requires the user to login and link their repo to a remote cache. Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching"
174+
},
175+
"preflight": {
176+
"type": "boolean",
177+
"description": "When enabled, any HTTP request will be preceded by an OPTIONS request to determine if the request is supported by the endpoint.\n\nDocumentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests"
178+
},
179+
"apiUrl": {
180+
"type": "string",
181+
"description": "Set endpoint for API calls to the remote cache. Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching#self-hosting"
182+
},
183+
"loginUrl": {
184+
"type": "string",
185+
"description": "Set endpoint for requesting tokens during `turbo login`. Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching#self-hosting"
186+
},
187+
"timeout": {
188+
"type": "number",
189+
"description": "Sets a timeout for remote cache operations. Value is given in seconds and only whole values are accepted. If `0` is passed, then there is no timeout for any cache operations."
174190
}
175191
},
176192
"additionalProperties": false

packages/turbo-types/schemas/schema.v2.json

+16
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@
171171
"enabled": {
172172
"type": "boolean",
173173
"description": "Indicates if the remote cache is enabled. When `false`, Turborepo will disable all remote cache operations, even if the repo has a valid token. If true, remote caching is enabled, but still requires the user to login and link their repo to a remote cache. Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching"
174+
},
175+
"preflight": {
176+
"type": "boolean",
177+
"description": "When enabled, any HTTP request will be preceded by an OPTIONS request to determine if the request is supported by the endpoint.\n\nDocumentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests"
178+
},
179+
"apiUrl": {
180+
"type": "string",
181+
"description": "Set endpoint for API calls to the remote cache. Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching#self-hosting"
182+
},
183+
"loginUrl": {
184+
"type": "string",
185+
"description": "Set endpoint for requesting tokens during `turbo login`. Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching#self-hosting"
186+
},
187+
"timeout": {
188+
"type": "number",
189+
"description": "Sets a timeout for remote cache operations. Value is given in seconds and only whole values are accepted. If `0` is passed, then there is no timeout for any cache operations."
174190
}
175191
},
176192
"additionalProperties": false

packages/turbo-types/src/types/config-v2.ts

+32
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,38 @@ export interface RemoteCache {
304304
* @defaultValue `true`
305305
*/
306306
enabled?: boolean;
307+
308+
/**
309+
* When enabled, any HTTP request will be preceded by an OPTIONS request to
310+
* determine if the request is supported by the endpoint.
311+
*
312+
* Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests
313+
*
314+
* @defaultValue `false`
315+
*/
316+
preflight?: boolean;
317+
/**
318+
* Set endpoint for API calls to the remote cache.
319+
* Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching#self-hosting
320+
*
321+
* @defaultValue `"https://vercel.com/api"`
322+
*/
323+
apiUrl?: string;
324+
/**
325+
* Set endpoint for requesting tokens during `turbo login`.
326+
* Documentation: https://turbo.build/repo/docs/core-concepts/remote-caching#self-hosting
327+
*
328+
* @defaultValue `"https://vercel.com"`
329+
*/
330+
loginUrl?: string;
331+
/**
332+
* Sets a timeout for remote cache operations. Value is given in seconds and
333+
* only whole values are accepted. If `0` is passed, then there is no timeout
334+
* for any cache operations.
335+
*
336+
* @defaultValue `30`
337+
*/
338+
timeout?: number;
307339
}
308340

309341
export const isRootSchemaV2 = (schema: Schema): schema is RootSchema =>

0 commit comments

Comments
 (0)