Skip to content

Commit

Permalink
Add assets directory. Update CI. Add asset and src extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Jul 22, 2024
1 parent e9b43f8 commit db6946f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions crates/depot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion crates/depot/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion crates/depot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/depot/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
71 changes: 50 additions & 21 deletions crates/depot/src/workspace/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<Target>,

#[serde(skip_serializing_if = "Option::is_none")]
pub no_server: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
pub asset_extensions: Option<Vec<String>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub source_extensions: Option<Vec<String>>,
}

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<PackageDepotConfig>;
Expand Down Expand Up @@ -266,35 +287,43 @@ impl PackageInner {
})
}

pub fn asset_files(&self) -> impl Iterator<Item = PathBuf> {
// TODO: make this configurable
let asset_extensions = hashset! { "scss", "css", "jpeg", "jpg", "png", "svg" };
pub fn asset_files(&self) -> impl Iterator<Item = PathBuf> + '_ {
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::<HashSet<_>>() // dedup
.into_iter()
}

pub fn source_files(&self) -> impl Iterator<Item = PathBuf> + '_ {
// 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;
Expand Down
10 changes: 10 additions & 0 deletions crates/depot/tests/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit db6946f

Please sign in to comment.