Skip to content

Commit

Permalink
new: Loosen ID restrictions.
Browse files Browse the repository at this point in the history
milesj committed Sep 6, 2024
1 parent f3de5b0 commit 0cbb7de
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
9 changes: 4 additions & 5 deletions crates/common/src/id.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ pub static ID_CLEAN: OnceLock<Regex> = 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, "-"))
19 changes: 13 additions & 6 deletions crates/project-graph/src/projects_locator.rs
Original file line number Diff line number Diff line change
@@ -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<ProjectSourceEntry> {
@@ -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));
}
}
}

3 changes: 1 addition & 2 deletions crates/project-graph/tests/project_graph_test.rs
Original file line number Diff line number Diff line change
@@ -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", "");

0 comments on commit 0cbb7de

Please sign in to comment.