Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ pub fn main() -> Result<(), std::io::Error> {
}
}

let output_path = Path::new(output_file);
if let Some(p) = output_path.parent() {
fs::create_dir_all(p)?
};
fs::write(output_file, code.as_bytes())?;

if let Some(css_modules) = cli_args.css_modules {
Expand Down
23 changes: 23 additions & 0 deletions tests/cli_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use indoc::indoc;
use lightningcss::css_modules::CssModuleExport;
use predicates::prelude::*;
use std::collections::HashMap;
use std::fs;
use std::process::Command;

fn test_file() -> Result<assert_fs::NamedTempFile, FixtureError> {
Expand Down Expand Up @@ -182,6 +183,28 @@ fn output_file_option() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[test]
fn output_file_option_create_missing_directories() -> Result<(), Box<dyn std::error::Error>> {
let infile = test_file()?;
let outdir = assert_fs::TempDir::new()?;
let outfile = outdir.child("out.css");
outdir.close()?;
let mut cmd = Command::cargo_bin("lightningcss")?;
cmd.arg(infile.path());
cmd.arg("--output-file").arg(outfile.path());
cmd.assert().success();
outfile.assert(predicate::str::contains(indoc! {
r#"
.foo {
border: none;
}
"#
}));
fs::remove_dir_all(outfile.parent().unwrap())?;

Ok(())
}

#[test]
fn minify_option() -> Result<(), Box<dyn std::error::Error>> {
let infile = test_file()?;
Expand Down