swc
swc copied to clipboard
@swc/cli --ignore option is not working
Describe the bug
--ignore option with -d option does not exclude given file from compile.
To reproduce:
- Create a directory
test - Make two arbitrary js files (
a.js,b.js) insidetest, and make a syntax error witha.js - run
npx swc test -d out --ignore a.js - 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
Oops sorry I think I've made some mistakes
Well, I tested again and it happens. Sorry for the inconvenience.
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.
Will this be fixed soon? Happening on my end as well.
if you use exclude in the config it works, FYI. Ran into this same issue and that worked for me.
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?
I have a same problem 😭
npx swc src --ignore **/*.stories.tsx --out-dir dist does not ignore *.stories.tsx files...
@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.
@alexn-s Sorry, I just realized i did accomplish it in another repo, by doing the following: "exclude": [".spec.js"],
@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.
@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 yeah, not ideal, but at least there is a work around I suppose :)
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.
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
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
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 😢
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.