@zntc/wasm 0.1.2 → 0.1.3
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 +38 -32
- package/dist/index.js +11 -11
- package/dist/shared/compat-engines.d.ts +1 -1
- package/package.json +1 -1
- package/zntc-bundler.wasm +0 -0
- package/zntc.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,72 +1,78 @@
|
|
|
1
1
|
# @zntc/wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English · **[한국어](./README_KO.md)**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> WASM build of [ZNTC](https://github.com/ohah/zntc) — transpile and bundle JavaScript / TypeScript / Flow in the browser, Deno, or Cloudflare Workers, with no native binary required.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/@zntc/wasm)
|
|
8
|
+
[](https://github.com/ohah/zntc/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
`@zntc/wasm` runs the ZNTC pipeline as pure WebAssembly. It's for environments where the `@zntc/core` NAPI module can't be loaded — browser in-page transpile, Edge runtimes, Cloudflare Workers, Deno — without needing a platform-specific `.node` binary.
|
|
11
|
+
|
|
12
|
+
For server-side builds on Node / Bun, prefer [`@zntc/core`](https://www.npmjs.com/package/@zntc/core) (native speed). Reach for `@zntc/wasm` when the environment rules out NAPI.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
8
15
|
|
|
9
16
|
```bash
|
|
10
17
|
bun add -D @zntc/wasm
|
|
11
|
-
#
|
|
18
|
+
# or
|
|
12
19
|
npm i -D @zntc/wasm
|
|
13
20
|
```
|
|
14
21
|
|
|
15
|
-
WASM
|
|
22
|
+
The WASM binaries ship with the package: `zntc.wasm` (~1.1 MB / 388 KB gzipped, transpile-only) and `zntc-bundler.wasm` (~2.0 MB / 675 KB gzipped, bundler).
|
|
16
23
|
|
|
17
|
-
##
|
|
24
|
+
## Usage
|
|
18
25
|
|
|
19
|
-
### Browser / Edge runtime
|
|
26
|
+
### Browser / Edge runtime / Workers
|
|
20
27
|
|
|
21
28
|
```ts
|
|
22
29
|
import { init, transpile } from '@zntc/wasm';
|
|
23
|
-
import wasmUrl from '@zntc/wasm/zntc.wasm?url'; // Vite
|
|
30
|
+
import wasmUrl from '@zntc/wasm/zntc.wasm?url'; // Vite-specific syntax
|
|
24
31
|
|
|
25
32
|
await init(wasmUrl);
|
|
26
|
-
const
|
|
27
|
-
console.log(
|
|
33
|
+
const result = transpile('const x: number = 1;', { filename: 'input.ts' });
|
|
34
|
+
console.log(result.code);
|
|
28
35
|
```
|
|
29
36
|
|
|
30
|
-
>
|
|
37
|
+
> Bundlers other than Vite use `fetch(new URL('@zntc/wasm/zntc.wasm', import.meta.url))` or their own asset-import pattern to obtain the WASM URL.
|
|
31
38
|
|
|
32
|
-
### Node.js / Bun (auto-resolve)
|
|
39
|
+
### Deno / Node.js / Bun (auto-resolve)
|
|
33
40
|
|
|
34
41
|
```ts
|
|
35
42
|
import { init, transpile } from '@zntc/wasm';
|
|
36
43
|
|
|
37
|
-
await init(); //
|
|
38
|
-
const
|
|
44
|
+
await init(); // loads the bundled zntc.wasm automatically (fs.readFileSync)
|
|
45
|
+
const result = transpile('const x: number = 1;', { filename: 'input.ts' });
|
|
39
46
|
```
|
|
40
47
|
|
|
41
|
-
### Bundler
|
|
48
|
+
### Bundler build
|
|
42
49
|
|
|
43
50
|
```ts
|
|
44
|
-
import {
|
|
51
|
+
import { build, initBundler, bundlerLastErrorMessage } from '@zntc/wasm';
|
|
45
52
|
import wasmUrl from '@zntc/wasm/zntc-bundler.wasm?url';
|
|
46
53
|
|
|
47
|
-
await initBundler(wasmUrl); //
|
|
54
|
+
await initBundler(wasmUrl); // separate from init() used for transpile
|
|
48
55
|
const out = build('/main.ts', { format: 'esm', target: 'es2020' });
|
|
49
56
|
if (out === null) throw new Error(bundlerLastErrorMessage());
|
|
50
57
|
```
|
|
51
58
|
|
|
52
|
-
`build`
|
|
53
|
-
|
|
54
|
-
## NAPI 와 차이
|
|
59
|
+
`build` is synchronous and returns `null` on failure — call `bundlerLastErrorMessage()` to read the last error.
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
| ----------- | ----------------- | ------------------------------------- |
|
|
58
|
-
| 환경 | Node.js / Bun | + Browser / Edge / Workers |
|
|
59
|
-
| 속도 | 빠름 (~native) | 50~70% (WASM 오버헤드) |
|
|
60
|
-
| binary 크기 | ~4MB (.node) | 1.1MB + 2.0MB (gzipped 388KB + 675KB) |
|
|
61
|
-
| install | 플랫폼별 prebuilt | 단일 wasm (universal) |
|
|
61
|
+
## `@zntc/core` vs `@zntc/wasm`
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
| | `@zntc/core` (NAPI) | `@zntc/wasm` |
|
|
64
|
+
| ----------- | --------------------- | ----------------------------------------- |
|
|
65
|
+
| Environment | Node.js / Bun | + Browser / Edge / Workers / Deno |
|
|
66
|
+
| Speed | Native | ~50–70% (WASM overhead) |
|
|
67
|
+
| Binary size | ~4 MB (`.node`) | 1.1 MB + 2.0 MB (388 KB + 675 KB gzipped) |
|
|
68
|
+
| Install | Per-platform prebuilt | Single universal `.wasm` |
|
|
64
69
|
|
|
65
|
-
##
|
|
70
|
+
## Documentation
|
|
66
71
|
|
|
67
|
-
-
|
|
68
|
-
-
|
|
72
|
+
- Repository: <https://github.com/ohah/zntc>
|
|
73
|
+
- Official docs: <https://ohah.github.io/zntc>
|
|
74
|
+
- Native build: [`@zntc/core`](https://www.npmjs.com/package/@zntc/core)
|
|
69
75
|
|
|
70
|
-
##
|
|
76
|
+
## License
|
|
71
77
|
|
|
72
|
-
MIT
|
|
78
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -7,17 +7,17 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
});
|
|
8
8
|
// ../shared/index.ts
|
|
9
9
|
var ES_TARGET_BITS = {
|
|
10
|
-
es5:
|
|
11
|
-
es2015:
|
|
12
|
-
es2016:
|
|
13
|
-
es2017:
|
|
14
|
-
es2018:
|
|
15
|
-
es2019:
|
|
16
|
-
es2020:
|
|
17
|
-
es2021:
|
|
18
|
-
es2022:
|
|
19
|
-
es2023:
|
|
20
|
-
es2024:
|
|
10
|
+
es5: 2147483647,
|
|
11
|
+
es2015: 1996486656,
|
|
12
|
+
es2016: 1996484608,
|
|
13
|
+
es2017: 1996480512,
|
|
14
|
+
es2018: 822067200,
|
|
15
|
+
es2019: 822050816,
|
|
16
|
+
es2020: 821952512,
|
|
17
|
+
es2021: 821821440,
|
|
18
|
+
es2022: 817889280,
|
|
19
|
+
es2023: 813694976,
|
|
20
|
+
es2024: 813694976,
|
|
21
21
|
es2025: 0,
|
|
22
22
|
esnext: 0
|
|
23
23
|
};
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export type Engine = 'chrome' | 'firefox' | 'safari' | 'edge' | 'node' | 'deno' | 'ios' | 'opera' | 'hermes';
|
|
13
13
|
/** compat.zig의 Feature enum과 동일 순서. bit 위치 = 배열 인덱스. */
|
|
14
|
-
export declare const FEATURES: readonly ["arrow", "class", "template_literal", "destructuring", "for_of", "spread", "object_extensions", "default_params", "block_scoping", "generator", "new_target", "exponentiation", "async_await", "object_spread", "optional_catch_binding", "nullish_coalescing", "optional_chaining", "logical_assignment", "class_static_block", "class_private_method", "class_private_field", "top_level_await", "hashbang", "using", "regex_sticky", "regex_dotall", "regex_named_groups", "unicode_brace_escape"];
|
|
14
|
+
export declare const FEATURES: readonly ["arrow", "class", "template_literal", "destructuring", "for_of", "spread", "object_extensions", "default_params", "block_scoping", "generator", "new_target", "exponentiation", "async_await", "object_spread", "optional_catch_binding", "nullish_coalescing", "optional_chaining", "logical_assignment", "class_static_block", "class_private_method", "class_private_field", "top_level_await", "hashbang", "using", "regex_sticky", "regex_dotall", "regex_named_groups", "unicode_brace_escape", "regex_duplicate_named_groups", "regex_modifiers", "regex_lookbehind"];
|
|
15
15
|
export type Feature = (typeof FEATURES)[number];
|
|
16
16
|
/**
|
|
17
17
|
* feature × engine → 최소 지원 버전 [major, minor].
|
package/package.json
CHANGED
package/zntc-bundler.wasm
CHANGED
|
Binary file
|
package/zntc.wasm
CHANGED
|
Binary file
|