cli
cli copied to clipboard
--only and --ignore clarity
It seems these two flags:
- --only
- --ignore
are not yet present in the cli handle
function.
Let's say I want to avoid to compile every js files under __tests__
folder.
That means the command would look more or less like this:
swc -d dist --ignore '**/__tests__/**'
But in the output folder, I would still have the __tests__
folder.
SWC version:
"@swc/cli": "0.1.36"
"@swc/core": "1.2.51"
I would be happy to open PR if you validate about this issue :)
I this is now supported by swcrc, "exclude": "(tests|mocks)", should we pass this options via cli as well ? @kdy1
Once problem with using exclude in swcrc is that it would break in jest tests. If I add above exclude then @swc/jest will error in jest with
cannot process file because it's ignored by .swcrc
see this build https://github.com/swc-project/cli/pull/32/checks?check_run_id=2713136059
This issue was fixed in 0.1.54(#90), but still exists in 0.1.55. In version 0.1.54, copying non-compilable files was not work(ignored files were not copied)
Hi guys, is there any update on the subject ? I am still struggling to ignore files through the --ignore
arg using the 0.1.57.
I'll also mention that the --ignore
option isn't working for us (on latest 0.1.57
).
A workaround is to have 2 .swcrc
, but this is not ideal :p
Our repo looks like:
📁 src
📁 __tests__
📁 components
And we're running swc ./src/ -d lib --ignore src/**/__tests__/*.tsx
. The tests get transpiled to lib
despite the --ignore
.
--ignore
, --only
are not supported at all.
Dir command compilation
https://github.dev/swc-project/cli/blob/ec9a985ba8ce0fa89c395a12c129a34d235e35e2/src/swc/dir.ts#L291
File command compilation
https://github.dev/swc-project/cli/blob/ec9a985ba8ce0fa89c395a12c129a34d235e35e2/src/swc/file.ts#L10
And cli options that are consumed by the code (program):
https://github.dev/swc-project/cli/blob/ec9a985ba8ce0fa89c395a12c129a34d235e35e2/src/swc/options.ts#L248
const cliOptions: CliOptions = {
outDir: opts.outDir,
outFile: opts.outFile,
filename: opts.filename,
filenames,
sync: !!opts.sync,
sourceMapTarget: opts.sourceMapTarget,
extensions: opts.extensions || DEFAULT_EXTENSIONS,
watch: !!opts.watch,
copyFiles: !!opts.copyFiles,
includeDotfiles: !!opts.includeDotfiles,
deleteDirOnStart: Boolean(opts.deleteDirOnStart),
quiet: !!opts.quiet,
};
I guess the API is not stable yet. And things may change in the future.
I guess also for testing. One as like with many tools and tsconfig. One can make different config files for different purposes. And hence separating the testing one from the main one.
Any update? Now I can only have 2 swcrc
for build and test. I have just turned my oss into swc based but now frustrated for this.
The following solution should work. Summary: Override swc config for files that require @swc/jest
.
const swcConfig = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, "utf-8"));
// ---
transform: {
".+\\.ts$": [
"@swc/jest",
{
...swcConfig,
exclude: [],
swcrc: false,
},
],
},
// ---
https://github.com/swc-project/jest/issues/62
The above solution is not a "solution". SWC's configuration leaves a LOT to be desired, which is unfortunate since it is otherwise such an exceptional tool.
The ability to specify which files should be included & excluded is a basic requirement of configuration. It shouldn't be this hard to do. There shouldn't be this many broken configuration options in the CLI or SWCRC.
I sincerely hope this gets resolved.
Same error for vitest.
Error: cannot process file because it's ignored by .swcrc
Same problem. Neither "exclude" nor "ignore" options are working properly yet.
@josteph Are you still willing to open a PR? If not, I'll work on it