From 0cbb7dec909e2b2a68b75ddf745eb648bfff550b Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Sep 2024 22:42:39 -0700 Subject: [PATCH] new: Loosen ID restrictions. --- CHANGELOG.md | 1 + crates/common/src/id.rs | 9 ++++----- crates/project-graph/src/projects_locator.rs | 19 +++++++++++++------ .../project-graph/tests/project_graph_test.rs | 3 +-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 821237be1c2..411c1ffe703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ #### 🚀 Updates - Added caching around `bun bun.lockb` commands, instead of running them for every task. +- Updated and loosened identifier naming restrictions. - Updated environment variable substitution to support different outputs when a variable is missing, based on a trailing flag syntax. - `$FOO` or `${FOO}` - If variable is missing, keeps the original syntax (current default). diff --git a/crates/common/src/id.rs b/crates/common/src/id.rs index a810f32db37..922b9dc0485 100644 --- a/crates/common/src/id.rs +++ b/crates/common/src/id.rs @@ -13,7 +13,7 @@ pub static ID_CLEAN: OnceLock = OnceLock::new(); #[derive(Error, Debug, Diagnostic)] #[diagnostic(code(id::invalid_format))] -#[error("Invalid format for {}, may only contain alpha-numeric characters, dashes (-), slashes (/), underscores (_), and dots (.), and must start with an alpha character.", .0.style(Style::Id))] +#[error("Invalid format for {}, may only contain alpha-numeric characters, dashes (-), slashes (/), underscores (_), and periods (.).", .0.style(Style::Id))] pub struct IdError(String); #[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] @@ -24,9 +24,8 @@ impl Id { let id = id.as_ref(); // The @ is to support npm package scopes! - let pattern = ID_PATTERN.get_or_init(|| { - Regex::new(format!("^([A-Za-z@_]{{1}}{})$", ID_CHARS).as_str()).unwrap() - }); + let pattern = + ID_PATTERN.get_or_init(|| Regex::new(format!("^(@?{})$", ID_CHARS).as_str()).unwrap()); if !pattern.is_match(id) { return Err(IdError(id.to_owned())); @@ -40,7 +39,7 @@ impl Id { // with a leading -, causing pattern failures let id = id.as_ref().replace('@', ""); - // This is to clean and ID and remove unwanted characters + // This is to clean an ID and remove unwanted characters let pattern = ID_CLEAN.get_or_init(|| Regex::new(r"[^0-9A-Za-z/\._-]+").unwrap()); Id::new(pattern.replace_all(&id, "-")) diff --git a/crates/project-graph/src/projects_locator.rs b/crates/project-graph/src/projects_locator.rs index d6eaed20359..7e0b79d61a0 100644 --- a/crates/project-graph/src/projects_locator.rs +++ b/crates/project-graph/src/projects_locator.rs @@ -4,11 +4,11 @@ use moon_config::{ProjectSourceEntry, ProjectsSourcesList}; use moon_vcs::BoxedVcs; use starbase_utils::{fs, glob}; use std::path::Path; -use tracing::{instrument, warn}; +use tracing::{debug, instrument, warn}; /// Infer a project name from a source path, by using the name of /// the project folder. -pub fn infer_project_id_and_source( +fn infer_project_id_and_source( path: &str, workspace_root: &Path, ) -> miette::Result { @@ -113,10 +113,17 @@ where } } - sources.push(infer_project_id_and_source( - &project_source, - workspace_root, - )?) + let (id, source) = infer_project_id_and_source(&project_source, workspace_root)?; + + if id.starts_with(".") { + debug!( + id = id.as_str(), + source = source.as_str(), + "Received a project for a hidden folder. These are not supported through globs, but can be mapped explicitly with project sources!" + ); + } else { + sources.push((id, source)); + } } } diff --git a/crates/project-graph/tests/project_graph_test.rs b/crates/project-graph/tests/project_graph_test.rs index fa2c1efdd1f..e70ff882212 100644 --- a/crates/project-graph/tests/project_graph_test.rs +++ b/crates/project-graph/tests/project_graph_test.rs @@ -193,8 +193,7 @@ mod project_graph { } #[tokio::test] - #[should_panic(expected = "Invalid format for .foo")] - async fn errors_for_dot_folders() { + async fn filters_dot_folders() { let sandbox = create_sandbox("dependencies"); sandbox.create_file(".foo/moon.yml", "");