包详细信息

amaro

nodejs13.7kMIT1.1.0

Node.js TypeScript wrapper

typescript, nodejs, type stripping, strip-types

自述文件

Amaro

Amaro is a wrapper around @swc/wasm-typescript, a WebAssembly port of the SWC TypeScript parser. It's used as an internal in Node.js for Type Stripping but can also be used as a standalone package.

Amaro means "bitter" in Italian. It's a reference to Mount Amaro) on whose slopes this package was conceived.

This package provides a stable API for the TypeScript parser and allows users to upgrade to the latest version of TypeScript transpiler independently from the one used internally in Node.js.

How to Install

To install Amaro, run:

npm install amaro

How to Use

By default Amaro exports a transformSync function that performs type stripping. Stack traces are preserved, by replacing removed types with white spaces.

const amaro = require('amaro');
const { code } = amaro.transformSync("const foo: string = 'bar';", { mode: "strip-only" });
console.log(code); // "const foo         = 'bar';"

Loader

It is possible to use Amaro as an external loader to execute TypeScript files. This allows the installed Amaro to override the Amaro version used by Node.js. In order to use Amaro as an external loader, type stripping needs to be enabled.

In node v23 and later you can omit the --experimental-strip-types flag, as it is enabled by default.

node --experimental-strip-types --import="amaro/strip" file.ts

Enabling TypeScript feature transformation:

node --experimental-transform-types --import="amaro/transform" file.ts

Note that the "amaro/transform" loader should be used with --experimental-transform-types flag, or at least with --enable-source-maps flag, to preserve the original source maps.

Type stripping in dependencies

Contrary to the Node.js TypeScript support, when used as a loader, Amaro handles TypeScript files inside folders under a node_modules path.

Monorepo usage

Amaro makes working in monorepos smoother by removing the need to rebuild internal packages during development. When used with the --conditions flag, you can reference TypeScript source files directly in exports:

"exports": {
  ".": {
    "typescript": "./src/index.ts",
    "types": "./dist/index.d.ts",
    "require": "./dist/index.js",
    "import": "./dist/index.js"
 }
}

Then run your app with:

node --watch --import="amaro/strip" --conditions=typescript ./src/index.ts

This setup allows Node.js to load TypeScript files from linked packages without a build step. Changes to any package are picked up immediately, speeding up and simplifying local development in monorepos.

TypeScript Version

The supported TypeScript version is 5.8.

License (MIT)

See LICENSE.md.

更新日志

Changelog

1.1.0 (2025-06-16)

Features

  • include types in published package (afc687c)

Miscellaneous

  • add package.json keywords (be513d3)
  • build wasm from swc v1.12.1 (732c564)
  • deps: bump github/codeql-action from 3.28.19 to 3.29.0 (91b8711)
  • deps: bump step-security/harden-runner from 2.12.0 to 2.12.1 (d4194bc)
  • update swc to v1.12.1 (a429e15)

1.0.0 (2025-06-09)

⚠ BREAKING CHANGES

  • The amaro/register loader has been removed.

Bug Fixes

Core

  • add snapshot for advanced type-level constructs (infer, keyof, typeof) (21e1cb2)
  • add snapshot for satisfies expressions (40a7cc9)

Miscellaneous

  • adds a note about monorepo workflows (45646df)
  • build wasm from swc v1.11.31 (743f038)
  • deps: bump biomejs/setup-biome from 2.5.0 to 2.5.1 (9e85b83)
  • deps: bump github/codeql-action from 3.28.17 to 3.28.18 (3f23676)
  • deps: bump github/codeql-action from 3.28.18 to 3.28.19 (8a3e2e7)
  • deps: bump ossf/scorecard-action from 2.4.1 to 2.4.2 (928172c)
  • fix spelling (d74400e)
  • fix typos in the documentation (2dbcf48)
  • improve docs (7503d5d)
  • remove amaro/register (125cf70)
  • update README.md to include a paragraph about type stripping in dependencies (cd8faad)
  • update swc to v1.11.31 (7413f85)
  • update test range to v24 (2481905)

0.5.3 (2025-05-05)

Miscellaneous

  • build wasm from swc v1.11.22 (843e731)
  • build wasm from swc v1.11.24 (b1a6aba)
  • deps: bump github/codeql-action from 3.28.15 to 3.28.16 (040c03c)
  • deps: bump github/codeql-action from 3.28.16 to 3.28.17 (44f47cf)
  • deps: bump step-security/harden-runner from 2.11.1 to 2.12.0 (11821f8)
  • update swc to v1.11.22 (ba05a1d)
  • update swc to v1.11.24 (67160ae)

0.5.2 (2025-04-14)

Core

  • check deeply nested expression oob (317a736)

Miscellaneous

  • build wasm from swc v1.11.16 (8c04615)
  • build wasm from swc v1.11.20 (d53b148)
  • build wasm from swc v1.11.21 (e2d86e8)
  • deps: bump actions/setup-node from 4.3.0 to 4.4.0 (12e149b)
  • deps: bump github/codeql-action from 3.28.13 to 3.28.15 (460fa7e)
  • deps: bump step-security/harden-runner from 2.11.0 to 2.11.1 (c880281)
  • update swc to v1.11.16 (744fd41)
  • update swc to v1.11.20 (e9f2c78)
  • update swc to v1.11.21 (789f5b7)

0.5.1 (2025-04-01)

Bug Fixes

  • use correct path in error message (78f9192)

Core

  • update test for lateset swc (722f8ba)

