swc icon indicating copy to clipboard operation
swc copied to clipboard

@swc/cli --ignore option is not working

Open Phryxia opened this issue 3 years ago • 15 comments
trafficstars

Describe the bug

--ignore option with -d option does not exclude given file from compile.

To reproduce:

  1. Create a directory test
  2. Make two arbitrary js files (a.js, b.js) inside test, and make a syntax error with a.js
  3. run npx swc test -d out --ignore a.js
  4. See error messages caused by a.js

Input code

No response

Config

Default (no .swcrc)

Playground link

No response

Expected behavior

Given files should not be compiled.

Actual behavior

Given files were tried to compile.

Version

@swc/cli: 0.1.55, @swc/core: 1.2.139

Additional context

No response

Phryxia avatar Feb 14 '22 07:02 Phryxia

Oops sorry I think I've made some mistakes

Phryxia avatar Feb 14 '22 07:02 Phryxia

Well, I tested again and it happens. Sorry for the inconvenience.

Phryxia avatar Feb 14 '22 07:02 Phryxia

Same here...
Wouldn't it make sense to provide an option to specify a tsconfig file and get this info also from its exclude array?
I've a tsconfig.build.json which excludes test files.

kolbma avatar Feb 15 '22 11:02 kolbma

Will this be fixed soon? Happening on my end as well.

totaland avatar Mar 30 '22 05:03 totaland

if you use exclude in the config it works, FYI. Ran into this same issue and that worked for me.

reintroducing avatar Mar 31 '22 15:03 reintroducing

are there any updates on that manner?

the cli ignore option does not work for me, as does not the .swcrc exclude key.

my config (.swcrc) is:

{
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "decorators": true,
            "dynamicImport": true
        },
        "transform": {
            "legacyDecorator": true,
            "decoratorMetadata": true
        },
        "target": "es2018",
        "keepClassNames": true,
        "loose": true,
        "baseUrl": "src",
        "paths": {
            "~/*": [
                "*"
            ]
        }
    },
    "exclude":["**/*.test.ts"],
    "module": {
        "type": "commonjs",
        "strict": true,
        "strictMode": true,
        "lazy": false,
        "noInterop": true
    },
    "sourceMaps": "inline"
}

the cli than prints the following error message for basically every file in my src dir

Caused by:
    0: failed to read swcrc file (src/lib-external/index.ts)
    1: failed to deserialize .swcrc (json) file: unmatched data: 22:31
    2: data did not match any variant of untagged enum FileMatcher at line 22 column 31
failed to process input file

without the exclude property swc compiles just fine.

are there any workarounds?

alexn-s avatar Apr 17 '22 23:04 alexn-s

I have a same problem 😭

npx swc src --ignore **/*.stories.tsx --out-dir dist does not ignore *.stories.tsx files...

psch300 avatar Apr 22 '22 07:04 psch300

@alexn-s I tried something similar and found that exclude will not take globs, only directories as far as I could tell. Luckily my stories and tests are in stories and tests folders so I was able to do "exclude": ["tests/", "stories/"], but when using globs like you show in your code, it was failing.

reintroducing avatar Apr 22 '22 14:04 reintroducing

@alexn-s Sorry, I just realized i did accomplish it in another repo, by doing the following: "exclude": [".spec.js"],

reintroducing avatar Apr 22 '22 14:04 reintroducing

@reintroducing thanks for the idea. i will try that. also not directly correlated to this issue, but i often found the swc error messages pretty irrelevant & not very helpful.

alexn-s avatar Apr 22 '22 14:04 alexn-s

@reintroducing

"exclude": [".spec.js"], this works 🟩

it is really counter intuitive for swc to handle it like that and not using globs/ crashing.

alexn-s avatar Apr 26 '22 15:04 alexn-s

@alexn-s yeah, not ideal, but at least there is a work around I suppose :)

reintroducing avatar Apr 26 '22 15:04 reintroducing

By using exclude in swcrc, you lose the ability to run tests with @swc/jest.

I think this discussion should be moved to @swc/cli. There is already an open issue about this problem --only and --ignore clarity.

CertainlyAria avatar Apr 26 '22 18:04 CertainlyAria

Sorry for extremely late update for this. I'm so surprised that this haven't fixed yet... But I decide to contribute somehow (and I've surprised again that cli used TypeScript) and I'll start to read docs and codes.

Thank you for your kind explanation. I didn't noticed that cli has its own repository at that time. Should I close this, or just leave it to point out that it is somehow connected to swc, or just copy these to the cli repo? As I'm not familiar with open source contribution, your explanation may save one's life :)

@CertainlyAria

Phryxia avatar Aug 08 '22 18:08 Phryxia

You can close the issue with a comment saying "closed in favor of ...." or "duplicate of ....". Replace dots with a link to the swc-project/cli. Also change the labels of this issue to stale & duplicate :)

@Phryxia

CertainlyAria avatar Aug 09 '22 09:08 CertainlyAria

Duplicated of https://github.com/swc-project/cli/issues/20

Also change the labels of this issue to stale & duplicate :)

Thanks, but I don't have authority to do that 😢

Phryxia avatar Aug 11 '22 17:08 Phryxia

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

swc-bot avatar Oct 16 '22 00:10 swc-bot