cjstoesm

A tool that can transform CommonJS to ESM

MIT License

Downloads
12.1K
Stars
376
Committers
2
cjstoesm - Latest Release

Published by wessberg over 2 years ago

fix: use ansi-colors instead of Chalk for better CJS fallback support

https://github.com/wessberg/cjstoesm/compare/v2.1.1...v2.1.2

cjstoesm -

Published by wessberg over 2 years ago

  • fix: handle .cts and .mts extensions c772152
  • chore: bump dependencies 3ca4377
  • docs: typo 132e14d
  • docs: add Import Assertions example 2a544dc

https://github.com/wessberg/cjstoesm/compare/v2.1.0...v2.1.1

cjstoesm -

Published by wessberg over 2 years ago

  • feat: add support for adding and customizing Import Assertions 6bf8056

https://github.com/wessberg/cjstoesm/compare/v2.0.0...v2.1.0

cjstoesm -

Published by wessberg over 2 years ago

New Features

The 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.

Improve emit behavior

No more replication of source folder structure (BREAKING CHANGE)

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>.

Allow overwriting in-place and make 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 **/*.*

Easier globbing

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.

  • feat: migrate to publishing ES-modules with a CommonJS fallback. Improve emit-behavior. Fix bugs related to inclusion of module specifiers 78592d0

https://github.com/wessberg/cjstoesm/compare/v1.1.5...v2.0.0

cjstoesm -

Published by wessberg over 2 years ago

  • feat: Add support for TypeScript 4.6. Add new sponsor b73eb9e

https://github.com/wessberg/cjstoesm/compare/v1.1.4...v1.1.5

cjstoesm -

Published by wessberg over 3 years ago

  • chore(build): bump dependencies ed627ca

https://github.com/wessberg/cjstoesm/compare/v1.1.3...v1.1.4

cjstoesm -

Published by wessberg over 3 years ago

  • chore(build): bump dependencies 0d5d528
  • Update README.md 49cc90c
  • chore(build): add [email protected] to test versions of TypeScript 50f5c5b

https://github.com/wessberg/cjstoesm/compare/v1.1.2...v1.1.3

cjstoesm -

Published by wessberg over 3 years ago

cjstoesm -

Published by wessberg over 3 years ago

  • refactor: move shared path helpers into dependency on crosspath 6a703f5
  • refactor: use helper types instead of duplications ba8fef4
  • fix: remove deprecated call to program.help() e47e45d

https://github.com/wessberg/cjstoesm/compare/v1.1.0...v1.1.1

cjstoesm -

Published by wessberg over 3 years ago

  • fix: ensure POSIX-formatted file names before passing on to glob d2d9acd
  • fix(api): fix issue where API would always return an empty file array 4a26823

https://github.com/wessberg/cjstoesm/compare/v1.0.1...v1.1.0

cjstoesm -

Published by wessberg over 3 years ago

  • chore(build): fix API entry points 18e4cd5

https://github.com/wessberg/cjstoesm/compare/v1.0.0...v1.0.1

cjstoesm -

Published by wessberg over 3 years ago

New Features

Automatic and configurable addition of file extensions to module specifiers

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 preserved
  • internal: CommonJS module specifiers identifying anything else than libraries or built-in modules are preserved
  • always: CommonJS module specifiers are never transformed.
  • never: CommonJS module specifiers are always transformed

It can also take a function that is invoked with a module specifier and returns a boolean determining whether or not it should be preserved.

Full changelog

  • docs(README): update README 02213db
  • feat: add new option, 'preserveModuleSpecifiers' 1bad5b7

https://github.com/wessberg/cjstoesm/compare/v0.1.3...v1.0.0

cjstoesm -

Published by wessberg about 4 years ago

  • feat: run tests for all TypeScript versions 0b0261c
  • fix: fix issue where function name could be lost 6de7830

https://github.com/wessberg/cjstoesm/compare/v0.1.2...v0.1.3

cjstoesm -

Published by wessberg about 4 years ago

  • fix: ensure no local bindings may conflict 7dafcd6

https://github.com/wessberg/cjstoesm/compare/v0.1.1...v0.1.2

cjstoesm -

Published by wessberg about 4 years ago

Features

  • feat(api): add API support ea42c39

Breaking Changes

  • BREAKING CHANGE: rename to cjstoesm, to align with the executable and make CLI usage easier 4eb039e
cjstoesm -

Published by wessberg over 4 years ago

  • fix: add support for 'export const foo = require(...)'. Closes #5 31d0141

https://github.com/wessberg/cjs-to-esm-transformer/compare/v0.0.21...v0.0.22

cjstoesm -

Published by wessberg over 4 years ago

  • fix: add support for CommonJS-based barrel exports e6e33c0

https://github.com/wessberg/cjs-to-esm-transformer/compare/v0.0.20...v0.0.21

cjstoesm -

Published by wessberg over 4 years ago

  • BREAKING CHANGE: Drop Node 8 support cadc608
  • fix: use a proper TransformationContext at all times. Adds TypeScript v3.9.5 support 1a14d64
  • fix: moving require calls up from a block scope will remove the surrounding block a66d7b5
  • chore(build): remove core-js dependency aa05321

https://github.com/wessberg/cjs-to-esm-transformer/compare/v0.0.19...v0.0.20

cjstoesm - v0.0.19

Published by wessberg over 4 years ago

  • chore: update with TypeScript v3.8 support 4cc4a09
  • Merge pull request #4 from FDiskas/patch-1 db11215
  • Update package.json 47c62e1
cjstoesm - v0.0.18

Published by wessberg over 4 years ago

New Features

  • Experimental support for UMD