iarna-toml icon indicating copy to clipboard operation
iarna-toml copied to clipboard

Use `.cjs` file extension for CommonJS modules

Open jsejcksn opened this issue 3 years ago • 0 comments

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 when package.type is commonjs or undefined — that's the case here. When package.type is module (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.

jsejcksn avatar Jul 13 '20 02:07 jsejcksn