Skip to content

Commit

Permalink
Polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 17, 2024
1 parent a796501 commit 6f36a15
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#### 🚀 Updates

- We are deprecating the concept of a task "platform", as this is required for the next step in supporting WASM based toolchain plugins. Going forward, any reference to platform is now a toolchain. The following changes have been made:
- Deprecated the `platform` task setting, use `toolchain` instead.
- Deprecated the `taskPlatform` query field, use `taskToolchain` instead.
- Removed the top-level `platform` setting from `moon.yml`. The toolchain is now inferred from the top-level `language` setting.
- Updated task option `runInCI` to support the values "always" (always run) and "affected" (only run
if affected, same as `true`).

Expand Down
12 changes: 4 additions & 8 deletions crates/app/src/commands/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ pub async fn project(session: CliSession, args: ProjectArgs) -> AppResult {
console.print_entry("Root", color::path(&project.root))?;
}

if let Some(toolchain) = &project.toolchain {
console.print_entry("Toolchain", toolchain)?;
}

if project.platform.is_javascript() {
console.print_entry("Platform", format!("{}", &project.platform))?;
}

console.print_entry(
"Toolchains",
project.language.get_toolchain_ids().join(", "),
)?;
console.print_entry("Language", format!("{}", &project.language))?;
console.print_entry("Stack", format!("{}", &project.stack))?;
console.print_entry("Type", format!("{}", &project.type_of))?;
Expand Down
3 changes: 1 addition & 2 deletions crates/app/src/commands/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ pub async fn task(session: CliSession, args: TaskArgs) -> AppResult {
console.print_entry("Task", color::id(&args.target.task_id))?;
console.print_entry("Project", color::id(&project.id))?;
console.print_entry("Toolchains", task.toolchains.join(", "))?;
console.print_entry("Platform", format!("{}", &task.platform))?;
console.print_entry("Type", format!("{}", &task.type_of))?;
console.print_entry("Type", task.type_of.to_string())?;

let mut modes = vec![];

Expand Down
7 changes: 4 additions & 3 deletions crates/config/src/language_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl Serialize for LanguageType {
}
}

