Coder Social home page Coder Social logo

Comments (3)

heygrady avatar heygrady commented on May 29, 2024 1

This is a regression. Previously this was using lodash/set. The current code is broken.

See here: https://github.com/swc-project/cli/blame/95c8a228ff7679c286858b6f34b4e3d703d643fc/src/swc/options.ts#L215

I was using this to set the module type to commonjs.

swc --config module.type=commonjs src -d cjs --source-maps --copy-files

That generates a final config like this:

{
  jsc: { parser: undefined, transform: {} },
  sourceMaps: true,
  sourceFileName: undefined,
  sourceRoot: undefined,
  configFile: undefined,
  'module.type': 'commonjs' // <-- this is clearly wrong
}

I hacked this in place of this offending line:

swcOptions[key] = value;

// essentially the same as lodash/set
let options = swcOptions
const keyParts = key.split('.')
const lastIndex = keyParts.length - 1
for (const [index, keyPart] of keyParts.entries()) {
    if (options[keyPart] === undefined && index !== lastIndex) {
        options[keyPart] = {}
    }
    if (index === lastIndex) {
        options[keyPart] = value
    } else {
        options = options[keyPart]
    }
}

Here's a helpful resource for removing lodash when you don't need it: https://youmightnotneed.com/lodash/#set

from cli.

heygrady avatar heygrady commented on May 29, 2024 1

Looks like it was broken with this PR: #32

reverting to 0.1.45 would probably work until this regression is patched.

you can see the history here: https://github.com/swc-project/cli/commits/master

from cli.

HelloWorld017 avatar HelloWorld017 commented on May 29, 2024

Closing as the #48 has been merged. Thanks!

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.