diff --git a/crates/cli/src/commands/query.rs b/crates/cli/src/commands/query.rs index adb85206a19..5028d0418c1 100644 --- a/crates/cli/src/commands/query.rs +++ b/crates/cli/src/commands/query.rs @@ -2,7 +2,7 @@ use crate::enums::TouchedStatus; pub use crate::queries::hash::query_hash; pub use crate::queries::hash_diff::query_hash_diff; pub use crate::queries::projects::{ - query_projects, QueryProjectsOptions, QueryProjectsResult, QueryTasksResult, + load_touched_files, query_projects, QueryProjectsOptions, QueryProjectsResult, QueryTasksResult, }; pub use crate::queries::touched_files::{ query_touched_files, QueryTouchedFilesOptions, QueryTouchedFilesResult, @@ -12,9 +12,10 @@ use console::Term; use miette::IntoDiagnostic; use moon_terminal::ExtendedTerm; use moon_workspace::Workspace; -use rustc_hash::FxHashMap; +use rustc_hash::{FxHashMap, FxHashSet}; use starbase::system; use starbase_styles::color; +use std::collections::BTreeMap; use std::io::{self, IsTerminal}; #[derive(Args, Clone, Debug)] @@ -149,6 +150,11 @@ pub async fn projects(args: ArgsRef, workspace: ResourceMut, workspace: ResourceMut>(); + + if filtered_tasks.is_empty() { + continue; + } + + grouped_tasks.insert(project.id.clone(), filtered_tasks); + } // Write to stdout directly to avoid broken pipe panics let term = Term::buffered_stdout(); if options.json { - let result = QueryTasksResult { - tasks: FxHashMap::from_iter( - projects - .into_iter() - .map(|p| (p.id.clone(), p.tasks.clone())), - ), - options, - }; - - term.line(serde_json::to_string_pretty(&result).into_diagnostic()?)?; - } else if !projects.is_empty() { - for project in projects { - if project.tasks.is_empty() { - continue; - } - - term.line(&project.id)?; + term.line( + serde_json::to_string_pretty(&QueryTasksResult { + tasks: grouped_tasks, + options, + }) + .into_diagnostic()?, + )?; + } else if !grouped_tasks.is_empty() { + for (project_id, tasks) in grouped_tasks { + term.line(project_id)?; - for (task_id, task) in &project.tasks { + for (task_id, task) in tasks { term.line(format!("\t:{} | {}", task_id, task.command))?; } } diff --git a/crates/cli/src/queries/projects.rs b/crates/cli/src/queries/projects.rs index 43c49d72cfe..66751b0d1ff 100644 --- a/crates/cli/src/queries/projects.rs +++ b/crates/cli/src/queries/projects.rs @@ -29,6 +29,7 @@ pub struct QueryProjectsOptions { pub source: Option, pub tags: Option, pub tasks: Option, + pub touched_files: FxHashSet, pub type_of: Option, } @@ -60,7 +61,7 @@ fn convert_to_regex(field: &str, value: &Option) -> AppResult AppResult> { let mut buffer = String::new(); @@ -106,11 +107,6 @@ pub async fn query_projects( debug!("Querying for projects"); let project_graph = generate_project_graph(workspace).await?; - let touched_files = if options.affected { - load_touched_files(workspace).await? - } else { - FxHashSet::default() - }; // When a MQL input is provided, it takes full precedence over option args if let Some(query) = &options.query { @@ -118,7 +114,7 @@ pub async fn query_projects( .query(moon_query::build_query(query)?)? .into_iter() .filter_map(|project| { - if options.affected && !project.is_affected(&touched_files) { + if options.affected && !project.is_affected(&options.touched_files) { return None; } @@ -139,7 +135,7 @@ pub async fn query_projects( let mut projects = vec![]; for project in project_graph.get_all()? { - if options.affected && !project.is_affected(&touched_files) { + if options.affected && !project.is_affected(&options.touched_files) { continue; } diff --git a/crates/cli/tests/query_test.rs b/crates/cli/tests/query_test.rs index c4de32917ef..4ffe1e717a7 100644 --- a/crates/cli/tests/query_test.rs +++ b/crates/cli/tests/query_test.rs @@ -658,20 +658,7 @@ mod tasks { projects.sort(); assert_eq!(tasks, string_vec!["lint", "test"]); - assert_eq!( - projects, - string_vec![ - "advanced", - "bar", - "basic", - "baz", - "emptyConfig", - "foo", - "noConfig", - "platforms", - "tasks", - ] - ); + assert_eq!(projects, string_vec!["platforms", "tasks"]); } } diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 7e234be1b60..3ae27ca7bae 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -8,11 +8,14 @@ - Tasks allowed to fail cannot be depended on. - Added colors to command line `--help` menus. - Updated `runner.archivableTargets` to support tag scoped targets. -- Updated proto integration from v0.13 to v0.16: +- Updated `moon query tasks` to filter out projects with no tasks. +- Updated `moon query tasks --affected` to filter based on affected task, instead of affected + project. +- Updated proto integration from v0.12 to v0.16: - proto tools are now powered by WASM plugins, which will be downloaded by moon on-demand. - Yarn v2+ will now download the requested version, and not downgrade to latest v1. - Please report any issues or degradations from this migration. - - View entire [proto changelog](https://github.com/moonrepo/proto/blob/master/CHANGELOG.md#0150). + - View entire [proto changelog](https://github.com/moonrepo/proto/blob/master/CHANGELOG.md#0160). #### 🐞 Fixes diff --git a/website/blog/2023-09-04_moon-v1.13.mdx b/website/blog/2023-09-04_moon-v1.13.mdx deleted file mode 100644 index 2e92258efd1..00000000000 --- a/website/blog/2023-09-04_moon-v1.13.mdx +++ /dev/null @@ -1,46 +0,0 @@ ---- -slug: moon-v1.13 -title: moon v1.13 - ??? -authors: [milesj] -tags: [tasks] -# image: ./img/moon/v1.12.png ---- - -??? - - - -## Allow tasks to fail - -"Allow tasks to fail?" You ask yourself. "Doesn't that defeat the point of a task runner?" You -question further. "You're not wrong!" We reply. These questions assume a perfect repository state, -where all tasks either pass or fail, and there's no middle ground. In reality, very rarely is that -true, and we want to support those stuck in the middle, such as: - -- In a heavy migration and it's known that a task is currently broken. -- The task is flaky but you've been unable to find the root cause. -- Upstream dependencies have published a backwards incompatible change, and you're waiting on a fix. -- And of course, in the middle of adopting moon! - -For situations where a task consistently or sometimes fails, but you don't want it to fail the -entire pipeline (especially in CI), you can enable the new -[`allowFailure` task option](/docs/config/project#allowfailure). - -```yaml title="moon.yml" -tasks: - typecheck: - command: 'tsc --build' - options: - allowFailure: true -``` - -When enabled, failing tasks will no longer bail [`moon run`](/docs/commands/run) early, nor will it -exit [`moon ci`](/docs/commands/ci) with a non-zero exit code. However, we still built guard rails -around this feature, as we don't want to encourage bad practices, and one of these guard rails is -that tasks that enable `allowFailure` _cannot_ be depended on by other tasks, as we cannot guarantee -that it's side-effect free. - -## Other changes - -View the [official release](https://github.com/moonrepo/moon/releases/tag/v1.13.0) for a full list -of changes. diff --git a/website/blog/2023-09-04_proto-v0.16.mdx b/website/blog/2023-09-04_proto-v0.16.mdx new file mode 100644 index 00000000000..96d900d29c0 --- /dev/null +++ b/website/blog/2023-09-04_proto-v0.16.mdx @@ -0,0 +1,63 @@ +--- +slug: proto-v0.16 +title: proto v0.16 - Add, remove, and purge plugins +authors: [milesj] +tags: [proto, plugin] +--- + +This release adds functionality for managing plugins and purging the proto store. + + + +## Add and remove plugins + +Now that proto has fully embraced a plugin based architecture, we thought it'd be nice to support +the management of these plugins through the CLI. This release adds two new commands: +[`proto add-plugin`](/docs/proto/commands/add-plugin) and +[`proto remove-plugin`](/docs/proto/commands/remove-plugin). + +Adding a plugin requires a unique ID and what we call a locator, which is a string that dictates +where to locate and download the plugin from. Here's an example for Node.js, but this isn't +necessary as it's built-in: + +```shell +$ proto add-plugin node source:https://github.com/moonrepo/node-plugin/releases/latest/download/node_plugin.wasm +``` + +Additionally, removing a plugin is even easier. + +```shell +$ proto remove-plugin node +``` + +## Purge tools and plugins + +proto has supported cleaning for quite some time through the +[`proto clean`](/docs/proto/commands/clean) command (and the +[`auto-clean` setting](/docs/proto/config#user-configuration)), which would automatically delete +installed tool versions and temporary files that are older then a specific timeframe. This helps to +free up disk space for unused or rarely used tools. + +In this release, we're expanding the `clean` command's functionality with a concept known as +purging, which will "delete entirely". The first being the new `--purge` option, which will delete a +tool, its manifest, _all_ installed versions, and the entire `~/.proto/tools/` directory. + +```shell +# Delete all traces of Node.js +$ proto clean --purge node +``` + +Additionaly, a new `--purge-plugins` option can be used to delete all downloaded plugins (the +`~/.proto/plugins` directory). Useful for house keeping or if you want to start fresh. + +```shell +$ proto clean --purge-plugins +``` + +## Other changes + +View the [official release](https://github.com/moonrepo/proto/releases/tag/v0.16.0) for a full list +of changes. + +- Added folder locking during tool installation to avoid colliding processes. +- Renamed `PROTO_ROOT` to `PROTO_HOME`, but we'll support `PROTO_ROOT` for the time being. diff --git a/website/blog/2023-09-05_moon-v1.13.mdx b/website/blog/2023-09-05_moon-v1.13.mdx new file mode 100644 index 00000000000..7fc28063075 --- /dev/null +++ b/website/blog/2023-09-05_moon-v1.13.mdx @@ -0,0 +1,84 @@ +--- +slug: moon-v1.13 +title: moon v1.13 - Toolchain now uses WASM plugins +authors: [milesj] +tags: [tasks, proto, wasm] +image: ./img/moon/v1.13.png +--- + +This is a light release that focused primarily on upgrading to the WASM based proto implementation. + + + +## proto upgrade and WASM plugins + +Over the last few months, we've made immense strides on [proto](/proto), our multi-language +toolchain. For those of you unaware, moon's toolchain is built on top of proto, and we accomplish +this by utilizing the same Rust code between both tools. + +However, moon has been locked to [proto v0.12](/blog/proto-v0.12), which was a purely Rust based +implementation. With the release of [proto v0.13](/blog/proto-v0.13) and onward, proto has moved to +a WASM based plugin architecture (with the core still in Rust), which allows us to support more +languages, and enables developers to write plugins in non-Rust languages. + +And since our WASM plugins have stabilized by [proto v0.16](/blog/proto-v0.16), we felt it was time +to finally upgrade moon's implementation to the latest and greatest. So what does this mean exactly? +A few things: + +- If you're using moon's [toolchain](/docs/config/toolchain) (like `node`), we will now download the + [Node.js WASM plugins](https://github.com/moonrepo/node-plugin) in the background (to + `~/.proto/plugins`). +- These plugins are in charge of downloading and installing the Node.js, npm, pnpm, or yarn version + specified in your toolchain configuration. +- The entire plugin flow is now logged to the console, so you can see what's happening behind the + scenes. +- In the future (most likely moon v2), our platform and language integration will also be powered by + WASM plugins. This enables you to build your own custom plugins! + +:::info + +This entire process should be transparent to all users, and you should not notice any changes. +However, in case this upgrade causes issues, we wanted to isolate it from other changes, hence the +light release! + +::: + +## Allow tasks to fail + +"Allow tasks to fail?" You ask yourself. "Doesn't that defeat the point of a task runner?" You +question further. "You're not wrong!" We reply. These questions assume a perfect repository state, +where all tasks either pass or fail, and there's no middle ground. In reality, very rarely is that +true, and we want to support those stuck in the middle, such as: + +- In a heavy migration and it's known that a task is currently broken. +- The task is flaky but you've been unable to find the root cause. +- Upstream dependencies have published a backwards incompatible change, and you're waiting on a fix. +- And of course, in the middle of adopting moon! + +For situations where a task consistently or sometimes fails, but you don't want it to fail the +entire pipeline (especially in CI), you can enable the new +[`allowFailure` task option](/docs/config/project#allowfailure). + +```yaml title="moon.yml" +tasks: + typecheck: + command: 'tsc --build' + options: + allowFailure: true +``` + +When enabled, failing tasks will no longer bail [`moon run`](/docs/commands/run) early, nor will it +exit [`moon ci`](/docs/commands/ci) with a non-zero exit code. However, we still built guard rails +around this feature, as we don't want to encourage bad practices, and one of these guard rails is +that tasks that enable `allowFailure` _cannot_ be depended on by other tasks, as we cannot guarantee +that it's side-effect free. + +## Other changes + +View the [official release](https://github.com/moonrepo/moon/releases/tag/v1.13.0) for a full list +of changes. + +- Added colors to command line `--help` menus. +- Updated `runner.archivableTargets` to support tag scoped targets. +- Updated `moon query tasks --affected` to filter based on affected task, instead of affected + project. diff --git a/website/blog/img/moon/v1.13.png b/website/blog/img/moon/v1.13.png new file mode 100644 index 00000000000..f60831dba9f Binary files /dev/null and b/website/blog/img/moon/v1.13.png differ diff --git a/website/docs/proto/commands/add-plugin.mdx b/website/docs/proto/commands/add-plugin.mdx new file mode 100644 index 00000000000..fdc4a49e7d1 --- /dev/null +++ b/website/docs/proto/commands/add-plugin.mdx @@ -0,0 +1,22 @@ +--- +title: add-plugin +--- + +The `proto add-plugin ` (or `proto ap`) command will add the provided plugin ID and +locator string to the `[plugins]` section of the local (`.prototools`) or global +(`~/.proto/config.toml`) config file. + +```shell +$ proto add-plugin node source:https://github.com/moonrepo/node-plugin/releases/latest/download/node_plugin.wasm +``` + +> Learn more about [plugin locator strings](../plugins#enabling-plugins). + +### Arguments + +- `` - ID of the plugin. +- `` - How to locate the plugin. + +### Options + +- `--global` - Add to the global config instead of local. diff --git a/website/docs/proto/commands/clean.mdx b/website/docs/proto/commands/clean.mdx index d5e3e2b1b6c..ca4d85f2598 100644 --- a/website/docs/proto/commands/clean.mdx +++ b/website/docs/proto/commands/clean.mdx @@ -2,14 +2,27 @@ title: clean --- -The `proto clean` command can be used to uninstall all stale and unused tools. By default, it will -remove tools that haven't been used in the last 30 days. +The `proto clean` command can be used to uninstall stale and unused tools or plugins. By default, it +will remove items that haven't been used in the last 30 days. ```shell $ proto clean ``` +Furthermore, the command can be used to purge a tool, which will remove it entirely from proto, or +purge all downloaded plugins. + +```shell +# Delete node from proto +$ proto clean --purge node + +# Delete all plugins +$ proto clean --purge-plugins +``` + ### Options - `--days` - Number of days before a tool is considered stale. +- `--purge` - Purge and delete the installed tool by ID (`~/.proto/tools/`). +- `--purge-plugins` - Purge and delete all downloaded plugins (`~/.proto/plugins`). - `--yes` - Avoid and confirm all prompts. diff --git a/website/docs/proto/commands/remove-plugin.mdx b/website/docs/proto/commands/remove-plugin.mdx new file mode 100644 index 00000000000..56a5b5e26f8 --- /dev/null +++ b/website/docs/proto/commands/remove-plugin.mdx @@ -0,0 +1,20 @@ +--- +title: remove-plugin +--- + +The `proto remove-plugin ` (or `proto rp`) command will remove the provided plugin ID from to +the `[plugins]` section of the local (`.prototools`) or global (`~/.proto/config.toml`) config file. + +```shell +$ proto remove-plugin node +``` + +> Built-in plugins _cannot_ be removed! + +### Arguments + +- `` - ID of the plugin. + +### Options + +- `--global` - Remove from the global config instead of local. diff --git a/website/sidebars.js b/website/sidebars.js index 67fb2ad4266..82c9bc7002b 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -274,6 +274,7 @@ const sidebars = { type: 'category', label: 'Commands', items: [ + 'proto/commands/add-plugin', 'proto/commands/alias', 'proto/commands/bin', 'proto/commands/clean', @@ -286,6 +287,7 @@ const sidebars = { 'proto/commands/list-remote', 'proto/commands/local', 'proto/commands/plugins', + 'proto/commands/remove-plugin', 'proto/commands/run', 'proto/commands/setup', 'proto/commands/unalias',