cli icon indicating copy to clipboard operation
cli copied to clipboard

--config doesn't handle anything with commas

Open walkerburgin opened this issue 2 years ago • 0 comments

I'm attempting to configure swc to use a custom plugin via the command line as part of a larger build process. Essentially I'm trying to replicate this .swcrc:

{
    "jsc": {
        "experimental": {
            "plugins": [
                ["./my_plugin.wasm", {}]
            ]
        }
    }
}

Calling swc --out-dir=dist --config=jsc.experimental.plugins=[[\"my_plugin.wasm\", {}]] src/ fails with an error like this:

invalid type: string "[[\"my_plugin.wasm\"", expected a sequence at line 1 column 187
Failed to compile 1 file with swc.
Error: Failed to compile:
test/index.ts
    at initialCompilation (/Users/wburgin/.nvm/versions/node/v12.20.2/pnpm-global/4/node_modules/.pnpm/@swc/[email protected]_@[email protected]/node_modules/@swc/cli/lib/swc/dir.js:172:19)
    at async dir (/Users/wburgin/.nvm/versions/node/v12.20.2/pnpm-global/4/node_modules/.pnpm/@swc/[email protected]_@[email protected]/node_modules/@swc/cli/lib/swc/dir.js:16:5)

I poked around a little bit, and here's what swcOptions ends up set to:

{
  jsc: {
    parser: undefined,
    transform: {},
    experimental: { plugins: '[["my_plugin.wasm"' }
  },
  sourceFileName: undefined,
  sourceRoot: undefined,
  configFile: undefined,
  swcrc: true,
  '': true
}

I think the collect() function (here) splitting the input on commas is causing the truncation.

walkerburgin avatar Jul 04 '22 18:07 walkerburgin