@zntc/web 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 +48 -0
- package/dist/dev-controller.d.ts +80 -0
- package/dist/html-env.d.ts +27 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1124 -0
- package/dist/inject.d.ts +17 -0
- package/dist/style/css-modules.d.ts +52 -0
- package/dist/style/css-parser.d.ts +15 -0
- package/dist/style/loader.d.ts +28 -0
- package/dist/style/postcss.d.ts +68 -0
- package/dist/style/sass.d.ts +52 -0
- package/dist/url.d.ts +2 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ohah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @zntc/web
|
|
2
|
+
|
|
3
|
+
ZNTC 의 web platform layer — dev server (HTTP/HTTPS + WebSocket HMR), HMR overlay, postcss/sass/lightningcss CSS pipeline, dev controller (file watcher + module graph).
|
|
4
|
+
|
|
5
|
+
## 설치
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add -D @zntc/web
|
|
9
|
+
# 또는
|
|
10
|
+
npm i -D @zntc/web
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@zntc/core` 가 dependency 로 자동 install 됨 (NAPI binary 포함).
|
|
14
|
+
|
|
15
|
+
### Optional (CSS pipeline)
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add -D postcss postcss-load-config sass
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- `postcss` / `postcss-load-config` — `postcss.config.{js,ts}` 자동 탐색 / Tailwind / PostCSS plugins
|
|
22
|
+
- `sass` — `.scss` / `.sass` 파일 처리
|
|
23
|
+
|
|
24
|
+
## 사용
|
|
25
|
+
|
|
26
|
+
`zntc dev`, `zntc preview`, `zntc build` (app mode) CLI 가 자동으로 `@zntc/web` 을 dynamic import 해서 사용. 사용자 코드에서 직접 import 할 일은 거의 없음.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bunx zntc dev # dev server + HMR
|
|
30
|
+
bunx zntc build # production app build
|
|
31
|
+
bunx zntc preview # production preview server
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
자세한 설정: [docs/CONFIG.md](https://github.com/ohah/zts/blob/main/docs/CONFIG.md) · [docs/HMR.md](https://github.com/ohah/zts/blob/main/docs/HMR.md)
|
|
35
|
+
|
|
36
|
+
## 직접 import (고급)
|
|
37
|
+
|
|
38
|
+
`createAppDevController` 가 dev controller 의 main entry. 옵션 surface 가 넓고 `@zntc/core` 의 `prepareAppDevSync` 결과를 받음 — 사용 예는 [docs/HMR.md](https://github.com/ohah/zts/blob/main/docs/HMR.md) 참조.
|
|
39
|
+
|
|
40
|
+
## 관련 패키지
|
|
41
|
+
|
|
42
|
+
- [@zntc/core](https://npmjs.com/package/@zntc/core) — 트랜스파일러 / 번들러 코어
|
|
43
|
+
- [@zntc/react-native](https://npmjs.com/package/@zntc/react-native) — RN platform layer
|
|
44
|
+
- [@zntc/vite-plugin](https://npmjs.com/package/@zntc/vite-plugin) — Vite 사용 시 ZNTC transform 적용
|
|
45
|
+
|
|
46
|
+
## 라이센스
|
|
47
|
+
|
|
48
|
+
MIT.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type BundleResult } from './inject.ts';
|
|
2
|
+
import { type NodeRequire } from './style/loader.ts';
|
|
3
|
+
interface ConfigEnv {
|
|
4
|
+
mode: string;
|
|
5
|
+
command?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AppDevControllerOptions {
|
|
8
|
+
outdir?: string | undefined;
|
|
9
|
+
base?: string | undefined;
|
|
10
|
+
publicPath?: string | undefined;
|
|
11
|
+
appRoot?: string | undefined;
|
|
12
|
+
entryHtml?: string | undefined;
|
|
13
|
+
publicDir?: string | false | undefined;
|
|
14
|
+
envDir?: string | undefined;
|
|
15
|
+
envPrefixes?: readonly string[] | undefined;
|
|
16
|
+
logLevel?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface AppDevControllerDeps {
|
|
19
|
+
/** dev/build 의 NAPI sync wrapper — core 가 이미 세션에서 init 됐다고 가정. */
|
|
20
|
+
fallbackRequire: NodeRequire;
|
|
21
|
+
/** zntc CLI 의 node_modules — app 에 node_modules 가 없으면 symlink 대상. */
|
|
22
|
+
cliNodeModules: string;
|
|
23
|
+
}
|
|
24
|
+
interface PipelineCache {
|
|
25
|
+
stylePipelineFiles: string[];
|
|
26
|
+
styleSourceFiles: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface PrepareAppCssPipelineRootOptions {
|
|
29
|
+
/** 이전 prep 의 tempRoot — incremental 재사용. null 이면 새로 mkdtemp. */
|
|
30
|
+
existingTempRoot?: string | null;
|
|
31
|
+
/** dirty 파일 path. existingTempRoot 와 함께 — 그 파일들만 sync. */
|
|
32
|
+
dirtyPaths?: readonly string[] | null;
|
|
33
|
+
/** 이전 prep 의 stylePipelineFiles + styleSourceFiles — 구조 변화 없으면 재사용. */
|
|
34
|
+
cache?: PipelineCache | null;
|
|
35
|
+
}
|
|
36
|
+
export interface AppCssPipelineResult {
|
|
37
|
+
tempRoot: string;
|
|
38
|
+
generatedCssAbsPaths: string[];
|
|
39
|
+
cache: PipelineCache;
|
|
40
|
+
}
|
|
41
|
+
export declare function cleanupPostcssTempRoot(tempRoot: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* postcss config + sass / css-modules 처리를 위한 temp root 준비. 입력 source 는
|
|
44
|
+
* tempRoot 로 cp 되어 mutable, 출력 (`.css` / `.module.zntc.css` / `.css.js` proxy)
|
|
45
|
+
* 도 같은 tempRoot 에 emit. 호출자가 generatedCssAbsPaths 를 받아 outdir mirror.
|
|
46
|
+
*
|
|
47
|
+
* Incremental — existingTempRoot + dirtyPaths 가 있으면 그 파일만 cp / 삭제 처리,
|
|
48
|
+
* cache 가 있으면 stylePipelineFiles / styleSourceFiles tree walk 도 skip.
|
|
49
|
+
*/
|
|
50
|
+
export declare function prepareAppCssPipelineRoot(root: string, outdir: string, configEnv: ConfigEnv, logLevel: string | undefined, phase: string, deps: AppDevControllerDeps, options?: PrepareAppCssPipelineRootOptions): Promise<AppCssPipelineResult | null>;
|
|
51
|
+
export interface AppDevPrepareResult {
|
|
52
|
+
entryPath: string;
|
|
53
|
+
}
|
|
54
|
+
export interface AppDevController {
|
|
55
|
+
readonly root: string;
|
|
56
|
+
readonly outdir: string;
|
|
57
|
+
readonly base: string;
|
|
58
|
+
prepare(dirtyPaths?: readonly string[] | null): Promise<AppDevPrepareResult>;
|
|
59
|
+
afterBundle(options?: {
|
|
60
|
+
changedPath?: string | null;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
deps: Set<string>;
|
|
63
|
+
dirDeps: Set<string>;
|
|
64
|
+
primaryHref: string | null;
|
|
65
|
+
processed: number;
|
|
66
|
+
}>;
|
|
67
|
+
injectBundleCssLinks(bundleResult: BundleResult): void;
|
|
68
|
+
isPostcssConfig(absPath: string): boolean;
|
|
69
|
+
isCssOnlyChange(absPath: string): boolean;
|
|
70
|
+
isSassOnlyChange(absPath: string): boolean;
|
|
71
|
+
rebuildScssIncremental(absPath: string): Promise<string | null>;
|
|
72
|
+
hrefFor(absPath: string): string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* dev server 의 lifecycle controller — prepare / afterBundle / HMR-related dispatch.
|
|
76
|
+
* runServe 가 watch debounce 후 controller 의 각 method 를 호출. 본 함수는 closure
|
|
77
|
+
* 로 cssDeps / pipelineRoot / pipelineCache 등 state 를 hold.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createAppDevController(opts: AppDevControllerOptions, root: string, configEnv: ConfigEnv, deps: AppDevControllerDeps): AppDevController;
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML 안의 EJS 스타일 토큰 `<%= KEY %>` 를 환경변수 값으로 치환.
|
|
3
|
+
*
|
|
4
|
+
* - 토큰 양식: `<%=` (양쪽 공백 허용) `KEY` `%>`. `KEY` 는 `[A-Za-z_][A-Za-z0-9_]*`.
|
|
5
|
+
* - 치환 값은 `<`, `>`, `&`, `"` 를 HTML escape 한다 — `.env` 값이 attribute 안 또는 script
|
|
6
|
+
* 안에 들어가 XSS / attribute 깨짐을 만드는 것을 차단. 사용자가 의도적으로 HTML 을
|
|
7
|
+
* 넣고 싶다면 별도 옵션 (현재 미지원) 또는 inline script + import.meta.env 사용.
|
|
8
|
+
* - 허용 prefix 외 키는 원본 토큰을 그대로 두고 warning. typo / secret 노출 실수를 가시화.
|
|
9
|
+
* - 미발견 키는 빈 문자열로 치환 + warning (Vite/CRA 호환).
|
|
10
|
+
* - expression 평가 (`<%= mode === 'prod' ? ... %>`) 는 미지원 — key-only. KEY 시작이
|
|
11
|
+
* 숫자 / 기호여서 regex 가 reject.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_HTML_ENV_PREFIX = "ZNTC_";
|
|
14
|
+
export interface TransformHtmlEnvResult {
|
|
15
|
+
html: string;
|
|
16
|
+
changed: boolean;
|
|
17
|
+
warnings: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare function transformHtmlEnvTokens(html: string, env: Record<string, string>, prefix?: string): TransformHtmlEnvResult;
|
|
20
|
+
/**
|
|
21
|
+
* `<outdir>/index.html` 을 읽고 EJS 토큰을 치환한 결과를 다시 쓴다.
|
|
22
|
+
* ENOENT 는 silent skip — dev mode 에서 entry HTML 이 아직 없을 수 있음.
|
|
23
|
+
* `changed=false` 면 write 도 생략 — 같은 결과 재기록으로 인한 mtime 변화 / watcher 트리거 방지.
|
|
24
|
+
*/
|
|
25
|
+
export declare function applyHtmlEnvTokens(outdir: string, env: Record<string, string>, prefix?: string): {
|
|
26
|
+
warnings: string[];
|
|
27
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { APP_DEV_HMR_CLIENT_PATH, APP_DEV_HMR_WS_PATH, type BunHmrClient, createHmrChannel, createWatcher, type CreateWatcherOptions, HMR_MSG, type HmrChannel, type HmrConnectedMessage, type HmrCssUpdateMessage, type HmrError, type HmrErrorMessage, type HmrFullReloadMessage, type HmrMessage, type HmrMessageType, type WatchEventType, type WatchFn, type WatchListener, type WatcherHandle, type WatcherInstance, } from '@zntc/server';
|
|
2
|
+
export { type BundleResult, injectAppDevBundleCssLinks, injectAppDevHmrClient, injectAppDevPipelineCssLinks, injectIntoDevHtml, } from './inject.ts';
|
|
3
|
+
export { DEFAULT_HTML_ENV_PREFIX, type TransformHtmlEnvResult, applyHtmlEnvTokens, transformHtmlEnvTokens, } from './html-env.ts';
|
|
4
|
+
export { joinUrl } from './url.ts';
|
|
5
|
+
export { isCssIdent, isCssIdentStart, skipCssString, skipCssUrl, startsWithCssIdent, } from './style/css-parser.ts';
|
|
6
|
+
export { collectAppFiles, type CollectAppFilesOptions, requireFromAppOrFallback, } from './style/loader.ts';
|
|
7
|
+
export { type AppDevPostcssOptions, type AppDevPostcssResult, collectPostcssMessages, findPostcssConfig, isCssFile, isPostcssConfigFile, loadPostcssConfig, logPostcssProcessed, type PostcssMessage, POSTCSS_CONFIG_NAMES, runPostcssForAppDev, runPostcssIfConfigured, } from './style/postcss.ts';
|
|
8
|
+
export { buildCssPreprocessorProxy, CSS_PREPROCESSOR_EXTENSIONS, compileSassFile, cssPreprocessorOutputPath, cssPreprocessorProxyPath, isCssModulePreprocessorFile, isCssPreprocessorFile, isStyleReferenceSource, loadSassCompiler, rewriteSassReferences, transformCssPreprocessors, type TransformCssPreprocessorOptions, } from './style/sass.ts';
|
|
9
|
+
export { buildCssModuleProxy, collectCssModuleClasses, type CssModuleClassToken, cssModuleGeneratedCssPath, cssModuleLocalName, cssModuleProxyPath, isCssModuleFile, isValidExportName, rewriteCssModuleClasses, rewriteCssModuleReferences, scanCssModuleClassTokens, transformCssModules, type TransformCssModulesOptions, } from './style/css-modules.ts';
|
|
10
|
+
export { type AppCssPipelineResult, type AppDevController, type AppDevControllerDeps, type AppDevControllerOptions, cleanupPostcssTempRoot, createAppDevController, prepareAppCssPipelineRoot, type PrepareAppCssPipelineRootOptions, } from './dev-controller.ts';
|
|
11
|
+
export { APP_DEV_HMR_CLIENT } from '../runtime/dev-overlay-client.mjs';
|