API modules export to `export.default` instead of `module.exports`
The API packages cannot import modules with this code:
const format = require('@commitlint/format');
format({}); // `stderr`: TypeError: format is not a function
While import from default works:
const format = require('@commitlint/format').default;
format({})
Current Behavior
After I do npm install --save @commitlint/format, then look into node_modules/index.js:
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(format_1).default; } });
That means the complied typescript code export itself to module.exports.default, not module.exports
Affected packages
All the API Packages with newest version
Possible Solution
We can change the documentation or the codebase
Steps to Reproduce (for bugs)
Test it on runkit. At first, it was so puzzling that I almost gave up using it ☺, please fix that, THANKS!
Your Environment
| Executable | Version |
|---|---|
node --version |
v14.15.1 |
Hey @beetcb , is #2405 related or maybe the same?
As as far as I know, format is a separate module and does not need to set commitlint.config.js.
Yes, both #2405 and this have the same issue: something about CommonJS and ECMAScript module
Anyway, the output should be something like this, can ts complier fix that (i know nothing about typescript)?
Object.defineProperty(module, 'exports', {
enumerable: true,
get: function () { return __importDefault(format_1).default; }
});
Or for simplicity, just change the documentation, add .default
Happy for any PR