Skip to content

v2.1.1

Compare
Choose a tag to compare
@lukeed lukeed released this 10 Oct 00:07
· 21 commits to master since this release

Patches

  • Ensure Windows support (#9): acb1071

  • Allow usage through global installation: fbbb29f

  • Allow require() of ".js" files with ESM content (#7, #8): 822f0ba
    This handles the ERR_REQUIRE_ESM error thrown when you require ESM ".js" file(s).

    Previously, tsm didn't handle the case where you could require a foo.js file that contained ESM syntax. Even though this combination is/should be invalid, tsm has to be able to rewrite the file(s) as necessary in the event there's a series or combination of tools that produce this scenario.

    For example, you could be writing tests in TypeScript & those tests import third-party code that's written in ESM within .js files. When executing those tests with a require hook – for example uvu -r tsm tests – then the TypeScript would be converted into CommonJS, making require() calls to the third-party ".js" file, which still contains ESM. This would fail.

    This is implemented in a way such that node -r tsm does nothing to .js files by default. It will only retry a .js file if the ERR_REQUIRE_ESM error was thrown. In fact, if any loader (regardless of extension) attempts to execute but throws the ERR_REQUIRE_ESM error, then the file is retried w/ the same options, but forcing format: cjs the second time around.

    Note: If you add custom configuration for .js files, then tsm will respect that and follow your directions anyway. Your config will always execute, not just when the ERR_REQUIRE_ESM error is thrown.

Chores

  • Add typescript + "type: module" tests: 1368d98
  • (require): Determine options.sourcefile once per loader: 98dab33
  • (require): Determine options.banner once per loader: 329ac1c

Full Changelog: v2.1.0...v2.1.1