Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow for specifying path of root turbo.json #9087

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f4d3120
chore: change turbo.json parse to take string instead of anchored path
chris-olszewski Aug 28, 2024
8d9a8d1
chore: read turbo.json using absolute paths
chris-olszewski Aug 28, 2024
752af61
chore(task access): make repo root private
chris-olszewski Aug 28, 2024
2dff810
chore(turbo.json): use absolute path for loading turbo.json
chris-olszewski Aug 28, 2024
fef536e
chore(task trace): move loading of task trace out of primary load path
chris-olszewski Aug 29, 2024
f9c6741
chore: reverse config layering reading order
chris-olszewski Aug 29, 2024
1aa8518
chore(config): move config to own module
chris-olszewski Aug 29, 2024
d3bf1a8
chore(config): break up config module
chris-olszewski Aug 29, 2024
c61458f
chore(config): remove conditional compilation test overrides
chris-olszewski Aug 29, 2024
a80bbaa
chore(config): make use of config trait
chris-olszewski Aug 29, 2024
e1e9c27
chore(config): delay calculation of config options until folding
chris-olszewski Aug 29, 2024
e836da6
chore(config): refactor env config to reduce allocations
chris-olszewski Aug 29, 2024
541e524
chore(config): factor in existing config during construction
chris-olszewski Aug 30, 2024
021ec7b
feat: allow for specifying path of root turbo.json
chris-olszewski Aug 30, 2024
5266e25
chore: add integration test for non-root turbo.json
chris-olszewski Sep 3, 2024
e2e43a9
fix(config): bubble up any errors from fetching a config option
chris-olszewski Sep 3, 2024
b452c1e
Update turborepo-tests/integration/tests/run/no-root-turbo.t
chris-olszewski Sep 3, 2024
8b24137
chore: update comment
chris-olszewski Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use miette::{Diagnostic, NamedSource, SourceSpan};
use serde::Deserialize;
use struct_iterable::Iterable;
use thiserror::Error;
use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPath, RelativeUnixPath};
use turbopath::{AbsoluteSystemPathBuf, RelativeUnixPath};
use turborepo_auth::{TURBO_TOKEN_DIR, TURBO_TOKEN_FILE, VERCEL_TOKEN_DIR, VERCEL_TOKEN_FILE};
use turborepo_dirs::{config_dir, vercel_config_dir};
use turborepo_errors::TURBO_SITE;
Expand Down Expand Up @@ -777,7 +777,7 @@ impl TurborepoConfigBuilder {

let turbo_json = RawTurboJson::read(
&self.repo_root,
AnchoredSystemPath::new("turbo.json").unwrap(),
&self.repo_root.join_component("turbo.json"),
)
.or_else(|e| {
if let Error::Io(e) = &e {
Expand Down
26 changes: 18 additions & 8 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,16 @@ impl TryFrom<RawTaskDefinition> for TaskDefinition {
impl RawTurboJson {
pub(crate) fn read(
repo_root: &AbsoluteSystemPath,
path: &AnchoredSystemPath,
path: &AbsoluteSystemPath,
) -> Result<RawTurboJson, Error> {
let absolute_path = repo_root.resolve(path);
let contents = absolute_path.read_to_string()?;
let raw_turbo_json = RawTurboJson::parse(&contents, path.as_str())?;
let contents = path.read_to_string()?;
// Anchoring the path can fail if paths reside on different drives.
chris-olszewski marked this conversation as resolved.
Show resolved Hide resolved
// Just display absolute path in that case.
let root_relative_path = repo_root.anchor(path).map_or_else(
|_| path.as_str().to_owned(),
|relative| relative.to_string(),
);
let raw_turbo_json = RawTurboJson::parse(&contents, &root_relative_path)?;

Ok(raw_turbo_json)
}
Expand Down Expand Up @@ -544,9 +549,14 @@ impl TurboJson {
root_package_json: &PackageJson,
include_synthesized_from_root_package_json: bool,
) -> Result<TurboJson, Error> {
let turbo_from_files = Self::read(repo_root, &dir.join_component(CONFIG_FILE));
let turbo_from_trace =
Self::read(repo_root, &dir.join_components(&TASK_ACCESS_CONFIG_PATH));
let turbo_json_path = repo_root.resolve(dir).join_component(CONFIG_FILE);
let turbo_from_files = Self::read(repo_root, &turbo_json_path);
let turbo_from_trace = Self::read(
repo_root,
&repo_root
.resolve(dir)
.join_components(&TASK_ACCESS_CONFIG_PATH),
);

// check the zero config case (turbo trace file, but no turbo.json file)
if let Ok(turbo_from_trace) = turbo_from_trace {
Expand Down Expand Up @@ -630,7 +640,7 @@ impl TurboJson {
/// and then converts it into `TurboJson`
pub(crate) fn read(
repo_root: &AbsoluteSystemPath,
path: &AnchoredSystemPath,
path: &AbsoluteSystemPath,
) -> Result<TurboJson, Error> {
let raw_turbo_json = RawTurboJson::read(repo_root, path)?;
raw_turbo_json.try_into()
Expand Down