// TODO: Remove in 2.0
derive_enum!(
/// Platforms that each programming language can belong to.
#[derive(ConfigEnum, Copy, Default, Hash)]
Expand Down Expand Up @@ -105,9 +106,9 @@ impl PlatformType {

pub fn get_toolchain_ids(&self) -> Vec<Id> {
match self {
PlatformType::Bun => vec![Id::raw("bun"), Id::raw("javascript")],
PlatformType::Deno => vec![Id::raw("deno"), Id::raw("javascript")],
PlatformType::Node => vec![Id::raw("node"), Id::raw("javascript")],
PlatformType::Bun => vec![Id::raw("bun")],
PlatformType::Deno => vec![Id::raw("deno")],
PlatformType::Node => vec![Id::raw("node")],
PlatformType::Python => vec![Id::raw("python")],
PlatformType::Rust => vec![Id::raw("rust")],
PlatformType::System => vec![Id::raw("system")],
Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pattern!(TOKEN_FUNC, "@([a-z]+)\\(([0-9A-Za-z_-]+)\\)");
pattern!(TOKEN_FUNC_DISTINCT, "^@([a-z]+)\\(([0-9A-Za-z_-]+)\\)$");
pattern!(
TOKEN_VAR,
"\\$(arch|language|osFamily|os|projectAlias|projectChannel|projectName|projectOwner|projectRoot|projectSource|projectStack|projectType|project|target|taskPlatform|taskType|task|timestamp|datetime|date|time|vcsBranch|vcsRepository|vcsRevision|workingDir|workspaceRoot)"
"\\$(arch|language|osFamily|os|projectAlias|projectChannel|projectName|projectOwner|projectRoot|projectSource|projectStack|projectType|project|target|taskPlatform|taskToolchain|taskToolchains|taskType|task|timestamp|datetime|date|time|vcsBranch|vcsRepository|vcsRevision|workingDir|workspaceRoot)"
);
pattern!(
TOKEN_VAR_DISTINCT,
"^\\$(arch|language|osFamily|os|projectAlias|projectChannel|projectName|projectOwner|projectRoot|projectSource|projectStack|projectType|project|target|taskPlatform|taskType|task|timestamp|datetime|date|time|vcsBranch|vcsRepository|vcsRevision|workingDir|workspaceRoot)$"
"^\\$(arch|language|osFamily|os|projectAlias|projectChannel|projectName|projectOwner|projectRoot|projectSource|projectStack|projectType|project|target|taskPlatform|taskToolchain|taskToolchains|taskType|task|timestamp|datetime|date|time|vcsBranch|vcsRepository|vcsRevision|workingDir|workspaceRoot)$"
);
1 change: 1 addition & 0 deletions crates/config/src/project/task_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ cacheable!(
/// available binaries, lookup paths, and more. When not provided, will
/// be automatically detected.
#[deprecated(note = "Use `toolchain` instead.")]
// TODO: Remove in 2.0
pub platform: PlatformType,

/// The preset to apply for the task. Will inherit default options.
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/shapes/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<T: Schematic> Default for OneOrMany<T> {
impl<T: Schematic + Clone> OneOrMany<T> {
pub fn is_empty(&self) -> bool {
match self {
Self::One(item) => false,
Self::One(_) => false,
Self::Many(list) => list.is_empty(),
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cacheable!(
pub language: LanguageType,

/// Default platform to run tasks against.
// TODO REMOVE
#[deprecated]
pub platform: PlatformType,

Expand All @@ -65,9 +66,6 @@ cacheable!(
/// Includes internal tasks!
pub task_targets: Vec<Target>,

/// Default toolchain to run tasks against.
pub toolchain: Option<Id>,

/// The type of project.
#[serde(rename = "type")]
pub type_of: ProjectType,
Expand Down
1 change: 1 addition & 0 deletions crates/task-builder/src/tasks_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ impl<'proj> TasksBuilder<'proj> {

// Backwards compat for when the user has explicitly configured
// the deprecated `platform` setting
// TODO: Remove in 2.0
#[allow(deprecated)]
if !task.platform.is_unknown() && task.toolchains.is_empty() {
task.toolchains = task.platform.get_toolchain_ids();
Expand Down
3 changes: 1 addition & 2 deletions crates/task-expander/src/token_expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ impl<'graph> TokenExpander<'graph> {
// Task
"target" => Cow::Borrowed(task.target.as_str()),
"task" => Cow::Borrowed(task.id.as_str()),
"taskPlatform" => Cow::Owned(task.platform.to_string()),
"taskToolchain" => Cow::Borrowed(task.toolchains[0].as_str()),
"taskPlatform" | "taskToolchain" => Cow::Borrowed(task.toolchains[0].as_str()),
"taskToolchains" => Cow::Owned(task.toolchains.join(",")),
"taskType" => Cow::Owned(task.type_of.to_string()),
// Datetime
Expand Down
6 changes: 1 addition & 5 deletions crates/task/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ impl Task {

/// Return true of the task will run in the system toolchain.
pub fn is_system_toolchain(&self) -> bool {
if self.toolchains.is_empty() {
self.platform.is_system()
} else {
self.toolchains.len() == 1 && self.toolchains[0] == "system"
}
self.toolchains.is_empty() || self.toolchains.len() == 1 && self.toolchains[0] == "system"
}

/// Return true if the task is a "test" type.
Expand Down
4 changes: 2 additions & 2 deletions legacy/bun/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod target_hash;
pub use bun_platform::*;

use moon_common::Id;
use moon_config::{NodePackageManager, PartialTaskConfig, PlatformType};
use moon_config::{NodePackageManager, PartialTaskConfig};
use moon_javascript_platform::ScriptParser;
use moon_node_lang::PackageJsonCache;
use std::collections::BTreeMap;
Expand All @@ -14,7 +14,7 @@ pub fn infer_tasks_from_scripts(
project_id: &str,
package_json: &PackageJsonCache,
) -> miette::Result<BTreeMap<Id, PartialTaskConfig>> {
let mut parser = ScriptParser::new(project_id, PlatformType::Bun, NodePackageManager::Bun);
let mut parser = ScriptParser::new(project_id, Id::raw("bun"), NodePackageManager::Bun);

parser.infer_scripts(package_json)?;

Expand Down
39 changes: 17 additions & 22 deletions legacy/javascript/platform/src/infer_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use moon_args::split_args;
use moon_common::Id;
use moon_config::{
NodePackageManager, OutputPath, PartialTaskArgs, PartialTaskConfig, PartialTaskDependency,
PlatformType,
NodePackageManager, OneOrMany, OutputPath, PartialTaskArgs, PartialTaskConfig,
PartialTaskDependency,
};
use moon_node_lang::package_json::{PackageJsonCache, ScriptsMap};
use moon_target::Target;
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn create_task(
script_name: &str,
script: &str,
context: TaskContext,
platform: PlatformType,
toolchain: &Id,
pm: NodePackageManager,
) -> miette::Result<PartialTaskConfig> {
let is_wrapping = matches!(context, TaskContext::WrapRunScript);
Expand Down Expand Up @@ -173,7 +173,7 @@ pub fn create_task(
}

if is_wrapping {
task_config.platform = Some(platform);
task_config.toolchain = Some(OneOrMany::One(toolchain.to_owned()));
task_config.command = Some(PartialTaskArgs::List(string_vec![
match pm {
NodePackageManager::Bun => "bun",
Expand All @@ -189,26 +189,21 @@ pub fn create_task(
if is_bash_script(command) {
args.insert(0, "bash".to_owned());
} else if is_node_script(command) {
args.insert(
0,
if platform == PlatformType::Bun {
"bun".to_owned()
} else {
"node".to_owned()
},
);
args.insert(0, toolchain.as_str().to_owned());
} else {
// Already there
}
} else {
args.insert(0, "noop".to_owned());
}

task_config.platform = Some(if is_system_command(&args[0]) || &args[0] == "noop" {
PlatformType::System
} else {
platform
});
task_config.toolchain = Some(OneOrMany::One(
if is_system_command(&args[0]) || &args[0] == "noop" {
Id::raw("system")
} else {
toolchain.to_owned()
},
));
task_config.command = Some(if args.len() == 1 {
PartialTaskArgs::String(args.remove(0))
} else {
Expand Down Expand Up @@ -263,12 +258,12 @@ pub struct ScriptParser<'a> {
/// Scripts that ran into issues while parsing.
unresolved_scripts: ScriptsMap,

platform: PlatformType,
toolchain: Id,
pm: NodePackageManager,
}

impl<'a> ScriptParser<'a> {
pub fn new(project_id: &'a str, platform: PlatformType, pm: NodePackageManager) -> Self {
pub fn new(project_id: &'a str, toolchain: Id, pm: NodePackageManager) -> Self {
ScriptParser {
life_cycles: ScriptsMap::default(),
names_to_ids: FxHashMap::default(),
Expand All @@ -278,7 +273,7 @@ impl<'a> ScriptParser<'a> {
scripts: ScriptsMap::default(),
tasks: BTreeMap::new(),
unresolved_scripts: ScriptsMap::default(),
platform,
toolchain,
pm,
}
}
Expand Down Expand Up @@ -307,7 +302,7 @@ impl<'a> ScriptParser<'a> {
name,
script,
TaskContext::WrapRunScript,
self.platform,
&self.toolchain,
self.pm,
)?,
);
Expand Down Expand Up @@ -494,7 +489,7 @@ impl<'a> ScriptParser<'a> {
name,
value,
TaskContext::ConvertToTask,
self.platform,
&self.toolchain,
self.pm,
)?,
);
Expand Down
6 changes: 3 additions & 3 deletions legacy/node/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use node_platform::NodePlatform;
pub use target_hash::NodeTargetHash;

use moon_common::Id;
use moon_config::{NodePackageManager, PartialTaskConfig, PlatformType};
use moon_config::{NodePackageManager, PartialTaskConfig};
use moon_javascript_platform::ScriptParser;
use moon_node_lang::PackageJsonCache;
use std::collections::BTreeMap;
Expand All @@ -16,7 +16,7 @@ pub fn create_tasks_from_scripts(
package_json: &mut PackageJsonCache,
package_manager: NodePackageManager,
) -> miette::Result<BTreeMap<Id, PartialTaskConfig>> {
let mut parser = ScriptParser::new(project_id, PlatformType::Node, package_manager);
let mut parser = ScriptParser::new(project_id, Id::raw("node"), package_manager);

parser.parse_scripts(package_json)?;
parser.update_package(package_json)?;
Expand All @@ -29,7 +29,7 @@ pub fn infer_tasks_from_scripts(
package_json: &PackageJsonCache,
package_manager: NodePackageManager,
) -> miette::Result<BTreeMap<Id, PartialTaskConfig>> {
let mut parser = ScriptParser::new(project_id, PlatformType::Node, package_manager);
let mut parser = ScriptParser::new(project_id, Id::raw("node"), package_manager);

parser.infer_scripts(package_json)?;

Expand Down

0 comments on commit 6f36a15

Please sign in to comment.