Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Update extends to support a list. #1772

Merged
merged 4 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
config files in the project/workspace root. This pattern is preferred when possible.
- Updated task option `runInCI` to support the values "always" (always run) and "affected" (only run
if affected, same as `true`).
- Updated the `extends` setting in `.moon/workspace.yml`, `toolchain.yml`, and `tasks.yml`, to support a list of files/URLs to extend.

#### 🐞 Fixes

- Fixed a panic that could occur during command argument parsing.

## 1.30.6

Expand Down
2 changes: 1 addition & 1 deletion crates/args/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
// Better way to do this?
let has_special_chars =
// Multi chars
bytes
bytes_len > 0 && bytes
.windows(bytes_len)
.any(|window| multi_chars.iter().any(|c| *c == window))
||
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'app> CodeGenerator<'app> {

let mut extends = vec![];

for extend_id in &template.config.extends {
for extend_id in template.config.extends.to_list() {
extends.push(self.get_template(extend_id)?);
}

Expand Down
1 change: 1 addition & 0 deletions crates/codegen/src/templates_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub async fn templates_command(
template
.config
.extends
.to_list()
.iter()
.map(color::id)
.collect::<Vec<_>>()
Expand Down
22 changes: 15 additions & 7 deletions crates/config-schema/src/typescript_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ fn generate_tasks(out_dir: &Path) -> miette::Result<()> {
generator.add::<PartialInheritedTasksConfig>();
generator.generate(
out_dir.join("tasks-config.ts"),
TypeScriptRenderer::default(),
TypeScriptRenderer::new(TypeScriptOptions {
exclude_references: vec!["ExtendsFrom".into()],
external_types: HashMap::from_iter([("./common".into(), vec!["ExtendsFrom".into()])]),
..Default::default()
}),
)
}

Expand All @@ -85,7 +89,11 @@ fn generate_toolchain(out_dir: &Path) -> miette::Result<()> {
generator.add::<PartialToolchainConfig>();
generator.generate(
out_dir.join("toolchain-config.ts"),
TypeScriptRenderer::default(),
TypeScriptRenderer::new(TypeScriptOptions {
exclude_references: vec!["ExtendsFrom".into()],
external_types: HashMap::from_iter([("./common".into(), vec!["ExtendsFrom".into()])]),
..Default::default()
}),
)
}

Expand All @@ -96,11 +104,11 @@ fn generate_workspace(out_dir: &Path) -> miette::Result<()> {
generator.generate(
out_dir.join("workspace-config.ts"),
TypeScriptRenderer::new(TypeScriptOptions {
exclude_references: vec!["PluginLocator".into()],
external_types: HashMap::from_iter([(
"./toolchain-config".into(),
vec!["PluginLocator".into()],
)]),
exclude_references: vec!["ExtendsFrom".into(), "PluginLocator".into()],
external_types: HashMap::from_iter([
("./common".into(), vec!["ExtendsFrom".into()]),
("./toolchain-config".into(), vec!["PluginLocator".into()]),
]),
..Default::default()
}),
)
Expand Down
6 changes: 3 additions & 3 deletions crates/config/src/inherited_tasks_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ cacheable!(
)]
pub schema: String,

/// Extends another tasks configuration file. Supports a relative
/// Extends one or many task configuration files. Supports a relative
/// file path or a secure URL.
#[setting(extend, validate = validate::extends_string)]
pub extends: Option<String>,
#[setting(extend, validate = validate::extends_from)]
pub extends: Option<schematic::ExtendsFrom>,

/// A mapping of group IDs to a list of file paths, globs, and
/// environment variables, that can be referenced from tasks.
Expand Down
9 changes: 8 additions & 1 deletion crates/config/src/shapes/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ impl<T: Schematic + Clone> OneOrMany<T> {
}
}

pub fn to_list(&self) -> Vec<T> {
pub fn to_list(&self) -> Vec<&T> {
match self {
Self::One(item) => vec![item],
Self::Many(list) => list.iter().collect(),
}
}

pub fn to_owned_list(&self) -> Vec<T> {
match self {
Self::One(item) => vec![item.to_owned()],
Self::Many(list) => list.to_owned(),
Expand Down
3 changes: 2 additions & 1 deletion crates/config/src/template_config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::shapes::OneOrMany;
use moon_common::Id;
use rustc_hash::FxHashMap;
use schematic::{validate, Config, ValidateError};
Expand Down Expand Up @@ -235,7 +236,7 @@ pub struct TemplateConfig {
pub destination: Option<String>,

/// Extends one or many other templates.
pub extends: Vec<Id>,
pub extends: OneOrMany<Id>,

/// Overrides the ID of the template, instead of using the folder name.
pub id: Option<Id>,
Expand Down
6 changes: 3 additions & 3 deletions crates/config/src/toolchain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub struct ToolchainConfig {
)]
pub schema: String,

/// Extends another toolchain configuration file. Supports a relative
/// Extends one or many toolchain configuration files. Supports a relative
/// file path or a secure URL.
#[setting(extend, validate = validate::extends_string)]
pub extends: Option<String>,
#[setting(extend, validate = validate::extends_from)]
pub extends: Option<schematic::ExtendsFrom>,

/// Configures and enables the Bun platform.
#[setting(nested)]
Expand Down
6 changes: 3 additions & 3 deletions crates/config/src/workspace_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ pub struct WorkspaceConfig {
#[setting(nested)]
pub experiments: ExperimentsConfig,

/// Extends another workspace configuration file. Supports a relative
/// Extends one or many workspace configuration file. Supports a relative
/// file path or a secure URL.
#[setting(extend, validate = validate::extends_string)]
pub extends: Option<String>,
#[setting(extend, validate = validate::extends_from)]
pub extends: Option<schematic::ExtendsFrom>,

/// Configures extensions that can be executed with `moon ext`.
#[setting(nested)]
Expand Down
4 changes: 2 additions & 2 deletions crates/task-builder/src/tasks_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl<'proj> TasksBuilder<'proj> {
if !config.toolchain.is_empty() {
task.toolchains = config
.toolchain
.to_list()
.to_owned_list()
.into_iter()
.filter(|tc| self.context.enabled_toolchains.contains(tc))
.collect();
Expand Down Expand Up @@ -635,7 +635,7 @@ impl<'proj> TasksBuilder<'proj> {
}

if let Some(os) = &config.os {
options.os = Some(os.to_list());
options.os = Some(os.to_owned_list());
}

if let Some(output_style) = &config.output_style {
Expand Down
2 changes: 1 addition & 1 deletion crates/task-runner/src/command_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'task> CommandExecutor<'task> {
}

fn monitor_running_status(&mut self) {
if self.persistent || self.interactive {
if self.persistent {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export interface Runtime {
requirement?: string;
overridden?: boolean;
}

export type ExtendsFrom = string[] | string;
2 changes: 1 addition & 1 deletion packages/types/src/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

/* eslint-disable */

import type { PartialTaskConfig, PlatformType, TaskConfig } from './tasks-config';
import type { UnresolvedVersionSpec } from './toolchain-config';
import type { PartialTaskConfig, PlatformType, TaskConfig } from './tasks-config';

/** The task-to-task relationship of the dependency. */
export type DependencyType = 'cleanup' | 'required' | 'optional';
Expand Down
10 changes: 6 additions & 4 deletions packages/types/src/tasks-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* eslint-disable */

import type { ExtendsFrom } from './common';

export type TaskArgs = null | string | string[];

/** Expanded information about a task dependency. */
Expand Down Expand Up @@ -261,10 +263,10 @@ export interface InheritedTasksConfig {
/** @default 'https://moonrepo.dev/schemas/tasks.json' */
$schema?: string;
/**
* Extends another tasks configuration file. Supports a relative
* Extends one or many task configuration files. Supports a relative
* file path or a secure URL.
*/
extends: string | null;
extends: ExtendsFrom | null;
/**
* A mapping of group IDs to a list of file paths, globs, and
* environment variables, that can be referenced from tasks.
Expand Down Expand Up @@ -509,10 +511,10 @@ export interface PartialInheritedTasksConfig {
/** @default 'https://moonrepo.dev/schemas/tasks.json' */
$schema?: string | null;
/**
* Extends another tasks configuration file. Supports a relative
* Extends one or many task configuration files. Supports a relative
* file path or a secure URL.
*/
extends?: string | null;
extends?: ExtendsFrom | null;
/**
* A mapping of group IDs to a list of file paths, globs, and
* environment variables, that can be referenced from tasks.
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/template-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export interface TemplateConfig {
*/
destination: string | null;
/** Extends one or many other templates. */
extends: string[];
extends: string | string[];
/** Overrides the ID of the template, instead of using the folder name. */
id: string | null;
/** A human-readable title for the template. */
Expand Down Expand Up @@ -218,7 +218,7 @@ export interface PartialTemplateConfig {
*/
destination?: string | null;
/** Extends one or many other templates. */
extends?: string[] | null;
extends?: string | string[] | null;
/** Overrides the ID of the template, instead of using the folder name. */
id?: string | null;
/** A human-readable title for the template. */
Expand Down
10 changes: 6 additions & 4 deletions packages/types/src/toolchain-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* eslint-disable */

import type { ExtendsFrom } from './common';

/** Formats that a `package.json` version dependency can be. */
export type NodeVersionFormat =
| 'file'
Expand Down Expand Up @@ -400,10 +402,10 @@ export interface ToolchainConfig {
/** Configures and enables the Deno platform. */
deno: DenoConfig | null;
/**
* Extends another toolchain configuration file. Supports a relative
* Extends one or many toolchain configuration files. Supports a relative
* file path or a secure URL.
*/
extends: string | null;
extends: ExtendsFrom | null;
/** Configures moon itself. */
moon: MoonConfig;
/** Configures and enables the Node.js platform. */
Expand Down Expand Up @@ -791,10 +793,10 @@ export interface PartialToolchainConfig {
/** Configures and enables the Deno platform. */
deno?: PartialDenoConfig | null;
/**
* Extends another toolchain configuration file. Supports a relative
* Extends one or many toolchain configuration files. Supports a relative
* file path or a secure URL.
*/
extends?: string | null;
extends?: ExtendsFrom | null;
/** Configures moon itself. */
moon?: PartialMoonConfig | null;
/** Configures and enables the Node.js platform. */
Expand Down
9 changes: 5 additions & 4 deletions packages/types/src/workspace-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* eslint-disable */

import type { ExtendsFrom } from './common';
import type { PluginLocator } from './toolchain-config';

/** How to order ownership rules within the generated file. */
Expand Down Expand Up @@ -371,10 +372,10 @@ export interface WorkspaceConfig {
/** Configures experiments across the entire moon workspace. */
experiments: ExperimentsConfig;
/**
* Extends another workspace configuration file. Supports a relative
* Extends one or many workspace configuration file. Supports a relative
* file path or a secure URL.
*/
extends: string | null;
extends: ExtendsFrom | null;
/** Configures extensions that can be executed with `moon ext`. */
extensions: Record<string, ExtensionConfig>;
/** Configures the generator for scaffolding from templates. */
Expand Down Expand Up @@ -748,10 +749,10 @@ export interface PartialWorkspaceConfig {
/** Configures experiments across the entire moon workspace. */
experiments?: PartialExperimentsConfig | null;
/**
* Extends another workspace configuration file. Supports a relative
* Extends one or many workspace configuration file. Supports a relative
* file path or a secure URL.
*/
extends?: string | null;
extends?: ExtendsFrom | null;
/** Configures extensions that can be executed with `moon ext`. */
extensions?: Record<string, PartialExtensionConfig> | null;
/** Configures the generator for scaffolding from templates. */
Expand Down
6 changes: 3 additions & 3 deletions website/docs/config/tasks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ $schema: 'https://moonrepo.dev/schemas/tasks.json'

<HeadingApiLink to="/api/types/interface/InheritedTasksConfig#extends" />

Defines an external `.moon/tasks.yml` to extend and inherit settings from. Perfect for reusability
and sharing configuration across repositories and projects. When defined, this setting must be an
HTTPS URL _or_ relative file system path that points to a valid YAML document!
Defines one or many external `.moon/tasks.yml`'s to extend and inherit settings from. Perfect for
reusability and sharing configuration across repositories and projects. When defined, this setting
must be an HTTPS URL _or_ relative file system path that points to a valid YAML document!

```yaml title=".moon/tasks.yml" {1}
extends: 'https://raw.githubusercontent.com/organization/repository/master/.moon/tasks.yml'
Expand Down
2 changes: 1 addition & 1 deletion website/docs/config/template.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ destination: 'packages/[name]'

<HeadingApiLink to="/api/types/interface/TemplateConfig#extends" />

A list of other templates that this template should extend. Will deeply inherit all template files
One or many other templates that this template should extend. Will deeply inherit all template files
and variables.

```yaml title="template.yml"
Expand Down
6 changes: 3 additions & 3 deletions website/docs/config/toolchain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ $schema: 'https://moonrepo.dev/schemas/toolchain.json'

<HeadingApiLink to="/api/types/interface/ToolchainConfig#extends" />

Defines an external `.moon/toolchain.yml` to extend and inherit settings from. Perfect for
reusability and sharing configuration across repositories and projects. When defined, this setting
must be an HTTPS URL _or_ relative file system path that points to a valid YAML document!
Defines one or many external `.moon/toolchain.yml`'s to extend and inherit settings from. Perfect
for reusability and sharing configuration across repositories and projects. When defined, this
setting must be an HTTPS URL _or_ relative file system path that points to a valid YAML document!

```yaml title=".moon/toolchain.yml" {1}
extends: 'https://raw.githubusercontent.com/organization/repository/master/.moon/toolchain.yml'
Expand Down
6 changes: 3 additions & 3 deletions website/docs/config/workspace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ $schema: 'https://moonrepo.dev/schemas/workspace.json'

<HeadingApiLink to="/api/types/interface/WorkspaceConfig#extends" />

Defines an external `.moon/workspace.yml` to extend and inherit settings from. Perfect for
reusability and sharing configuration across repositories and projects. When defined, this setting
must be an HTTPS URL _or_ relative file system path that points to a valid YAML document!
Defines one or many external `.moon/workspace.yml`'s to extend and inherit settings from. Perfect
for reusability and sharing configuration across repositories and projects. When defined, this
setting must be an HTTPS URL _or_ relative file system path that points to a valid YAML document!

```yaml title=".moon/workspace.yml" {1}
extends: 'https://raw.githubusercontent.com/organization/repository/master/.moon/workspace.yml'
Expand Down
17 changes: 15 additions & 2 deletions website/static/schemas/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"extends": {
"title": "extends",
"description": "Extends another tasks configuration file. Supports a relative file path or a secure URL.",
"description": "Extends one or many task configuration files. Supports a relative file path or a secure URL.",
"anyOf": [
{
"type": "string"
"$ref": "#/definitions/ExtendsFrom"
},
{
"type": "null"
Expand Down Expand Up @@ -76,6 +76,19 @@
},
"additionalProperties": false,
"definitions": {
"ExtendsFrom": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"PlatformType": {
"description": "Platforms that each programming language can belong to.",
"type": "string",
Expand Down
Loading
Loading