Content-Length: 4585 | pFad | http://github.com/postgresml/postgresml/pull/1118.diff

thub.com diff --git a/packages/cargo-pgml-components/Cargo.lock b/packages/cargo-pgml-components/Cargo.lock index 89f1b1467..92f4118dc 100644 --- a/packages/cargo-pgml-components/Cargo.lock +++ b/packages/cargo-pgml-components/Cargo.lock @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cargo-pgml-components" -version = "0.1.19" +version = "0.1.20" dependencies = [ "anyhow", "assert_cmd", @@ -143,6 +143,7 @@ dependencies = [ "regex", "sailfish", "serde", + "serde_json", "toml", ] @@ -428,6 +429,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + [[package]] name = "itoap" version = "1.0.1" @@ -670,6 +677,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_spanned" version = "0.6.3" diff --git a/packages/cargo-pgml-components/Cargo.toml b/packages/cargo-pgml-components/Cargo.toml index 9638e05a2..55fff6533 100644 --- a/packages/cargo-pgml-components/Cargo.toml +++ b/packages/cargo-pgml-components/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-pgml-components" -version = "0.1.19" +version = "0.1.20" edition = "2021" authors = ["PostgresML "] license = "MIT" @@ -22,6 +22,7 @@ regex = "1" toml = "0.7" serde = { version = "1", features = ["derive"] } file-lock = "2" +serde_json = "1" [dev-dependencies] assert_cmd = "2" diff --git a/packages/cargo-pgml-components/src/frontend/javascript.rs b/packages/cargo-pgml-components/src/frontend/javascript.rs index 8784d2a98..5b00a9e11 100644 --- a/packages/cargo-pgml-components/src/frontend/javascript.rs +++ b/packages/cargo-pgml-components/src/frontend/javascript.rs @@ -1,13 +1,14 @@ //! Javascript bundling. use glob::glob; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::fs::{copy, read_to_string, remove_file, File}; use std::io::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::{exit, Command}; use convert_case::{Case, Casing}; +use serde::{Deserialize, Serialize}; use crate::config::Config; use crate::frontend::tools::execute_with_nvm; @@ -32,6 +33,11 @@ static OLD_BUNLDES_GLOB: &'static str = "static/js/*.*.js"; //github.com/ JS compiler static JS_COMPILER: &'static str = "rollup"; +#[derive(Serialize, Deserialize, Debug)] +struct Packages { + dependencies: HashMap, +} + //github.com/ Delete old bundles we may have created. fn cleanup_old_bundles() { // Clean up old bundles @@ -146,6 +152,16 @@ pub fn bundle(config: Config, minify: bool) { cleanup_old_bundles(); assemble_modules(config.clone()); + let package_json = Path::new("package.json"); + + let packages: Packages = if package_json.is_file() { + let packages = unwrap_or_exit!(read_to_string(package_json)); + unwrap_or_exit!(serde_json::from_str(&packages)) + } else { + warn("package.json not found, can't validate rollup output"); + serde_json::from_str(r#"{"dependencies": {}}"#).unwrap() + }; + let mut command = Command::new(JS_COMPILER); command @@ -163,7 +179,17 @@ pub fn bundle(config: Config, minify: bool) { // Bundle JavaScript. info("bundling javascript with rollup"); - unwrap_or_exit!(execute_with_nvm(&mut command)); + let output = unwrap_or_exit!(execute_with_nvm(&mut command)); + + let lines = output.split("\n"); + for line in lines { + for (package, _version) in &packages.dependencies { + if line.contains(package) { + error(&format!("unresolved import: {}", package)); + exit(1); + } + } + } info(&format!("written {}", JS_FILE)); diff --git a/packages/cargo-pgml-components/src/util.rs b/packages/cargo-pgml-components/src/util.rs index b2f8c4e82..fcf31ad49 100644 --- a/packages/cargo-pgml-components/src/util.rs +++ b/packages/cargo-pgml-components/src/util.rs @@ -69,7 +69,7 @@ pub fn execute_command(command: &mut Command) -> std::io::Result { info!("{}", stdout); } - Ok(stdout) + Ok(stdout.clone() + &stderr) } pub fn write_to_file(path: &Path, content: &str) -> std::io::Result<()> {








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgresml/postgresml/pull/1118.diff

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy