Releases: lukeed/tsm
v2.3.0
Features
- Bump
esbuildto^15.16.0version.
Previously using the14.xrelease cycle.
This15.xrange includes features such as:
* Yarn Plug'N'Play (PnP) support
* Improved Yarn Workspaces support
* Newsupportedoptions (accessible within tsm config)
* Support for TypeScript 4.9satisfiesoperator (#42)
* Improvedimportssubpath resolution (#31)
* Addsdenoas a validtargetvalue
* & more.. see esbuild changelog!
Patches
-
Correctly resolve non-
.jsfile when requiring or importing the would-be.jsvirtual path (#33):
TypeScript allows (and expects) you to writeimport("./App.js")in your source, even though onlyApp.tsxorApp.jsxexists on disk. There are many other extension aliases like this, all of which are now supported:"*.js" // <-- [".js", ".ts", ".tsx", ".jsx"] "*.mjs" // <-- [".mjs", ".mts"] "*.cjs" // <-- [".cjs", ".cts"] "*.jsx" // <-- [".jsx", ".tsx"]
-
Fix dynamic imports within CommonJS files (#27)
Previously,tsmleft dynamic imports alone, relying on native behavior. However, this meant that thenode -r tsm <file>usage might encounter code likeimport("./Post.tsx")that would throw an error because nativeimport()cannot deal with the.tsxfile type. This release now covers this use case, allowing CommonJS/--requireusers to dynamically import any non-.jsfile...tsmwill transform it correctly, as configured. -
Improve source map support for
tsm <file>CLI usage (#32):
When runningtsmdirectly, the--enable-source-mapsflag is enabled for native Node.js sourcemap support. This means that any errors / stack traces will correctly map to the.tssource locations!Note: If running
node -r tsmornode --loader tsm, then you must include the--enable-source-mapsflag manually.
Full Changelog: v2.2.2...v2.3.0
v2.2.2
Patches
- Add support for Node.js v18.6.0+ (#36, #37): 82c0e90
Node 18.6 now requiresshortCircuit: truein return values. This is a breaking change within the Node 18.x release cycle, but this (I suppose) is permissible since ESM hooks are still in Stability 1: Experimental stage.
Thank you @antongolub for the fix~!
Full Changelog: v2.2.1...v2.2.2
v2.2.0
v2.1.4
v2.1.3
Patches
-
Support the new API for ESM loader hooks (#13, #16): b483e40
As of [email protected], ESM loader hooks received an API update. This release adheres to the new design while also continuing support for the previous (now deprecated) API design.
tsm will continue to support both API designs until sufficient time has passed that it's safe to assume users are no longer using (or should be using) previous/non-LTS Node versions that carry the old design. Dropping support for the old ESM loader hooks design will likely warrant a future
3.0.0release.
Chores
Full Changelog: v2.1.2...v2.1.3
v2.1.2
Patches
- (bin): Support global usage on Windows: 67600a7
Apparently, on Windows, you need to passfile://URLs to--loaderwhen used viachild_processmodule.
Chores
- (docs): Include usage instructions/example for using
tsmas a bash shebang: 83896bc#!/usr/bin/env tsm import { greet } from './hello'; let [name] = process.argv.slice(2); greet(name || 'world'); //=> Hello, world!
Full Changelog: v2.1.1...v2.1.2
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_ESMerror thrown when yourequireESM ".js" file(s).Previously, tsm didn't handle the case where you could
requireafoo.jsfile 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
.jsfiles. 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 tsmdoes nothing to.jsfiles by default. It will only retry a.jsfile if theERR_REQUIRE_ESMerror was thrown. In fact, if any loader (regardless of extension) attempts to execute but throws theERR_REQUIRE_ESMerror, then the file is retried w/ the same options, but forcingformat: cjsthe second time around.Note: If you add custom configuration for
.jsfiles, then tsm will respect that and follow your directions anyway. Your config will always execute, not just when theERR_REQUIRE_ESMerror is thrown.
Chores
- Add typescript + "type: module" tests: 1368d98
- (require): Determine
options.sourcefileonce per loader: 98dab33 - (require): Determine
options.banneronce per loader: 329ac1c
Full Changelog: v2.1.0...v2.1.1
v2.1.0
Features
-
Support the
.mtsand.ctsTypeScript extensions π (#3): cc7ce98Upgraded to
[email protected]which includes full support for these extensions. This upgrade allows tsm to safely support & add.mtsand.ctsto its default extensions map. -
Allow JavaScript extensions for TypeScript imports (#2, #1): c935537
If you have a
foo.tsfile, this allows you to import it asfoo.jsfrom another file. This is useful for TypeScript projects that are not using a bundler, where every input is mapped to its own output file. In this this scenario, and when producing ESM output, you need to include the.jsextension in your import statements so that the output file(s) resolve to fully-qualified URLs.Note: This is a long-awaited TypeScript feature & there's now official movement. Please see microsoft/TypeScript#16577 or this nice summary thread.
Example Usage
Assume this project structure:
demo βββ aaa.ts βββ bbb.cts βββ ccc.mts βββ main.tsAnd the
main.tsfile includes the following:import aaa from './aaa.js'; // => loads the "aaa.ts" file import bbb from './bbb.cjs'; // => loads the "bbb.cts" file import ccc from './ccc.mjs'; // => loads the "ccc.mts" file
Full Changelog: v2.0.0...v2.1.0