@zntc/vite-plugin 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 CHANGED
@@ -1,18 +1,25 @@
1
1
  # @zntc/vite-plugin
2
2
 
3
- Vite esbuild transform 을 ZNTC 로 교체하는 플러그인. TypeScript / JSX / Flow / decorators 변환을 ZNTC (Zig 기반) 가 담당하면서 Vite 의 dev server / HMR / plugin 생태계는 그대로 유지.
3
+ English · **[한국어](./README_KO.md)**
4
4
 
5
- ## 설치
5
+ > Replace Vite's esbuild transform with ZNTC — TypeScript / JSX / Flow / decorators handled by ZNTC (Zig-based), while Vite's dev server / HMR / plugin ecosystem stays intact.
6
+
7
+ [![npm](https://img.shields.io/npm/v/@zntc/vite-plugin.svg)](https://www.npmjs.com/package/@zntc/vite-plugin)
8
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ohah/zntc/blob/main/LICENSE)
9
+
10
+ This plugin swaps Vite's built-in esbuild transform step for [ZNTC](https://github.com/ohah/zntc), a single-pass transpiler written in Zig. TypeScript, JSX, Flow, and decorator transforms all flow through ZNTC, and you keep the rest of the Vite pipeline (dev server, HMR, plugins) untouched.
11
+
12
+ ## Installation
6
13
 
7
14
  ```bash
8
15
  bun add -D @zntc/vite-plugin @zntc/core
9
- # 또는
16
+ # or
10
17
  npm i -D @zntc/vite-plugin @zntc/core
11
18
  ```
12
19
 
13
- `@zntc/core` dependency 함께 따라옴 (NAPI binary 포함).
20
+ `@zntc/core` (which ships the native NAPI binary) is required alongside the plugin.
14
21
 
15
- ## 사용
22
+ ## Usage
16
23
 
17
24
  ```ts
18
25
  // vite.config.ts
@@ -21,37 +28,31 @@ import { zntc } from '@zntc/vite-plugin';
21
28
 
22
29
  export default defineConfig({
23
30
  plugins: [zntc()],
24
- // esbuild 자동 비활성화 (zntc .ts/.tsx/.jsx 변환 담당)
31
+ // Disable esbuild ZNTC handles .ts / .tsx / .jsx transforms.
25
32
  esbuild: false,
26
33
  });
27
34
  ```
28
35
 
29
- ## 옵션
36
+ ### Options
30
37
 
31
38
  ```ts
32
39
  zntc({
33
- include: /\.(tsx?|jsx)$/, // 변환할 파일 패턴 (default)
34
- exclude: /node_modules/, // 제외 패턴 (default)
35
- tsconfigCache: true, // tsconfig autodiscover 결과 캐시 (default: true)
40
+ include: /\.(tsx?|jsx)$/, // files to transform (default)
41
+ exclude: /node_modules/, // files to skip (default)
42
+ tsconfigCache: true, // cache tsconfig autodiscovery results (default: true)
36
43
  transpileOptions: {
37
- // ZNTC transpile 옵션 (target / jsx / decorators )
44
+ // ZNTC transpile options (target / jsx / decorators, etc.)
38
45
  target: 'es2020',
39
46
  jsx: 'automatic',
40
47
  },
41
48
  });
42
49
  ```
43
50
 
44
- ## Framework plugin 함께 쓰기
51
+ ### Using with framework plugins
45
52
 
46
- 대부분의 framework plugin (`@vitejs/plugin-react`, `@vitejs/plugin-vue`,
47
- `@sveltejs/vite-plugin-svelte`, `vite-plugin-solid`) 은 ZNTC 와 충돌 없이 같이
48
- 쓸 수 있습니다. 다만 **babel 기반으로 `.tsx` 를 자체적으로 다시 변환하는 plugin**
49
- — 대표적으로 `@preact/preset-vite` — 와 함께 쓰면 `.tsx` 가 둘 다 처리되면서
50
- 결과가 깨질 수 있습니다 (component body 의 JSX return 이 비어버림).
53
+ Most framework plugins (`@vitejs/plugin-react`, `@vitejs/plugin-vue`, `@sveltejs/vite-plugin-svelte`, `vite-plugin-solid`) work alongside ZNTC without conflict. The exception is a **Babel-based plugin that re-transforms `.tsx` on its own** — most notably `@preact/preset-vite` — where `.tsx` gets processed twice and the output can break (the JSX return inside a component body ends up empty).
51
54
 
52
- 경우 `jsx: 'preserve'` 옵션을 사용합니다 ZNTC `.tsx`/`.jsx` 처리를
53
- 건너뛰고 framework plugin 이 JSX + TS 까지 모두 담당합니다. `.ts` 는 그대로
54
- ZNTC 가 처리.
55
+ In that case set `jsx: 'preserve'`. ZNTC then skips `.tsx` / `.jsx` and lets the framework plugin handle both JSX and TS, while `.ts` is still processed by ZNTC.
55
56
 
56
57
  ```ts
57
58
  // preact + vite
@@ -64,13 +65,17 @@ export default defineConfig({
64
65
  });
65
66
  ```
66
67
 
67
- `jsx: 'preserve'` tsc `"jsx": "preserve"` 동등한 의미 JSX 변환을
68
- downstream tool 에 위임합니다.
68
+ `jsx: 'preserve'` is equivalent to tsc's `"jsx": "preserve"` it delegates JSX transformation to a downstream tool.
69
+
70
+ ### Peer requirements
71
+
72
+ - `vite >= 5.0.0` (8.x recommended)
69
73
 
70
- ## peer
74
+ ## Documentation
71
75
 
72
- - `vite >= 5.0.0` (8.x 권장)
76
+ - Monorepo: <https://github.com/ohah/zntc>
77
+ - Docs: <https://ohah.github.io/zntc>
73
78
 
74
- ## 라이센스
79
+ ## License
75
80
 
76
- MIT.
81
+ MIT
package/dist/index.d.ts CHANGED
@@ -37,5 +37,11 @@ export interface ZntcPluginOptions {
37
37
  */
38
38
  tsconfigCache?: boolean;
39
39
  }
40
+ /**
41
+ * Vite 5 이하에서만 esbuild 변환을 비활성화해야 하는지 판단(Vite 6+ 는 Rolldown 기반이라 불필요).
42
+ * version 문자열의 major 세그먼트만 robust 파싱 — `parseInt('6.0.0-beta')` 류 취약성 회피, 파싱
43
+ * 불가 시 보수적으로 false(비활성화 안 함). 순수 함수로 분리해 단위 테스트 가능.
44
+ */
45
+ export declare function shouldDisableEsbuildForVite(version: string): boolean;
40
46
  export declare function zntc(options?: ZntcPluginOptions): Plugin;
41
47
  export default zntc;
package/dist/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  import { TsconfigCache, init, transpile } from "@zntc/core";
2
2
  //#region index.ts
3
3
  const DEFAULT_INCLUDE = /\.(tsx?|jsx)$/,DEFAULT_EXCLUDE = /node_modules/,JSX_EXT_PATTERN = /\.[jt]sx$/;
4
+ function shouldDisableEsbuildForVite(version) {
5
+ const major = Number.parseInt(version.split(".", 1)[0] ?? "", 10);
6
+ return Number.isFinite(major) && major < 6;
7
+ }
4
8
  function zntc(options={}) {
5
9
  const include = options.include ?? DEFAULT_INCLUDE,exclude = options.exclude ?? DEFAULT_EXCLUDE,transpileOpts = options.transpileOptions ?? {},useTsconfigCache = options.tsconfigCache ?? true;
6
10
  let initialized = false,cache;
7
- return { name: "@zntc/vite-plugin", config(_,_env) {
11
+ return { name: "@zntc/vite-plugin", async config(_,_env) {
8
12
  try {
9
- const viteVersion = parseInt(require("vite/package.json").version);
10
- if (viteVersion < 6)return { esbuild: false };
13
+ const { version:version } = await import("vite");
14
+ if (shouldDisableEsbuildForVite(version))return { esbuild: false };
11
15
  } catch {
12
16
  }
13
17
  return {};
@@ -30,5 +34,5 @@ function zntc(options={}) {
30
34
  } };
31
35
  }
32
36
 
33
- export { zntc, zntc as default };
37
+ export { shouldDisableEsbuildForVite, zntc, zntc as default };
34
38
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zntc/vite-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Use ZNTC as the TypeScript/JSX transformer in Vite (replaces esbuild)",
5
5
  "keywords": [
6
6
  "esbuild",
@@ -45,7 +45,7 @@
45
45
  "prepublishOnly": "bun run build && bunx publint --strict --level error ."
46
46
  },
47
47
  "dependencies": {
48
- "@zntc/core": "0.1.2"
48
+ "@zntc/core": "0.1.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^25.5.2",