@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,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zntc.config.{ts,mts,cts,mjs,js,cjs,json} 로더.
|
|
3
|
+
*
|
|
4
|
+
* `.ts/.mts/.cts` 는 NAPI `transpile()` 로 self-compile 후 dynamic import.
|
|
5
|
+
* `.mjs/.js/.cjs` 는 직접 dynamic import. `.json` 은 readFileSync + JSON.parse.
|
|
6
|
+
*
|
|
7
|
+
* tmp 파일은 config 옆에 작성해 사용자의 node_modules resolution 을 보존한다
|
|
8
|
+
* (esbuild `esbuild.config.bundled-*.mjs` 패턴).
|
|
9
|
+
*/
|
|
10
|
+
import type { BuildOptions } from '../index';
|
|
11
|
+
/**
|
|
12
|
+
* config 객체 형태 — 모든 BuildOptions 의 부분 집합.
|
|
13
|
+
*
|
|
14
|
+
* `extends` (`#2108`) 는 다른 config 파일을 base 로 상속받는 식별자 — 단일 string
|
|
15
|
+
* 또는 배열. config-loader 가 로드 시 자동 해석하므로 최종 사용자 config 에는
|
|
16
|
+
* 노출되지 않는다 (resolveExtends 가 strip).
|
|
17
|
+
*/
|
|
18
|
+
export type UserConfig = Partial<BuildOptions> & {
|
|
19
|
+
extends?: string | string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 함수형 config 호출 시 주입되는 컨텍스트 (Vite 호환 형태).
|
|
23
|
+
*
|
|
24
|
+
* - `command`: CLI 모드. `bundle` (default), `serve`, `watch`.
|
|
25
|
+
* - `mode`: `--mode <name>` 으로 지정. 미지정 시 command 별 기본값
|
|
26
|
+
* (`serve`/`watch` → `development`, 그 외 → `production`).
|
|
27
|
+
* - `env`: `process.env` + `.env*` merge 결과. CLI 경로에서는 `loadEnv()` prefix 필터
|
|
28
|
+
* 결과를 shell env 위에 합쳐 전달한다.
|
|
29
|
+
*/
|
|
30
|
+
export interface ConfigEnv {
|
|
31
|
+
command: 'bundle' | 'serve' | 'watch';
|
|
32
|
+
mode: string;
|
|
33
|
+
env: Record<string, string | undefined>;
|
|
34
|
+
}
|
|
35
|
+
/** 함수형 config — `defineConfig(({ command, mode, env }) => ...)` 형태. */
|
|
36
|
+
export type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>;
|
|
37
|
+
/** config 파일이 export 가능한 형태 — 객체 또는 함수. */
|
|
38
|
+
export type UserConfigInput = UserConfig | UserConfigFn;
|
|
39
|
+
/**
|
|
40
|
+
* 자동 탐색 우선순위. 동일 디렉토리에 다중 확장자 존재 시 첫 매치 반환.
|
|
41
|
+
* 사용자가 의도적으로 여러 형식을 두는 경우는 거의 없으므로 silent precedence 로 충분.
|
|
42
|
+
*
|
|
43
|
+
* 같은 배열에서 `TS_EXTS`/`JS_EXTS` 를 derive — 새 확장자 추가 시 한 곳만 고침.
|
|
44
|
+
*/
|
|
45
|
+
export declare const CONFIG_EXT_PRIORITY: readonly [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
|
|
46
|
+
/**
|
|
47
|
+
* config 파일을 로드한다. 확장자에 따라 self-compile 또는 직접 import.
|
|
48
|
+
*
|
|
49
|
+
* 존재 여부는 사전 stat 으로 확인하지 않고 실제 read/import 의 ENOENT 를 catch
|
|
50
|
+
* 한다 — TOCTOU 회피 + 1 syscall 절감.
|
|
51
|
+
*
|
|
52
|
+
* 함수형 config 가 export 됐으면 `env` 인자를 전달해 호출하고 반환된 객체를 사용한다.
|
|
53
|
+
* `env` 미제공 시 적절한 기본값 (`command: "bundle", mode: "production"`) 으로 호출.
|
|
54
|
+
*
|
|
55
|
+
* @throws 파일이 없거나, 확장자가 지원되지 않거나, 컴파일/평가가 실패하면 throw.
|
|
56
|
+
*/
|
|
57
|
+
export declare function loadConfig(filePath: string, env?: ConfigEnv): Promise<UserConfig>;
|
|
58
|
+
/**
|
|
59
|
+
* 함수형 config / workspace 가 `env` 인자를 안 받았을 때 사용할 기본 컨텍스트.
|
|
60
|
+
*
|
|
61
|
+
* - `command: "bundle"` — production 빌드를 가정 (CLI 주 용도).
|
|
62
|
+
* - `mode: "production"` — `--mode` 미지정 시의 default.
|
|
63
|
+
* - `env: process.env` — `import.meta.env.*` 정적 치환에서도 동일 source 사용.
|
|
64
|
+
*
|
|
65
|
+
* `loadConfig` 와 `loadWorkspace` 가 공유 — 한 곳에서만 default 정의해 drift 방지.
|
|
66
|
+
*
|
|
67
|
+
* @returns 새 `ConfigEnv` 객체 (호출마다 새 참조 — 호출자가 mutate 해도 안전).
|
|
68
|
+
*/
|
|
69
|
+
export declare function defaultConfigEnv(): ConfigEnv;
|
|
70
|
+
/**
|
|
71
|
+
* `loadModuleDefault` 가 받는 모듈 종류 라벨.
|
|
72
|
+
*
|
|
73
|
+
* - 에러 메시지에 라벨로 삽입 (`"config file not found"` vs `"workspace file not found"`).
|
|
74
|
+
* - tmp 컴파일 파일명에도 사용 (`.zntc-config.bundled-*.mjs` / `.zntc-workspace.bundled-*.mjs`).
|
|
75
|
+
*
|
|
76
|
+
* 새 모듈 종류 추가 시 이 union 을 확장하고 호출 사이트도 맞춰 갱신.
|
|
77
|
+
*/
|
|
78
|
+
export type ModuleKind = 'config' | 'workspace';
|
|
79
|
+
/**
|
|
80
|
+
* 임의 모듈 파일 (TS/JS/JSON) 의 default export 를 로드. `loadConfig` 의 디스패치 로직을
|
|
81
|
+
* generic 화 — workspace (#2111) 등 config 와 다른 export shape 에서 재사용.
|
|
82
|
+
*
|
|
83
|
+
* 분기:
|
|
84
|
+
* - `.json`: `readFileSync` + `JSON.parse`
|
|
85
|
+
* - `.ts/.mts/.cts`: NAPI `transpile()` self-compile → tmp `.mjs` → dynamic import (cleanup 포함)
|
|
86
|
+
* - `.mjs/.js/.cjs`: 직접 dynamic import
|
|
87
|
+
*
|
|
88
|
+
* 존재 여부는 사전 stat 으로 확인하지 않고 read/import 의 ENOENT 를 catch — TOCTOU 회피
|
|
89
|
+
* + 1 syscall 절감.
|
|
90
|
+
*
|
|
91
|
+
* @template T 호출자가 기대하는 default export 타입. 런타임 검증은 `allowArray` 외에는 없음.
|
|
92
|
+
* @param absPath 절대 경로.
|
|
93
|
+
* @param kind 모듈 종류 — 에러 메시지/임시 파일명에 사용.
|
|
94
|
+
* @param options `allowArray: true` 면 default export 가 배열일 때도 통과 (workspace 용).
|
|
95
|
+
* @returns default export (또는 default 가 없으면 namespace 객체).
|
|
96
|
+
*
|
|
97
|
+
* @throws `@zntc/core: <kind> file not found: <path>` — 파일 부재
|
|
98
|
+
* @throws `@zntc/core: failed to parse JSON <kind> ...` — JSON 파싱 실패
|
|
99
|
+
* @throws `@zntc/core: <kind> compile failed in ...` — TS self-compile 실패 (ZNTC parser 에러)
|
|
100
|
+
* @throws `@zntc/core: <kind> must export an object or function (got X)` — default 가 잘못된 타입
|
|
101
|
+
* @throws `@zntc/core: unsupported <kind> extension "<ext>"` — 지원 안 하는 확장자
|
|
102
|
+
*/
|
|
103
|
+
export declare function loadModuleDefault<T>(absPath: string, kind: ModuleKind, options?: {
|
|
104
|
+
allowArray?: boolean;
|
|
105
|
+
}): Promise<T>;
|
|
106
|
+
/**
|
|
107
|
+
* 절대 경로를 `file://` URL 로 dynamic import 한 뒤 default export (없으면
|
|
108
|
+
* namespace 객체) 를 반환한다. 함수형 config 도 허용하므로 객체 또는 함수만 통과.
|
|
109
|
+
*
|
|
110
|
+
* `pathToFileURL` 으로 Windows 절대경로 (드라이브 문자) 를 안전하게 처리.
|
|
111
|
+
* config 로더와 CLI 의 `--plugin <path>` 로더가 공유.
|
|
112
|
+
*
|
|
113
|
+
* 같은 프로세스에서 다중 reload 가 필요한 watch (#2107) 는 별도 cache-bust 적용 예정.
|
|
114
|
+
*
|
|
115
|
+
* `options.allowArray` 가 `true` 면 array default export 도 통과 — workspace 처럼
|
|
116
|
+
* top-level array 가 정상인 호출자용. 기본값은 `false` (config/플러그인 호환).
|
|
117
|
+
*/
|
|
118
|
+
export declare function importAndResolveDefault<T = UserConfig>(absPath: string, options?: {
|
|
119
|
+
allowArray?: boolean;
|
|
120
|
+
}): Promise<T>;
|
|
121
|
+
/**
|
|
122
|
+
* 파일 부재를 정상 케이스로 처리하는 read. ENOENT/ENOTDIR 면 null, 그 외는 throw.
|
|
123
|
+
* `.env` 같은 optional 파일 로딩 (`load-env.ts`) 에서 사용.
|
|
124
|
+
*
|
|
125
|
+
* ENOTDIR: 부모 경로가 디렉토리가 아닌 케이스 (예: envDir 가 실수로 파일을 가리키는 경우).
|
|
126
|
+
* optional lookup 의 의미상 "없음"과 동등하므로 swallow.
|
|
127
|
+
*/
|
|
128
|
+
export declare function readFileIfExists(absPath: string): string | null;
|
|
129
|
+
/**
|
|
130
|
+
* cwd 에서 `zntc.config.*` 자동 탐색. 우선순위는 `CONFIG_EXT_PRIORITY` 참조.
|
|
131
|
+
*
|
|
132
|
+
* 동기 stat (`existsSync`) 사용 — CLI 시작 시 한 번만 호출되므로 비용 무시 가능.
|
|
133
|
+
* parent 디렉토리 traversal 은 모노레포 워크스페이스 (#2111 / Phase 3-4) 에서 처리.
|
|
134
|
+
*
|
|
135
|
+
* Note: Zig CLI (`src/main.zig:293` `applyZntcConfigJson`) 은 현재 `.json` 만
|
|
136
|
+
* 직접 처리한다. 다른 확장자는 JS CLI (`zntc.mjs`) 만 자동 탐색하므로 두 경로의
|
|
137
|
+
* 동작이 의도적으로 갈린다. 통합은 #2105 (Phase 2-3 bundler 옵션 매핑) 에서.
|
|
138
|
+
*/
|
|
139
|
+
export declare function findConfigPath(cwd: string): string | null;
|
|
140
|
+
/**
|
|
141
|
+
* mode-specific config 파일 자동 탐색 — `zntc.config.${mode}.{ext}` 형태 (#2110).
|
|
142
|
+
*
|
|
143
|
+
* Vite 의 mode 별 config 패턴: base `zntc.config.ts` 가 default, `zntc.config.production.ts`
|
|
144
|
+
* 같은 mode-specific 파일이 base 를 부분 override. mode 가 비어있거나 매칭 파일 없으면 null.
|
|
145
|
+
*/
|
|
146
|
+
export declare function findModeConfigPath(cwd: string, mode: string): string | null;
|
|
147
|
+
/**
|
|
148
|
+
* base config + mode-specific config 머지. mode 가 base 를 override.
|
|
149
|
+
*
|
|
150
|
+
* 머지 정책 (Vite 호환):
|
|
151
|
+
* - scalar / string: mode 값이 정의됐으면 그것 사용
|
|
152
|
+
* - 배열: mode 가 정의됐으면 base 를 완전 대체 (concat 안 함 — 의도 명확화)
|
|
153
|
+
* - 객체 (`define`/`alias`/`loader`): shallow merge — base 키 + mode 키 (mode 우선)
|
|
154
|
+
*
|
|
155
|
+
* `plugins` 는 concat (Vite 와 일치 — 둘 다 적용).
|
|
156
|
+
*/
|
|
157
|
+
export declare function mergeUserConfigs(base: UserConfig, mode: UserConfig): UserConfig;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.env` 파일 로더 (Vite 호환).
|
|
3
|
+
*
|
|
4
|
+
* 4단계 우선순위 (낮은 → 높은) 로 머지:
|
|
5
|
+
* 1. `.env` (general, committed)
|
|
6
|
+
* 2. `.env.local` (general, gitignored)
|
|
7
|
+
* 3. `.env.${mode}` (mode-specific, committed)
|
|
8
|
+
* 4. `.env.${mode}.local` (mode-specific, gitignored)
|
|
9
|
+
*
|
|
10
|
+
* `prefixes` 로 시작하는 키만 반환. default 는 `["VITE_", "ZNTC_"]` 두 개:
|
|
11
|
+
* - `VITE_` — Vite 호환 prefix (사용자가 Vite 에서 마이그레이션 시 동일 동작)
|
|
12
|
+
* - `ZNTC_` — ZNTC 전용 prefix (Vite 와 의도적으로 구분된 키 노출 시)
|
|
13
|
+
*
|
|
14
|
+
* 빈 문자열 prefix `""` 를 포함하면 전체 노출 — 주의해서 사용.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* `mode` 와 `envDir` 기준으로 `.env*` 파일 4종을 우선순위대로 로드 + 머지하고,
|
|
18
|
+
* `prefixes` 로 시작하는 키만 반환.
|
|
19
|
+
*
|
|
20
|
+
* @param mode `--mode <name>` 으로 전달되는 값. 보통 `"production"` / `"development"`.
|
|
21
|
+
* @param envDir `.env` 파일을 찾을 디렉토리. CLI 의 cwd 기본.
|
|
22
|
+
* @param prefixes 노출할 키 prefix 목록. default `["VITE_", "ZNTC_"]`. 단일 string 도 허용.
|
|
23
|
+
*/
|
|
24
|
+
export declare function loadEnv(mode: string, envDir: string, prefixes?: string | string[]): Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* `loadEnv` 결과 + 빌드 컨텍스트를 `import.meta.env.*` define 으로 변환.
|
|
27
|
+
*
|
|
28
|
+
* `import.meta.env.MODE` / `PROD` / `DEV` / `SSR` 를 자동 주입한다 (Vite 호환).
|
|
29
|
+
* 사용자 정의 키는 모두 `JSON.stringify` 로 직렬화해 ZNTC define 에 안전한 리터럴 형태로 전달.
|
|
30
|
+
*/
|
|
31
|
+
export declare function envToDefine(env: Record<string, string>, mode: string, baseUrl?: string): Record<string, string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NAPI publish 의 platform 매트릭스 단일 source.
|
|
3
|
+
*
|
|
4
|
+
* 새 platform 추가 시 (예: musl, riscv, android):
|
|
5
|
+
* 1. 여기에 entry 추가
|
|
6
|
+
* 2. `packages/core-{name}/` skeleton 생성 (package.json + README)
|
|
7
|
+
* 3. `packages/core/index.ts:getPlatformPackage()` 매핑 추가
|
|
8
|
+
* 4. `.github/workflows/release.yml` 매트릭스에 추가 (이 파일과 sync — YAML 정적 한계)
|
|
9
|
+
* 5. `.github/workflows/ci.yml:napi-package-smoke` 매트릭스도 sync
|
|
10
|
+
*
|
|
11
|
+
* win32 정책: napi-rs/swc/oxc 컨벤션 따름 — MSVC 만 publish, mingw/gnu 안 함
|
|
12
|
+
* (GHA windows-latest = MSVC node 라 install 매칭 자체가 의미 없음).
|
|
13
|
+
*/
|
|
14
|
+
export interface PlatformTarget {
|
|
15
|
+
/** sub-package suffix (e.g. "linux-x64-gnu"). `@zntc/core-${name}` 가 npm 이름. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** npm `os` 필드 — install 매칭. */
|
|
18
|
+
npmOs: 'linux' | 'darwin' | 'win32';
|
|
19
|
+
/** npm `cpu` 필드. */
|
|
20
|
+
npmCpu: 'x64' | 'arm64' | 'ia32';
|
|
21
|
+
/** npm `libc` 필드 (linux 만). */
|
|
22
|
+
npmLibc?: 'glibc' | 'musl';
|
|
23
|
+
/** `zig build napi -Dtarget=<zigTarget>` */
|
|
24
|
+
zigTarget: string;
|
|
25
|
+
/** GitHub Actions runner — release.yml/ci.yml 매트릭스에서도 동일 사용. */
|
|
26
|
+
ghaRunner: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const PLATFORMS: PlatformTarget[];
|
|
29
|
+
export declare function subPackageName(platform: PlatformTarget): string;
|
|
30
|
+
export declare function subPackageDir(platform: PlatformTarget): string;
|
|
31
|
+
/**
|
|
32
|
+
* findAddon() 의 "Supported: ..." 에러 메시지용 — PLATFORMS 변경 시 자동 반영.
|
|
33
|
+
* 동일 (os, cpu) 에 glibc/musl 둘 다 있으면 "(glibc/musl)" 로 합쳐 표기.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatSupportedPlatforms(): string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
export type RuntimePolyfillMode = 'auto' | 'usage' | 'entry';
|
|
3
|
+
export type RuntimePolyfillProvider = 'core-js';
|
|
4
|
+
export interface RuntimePolyfillOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Runtime polyfill injection strategy.
|
|
7
|
+
*
|
|
8
|
+
* `auto` and `usage` select from graph-detected API usage, while `entry`
|
|
9
|
+
* injects all target-required core-js ES/Web modules.
|
|
10
|
+
*/
|
|
11
|
+
mode?: RuntimePolyfillMode;
|
|
12
|
+
/** Polyfill provider. Only `core-js` is currently supported. */
|
|
13
|
+
provider?: RuntimePolyfillProvider;
|
|
14
|
+
/**
|
|
15
|
+
* Browserslist targets for core-js-compat, matching Rspack/SWC `env.targets`.
|
|
16
|
+
*
|
|
17
|
+
* Examples: `["chrome >= 87", "edge >= 88", "firefox >= 78", "safari >= 14"]`.
|
|
18
|
+
* Physical device names such as `"iPhone 8"` and compact shorthands such as
|
|
19
|
+
* `"ios12"` are rejected.
|
|
20
|
+
*/
|
|
21
|
+
targets?: string | string[];
|
|
22
|
+
/** core-js version used for compatibility calculation, matching Rspack/SWC `env.coreJs`. */
|
|
23
|
+
coreJs?: string;
|
|
24
|
+
/** Additional core-js modules to force into the runtime prelude. */
|
|
25
|
+
include?: string[];
|
|
26
|
+
/** core-js modules to remove after target and usage calculation. */
|
|
27
|
+
exclude?: string[];
|
|
28
|
+
/** Include proposal polyfills when querying core-js-compat. */
|
|
29
|
+
proposals?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type RuntimePolyfillsOption = 'off' | RuntimePolyfillMode | RuntimePolyfillOptions;
|
|
32
|
+
export interface RuntimePolyfillBuildOptions {
|
|
33
|
+
entryPoints: string[];
|
|
34
|
+
platform?: string;
|
|
35
|
+
target?: string;
|
|
36
|
+
browserslist?: string | string[];
|
|
37
|
+
runtimePolyfills?: RuntimePolyfillsOption;
|
|
38
|
+
coreJs?: string;
|
|
39
|
+
runBeforeMain?: string[];
|
|
40
|
+
resolveExtensions?: string[];
|
|
41
|
+
}
|
|
42
|
+
interface NormalizedRuntimePolyfills {
|
|
43
|
+
mode: RuntimePolyfillMode;
|
|
44
|
+
provider: RuntimePolyfillProvider;
|
|
45
|
+
targets: CoreJsTargets;
|
|
46
|
+
include: string[];
|
|
47
|
+
exclude: string[];
|
|
48
|
+
proposals: boolean;
|
|
49
|
+
coreJsVersion?: string;
|
|
50
|
+
}
|
|
51
|
+
type CoreJsTargetObject = Record<string, string | number>;
|
|
52
|
+
type CoreJsTargets = string | string[] | CoreJsTargetObject;
|
|
53
|
+
type RuntimeRequire = ReturnType<typeof createRequire>;
|
|
54
|
+
type RuntimePolyfillFeature = string;
|
|
55
|
+
export interface ResolvedRuntimeModule {
|
|
56
|
+
module: string;
|
|
57
|
+
path: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ResolvedRuntimeCandidate extends ResolvedRuntimeModule {
|
|
60
|
+
feature: RuntimePolyfillFeature;
|
|
61
|
+
}
|
|
62
|
+
/** NAPI 로 전달되는 단일 plan 객체. usage 모드는 candidates, entry 모드는 entry 를 채운다. */
|
|
63
|
+
export interface RuntimePolyfillNativePlan {
|
|
64
|
+
mode: 'usage' | 'entry';
|
|
65
|
+
candidates?: readonly ResolvedRuntimeCandidate[];
|
|
66
|
+
entry?: readonly ResolvedRuntimeModule[];
|
|
67
|
+
include?: readonly ResolvedRuntimeModule[];
|
|
68
|
+
exclude?: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** @internal */
|
|
71
|
+
export declare const __runtimePolyfillTestHooks: {
|
|
72
|
+
reset(): void;
|
|
73
|
+
setRuntimeRequire(runtimeRequire: RuntimeRequire | null): void;
|
|
74
|
+
};
|
|
75
|
+
/** @internal — Zig 매핑 테이블과의 sync 검증용. 외부 사용자는 사용 금지. */
|
|
76
|
+
export declare const __runtimePolyfillTestInternals: {
|
|
77
|
+
readonly featureModules: Readonly<typeof RUNTIME_POLYFILL_FEATURE_MODULES>;
|
|
78
|
+
};
|
|
79
|
+
declare const RUNTIME_POLYFILL_FEATURE_MODULES: readonly {
|
|
80
|
+
feature: RuntimePolyfillFeature;
|
|
81
|
+
module: string;
|
|
82
|
+
}[];
|
|
83
|
+
export declare function isEsTarget(target: string | undefined): boolean;
|
|
84
|
+
export declare function normalizeRuntimeTargets(targets: string | string[]): string | string[];
|
|
85
|
+
export declare function normalizeRuntimePolyfillOptions(options: RuntimePolyfillBuildOptions): NormalizedRuntimePolyfills | null;
|
|
86
|
+
export declare function computeCoreJsCompatModules(targets: CoreJsTargets, modules: string[] | RegExp, options?: {
|
|
87
|
+
version?: string;
|
|
88
|
+
proposals?: boolean;
|
|
89
|
+
}): string[];
|
|
90
|
+
export declare function applyRuntimePolyfillsToNapiOptions(napiOptions: Record<string, unknown>, options: RuntimePolyfillBuildOptions): {
|
|
91
|
+
cleanup: () => void;
|
|
92
|
+
modules: string[];
|
|
93
|
+
};
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema sync 테스트 공통 allowlist — `BuildOptionsCommon` 에 정의되어 있지만 사용자가 직접
|
|
3
|
+
* 명시할 일 없는 **NAPI/internal/번들러-전용** 옵션 집합.
|
|
4
|
+
*
|
|
5
|
+
* 사용처:
|
|
6
|
+
* - `packages/core/src/typo-suggest.test.ts`: `KNOWN_CONFIG_KEYS` 미포함 정당화 (사용자가
|
|
7
|
+
* `zntc.config.*` 에 적을 일 없으므로 typo 검출 대상 아님)
|
|
8
|
+
* - `packages/core/bin/zntc-cli-schema-sync.test.ts`: CLI flag 미노출 정당화
|
|
9
|
+
*
|
|
10
|
+
* Zig DTO sync (`src/transpile_options_dto_test.zig:ts_buildoptions_only_allowlist`) 는 별
|
|
11
|
+
* 언어라 별도 유지 — 새 internal 키 추가 시 양쪽 모두 갱신 필요. (TypeScript Compiler API
|
|
12
|
+
* 도입 + codegen 으로 single source 화는 ROI 낮아 보류, future work.)
|
|
13
|
+
*
|
|
14
|
+
* 새 internal 키 추가 시 여기 1곳에만 등록 → 두 TS 테스트 모두 자동 통과. 각 테스트의 추가
|
|
15
|
+
* allowlist (테스트만의 특수 케이스) 는 그대로 유지.
|
|
16
|
+
*/
|
|
17
|
+
export declare const NAPI_INTERNAL_ONLY_KEYS: readonly ["allowOverwrite", "assetRegistry", "blockList", "collectModuleCodes", "configurableExports", "devMode", "emitDiskSourcemap", "entryErrorGuard", "experimentalCodeCache", "fallback", "globalIdentifiers", "onReady", "onRebuild", "polyfills", "reactRefresh", "rootDir", "runBeforeMain", "scopeHoist", "silentConsoleErrorPatterns", "strictExecutionOrder", "watchExclude", "watchFolders", "watchInclude", "workletPluginVersion", "workletTransform", "write"];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typo 검출 및 "did you mean ...?" 제안 (#2109).
|
|
3
|
+
*
|
|
4
|
+
* `levenshtein` 으로 알려진 옵션 키와 비교해 거리 ≤ threshold 인 가장 가까운
|
|
5
|
+
* 키를 제안. config 파일의 unknown 키, CLI flag 의 unknown name 둘 다 사용.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* `unknown` 과 가장 가까운 `known` 키 중 거리 `<= threshold` 인 것 반환.
|
|
9
|
+
*
|
|
10
|
+
* threshold 기본 2 — 짧은 키 (3자 이하) 는 거리 2 만 허용해도 false positive 가
|
|
11
|
+
* 많아질 수 있으므로 길이별로 자동 조정 (`Math.min(threshold, ceil(len/3))`).
|
|
12
|
+
*
|
|
13
|
+
* 다중 매치 시 가장 짧은 거리, 동률이면 알파벳순.
|
|
14
|
+
*/
|
|
15
|
+
export declare function suggestKey(unknown: string, known: readonly string[], threshold?: number): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* config 객체의 모든 키를 검사해 unknown 발견 시 console.warn 으로 경고 + 제안.
|
|
18
|
+
*
|
|
19
|
+
* `silent: true` 면 출력 안 하고 `{ unknown, suggestion }` 배열만 반환 — 테스트용.
|
|
20
|
+
*/
|
|
21
|
+
export declare function warnUnknownKeys(config: Record<string, unknown>, known: readonly string[], options?: {
|
|
22
|
+
silent?: boolean;
|
|
23
|
+
sourceLabel?: string;
|
|
24
|
+
}): Array<{
|
|
25
|
+
unknown: string;
|
|
26
|
+
suggestion: string | null;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* 알려진 BuildOptions / TranspileOptions / config-only 키 (`extends` 등) 통합 목록.
|
|
30
|
+
*
|
|
31
|
+
* TypeScript 타입은 런타임에 지워지므로 `warnUnknownKeys()` 가 이 목록을 직접
|
|
32
|
+
* `BuildOptions` 에서 읽을 수는 없다. 그래서 런타임 값은 수동 목록으로 유지한다.
|
|
33
|
+
*
|
|
34
|
+
* drift 는 `typo-suggest.test.ts` 가 `BuildOptionsCommon` 선언을 파싱해 CI 에서
|
|
35
|
+
* 검출한다. 완전한 단일 source of truth 화는 #2112 (Phase 3-5 schema sync) 에서
|
|
36
|
+
* `BuildOptions` / Zig DTO / config key 목록을 빌드타임 생성 대상으로 묶을 때 가능하다.
|
|
37
|
+
*/
|
|
38
|
+
export declare const KNOWN_CONFIG_KEYS: readonly string[];
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `zntc.workspace.{ts,mts,cts,mjs,js,cjs,json}` 모노레포 워크스페이스 로더 (#2111).
|
|
3
|
+
*
|
|
4
|
+
* Vitest `vitest.workspace.ts` 패턴 벤치마킹. root 디렉토리에 단일 워크스페이스
|
|
5
|
+
* 파일을 두고, 그 안에서 패키지별 build target 을 정의한다.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* export default defineWorkspace([
|
|
9
|
+
* "./packages/app", // 디렉토리 — 안의 zntc.config.* 자동 탐색
|
|
10
|
+
* "./packages/*", // glob — 매칭 디렉토리들 일괄
|
|
11
|
+
* { name: "shared", entryPoints: [...] }, // inline — 즉시 워크스페이스화
|
|
12
|
+
* ])
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* `--workspace=<name>` 으로 단일 entry 만 빌드 가능. root config (`zntc.config.*`)
|
|
16
|
+
* 와 같은 디렉토리에 두면 root 옵션을 모든 entry 가 상속.
|
|
17
|
+
*/
|
|
18
|
+
import { type ConfigEnv, type UserConfig } from './config-loader.ts';
|
|
19
|
+
declare const CONFIG_EXT_PRIORITY_LOCAL: readonly [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
|
|
20
|
+
/**
|
|
21
|
+
* 디렉토리 경로 또는 단일 `*` 가 포함된 glob.
|
|
22
|
+
*
|
|
23
|
+
* - `"./packages/app"` — 단일 디렉토리. 안의 `zntc.config.*` 가 있으면 자동 로드.
|
|
24
|
+
* - `"./packages/*"` — trailing wildcard. baseDir 의 직속 디렉토리 모두 매칭 (hidden / `node_modules` 제외).
|
|
25
|
+
* - `"./apps/web-*"` — prefix 매칭도 동일 규칙.
|
|
26
|
+
*
|
|
27
|
+
* `**` (재귀 glob) 은 미지원 — 워크스페이스에서 흔치 않고 perf/edge case 가 늘어 의도적 제외.
|
|
28
|
+
*/
|
|
29
|
+
export type WorkspaceEntryPath = string;
|
|
30
|
+
/**
|
|
31
|
+
* 디렉토리 없이 root cwd 에서 직접 build 되는 inline entry.
|
|
32
|
+
*
|
|
33
|
+
* `name` 은 식별자(필수) — `--workspace=<name>` 필터, 로그 출력에 사용. 그 외 모든 필드는
|
|
34
|
+
* `BuildOptions` (`UserConfig`) 와 동일하며 root config 를 override 한다.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* export default defineWorkspace([
|
|
39
|
+
* { name: "shared-utils", entryPoints: ["./shared/utils.ts"], outdir: "./shared/dist" },
|
|
40
|
+
* ]);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export type WorkspaceEntryInline = UserConfig & {
|
|
44
|
+
name: string;
|
|
45
|
+
};
|
|
46
|
+
/** workspace 배열 원소 — string path/glob 또는 inline 객체. */
|
|
47
|
+
export type WorkspaceEntry = WorkspaceEntryPath | WorkspaceEntryInline;
|
|
48
|
+
/** workspace 파일이 export 하는 entries 배열. */
|
|
49
|
+
export type Workspace = WorkspaceEntry[];
|
|
50
|
+
/**
|
|
51
|
+
* 함수형 workspace — `defineWorkspace((env) => [...])`.
|
|
52
|
+
*
|
|
53
|
+
* `env.command` (`bundle`/`serve`/`watch`), `env.mode`, `env.env` (process.env 기반)
|
|
54
|
+
* 를 받아 동적으로 entries 결정. 비동기 (Promise) 반환 허용.
|
|
55
|
+
*/
|
|
56
|
+
export type WorkspaceFn = (env: ConfigEnv) => Workspace | Promise<Workspace>;
|
|
57
|
+
/** workspace 파일이 default export 가능한 형태 — 배열 또는 함수. */
|
|
58
|
+
export type WorkspaceInput = Workspace | WorkspaceFn;
|
|
59
|
+
/**
|
|
60
|
+
* Vitest 식 identity 헬퍼. 입력을 그대로 반환 — 타입 추론 / IDE 자동완성을 위해 존재.
|
|
61
|
+
*
|
|
62
|
+
* @param input workspace 정의 — 배열 또는 함수형
|
|
63
|
+
* @returns 입력 그대로 (런타임 변경 없음)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { defineWorkspace } from "@zntc/core";
|
|
68
|
+
*
|
|
69
|
+
* export default defineWorkspace([
|
|
70
|
+
* "./packages/*",
|
|
71
|
+
* { name: "shared", entryPoints: ["./shared/index.ts"] },
|
|
72
|
+
* ]);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function defineWorkspace<T extends WorkspaceInput>(input: T): T;
|
|
76
|
+
/**
|
|
77
|
+
* workspace 파일 자동 탐색 우선순위. `CONFIG_EXT_PRIORITY` 와 동일 정책 — 동일 디렉토리에
|
|
78
|
+
* 다중 확장자 존재 시 첫 매치를 반환한다 (`.ts` > `.mts` > `.cts` > `.mjs` > `.js` > `.cjs` > `.json`).
|
|
79
|
+
*/
|
|
80
|
+
export declare const WORKSPACE_EXT_PRIORITY: typeof CONFIG_EXT_PRIORITY_LOCAL;
|
|
81
|
+
/**
|
|
82
|
+
* `cwd` 에서 `zntc.workspace.{ext}` 를 자동 탐색.
|
|
83
|
+
*
|
|
84
|
+
* @param cwd 탐색 시작 디렉토리 (보통 `process.cwd()`)
|
|
85
|
+
* @returns 발견된 절대 경로 또는 `null`
|
|
86
|
+
*
|
|
87
|
+
* 동기 stat (`existsSync`) 사용 — CLI 시작 시 한 번만 호출되므로 무시 가능한 비용.
|
|
88
|
+
* parent traversal 은 안 함 — 모노레포 root 가 아닌 sub-package 안에서 호출되면 `null` 반환.
|
|
89
|
+
*/
|
|
90
|
+
export declare function findWorkspacePath(cwd: string): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* workspace 파일 로드. `loadModuleDefault` 가 TS/JS/JSON 디스패치 + (tmp 파일) self-compile
|
|
93
|
+
* 까지 처리하므로 호출자는 단일 진입점만 알면 된다. 함수형 export 면 `env` (또는
|
|
94
|
+
* `defaultConfigEnv()`) 와 호출. 결과는 항상 검증된 entries 배열.
|
|
95
|
+
*
|
|
96
|
+
* @param filePath workspace 파일 — 절대 또는 cwd 기준 상대 경로
|
|
97
|
+
* @param env 함수형 workspace 호출 시 주입할 컨텍스트. 미제공 시 `defaultConfigEnv()`.
|
|
98
|
+
* @returns 검증된 entries 배열 (순서 유지)
|
|
99
|
+
*
|
|
100
|
+
* @throws `@zntc/core: workspace must export an array (got X) from <path>` — top-level 배열 아님
|
|
101
|
+
* @throws `@zntc/core: workspace[i] is empty string in <path>` — 빈 문자열 entry
|
|
102
|
+
* @throws `@zntc/core: workspace[i] must be a string or object (got X) in <path>` — 잘못된 타입
|
|
103
|
+
* @throws `@zntc/core: workspace[i] inline entry requires non-empty 'name' in <path>` — inline 인데 name 없음
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const ws = await loadWorkspace("zntc.workspace.ts", { command: "bundle", mode: "production", env: process.env });
|
|
108
|
+
* // ws: WorkspaceEntry[]
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function loadWorkspace(filePath: string, env?: ConfigEnv): Promise<Workspace>;
|
|
112
|
+
/**
|
|
113
|
+
* 식별 단계 결과 — cwd/name/source 만 확정하고 config 로드는 보류.
|
|
114
|
+
*
|
|
115
|
+
* `loadIdentifiedConfig` 로 후처리하면 `config: UserConfig` 가 채워진 build target 형태로 완성.
|
|
116
|
+
*/
|
|
117
|
+
export interface IdentifiedWorkspace {
|
|
118
|
+
/** 워크스페이스 식별자 — `--workspace=<name>` 필터 키. */
|
|
119
|
+
name: string;
|
|
120
|
+
/** 매칭/지정된 cwd 절대 경로. */
|
|
121
|
+
cwd: string;
|
|
122
|
+
/** 어떤 entry 형식에서 왔는지. */
|
|
123
|
+
source: 'path' | 'glob' | 'inline';
|
|
124
|
+
/** inline 인 경우 미리 알려진 config (name 필드는 제외). path/glob 는 `null` — 디스크에서 로드 필요. */
|
|
125
|
+
inlineConfig: UserConfig | null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* entries 를 식별 단계까지만 처리 — `cwd`/`name`/`source` 결정하고 config 로드는 보류.
|
|
129
|
+
*
|
|
130
|
+
* `--workspace=<name>` 필터를 config 로드 **전에** 적용해 비용 큰 TS config self-compile 을
|
|
131
|
+
* 필터링된 N-1 개 entry 에 대해 회피하기 위함. path entry 는 `package.json` 만 읽어 name
|
|
132
|
+
* 결정 (저렴), glob 은 디렉토리 enumerate.
|
|
133
|
+
*
|
|
134
|
+
* dedup: 같은 `cwd` 가 path + glob 양쪽에 매칭되면 **첫 번째 (선언 순서)** 만 유지. 명시적
|
|
135
|
+
* path 가 glob 보다 우선하는 자연스러운 의도 — 사용자가 "all packages 중 app 은 특별 설정"
|
|
136
|
+
* 같은 패턴을 쓸 수 있게.
|
|
137
|
+
*
|
|
138
|
+
* @param entries `loadWorkspace` 가 반환한 검증된 entries 배열
|
|
139
|
+
* @param rootDir workspace 파일이 있는 디렉토리 (절대 경로 권장)
|
|
140
|
+
* @returns 식별된 워크스페이스 목록 (선언 순서 유지, dedup 적용)
|
|
141
|
+
*
|
|
142
|
+
* @throws `@zntc/core: workspace glob '**' is not supported (got '<pattern>')` — `**` glob 사용
|
|
143
|
+
* @throws `@zntc/core: workspace glob with '*' in directory part is not supported (got '<pattern>')` — 디렉토리부 wildcard
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const ws = await loadWorkspace("zntc.workspace.ts");
|
|
148
|
+
* const ids = identifyWorkspaceEntries(ws, "/repo");
|
|
149
|
+
* const target = filterWorkspaces(ids, "my-app");
|
|
150
|
+
* const resolved = await Promise.all(target.map((w) => loadIdentifiedConfig(w)));
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function identifyWorkspaceEntries(entries: Workspace, rootDir: string): IdentifiedWorkspace[];
|
|
154
|
+
/**
|
|
155
|
+
* 식별된 entry 의 config 를 디스크에서 로드. path/glob 은 `findConfigPath` 로 cwd 안의
|
|
156
|
+
* `zntc.config.*` 자동 탐색 후 `loadConfig` (extends 처리, 함수형 호출 포함). inline 은
|
|
157
|
+
* 이미 갖고 있는 `inlineConfig` 그대로.
|
|
158
|
+
*
|
|
159
|
+
* 비싸다 — TS config 면 NAPI transpile + tmp `.mjs` write/import/unlink. 필터링된 entry
|
|
160
|
+
* 에 대해서만 호출하는 것을 권장 (`identifyWorkspaceEntries` → `filterWorkspaces` → 이 함수).
|
|
161
|
+
*
|
|
162
|
+
* @param w 식별된 워크스페이스 entry
|
|
163
|
+
* @param env `loadConfig` 에 전달할 함수형 config 컨텍스트
|
|
164
|
+
* @returns entry 의 config (inline 또는 디스크 로드 결과). config 파일 없으면 빈 객체 `{}`.
|
|
165
|
+
*/
|
|
166
|
+
export declare function loadIdentifiedConfig(w: IdentifiedWorkspace, env?: ConfigEnv): Promise<UserConfig>;
|
|
167
|
+
/**
|
|
168
|
+
* `--workspace=<name>` 필터. 매칭 0개면 throw — 사용자 typo 보호 (가능한 후보 노출).
|
|
169
|
+
*
|
|
170
|
+
* `name` 필드를 가진 객체면 모두 받도록 generic — `IdentifiedWorkspace` 든 caller 가 정의한
|
|
171
|
+
* 후속 형태든 동일 동작. config 로드는 비싸므로 `identifyWorkspaceEntries` 결과에 즉시 필터
|
|
172
|
+
* 후 `loadIdentifiedConfig` 호출을 권장.
|
|
173
|
+
*
|
|
174
|
+
* `name` 일치만 사용 — Vitest 의 `--project` 와 동일. glob/regex 매칭은 향후 확장.
|
|
175
|
+
*
|
|
176
|
+
* @param workspaces 식별/해석된 워크스페이스 배열
|
|
177
|
+
* @param filter `--workspace=<name>` 값. `undefined`/빈 문자열이면 전체 그대로 반환.
|
|
178
|
+
* @returns `name === filter` 인 entries (보통 1개). filter 미지정 시 입력 동일 참조 반환.
|
|
179
|
+
*
|
|
180
|
+
* @throws `@zntc/core: --workspace='<filter>' matched 0 entries (available: ...)` — 매칭 실패
|
|
181
|
+
*/
|
|
182
|
+
export declare function filterWorkspaces<T extends {
|
|
183
|
+
name: string;
|
|
184
|
+
}>(workspaces: T[], filter: string | undefined): T[];
|
|
185
|
+
export {};
|