@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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Engine × Feature 지원 버전 테이블 (JS 미러).
3
+ *
4
+ * src/transformer/compat.zig의 compat_table을 거울 복사.
5
+ * browserslist → UnsupportedFeatures bitmask 계산에 사용.
6
+ *
7
+ * **주의**: compat.zig를 수정하면 이 파일도 함께 업데이트.
8
+ * 장기적으론 scripts/compat-from-kangax.ts를 확장해 자동 생성.
9
+ *
10
+ * Bit 레이아웃은 packages/shared/index.ts ES_TARGET_BITS와 동일 (0-27).
11
+ */
12
+ export type Engine = 'chrome' | 'firefox' | 'safari' | 'edge' | 'node' | 'deno' | 'ios' | 'opera' | 'hermes';
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"];
15
+ export type Feature = (typeof FEATURES)[number];
16
+ /**
17
+ * feature × engine → 최소 지원 버전 [major, minor].
18
+ * 엔진에 키가 없으면 "해당 엔진에서 미지원" (compat.zig의 보수적 해석).
19
+ */
20
+ export declare const SUPPORT: Partial<Record<Feature, Partial<Record<Engine, [number, number]>>>>;
21
+ export type EngineVersion = {
22
+ engine: Engine;
23
+ major: number;
24
+ minor: number;
25
+ };
26
+ /**
27
+ * 엔진 목록에 대해 unsupported feature bitmask 계산.
28
+ * 하나라도 미지원인 feature는 set (가장 보수적).
29
+ */
30
+ export declare function computeUnsupportedFromEngines(engines: EngineVersion[]): number;
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @zntc/shared — Types and utilities shared by @zntc/core and @zntc/wasm.
3
+ */
4
+ export type Target = 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'es2024' | 'es2025' | 'esnext';
5
+ export type Platform = 'browser' | 'node' | 'neutral' | 'react-native';
6
+ export interface TranspileOptions {
7
+ /** File path (used for extension detection, default: "input.ts"). */
8
+ filename?: string;
9
+ /** Generate a source map. */
10
+ sourcemap?: boolean;
11
+ /** Source map Debug ID (Sentry-compatible). */
12
+ sourcemapDebugIds?: boolean;
13
+ /** Include the original source in the source map (default: true). */
14
+ sourcesContent?: boolean;
15
+ /** Minify whitespace. */
16
+ minifyWhitespace?: boolean;
17
+ /** Minify identifiers. */
18
+ minifyIdentifiers?: boolean;
19
+ /** Minify syntax. */
20
+ minifySyntax?: boolean;
21
+ /** Full minification (whitespace + identifiers + syntax). */
22
+ minify?: boolean;
23
+ /** JSX runtime. `'preserve'` emits JSX unchanged — only TypeScript annotations
24
+ * are stripped. Use this to delegate JSX handling to a downstream tool (e.g.
25
+ * @vitejs/plugin-react, @preact/preset-vite, vite-plugin-solid). Equivalent to
26
+ * tsc `"jsx": "preserve"`. */
27
+ jsx?: 'classic' | 'automatic' | 'automatic-dev' | 'preserve';
28
+ /** classic-mode JSX factory (default: "React.createElement"). */
29
+ jsxFactory?: string;
30
+ /** classic-mode Fragment factory (default: "React.Fragment"). */
31
+ jsxFragment?: string;
32
+ /** automatic-mode import source (default: "react"). */
33
+ jsxImportSource?: string;
34
+ /** Allow JSX in .js files as well. */
35
+ jsxInJs?: boolean;
36
+ /**
37
+ * React Fast Refresh transform — registers components via
38
+ * `$RefreshReg$(_c, "Name")`. Equivalent to the SWC builtin
39
+ * `jsc.transform.react.refresh: true` / babel-plugin-react-refresh component
40
+ * registration. Used by loaders (rspack-loader, webpack/vite plugin) when
41
+ * enabled on the single-file transpile path.
42
+ *
43
+ * The default behavior is Metro-compatible (registration only, no hook
44
+ * signatures). The babel/SWC-equivalent hook signature emit is opt-in via
45
+ * `reactRefreshHookSignatures: true`. Defining the HMR runtime
46
+ * ($RefreshReg$/$RefreshSig$) is the consumer's responsibility.
47
+ */
48
+ reactRefresh?: boolean;
49
+ /**
50
+ * On top of `reactRefresh: true`, adds hook signature emit
51
+ * (`var _s = $RefreshSig$();` + `_s(Component, "sig")`). Equivalent to
52
+ * babel-plugin-react-refresh. Default false — preserves the Metro policy
53
+ * (no signatures).
54
+ *
55
+ * When enabled, the transformer scans hook calls inside function bodies to
56
+ * build the signature string, then emits a `_s(Comp, "sig")` call right after
57
+ * component registration. RN HMR keeps the default (false), so it is
58
+ * unaffected.
59
+ */
60
+ reactRefreshHookSignatures?: boolean;
61
+ /** Remove console.* calls. */
62
+ dropConsole?: boolean;
63
+ /** Remove debugger statements. */
64
+ dropDebugger?: boolean;
65
+ /** Escape non-ASCII to \uXXXX. */
66
+ asciiOnly?: boolean;
67
+ /** Do not escape non-ASCII. */
68
+ charsetUtf8?: boolean;
69
+ /** Strip Flow types. */
70
+ flow?: boolean;
71
+ /** legacy decorator transform. */
72
+ experimentalDecorators?: boolean;
73
+ /** decorator metadata emit */
74
+ emitDecoratorMetadata?: boolean;
75
+ /** Transform class fields → `constructor` this.x = v (default: true). */
76
+ useDefineForClassFields?: boolean;
77
+ /** verbatimModuleSyntax (TS 5.0+): when true, unused value imports are not elided. */
78
+ verbatimModuleSyntax?: boolean;
79
+ /**
80
+ * Path to tsconfig.json (file or directory). When set, compilerOptions are
81
+ * auto-loaded and merged. Fields set explicitly via JS options take
82
+ * precedence — only unspecified fields are filled from the tsconfig values.
83
+ * e.g. "./tsconfig.json" or "./project-dir".
84
+ */
85
+ tsconfigPath?: string;
86
+ /**
87
+ * Inline tsconfig JSON string (same meaning as esbuild's `tsconfigRaw`).
88
+ * When set, both `tsconfigPath` and autodiscovery are ignored — raw is the
89
+ * single source of truth. The Zig-side `tsconfig_merge` applies
90
+ * compilerOptions such as jsx/target/decorators directly.
91
+ */
92
+ tsconfigRaw?: string;
93
+ /** Module format. */
94
+ format?: 'esm' | 'cjs';
95
+ /** String quote style. */
96
+ quotes?: 'double' | 'single' | 'preserve';
97
+ /** Target platform. */
98
+ platform?: Platform;
99
+ /** ES downlevel target. */
100
+ target?: Target;
101
+ /**
102
+ * browserslist query (e.g. "last 2 versions", ">1%, not dead").
103
+ * Takes precedence over target when set. Resolved only in the core package
104
+ * (depends on browserslist).
105
+ */
106
+ browserslist?: string | string[];
107
+ /** The source map's sourceRoot field (default: empty string). */
108
+ sourceRoot?: string;
109
+ /**
110
+ * Identifier substitution pairs. `value` is raw JSON (strings must include
111
+ * the surrounding quotes).
112
+ * e.g. `[{ key: "process.env.NODE_ENV", value: "\"production\"" }]`
113
+ */
114
+ define?: Array<{
115
+ key: string;
116
+ value: string;
117
+ }>;
118
+ /**
119
+ * Pipeline early-exit point — for debug/profile. When set, all stages after
120
+ * the given phase are skipped and empty output is returned. Useful combined
121
+ * with `profile` to measure a specific phase's cost in isolation.
122
+ *
123
+ * - "scan": Scanner token drain only
124
+ * - "parse": after Parser AST construction
125
+ * - "semantic": after the Semantic analyzer
126
+ * - "transform": after the Transformer
127
+ * - "codegen": full run (same as the default behavior)
128
+ */
129
+ stopAfter?: 'scan' | 'parse' | 'semantic' | 'transform' | 'codegen';
130
+ }
131
+ export interface TranspileResult {
132
+ /** Transformed JavaScript code. */
133
+ code: string;
134
+ /** Source map JSON (when sourcemap: true). */
135
+ map?: string;
136
+ /**
137
+ * Full error text rendered in the same format as the CLI when semantic
138
+ * errors are present. tsc-compatible policy: code is still returned even
139
+ * when there are errors. Playgrounds/IDEs parse this field to display
140
+ * markers.
141
+ */
142
+ errors?: string;
143
+ }
144
+ export declare const ES_TARGET_BITS: Record<string, number>;
145
+ export declare function targetToUnsupported(target?: Target): number;
146
+ /**
147
+ * Narrows whether `value` is a plain object (non-null, not an array).
148
+ * Use this to narrow a value of unknown shape — such as a `JSON.parse` result
149
+ * or a dynamic config object — to `Record<string, unknown>`. Shared across
150
+ * functional config / workspace entries / tsconfigRaw validation, etc.
151
+ */
152
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
153
+ /**
154
+ * Pre-validates user-supplied `tsconfigRaw` input.
155
+ *
156
+ * NAPI (`napi_entry.zig` / `transpile.zig`) silently falls back to an empty
157
+ * TsConfig on raw parse failure, so an invalid raw passed through looks to the
158
+ * user as if the option were ignored. Called from both the CLI and JS API
159
+ * entry points so they uniformly throw the same explicit error
160
+ * (`failed to parse --tsconfig-raw: ...`). No-op when undefined.
161
+ */
162
+ export declare function validateTsConfigRaw(raw: string | undefined): void;
163
+ /**
164
+ * Serializes TranspileOptions into Zig `ConfigOptionsDto` JSON.
165
+ *
166
+ * - Default values are omitted (minimizes payload size).
167
+ * - enum keys match the Zig enum name (e.g. "react-native" → "react_native").
168
+ * - The browserslist resolution result can be injected as the
169
+ * `unsupportedOverride` number. When set, it takes precedence over the
170
+ * `target`-based fallback on the Zig side.
171
+ * - `define` is serialized as a `[{ key, value }]` array (compatible with Zig
172
+ * DefineEntry).
173
+ */
174
+ export declare function buildOptionsJson(opts?: TranspileOptions, unsupportedOverride?: number): string;
175
+ export type { Engine, EngineVersion, Feature } from './compat-engines';
176
+ export { computeUnsupportedFromEngines, FEATURES } from './compat-engines';
177
+ import type { EngineVersion } from './compat-engines';
178
+ /** browserslist result string ("chrome 100", "ios_saf 14.5") → EngineVersion. */
179
+ export declare function parseBrowserslistEntry(entry: string): EngineVersion | null;
180
+ /**
181
+ * browserslist result string array → unsupported bitmask.
182
+ * Unmappable engines (samsung, kaios, etc.) are ignored (engines ZNTC does not
183
+ * target).
184
+ */
185
+ export declare function browserslistToUnsupported(entries: string[]): number;
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@zntc/core",
3
+ "version": "0.1.0",
4
+ "description": "ZNTC native transpiler & compiler binding",
5
+ "keywords": [
6
+ "bundler",
7
+ "compiler",
8
+ "esbuild",
9
+ "flow",
10
+ "javascript",
11
+ "jsx",
12
+ "napi",
13
+ "oxc",
14
+ "swc",
15
+ "transpiler",
16
+ "tsx",
17
+ "typescript",
18
+ "zig",
19
+ "zntc"
20
+ ],
21
+ "homepage": "https://ohah.github.io/zntc",
22
+ "bugs": {
23
+ "url": "https://github.com/ohah/zntc/issues"
24
+ },
25
+ "license": "MIT",
26
+ "author": "ohah",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/ohah/zntc.git",
30
+ "directory": "packages/core"
31
+ },
32
+ "bin": {
33
+ "zntc": "./bin/zntc.mjs"
34
+ },
35
+ "source": "./index.ts",
36
+ "files": [
37
+ "dist/",
38
+ "bin/banner.mjs",
39
+ "bin/cli-flags.mjs",
40
+ "bin/rn-asset-copy.mjs",
41
+ "bin/rn-dev-input.mjs",
42
+ "bin/verify.mjs",
43
+ "bin/zntc.mjs"
44
+ ],
45
+ "type": "module",
46
+ "main": "dist/index.cjs",
47
+ "types": "dist/core/index.d.ts",
48
+ "exports": {
49
+ ".": {
50
+ "source": "./index.ts",
51
+ "import": {
52
+ "types": "./dist/core/index.d.ts",
53
+ "default": "./dist/index.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/core/index.d.cts",
57
+ "default": "./dist/index.cjs"
58
+ }
59
+ }
60
+ },
61
+ "scripts": {
62
+ "build:napi": "cd ../.. && zig build napi",
63
+ "build:js:esm": "bun build index.ts --outdir dist --format esm --target node",
64
+ "build:js:cjs": "node bin/zntc.mjs --bundle index.ts --outfile dist/index.cjs --format=cjs --platform=node --packages=external",
65
+ "build:js": "bun run build:js:esm && bun run build:js:cjs",
66
+ "build:dts": "bun x tsc -b && cp dist/core/index.d.ts dist/core/index.d.cts",
67
+ "build": "bun run build:js && bun run build:dts",
68
+ "build:local": "bun run build:napi && cp ../../zig-out/lib/zntc.node . && bun run build:js && bun run build:dts",
69
+ "postinstall": "[ -f ../../zig-out/lib/zntc.node ] && cp ../../zig-out/lib/zntc.node . || true",
70
+ "pretest": "bun run --cwd ../server build && bun run --cwd ../web build && bun run --cwd ../react-native build",
71
+ "test": "bun test --timeout 10000",
72
+ "prepublishOnly": "bun run build && bunx publint --strict --level error ."
73
+ },
74
+ "devDependencies": {
75
+ "@types/node": "^25.5.2",
76
+ "@zntc/test-helpers": "workspace:*"
77
+ },
78
+ "optionalDependencies": {
79
+ "@zntc/core-darwin-arm64": "0.1.0",
80
+ "@zntc/core-darwin-x64": "0.1.0",
81
+ "@zntc/core-linux-arm64-gnu": "0.1.0",
82
+ "@zntc/core-linux-arm64-musl": "0.1.0",
83
+ "@zntc/core-linux-x64-gnu": "0.1.0",
84
+ "@zntc/core-linux-x64-musl": "0.1.0",
85
+ "@zntc/core-win32-arm64-msvc": "0.1.0",
86
+ "@zntc/core-win32-ia32-msvc": "0.1.0",
87
+ "@zntc/core-win32-x64-msvc": "0.1.0",
88
+ "browserslist": "^4.24.0",
89
+ "core-js": "^3.49.0",
90
+ "core-js-compat": "^3.49.0",
91
+ "lightningcss": "^1.28.0",
92
+ "playwright": "^1.50.0"
93
+ },
94
+ "engines": {
95
+ "node": ">=24.0.0"
96
+ }
97
+ }