cli icon indicating copy to clipboard operation
cli copied to clipboard

--only and --ignore clarity

Open josteph opened this issue 3 years ago • 6 comments

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 :)

josteph avatar Apr 05 '21 17:04 josteph

I this is now supported by swcrc, "exclude": "(tests|mocks)", should we pass this options via cli as well ? @kdy1

chyzwar avatar May 31 '21 19:05 chyzwar

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

chyzwar avatar May 31 '21 19:05 chyzwar

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)

coffee377 avatar Feb 27 '22 08:02 coffee377

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.

r-guerin avatar May 12 '22 12:05 r-guerin

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.

Naoto-Ida avatar May 25 '22 06:05 Naoto-Ida

--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.

MohamedLamineAllal avatar Sep 19 '22 16:09 MohamedLamineAllal

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.

tangye1234 avatar Feb 26 '23 02:02 tangye1234

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

Document

caseykhuc avatar Mar 23 '23 07:03 caseykhuc

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.

craigmiller160 avatar Sep 18 '23 14:09 craigmiller160

Same error for vitest.

Error: cannot process file because it's ignored by .swcrc

Mnigos avatar Oct 26 '23 08:10 Mnigos

Same problem. Neither "exclude" nor "ignore" options are working properly yet.

cilvet avatar Jan 16 '24 11:01 cilvet

@josteph Are you still willing to open a PR? If not, I'll work on it

kdy1 avatar Jan 16 '24 11:01 kdy1