Repository: swc-project/swc (rust)

Issue:
@swc/core's binary does not handle folders with `.js` suffix well
### Describe the bug

I found that SWC mistakenly treats a folder with the `.js` suffix as a file, which introduces this bug:

```
$ ./swc-darwin-arm64-1.7.26 compile .
Error: Failed to open file ./vendor/chart.js

Caused by:
    Is a directory (os error 21)
```

Note that the binary is downloaded from the GitHub Releases:

```
wget https://github.com/swc-project/swc/releases/download/v1.7.26/swc-darwin-arm64 -O swc-darwin-arm64-1.7.26 && chmod +x swc-darwin-arm64-1.7.26
```


### Input code

_No response_

### Config

_No response_

### Playground link (or link to the minimal reproduction)

https://github.com/pan93412/swc-minimum-repro

### SWC Info output

```
    Operating System:
        Platform: darwin
        Arch: arm64
        Machine Type: arm64
        Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:41 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6031
        CPU: (16 cores)
            Models: Apple M3 Max

    Binaries:
        Node: 20.17.0
        npm: 10.8.2
        Yarn: N/A
        pnpm: N/A

    Relevant Packages:
        @swc/core: N/A
        @swc/helpers: N/A
        @swc/types: N/A


    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A
```

### Expected behavior

It should be able to build. For example, when I rename `chart.js` to `charts`:

```
$ mv vendor/chart.js/ vendor/chartjs

$ ./swc-darwin-arm64-1.7.26 compile .
./vendor/chartjs/chart.js.min.js
console.log("hi chart.js");

./index.ts
console.log("Hello");
```

### Actual behavior

```
$ mv vendor/chartjs vendor/chart.js

$ ./swc-darwin-arm64-1.7.26 compile .
Error: Failed to open file ./vendor/chart.js

Caused by:
    Is a directory (os error 21)
```

### Version

1.7.26

### Additional context

_No response_

Pull request:
fix(cli): Exclude non-files from get_files_list
**Description:**

`get_files_list` does not check if a path with the `extensions` is really a file.


**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/9559


Patch:
diff --git a/.changeset/weak-papayas-deliver.md b/.changeset/weak-papayas-deliver.md
new file mode 100644
index 0000000000..f51e827d85
--- /dev/null
+++ b/.changeset/weak-papayas-deliver.md
@@ -0,0 +1,6 @@
+---
+swc_core: patch
+swc_cli_impl: patch
+---
+
+fix(cli): Exclude non-files from get_files_list
diff --git a/crates/swc_cli_impl/src/commands/compile.rs b/crates/swc_cli_impl/src/commands/compile.rs
index 5abbc50b6e..cef751ebff 100644
--- a/crates/swc_cli_impl/src/commands/compile.rs
+++ b/crates/swc_cli_impl/src/commands/compile.rs
@@ -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()


Test patch:
diff --git a/crates/swc_cli_impl/tests/issues.rs b/crates/swc_cli_impl/tests/issues.rs
index 5d29cd0124..daccc40420 100644
--- a/crates/swc_cli_impl/tests/issues.rs
+++ b/crates/swc_cli_impl/tests/issues.rs
@@ -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)]