Skip to content

Commit 82bca74

Browse files
authored
Support creating missing directories with --output-file option (parcel-bundler#432)
1 parent 05c23f1 commit 82bca74

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ pub fn main() -> Result<(), std::io::Error> {
217217
}
218218
}
219219

220+
let output_path = Path::new(output_file);
221+
if let Some(p) = output_path.parent() {
222+
fs::create_dir_all(p)?
223+
};
220224
fs::write(output_file, code.as_bytes())?;
221225

222226
if let Some(css_modules) = cli_args.css_modules {

tests/cli_integration_tests.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use indoc::indoc;
55
use lightningcss::css_modules::CssModuleExport;
66
use predicates::prelude::*;
77
use std::collections::HashMap;
8+
use std::fs;
89
use std::process::Command;
910

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

186+
#[test]
187+
fn output_file_option_create_missing_directories() -> Result<(), Box<dyn std::error::Error>> {
188+
let infile = test_file()?;
189+
let outdir = assert_fs::TempDir::new()?;
190+
let outfile = outdir.child("out.css");
191+
outdir.close()?;
192+
let mut cmd = Command::cargo_bin("lightningcss")?;
193+
cmd.arg(infile.path());
194+
cmd.arg("--output-file").arg(outfile.path());
195+
cmd.assert().success();
196+
outfile.assert(predicate::str::contains(indoc! {
197+
r#"
198+
.foo {
199+
border: none;
200+
}
201+
"#
202+
}));
203+
fs::remove_dir_all(outfile.parent().unwrap())?;
204+
205+
Ok(())
206+
}
207+
185208
#[test]
186209
fn minify_option() -> Result<(), Box<dyn std::error::Error>> {
187210
let infile = test_file()?;

0 commit comments

Comments
 (0)