From 77d11f6d9aac8fa75ae5a3ca8224a1c4f7666057 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 16 Aug 2023 17:24:30 -0500 Subject: [PATCH] Fix the asset config in the CLI --- packages/cli/src/builder.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index ddfa95dfe..a5cb29dc5 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -40,6 +40,8 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result { .. } = config; + let _gaurd = AssetConfigDropGaurd::new(); + // start to build the assets let ignore_files = build_assets(config)?; @@ -431,6 +433,8 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { } pub fn gen_page(config: &CrateConfig, serve: bool) -> String { + let _gaurd = AssetConfigDropGaurd::new(); + let crate_root = crate::cargo::crate_root().unwrap(); let custom_html_file = crate_root.join("index.html"); let mut html = if custom_html_file.is_file() { @@ -693,11 +697,6 @@ fn build_assets(config: &CrateConfig) -> Result> { } // SASS END - // Set up the collect asset config - assets_cli_support::Config::default() - .with_assets_serve_location("/") - .save(); - Ok(result) } @@ -718,9 +717,6 @@ fn process_assets(config: &CrateConfig) -> anyhow::Result<()> { manifest.copy_static_assets_to(&static_asset_output_dir)?; - // Reset the config - assets_cli_support::Config::default().save(); - Ok(()) } @@ -755,3 +751,22 @@ fn process_assets(config: &CrateConfig) -> anyhow::Result<()> { // install_permitted, // )?) // } + +struct AssetConfigDropGaurd; + +impl AssetConfigDropGaurd { + pub fn new() -> Self { + // Set up the collect asset config + assets_cli_support::Config::default() + .with_assets_serve_location("/") + .save(); + Self {} + } +} + +impl Drop for AssetConfigDropGaurd { + fn drop(&mut self) { + // Reset the config + assets_cli_support::Config::default().save(); + } +}