iarna-toml
iarna-toml copied to clipboard
Use `.cjs` file extension for CommonJS modules
In consideration of ESM support (pending #36), I think it makes sense for this package to be explicit about CommonJS modules by utilizing the .cjs
extension.
-
JavaScript has standardized on ESM, and Node doesn't care if CommonJS module file extensions are
.js
or.cjs
whenpackage.type
iscommonjs
or undefined — that's the case here. Whenpackage.type
ismodule
(not the case here) CommonJS files must end in.cjs
. (See https://nodejs.org/api/esm.html) -
It provides immediate clarity to anyone casually browsing the repository: they can see the
.cjs
extension and instantly know it's a CommonJS module. Similarly,.mjs
serves as an indicator that a file is an ES module for Node (vs. for browser, etc.). This cognitive benefit is the biggest win, IMO.