diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml index 88d37b9..f1b3d32 100644 --- a/.github/workflows/pre-release.yaml +++ b/.github/workflows/pre-release.yaml @@ -31,7 +31,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Add target run: rustup target add ${{ matrix.target }} - name: Cross-compile @@ -42,7 +42,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to crates.io run: cargo login ${{ secrets.CRATES_IO_TOKEN }} - name: Dry run of crate publish diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b7d026d..88c5a8b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,7 +22,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Add target run: rustup target add ${{ matrix.target }} - name: Compile binary @@ -32,7 +32,7 @@ jobs: cd target/${{ matrix.target }}/release tar -czf ${{ matrix.target }}.tar.gz depot - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.target }} path: target/${{ matrix.target }}/release/${{ matrix.target }}.tar.gz @@ -46,7 +46,7 @@ jobs: with: crate: cargo-workspaces - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to crates.io run: cargo login ${{ secrets.CRATES_IO_TOKEN }} - name: Publish crates diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5a1b7fc..f3ed7f4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -19,7 +19,7 @@ jobs: TOKIO_WORKER_THREADS: 1 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run tests run: cargo test --features dev -- --test-threads=1 - name: Run lints diff --git a/crates/depot/Cargo.toml b/crates/depot/Cargo.toml index 9a1171e..397685b 100644 --- a/crates/depot/Cargo.toml +++ b/crates/depot/Cargo.toml @@ -21,29 +21,19 @@ package_json_schema = "0.2" indexmap = "1" # This must match package_json_schema ## TUI -ratatui = "0.27.0" +ratatui = "=0.27.0" # Note: use-dev-tty seems to be important to avoid a slowdown of handling user input # when combined w/ async-process... not sure why crossterm = { version = "0.26", features = ["event-stream", "use-dev-tty"] } -ansi-to-tui = "4.0.1" # This must match ratatui +ansi-to-tui = "=4.0.1" # This must match ratatui ansi-diff = "1" indicatif = "0.17" -## Utils -anyhow = "1" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -home = "0.5" -petgraph = { version = "0.6", default-features = false } -cfg-if = "1" -textwrap = "0.16" -bimap = "0.6" -maplit = "1" +## OS notify = { version = "6.0.1", default-features = false, features = ["macos_kqueue"] } notify-debouncer-mini = { version = "0.3.0", default-features = false } -ignore = "0.4.22" pathsearch = "0.2.0" -chrono = { version = "0.4.38", features = ["serde", "std", "now"], default-features = false } +home = "0.5" ## Async futures = { version = "0.3", default-features = false, features = ["std"] } @@ -53,6 +43,18 @@ atomic_enum = "0.2" # We use rustls to avoid issues linking w/ libssl when cross-compiling reqwest = {version = "0.11.27", default-features = false, features = ["stream", "rustls-tls"]} +## Utils +anyhow = "1" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +petgraph = { version = "0.6", default-features = false } +cfg-if = "1" +textwrap = "0.16" +bimap = "0.6" +maplit = "1" +ignore = "0.4.22" +chrono = { version = "0.4.38", features = ["serde", "std", "now"], default-features = false } + ## Dev log = "0.4" env_logger = { version = "0.10", default-features = false } diff --git a/crates/depot/src/commands/new.rs b/crates/depot/src/commands/new.rs index 434d2d3..1f130d1 100644 --- a/crates/depot/src/commands/new.rs +++ b/crates/depot/src/commands/new.rs @@ -641,7 +641,7 @@ export default defineConfig(({{ mode }}) => ({{ let pkg_config = PackageDepotConfig { platform: *platform, target: Some(*target), - no_server: None, + ..Default::default() }; let ws_config = WorkspaceDepotConfig { depot_version: DEPOT_VERSION.to_string(), diff --git a/crates/depot/src/lib.rs b/crates/depot/src/lib.rs index e018dd5..51d4f92 100644 --- a/crates/depot/src/lib.rs +++ b/crates/depot/src/lib.rs @@ -3,7 +3,8 @@ clippy::format_collect, clippy::similar_names, clippy::module_name_repetitions, - clippy::single_match_else + clippy::single_match_else, + clippy::items_after_statements )] use self::commands::Command; diff --git a/crates/depot/src/utils.rs b/crates/depot/src/utils.rs index 245c2e3..d7143a9 100644 --- a/crates/depot/src/utils.rs +++ b/crates/depot/src/utils.rs @@ -54,8 +54,7 @@ macro_rules! test_packages { if !other.contains_key("depot") { other.insert(String::from("depot"), serde_json::to_value(PackageDepotConfig { platform: Platform::Browser, - target: None, - no_server: None + ..Default::default() }).unwrap()); } let manifest = PackageManifest::from_json(manifest, std::path::Path::new("dummy.rs")).expect("Manifest failed to convert to Depot format"); diff --git a/crates/depot/src/workspace/package.rs b/crates/depot/src/workspace/package.rs index 2f36a49..e2ae310 100644 --- a/crates/depot/src/workspace/package.rs +++ b/crates/depot/src/workspace/package.rs @@ -3,6 +3,7 @@ use anyhow::{bail, ensure, Context, Error, Result}; use ignore::Walk; use maplit::hashset; use std::{ + collections::HashSet, fmt::{self, Debug}, hash::Hash, path::{Path, PathBuf}, @@ -112,10 +113,30 @@ impl FromStr for PackageName { #[serde(rename_all = "kebab-case")] pub struct PackageDepotConfig { pub platform: Platform, + #[serde(skip_serializing_if = "Option::is_none")] pub target: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub no_server: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub asset_extensions: Option>, + + #[serde(skip_serializing_if = "Option::is_none")] + pub source_extensions: Option>, +} + +impl Default for PackageDepotConfig { + fn default() -> Self { + PackageDepotConfig { + platform: Platform::Browser, + target: None, + no_server: None, + asset_extensions: None, + source_extensions: None, + } + } } pub type PackageManifest = DepotManifest; @@ -266,35 +287,43 @@ impl PackageInner { }) } - pub fn asset_files(&self) -> impl Iterator { - // TODO: make this configurable - let asset_extensions = hashset! { "scss", "css", "jpeg", "jpg", "png", "svg" }; + pub fn asset_files(&self) -> impl Iterator + '_ { + let mut asset_extensions: HashSet<&str> = + hashset! { "scss", "css", "jpeg", "jpg", "png", "svg" }; + if let Some(exts) = &self.manifest.config.asset_extensions { + asset_extensions.extend(exts.iter().map(String::as_str)); + } - self.iter_files("src").filter_map(move |path| { - let ext = path.extension()?; - asset_extensions - .contains(ext.to_str().unwrap()) - .then_some(path) - }) + self + .iter_files("src") + .filter_map(move |path| { + let ext = path.extension()?; + asset_extensions + .contains(ext.to_str().unwrap()) + .then_some(path) + }) + .chain(self.iter_files("src/assets")) + .collect::>() // dedup + .into_iter() } pub fn source_files(&self) -> impl Iterator + '_ { - // TODO: make this configurable - let source_extensions = hashset! { "ts", "tsx", "html" }; + let mut source_extensions = hashset! { "ts", "tsx", "html" }; + if let Some(exts) = &self.manifest.config.source_extensions { + source_extensions.extend(exts.iter().map(String::as_str)); + } + + const CONFIG_FILES: &[&str] = &[ + "vite.config.ts", + "vite.config.mts", + "vitest.config.ts", + "vitest.config.mts", + ]; ["src", "tests"] .into_iter() .flat_map(|dir| self.iter_files(dir)) - .chain( - [ - "vite.config.ts", - "vite.config.mts", - "vitest.config.ts", - "vitest.config.mts", - ] - .iter() - .map(PathBuf::from), - ) + .chain(CONFIG_FILES.iter().map(PathBuf::from)) .filter_map(move |path| { if !path.exists() { return None; diff --git a/crates/depot/tests/tests/build.rs b/crates/depot/tests/tests/build.rs index 7d58d7d..57d8afd 100644 --- a/crates/depot/tests/tests/build.rs +++ b/crates/depot/tests/tests/build.rs @@ -60,6 +60,16 @@ fn basic_site_browser_sass() { assert!(project.exists("dist/index.html")); } +#[test] +fn copy_assets() { + let p = project(); + p.file("src/assets/foo.txt", ""); + p.file("src/styles/bar.css", ""); + p.depot("build"); + assert!(p.exists("dist/assets/foo.txt")); + assert!(p.exists("dist/styles/bar.css")); +} + #[test] fn release() { let p = project();