A tool that can transform CommonJS to ESM
MIT License
fix: use ansi-colors instead of Chalk for better CJS fallback support
https://github.com/wessberg/cjstoesm/compare/v2.1.1...v2.1.2
https://github.com/wessberg/cjstoesm/compare/v2.1.0...v2.1.1
https://github.com/wessberg/cjstoesm/compare/v2.0.0...v2.1.0
cjstoesm
package is now based on ESM and requires Node v14.19.0 (BREAKING CHANGE)Despite being a tool for converting CommonJS to ESM, and a bit ironically, cjstoesm
has been published as an NPM package with a CommonJS entrypoint (dist/cjs/index.js
), and an ESM entrypoint (dist/esm/index.js
), while the CLI itself was CommonJS based.
Now, the cjstoesm
package is fully based on ESM. There are still API entrypoints for CommonJS using the package exports feature, as well as pointed to from the main
field in the package.json.
From this new major version of cjstoesm
, you must be using Node.js v14.19.0 or newer.
In the past, cjstoesm
would replicate the source folder structure inside the destination folder.
For example, if you called to CLI with something like:
cjstoesm foo/bar/baz/** target
You would get files following a pattern like this: target/foo/bar/baz/<filename>
.
This was a bit counterintuitive.
In the new version, this behavior changes and aligns with general user expectations. In the example above, from the new version files will follow a pattern like this: target/<filename>
.
outDir
an optional argument (BREAKING CHANGE)In the old version of cjstoesm
, passing in an output directory was strictly required. From the new version, the default behavior is to simply overwrite the files in-place. You can still pass in a separate output directory as the second argument if you want, but from the new version this is completely optional.
This means that the following is now possible:
cjstoesm **/*.*
In the old version of cjstoesm
, the following wouldn't work:
cjstoesm src
Since src
doesn't match anything as a glob. However, to align with user expectations, in the new version, any direct descendent of the src
folder will now be matched by the above command.
https://github.com/wessberg/cjstoesm/compare/v1.1.5...v2.0.0
https://github.com/wessberg/cjstoesm/compare/v1.1.4...v1.1.5
https://github.com/wessberg/cjstoesm/compare/v1.1.3...v1.1.4
https://github.com/wessberg/cjstoesm/compare/v1.1.2...v1.1.3
https://github.com/wessberg/cjstoesm/compare/v1.1.1...v1.1.2
https://github.com/wessberg/cjstoesm/compare/v1.1.0...v1.1.1
https://github.com/wessberg/cjstoesm/compare/v1.0.1...v1.1.0
https://github.com/wessberg/cjstoesm/compare/v1.0.0...v1.0.1
Support for EcmaScript modules is now stable in both node.js and supported browsers. In both of these environments, file extensions must be provided to module specifiers when using ES modules. Additionally, directory indexes must also be fully specified.
Until now, cjstoesm
always preserved module specifiers as they were. While this might work fine for a lot of use cases, ideally cjstoesm
generates standards compliant modules.
Going forward, this behavior is now configurable and defaults to adding file extensions to relative module specifiers, while leaving alone module specifiers for built-in modules and external libraries. The preserveModuleSpecifiers
option (or --preserve-module-specifiers
via the CLI).
Here's all the supported options:
external
(default): CommonJS module specifiers identifying libraries or built-in modules are preservedinternal
: CommonJS module specifiers identifying anything else than libraries or built-in modules are preservedalways
: CommonJS module specifiers are never transformed.never
: CommonJS module specifiers are always transformedIt can also take a function that is invoked with a module specifier and returns a boolean determining whether or not it should be preserved.
https://github.com/wessberg/cjstoesm/compare/v0.1.3...v1.0.0
https://github.com/wessberg/cjstoesm/compare/v0.1.2...v0.1.3
https://github.com/wessberg/cjstoesm/compare/v0.1.1...v0.1.2
https://github.com/wessberg/cjs-to-esm-transformer/compare/v0.0.21...v0.0.22
https://github.com/wessberg/cjs-to-esm-transformer/compare/v0.0.20...v0.0.21
https://github.com/wessberg/cjs-to-esm-transformer/compare/v0.0.19...v0.0.20
Published by wessberg over 4 years ago
Published by wessberg over 4 years ago