这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions crates/turborepo-lib/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use turborepo_ui::BOLD;
use super::CommandBase;
use crate::{
config::{CONFIG_FILE, CONFIG_FILE_JSONC},
turbo_json::RawTurboJson,
turbo_json::{RawRootTurboJson, RawTurboJson},
};

pub const DEFAULT_OUTPUT_DIR: &str = "out";
Expand Down Expand Up @@ -473,7 +473,8 @@ impl<'a> Prune<'a> {
return Ok(None);
};

let turbo_json = RawTurboJson::parse(&turbo_json_contents, turbo_json_name.as_str())?;
let turbo_json =
RawRootTurboJson::parse(&turbo_json_contents, turbo_json_name.as_str())?.into();
Ok(Some((turbo_json, turbo_json_name)))
}
}
9 changes: 8 additions & 1 deletion crates/turborepo-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use turborepo_cache::CacheConfig;
use turborepo_errors::TURBO_SITE;
use turborepo_repository::package_graph::PackageName;

pub use crate::turbo_json::{RawTurboJson, UIMode};
pub use crate::turbo_json::UIMode;
use crate::{
cli::{EnvMode, LogOrder},
turbo_json::FutureFlags,
Expand Down Expand Up @@ -140,6 +140,13 @@ pub enum Error {
#[source_code]
text: NamedSource<String>,
},
#[error("You must extend from the root of the workspace first.")]
ExtendsRootFirst {
#[label("'//' should be first")]
span: Option<SourceSpan>,
#[source_code]
text: NamedSource<String>,
},
#[error("`{field}` cannot contain an environment variable.")]
InvalidDependsOnValue {
field: &'static str,
Expand Down
43 changes: 38 additions & 5 deletions crates/turborepo-lib/src/config/turbo_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use camino::Utf8PathBuf;
use turbopath::{AbsoluteSystemPath, RelativeUnixPath};

use super::{ConfigurationOptions, Error, ResolvedConfigurationOptions};
use crate::turbo_json::{RawRemoteCacheOptions, RawTurboJson};
use crate::turbo_json::{RawRemoteCacheOptions, RawRootTurboJson, RawTurboJson};

pub struct TurboJsonReader<'a> {
repo_root: &'a AbsoluteSystemPath,
Expand Down Expand Up @@ -89,8 +89,16 @@ impl<'a> ResolvedConfigurationOptions for TurboJsonReader<'a> {
existing_config: &ConfigurationOptions,
) -> Result<ConfigurationOptions, Error> {
let turbo_json_path = existing_config.root_turbo_json_path(self.repo_root)?;
let turbo_json = RawTurboJson::read(self.repo_root, &turbo_json_path)
.map(|turbo_json| turbo_json.unwrap_or_default())?;
let root_relative_turbo_json_path = self.repo_root.anchor(&turbo_json_path).map_or_else(
|_| turbo_json_path.as_str().to_owned(),
|relative| relative.to_string(),
);
let turbo_json = match turbo_json_path.read_existing_to_string()? {
Some(contents) => {
RawRootTurboJson::parse(&contents, &root_relative_turbo_json_path)?.into()
}
None => RawTurboJson::default(),
};
Self::turbo_json_to_config_options(turbo_json)
}
}
Expand All @@ -99,6 +107,7 @@ impl<'a> ResolvedConfigurationOptions for TurboJsonReader<'a> {
mod test {
use serde_json::json;
use tempfile::tempdir;
use test_case::test_case;

use super::*;
use crate::config::CONFIG_FILE;
Expand Down Expand Up @@ -165,7 +174,7 @@ mod test {
let login_url = "localhost:3001";
let team_slug = "acme-packers";
let team_id = "id-123";
let turbo_json = RawTurboJson::parse(
let turbo_json = RawRootTurboJson::parse(
&serde_json::to_string_pretty(&json!({
"remoteCache": {
"enabled": true,
Expand All @@ -182,7 +191,8 @@ mod test {
.unwrap(),
"junk",
)
.unwrap();
.unwrap()
.into();
let config = TurboJsonReader::turbo_json_to_config_options(turbo_json).unwrap();
assert!(config.enabled());
assert_eq!(config.timeout(), timeout);
Expand All @@ -194,4 +204,27 @@ mod test {
assert!(config.signature());
assert!(config.preflight());
}

#[test_case(None, false)]
#[test_case(Some(false), false)]
#[test_case(Some(true), true)]
fn test_dangerously_disable_package_manager_check(value: Option<bool>, expected: bool) {
let turbo_json = RawRootTurboJson::parse(
&serde_json::to_string_pretty(
&(if let Some(value) = value {
json!({
"dangerouslyDisablePackageManagerCheck": value
})
} else {
json!({})
}),
)
.unwrap(),
"turbo.json",
)
.unwrap()
.into();
let config = TurboJsonReader::turbo_json_to_config_options(turbo_json).unwrap();
assert_eq!(config.allow_no_package_manager(), expected);
}
}
Loading
Loading