@zntc/core 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ohah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @zntc/core
2
+
3
+ ZNTC (Zig Native Transpiler & Compiler) 의 코어 — Zig 로 작성된 JS/TS/Flow 트랜스파일러 + 번들러의 Node.js NAPI 바인딩 + JS API + CLI.
4
+
5
+ SWC / oxc 와 동급 성능을 목표로, in-process 호출 (NAPI) + Vite/Rollup 어댑터 / 단독 CLI 모두 제공.
6
+
7
+ ## 설치
8
+
9
+ ```bash
10
+ bun add -D @zntc/core
11
+ # 또는
12
+ npm i -D @zntc/core
13
+ ```
14
+
15
+ 플랫폼별 prebuilt binary 가 함께 install 됨 (linux/darwin/windows × x64/arm64).
16
+
17
+ ### Optional (필요 시)
18
+
19
+ ```bash
20
+ bun add -D browserslist core-js core-js-compat lightningcss
21
+ ```
22
+
23
+ - `browserslist` / `core-js-compat` — `runtimePolyfills` 옵션 사용 시
24
+ - `lightningcss` — CSS minify / nesting 사용 시
25
+
26
+ ## CLI
27
+
28
+ ```bash
29
+ # transpile single file
30
+ bunx zntc src/index.ts --outfile out.js
31
+
32
+ # bundle (multi-entry)
33
+ bunx zntc --bundle src/index.ts --outfile dist/bundle.js --format=esm --target=node
34
+ ```
35
+
36
+ 전체 옵션: `bunx zntc --help`
37
+
38
+ App-mode (`bunx zntc dev / build / preview`) 는 `@zntc/web` 또는 `@zntc/react-native` 가 함께 install 되어야 동작 — 각 패키지 README 참조.
39
+
40
+ ## JS API
41
+
42
+ ```ts
43
+ import { init, transpile, build } from '@zntc/core';
44
+
45
+ await init();
46
+
47
+ // 단일 파일 transpile
48
+ const r = transpile('const x: number = 1;', { filename: 'input.ts' });
49
+ console.log(r.code); // "const x = 1;"
50
+
51
+ // bundle (multi-file)
52
+ const out = await build({
53
+ entryPoints: ['src/index.ts'],
54
+ outdir: 'dist',
55
+ format: 'esm',
56
+ target: 'es2020',
57
+ });
58
+ ```
59
+
60
+ 자세한 옵션: [docs/CONFIG.md](https://github.com/ohah/zts/blob/main/docs/CONFIG.md) · [docs/USAGE.md](https://github.com/ohah/zts/blob/main/docs/USAGE.md)
61
+
62
+ ## 관련 패키지
63
+
64
+ - [@zntc/web](https://npmjs.com/package/@zntc/web) — dev server + HMR overlay + postcss/sass
65
+ - [@zntc/react-native](https://npmjs.com/package/@zntc/react-native) — RN preset + Metro HMR adapter
66
+ - [@zntc/wasm](https://npmjs.com/package/@zntc/wasm) — browser-side WASM 빌드 (NAPI 대신)
67
+ - [@zntc/init](https://npmjs.com/package/@zntc/init) — 기존 RN 프로젝트에 ZNTC 도입
68
+ - [@zntc/vite-plugin](https://npmjs.com/package/@zntc/vite-plugin) — Vite 의 esbuild transform 을 ZNTC 로 교체
69
+
70
+ ## 라이센스
71
+
72
+ MIT.
package/bin/banner.mjs ADDED
@@ -0,0 +1,131 @@
1
+ // ZNTC CLI 시작 banner — ASCII 로고 + 그라디언트 + 박스.
2
+ // 시각 디자인은 packages/react-native/src/dev-server/logger.ts 의
3
+ // `printZntcRnBanner` 와 sync 유지 (양쪽 동시 수정).
4
+
5
+ const colors = {
6
+ reset: '\x1b[0m',
7
+ bold: '\x1b[1m',
8
+ gray: '\x1b[90m',
9
+ yellow: '\x1b[33m',
10
+ blue: '\x1b[34m',
11
+ magenta: '\x1b[35m',
12
+ cyan: '\x1b[36m',
13
+ // 16-color 엔 진짜 amber/orange 가 없어 bright-yellow→yellow→bright-red 로
14
+ // warm 근사. 256-color 는 미지원 터미널서 무색으로 떨어져 보편 16-color 사용.
15
+ brightYellow: '\x1b[93m',
16
+ brightRed: '\x1b[91m',
17
+ };
18
+
19
+ /**
20
+ * 색상(ANSI) 출력 사용 여부. NO_COLOR / FORCE_COLOR 관례(no-color.org,
21
+ * supports-color) 준수: `NO_COLOR` 가 비어있지 않으면 무조건 비활성,
22
+ * `FORCE_COLOR` 가 "0"/"false" 가 아니면(빈 문자열 포함 — supports-color 관례상
23
+ * 활성) 무조건 활성, 둘 다 없으면 TTY 여부.
24
+ */
25
+ export function shouldUseColor() {
26
+ const { NO_COLOR, FORCE_COLOR } = process.env;
27
+ if (NO_COLOR) return false;
28
+ if (FORCE_COLOR !== undefined) return FORCE_COLOR !== '0' && FORCE_COLOR !== 'false';
29
+ return Boolean(process.stdout.isTTY);
30
+ }
31
+
32
+ /**
33
+ * `zntc --color` / `--no-color` 를 NO_COLOR/FORCE_COLOR env 로 환원해 shouldUseColor()
34
+ * 단일 경로로 합류시킨다. 명시 flag 는 **반대편 env 를 제거**해 기존 env 보다
35
+ * 우선한다 (`NO_COLOR=1 zntc --color` → 색상 ON). `color` 미지정(undefined) 시
36
+ * env 무변경 → 기존 NO_COLOR/FORCE_COLOR/TTY 자동 판정 유지.
37
+ *
38
+ * @param {boolean | undefined} color opts.color (true=강제, false=억제, undefined=자동)
39
+ * @param {Record<string, string | undefined>} env 기본 process.env (테스트는 주입)
40
+ */
41
+ export function applyColorPreference(color, env = process.env) {
42
+ if (color === true) {
43
+ delete env.NO_COLOR;
44
+ env.FORCE_COLOR = '1';
45
+ } else if (color === false) {
46
+ delete env.FORCE_COLOR;
47
+ env.NO_COLOR = '1';
48
+ }
49
+ }
50
+
51
+ const BANNER_WIDTH = 59;
52
+
53
+ function bannerLine(content) {
54
+ // eslint-disable-next-line no-control-regex
55
+ const visibleLen = content.replace(/\x1b\[[0-9;]*m/g, '').length;
56
+ const padding = Math.max(0, BANNER_WIDTH - visibleLen);
57
+ const left = Math.floor(padding / 2);
58
+ const right = padding - left;
59
+ return `${colors.cyan} ║${colors.reset}${' '.repeat(left)}${content}${' '.repeat(right)}${colors.cyan}║${colors.reset}`;
60
+ }
61
+
62
+ // 지구라트 로고 — zntc-logo.svg / favicon 과 동일: 단 사이가 띈 적층 바
63
+ // (햄버거식). half-block `▀` 로 한 줄에 바+여백을 담아 절반 높이·컴팩트.
64
+ // ZNTC_GRADIENT 와 index 1:1. bannerLine 이 각 줄을 박스 중앙 정렬.
65
+ export const ZNTC_ASCII = [
66
+ '▀▀▀▀▀▀▀▀',
67
+ '▀▀▀▀▀▀▀▀▀▀▀▀',
68
+ '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
69
+ '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
70
+ '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
71
+ ];
72
+
73
+ export const ZNTC_GRADIENT = [
74
+ colors.brightYellow,
75
+ colors.brightYellow,
76
+ colors.yellow,
77
+ colors.brightRed,
78
+ colors.brightRed,
79
+ ];
80
+
81
+ // ZNTC_ASCII[i] 는 ZNTC_GRADIENT[i] 로 색칠 — desync 시 undefined 가
82
+ // visibleLen 을 오염시켜 줄 정렬이 깨진다. import 시점 fail-fast.
83
+ if (ZNTC_ASCII.length !== ZNTC_GRADIENT.length) {
84
+ throw new Error(
85
+ `ZNTC banner: ZNTC_ASCII(${ZNTC_ASCII.length}) / ZNTC_GRADIENT(${ZNTC_GRADIENT.length}) 길이 불일치`,
86
+ );
87
+ }
88
+
89
+ const TAGLINES = {
90
+ web: 'Lightning Fast Web Bundler',
91
+ rn: 'Lightning Fast React Native Bundler',
92
+ };
93
+
94
+ /**
95
+ * ZNTC 시작 banner 출력.
96
+ *
97
+ * - `silent: true` 또는 색상 비활성 환경(비-TTY / NO_COLOR / `--no-color`)에서는
98
+ * plain 한 줄 (`zntc <flavor> v0.1.0`) 만 출력. ASCII art 의 ANSI escape 가 CI
99
+ * 로그 / pipe 에서 노이즈가 되는 것을 막는다.
100
+ *
101
+ * @param {{ flavor: 'web' | 'rn', version?: string, silent?: boolean }} opts
102
+ */
103
+ export function printZntcBanner({ flavor, version, silent = false }) {
104
+ if (silent) return;
105
+ const tagline = TAGLINES[flavor];
106
+ if (!tagline) throw new Error(`printZntcBanner: unknown flavor "${flavor}"`);
107
+
108
+ const versionText = version ? `v${version}` : '';
109
+
110
+ if (!shouldUseColor()) {
111
+ console.log(`zntc ${flavor}${versionText ? ` ${versionText}` : ''} — ${tagline}`);
112
+ return;
113
+ }
114
+
115
+ const logoLines = ZNTC_ASCII.map((line, i) =>
116
+ bannerLine(`${colors.bold}${ZNTC_GRADIENT[i]}${line}${colors.reset}`),
117
+ );
118
+ const lines = [
119
+ '',
120
+ `${colors.cyan} ╔${'═'.repeat(BANNER_WIDTH)}╗${colors.reset}`,
121
+ bannerLine(''),
122
+ ...logoLines,
123
+ bannerLine(''),
124
+ bannerLine(`${colors.cyan}${tagline}${colors.reset}`),
125
+ bannerLine(`${colors.gray}${versionText}${colors.reset}`),
126
+ bannerLine(''),
127
+ `${colors.cyan} ╚${'═'.repeat(BANNER_WIDTH)}╝${colors.reset}`,
128
+ '',
129
+ ];
130
+ console.log(lines.join('\n'));
131
+ }