@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 +21 -0
- package/README.md +72 -0
- package/bin/banner.mjs +131 -0
- package/bin/cli-flags.mjs +473 -0
- package/bin/rn-asset-copy.mjs +151 -0
- package/bin/rn-dev-input.mjs +225 -0
- package/bin/verify.mjs +190 -0
- package/bin/zntc.mjs +2327 -0
- package/dist/core/index.d.cts +1311 -0
- package/dist/core/index.d.ts +1311 -0
- package/dist/core/src/config-loader.d.ts +157 -0
- package/dist/core/src/load-env.d.ts +31 -0
- package/dist/core/src/platforms.d.ts +35 -0
- package/dist/core/src/runtime-polyfills.d.ts +94 -0
- package/dist/core/src/schema-allowlists.d.ts +17 -0
- package/dist/core/src/typo-suggest.d.ts +38 -0
- package/dist/core/src/workspace.d.ts +185 -0
- package/dist/index.cjs +1608 -0
- package/dist/index.js +3637 -0
- package/dist/shared/compat-engines.d.ts +30 -0
- package/dist/shared/index.d.ts +185 -0
- package/package.json +97 -0
|
@@ -0,0 +1,1311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zntc/core — Native NAPI bindings for the ZNTC TypeScript transpiler.
|
|
3
|
+
*
|
|
4
|
+
* A NAPI native module that supports Node.js, Bun, and Deno.
|
|
5
|
+
* Returns results directly on the JS heap with no global state.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { transpile } from "@zntc/core";
|
|
10
|
+
* const result = transpile("const x: number = 1;", { filename: "input.ts" });
|
|
11
|
+
* console.log(result.code);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type { Target, Platform, TranspileOptions, TranspileResult } from '../shared/index';
|
|
15
|
+
import type { TranspileOptions, TranspileResult } from '../shared/index';
|
|
16
|
+
import { isPlainObject, validateTsConfigRaw } from '../shared/index';
|
|
17
|
+
import { type RuntimePolyfillOptions, type RuntimePolyfillsOption } from './src/runtime-polyfills.ts';
|
|
18
|
+
export { isPlainObject, validateTsConfigRaw };
|
|
19
|
+
export type { RuntimePolyfillOptions, RuntimePolyfillsOption };
|
|
20
|
+
interface OutputFile {
|
|
21
|
+
path: string;
|
|
22
|
+
/** Raw byte content. Exposed by NAPI via `napi_create_buffer_copy` — avoids
|
|
23
|
+
* the string copy + UTF-8 validation cost (safe for binary asset / CSS bundle
|
|
24
|
+
* / source map alike). Equivalent to esbuild OutputFile.contents. */
|
|
25
|
+
contents: Uint8Array;
|
|
26
|
+
/** Lazy UTF-8 decode of `contents`. Decoded once on first access and cached.
|
|
27
|
+
* Equivalent to esbuild OutputFile.text. */
|
|
28
|
+
readonly text: string;
|
|
29
|
+
/** When code splitting, the absolute paths of the modules in this chunk
|
|
30
|
+
* (compatible with rolldown `chunk.moduleIds`). Empty array for a single
|
|
31
|
+
* bundle / asset output. */
|
|
32
|
+
moduleIds?: string[];
|
|
33
|
+
/** The list of symbol names this chunk exports (for cross-chunk validation). */
|
|
34
|
+
exports?: string[];
|
|
35
|
+
/** The final filenames of the other chunks this chunk imports (compatible
|
|
36
|
+
* with rolldown `chunk.imports`). Paths are resolved down to the
|
|
37
|
+
* content-hash. */
|
|
38
|
+
imports?: string[];
|
|
39
|
+
}
|
|
40
|
+
interface Diagnostic {
|
|
41
|
+
text: string;
|
|
42
|
+
code?: string;
|
|
43
|
+
location?: {
|
|
44
|
+
file: string;
|
|
45
|
+
line?: number;
|
|
46
|
+
column?: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* RN AssetRegistry.registerAsset metadata — only exposes the fields actually
|
|
51
|
+
* read by the `rn-asset-copy` release copy path. width/height/hash are passed
|
|
52
|
+
* directly to the RN runtime via the in-bundle `registerAsset({...})` call, so
|
|
53
|
+
* they are not duplicated on this side channel.
|
|
54
|
+
*/
|
|
55
|
+
export interface RnAssetMetadata {
|
|
56
|
+
httpServerLocation: string;
|
|
57
|
+
fileSystemLocation: string;
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
scales: number[];
|
|
61
|
+
}
|
|
62
|
+
interface NativeTsconfigCacheHandle {
|
|
63
|
+
clear(): void;
|
|
64
|
+
size(): number;
|
|
65
|
+
}
|
|
66
|
+
export interface TokenizeToken {
|
|
67
|
+
kind: string;
|
|
68
|
+
text: string;
|
|
69
|
+
start: number;
|
|
70
|
+
end: number;
|
|
71
|
+
line: number;
|
|
72
|
+
column: number;
|
|
73
|
+
hasNewlineBefore: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface TokenizeOptions {
|
|
76
|
+
filename?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `zntc.config.{ts,js}` 의 타입 체크 / 자동완성을 위한 identity helper.
|
|
80
|
+
*
|
|
81
|
+
* 객체 config 와 함수형 config 를 모두 지원한다.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { defineConfig } from "@zntc/core";
|
|
86
|
+
*
|
|
87
|
+
* export default defineConfig({
|
|
88
|
+
* entryPoints: ["src/index.ts"],
|
|
89
|
+
* format: "esm",
|
|
90
|
+
* sourcemap: true,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { defineConfig } from "@zntc/core";
|
|
97
|
+
*
|
|
98
|
+
* export default defineConfig(({ command, mode, env }) => {
|
|
99
|
+
* const production = command === "bundle" && mode === "production";
|
|
100
|
+
*
|
|
101
|
+
* return {
|
|
102
|
+
* entryPoints: ["src/index.ts"],
|
|
103
|
+
* minify: production,
|
|
104
|
+
* define: {
|
|
105
|
+
* __APP_ENV__: JSON.stringify(env.ZNTC_APP_ENV ?? mode),
|
|
106
|
+
* },
|
|
107
|
+
* };
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function defineConfig<T extends UserConfigInput>(config: T): T;
|
|
112
|
+
export { defaultConfigEnv, findConfigPath, findModeConfigPath, importAndResolveDefault, loadConfig, loadModuleDefault, mergeUserConfigs, } from './src/config-loader.ts';
|
|
113
|
+
export type { ConfigEnv, ModuleKind, UserConfig, UserConfigFn, UserConfigInput, } from './src/config-loader.ts';
|
|
114
|
+
export { envToDefine, loadEnv } from './src/load-env.ts';
|
|
115
|
+
export { KNOWN_CONFIG_KEYS, suggestKey, warnUnknownKeys } from './src/typo-suggest.ts';
|
|
116
|
+
export { defineWorkspace, filterWorkspaces, findWorkspacePath, identifyWorkspaceEntries, loadIdentifiedConfig, loadWorkspace, WORKSPACE_EXT_PRIORITY, } from './src/workspace.ts';
|
|
117
|
+
export type { IdentifiedWorkspace, Workspace, WorkspaceEntry, WorkspaceEntryInline, WorkspaceEntryPath, WorkspaceFn, WorkspaceInput, } from './src/workspace.ts';
|
|
118
|
+
import type { UserConfigInput } from './src/config-loader.ts';
|
|
119
|
+
/**
|
|
120
|
+
* Loads the NAPI addon — called automatically on the first invocation of a
|
|
121
|
+
* native API such as `transpile()`/`build()`/`watch()`, so calling it
|
|
122
|
+
* explicitly is optional. Call it directly only when you need an addon path
|
|
123
|
+
* override (e.g. a custom prebuild). No-op if already loaded.
|
|
124
|
+
*/
|
|
125
|
+
export declare function init(addonPath?: string): void;
|
|
126
|
+
/**
|
|
127
|
+
* Cache of tsconfig autodiscovery walk results (#2367). A NAPI consumer that
|
|
128
|
+
* repeatedly transpiles many files in-process (Vite/Rollup plugin, etc.)
|
|
129
|
+
* creates one instance and reuses it across transpile calls → saves 5–10 fs
|
|
130
|
+
* syscalls per file.
|
|
131
|
+
*
|
|
132
|
+
* Passed via the `cache` option of `transpile()`. When `tsconfigPath` /
|
|
133
|
+
* `tsconfigRaw` is specified, the cache is bypassed and the explicit value is
|
|
134
|
+
* used. The instance is cleaned up automatically on GC — explicit dispose is
|
|
135
|
+
* not required.
|
|
136
|
+
*
|
|
137
|
+
* Aligned with rolldown `TsconfigCache` (the design is an N-slot HashMap, not
|
|
138
|
+
* a single slot).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* const cache = new TsconfigCache();
|
|
142
|
+
* for (const file of files) {
|
|
143
|
+
* transpile(source, { filename: file, cache });
|
|
144
|
+
* }
|
|
145
|
+
*/
|
|
146
|
+
export declare class TsconfigCache {
|
|
147
|
+
/** @internal native handle — unwrapped and used by `transpile()`. Do not use externally. */
|
|
148
|
+
private readonly _handle;
|
|
149
|
+
constructor();
|
|
150
|
+
/** Reclaims all cache entries and internal string memory. The instance can be reused. */
|
|
151
|
+
clear(): void;
|
|
152
|
+
/** Current number of cached entries (testing / debugging). */
|
|
153
|
+
get size(): number;
|
|
154
|
+
/**
|
|
155
|
+
* Explicit Resource Management (TC39 Stage 4) — `using cache = new TsconfigCache();`
|
|
156
|
+
* automatically calls `clear()` on scope exit. The memory itself is reclaimed
|
|
157
|
+
* by the GC finalizer, so this method only "empties the cache" (the instance
|
|
158
|
+
* can be reused).
|
|
159
|
+
*/
|
|
160
|
+
[Symbol.dispose](): void;
|
|
161
|
+
/** Used by transpile() to extract the native handle — do not use externally (private escape hatch). */
|
|
162
|
+
/** @internal */
|
|
163
|
+
static _unwrap(c: TsconfigCache): NativeTsconfigCacheHandle;
|
|
164
|
+
}
|
|
165
|
+
export declare function transpile(source: string, options?: TranspileOptions & {
|
|
166
|
+
cache?: TsconfigCache;
|
|
167
|
+
}): TranspileResult;
|
|
168
|
+
export declare function tokenize(source: string, options?: TokenizeOptions): TokenizeToken[];
|
|
169
|
+
export declare function configureProfile(profile: string[], level?: 'summary' | 'detailed' | 'per-module' | 'per-pass'): void;
|
|
170
|
+
export declare function profileReport(format?: 'table' | 'tree' | 'json' | 'csv'): string;
|
|
171
|
+
export type { OutputFile, Diagnostic };
|
|
172
|
+
/** Return value of `meta.getModuleInfo(id)` in Rollup `manualChunks(id, meta)`. */
|
|
173
|
+
export interface ManualChunksModuleInfo {
|
|
174
|
+
id: string;
|
|
175
|
+
isEntry: boolean;
|
|
176
|
+
/** A module not included in the bundle because it matched an `external`
|
|
177
|
+
* pattern. No AST/source — exposed only as a first-class graph traversal
|
|
178
|
+
* node. */
|
|
179
|
+
isExternal: boolean;
|
|
180
|
+
/** Whether the module may have side effects (compatible with Rollup
|
|
181
|
+
* `hasModuleSideEffects`). Determined by the `package.json` `sideEffects`
|
|
182
|
+
* field or the `treeShaking.moduleSideEffects` option. When `false`, the
|
|
183
|
+
* tree-shaker may remove it if unused. */
|
|
184
|
+
hasModuleSideEffects: boolean;
|
|
185
|
+
/** Module source code (compatible with Rollup `code`).
|
|
186
|
+
* null for external / asset / unparsed modules. Also null if UTF-8 decoding
|
|
187
|
+
* fails. */
|
|
188
|
+
code: string | null;
|
|
189
|
+
/** Whether the module is included in the bundle after tree-shaking
|
|
190
|
+
* (compatible with Rollup `isIncluded`). When `treeShaking: false`, all
|
|
191
|
+
* modules may appear false — it is a mirror flag on Module, so it stays at
|
|
192
|
+
* its default if the tree-shaker does not run. */
|
|
193
|
+
isIncluded: boolean;
|
|
194
|
+
/** The list of names this module exports (compatible with Rollup `exports`).
|
|
195
|
+
* Includes both default and re-export stars. Empty array for external (the
|
|
196
|
+
* graph has no export info). */
|
|
197
|
+
exports: string[];
|
|
198
|
+
/** Synthetic named exports defined by a plugin (compatible with Rollup
|
|
199
|
+
* `syntheticNamedExports`). Always false until the ZNTC plugin context API
|
|
200
|
+
* extension (#1880). */
|
|
201
|
+
syntheticNamedExports: boolean;
|
|
202
|
+
/** Result of the `implicitlyLoadedAfterOneOf` option of `this.emitFile`
|
|
203
|
+
* (Rollup-compatible). Always an empty array until the ZNTC plugin context
|
|
204
|
+
* API (#1880). */
|
|
205
|
+
implicitlyLoadedAfterOneOf: string[];
|
|
206
|
+
/** The opposite direction — modules that must be loaded after this module is
|
|
207
|
+
* implicitly loaded. */
|
|
208
|
+
implicitlyLoadedBefore: string[];
|
|
209
|
+
/** Modules that statically import this module. External modules are also
|
|
210
|
+
* included in the importer list (when itself is external, an in-graph module
|
|
211
|
+
* is the importer). */
|
|
212
|
+
importers: string[];
|
|
213
|
+
/** Modules that dynamically import (`import()`) this module. */
|
|
214
|
+
dynamicImporters: string[];
|
|
215
|
+
/** Modules that this module statically imports. Includes external modules. */
|
|
216
|
+
importedIds: string[];
|
|
217
|
+
/** Modules that this module dynamically imports (`import()`). Includes
|
|
218
|
+
* external modules. */
|
|
219
|
+
dynamicallyImportedIds: string[];
|
|
220
|
+
}
|
|
221
|
+
/** The second argument of the `manualChunks` callback — module graph topology lookup. */
|
|
222
|
+
export interface ManualChunksMeta {
|
|
223
|
+
/** Look up module info by `id`. null if not found. */
|
|
224
|
+
getModuleInfo(id: string): ManualChunksModuleInfo | null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The `compiler` namespace — per-library 1st-party transform settings
|
|
228
|
+
* (`@next/swc`-compatible surface).
|
|
229
|
+
*
|
|
230
|
+
* The 1st-party counterpart to `babel-plugin-styled-components` /
|
|
231
|
+
* `@emotion/babel-plugin`. Enabling the option alone, without registering a
|
|
232
|
+
* plugin, produces the same transform result.
|
|
233
|
+
*/
|
|
234
|
+
export interface CompilerOptions {
|
|
235
|
+
/**
|
|
236
|
+
* styled-components 1st-party transform.
|
|
237
|
+
* Same transform intent as `babel-plugin-styled-components` /
|
|
238
|
+
* `@swc/plugin-styled-components`.
|
|
239
|
+
*/
|
|
240
|
+
styledComponents?: boolean | StyledComponentsOptions;
|
|
241
|
+
/**
|
|
242
|
+
* emotion 1st-party transform.
|
|
243
|
+
* Same transform intent as `@emotion/babel-plugin` / `@swc/plugin-emotion`.
|
|
244
|
+
*/
|
|
245
|
+
emotion?: boolean | EmotionOptions;
|
|
246
|
+
}
|
|
247
|
+
/** styled-components transform options (`babel-plugin-styled-components`-compatible). */
|
|
248
|
+
export interface StyledComponentsOptions {
|
|
249
|
+
/** Auto-assign a displayName for devtools display (default: NODE_ENV !== "production"). */
|
|
250
|
+
displayName?: boolean;
|
|
251
|
+
/** Deterministic componentId hash for stable SSR hydration (default: true). */
|
|
252
|
+
ssr?: boolean;
|
|
253
|
+
/** Include the file name in componentId (default: true). */
|
|
254
|
+
fileName?: boolean;
|
|
255
|
+
/** Minify CSS whitespace (default: true). */
|
|
256
|
+
minify?: boolean;
|
|
257
|
+
/** Recognize template literals downleveled to modern JS (default: true). */
|
|
258
|
+
transpileTemplateLiterals?: boolean;
|
|
259
|
+
/** Tell the minifier that styled.X is side-effect-free (default: false). */
|
|
260
|
+
pure?: boolean;
|
|
261
|
+
/** Namespace prefix for displayName / componentId — isolates multiple styled instances. */
|
|
262
|
+
namespace?: string;
|
|
263
|
+
/**
|
|
264
|
+
* List that makes the displayName prefix fall back to the parent dir when
|
|
265
|
+
* the basename is meaningless (default: `["index"]`). Equivalent to the
|
|
266
|
+
* option of the same name in babel-plugin-styled-components.
|
|
267
|
+
*/
|
|
268
|
+
meaninglessFileNames?: string[];
|
|
269
|
+
/**
|
|
270
|
+
* List of import sources to recognize as vendored forks (e.g. `@my-org/styled`,
|
|
271
|
+
* `@my-org/*`, `@{my-org,co}/*`). picomatch-compatible glob — `*`, `?`,
|
|
272
|
+
* `[abc]`/`[a-z]`/`[!abc]`, `{a,b}` (nesting allowed).
|
|
273
|
+
*/
|
|
274
|
+
topLevelImportPaths?: string[];
|
|
275
|
+
/**
|
|
276
|
+
* Extract the `<div css={...}>` JSX prop into a module-level styled component
|
|
277
|
+
* (default: false). Opt-in, unlike babel-plugin-styled-components which
|
|
278
|
+
* defaults to true. Supports intrinsic / custom (including
|
|
279
|
+
* jsx_member_expression) / `css\`\`` template / object form / `${expr}`
|
|
280
|
+
* dynamic prop forwarding. On auto-inject, a `styled` binding collision is
|
|
281
|
+
* automatically mangled to `_styled` / `_styled2`.
|
|
282
|
+
*/
|
|
283
|
+
cssProp?: boolean;
|
|
284
|
+
/** Emit the [meta] marker (default: false). */
|
|
285
|
+
meta?: boolean;
|
|
286
|
+
}
|
|
287
|
+
/** emotion transform options (`@emotion/babel-plugin`-compatible). */
|
|
288
|
+
export interface EmotionOptions {
|
|
289
|
+
/** Generate a sourceMap (default: true). */
|
|
290
|
+
sourceMap?: boolean;
|
|
291
|
+
/** Auto-assign the variable name as the CSS class label (default: "dev-only"). `false` disables autoLabel. */
|
|
292
|
+
autoLabel?: 'always' | 'dev-only' | 'never' | boolean;
|
|
293
|
+
/** label format string. tokens: `[local]`, `[filename]`, `[dirname]` (default: "[local]") */
|
|
294
|
+
labelFormat?: string;
|
|
295
|
+
/** Import path alias — for using a fork or vendored emotion. */
|
|
296
|
+
importMap?: Record<string, Record<string, {
|
|
297
|
+
canonicalImport: [string, string];
|
|
298
|
+
}>>;
|
|
299
|
+
}
|
|
300
|
+
/** Vite-style dev server options used by `zntc dev` / `zntc --serve`. */
|
|
301
|
+
export interface DevServerOptions {
|
|
302
|
+
/** Port to listen on. CLI `--port` overrides this value. */
|
|
303
|
+
port?: number;
|
|
304
|
+
/** Host to listen on. `true` means `0.0.0.0`, matching Vite. CLI `--host` overrides this value. */
|
|
305
|
+
host?: string | boolean;
|
|
306
|
+
/** Exit if the configured port is already in use instead of trying the next port. */
|
|
307
|
+
strictPort?: boolean;
|
|
308
|
+
/** Open the served URL in the browser after startup. CLI `--open` overrides this value. */
|
|
309
|
+
open?: boolean;
|
|
310
|
+
}
|
|
311
|
+
type BuildTarget = import('../shared/index').Target | (string & {});
|
|
312
|
+
/**
|
|
313
|
+
* Common build options shared by all platforms.
|
|
314
|
+
* The `platform` + `target` combination is constrained as a discriminated
|
|
315
|
+
* union in `BuildOptions`.
|
|
316
|
+
*/
|
|
317
|
+
/** Module Federation `shared` dependency options (a subset of MF2 `SharedConfig`, #3318). */
|
|
318
|
+
export interface MfSharedConfig {
|
|
319
|
+
singleton?: boolean;
|
|
320
|
+
requiredVersion?: string;
|
|
321
|
+
strictVersion?: boolean;
|
|
322
|
+
eager?: boolean;
|
|
323
|
+
}
|
|
324
|
+
/** Module Federation config block (#3318 P1-0). A record shape isomorphic to
|
|
325
|
+
* the webpack/rspack `ModuleFederationPlugin` — targeting the
|
|
326
|
+
* `@module-federation/runtime` contract. **P1-0 is zntc.config parsing &
|
|
327
|
+
* validation only** (emit not wired up; consumed in P1-1+; build()/NAPI mf
|
|
328
|
+
* extraction is also P1-1+). The `shared` array/boolean shorthand is P1-1+ —
|
|
329
|
+
* P1-0 only supports record-of-object. */
|
|
330
|
+
export interface ModuleFederationConfig {
|
|
331
|
+
/** remote identifier. Required when using `exposes`/`remotes`. */
|
|
332
|
+
name?: string;
|
|
333
|
+
/** Exposed modules: `{ "./Widget": "./src/Widget.tsx" }`. */
|
|
334
|
+
exposes?: Record<string, string>;
|
|
335
|
+
/** Consumed remotes: `{ remoteA: "remoteA@https://…/mf-manifest.json" }`. */
|
|
336
|
+
remotes?: Record<string, string>;
|
|
337
|
+
/** Shared dependencies: `{ react: { singleton: true, requiredVersion: "^18" } }`.
|
|
338
|
+
* (P1-0: record-of-object only. boolean/array shorthand is P1-1+.) */
|
|
339
|
+
shared?: Record<string, MfSharedConfig>;
|
|
340
|
+
/** share scope name (default `"default"`). */
|
|
341
|
+
shareScope?: string;
|
|
342
|
+
}
|
|
343
|
+
interface BuildOptionsCommon {
|
|
344
|
+
entryPoints: string[];
|
|
345
|
+
format?: 'esm' | 'cjs' | 'iife' | 'umd' | 'amd';
|
|
346
|
+
external?: string[];
|
|
347
|
+
minify?: boolean;
|
|
348
|
+
minifyWhitespace?: boolean;
|
|
349
|
+
minifyIdentifiers?: boolean;
|
|
350
|
+
minifySyntax?: boolean;
|
|
351
|
+
splitting?: boolean;
|
|
352
|
+
/** Rollup `output.inlineDynamicImports` — absorbs the dynamic import target
|
|
353
|
+
* into the importer's chunk and rewrites the `import("./x")` call into an
|
|
354
|
+
* `__esm` wrapper init/exports call. Combine with `splitting: true`. The
|
|
355
|
+
* resulting bundle is runnable as a single file.
|
|
356
|
+
*
|
|
357
|
+
* Preservation guarantees:
|
|
358
|
+
* - namespace identity: `(await import("./x")) === (await import("./x"))`
|
|
359
|
+
* - top-level side effects run once (cached)
|
|
360
|
+
* - live bindings (if the module mutates an `export let`, the change is
|
|
361
|
+
* reflected on the caller side too)
|
|
362
|
+
*/
|
|
363
|
+
inlineDynamicImports?: boolean;
|
|
364
|
+
/** Like Rollup `output.experimentalMinChunkSize` — automatically merges a
|
|
365
|
+
* small common chunk whose (estimated) total module source is under this
|
|
366
|
+
* many bytes into a chunk whose reachability is a superset (no over-fetch).
|
|
367
|
+
* entry/manual/dynamic chunks are preserved. 0/unspecified = disabled. */
|
|
368
|
+
minChunkSize?: number;
|
|
369
|
+
/** Module Federation config (#3318 P1-0). Parsing & validation only — emit
|
|
370
|
+
* is a follow-up (P1-1+). Being a nested object, it is config/`build()`-only
|
|
371
|
+
* (no CLI flag — the whole ecosystem is config-driven). MF2 contract
|
|
372
|
+
* (`name`/`exposes`/`remotes`/`shared`/`shareScope`). */
|
|
373
|
+
mf?: ModuleFederationConfig;
|
|
374
|
+
sourcemap?: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* Source map output format (only meaningful when `sourcemap: true`).
|
|
377
|
+
* esbuild / rolldown-compatible (#2152).
|
|
378
|
+
* - `"linked"` (default): emit a `.map` file +
|
|
379
|
+
* `//# sourceMappingURL=<file>.map` comment.
|
|
380
|
+
* - `"external"`: emit a `.map` file, no URL comment (Sentry/CI standard —
|
|
381
|
+
* location not disclosed).
|
|
382
|
+
* - `"inline"`: no `.map` file, embed the JSON as a base64 data URL in a
|
|
383
|
+
* comment.
|
|
384
|
+
*
|
|
385
|
+
* In watch / dev server environments, `linked` is forced (guarantees
|
|
386
|
+
* HMR + DevTools integration).
|
|
387
|
+
*/
|
|
388
|
+
sourcemapMode?: 'linked' | 'external' | 'inline';
|
|
389
|
+
sourcemapDebugIds?: boolean;
|
|
390
|
+
sourcesContent?: boolean;
|
|
391
|
+
treeShaking?: boolean;
|
|
392
|
+
metafile?: boolean;
|
|
393
|
+
keepNames?: boolean;
|
|
394
|
+
shimMissingExports?: boolean;
|
|
395
|
+
flow?: boolean;
|
|
396
|
+
jsxInJs?: boolean;
|
|
397
|
+
charsetUtf8?: boolean;
|
|
398
|
+
useDefineForClassFields?: boolean;
|
|
399
|
+
experimentalDecorators?: boolean;
|
|
400
|
+
emitDecoratorMetadata?: boolean;
|
|
401
|
+
/** `import { x } from 'mod'` cherry-pick decomposition mapping. The ZNTC
|
|
402
|
+
* equivalent of babel-plugin-lodash and the like (#2393).
|
|
403
|
+
* key = source module name (exact match), value = template (the `{name}`
|
|
404
|
+
* placeholder is replaced with the specifier name).
|
|
405
|
+
*
|
|
406
|
+
* e.g. with `{ lodash: 'lodash/{name}' }`, `import { map } from 'lodash'`
|
|
407
|
+
* becomes `import map from 'lodash/map'`.
|
|
408
|
+
*
|
|
409
|
+
* Transform conditions (all must hold): named specifiers only, no alias, not
|
|
410
|
+
* type-only. If not met, the original import is kept — a safety net for when
|
|
411
|
+
* the library does not support path imports.
|
|
412
|
+
*/
|
|
413
|
+
moduleSpecifierMap?: Record<string, string>;
|
|
414
|
+
banner?: string;
|
|
415
|
+
footer?: string;
|
|
416
|
+
/** Rollup `output.intro`: text to insert before the code inside the format wrapper. */
|
|
417
|
+
intro?: string;
|
|
418
|
+
/** Rollup `output.outro`: text to insert after the code inside the format wrapper. */
|
|
419
|
+
outro?: string;
|
|
420
|
+
globalName?: string;
|
|
421
|
+
/** Rollup `output.globals`: IIFE/UMD external specifier → global variable mapping */
|
|
422
|
+
globals?: Record<string, string>;
|
|
423
|
+
publicPath?: string;
|
|
424
|
+
entryNames?: string;
|
|
425
|
+
chunkNames?: string;
|
|
426
|
+
assetNames?: string;
|
|
427
|
+
/** Metro AssetRegistry module path (React Native-only layer).
|
|
428
|
+
* - `undefined`: determined by the platform preset (with
|
|
429
|
+
* `platform: "react-native"`, the default path is used automatically)
|
|
430
|
+
* - `string`: wrap with the registerAsset at that path as
|
|
431
|
+
* `module.exports = require(path).registerAsset({...})`
|
|
432
|
+
* - `false`: disabled (export the same URL string as web)
|
|
433
|
+
* Default path: `"react-native/Libraries/Image/AssetRegistry"` */
|
|
434
|
+
assetRegistry?: string | false;
|
|
435
|
+
/** JSX runtime mode. `'preserve'` emits JSX unchanged — only TS annotations
|
|
436
|
+
* are stripped. Use this to delegate JSX handling to a downstream tool (e.g.
|
|
437
|
+
* `@vitejs/plugin-react` / `@preact/preset-vite` / `vite-plugin-solid`).
|
|
438
|
+
* Equivalent to tsc `"jsx": "preserve"`.
|
|
439
|
+
* Known limitation — TS annotations inside an expression container within JSX
|
|
440
|
+
* (e.g. `<Foo prop={value as Type}>`) are left raw, not stripped. */
|
|
441
|
+
jsx?: 'classic' | 'automatic' | 'automatic-dev' | 'preserve';
|
|
442
|
+
jsxFactory?: string;
|
|
443
|
+
jsxFragment?: string;
|
|
444
|
+
jsxImportSource?: string;
|
|
445
|
+
/** Compile-time constant substitution (esbuild `define`-compatible).
|
|
446
|
+
* Keys are identifiers or member expressions like `obj.prop`; values are JS
|
|
447
|
+
* expression strings.
|
|
448
|
+
* e.g. `{ "__DEV__": "false", "process.env.NODE_ENV": '"production"' }` */
|
|
449
|
+
define?: Record<string, string>;
|
|
450
|
+
/** Dev server defaults for `zntc dev` / `zntc --serve`. CLI flags still take precedence. */
|
|
451
|
+
server?: DevServerOptions;
|
|
452
|
+
/** Import path aliases — two forms supported (esbuild / Vite-compatible):
|
|
453
|
+
*
|
|
454
|
+
* 1. **Object form** (esbuild `alias`): exact + prefix matching. Only the
|
|
455
|
+
* given specifier is substituted.
|
|
456
|
+
* e.g. `{ react: "preact/compat" }` — `react` or `react/hooks` →
|
|
457
|
+
* `preact/compat[/hooks]`
|
|
458
|
+
*
|
|
459
|
+
* 2. **Array form** (Vite `resolve.alias`, #2153): supports `RegExp` find.
|
|
460
|
+
* The first match in order is applied. When `find` is a string it is
|
|
461
|
+
* prefix-matched; when a RegExp, the host runtime matches and substitutes
|
|
462
|
+
* via `replacement`.
|
|
463
|
+
* e.g. `[{ find: /^@\/(.*)$/, replacement: "./src/$1" }]`
|
|
464
|
+
*
|
|
465
|
+
* Substituted **unconditionally before** normal resolution — even an
|
|
466
|
+
* actually-installed package is ignored. For an optional shim, use
|
|
467
|
+
* `fallback` instead (applied only on failure). The array form is also
|
|
468
|
+
* supported in buildSync(), which uses only sync hooks. */
|
|
469
|
+
alias?: Record<string, string> | Array<{
|
|
470
|
+
find: string | RegExp;
|
|
471
|
+
replacement: string;
|
|
472
|
+
}>;
|
|
473
|
+
/** Fallback resolution — applied **only when** normal resolution fails
|
|
474
|
+
* (webpack `resolve.fallback` / Metro `resolver.extraNodeModules`-compatible).
|
|
475
|
+
* If the value is a string, re-resolve to that specifier; if `false`,
|
|
476
|
+
* substitute an empty module.
|
|
477
|
+
* e.g. `{ crypto: "crypto-browserify", fs: false }` */
|
|
478
|
+
fallback?: Record<string, string | false>;
|
|
479
|
+
/** Resolution-blocking patterns (Metro `resolver.blockList` / webpack
|
|
480
|
+
* `IgnorePlugin`-compatible). Absolute paths that match are failed by the
|
|
481
|
+
* resolver and not included in the bundle graph.
|
|
482
|
+
* - `RegExp`: `.source` is extracted and used as the pattern
|
|
483
|
+
* - `string`: used as the regex string as-is
|
|
484
|
+
*
|
|
485
|
+
* Supported syntax: literals, `.*`, `^`, `$`, `\x` escapes. `|`, `[]`, `()`,
|
|
486
|
+
* `+?`, `\w\d` are not supported.
|
|
487
|
+
*
|
|
488
|
+
* With `platform: "react-native"`, Metro's default patterns (`__tests__`,
|
|
489
|
+
* iOS/Android build folders, etc.) are auto-prepended. User patterns are
|
|
490
|
+
* appended after them. */
|
|
491
|
+
blockList?: (RegExp | string)[];
|
|
492
|
+
inject?: string[];
|
|
493
|
+
jobs?: number;
|
|
494
|
+
plugins?: ZntcPlugin[];
|
|
495
|
+
/** User-defined chunk splitting — Rollup/rolldown `manualChunks`-compatible
|
|
496
|
+
* (#1027). Receives a module id (absolute path); returning a chunk name
|
|
497
|
+
* groups that module into the chunk of that name. Returning null/undefined
|
|
498
|
+
* uses the existing automatic distribution. Transitive dependencies follow
|
|
499
|
+
* into the same chunk (avoids cross-chunk cycles). Dynamic import targets
|
|
500
|
+
* prefer the manual chunk over an async chunk.
|
|
501
|
+
*
|
|
502
|
+
* The second argument `meta.getModuleInfo(id)` is a graph topology lookup —
|
|
503
|
+
* Rollup-compatible.
|
|
504
|
+
*
|
|
505
|
+
* e.g.:
|
|
506
|
+
* ```ts
|
|
507
|
+
* manualChunks: (id, meta) => {
|
|
508
|
+
* const info = meta.getModuleInfo(id);
|
|
509
|
+
* if (info && info.importers.length >= 2) return 'shared';
|
|
510
|
+
* if (/node_modules\/react/.test(id)) return 'react';
|
|
511
|
+
* return null;
|
|
512
|
+
* }
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
manualChunks?: (id: string, meta: ManualChunksMeta) => string | null | undefined;
|
|
516
|
+
/** Per-extension loader override (e.g. { ".png": "file", ".svg": "text" }). */
|
|
517
|
+
loader?: Record<string, string>;
|
|
518
|
+
/** Custom package.json exports conditions. */
|
|
519
|
+
conditions?: string[];
|
|
520
|
+
/** Extension resolution order (e.g. [".ts", ".tsx", ".js"]). */
|
|
521
|
+
resolveExtensions?: string[];
|
|
522
|
+
/** package.json field order (e.g. ["module", "main"]). */
|
|
523
|
+
mainFields?: string[];
|
|
524
|
+
/** Output directory (used when write: true). */
|
|
525
|
+
outdir?: string;
|
|
526
|
+
/** Output file path (for a single entry, used when write: true). */
|
|
527
|
+
outfile?: string;
|
|
528
|
+
/**
|
|
529
|
+
* Multi-format emit (rolldown-style). 배열 길이 >= 2 시 같은 entry 로 각 format 별
|
|
530
|
+
* build() 호출 후 BuildResult.outputsByFormat 에 결과 묶음. 사용자가 한 호출로
|
|
531
|
+
* ESM+CJS 동시 출력. graph 재사용은 현재 미지원 (각 format 마다 graph 재빌드).
|
|
532
|
+
*/
|
|
533
|
+
output?: OutputOptions[];
|
|
534
|
+
/** Whether to write to disk (default: false, automatically true when outdir/outfile is set). */
|
|
535
|
+
write?: boolean;
|
|
536
|
+
/** Allow output files to overwrite input files. */
|
|
537
|
+
allowOverwrite?: boolean;
|
|
538
|
+
/** Common base path for entry points (determines the output directory structure). */
|
|
539
|
+
outbase?: string;
|
|
540
|
+
/** Treat all bare imports as external. */
|
|
541
|
+
packagesExternal?: boolean;
|
|
542
|
+
/** Resolve to the link path instead of following symlinks (esbuild/Node-compatible). */
|
|
543
|
+
preserveSymlinks?: boolean;
|
|
544
|
+
/**
|
|
545
|
+
* When normal `node_modules` resolution fails, search once more in the
|
|
546
|
+
* realpath directory of `source_dir`. Used as a fallback when an RN/pnpm
|
|
547
|
+
* peer dependency exists only in a sibling `node_modules` beyond a symlink.
|
|
548
|
+
* Orthogonal to `preserveSymlinks` — they are commonly enabled together.
|
|
549
|
+
*/
|
|
550
|
+
resolveSymlinkSiblings?: boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Metro `resolver.disableHierarchicalLookup`-compatible. When true, blocks
|
|
553
|
+
* `node_modules` walk-up resolution outside the entry directory — used in a
|
|
554
|
+
* monorepo to force dependency hoisting or to prevent leakage of modules
|
|
555
|
+
* outside the workspace.
|
|
556
|
+
*/
|
|
557
|
+
disableHierarchicalLookup?: boolean;
|
|
558
|
+
/** Ignore @__PURE__ and sideEffects annotations. */
|
|
559
|
+
ignoreAnnotations?: boolean;
|
|
560
|
+
/** Do not tree-shake unused JSX. */
|
|
561
|
+
jsxSideEffects?: boolean;
|
|
562
|
+
/** Bundle analysis output (forces metafile on). */
|
|
563
|
+
analyze?: boolean;
|
|
564
|
+
/** List of label names of labeled statements to remove. */
|
|
565
|
+
dropLabels?: string[];
|
|
566
|
+
/** Remove `console.*` call expression statements in the transformer (#2155). Applied identically for bundle/transpile. */
|
|
567
|
+
dropConsole?: boolean;
|
|
568
|
+
/** Remove `debugger;` statements in the transformer (#2155). Applied identically for bundle/transpile. */
|
|
569
|
+
dropDebugger?: boolean;
|
|
570
|
+
/** List of global function names to mark as pure. */
|
|
571
|
+
pure?: string[];
|
|
572
|
+
/**
|
|
573
|
+
* Diagnostic output level (esbuild-compatible, #2158). NAPI filters the
|
|
574
|
+
* build result's errors/warnings arrays by this level — the items included
|
|
575
|
+
* in `result.errors` / `result.warnings` themselves are reduced.
|
|
576
|
+
*
|
|
577
|
+
* - `"silent"`: both errors / warnings are empty arrays — even a failure is
|
|
578
|
+
* observed via the result object (no throw)
|
|
579
|
+
* - `"error"`: only warnings is an empty array, errors as-is
|
|
580
|
+
* - `"warning"` (default): both errors + warnings as-is
|
|
581
|
+
* - `"info"` / `"debug"` / `"verbose"`: same as warning (info-level
|
|
582
|
+
* diagnostics are not emitted currently)
|
|
583
|
+
*/
|
|
584
|
+
logLevel?: 'silent' | 'error' | 'warning' | 'info' | 'debug' | 'verbose';
|
|
585
|
+
/**
|
|
586
|
+
* Diagnostic count limit (esbuild `logLimit`, #2158). 0 means unlimited
|
|
587
|
+
* (default). The same limit applies to each of the errors / warnings arrays
|
|
588
|
+
* — excess items are auto-truncated.
|
|
589
|
+
*/
|
|
590
|
+
logLimit?: number;
|
|
591
|
+
/**
|
|
592
|
+
* CJS / UMD entry export format (Rollup `output.exports`-compatible, #2159).
|
|
593
|
+
* Ignored for ESM output.
|
|
594
|
+
*
|
|
595
|
+
* - `"auto"` (default): default-only → `module.exports = X`. named-only → `exports.X = X`
|
|
596
|
+
* (no `__esModule` flag). mixed → `exports.X = X` + `__esModule` flag.
|
|
597
|
+
* - `"named"`: always named (`exports.X = X`). If a default exists, the
|
|
598
|
+
* `__esModule` flag is added automatically (rolldown `IfDefaultProp`
|
|
599
|
+
* behavior — no flag when there is no default).
|
|
600
|
+
* - `"default"`: single `module.exports = X` — only when default-only. If
|
|
601
|
+
* named is mixed in, warning + empty output.
|
|
602
|
+
* - `"none"`: no export output.
|
|
603
|
+
*/
|
|
604
|
+
outputExports?: 'auto' | 'named' | 'default' | 'none';
|
|
605
|
+
/**
|
|
606
|
+
* Inline tsconfig JSON string (same meaning as esbuild's `tsconfigRaw`).
|
|
607
|
+
* When set, both `tsconfigPath` and autodiscovery are ignored — raw is the
|
|
608
|
+
* single source of truth. compilerOptions such as jsx/target/decorators are
|
|
609
|
+
* applied by the Zig-side `tsconfig_merge`.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* tsconfigRaw: JSON.stringify({ compilerOptions: { jsx: "react-jsx", jsxImportSource: "preact" } })
|
|
613
|
+
*/
|
|
614
|
+
tsconfigRaw?: string;
|
|
615
|
+
/**
|
|
616
|
+
* Path to tsconfig.json (file or directory). When set, compilerOptions are
|
|
617
|
+
* auto-loaded and merged. Fields set explicitly via JS options take
|
|
618
|
+
* precedence — only unspecified fields are filled from the tsconfig values.
|
|
619
|
+
* e.g. "./tsconfig.json" or "./project-dir".
|
|
620
|
+
*/
|
|
621
|
+
tsconfigPath?: string;
|
|
622
|
+
/** Additional NODE_PATH resolution paths. */
|
|
623
|
+
nodePaths?: string[];
|
|
624
|
+
/** Line length limit (0=unlimited). */
|
|
625
|
+
lineLimit?: number;
|
|
626
|
+
/** Output file extension override (e.g. ".mjs"). */
|
|
627
|
+
outExtension?: string;
|
|
628
|
+
/** Source map sourceRoot field. */
|
|
629
|
+
sourceRoot?: string;
|
|
630
|
+
/** License comment handling ("none" | "inline" | "eof" | "linked"). */
|
|
631
|
+
legalComments?: 'none' | 'inline' | 'eof' | 'linked';
|
|
632
|
+
/** Emit a separate file per module (library build). */
|
|
633
|
+
preserveModules?: boolean;
|
|
634
|
+
/** Base path for the preserve-modules output directory structure. */
|
|
635
|
+
preserveModulesRoot?: string;
|
|
636
|
+
/**
|
|
637
|
+
* List of profile categories to enable (union with the ZNTC_PROFILE env).
|
|
638
|
+
* e.g. `["all"]`, `["parse", "transform"]`, `["transform.jsx"]`.
|
|
639
|
+
* Specifying a parent auto-enables children too (e.g. "transform" →
|
|
640
|
+
* "transform.jsx"/"transform.ts_strip"/...).
|
|
641
|
+
* Available categories: see docs/design/profile-infrastructure.md.
|
|
642
|
+
*/
|
|
643
|
+
profile?: string[];
|
|
644
|
+
/**
|
|
645
|
+
* Profile detail level.
|
|
646
|
+
* - "summary": phase totals only (default)
|
|
647
|
+
* - "detailed": includes sub-phases
|
|
648
|
+
* - "per-module": per-module breakdown
|
|
649
|
+
* - "per-pass": transformer visit level
|
|
650
|
+
*/
|
|
651
|
+
profileLevel?: 'summary' | 'detailed' | 'per-module' | 'per-pass';
|
|
652
|
+
/**
|
|
653
|
+
* Profile report output format.
|
|
654
|
+
* - "table": human-readable (default)
|
|
655
|
+
* - "tree": parent/child tree
|
|
656
|
+
* - "json": machine-readable
|
|
657
|
+
* - "csv": spreadsheet
|
|
658
|
+
*/
|
|
659
|
+
profileFormat?: 'table' | 'tree' | 'json' | 'csv';
|
|
660
|
+
/** dev mode: wrap modules in a __zntc_register() factory + inject the HMR runtime. */
|
|
661
|
+
devMode?: boolean;
|
|
662
|
+
/** dev mode module ID base path. */
|
|
663
|
+
rootDir?: string;
|
|
664
|
+
/** Enable React Fast Refresh. */
|
|
665
|
+
reactRefresh?: boolean;
|
|
666
|
+
/** Collect dev mode per-module codes (for HMR rebuilds). */
|
|
667
|
+
collectModuleCodes?: boolean;
|
|
668
|
+
/** Add configurable: true to Object.defineProperty (RN/Hermes-compatible). */
|
|
669
|
+
configurableExports?: boolean;
|
|
670
|
+
/** Guarantee ESM execution order — downgrade function declarations to
|
|
671
|
+
* assignments inside the factory to prevent hoisting. Same as Rolldown's
|
|
672
|
+
* strictExecutionOrder. Auto-enabled on the React Native platform. */
|
|
673
|
+
strictExecutionOrder?: boolean;
|
|
674
|
+
/** Wrap entry trigger (`init_X()` / `require_X()`) calls in try/catch +
|
|
675
|
+
* ErrorUtils.reportFatalError. Equivalent mechanism to Metro
|
|
676
|
+
* `guardedLoadModule` (top-level `__r` wrapper) — a module factory throw is
|
|
677
|
+
* shown as fatal in the standard RN LogBox instead of blocking boot. In
|
|
678
|
+
* environments without ErrorUtils (test / browser), the throw is re-thrown
|
|
679
|
+
* as-is. It was discovered when iOS 26.4 Hermes pre-registers spec globals
|
|
680
|
+
* such as `Location` with an immutable descriptor (`configurable: false`)
|
|
681
|
+
* and expo-metro-runtime's unguarded `defineProperty` attempt threw, but the
|
|
682
|
+
* mechanism is OS/engine-agnostic — it covers every module factory throw
|
|
683
|
+
* case. Auto-enabled on the React Native platform. */
|
|
684
|
+
entryErrorGuard?: boolean;
|
|
685
|
+
/** Inject a `console.error` setter intercept into the prologue — console.error
|
|
686
|
+
* calls matching any one of the RegExp source string array are silently
|
|
687
|
+
* swallowed. Orthogonal to `entryErrorGuard`. The consumer detects the
|
|
688
|
+
* environment (e.g. expo) and injects the patterns. When empty or
|
|
689
|
+
* unspecified, the wrap itself is not emitted → a vanilla RN CLI build has
|
|
690
|
+
* zero dead code. Not auto-enabled even by the RN preset (the trigger is
|
|
691
|
+
* environment-specific).
|
|
692
|
+
*
|
|
693
|
+
* e.g.: `["^Failed to set polyfill\\.\\s+\\w+\\s+is not configurable\\.?$"]`
|
|
694
|
+
* (the native immutable global collision message of expo `installGlobal.ts`
|
|
695
|
+
* + RN `polyfillObjectProperty`) */
|
|
696
|
+
silentConsoleErrorPatterns?: string[];
|
|
697
|
+
/** Enable scope hoisting (default true). Removes module boundaries within a single chunk and flattens symbols. */
|
|
698
|
+
scopeHoist?: boolean;
|
|
699
|
+
/** Reanimated worklet transform — injects __workletHash/__closure/__initData
|
|
700
|
+
* into functions with the "worklet" directive. Auto-enabled on the React
|
|
701
|
+
* Native platform. */
|
|
702
|
+
workletTransform?: boolean;
|
|
703
|
+
/** The worklet's `__pluginVersion` value (for cross-checking Reanimated dev
|
|
704
|
+
* mode jsVersion). Must be passed the react-native-worklets package version
|
|
705
|
+
* from the user's environment to avoid a runtime error. */
|
|
706
|
+
workletPluginVersion?: string;
|
|
707
|
+
/** RN view config codegen — replaces the `codegenNativeComponent` call in
|
|
708
|
+
* `*NativeComponent.{js,ts}` with an inline view config (#2348). Auto-enabled
|
|
709
|
+
* on the React Native platform. Same as the
|
|
710
|
+
* `GenerateViewConfigJs.generate()` fileTemplate of `@react-native/codegen`.
|
|
711
|
+
* Avoids the Fabric early-register race (`View config not found for
|
|
712
|
+
* component 'X'`). */
|
|
713
|
+
codegenTransform?: boolean;
|
|
714
|
+
/** Global identifiers to reserve during scope hoisting. */
|
|
715
|
+
globalIdentifiers?: string[];
|
|
716
|
+
/** Paths of polyfills to run immediately at bundle start. */
|
|
717
|
+
polyfills?: string[];
|
|
718
|
+
/**
|
|
719
|
+
* Auto-inject core-js-based runtime API polyfills.
|
|
720
|
+
*
|
|
721
|
+
* - `"off"` (default): no automatic runtime polyfills.
|
|
722
|
+
* - `"auto"` / `"usage"`: after resolve/load/transform, detect the APIs
|
|
723
|
+
* actually used in the bundle graph and inject the modules unsupported by
|
|
724
|
+
* the target.
|
|
725
|
+
* - `"entry"`: comprehensively inject the core-js ES/Web modules required by
|
|
726
|
+
* the target into the entry prelude.
|
|
727
|
+
* - Target specification uses a Browserslist query array, like Rspack/SWC
|
|
728
|
+
* `env.targets`.
|
|
729
|
+
*/
|
|
730
|
+
runtimePolyfills?: RuntimePolyfillsOption;
|
|
731
|
+
/** core-js version used for the core-js-compat computation (e.g. `"3.49"`). Same role as `runtimePolyfills.coreJs`. */
|
|
732
|
+
coreJs?: string;
|
|
733
|
+
/** Paths of modules to run immediately before the entry module. */
|
|
734
|
+
runBeforeMain?: string[];
|
|
735
|
+
/** Add directories outside the bundle graph to the watch roots (Metro
|
|
736
|
+
* watchFolders-compatible). Both absolute and relative paths are allowed.
|
|
737
|
+
* The given paths are recursively scanned and included in the watch set. */
|
|
738
|
+
watchFolders?: string[];
|
|
739
|
+
/** File glob whitelist to include when scanning watchFolders (paths relative to the root). */
|
|
740
|
+
watchInclude?: string[];
|
|
741
|
+
/** File globs to exclude when scanning watchFolders (paths relative to the root). */
|
|
742
|
+
watchExclude?: string[];
|
|
743
|
+
/** watch-mode build-complete callback. */
|
|
744
|
+
onReady?: (event: WatchReadyEvent) => void | Promise<void>;
|
|
745
|
+
/** watch-mode rebuild callback. */
|
|
746
|
+
onRebuild?: (event: WatchRebuildEvent) => void | Promise<void>;
|
|
747
|
+
/**
|
|
748
|
+
* Whether to write the `.map` file to disk (Issue #1727 Phase B).
|
|
749
|
+
*
|
|
750
|
+
* - Default `true` — save `bundle.js.map` to the `output_filename + ".map"`
|
|
751
|
+
* path.
|
|
752
|
+
* - `false` — skip disk I/O. Recommended when a dev server such as bungae
|
|
753
|
+
* serves it from a lazy endpoint by calling
|
|
754
|
+
* {@link WatchHandle.getBundleSourceMap} /
|
|
755
|
+
* {@link WatchHandle.getHmrSourceMap}.
|
|
756
|
+
*/
|
|
757
|
+
emitDiskSourcemap?: boolean;
|
|
758
|
+
/**
|
|
759
|
+
* Per-library 1st-party transform settings (`@next/swc` `compiler`-compatible
|
|
760
|
+
* surface).
|
|
761
|
+
*
|
|
762
|
+
* Currently a type stub — no runtime effect since the Zig transformer does
|
|
763
|
+
* not recognize it yet. Activated in a follow-up epic when the
|
|
764
|
+
* styled-components / emotion 1st-party transforms are introduced.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```ts
|
|
768
|
+
* defineConfig({
|
|
769
|
+
* compiler: {
|
|
770
|
+
* styledComponents: true,
|
|
771
|
+
* emotion: { autoLabel: "dev-only" },
|
|
772
|
+
* },
|
|
773
|
+
* });
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
776
|
+
compiler?: CompilerOptions;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* BuildOptions: the user-facing public API.
|
|
780
|
+
*
|
|
781
|
+
* When `platform === "react-native"`, the Hermes compatibility matrix is
|
|
782
|
+
* forced, so `target` / `browserslist` cannot be passed (they are ignored at
|
|
783
|
+
* runtime too).
|
|
784
|
+
*/
|
|
785
|
+
export type BuildOptions = (BuildOptionsCommon & {
|
|
786
|
+
/** React Native (Hermes) preset. target is forced to the Hermes matrix. */
|
|
787
|
+
platform: Extract<import('../shared/index').Platform, 'react-native'>;
|
|
788
|
+
target?: BuildTarget;
|
|
789
|
+
browserslist?: never;
|
|
790
|
+
}) | (BuildOptionsCommon & {
|
|
791
|
+
platform?: Exclude<import('../shared/index').Platform, 'react-native'>;
|
|
792
|
+
/** ES downlevel target. Rspack-style node/hermes target strings are accepted by the JS wrapper. */
|
|
793
|
+
target?: BuildTarget;
|
|
794
|
+
/** browserslist query (string or string[]). Takes precedence over target when set. */
|
|
795
|
+
browserslist?: string | string[];
|
|
796
|
+
});
|
|
797
|
+
export interface WatchReadyEvent {
|
|
798
|
+
files: number;
|
|
799
|
+
bytes: number;
|
|
800
|
+
}
|
|
801
|
+
export interface WatchRebuildEvent {
|
|
802
|
+
success: boolean;
|
|
803
|
+
error?: string;
|
|
804
|
+
changed?: string[];
|
|
805
|
+
graphChanged?: boolean;
|
|
806
|
+
updates?: Array<{
|
|
807
|
+
id: string;
|
|
808
|
+
code: string;
|
|
809
|
+
/**
|
|
810
|
+
* Per-module standalone source map (V3 JSON). Populated when the sourcemap
|
|
811
|
+
* option is enabled. When the HMR client attaches it to the eval'd code as
|
|
812
|
+
* a sourceMappingURL data URL, debugger mapping is preserved without
|
|
813
|
+
* regenerating the whole bundle sourcemap (Issue #1248).
|
|
814
|
+
*/
|
|
815
|
+
map?: string;
|
|
816
|
+
}>;
|
|
817
|
+
bytes?: number;
|
|
818
|
+
/**
|
|
819
|
+
* Per-phase build time (milliseconds). Exposed only on a successful rebuild.
|
|
820
|
+
*
|
|
821
|
+
* **Base phases** (always measured):
|
|
822
|
+
* - `detect` / `graph` / `link` / `shake` / `emit` / `delta` / `total`
|
|
823
|
+
* Field names exactly match their actual values. The pre-2026-04-22 `parse` /
|
|
824
|
+
* `semantic` were in fact legacy names that held `graph` / `link+shake`
|
|
825
|
+
* respectively and have been removed — they are now exposed only as
|
|
826
|
+
* sub-phases (the real parser / SemanticAnalyzer times).
|
|
827
|
+
*
|
|
828
|
+
* **Sub-phases** (when `ZNTC_PROFILE=<cat>` / `BUNGAE_HMR_PROFILE=1` /
|
|
829
|
+
* `profile: ["<cat>"]` is active):
|
|
830
|
+
* - `scan` / `parse` / `resolve` / `semantic` / `transform` / `codegen` / `metadata`
|
|
831
|
+
* - All 0 when inactive. `parse` is now the real parser time, `semantic` the
|
|
832
|
+
* real SemanticAnalyzer.
|
|
833
|
+
*/
|
|
834
|
+
phaseDurations?: {
|
|
835
|
+
/** Change detection (mtime scan). */
|
|
836
|
+
detect: number;
|
|
837
|
+
/** Module graph build — resolve + parse + semantic + finalize */
|
|
838
|
+
graph: number;
|
|
839
|
+
/** Scope hoisting + linker */
|
|
840
|
+
link: number;
|
|
841
|
+
/** Tree shaking */
|
|
842
|
+
shake: number;
|
|
843
|
+
/** Code generation (transform + codegen + emit). */
|
|
844
|
+
emit: number;
|
|
845
|
+
/** HMR delta extraction. */
|
|
846
|
+
delta: number;
|
|
847
|
+
/** Total rebuild time (sum of detect → delta). */
|
|
848
|
+
total: number;
|
|
849
|
+
/** Scanner tokenization */
|
|
850
|
+
scan: number;
|
|
851
|
+
/** Parser — real parser time only. */
|
|
852
|
+
parse: number;
|
|
853
|
+
/** Dependency resolution */
|
|
854
|
+
resolve: number;
|
|
855
|
+
/** SemanticAnalyzer — real semantic analysis time only. */
|
|
856
|
+
semantic: number;
|
|
857
|
+
/** Transformer total. */
|
|
858
|
+
transform: number;
|
|
859
|
+
/** Codegen total. */
|
|
860
|
+
codegen: number;
|
|
861
|
+
/** Linker metadata build */
|
|
862
|
+
metadata: number;
|
|
863
|
+
/** `graph.build()` / `graph.buildIncremental()` — the module graph construction body. */
|
|
864
|
+
graphBuild: number;
|
|
865
|
+
/** Separate build of the `new Worker(new URL(...))` pattern entry. */
|
|
866
|
+
graphWorker: number;
|
|
867
|
+
/** Phase 1: event queue BFS scan (module discovery + parsing + resolve). */
|
|
868
|
+
graphDiscover: number;
|
|
869
|
+
/** Phase 2-4: DFS exec_index + ExportsKind promotion + TLA propagation. */
|
|
870
|
+
graphFinalize: number;
|
|
871
|
+
/** Loading `--polyfill` file contents + Flow transpilation. */
|
|
872
|
+
emitPolyfill: number;
|
|
873
|
+
/** Assembling the React Refresh runtime preamble/epilogue (dev + browser). */
|
|
874
|
+
emitRefresh: number;
|
|
875
|
+
/** `emitter.emitWithTreeShaking` / `emitChunks` — the bundle output generation body. */
|
|
876
|
+
emitOutput: number;
|
|
877
|
+
/** `--metafile` / `--analyze` JSON generation. */
|
|
878
|
+
emitMetafile: number;
|
|
879
|
+
/** Per-CSS-entry bundling + lightningcss post-processing. */
|
|
880
|
+
emitCss: number;
|
|
881
|
+
/** Format prologue + polyfill IIFE + runtime helper injection. */
|
|
882
|
+
emitPrelude: number;
|
|
883
|
+
/** Phase 1/1.5/2/2.5 — used_names + cache lookup + emitModule + cache put */
|
|
884
|
+
emitModulePass: number;
|
|
885
|
+
/** Phase 3: module concat + runtime helpers summation + renderChunk + epilogue. */
|
|
886
|
+
emitConcat: number;
|
|
887
|
+
/** Source map V3 JSON generation (VLQ encode + sources content + debugId). */
|
|
888
|
+
emitSourcemapFinalize: number;
|
|
889
|
+
};
|
|
890
|
+
/** Number of modules reparsed in the incremental graph. Counts cache-missed
|
|
891
|
+
* modules only. Not exposed for full builds. */
|
|
892
|
+
reparsedModules?: number;
|
|
893
|
+
}
|
|
894
|
+
export interface WatchHandle {
|
|
895
|
+
stop(): void;
|
|
896
|
+
/**
|
|
897
|
+
* Lazily generates and returns the full-bundle sourcemap JSON of the latest
|
|
898
|
+
* rebuild (Issue #1727 Phase B).
|
|
899
|
+
*
|
|
900
|
+
* The emit step skips VLQ encoding + sourcesContent attachment, deferring
|
|
901
|
+
* that cost out of HMR latency until request time. Called when the dev
|
|
902
|
+
* server receives a `/bundle.js.map` request.
|
|
903
|
+
*
|
|
904
|
+
* - `null` when sourcemap is disabled / before the initial build / after
|
|
905
|
+
* `stop()`.
|
|
906
|
+
* - Metro `_processSourceMapRequest` pattern.
|
|
907
|
+
*/
|
|
908
|
+
getBundleSourceMap(): string | null;
|
|
909
|
+
/**
|
|
910
|
+
* Lazily generates and returns the per-module sourcemap JSON of the latest
|
|
911
|
+
* rebuild.
|
|
912
|
+
*
|
|
913
|
+
* Called when the dev server receives a `/hmr-map/:moduleId` request.
|
|
914
|
+
* `null` if `moduleId` was not included in this rebuild.
|
|
915
|
+
*/
|
|
916
|
+
getHmrSourceMap(moduleId: string): string | null;
|
|
917
|
+
}
|
|
918
|
+
export interface ZntcPlugin {
|
|
919
|
+
name: string;
|
|
920
|
+
setup(build: PluginBuild): void;
|
|
921
|
+
}
|
|
922
|
+
/** Plugin hook return value: both sync and async allowed. null/undefined for pass-through. */
|
|
923
|
+
type HookResult<T> = T | null | undefined | Promise<T | null | undefined>;
|
|
924
|
+
export interface PluginBuild {
|
|
925
|
+
onResolve(options: {
|
|
926
|
+
filter: RegExp;
|
|
927
|
+
}, callback: (args: {
|
|
928
|
+
path: string;
|
|
929
|
+
importer: string | null;
|
|
930
|
+
}) => HookResult<{
|
|
931
|
+
path?: string;
|
|
932
|
+
/** Keep the import statement as-is — resolved at runtime (esbuild-compatible). */
|
|
933
|
+
external?: boolean;
|
|
934
|
+
/** Substitute the module with an empty object (`module.exports = {}`).
|
|
935
|
+
* For mapping when Metro `resolveRequest` returns `{ type: 'empty' }`, or
|
|
936
|
+
* when webpack `resolve.fallback` is `false`. If `path` is omitted, the
|
|
937
|
+
* specifier is used as the identifier. */
|
|
938
|
+
disabled?: boolean;
|
|
939
|
+
}>): void;
|
|
940
|
+
onLoad(options: {
|
|
941
|
+
filter: RegExp;
|
|
942
|
+
}, callback: (args: {
|
|
943
|
+
path: string;
|
|
944
|
+
}) => HookResult<{
|
|
945
|
+
contents: string | Uint8Array;
|
|
946
|
+
loader?: string;
|
|
947
|
+
map?: unknown;
|
|
948
|
+
}>): void;
|
|
949
|
+
onTransform(options: {
|
|
950
|
+
filter: RegExp;
|
|
951
|
+
}, callback: (args: {
|
|
952
|
+
code: string;
|
|
953
|
+
path: string;
|
|
954
|
+
}) => HookResult<{
|
|
955
|
+
code: string;
|
|
956
|
+
map?: unknown;
|
|
957
|
+
}>): void;
|
|
958
|
+
onRenderChunk(options: {
|
|
959
|
+
filter: RegExp;
|
|
960
|
+
}, callback: (args: {
|
|
961
|
+
code: string;
|
|
962
|
+
chunk: string;
|
|
963
|
+
}) => HookResult<{
|
|
964
|
+
code: string;
|
|
965
|
+
}>): void;
|
|
966
|
+
onGenerateBundle(callback: (outputs: OutputFile[]) => void | Promise<void>): void;
|
|
967
|
+
/**
|
|
968
|
+
* Called once at bundle start. Same as esbuild `onStart`,
|
|
969
|
+
* Rollup/Vite/rolldown `buildStart` (#2156). In watch mode it is called for
|
|
970
|
+
* the initial build and on every rebuild (same as the Rollup 5+ policy).
|
|
971
|
+
*
|
|
972
|
+
* No arguments — same as esbuild `onStart`. `BuildOptions` is already passed
|
|
973
|
+
* during the plugin's own setup.
|
|
974
|
+
*/
|
|
975
|
+
onBuildStart(callback: () => void | Promise<void>): void;
|
|
976
|
+
/**
|
|
977
|
+
* Called once at bundle end. Dispatched for both success and failure. On
|
|
978
|
+
* failure, the first fatal diagnostic item is wrapped in an `Error` and
|
|
979
|
+
* passed (#2156). In watch mode it is called for the initial build and on
|
|
980
|
+
* every rebuild.
|
|
981
|
+
*
|
|
982
|
+
* Called before `onCloseBundle`.
|
|
983
|
+
*/
|
|
984
|
+
onBuildEnd(callback: (error?: Error) => void | Promise<void>): void;
|
|
985
|
+
/**
|
|
986
|
+
* Called once after output files are written (#2156). Same as Rollup
|
|
987
|
+
* `closeBundle` — used for temp file cleanup, notifying external systems of
|
|
988
|
+
* build completion, etc. In watch mode it is called for the initial build
|
|
989
|
+
* and on every rebuild.
|
|
990
|
+
*/
|
|
991
|
+
onCloseBundle(callback: () => void | Promise<void>): void;
|
|
992
|
+
onAstFunction(options: {
|
|
993
|
+
filter: RegExp;
|
|
994
|
+
}, callback: (info: AstFunctionInfo) => HookResult<AstFunctionResult>): void;
|
|
995
|
+
/**
|
|
996
|
+
* Fills in the match results of `require.context(dir, recursive, filter,
|
|
997
|
+
* mode)` from the host runtime. (#1579) Since ZNTC has no regex executor of
|
|
998
|
+
* its own (#1771), this is delegated to the host's RegExp — Node V8 / Bun
|
|
999
|
+
* JSC.
|
|
1000
|
+
*
|
|
1001
|
+
* `options.filter` applies to `dir` (e.g. `/^\.\/app/` to process only a
|
|
1002
|
+
* specific directory).
|
|
1003
|
+
* Callback return:
|
|
1004
|
+
* - `{ context: string[] }` — array of matched file paths (empty array =
|
|
1005
|
+
* empty context)
|
|
1006
|
+
* - `null`/`undefined` — try the next plugin (if all are null, the graph
|
|
1007
|
+
* emits a require_context_no_handler diagnostic)
|
|
1008
|
+
*
|
|
1009
|
+
* The callback argument `filter` is the regex body of require.context
|
|
1010
|
+
* (without slashes), and `flags` are the regex flags. The host compiles it
|
|
1011
|
+
* with `new RegExp(filter, flags)` and then matches.
|
|
1012
|
+
*/
|
|
1013
|
+
onResolveContext(options: {
|
|
1014
|
+
filter: RegExp;
|
|
1015
|
+
}, callback: (args: {
|
|
1016
|
+
dir: string;
|
|
1017
|
+
recursive: boolean;
|
|
1018
|
+
filter?: string;
|
|
1019
|
+
flags?: string;
|
|
1020
|
+
importer: string;
|
|
1021
|
+
}) => HookResult<{
|
|
1022
|
+
context: string[];
|
|
1023
|
+
}>): void;
|
|
1024
|
+
}
|
|
1025
|
+
export interface AstFunctionInfo {
|
|
1026
|
+
name: string | null;
|
|
1027
|
+
directives: string[];
|
|
1028
|
+
closureVars: string[];
|
|
1029
|
+
params: string[];
|
|
1030
|
+
sourcePath: string;
|
|
1031
|
+
bodyText: string;
|
|
1032
|
+
flags: {
|
|
1033
|
+
async: boolean;
|
|
1034
|
+
generator: boolean;
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
export interface AstFunctionResult {
|
|
1038
|
+
stripDirective?: string;
|
|
1039
|
+
trailingCode?: string[];
|
|
1040
|
+
}
|
|
1041
|
+
export interface BuildResult {
|
|
1042
|
+
outputFiles: OutputFile[];
|
|
1043
|
+
errors: Diagnostic[];
|
|
1044
|
+
warnings: Diagnostic[];
|
|
1045
|
+
metafile?: string;
|
|
1046
|
+
outputCount?: number;
|
|
1047
|
+
rnAssetMetadata?: RnAssetMetadata[];
|
|
1048
|
+
outputsByFormat?: Array<{
|
|
1049
|
+
format: 'esm' | 'cjs' | 'iife' | 'umd' | 'amd';
|
|
1050
|
+
outputFiles: OutputFile[];
|
|
1051
|
+
}>;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Options for building a Vite-style browser application from an HTML entry.
|
|
1055
|
+
*/
|
|
1056
|
+
export interface AppBuildOptions {
|
|
1057
|
+
/** Application root directory used to resolve index.html, public/, and env files. */
|
|
1058
|
+
root?: string;
|
|
1059
|
+
/** Output directory for the production app build. Defaults to "dist". */
|
|
1060
|
+
outdir?: string;
|
|
1061
|
+
/** HTML entry file to scan for module scripts, stylesheets, and static assets. */
|
|
1062
|
+
entryHtml?: string;
|
|
1063
|
+
/** Public assets directory to copy as-is, or false to disable public asset copying. */
|
|
1064
|
+
publicDir?: string | false;
|
|
1065
|
+
/** Base URL prefix used when rewriting HTML and emitted asset URLs. */
|
|
1066
|
+
base?: string;
|
|
1067
|
+
/** Environment mode used for .env resolution and import.meta.env defaults. */
|
|
1068
|
+
mode?: string;
|
|
1069
|
+
/** Directory to load .env files from. Defaults to the application root. */
|
|
1070
|
+
envDir?: string;
|
|
1071
|
+
/** Environment variable prefixes that are exposed to import.meta.env. */
|
|
1072
|
+
envPrefixes?: string[];
|
|
1073
|
+
/** Additional compile-time defines merged into the underlying bundle build. */
|
|
1074
|
+
define?: Record<string, string>;
|
|
1075
|
+
/** Minify emitted JavaScript and CSS when supported by the underlying builder. */
|
|
1076
|
+
minify?: boolean;
|
|
1077
|
+
/** Emit sourcemaps for bundled application assets. */
|
|
1078
|
+
sourcemap?: boolean;
|
|
1079
|
+
/** Enable code splitting for the application bundle. */
|
|
1080
|
+
splitting?: boolean;
|
|
1081
|
+
/** JSX runtime: "automatic" / "automatic-dev" / "classic" / "preserve". */
|
|
1082
|
+
jsx?: 'classic' | 'automatic' | 'automatic-dev' | 'preserve';
|
|
1083
|
+
/** JSX import source for the automatic runtime (e.g. "react", "@emotion/react"). */
|
|
1084
|
+
jsxImportSource?: string;
|
|
1085
|
+
/** Classic-runtime JSX factory (e.g. "React.createElement", "h"). */
|
|
1086
|
+
jsxFactory?: string;
|
|
1087
|
+
/** Classic-runtime JSX fragment (e.g. "React.Fragment"). */
|
|
1088
|
+
jsxFragment?: string;
|
|
1089
|
+
/**
|
|
1090
|
+
* Per-library 1st-party transform (`@next/swc` `compiler`-compatible
|
|
1091
|
+
* surface). Same meaning as in BuildOptions — both bundle / app builds use
|
|
1092
|
+
* the same option representation.
|
|
1093
|
+
*/
|
|
1094
|
+
compiler?: CompilerOptions;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Options for preparing a Vite-style application for the development server.
|
|
1098
|
+
*/
|
|
1099
|
+
export interface AppDevPrepareOptions {
|
|
1100
|
+
/** Application root directory used to resolve index.html, public/, and env files. */
|
|
1101
|
+
root?: string;
|
|
1102
|
+
/** Temporary output directory used by the dev server. Defaults to ".zntc-dev". */
|
|
1103
|
+
outdir?: string;
|
|
1104
|
+
/** HTML entry file to scan for module scripts, stylesheets, and static assets. */
|
|
1105
|
+
entryHtml?: string;
|
|
1106
|
+
/** Public assets directory to copy as-is, or false to disable public asset copying. */
|
|
1107
|
+
publicDir?: string | false;
|
|
1108
|
+
/** Base URL prefix used when rewriting dev HTML and asset URLs. */
|
|
1109
|
+
base?: string;
|
|
1110
|
+
/** Environment mode used for .env resolution. Defaults to "development". */
|
|
1111
|
+
mode?: string;
|
|
1112
|
+
/** Directory to load .env files from. Defaults to the application root. */
|
|
1113
|
+
envDir?: string;
|
|
1114
|
+
/** Environment variable prefixes that are exposed to import.meta.env. */
|
|
1115
|
+
envPrefixes?: string[];
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Result produced after preparing an application entry for dev-server bundling.
|
|
1119
|
+
*/
|
|
1120
|
+
export interface AppDevPrepareResult {
|
|
1121
|
+
/** Prepared JavaScript entry path that the dev server should bundle and serve. */
|
|
1122
|
+
entryPath: string;
|
|
1123
|
+
/** Number of files emitted while preparing the dev app, when available. */
|
|
1124
|
+
outputCount?: number;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Runs bundling asynchronously. Does not block the event loop.
|
|
1128
|
+
* Promise/async hooks of JS plugins are supported in this function.
|
|
1129
|
+
*
|
|
1130
|
+
* Plugin lifecycle call order: buildStart → (NAPI build) → buildEnd → write →
|
|
1131
|
+
* closeBundle.
|
|
1132
|
+
* `buildEnd` is called even on NAPI failure, with the error argument passed
|
|
1133
|
+
* (same as Rollup).
|
|
1134
|
+
* `closeBundle` is called only on a successful write.
|
|
1135
|
+
*/
|
|
1136
|
+
export declare function build(options: BuildOptions): Promise<BuildResult>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Runs bundling synchronously.
|
|
1139
|
+
* JS plugins support only sync hooks. Promise/async hooks fail with a
|
|
1140
|
+
* plugin_error.
|
|
1141
|
+
*/
|
|
1142
|
+
export declare function buildSync(options: BuildOptions): BuildResult;
|
|
1143
|
+
export interface OutputOptions {
|
|
1144
|
+
format?: 'esm' | 'cjs' | 'iife' | 'umd' | 'amd';
|
|
1145
|
+
dir?: string;
|
|
1146
|
+
file?: string;
|
|
1147
|
+
globals?: Record<string, string>;
|
|
1148
|
+
}
|
|
1149
|
+
export declare class BuildInstance {
|
|
1150
|
+
#private;
|
|
1151
|
+
constructor(base: BuildOptions);
|
|
1152
|
+
get closed(): boolean;
|
|
1153
|
+
write(output?: OutputOptions): Promise<BuildResult>;
|
|
1154
|
+
generate(output?: OutputOptions): Promise<BuildResult>;
|
|
1155
|
+
close(): Promise<void>;
|
|
1156
|
+
}
|
|
1157
|
+
export declare function zntc(options: BuildOptions): Promise<BuildInstance>;
|
|
1158
|
+
export declare function buildAppSync(options?: AppBuildOptions): BuildResult;
|
|
1159
|
+
export declare function prepareAppDevSync(options?: AppDevPrepareOptions): AppDevPrepareResult;
|
|
1160
|
+
/**
|
|
1161
|
+
* Releases resources (the NAPI module is released automatically on process
|
|
1162
|
+
* exit). Kept for API compatibility.
|
|
1163
|
+
*/
|
|
1164
|
+
export declare function close(): void;
|
|
1165
|
+
/**
|
|
1166
|
+
* Benchmark options. One of `source` or `file` must be specified.
|
|
1167
|
+
*/
|
|
1168
|
+
export interface BenchmarkOptions {
|
|
1169
|
+
/** Source code string (one of this or file). */
|
|
1170
|
+
source?: string;
|
|
1171
|
+
/** File path (one of this or source). */
|
|
1172
|
+
file?: string;
|
|
1173
|
+
/** filename (used together with source, for extension detection). */
|
|
1174
|
+
filename?: string;
|
|
1175
|
+
/**
|
|
1176
|
+
* List of profile categories to measure (required, non-empty).
|
|
1177
|
+
* e.g. `["parse"]`, `["scan", "parse", "transform"]`, `["transform.jsx"]`.
|
|
1178
|
+
* `all` / `none` are not allowed — concrete phase names only.
|
|
1179
|
+
*/
|
|
1180
|
+
phases: string[];
|
|
1181
|
+
/** Number of iterations (default 100). */
|
|
1182
|
+
iterations?: number;
|
|
1183
|
+
/** Warmup iterations (default 10). */
|
|
1184
|
+
warmup?: number;
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Statistics for a single phase (all values in ms).
|
|
1188
|
+
*/
|
|
1189
|
+
export interface BenchmarkPhaseStats {
|
|
1190
|
+
samples: number;
|
|
1191
|
+
mean_ms: number;
|
|
1192
|
+
median_ms: number;
|
|
1193
|
+
p95_ms: number;
|
|
1194
|
+
p99_ms: number;
|
|
1195
|
+
min_ms: number;
|
|
1196
|
+
max_ms: number;
|
|
1197
|
+
stddev_ms: number;
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Benchmark result — statistics per category specified in the `phases` option.
|
|
1201
|
+
*/
|
|
1202
|
+
export interface BenchmarkResult {
|
|
1203
|
+
phases: Record<string, BenchmarkPhaseStats>;
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Runs a specific phase N times and returns statistics
|
|
1207
|
+
* (mean/median/p95/p99/stddev/min/max).
|
|
1208
|
+
*
|
|
1209
|
+
* The NAPI counterpart of CLI `zntc bench --phase=...` — uses the same engine.
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```ts
|
|
1213
|
+
* import { benchmark } from "@zntc/core";
|
|
1214
|
+
*
|
|
1215
|
+
* const result = benchmark({
|
|
1216
|
+
* file: "./src/App.tsx",
|
|
1217
|
+
* phases: ["parse"],
|
|
1218
|
+
* iterations: 100,
|
|
1219
|
+
* });
|
|
1220
|
+
* console.log(result.phases.parse.mean_ms); // 42.3
|
|
1221
|
+
* ```
|
|
1222
|
+
*/
|
|
1223
|
+
export declare function benchmark(options: BenchmarkOptions): BenchmarkResult;
|
|
1224
|
+
/**
|
|
1225
|
+
* Converts a Rollup/Vite-style plugin into a ZNTC plugin.
|
|
1226
|
+
*
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* import { vitePlugin } from "@zntc/core";
|
|
1230
|
+
*
|
|
1231
|
+
* const result = await build({
|
|
1232
|
+
* entryPoints: ["src/index.ts"],
|
|
1233
|
+
* plugins: [
|
|
1234
|
+
* vitePlugin({
|
|
1235
|
+
* name: "my-rollup-plugin",
|
|
1236
|
+
* resolveId(source) { ... },
|
|
1237
|
+
* load(id) { ... },
|
|
1238
|
+
* transform(code, id) { ... },
|
|
1239
|
+
* }),
|
|
1240
|
+
* ],
|
|
1241
|
+
* });
|
|
1242
|
+
* ```
|
|
1243
|
+
*/
|
|
1244
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
1245
|
+
/** vite 4+ 신형 hook object. plugin 작성자가 hook 단위로 filter 를 선언하는 형식.
|
|
1246
|
+
* ZNTC 는 현재 filter 를 native 단계에서 활용하지 않고 handler 만 추출해 호출한다. */
|
|
1247
|
+
type HookObject<F extends (...args: never[]) => unknown> = {
|
|
1248
|
+
filter?: unknown;
|
|
1249
|
+
order?: 'pre' | 'post' | null;
|
|
1250
|
+
handler: F;
|
|
1251
|
+
};
|
|
1252
|
+
type Hook<F extends (...args: never[]) => unknown> = F | HookObject<F>;
|
|
1253
|
+
export interface RollupPluginContext {
|
|
1254
|
+
/** Throw an error from within the plugin. Rollup `this.error`-compatible. */
|
|
1255
|
+
error(error: unknown): never;
|
|
1256
|
+
/** Print a warning to the console. Rollup `this.warn`-compatible — does not stop the build. */
|
|
1257
|
+
warn(message: unknown): void;
|
|
1258
|
+
/** Register an additional file to watch in watch mode. Currently a no-op (graph mutation not supported). */
|
|
1259
|
+
addWatchFile(id: string): void;
|
|
1260
|
+
/** Module resolve. Currently unsupported — throws an Error when called to notify the plugin author. */
|
|
1261
|
+
resolve(source: string, importer?: string | null, options?: unknown): Promise<{
|
|
1262
|
+
id: string;
|
|
1263
|
+
external?: boolean;
|
|
1264
|
+
} | null>;
|
|
1265
|
+
/** Emit an additional asset/chunk. Currently unsupported — throws an Error when called. */
|
|
1266
|
+
emitFile(file: unknown): string;
|
|
1267
|
+
}
|
|
1268
|
+
type ResolveIdResult = string | null | undefined | void | {
|
|
1269
|
+
id: string;
|
|
1270
|
+
external?: boolean;
|
|
1271
|
+
};
|
|
1272
|
+
type LoadResult = string | null | undefined | void | {
|
|
1273
|
+
code: string;
|
|
1274
|
+
map?: unknown;
|
|
1275
|
+
};
|
|
1276
|
+
type TransformResult = string | null | undefined | void | {
|
|
1277
|
+
code: string;
|
|
1278
|
+
map?: unknown;
|
|
1279
|
+
};
|
|
1280
|
+
type RenderChunkResult = string | null | undefined | void | {
|
|
1281
|
+
code: string;
|
|
1282
|
+
};
|
|
1283
|
+
export interface RollupPlugin {
|
|
1284
|
+
name: string;
|
|
1285
|
+
/** Rollup `resolveId`. Both a function and a vite 4+ new-style hook object `{ filter, handler }` are allowed. */
|
|
1286
|
+
resolveId?: Hook<(this: RollupPluginContext, source: string, importer?: string | null) => MaybePromise<ResolveIdResult>>;
|
|
1287
|
+
load?: Hook<(this: RollupPluginContext, id: string) => MaybePromise<LoadResult>>;
|
|
1288
|
+
transform?: Hook<(this: RollupPluginContext, code: string, id: string) => MaybePromise<TransformResult>>;
|
|
1289
|
+
renderChunk?: Hook<(this: RollupPluginContext, code: string, chunk: string) => MaybePromise<RenderChunkResult>>;
|
|
1290
|
+
generateBundle?: Hook<(this: RollupPluginContext, outputs: OutputFile[]) => MaybePromise<void>>;
|
|
1291
|
+
/** Once at bundle start. esbuild `onStart` / Rollup `buildStart`-compatible
|
|
1292
|
+
* (#2156). ZNTC calls it with no arguments (esbuild style) — if a Rollup
|
|
1293
|
+
* plugin expects the `options` argument, capture it in the plugin's own
|
|
1294
|
+
* closure. */
|
|
1295
|
+
buildStart?: Hook<(this: RollupPluginContext) => MaybePromise<void>>;
|
|
1296
|
+
/** Once at bundle end. Rollup `buildEnd`-compatible — if there is an error, the build fails. */
|
|
1297
|
+
buildEnd?: Hook<(this: RollupPluginContext, error?: Error) => MaybePromise<void>>;
|
|
1298
|
+
/** After output files are written. Rollup `closeBundle`-compatible. */
|
|
1299
|
+
closeBundle?: Hook<(this: RollupPluginContext) => MaybePromise<void>>;
|
|
1300
|
+
}
|
|
1301
|
+
export declare function vitePlugin(rollupPlugin: RollupPlugin): ZntcPlugin;
|
|
1302
|
+
/**
|
|
1303
|
+
* Bundles in watch mode. On file changes: incremental rebuild + HMR diff.
|
|
1304
|
+
* Calls the onReady callback when the initial build completes, and onRebuild
|
|
1305
|
+
* on each rebuild.
|
|
1306
|
+
*
|
|
1307
|
+
* Plugin lifecycle call order: buildStart → (NAPI build/rebuild) → buildEnd
|
|
1308
|
+
* → onReady/onRebuild → closeBundle. closeBundle is called even if there is no
|
|
1309
|
+
* callback or it throws.
|
|
1310
|
+
*/
|
|
1311
|
+
export declare function watch(options: BuildOptions): WatchHandle;
|