amaro 0.5.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -9
- package/dist/errors.d.ts +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/package.json +1 -1
- package/dist/strip-loader.d.ts +2 -0
- package/dist/transform-loader.d.ts +2 -0
- package/dist/transform.d.ts +2 -0
- package/lib/wasm.d.ts +59 -0
- package/lib/wasm_bg.wasm.d.ts +12 -0
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# Amaro
|
|
2
2
|
|
|
3
3
|
Amaro is a wrapper around `@swc/wasm-typescript`, a WebAssembly port of the SWC TypeScript parser.
|
|
4
|
-
It's
|
|
5
|
-
The main goal of this package is to provide a stable API for TypeScript parser, which is unstable and subject to change.
|
|
4
|
+
It's used as an internal in Node.js for [Type Stripping](https://nodejs.org/api/typescript.html#type-stripping) but can also be used as a standalone package.
|
|
6
5
|
|
|
7
6
|
> Amaro means "bitter" in Italian. It's a reference to [Mount Amaro](https://en.wikipedia.org/wiki/Monte_Amaro_(Abruzzo)) on whose slopes this package was conceived.
|
|
8
7
|
|
|
8
|
+
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.
|
|
9
|
+
|
|
9
10
|
## How to Install
|
|
10
11
|
|
|
11
12
|
To install Amaro, run:
|
|
@@ -31,25 +32,48 @@ It is possible to use Amaro as an external loader to execute TypeScript files.
|
|
|
31
32
|
This allows the installed Amaro to override the Amaro version used by Node.js.
|
|
32
33
|
In order to use Amaro as an external loader, type stripping needs to be enabled.
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
node --experimental-strip-types --import="amaro/register" script.ts
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Or with the alias:
|
|
35
|
+
In node v23 and later you can omit the `--experimental-strip-types` flag, as it is enabled by default.
|
|
39
36
|
|
|
40
37
|
```bash
|
|
41
|
-
node --experimental-strip-types --import="amaro/strip"
|
|
38
|
+
node --experimental-strip-types --import="amaro/strip" file.ts
|
|
42
39
|
```
|
|
43
40
|
|
|
44
41
|
Enabling TypeScript feature transformation:
|
|
45
42
|
|
|
46
43
|
```bash
|
|
47
|
-
node --experimental-transform-types --import="amaro/transform"
|
|
44
|
+
node --experimental-transform-types --import="amaro/transform" file.ts
|
|
48
45
|
```
|
|
49
46
|
|
|
50
47
|
> Note that the "amaro/transform" loader should be used with `--experimental-transform-types` flag, or
|
|
51
48
|
> at least with `--enable-source-maps` flag, to preserve the original source maps.
|
|
52
49
|
|
|
50
|
+
#### Type stripping in dependencies
|
|
51
|
+
|
|
52
|
+
Contrary to the Node.js [TypeScript support](https://nodejs.org/docs/latest/api/typescript.html#type-stripping-in-dependencies), when used as a loader, Amaro handles TypeScript files inside folders under a `node_modules` path.
|
|
53
|
+
|
|
54
|
+
### Monorepo usage
|
|
55
|
+
|
|
56
|
+
Amaro makes working in monorepos smoother by removing the need to rebuild internal packages during development. When used with the [`--conditions`](https://nodejs.org/docs/latest/api/cli.html#-c-condition---conditionscondition) flag, you can reference TypeScript source files directly in exports:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
"exports": {
|
|
60
|
+
".": {
|
|
61
|
+
"typescript": "./src/index.ts",
|
|
62
|
+
"types": "./dist/index.d.ts",
|
|
63
|
+
"require": "./dist/index.js",
|
|
64
|
+
"import": "./dist/index.js"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Then run your app with:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
node --watch --import="amaro/strip" --conditions=typescript ./src/index.ts
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
53
77
|
### TypeScript Version
|
|
54
78
|
|
|
55
79
|
The supported TypeScript version is 5.8.
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type SwcError = {
|
|
2
|
+
code: "UnsupportedSyntax" | "InvalidSyntax";
|
|
3
|
+
message: string;
|
|
4
|
+
startColumn: number;
|
|
5
|
+
startLine: number;
|
|
6
|
+
snippet: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
endColumn: number;
|
|
9
|
+
endLine: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function isSwcError(error: unknown): error is SwcError;
|
|
12
|
+
export declare function wrapAndReThrowSwcError(error: SwcError): never;
|
|
13
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { transformSync } from "./transform.ts";
|