@zntc/core 0.1.1 → 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 +35 -25
- package/bin/cli-flags.mjs +16 -0
- package/bin/rn-dev-input.mjs +11 -0
- package/bin/zntc.mjs +816 -48
- package/dist/core/index.d.cts +300 -3
- package/dist/core/index.d.ts +300 -3
- package/dist/core/src/config-loader.d.ts +1 -1
- package/dist/core/src/schema-allowlists.d.ts +2 -2
- package/dist/index.cjs +283 -82
- package/dist/index.js +361 -83
- package/dist/shared/compat-engines.d.ts +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1,54 +1,61 @@
|
|
|
1
1
|
# @zntc/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English · **[한국어](./README_KO.md)**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> The core of ZNTC (Zig Native Transpiler & Compiler) — a NAPI binding + JS API + `zntc` CLI for a JS / TS / Flow transpiler and bundler written in Zig.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/@zntc/core)
|
|
8
|
+
[](https://github.com/ohah/zntc/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
`@zntc/core` ships the native `.node` NAPI binding plus the `zntc` CLI for Node.js and Bun. It targets SWC / oxc-class performance and provides in-process (NAPI) calls, Vite / Rollup adapters, and a standalone CLI — covering transpile, bundle, and lightningcss-based CSS handling.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
8
13
|
|
|
9
14
|
```bash
|
|
10
15
|
bun add -D @zntc/core
|
|
11
|
-
#
|
|
16
|
+
# or
|
|
12
17
|
npm i -D @zntc/core
|
|
13
18
|
```
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
Platform-specific prebuilt binaries are installed automatically (linux / darwin / windows × x64 / arm64).
|
|
16
21
|
|
|
17
|
-
### Optional (
|
|
22
|
+
### Optional (as needed)
|
|
18
23
|
|
|
19
24
|
```bash
|
|
20
25
|
bun add -D browserslist core-js core-js-compat lightningcss
|
|
21
26
|
```
|
|
22
27
|
|
|
23
|
-
- `browserslist` / `core-js-compat` — `runtimePolyfills`
|
|
24
|
-
- `lightningcss` — CSS minify / nesting
|
|
28
|
+
- `browserslist` / `core-js-compat` — required for the `runtimePolyfills` option
|
|
29
|
+
- `lightningcss` — required for CSS minify / nesting
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
### CLI
|
|
27
34
|
|
|
28
35
|
```bash
|
|
29
|
-
#
|
|
36
|
+
# Transpile a single file
|
|
30
37
|
bunx zntc src/index.ts --outfile out.js
|
|
31
38
|
|
|
32
|
-
#
|
|
39
|
+
# Bundle (multi-entry)
|
|
33
40
|
bunx zntc --bundle src/index.ts --outfile dist/bundle.js --format=esm --target=node
|
|
34
41
|
```
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
See `bunx zntc --help` for the full list of options.
|
|
37
44
|
|
|
38
|
-
App
|
|
45
|
+
App mode (`bunx zntc dev / build / preview`) requires `@zntc/web` or `@zntc/react-native` to also be installed — see each package's README.
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
### JS / NAPI API
|
|
41
48
|
|
|
42
49
|
```ts
|
|
43
50
|
import { init, transpile, build } from '@zntc/core';
|
|
44
51
|
|
|
45
52
|
await init();
|
|
46
53
|
|
|
47
|
-
//
|
|
54
|
+
// Transpile a single file
|
|
48
55
|
const r = transpile('const x: number = 1;', { filename: 'input.ts' });
|
|
49
56
|
console.log(r.code); // "const x = 1;"
|
|
50
57
|
|
|
51
|
-
//
|
|
58
|
+
// Bundle (multi-file)
|
|
52
59
|
const out = await build({
|
|
53
60
|
entryPoints: ['src/index.ts'],
|
|
54
61
|
outdir: 'dist',
|
|
@@ -57,16 +64,19 @@ const out = await build({
|
|
|
57
64
|
});
|
|
58
65
|
```
|
|
59
66
|
|
|
60
|
-
|
|
67
|
+
## Related packages
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- [@zntc/web](https://npmjs.com/package/@zntc/web) — dev server + HMR overlay + postcss/sass
|
|
69
|
+
- [@zntc/web](https://npmjs.com/package/@zntc/web) — dev server + HMR overlay + postcss / sass
|
|
65
70
|
- [@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
|
|
67
|
-
- [@zntc/init](https://npmjs.com/package/@zntc/init) —
|
|
68
|
-
- [@zntc/vite-plugin](https://npmjs.com/package/@zntc/vite-plugin) — Vite
|
|
71
|
+
- [@zntc/wasm](https://npmjs.com/package/@zntc/wasm) — browser-side WASM build (instead of NAPI)
|
|
72
|
+
- [@zntc/init](https://npmjs.com/package/@zntc/init) — add ZNTC to an existing RN project
|
|
73
|
+
- [@zntc/vite-plugin](https://npmjs.com/package/@zntc/vite-plugin) — replace Vite's esbuild transform with ZNTC
|
|
74
|
+
|
|
75
|
+
## Documentation
|
|
76
|
+
|
|
77
|
+
- Repository: <https://github.com/ohah/zntc>
|
|
78
|
+
- Docs: <https://ohah.github.io/zntc>
|
|
69
79
|
|
|
70
|
-
##
|
|
80
|
+
## License
|
|
71
81
|
|
|
72
|
-
MIT
|
|
82
|
+
MIT
|
package/bin/cli-flags.mjs
CHANGED
|
@@ -52,6 +52,9 @@ export const FLAG_REGISTRY = [
|
|
|
52
52
|
{ kind: 'bool', flag: '--watch', target: 'watch', aliases: ['-w'] },
|
|
53
53
|
{ kind: 'bool', flag: '--watch-json', target: 'watchJson', extra: { watch: true } },
|
|
54
54
|
{ kind: 'bool', flag: '--open', target: 'open' },
|
|
55
|
+
// #4062 PR-C-3 — `zntc dev --lazy`: 동적 import 타겟을 on-demand 로 컴파일(미사용 라우트
|
|
56
|
+
// 미파싱·미emit). dev 서버가 브라우저 요청 시점에 그 청크만 빌드한다. env ZNTC_LAZY=1 와 동치.
|
|
57
|
+
{ kind: 'bool', flag: '--lazy', target: 'lazy' },
|
|
55
58
|
// RN CLI 호환 (#2605 audit P0)
|
|
56
59
|
{ kind: 'bool', flag: '--reset-cache', target: 'resetCache' },
|
|
57
60
|
{ kind: 'bool', flag: '--sourcemap-use-absolute-path', target: 'sourcemapUseAbsolutePath' },
|
|
@@ -81,6 +84,7 @@ export const FLAG_REGISTRY = [
|
|
|
81
84
|
{ kind: 'bool', flag: '--no-tree-shaking', target: 'treeShaking', value: false },
|
|
82
85
|
{ kind: 'bool', flag: '--no-scope-hoist', target: 'scopeHoist', value: false },
|
|
83
86
|
{ kind: 'bool', flag: '--no-emit-disk-sourcemap', target: 'emitDiskSourcemap', value: false },
|
|
87
|
+
{ kind: 'bool', flag: '--no-react-refresh', target: 'reactRefresh', value: false },
|
|
84
88
|
{ kind: 'bool', flag: '--analyze', target: 'analyze', extra: { metafile: 'meta.json' } },
|
|
85
89
|
{ kind: 'bool', flag: '--flow', target: 'flow' },
|
|
86
90
|
{ kind: 'bool', flag: '--experimental-decorators', target: 'experimentalDecorators' },
|
|
@@ -116,6 +120,7 @@ export const FLAG_REGISTRY = [
|
|
|
116
120
|
{ kind: 'string', flag: '--entry-names', target: 'entryNames', forms: ['equal'] },
|
|
117
121
|
{ kind: 'string', flag: '--chunk-names', target: 'chunkNames', forms: ['equal'] },
|
|
118
122
|
{ kind: 'string', flag: '--asset-names', target: 'assetNames', forms: ['equal'] },
|
|
123
|
+
{ kind: 'string', flag: '--css-names', target: 'cssNames', forms: ['equal'] },
|
|
119
124
|
{ kind: 'string', flag: '--quotes', target: 'quotes', forms: ['equal'] },
|
|
120
125
|
{ kind: 'string', flag: '--log-level', target: 'logLevel', forms: ['equal'] },
|
|
121
126
|
{ kind: 'string', flag: '--legal-comments', target: 'legalComments', forms: ['equal'] },
|
|
@@ -126,8 +131,14 @@ export const FLAG_REGISTRY = [
|
|
|
126
131
|
forms: ['equal'],
|
|
127
132
|
},
|
|
128
133
|
{ kind: 'string', flag: '--rn-platform', target: 'rnPlatform', forms: ['equal', 'pair'] },
|
|
134
|
+
// RN 버전 타겟 — platform=react-native 함의 + RN 문서 기준 버전별 정밀 다운레벨.
|
|
135
|
+
// 예: --rn-version=0.80 / --rn-version ">=0.74" / "<=0.84" / "==0.76"
|
|
136
|
+
{ kind: 'string', flag: '--rn-version', target: 'rnVersion', forms: ['equal', 'pair'] },
|
|
129
137
|
// #2540 PR #7 — RN preset 의 projectRoot. 기본 cwd, 사용자 monorepo root 지정 시 사용.
|
|
130
138
|
{ kind: 'string', flag: '--rn-project-root', target: 'rnProjectRoot', forms: ['equal', 'pair'] },
|
|
139
|
+
// #4438 디스크 캐시 opt-in: --disk-cache(활성, 기본 node_modules/.cache/zntc) / --cache-dir <path>.
|
|
140
|
+
{ kind: 'bool', flag: '--disk-cache', target: 'diskCache' },
|
|
141
|
+
{ kind: 'string', flag: '--cache-dir', target: 'cacheDir', forms: ['equal', 'pair'] },
|
|
131
142
|
// ─── RN CLI 호환 flag 매트릭스 (#2605 audit P0) ───
|
|
132
143
|
// `react-native bundle` / Metro CLI 의 standard flag 들 — `zntc bundle --platform=react-native`
|
|
133
144
|
// 가 dropin 으로 동작하기 위한 호환 layer. zntc 내부 옵션 (outfile 등) 과 별개로 받아 매핑.
|
|
@@ -183,6 +194,8 @@ export const FLAG_REGISTRY = [
|
|
|
183
194
|
{ kind: 'int', flag: '--line-limit', target: 'lineLimit', forms: ['equal'] },
|
|
184
195
|
// Rollup output.experimentalMinChunkSize 류 — 작은 common 청크 자동 병합 (bytes).
|
|
185
196
|
{ kind: 'int', flag: '--min-chunk-size', target: 'minChunkSize', forms: ['equal'] },
|
|
197
|
+
// #4466 — 이 byte 수 이하 asset 을 data URL 로 인라인 (0 = 끔). 기본 4096.
|
|
198
|
+
{ kind: 'int', flag: '--asset-inline-limit', target: 'assetInlineLimit', forms: ['equal'] },
|
|
186
199
|
// RN CLI 호환 — `--max-workers N` (Metro). zntc `--jobs` 와 의미 동일이므로 alias.
|
|
187
200
|
{ kind: 'int', flag: '--max-workers', target: 'jobs', forms: ['equal'] },
|
|
188
201
|
|
|
@@ -266,6 +279,9 @@ export const FLAG_REGISTRY = [
|
|
|
266
279
|
{ kind: 'string-bool', flag: '--emit-disk-sourcemap', target: 'emitDiskSourcemap' },
|
|
267
280
|
{ kind: 'string-bool', flag: '--use-define-for-class-fields', target: 'useDefineForClassFields' },
|
|
268
281
|
{ kind: 'string-bool', flag: '--tokenize', target: 'tokenize' },
|
|
282
|
+
// React Fast Refresh. `zntc dev` 는 기본 on(아래 dev 블록) — `--react-refresh=false`
|
|
283
|
+
// / `--no-react-refresh` 로 opt-out. NAPI BuildOptions.reactRefresh 와 동일 target.
|
|
284
|
+
{ kind: 'string-bool', flag: '--react-refresh', target: 'reactRefresh' },
|
|
269
285
|
|
|
270
286
|
// ─── `zntc verify` 전용. 다른 모드와 silent 충돌 방지를 위해 prefix 강제 ───
|
|
271
287
|
{ kind: 'int', flag: '--verify-timeout', target: 'verifyTimeout' },
|
package/bin/rn-dev-input.mjs
CHANGED
|
@@ -91,6 +91,9 @@ export function buildRnBundleExtra(config, opts = {}) {
|
|
|
91
91
|
fallback: resolver.extraNodeModules ?? undefined,
|
|
92
92
|
metroResolveRequest: resolver.resolveRequest ?? undefined,
|
|
93
93
|
babelTransformerPath: transformer.babelTransformerPath ?? undefined,
|
|
94
|
+
// HMR 위상 보존 게이트 명시 override (config top-level). 사용자가 "내 resolveRequest/
|
|
95
|
+
// transformer 는 결정적"임을 보장하면 true 로 보존 강제 — preset 의 보수적 자동판정을 덮어쓴다.
|
|
96
|
+
preserveSafePlugins: cfg.preserveSafePlugins ?? undefined,
|
|
94
97
|
polyfills: getSerializerPolyfills(serializer, opts),
|
|
95
98
|
extraVars: serializer.extraVars ?? undefined,
|
|
96
99
|
prelude: serializer.prelude ?? undefined,
|
|
@@ -118,6 +121,11 @@ function assignRnBuildOptionOverrides(out, config, opts = {}) {
|
|
|
118
121
|
} else if (opts.inlineDynamicImports === false || cfg.inlineDynamicImports === false) {
|
|
119
122
|
out.inlineDynamicImports = false;
|
|
120
123
|
}
|
|
124
|
+
// --rn-version: RN preset 경로(runRnBundle/runRnDev)에서도 버전별 정밀 매트릭스를 적용하도록
|
|
125
|
+
// override 로 forward. 없으면 preset 의 blunt fromHermesPreset 이 그대로 쓰인다.
|
|
126
|
+
if (typeof opts.rnVersion === 'string' || typeof cfg.rnVersion === 'string') {
|
|
127
|
+
out.rnVersion = opts.rnVersion ?? cfg.rnVersion;
|
|
128
|
+
}
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
/**
|
|
@@ -208,6 +216,9 @@ export function buildRnDevServerInput(opts, config) {
|
|
|
208
216
|
opts.minifySyntax ||
|
|
209
217
|
cfg.minify ||
|
|
210
218
|
false,
|
|
219
|
+
// watch 디바운스(ms) — CLI `--watch-delay`. native NAPI watch 의 debounce_ms 로 전달
|
|
220
|
+
// (buildRnBundleOptions → watch → getObjectUint32("watchDelay")). 기본 16.
|
|
221
|
+
watchDelay: opts.watchDelay,
|
|
211
222
|
extra: buildRnBundleExtra(cfg, opts),
|
|
212
223
|
override: buildRnBundleOverride({ config: cfg, opts }),
|
|
213
224
|
},
|