Releases: lukeed/tsm
v2.3.0
Features
- Bump
esbuild
to^15.16.0
version.
Previously using the14.x
release cycle.
This15.x
range includes features such as:
* Yarn Plug'N'Play (PnP) support
* Improved Yarn Workspaces support
* Newsupported
options (accessible within tsm config)
* Support for TypeScript 4.9satisfies
operator (#42)
* Improvedimports
subpath resolution (#31)
* Addsdeno
as a validtarget
value
* & more.. see esbuild changelog!
Patches
-
Correctly resolve non-
.js
file when requiring or importing the would-be.js
virtual path (#33):
TypeScript allows (and expects) you to writeimport("./App.js")
in your source, even though onlyApp.tsx
orApp.jsx
exists 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,tsm
left 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.tsx
file type. This release now covers this use case, allowing CommonJS/--require
users to dynamically import any non-.js
file...tsm
will transform it correctly, as configured. -
Improve source map support for
tsm <file>
CLI usage (#32):
When runningtsm
directly, the--enable-source-maps
flag is enabled for native Node.js sourcemap support. This means that any errors / stack traces will correctly map to the.ts
source locations!Note: If running
node -r tsm
ornode --loader tsm
, then you must include the--enable-source-maps
flag 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: true
in 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.0
release.
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--loader
when used viachild_process
module.
Chores
- (docs): Include usage instructions/example for using
tsm
as 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_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
v2.1.0
Features
-
Support the
.mts
and.cts
TypeScript extensions π (#3): cc7ce98Upgraded to
[email protected]
which includes full support for these extensions. This upgrade allows tsm to safely support & add.mts
and.cts
to its default extensions map. -
Allow JavaScript extensions for TypeScript imports (#2, #1): c935537
If you have a
foo.ts
file, this allows you to import it asfoo.js
from 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.js
extension 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.ts
And the
main.ts
file 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