rescript-association / genType

Auto generation of idiomatic bindings between Reason and JavaScript: either vanilla or typed with TypeScript/FlowType.

Home Page:https://rescript-lang.org/docs/gentype/latest/introduction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

genType doesn't read bsconfig module flag

adnelson opened this issue · comments

I was running into an issue where gentype would generate

const Curry = require('bs-platform/lib/es6/curry.mjs');

rather than

var Curry = require("bs-platform/lib/js/curry.js");

Which is what appears in .bs.js files. This resulted in a very unhappy compiler (tsc):

[Node] ./node_modules/bs-platform/lib/es6/curry.mjs:3
[Node] import * as Caml_array from "./caml_array.mjs";
[Node] ^^^^^^
[Node] 
[Node] SyntaxError: Cannot use import statement outside a module

My bsconfig.json specifies "commonjs" for .bs.js files,

{
  "package-specs": [
    {
      "module": "commonjs",
      "in-source": true
    }
  ],
  ...
}   

Looking over Config_.re in this project, I saw that the fix was to put it in my gentypeconfig:

{
  "gentypeconfig": {
    "module": "commonjs"
    ...
  },
  ...
}

I think if gentype used whatever's in package-specs, with the ability to override it on the gentypeconfig, it would make for a little more intuitive experience.

Thoughts?

@adnelson thanks for the suggestion! It makes sense.