Skip to content

Commit

Permalink
Wrapped up first implementation of turbo_json loading
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Apr 20, 2023
1 parent 8318200 commit e44aed2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/package_json.rs
Expand Up @@ -8,6 +8,7 @@ use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPathBuf};
pub struct PackageJson {
name: String,
version: String,
pub scripts: BTreeMap<String, String>,
dependencies: BTreeMap<String, String>,
dev_dependencies: BTreeMap<String, String>,
optional_dependencies: BTreeMap<String, String>,
Expand Down
9 changes: 7 additions & 2 deletions crates/turborepo-lib/src/pipeline.rs
Expand Up @@ -3,6 +3,11 @@ use std::collections::{HashMap, HashSet};
pub type Pipeline = HashMap<String, BookkeepingTaskDefinition>;

pub struct BookkeepingTaskDefinition {
defined_fields: HashSet<String>,
experimental_fields: HashSet<String>,
pub defined_fields: HashSet<String>,
pub experimental_fields: HashSet<String>,
pub task_definition: HashableTaskDefinition,
}

pub struct HashableTaskDefinition {
pub should_cache: bool,
}
29 changes: 25 additions & 4 deletions crates/turborepo-lib/src/turbo_config.rs
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use anyhow::{anyhow, Result};
use log::warn;
use serde::Deserialize;
Expand All @@ -6,7 +8,7 @@ use turbopath::{AbsoluteSystemPathBuf, RelativeSystemPathBuf};
use crate::{
commands::CommandBase,
package_json::PackageJson,
pipeline::{BookkeepingTaskDefinition, Pipeline},
pipeline::{BookkeepingTaskDefinition, HashableTaskDefinition, Pipeline},
task_utils::{is_package_task, root_task_id},
};

Expand All @@ -20,7 +22,7 @@ struct TurboJson {
fn load_turbo_config_for_single_package(
base: &mut CommandBase,
root_package_json: &mut PackageJson,
) -> Result<()> {
) -> Result<TurboJson> {
if root_package_json.legacy_turbo_config.is_some() {
warn!(
"[WARNING] \"turbo\" in package.json is no longer supported. Migrate to {} by running \
Expand All @@ -31,7 +33,7 @@ fn load_turbo_config_for_single_package(
root_package_json.legacy_turbo_config = None;
}

let turbo_from_files = read_turbo_config(
let mut turbo_json = read_turbo_config(
&base
.repo_root
.join_relative(RelativeSystemPathBuf::new("turbo.json")?),
Expand All @@ -47,8 +49,27 @@ fn load_turbo_config_for_single_package(
));
}
pipeline.insert(root_task_id(&task_id).to_string(), task_definition);
turbo_from_files.pipeline = pipeline;
}

turbo_json.pipeline = pipeline;

for (script_name, _) in &root_package_json.scripts {
if !turbo_from_files.pipeline.contains_key(&script_name) {
let task_name = root_task_id(script_name);
let mut defined_fields = HashSet::new();
defined_fields.insert("ShouldCache".to_string());
let task_definition = BookkeepingTaskDefinition {
defined_fields,
task_definition: HashableTaskDefinition {
should_cache: false,
},
..Default::default()
};
turbo_from_files.insert(task_name, task_definition);
}
}

Ok(turbo_from_files)
}

fn read_turbo_config(turbo_json_path: &AbsoluteSystemPathBuf) -> Result<TurboJson> {
Expand Down

0 comments on commit e44aed2

Please sign in to comment.