Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions deps/amaro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ This allows the installed Amaro to override the Amaro version used by Node.js.
node --experimental-strip-types --import="amaro/register" script.ts
```

Or with the alias:

```bash
node --experimental-strip-types --import="amaro/strip" script.ts
```

Enabling TypeScript feature transformation:

```bash
node --experimental-transform-types --import="amaro/transform" script.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.

### How to update SWC

To update the SWC version, run:
Expand Down
55 changes: 16 additions & 39 deletions deps/amaro/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps/amaro/dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"강동윤 <kdy1997.dev@gmail.com>"
],
"description": "wasm module for swc",
"version": "1.7.35",
"version": "1.7.40",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions deps/amaro/dist/register-strip.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { register } from "node:module";

register("./strip-loader.js", import.meta.url);
12 changes: 12 additions & 0 deletions deps/amaro/dist/register-transform.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { register } from "node:module";
import { emitWarning, env, execArgv } from "node:process";

const hasSourceMaps =
execArgv.includes("--enable-source-maps") ||
env.NODE_OPTIONS?.includes("--enable-source-maps");

if (!hasSourceMaps) {
emitWarning("Source maps are disabled, stack traces will not accurate");
}

register("./transform-loader.js", import.meta.url);
3 changes: 0 additions & 3 deletions deps/amaro/dist/register.mjs

This file was deleted.

24 changes: 24 additions & 0 deletions deps/amaro/dist/strip-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
import { transformSync } from "./index.js";
export async function load(url, context, nextLoad) {
const { format } = context;
if (format.endsWith("-typescript")) {
const { source } = await nextLoad(url, {
...context,
format: "module"
});
const { code } = transformSync(source.toString(), {
mode: "strip-only"
});
return {
format: format.replace("-typescript", ""),
// Source map is not necessary in strip-only mode. However, to map the source
// file in debuggers to the original TypeScript source, add a sourceURL magic
// comment to hint that it is a generated source.
source: `${code}

//# sourceURL=${url}`
};
}
return nextLoad(url, context);
}
30 changes: 30 additions & 0 deletions deps/amaro/dist/transform-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
import { transformSync } from "./index.js";
export async function load(url, context, nextLoad) {
const { format } = context;
if (format.endsWith("-typescript")) {
const { source } = await nextLoad(url, {
...context,
format: "module"
});
const { code, map } = transformSync(source.toString(), {
mode: "transform",
sourceMap: true,
filename: url
});
let output = code;
if (map) {
const base64SourceMap = Buffer.from(map).toString("base64");
output = `${code}

//# sourceMappingURL=data:application/json;base64,${base64SourceMap}`;
}
return {
format: format.replace("-typescript", ""),
source: `${output}

//# sourceURL=${url}`
};
}
return nextLoad(url, context);
}
15 changes: 10 additions & 5 deletions deps/amaro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amaro",
"version": "0.1.9",
"version": "0.2.0",
"description": "Node.js TypeScript wrapper",
"license": "MIT",
"type": "commonjs",
Expand All @@ -21,22 +21,27 @@
"ci:fix": "biome check --write",
"prepack": "npm run build",
"postpack": "npm run clean",
"build": "node esbuild.config.js",
"build": "node esbuild.config.mjs",
"typecheck": "tsc --noEmit",
"test": "node --test --experimental-test-snapshots \"**/*.test.js\"",
"test:regenerate": "node --test --experimental-test-snapshots --test-update-snapshots \"**/*.test.js\""
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/node": "^20.14.11",
"@types/node": "^22.0.0",
"esbuild": "^0.23.0",
"esbuild-plugin-copy": "^2.1.1",
"rimraf": "^6.0.1",
"typescript": "^5.5.3"
},
"exports": {
".": "./dist/index.js",
"./register": "./dist/register.mjs"
"./register": "./dist/register-strip.mjs",
"./strip": "./dist/register-strip.mjs",
"./transform": "./dist/register-transform.mjs"
},
"files": ["dist", "LICENSE.md"]
"files": ["dist", "LICENSE.md"],
"engines": {
"node": ">=22"
}
}
2 changes: 1 addition & 1 deletion src/amaro_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// Refer to tools/dep_updaters/update-amaro.sh
#ifndef SRC_AMARO_VERSION_H_
#define SRC_AMARO_VERSION_H_
#define AMARO_VERSION "0.1.9"
#define AMARO_VERSION "0.2.0"
#endif // SRC_AMARO_VERSION_H_
Loading