diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 785459fe..5ae08b8e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,82 +15,57 @@ on: - "Cargo.toml" env: CARGO_TERM_COLOR: always - CARGO_INCREMENTAL: true + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse concurrency: group: CI-${{ github.ref }} cancel-in-progress: true jobs: - build: - name: Build and Initialize profile.dev Cache - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3.3.0 - - uses: rui314/setup-mold@v1 - - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions/cache@v3.2.5 - with: - path: | - ./.cargo/.build - ./target - ~/.cargo - key: ${{ runner.os }}-cargo-dev-${{ hashFiles('**/Cargo.lock') }} - - uses: actions-rs/cargo@v1.0.3 - with: - command: build - check: - name: Check - needs: [build] + development-lint: + name: Clippy with debug-assertions runs-on: ubuntu-latest steps: - uses: actions/checkout@v3.3.0 - uses: rui314/setup-mold@v1 - - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions/cache@v3.2.5 + - run: rustup install stable + - run: rustup update + - run: rustup component add clippy + - uses: actions/cache@v3.2.6 with: path: | ./.cargo/.build ./target ~/.cargo key: ${{ runner.os }}-cargo-dev-${{ hashFiles('**/Cargo.lock') }} - - uses: actions-rs/cargo@v1.0.3 + - name: Clippy + uses: actions-rs/cargo@v1.0.3 with: - command: check - - clippy: - name: Clippy - needs: [build] + command: clippy + args: -- -D warnings -C debug-assertions=y + + production-lint: + name: Clippy without debug-assertions runs-on: ubuntu-latest steps: - uses: actions/checkout@v3.3.0 - uses: rui314/setup-mold@v1 - - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - override: true + - run: rustup install stable + - run: rustup update - run: rustup component add clippy - - uses: actions/cache@v3.2.5 + - uses: actions/cache@v3.2.6 with: path: | ./.cargo/.build ./target ~/.cargo - key: ${{ runner.os }}-cargo-dev-${{ hashFiles('**/Cargo.lock') }} - - uses: actions-rs/cargo@v1.0.3 + key: ${{ runner.os }}-cargo-prod-${{ hashFiles('**/Cargo.lock') }} + - name: Clippy + uses: actions-rs/cargo@v1.0.3 with: command: clippy - args: -- -D warnings + args: -- -D warnings -C debug-assertions=n # things that use the cargo-test cache test: @@ -99,11 +74,8 @@ jobs: steps: - uses: actions/checkout@v3.3.0 - uses: rui314/setup-mold@v1 - - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - override: true + - run: rustup install stable + - run: rustup update - uses: actions/cache@v3.2.5 with: path: | @@ -122,13 +94,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3.3.0 - - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - override: true + - run: rustup install stable + - run: rustup update - run: rustup component add rustfmt - uses: actions-rs/cargo@v1.0.3 with: command: fmt - args: --all -- --check + args: --all -- --check \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5bb68acd..0d99d3ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3105,9 +3105,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.45" +version = "0.10.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +checksum = "518915b97df115dd36109bfa429a48b8f737bd05508cf9588977b599648926d2" dependencies = [ "bitflags", "cfg-if", @@ -3137,9 +3137,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.80" +version = "0.9.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +checksum = "666416d899cf077260dac8698d60a60b435a46d57e82acb1be3d0dad87284e5b" dependencies = [ "autocfg", "cc", @@ -3716,9 +3716,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "6.4.2" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "283ffe2f866869428c92e0d61c2f35dfb4355293cdfdc48f49e895c15f1333d1" +checksum = "1b68543d5527e158213414a92832d2aab11a84d2571a5eb021ebe22c43aab066" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -3727,9 +3727,9 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "6.3.1" +version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ab23d42d71fb9be1b643fe6765d292c5e14d46912d13f3ae2815ca048ea04d" +checksum = "4d4e0f0ced47ded9a68374ac145edd65a6c1fa13a96447b873660b2a568a0fd7" dependencies = [ "proc-macro2", "quote", @@ -3741,9 +3741,9 @@ dependencies = [ [[package]] name = "rust-embed-utils" -version = "7.3.0" +version = "7.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1669d81dfabd1b5f8e2856b8bbe146c6192b0ba22162edc738ac0a5de18f054" +checksum = "512b0ab6853f7e14e3c8754acb43d6f748bb9ced66aa5915a6553ac8213f7731" dependencies = [ "sha2", "walkdir", diff --git a/create-rust-app/Cargo.toml b/create-rust-app/Cargo.toml index f31a33c6..b412912a 100644 --- a/create-rust-app/Cargo.toml +++ b/create-rust-app/Cargo.toml @@ -110,6 +110,7 @@ plugin_storage = [ "aws-config", "aws-types", "aws-endpoint", "aws-sdk-s3", "tok plugin_graphql = [] plugin_utoipa = ["utoipa", "utoipa-swagger-ui", "backend_actix-web"] plugin_tasks = ["fang"] +plugin_workspace_support = [] backend_poem = ["poem", "anyhow", "mime_guess", "tokio"] backend_actix-web = ["actix-web", "actix-http", "actix-files", "actix-multipart", "actix-web-httpauth","derive_more", "futures", "env_logger"] backend_axum = ["axum", "axum/ws", "tokio"] diff --git a/create-rust-app/src/database/mod.rs b/create-rust-app/src/database/mod.rs index c8b9f9a4..ddbd053c 100644 --- a/create-rust-app/src/database/mod.rs +++ b/create-rust-app/src/database/mod.rs @@ -1,5 +1,5 @@ -use diesel::PgConnection; use diesel::r2d2::{self, ConnectionManager, PooledConnection}; + use once_cell::sync::OnceCell; #[cfg(feature = "database_postgres")] @@ -8,6 +8,7 @@ type DbCon = diesel::PgConnection; #[cfg(feature = "database_sqlite")] type DbCon = diesel::SqliteConnection; +#[allow(dead_code)] #[cfg(feature = "database_postgres")] pub type DieselBackend = diesel::pg::Pg; diff --git a/create-rust-app/src/dev/mod.rs b/create-rust-app/src/dev/mod.rs index 1abc55ff..bebef395 100644 --- a/create-rust-app/src/dev/mod.rs +++ b/create-rust-app/src/dev/mod.rs @@ -197,7 +197,15 @@ fn get_features(project_dir: &'static str) -> Vec { let cargo_toml = Manifest::from_path(PathBuf::from_iter([project_dir, "Cargo.toml"])) .unwrap_or_else(|_| panic!("Could not find \"{}\"", project_dir)); // .expect(&format!("Could not find \"{project_dir}\"")); + #[cfg(not(feature = "plugin_workspace_support"))] let deps = cargo_toml.dependencies; + #[cfg(feature = "plugin_workspace_support")] + let mut deps = cargo_toml.dependencies; + #[cfg(feature = "plugin_workspace_support")] + if let Some(workspace) = cargo_toml.workspace { + // if the manifest has a workspace table, also read dependencies in there + deps.extend(workspace.dependencies); + } let dep = deps.get("create-rust-app").unwrap_or_else(|| { panic!( "Expected \"{}\" to list 'create-rust-app' as a dependency.", diff --git a/create-rust-app/src/tasks/mod.rs b/create-rust-app/src/tasks/mod.rs index d2ebc9cc..c9cd5525 100644 --- a/create-rust-app/src/tasks/mod.rs +++ b/create-rust-app/src/tasks/mod.rs @@ -1,6 +1,6 @@ +use crate::Database; use fang::Queue; use once_cell::sync::OnceCell; -use crate::Database; // re-export setup for tasks pub use crate::setup; @@ -13,8 +13,6 @@ pub fn queue() -> &'static Queue { QUEUE.get_or_init(|| { let db = Database::new(); - Queue::builder() - .connection_pool(db.pool.clone()) - .build() + Queue::builder().connection_pool(db.pool.clone()).build() }) } diff --git a/create-rust-app/src/util/actix_web_utils.rs b/create-rust-app/src/util/actix_web_utils.rs index e819f78f..52bdb866 100644 --- a/create-rust-app/src/util/actix_web_utils.rs +++ b/create-rust-app/src/util/actix_web_utils.rs @@ -1,10 +1,14 @@ +#[cfg(debug_assertions)] +use actix_http::Uri; +#[cfg(debug_assertions)] use std::str::FromStr; +#[cfg(debug_assertions)] use std::sync::Mutex; use super::template_utils::SinglePageApplication; use crate::util::template_utils::{to_template_name, DEFAULT_TEMPLATE, TEMPLATES}; use actix_files::NamedFile; -use actix_http::Uri; + use actix_web::http::StatusCode; use actix_web::{web, HttpRequest, HttpResponse, Scope}; use tera::Context; @@ -136,11 +140,14 @@ pub async fn render_views(req: HttpRequest) -> HttpResponse { template_response(req, content) } -fn template_response(req: HttpRequest, content: String) -> HttpResponse { +fn template_response(_req: HttpRequest, content: String) -> HttpResponse { + #[cfg(not(debug_assertions))] + let content = content; + #[cfg(debug_assertions)] let mut content = content; #[cfg(debug_assertions)] { - let uri = Uri::from_str(req.connection_info().host()); + let uri = Uri::from_str(_req.connection_info().host()); let hostname = match &uri { Ok(uri) => uri.host().unwrap_or("localhost"), Err(_) => "localhost", diff --git a/create-rust-app/src/util/template_utils.rs b/create-rust-app/src/util/template_utils.rs index 99d87702..ee68a87c 100644 --- a/create-rust-app/src/util/template_utils.rs +++ b/create-rust-app/src/util/template_utils.rs @@ -54,7 +54,9 @@ impl tera::Function for InjectBundle { { let manifest_entry = VITE_MANIFEST .get(&format!("bundles/{bundle_name}")) - .expect(&format!("could not get bundle `{bundle_name}`")); + .unwrap_or_else(|| { + panic!("{}", "could not get bundle `{bundle_name}`") + }); let entry_file = format!( r#""#, file = manifest_entry.file @@ -63,7 +65,7 @@ impl tera::Function for InjectBundle { .css .as_ref() .unwrap_or(&vec![]) - .into_iter() + .iter() .map(|css_file| { format!( r#""#, @@ -76,7 +78,7 @@ impl tera::Function for InjectBundle { .dynamicImports .as_ref() .unwrap_or(&vec![]) - .into_iter() + .iter() .map(|dyn_script_file| { // TODO: make this deferred or async -- look this up!~ format!( diff --git a/create-rust-app_cli/Cargo.toml b/create-rust-app_cli/Cargo.toml index d419c4ac..5f4754a4 100644 --- a/create-rust-app_cli/Cargo.toml +++ b/create-rust-app_cli/Cargo.toml @@ -18,7 +18,7 @@ console = "0.15.5" dialoguer = "0.10.3" indoc = "1.0.8" walkdir = "2.3.2" -rust-embed = "6.4.2" +rust-embed = { version = "6.6.1", features = ["debug-embed"] } clap = {version = "4.1", features = ["wrap_help", "derive", "cargo"]} toml = "0.5.11" tsync = "1" diff --git a/create-rust-app_cli/qsync/src/hook.rs b/create-rust-app_cli/qsync/src/hook.rs index 7a38ebf9..1d2d0504 100644 --- a/create-rust-app_cli/qsync/src/hook.rs +++ b/create-rust-app_cli/qsync/src/hook.rs @@ -226,7 +226,6 @@ impl Hook { .endpoint_url .trim_start_matches("/api/") .split('/') - .into_iter() .map(|t| { // in actix-web, paths which have {} denote a path param if t.starts_with('{') && t.ends_with('}') { diff --git a/create-rust-app_cli/qsync/src/processor.rs b/create-rust-app_cli/qsync/src/processor.rs index 229bbc6b..a66ce6fa 100644 --- a/create-rust-app_cli/qsync/src/processor.rs +++ b/create-rust-app_cli/qsync/src/processor.rs @@ -109,7 +109,7 @@ fn has_qsync_attribute( if has_actix_attribute && has_qsync_attribute { Some(QsyncAttributeProps { is_mutation: is_mutation.unwrap_or_default(), - return_type: return_type, + return_type, }) } else { None diff --git a/create-rust-app_cli/src/content/model.rs b/create-rust-app_cli/src/content/model.rs index 38dc78a7..3f69a3c9 100644 --- a/create-rust-app_cli/src/content/model.rs +++ b/create-rust-app_cli/src/content/model.rs @@ -2,17 +2,20 @@ use crate::inflector::Inflector; use anyhow::Result; use indoc::indoc; +#[allow(dead_code)] pub struct Model { pub config: ModelConfig, pub file_contents: String, } +#[allow(dead_code)] pub struct ModelConfig { pub model_name: String, pub table_name: String, pub file_name: String, } +#[allow(dead_code)] pub fn create(resource_name: &str) -> Result { let resource = generate(resource_name); @@ -25,6 +28,7 @@ pub fn create(resource_name: &str) -> Result { Ok(resource) } +#[allow(dead_code)] fn config(resource_name: &str) -> ModelConfig { let model_name = resource_name.to_pascal_case(); let file_name = model_name.to_snake_case(); @@ -37,6 +41,7 @@ fn config(resource_name: &str) -> ModelConfig { } } +#[allow(dead_code)] fn generate(resource_name: &str) -> Model { let config = config(resource_name); diff --git a/create-rust-app_cli/src/content/project.rs b/create-rust-app_cli/src/content/project.rs index cc411599..23975d43 100644 --- a/create-rust-app_cli/src/content/project.rs +++ b/create-rust-app_cli/src/content/project.rs @@ -44,7 +44,10 @@ fn get_current_cra_lib_version() -> String { "9".to_string() } -fn add_bins_to_cargo_toml(project_dir: &std::path::PathBuf, creations_options: &CreationOptions) -> Result<(), std::io::Error> { +fn add_bins_to_cargo_toml( + project_dir: &std::path::PathBuf, + creations_options: &CreationOptions, +) -> Result<(), std::io::Error> { let mut path = std::path::PathBuf::from(project_dir); path.push("Cargo.toml"); @@ -77,7 +80,10 @@ fn add_bins_to_cargo_toml(project_dir: &std::path::PathBuf, creations_options: & let updated_toml = toml::to_string(&parsed_toml).unwrap(); - let queue_bin = if creations_options.cra_enabled_features.contains(&"plugin_tasks".to_string()) { + let queue_bin = if creations_options + .cra_enabled_features + .contains(&"plugin_tasks".to_string()) + { r##" [[bin]] name = "queue" @@ -115,7 +121,8 @@ path = "backend/main.rs" {queue_bin} [profile.dev] debug-assertions=true -"#); +"# + ); let mut final_toml = String::default(); diff --git a/create-rust-app_cli/src/main.rs b/create-rust-app_cli/src/main.rs index 88410363..9b2b944b 100644 --- a/create-rust-app_cli/src/main.rs +++ b/create-rust-app_cli/src/main.rs @@ -379,7 +379,7 @@ fn create_project( // let install_config = plugins::InstallConfig { - project_name: project_name.clone(), + project_name, project_dir: PathBuf::from("."), backend_framework, backend_database, diff --git a/create-rust-app_cli/src/plugins/tasks.rs b/create-rust-app_cli/src/plugins/tasks.rs index f7cc6d3d..262e9880 100644 --- a/create-rust-app_cli/src/plugins/tasks.rs +++ b/create-rust-app_cli/src/plugins/tasks.rs @@ -2,12 +2,12 @@ use anyhow::Result; use indoc::indoc; use rust_embed::RustEmbed; -use crate::{BackendDatabase, BackendFramework}; use crate::content::cargo_toml::add_dependency; use crate::plugins::InstallConfig; use crate::plugins::Plugin; use crate::utils::fs; use crate::utils::logger::add_file_msg; +use crate::{BackendDatabase, BackendFramework}; pub struct Tasks {} @@ -26,15 +26,11 @@ impl Plugin for Tasks { // =============================== if install_config.backend_database != BackendDatabase::Postgres { - return Err(anyhow::anyhow!( - "The tasks plugin only supports Postgres" - )); + return Err(anyhow::anyhow!("The tasks plugin only supports Postgres")); } if install_config.backend_framework != BackendFramework::ActixWeb { - return Err(anyhow::anyhow!( - "The tasks plugin only supports actix-web" - )); + return Err(anyhow::anyhow!("The tasks plugin only supports actix-web")); } // =============================== @@ -106,12 +102,7 @@ impl Plugin for Tasks { // Add dependencies // =============================== - add_dependency( - &install_config.project_dir, - "fang", - r#"fang = "0.10.3""#, - )?; - + add_dependency(&install_config.project_dir, "fang", r#"fang = "0.10.3""#)?; Ok(()) } diff --git a/create-rust-app_cli/template/frontend/package-lock.json b/create-rust-app_cli/template/frontend/package-lock.json index 32d424e7..939ab92d 100644 --- a/create-rust-app_cli/template/frontend/package-lock.json +++ b/create-rust-app_cli/template/frontend/package-lock.json @@ -460,19 +460,20 @@ } }, "@playwright/test": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz", - "integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==", + "version": "1.32.3", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.32.3.tgz", + "integrity": "sha512-BvWNvK0RfBriindxhLVabi8BRe3X0J9EVjKlcmhxjg4giWBD/xleLcg2dz7Tx0agu28rczjNIPQWznwzDwVsZQ==", "dev": true, "requires": { "@types/node": "*", - "playwright-core": "1.30.0" + "fsevents": "2.3.2", + "playwright-core": "1.32.3" }, "dependencies": { "playwright-core": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz", - "integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==", + "version": "1.32.3", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.3.tgz", + "integrity": "sha512-SB+cdrnu74ZIn5Ogh/8278ngEh9NEEV0vR4sJFmK04h2iZpybfbqBY0bX6+BLYWVdV12JLLI+JEFtSnYgR+mWg==", "dev": true } } diff --git a/create-rust-app_cli/template/frontend/package.json b/create-rust-app_cli/template/frontend/package.json index cbdb871a..e2c9d788 100644 --- a/create-rust-app_cli/template/frontend/package.json +++ b/create-rust-app_cli/template/frontend/package.json @@ -36,7 +36,7 @@ ] }, "devDependencies": { - "@playwright/test": "^1.30.0", + "@playwright/test": "^1.32.3", "@types/node": "^18.13.0", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10",