Skip to content

Commit

Permalink
fix(cli): Exclude non-files from get_files_list (#9560)
Browse files Browse the repository at this point in the history
**Description:**

`get_files_list` does not check if a path with the `extensions` is really a file.


**Related issue:**

 - Closes #9559
  • Loading branch information
pan93412 committed Sep 17, 2024
1 parent 9dd8f6f commit 85cc2bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/weak-papayas-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_cli_impl: patch
---

fix(cli): Exclude non-files from get_files_list
1 change: 1 addition & 0 deletions crates/swc_cli_impl/src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fn get_files_list(
.into_iter()
.filter_map(|e| e.ok())
.map(|e| e.into_path())
.filter(|e| e.is_file())
.filter(|e| {
extensions
.iter()
Expand Down
14 changes: 14 additions & 0 deletions crates/swc_cli_impl/tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ fn issue_8667_1() -> Result<()> {
Ok(())
}

#[test]
fn issue_9559() -> Result<()> {
let sandbox = TempDir::new()?;
fs::write(sandbox.path().join("index.ts"), r"console.log('Hello')")?;
fs::create_dir(sandbox.path().join("chart.js"))?;

let mut cmd = cli()?;
cmd.current_dir(&sandbox).arg("compile").arg(sandbox.path());

cmd.assert().success();

Ok(())
}

/// ln -s $a $b
fn symlink(a: &Path, b: &Path) {
#[cfg(unix)]
Expand Down

0 comments on commit 85cc2bd

Please sign in to comment.