Skip to content

Commit ba608dc

Browse files
committed
Use relative path from cwd for hashes
1 parent 1c94160 commit ba608dc

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ lazy_static = "1.4.0"
3434
clap = { version = "3.0.6", features = ["derive"] }
3535
retain_mut = "0.1.5"
3636
serde_json = "*"
37+
pathdiff = "0.2.1"
3738

3839
[dev-dependencies]
3940
indoc = "1.0.3"

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub fn main() -> Result<(), std::io::Error> {
4242
let cli_args = CliArgs::parse();
4343
let source = fs::read_to_string(&cli_args.input_file)?;
4444

45-
let filename = path::Path::new(&cli_args.input_file)
46-
.file_name()
45+
let absolute_path = fs::canonicalize(cli_args.input_file)?;
46+
let filename = pathdiff::diff_paths(absolute_path, std::env::current_dir()?)
4747
.unwrap()
4848
.to_str()
4949
.unwrap()

tests/cli_integration_tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ fn css_modules_stdout() -> Result<(), Box<dyn std::error::Error>> {
242242
let infile = assert_fs::NamedTempFile::new("test.css")?;
243243
infile.write_str(&input)?;
244244
let mut cmd = Command::cargo_bin("parcel_css")?;
245+
cmd.current_dir(infile.path().parent().unwrap());
245246
cmd.arg(infile.path());
246247
cmd.arg("--css-modules");
247248
cmd.assert().success().stdout(predicate::str::contains(output));
@@ -263,6 +264,7 @@ fn css_modules_infer_output_file() -> Result<(), Box<dyn std::error::Error>> {
263264
let outfile = assert_fs::NamedTempFile::new("out.css")?;
264265
infile.write_str(&input)?;
265266
let mut cmd = Command::cargo_bin("parcel_css")?;
267+
cmd.current_dir(infile.path().parent().unwrap());
266268
cmd.arg(infile.path());
267269
cmd.arg("--css-modules");
268270
cmd.arg("-o").arg(outfile.path());
@@ -284,6 +286,7 @@ fn css_modules_output_target_option() -> Result<(), Box<dyn std::error::Error>>
284286
let modules_file = assert_fs::NamedTempFile::new("module.json")?;
285287
infile.write_str(&input)?;
286288
let mut cmd = Command::cargo_bin("parcel_css")?;
289+
cmd.current_dir(infile.path().parent().unwrap());
287290
cmd.arg(infile.path());
288291
cmd.arg("-o").arg(outfile.path());
289292
cmd.arg("--css-modules");
@@ -305,6 +308,7 @@ fn sourcemap() -> Result<(), Box<dyn std::error::Error>> {
305308
let outfile = outdir.child("out.css");
306309
infile.write_str(&input)?;
307310
let mut cmd = Command::cargo_bin("parcel_css")?;
311+
cmd.current_dir(infile.path().parent().unwrap());
308312
cmd.arg(infile.path());
309313
cmd.arg("-o").arg(outfile.path());
310314
cmd.arg("--sourcemap");

0 commit comments

Comments
 (0)