jorgebucaran / classcat

Build a class attribute string quickly
MIT License
906 stars 22 forks source link

Export CommonJS module #31

Closed wata727 closed 5 years ago

wata727 commented 5 years ago

Congratulations on the v4 release :tada:

Btw, our Jest tests are broken with the classcat v4 :cry:

/home/wata727/ghq/github.com/wata727/sideci/node_modules/classcat/src/index.js:3                         
    export default function cc(names) {                                                                      
    ^^^^^^                                                                                                   

    SyntaxError: Unexpected token export

      13 |   readonly className?: string
      14 |   readonly onClick?: (children: string) => void
    > 15 |   readonly children: string
         |                                    ^
      16 |   readonly dismissible?: boolean
      17 |   readonly button?: boolean
      18 |   readonly "data-spec"?: string

      at ScriptTransformer._transformAndBuildScript (../node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
      at ScriptTransformer.transform (../node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
      at Object.<anonymous> (src/cheshire/components/Chip/index.tsx:15:36)

I guess that's probably because the main target is now an ES module. But Jest doesn't support ES modules natively. See https://github.com/facebook/jest/issues/4842

My team thinks it is not a good idea to introduce Babel just because of this problem... Could you also support CommonJS style modules? Thank you.

jorgebucaran commented 5 years ago

@wata727 Do you mean changing main to a UMD or would it be enough with creating a new target like dist/classcat.umd.js?

wata727 commented 5 years ago

I think that the least impact from the current release is to add a new target. We plan to use moduleNameMapper to replace it during testing. See https://jestjs.io/docs/en/configuration.html#modulenamemapper-object-string-string

{
  "moduleNameMapper": {
    "classcat": "classcat/dist/classcat.umd.js"
  }
}
jorgebucaran commented 5 years ago

@wata727 That's a good idea. Would you like to send me a PR? Otherwise, I can get to it later today.

wata727 commented 5 years ago

Sure! I'll try it.

jorgebucaran commented 5 years ago

@wata727 Fixed with 378cabe, but do check, please. 🎉

wata727 commented 5 years ago

@jorgebucaran It worked well. Thank you!