diff --git a/Cargo.lock b/Cargo.lock index 12fc8de1..b2cfe865 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,6 +180,12 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "build-print" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e6738dfb11354886f890621b4a34c0b177f75538023f7100b608ab9adbd66b" + [[package]] name = "bumpalo" version = "3.19.0" @@ -2418,6 +2424,7 @@ dependencies = [ name = "trusted-server-js" version = "0.1.0" dependencies = [ + "build-print", "hex", "sha2 0.10.9", "which", diff --git a/Cargo.toml b/Cargo.toml index 5133b733..9f0385e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ debug = 1 async-trait = "0.1" base64 = "0.22" brotli = "8.0" +build-print = "1.0.1" bytes = "1.11" chacha20poly1305 = "0.10" chrono = "0.4.42" diff --git a/crates/js/Cargo.toml b/crates/js/Cargo.toml index 1917e9b8..905f9304 100644 --- a/crates/js/Cargo.toml +++ b/crates/js/Cargo.toml @@ -18,6 +18,7 @@ repository = "https://example.invalid/trusted-server" readme = "README.md" [build-dependencies] +build-print = { workspace = true } which = { workspace = true } [dependencies] diff --git a/crates/js/build.rs b/crates/js/build.rs index 15417160..92023200 100644 --- a/crates/js/build.rs +++ b/crates/js/build.rs @@ -5,6 +5,8 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; +use build_print::{info, warn}; + const UNIFIED_BUNDLE: &str = "tsjs-unified.js"; fn main() { @@ -34,14 +36,14 @@ fn main() { // If Node/npm is absent, keep going if dist exists let npm = which::which("npm").ok(); if npm.is_none() { - println!("cargo:warning=tsjs: npm not found; will use existing dist if available"); + warn!("tsjs: npm not found; will use existing dist if available"); } // Install deps if node_modules missing if !skip { - if let Some(npm_path) = npm.clone() { + if let Some(npm_path) = npm.as_deref() { if !ts_dir.join("node_modules").exists() { - let status = Command::new(npm_path.clone()) + let status = Command::new(npm_path) .arg("install") .current_dir(&ts_dir) .status(); @@ -50,9 +52,7 @@ fn main() { .map(std::process::ExitStatus::success) .unwrap_or(false) { - println!( - "cargo:warning=tsjs: npm install failed; using existing dist if available" - ); + warn!("tsjs: npm install failed; using existing dist if available"); } } } @@ -60,7 +60,7 @@ fn main() { // Run tests if requested if !skip && npm.is_some() && env::var("TSJS_TEST").map(|v| v == "1").unwrap_or(false) { - let _ = Command::new(npm.clone().unwrap()) + let _ = Command::new(npm.as_deref().unwrap()) .args(["run", "test", "--", "--run"]) // ensure non-watch .current_dir(&ts_dir) .status(); @@ -68,13 +68,13 @@ fn main() { // Build unified bundle if !skip { - if let Some(npm_path) = npm.clone() { - println!("cargo:warning=tsjs: Building unified bundle"); + if let Some(npm_path) = npm.as_deref() { + info!("tsjs: Building unified bundle"); let js_modules = env::var("TSJS_MODULES").unwrap_or("".to_string()); - let status = Command::new(&npm_path) + let status = Command::new(npm_path) .env("TSJS_MODULES", js_modules) - .args(["run", "build:custom"]) + .args(["run", "build"]) .current_dir(&ts_dir) .status(); if !status @@ -82,12 +82,12 @@ fn main() { .map(std::process::ExitStatus::success) .unwrap_or(false) { - panic!("tsjs: npm run build:custom failed - refusing to use stale bundle"); + panic!("tsjs: npm run build failed - refusing to use stale bundle"); } } } - // Copy unified bundle into OUT_DIR for include_str! + // Copy bundle into OUT_DIR for include_str! copy_bundle(UNIFIED_BUNDLE, true, &crate_dir, &dist_dir, &out_dir); } diff --git a/crates/js/lib/package.json b/crates/js/lib/package.json index 93164d3f..8b508f6a 100644 --- a/crates/js/lib/package.json +++ b/crates/js/lib/package.json @@ -6,7 +6,6 @@ "description": "Trusted Server tsjs TypeScript library with queue and simple banner rendering.", "scripts": { "build": "vite build", - "build:custom": "vite build", "dev": "vite build --watch", "test": "vitest run", "test:watch": "vitest", diff --git a/crates/js/lib/vite.config.ts b/crates/js/lib/vite.config.ts index 8b9ed866..a6cc7005 100644 --- a/crates/js/lib/vite.config.ts +++ b/crates/js/lib/vite.config.ts @@ -84,8 +84,6 @@ export type ModuleName = ${finalModules.map((m) => `'${m}'`).join(' | ')}; export default defineConfig(() => { const distDir = path.resolve(__dirname, '../dist'); - const buildTimestamp = new Date().toISOString(); - const banner = `// build: ${buildTimestamp}\n`; return { build: { @@ -93,11 +91,11 @@ export default defineConfig(() => { outDir: distDir, assetsDir: '.', sourcemap: false, - minify: 'esbuild', + minify: 'esbuild' as const, rollupOptions: { input: path.resolve(__dirname, 'src/index.ts'), output: { - format: 'iife', + format: 'iife' as const, dir: distDir, entryFileNames: 'tsjs-unified.js', inlineDynamicImports: true,