Miscellaneous

  • build wasm from swc v1.11.13 (a483bef)
  • build wasm from swc v1.11.15 (a1478a5)
  • create CODEOWNERS file (0fb76e8)
  • deps: bump actions/upload-artifact from 4.6.1 to 4.6.2 (fab71f5)
  • deps: bump biomejs/setup-biome from 2.3.0 to 2.5.0 (b56fa04)
  • deps: bump github/codeql-action from 3.28.11 to 3.28.12 (06ead41)
  • deps: bump github/codeql-action from 3.28.12 to 3.28.13 (e51cb7f)
  • update swc to v1.11.13 (70b71c3)
  • update swc to v1.11.15 (29d4c2d)

0.5.0 (2025-03-23)

Features

  • build error snippet manually (ca68f6b)

Core

  • check nested generics are handled correctly (9c7580a)
  • drop --experimental-test-snapshots (1894330)

Miscellaneous

  • build wasm from swc v1.11.12 (9d86a02)
  • build wasm from swc v1.11.9 (34311ed)
  • deps: bump actions/setup-node from 4.2.0 to 4.3.0 (e8f9760)
  • deps: bump docker/setup-buildx-action from 3.9.0 to 3.10.0 (d44959c)
  • deps: bump EmbarkStudios/cargo-deny-action from 2.0.10 to 2.0.11 (d477d0d)
  • deps: bump EmbarkStudios/cargo-deny-action from 2.0.5 to 2.0.6 (0d89338)
  • deps: bump EmbarkStudios/cargo-deny-action from 2.0.6 to 2.0.10 (c2a1506)
  • deps: bump github/codeql-action from 3.28.10 to 3.28.11 (05679c1)
  • deps: bump googleapis/release-please-action from 4.1.3 to 4.1.4 (597a8e1)
  • deps: bump googleapis/release-please-action from 4.1.4 to 4.2.0 (61dca14)
  • document amaro as loader (1094c02)
  • update swc to v1.11.12 (b7f663b)
  • update swc to v1.11.9 (2b4a2df)

0.4.1 (2025-02-28)

Core

  • make sure the right error is emitted (9695cf8)

Miscellaneous

  • build wasm from swc v1.10.18 (ba898ad)
  • build wasm from swc v1.11.4 (4f345be)
  • build wasm from swc v1.11.5 (95d2869)
  • deps: bump actions/upload-artifact from 4.6.0 to 4.6.1 (a37726b)
  • deps: bump EmbarkStudios/cargo-deny-action from 2.0.4 to 2.0.5 (c31db0e)
  • deps: bump github/codeql-action from 3.28.9 to 3.28.10 (1230254)
  • deps: bump ossf/scorecard-action from 2.4.0 to 2.4.1 (2855ed6)
  • update swc to v1.10.18 (ac490b2)
  • update swc to v1.11.4 (a41ab59)
  • update swc to v1.11.5 (25e13ea)

0.4.0 (2025-02-18)

Features

  • add option deprecatedTsModuleAsError (cfc3f00)

Miscellaneous

  • build wasm from swc v1.10.15 (4e993fd)
  • build wasm from swc v1.10.16 (b097846)
  • deps: bump docker/setup-buildx-action from 3.8.0 to 3.9.0 (65e736c)
  • deps: bump github/codeql-action from 3.28.8 to 3.28.9 (936abc0)
  • deps: bump step-security/harden-runner from 2.10.4 to 2.11.0 (9438700)
  • remove manual update docs (59e35a9)
  • update swc to v1.10.15 (78391dd)
  • update swc to v1.10.16 (fd283be)

0.3.2 (2025-02-04)

Core

  • check erasable namespaces are supported (e489d48)
  • swc allows invalid js syntax (2a3fbe8)

Miscellaneous

  • build wasm from swc v1.10.12 (081dee3)
  • build wasm from swc v1.10.14 (4e6441c)
  • deps: bump actions/setup-node from 4.1.0 to 4.2.0 (43ee356)
  • deps: bump github/codeql-action from 3.28.5 to 3.28.8 (85ca75b)
  • update swc to v1.10.12 (e2559e7)
  • update swc to v1.10.14 (fa2d3ac)

0.3.1 (2025-01-27)

Bug Fixes

Core

  • check if newline on return works (fe0f570)
  • check if yield and throw newline work (96dba79)

Miscellaneous

  • build wasm from swc v1.10.11 (cdea312)
  • deps: bump github/codeql-action from 3.28.1 to 3.28.5 (ce514fa)
  • deps: bump step-security/harden-runner from 2.10.3 to 2.10.4 (9059a36)
  • deps: bump wagoid/commitlint-github-action from 6.2.0 to 6.2.1 (1a876ff)
  • update swc to v1.10.11 (e9a918c)

0.3.0 (2025-01-13)

Features

  • wrap and rethrow swc errors (8764122)

Miscellaneous

  • build wasm from swc v1.10.7 (35efcea)
  • deps: bump actions/upload-artifact from 4.5.0 to 4.6.0 (1d8a938)
  • deps: bump biomejs/setup-biome from 2.2.1 to 2.3.0 (10c101c)
  • deps: bump github/codeql-action from 3.28.0 to 3.28.1 (4b29609)
  • deps: bump step-security/harden-runner from 2.10.2 to 2.10.3 (e355436)
  • exclude fixtures from typecheck (2a3c016)
  • update swc to v1.10.7 (8051db3)

0.2.2 (2025-01-06)

Miscellaneous

  • build wasm from swc v1.10.4 (a00240a)
  • deps: bump github/codeql-action from 3.27.0 to 3.28.0 (88051e0)
  • include chore in change logs (9ab6341)
  • update release actions (9538187)
  • update swc to v1.10.4 (af1fd9c)