Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

new: Add pre-publish validation and build steps. #19

Closed
wants to merge 11 commits into from
Closed
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
856 changes: 380 additions & 476 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,38 @@ resolver = "2"
members = ["crates/*"]

[workspace.dependencies]
cached = "0.44.0"
clap = { version = "4.4.2", features = ["derive"] }
cached = "0.46.0"
clap = { version = "4.4.6", features = ["derive"] }
miette = "5.10.0"
once_cell = "1.18.0"
once_map = "0.4.8"
petgraph = "0.6.4"
relative-path = { version = "1.9.0", features = ["serde"] }
reqwest = { version = "0.11.20", default-features = false, features = [
reqwest = { version = "0.11.22", default-features = false, features = [
"rustls-tls",
] }
schematic = { version = "0.11.5", default-features = false, features = [
schematic = { version = "0.12.7", default-features = false, features = [
"config",
"schema",
"toml",
"type_relative_path",
"type_semver",
"type_url",
"valid_url",
] }
semver = "1.0.18"
serde = "1.0.188"
serde_json = "1.0.105"
starbase = { version = "0.2.5" }
starbase_archive = { version = "0.2.0", default-features = false }
starbase_sandbox = { version = "0.1.8" }
starbase_styles = "0.1.13"
starbase_utils = { version = "0.2.21", default-features = false, features = [
semver = "1.0.20"
serde = "1.0.189"
serde_json = "1.0.107"
starbase = { version = "0.2.9" }
starbase_archive = { version = "0.2.4", default-features = false }
starbase_sandbox = { version = "0.1.12" }
starbase_styles = "0.1.16"
starbase_utils = { version = "0.3.6", default-features = false, features = [
"glob",
] }
thiserror = "1.0.48"
tokio = { version = "1.32.0", features = ["full", "tracing"] }
tracing = "0.1.37"
thiserror = "1.0.50"
tokio = { version = "1.33.0", features = ["full", "tracing"] }
tracing = "0.1.40"
url = { version = "2.4.1", features = ["serde"] }

# Config for 'cargo dist'
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ espresso_store = { path = "../store" }
espresso_workspace = { path = "../workspace" }
clap = { workspace = true, features = ["derive", "env", "wrap_help"] }
console = "0.15.7"
dialoguer = { version = "0.10.4", default-features = false }
dialoguer = { version = "0.11.0", default-features = false }
miette = { workspace = true }
mimalloc = { version = "0.1.38", default-features = false }
mimalloc = { version = "0.1.39", default-features = false }
relative-path = { workspace = true }
starbase = { workspace = true }
starbase_styles = { workspace = true }
Expand Down
32 changes: 16 additions & 16 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::commands::{BuildArgs, NewArgs};
use crate::commands::{BuildArgs, NewArgs, PublishArgs};
use clap::{Parser, Subcommand};
use espresso_common::PackageName;
use espresso_workspace::SelectQuery;
Expand All @@ -7,7 +7,7 @@ use starbase::State;
pub const BIN_NAME: &str = if cfg!(windows) { "espm.exe" } else { "espm" };

static HEADING_FILTER: &str = "Package selection";
static HEADING_PKG_MANAGEMENT: &str = "Package management";
// static HEADING_PKG_MANAGEMENT: &str = "Package management";

#[derive(Clone, Debug, State)]
pub struct GlobalArgs {
Expand All @@ -28,6 +28,14 @@ impl GlobalArgs {

#[derive(Clone, Debug, Subcommand)]
pub enum Commands {
#[command(
alias = "b",
name = "build",
about = "Build a package.",
long_about = "Build a package by transforming source files (from the package's `src` directory) to the `.espm/<target>` output directory."
)]
Build(BuildArgs),

#[command(name = "debug", about = "Debug espresso instance.", hide = true)]
Debug,

Expand All @@ -38,23 +46,15 @@ pub enum Commands {
)]
Init(NewArgs),

// PACKAGE MANAGEMENT
#[command(
alias = "b",
name = "build",
about = "Build a package.",
long_about = "Build a package by transforming source files (from the package's `src` directory) to the `.espm/<target>` output directory.",
next_help_heading = HEADING_PKG_MANAGEMENT,
)]
Build(BuildArgs),
#[command(alias = "n", name = "new", about = "Create a new package.")]
New(NewArgs),

#[command(
alias = "n",
name = "new",
about = "Create a new package.",
next_help_heading = HEADING_PKG_MANAGEMENT,
alias = "p",
name = "publish",
about = "Publish a package to the espresso registry."
)]
New(NewArgs),
Publish(PublishArgs),
}

#[derive(Clone, Debug, Parser, State)]
Expand Down
24 changes: 18 additions & 6 deletions crates/cli/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use crate::helpers::loop_packages;
use clap::Args;
use espresso_common::EsTarget;
use espresso_compiler::Compiler;
use espresso_package::Package;
use espresso_store::Store;
use espresso_workspace::Workspace;
use starbase::system;
use starbase::{system, AppResult};
use starbase_styles::color;
use std::path::PathBuf;
use std::sync::Arc;

#[derive(Args, Clone, Debug)]
Expand All @@ -22,6 +24,20 @@ pub struct BuildArgs {
pub target: EsTarget,
}

pub async fn internal_build(
store: Arc<Store>,
package: Arc<Package>,
target: EsTarget,
) -> AppResult<PathBuf> {
let out_dir = Compiler::new(Arc::clone(&package), store)?
.compile(target)
.await?;

package.copy_info_files(&out_dir)?;

Ok(out_dir)
}

#[system]
pub async fn build(
args: ArgsRef<BuildArgs>,
Expand All @@ -35,11 +51,7 @@ pub async fn build(
loop_packages(packages, |package| async {
println!("Building target {}", color::symbol(args.target.to_string()));

let out_dir = Compiler::new(package, Arc::clone(&store))?
.compile(args.target)
.await?;

package.copy_info_files(&out_dir)?;
let out_dir = internal_build(Arc::clone(&store), package, args.target).await?;

println!("Built to {}", color::path(out_dir));

Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ mod build;
mod debug;
mod init;
mod new;
mod publish;

pub use build::*;
pub use debug::*;
pub use init::*;
pub use new::*;
pub use publish::*;
52 changes: 52 additions & 0 deletions crates/cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use super::build::internal_build;
use crate::app::GlobalArgs;
use crate::helpers::start_checkpoint;
use clap::Args;
use espresso_common::{Channel, EsTarget};
use espresso_store::Store;
use espresso_workspace::Workspace;
use starbase::system;
use starbase_styles::color;
use std::sync::Arc;
use tracing::debug;

#[derive(Args, Clone, Debug)]
pub struct PublishArgs {
#[arg(
value_enum,
long,
env = "ESPM_CHANNEL",
help = "Release channel to publish to.",
default_value_t
)]
pub channel: Channel,
}

#[system]
pub async fn publish(
_args: ArgsRef<PublishArgs>,
global_args: StateRef<GlobalArgs>,
workspace: ResourceRef<Workspace>,
store: ResourceRef<Store>,
) {
let store = Arc::new(store.to_owned());
let packages = workspace.select_packages(global_args.to_package_select_query())?;

start_checkpoint("Validating manifests");

for package in &packages {
debug!("Validating {}", color::id(package.name()));

package.validate_for_publish()?;
}

start_checkpoint("Running test builds");

for package in &packages {
debug!("Building {}", color::id(package.name()));

internal_build(Arc::clone(&store), Arc::clone(package), EsTarget::Es2015).await?;
}

start_checkpoint("Publishing packages (TODO)");
}
13 changes: 5 additions & 8 deletions crates/cli/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use dialoguer::theme::ColorfulTheme;
use espresso_package::Package;
use starbase_styles::color::{create_style, Color, OwoStyle};
use std::future::Future;
use std::sync::Arc;

pub fn create_theme() -> ColorfulTheme {
ColorfulTheme {
Expand Down Expand Up @@ -51,32 +52,28 @@ pub fn create_theme() -> ColorfulTheme {
.bold()
.color256(Color::Teal as u8),
unpicked_item_prefix: style(" ".to_string()).for_stderr(),
..ColorfulTheme::default()
}
}

pub fn start_checkpoint<T: AsRef<str>>(label: T) {
println!(
"{} {}",
create_style(Color::Yellow as u8).bold().style("===>"),
create_style(Color::Yellow as u8).bold().style("==>"),
OwoStyle::new().bold().style(label.as_ref()),
);
}

pub async fn loop_packages<'pkg, F, Fut>(
packages: Vec<&'pkg Package>,
func: F,
) -> miette::Result<()>
pub async fn loop_packages<F, Fut>(packages: Vec<Arc<Package>>, func: F) -> miette::Result<()>
where
F: Fn(&'pkg Package) -> Fut,
F: Fn(Arc<Package>) -> Fut,
Fut: Future<Output = miette::Result<()>>,
{
let last_index = packages.len() - 1;

for (index, package) in packages.iter().enumerate() {
start_checkpoint(package.name());

func(package).await?;
func(Arc::clone(package)).await?;

if index != last_index {
println!();
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ async fn main() -> MainResult {
Commands::New(args) => {
app.execute_with_args(commands::new, args);
}
Commands::Publish(args) => {
app.execute_with_args(commands::publish, args);
}
};

app.run().await?;
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub fn create_espm_command(sandbox: &Path) -> starbase_sandbox::assert_cmd::Comm
let mut cmd = create_command_with_name(sandbox, "espm");
cmd.env("ESPM_LOG", "trace");
cmd.env("ESPM_TEST", "true");
cmd.env(
"ESPM_ROOT",
sandbox.join(".espresso").to_string_lossy().to_string(),
);
// cmd.env(
// "ESPM_ROOT",
// sandbox.join(".espresso").to_string_lossy().to_string(),
// );
cmd
}

Expand Down
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
clap = { workspace = true }
miette = { workspace = true }
once_cell = { workspace = true }
regex = "1.9.5"
regex = "1.10.2"
schematic = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/common/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use clap::ValueEnum;
use schematic::{derive_enum, ConfigEnum};

derive_enum!(
#[derive(ConfigEnum, ValueEnum)]
#[derive(ConfigEnum, Default, ValueEnum)]
pub enum Channel {
Stable, // latest
#[default]
Stable, // latest
Unstable, // next, beta, alpha, etc
Experimental, // one-off
Nightly,
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ anyhow = "1.0.75"
cached = { workspace = true }
futures = "0.3.28"
miette = { workspace = true }
oxipng = "8.0.0"
oxipng = "9.0.0"
relative-path = { workspace = true }
swc = "0.264.71"
swc_core = { version = "0.81.6", default-features = false, features = [
swc = "0.266.1"
swc_core = { version = "0.83.2", default-features = false, features = [
"common",
"ecma_ast",
"ecma_parser",
Expand Down
8 changes: 4 additions & 4 deletions crates/compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use swc_core::common::{FilePathMapping, SourceMap};
use tokio::task::{self, JoinHandle};
use tracing::debug;

pub struct Compiler<'pkg> {
pub struct Compiler {
compiler: Arc<SwcCompiler>,
package: &'pkg Package,
package: Arc<Package>,
store: Arc<Store>,
}

impl<'pkg> Compiler<'pkg> {
pub fn new(package: &Package, store: Arc<Store>) -> miette::Result<Compiler> {
impl Compiler {
pub fn new(package: Arc<Package>, store: Arc<Store>) -> miette::Result<Compiler> {
debug!(package = package.name(), "Creating compiler");

Ok(Compiler {
Expand Down
Loading
Loading