My question concerns an existing library that I wish to publish as an NPM module. The library is already in use, and currently require
d via the local file syste
Now this is ugly workaround and it does pollute the root of your package. But until Jordan's answer works, this feels like the way to achieve what you ask.
Just add a file in the root of your package for each of the modules you want to export using the require with slash notation. Such file will have the same name as the module being exported and it will simply reexport it.
.
├── package.json
├── thing.js <--
├── that.js <--
├── src
| ├── js
| └────── lib
| └───────── my
| └───────────── thing.js
| └───────────── that.js
For example file ./thing.js
will contain:
module.exports = require('./src/js/lib/my/thing');
And so you could require it as:
const thing = require('mypackage/thing');
Also as stated in the bug about adding mainDir property into package.json you can just temporarily copy your sources and the package.json file into one directory and publish from there.