"in-source" config bleeds into node_modules?

Hi folks.
I am trying to write a node script in rescript, deployed as an npm package.
My scripts package depends on a second rescript npm package, that itself has in-source: true so it can import a js implementation file @module('./impl.js'). All fine so far. But if i configure my outer package without in-source, the installed node module is not built according to its own configuration, and then the rescript files there, now built into lib/ fail to find the relative ./impl.js.

It seems to me that each package should honor its own bsconfig, or maybe builds in-source: false should copy relative files to the dist directory? Otherwise there is a pressure for all packages to eventually build in-source, and Iā€™m sure people have their own reasons for building to a lib dir. Whats the right pattern here?

TIA
Alex

1 Like

One useful trick is to register the JS modules as an exports entry in package.json.

{
  "name": "my-package",
  "exports": {
    "./js-impl": "./src/path/to/impl.js"
  }
}

then you can use @module("my-package/js-impl")

Note that this relies on a feature of Node.js module resolution, so it will only work in ecosystems compatible with it (Node.js, Bun), and other standard ESM environments may need an additional import map to use this.

1 Like