v2.1.1
Patches
-
Allow usage through global installation: fbbb29f
-
Allow
require()
of ".js" files with ESM content (#7, #8): 822f0ba
This handles theERR_REQUIRE_ESM
error thrown when yourequire
ESM ".js" file(s).Previously, tsm didn't handle the case where you could
require
afoo.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 exampleuvu -r tsm tests
– then the TypeScript would be converted into CommonJS, makingrequire()
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 theERR_REQUIRE_ESM
error was thrown. In fact, if any loader (regardless of extension) attempts to execute but throws theERR_REQUIRE_ESM
error, then the file is retried w/ the same options, but forcingformat: 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 theERR_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