@apps-in-toss/devtools 3.0.5 → 3.1.0-beta.1
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 +28 -201
- package/README.md +871 -237
- package/dist/mock/2x.d.ts +155 -3
- package/dist/mock/2x.js +1560 -1306
- package/dist/mock/3x.d.ts +123 -3
- package/dist/mock/3x.js +1507 -1245
- package/dist/mock/index.d.ts +123 -3
- package/dist/mock/index.js +1507 -1245
- package/dist/panel/index.js +106 -154
- package/dist/tunnel-BvEf1qGV.js +186 -0
- package/dist/tunnel-DtCTOUlp.cjs +187 -0
- package/dist/unplugin/index.cjs +147 -12
- package/dist/unplugin/index.d.cts +78 -408
- package/dist/unplugin/index.d.ts +78 -408
- package/dist/unplugin/index.js +147 -13
- package/dist/unplugin/tunnel.cjs +191 -0
- package/dist/unplugin/tunnel.d.cts +140 -0
- package/dist/unplugin/tunnel.d.ts +140 -0
- package/dist/unplugin/tunnel.js +186 -0
- package/package.json +8 -5
- package/CHANGELOG.md +0 -32
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
//#region src/unplugin/tunnel.ts
|
|
5
|
+
/**
|
|
6
|
+
* Cloudflare quick-tunnel helper for the devtools unplugin.
|
|
7
|
+
*
|
|
8
|
+
* Loaded lazily (`await import('./tunnel.js')`) only when the `tunnel` option is
|
|
9
|
+
* on, so `cloudflared` / `qrcode-terminal` are never pulled in for the common
|
|
10
|
+
* case. This is the one place in `@apps-in-toss/devtools` that depends on Node-only
|
|
11
|
+
* APIs (`child_process` via the `cloudflared` wrapper) — keep it thin and out of
|
|
12
|
+
* jsdom unit tests; the spawn path is verified by hand / e2e (same spirit as the
|
|
13
|
+
* "web 모드는 e2e" rule in CLAUDE.md). The pure helpers below
|
|
14
|
+
* (`parseTrycloudflareUrl`, `printTunnelBanner`) are unit-tested.
|
|
15
|
+
*/
|
|
16
|
+
/** Matches the public URL cloudflared prints for an unauthenticated quick tunnel. */
|
|
17
|
+
const TRYCLOUDFLARE_RE = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/i;
|
|
18
|
+
/**
|
|
19
|
+
* Extract the `https://<sub>.trycloudflare.com` URL from a line of cloudflared
|
|
20
|
+
* output, or `null` if the line doesn't contain one. Pulled out as a pure
|
|
21
|
+
* function so it can be unit-tested without spawning anything.
|
|
22
|
+
*/
|
|
23
|
+
function parseTrycloudflareUrl(line) {
|
|
24
|
+
const m = line.match(TRYCLOUDFLARE_RE);
|
|
25
|
+
return m ? m[0] : null;
|
|
26
|
+
}
|
|
27
|
+
const LAUNCHER_URL = "https://devtools.aitc.dev/launcher/";
|
|
28
|
+
/**
|
|
29
|
+
* Build the deep-link URL that QR codes encode: when the launcher PWA is
|
|
30
|
+
* already on the phone's home screen, scanning this opens it directly into the
|
|
31
|
+
* live view for `tunnelUrl` (the launcher consumes `?url=` and clears it).
|
|
32
|
+
* Plain-text raw URL is no longer enough — the launcher gates its setup UI to
|
|
33
|
+
* the installed PWA, so a raw tunnel URL opened in a normal browser tab would
|
|
34
|
+
* land on a "please install" screen.
|
|
35
|
+
*
|
|
36
|
+
* When `opts.name` is given (non-blank), it is added as `&name=` so the launcher
|
|
37
|
+
* partner bar shows the app name instead of the generic default (#498).
|
|
38
|
+
*
|
|
39
|
+
* When `opts.webViewType` is `'game'`, `&navBarType=game` is appended so the
|
|
40
|
+
* launcher enters game nav chrome (floating capsule, no full bar) automatically
|
|
41
|
+
* on scan. `'partner'` is the launcher's implicit default and is not added to
|
|
42
|
+
* keep the URL clean (#584).
|
|
43
|
+
*
|
|
44
|
+
* When `opts.navBarTransparent` is `true`, `&navBarTransparent=1` is appended
|
|
45
|
+
* so the launcher partner bar renders with a transparent background (#587).
|
|
46
|
+
*
|
|
47
|
+
* When `opts.navBarTheme` is `'light'` or `'dark'`, `&navBarTheme=<v>` is
|
|
48
|
+
* appended so the launcher partner bar uses the matching foreground colour (#587).
|
|
49
|
+
*/
|
|
50
|
+
function buildLauncherDeepLink(tunnelUrl, optsParam) {
|
|
51
|
+
const opts = optsParam ?? {};
|
|
52
|
+
let url = `${LAUNCHER_URL}?url=${encodeURIComponent(tunnelUrl)}`;
|
|
53
|
+
if (opts.name !== void 0 && opts.name.trim() !== "") url += `&name=${encodeURIComponent(opts.name.trim())}`;
|
|
54
|
+
if (opts.webViewType === "game") url += "&navBarType=game";
|
|
55
|
+
if (opts.navBarTransparent === true) url += "&navBarTransparent=1";
|
|
56
|
+
if (opts.navBarTheme === "light" || opts.navBarTheme === "dark") url += `&navBarTheme=${opts.navBarTheme}`;
|
|
57
|
+
return url;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Print the terminal banner announcing the live tunnel: the public URL, an ASCII
|
|
61
|
+
* QR encoding a launcher deep-link, and a one-line note that quick tunnels are
|
|
62
|
+
* ephemeral, unauthenticated and not for production. Pure w.r.t. side effects
|
|
63
|
+
* other than the injected `log` sink and `qrcode-terminal` — unit-tested.
|
|
64
|
+
*/
|
|
65
|
+
async function printTunnelBanner(url, opts = {}) {
|
|
66
|
+
const log = opts.log ?? ((m) => console.log(m));
|
|
67
|
+
const deepLink = buildLauncherDeepLink(url, {
|
|
68
|
+
name: opts.name,
|
|
69
|
+
webViewType: opts.webViewType,
|
|
70
|
+
navBarTransparent: opts.navBarTransparent,
|
|
71
|
+
navBarTheme: opts.navBarTheme
|
|
72
|
+
});
|
|
73
|
+
log([
|
|
74
|
+
"",
|
|
75
|
+
" ┌─ @apps-in-toss/devtools · live tunnel ────────────────────────────",
|
|
76
|
+
` │ ${url}`,
|
|
77
|
+
" │",
|
|
78
|
+
` │ Install the launcher PWA once: ${LAUNCHER_URL}`,
|
|
79
|
+
" │ Then scan the QR below — it opens the launcher directly",
|
|
80
|
+
" │ into this tunnel URL (no manual paste needed).",
|
|
81
|
+
" │ Quick tunnels are unauthenticated, change every run, and are",
|
|
82
|
+
" │ not for production use.",
|
|
83
|
+
" └──────────────────────────────────────────────────────────────",
|
|
84
|
+
""
|
|
85
|
+
].join("\n"));
|
|
86
|
+
if (opts.qr !== false) {
|
|
87
|
+
const qrcode = (await import("qrcode-terminal")).default;
|
|
88
|
+
await new Promise((resolve) => {
|
|
89
|
+
qrcode.generate(deepLink, { small: true }, (out) => {
|
|
90
|
+
log(out);
|
|
91
|
+
resolve();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Sanitize cloudflared stderr output for error diagnostics (#421).
|
|
98
|
+
*
|
|
99
|
+
* Masks `*.trycloudflare.com` hostnames and full `https://` / `wss://` URLs
|
|
100
|
+
* that carry those hostnames so tunnel host values never appear in error
|
|
101
|
+
* messages. Diagnostic content (error codes, reasons, JSON blobs) is preserved.
|
|
102
|
+
*
|
|
103
|
+
* SECRET-HANDLING: tunnel host is SECRET-class per harness policy — only
|
|
104
|
+
* placeholder text is emitted.
|
|
105
|
+
*/
|
|
106
|
+
function sanitizeCloudflaredOutput(line) {
|
|
107
|
+
let s = line.replace(/(?:https?|wss?):\/\/[a-z0-9-]+\.trycloudflare\.com(?:\/[^\s]*)*/gi, (m) => m.replace(/[a-z0-9-]+\.trycloudflare\.com/i, "<HOST>.trycloudflare.com"));
|
|
108
|
+
s = s.replace(/[a-z0-9-]+\.trycloudflare\.com/gi, "<HOST>.trycloudflare.com");
|
|
109
|
+
return s;
|
|
110
|
+
}
|
|
111
|
+
const URL_TIMEOUT_MS = 2e4;
|
|
112
|
+
/**
|
|
113
|
+
* Start an unauthenticated Cloudflare quick tunnel to `http://localhost:<port>`
|
|
114
|
+
* and resolve once the public URL is known. Downloads the `cloudflared` binary
|
|
115
|
+
* on first use if it is not already installed. Rejects with a friendly error if
|
|
116
|
+
* no URL appears within {@link URL_TIMEOUT_MS}.
|
|
117
|
+
*/
|
|
118
|
+
async function startQuickTunnel(port) {
|
|
119
|
+
const { bin, install, Tunnel } = await import("cloudflared");
|
|
120
|
+
if (!existsSync(bin)) {
|
|
121
|
+
await mkdir(dirname(bin), { recursive: true });
|
|
122
|
+
await install(bin);
|
|
123
|
+
}
|
|
124
|
+
const tunnel = Tunnel.quick(`http://localhost:${port}`);
|
|
125
|
+
let stopped = false;
|
|
126
|
+
const stop = () => {
|
|
127
|
+
if (stopped) return;
|
|
128
|
+
stopped = true;
|
|
129
|
+
try {
|
|
130
|
+
tunnel.stop();
|
|
131
|
+
} catch {}
|
|
132
|
+
};
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
const stderrLines = [];
|
|
135
|
+
/**
|
|
136
|
+
* Format the last `n` sanitized stderr lines as a diagnostic appendix.
|
|
137
|
+
* Returns an empty string when no lines have been collected.
|
|
138
|
+
*/
|
|
139
|
+
const stderrTail = (n = 15) => {
|
|
140
|
+
if (stderrLines.length === 0) return "";
|
|
141
|
+
const tail = stderrLines.slice(-n).map(sanitizeCloudflaredOutput).join("");
|
|
142
|
+
return `\ncloudflared 출력 (마지막 ${Math.min(n, stderrLines.length)}줄):\n${tail}`;
|
|
143
|
+
};
|
|
144
|
+
const timer = setTimeout(() => {
|
|
145
|
+
cleanup();
|
|
146
|
+
stop();
|
|
147
|
+
reject(/* @__PURE__ */ new Error(`[@apps-in-toss/devtools] cloudflared did not report a tunnel URL within ${URL_TIMEOUT_MS / 1e3}s. Check your network connection, or run \`cloudflared tunnel --url http://localhost:${port}\` manually.${stderrTail()}`));
|
|
148
|
+
}, URL_TIMEOUT_MS);
|
|
149
|
+
const onUrl = (line) => {
|
|
150
|
+
const found = parseTrycloudflareUrl(line);
|
|
151
|
+
if (!found) return;
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
cleanup();
|
|
154
|
+
resolve({
|
|
155
|
+
url: found,
|
|
156
|
+
stop
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const pushStderr = (line) => {
|
|
160
|
+
stderrLines.push(line);
|
|
161
|
+
};
|
|
162
|
+
const cleanup = () => {
|
|
163
|
+
tunnel.off("stdout", onUrl);
|
|
164
|
+
tunnel.off("stderr", onUrl);
|
|
165
|
+
tunnel.off("stderr", pushStderr);
|
|
166
|
+
};
|
|
167
|
+
tunnel.once("url", onUrl);
|
|
168
|
+
tunnel.on("stdout", onUrl);
|
|
169
|
+
tunnel.on("stderr", onUrl);
|
|
170
|
+
tunnel.on("stderr", pushStderr);
|
|
171
|
+
tunnel.once("error", (err) => {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
cleanup();
|
|
174
|
+
stop();
|
|
175
|
+
reject(err);
|
|
176
|
+
});
|
|
177
|
+
tunnel.once("exit", (code) => {
|
|
178
|
+
if (stopped) return;
|
|
179
|
+
clearTimeout(timer);
|
|
180
|
+
cleanup();
|
|
181
|
+
reject(/* @__PURE__ */ new Error(`[@apps-in-toss/devtools] cloudflared exited (code ${code ?? "null"}) before reporting a tunnel URL.${stderrTail()}`));
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
export { buildLauncherDeepLink, parseTrycloudflareUrl, printTunnelBanner, sanitizeCloudflaredOutput, startQuickTunnel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apps-in-toss/devtools",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-beta.1",
|
|
4
4
|
"description": "Browser development tools for Apps in Toss mini-apps — mock SDK, floating devtools panel, and universal bundler plugin. devDependency only; contributes nothing to a production bundle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apps-in-toss",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"vite-plugin",
|
|
16
16
|
"webpack-plugin"
|
|
17
17
|
],
|
|
18
|
-
"license": "
|
|
18
|
+
"license": "BSD-3-Clause",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
@@ -64,14 +64,17 @@
|
|
|
64
64
|
"check:footprint-absent": "bash scripts/check-devtools-footprint-absent.sh"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
+
"cloudflared": "^0.7.1",
|
|
68
|
+
"qrcode-terminal": "^0.12.0",
|
|
67
69
|
"unplugin": "^3.2.0"
|
|
68
70
|
},
|
|
69
71
|
"devDependencies": {
|
|
70
|
-
"@apps-in-toss/web-framework": "^3.0.
|
|
72
|
+
"@apps-in-toss/web-framework": "^3.1.0-beta.1",
|
|
71
73
|
"@apps-in-toss/web-framework-2x": "npm:@apps-in-toss/web-framework@2.10.8",
|
|
72
74
|
"@testing-library/dom": "10.4.1",
|
|
73
75
|
"@testing-library/react": "16.3.2",
|
|
74
76
|
"@types/node": "~24.13.3",
|
|
77
|
+
"@types/qrcode-terminal": "0.12.2",
|
|
75
78
|
"@types/react": "19.2.17",
|
|
76
79
|
"@types/react-dom": "19.2.3",
|
|
77
80
|
"jsdom": "29.1.1",
|
|
@@ -84,7 +87,7 @@
|
|
|
84
87
|
"vitest": "4.1.9"
|
|
85
88
|
},
|
|
86
89
|
"peerDependencies": {
|
|
87
|
-
"@apps-in-toss/web-framework": ">=
|
|
90
|
+
"@apps-in-toss/web-framework": ">=3.1.0-beta.0"
|
|
88
91
|
},
|
|
89
92
|
"peerDependenciesMeta": {
|
|
90
93
|
"@apps-in-toss/web-framework": {
|
|
@@ -94,4 +97,4 @@
|
|
|
94
97
|
"engines": {
|
|
95
98
|
"node": ">=24"
|
|
96
99
|
}
|
|
97
|
-
}
|
|
100
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# @apps-in-toss/devtools
|
|
2
|
-
|
|
3
|
-
## 3.0.5
|
|
4
|
-
|
|
5
|
-
## 3.0.4
|
|
6
|
-
|
|
7
|
-
### Patch Changes
|
|
8
|
-
|
|
9
|
-
- 6e935ed: - webView.pullToRefreshEnabled 기본값을 false로 변경해요.
|
|
10
|
-
- ait --help를 개선해요 (ko/en, --version, 컬러/라우팅 정리).
|
|
11
|
-
- 빌드 시 appName·brand·webBundle validation을 추가해요.
|
|
12
|
-
- 라이선스를 Apache-2.0으로 변경해요.
|
|
13
|
-
- 006f22a: feat: mock 커스터마이즈 수단과 충실도를 개선해요.
|
|
14
|
-
|
|
15
|
-
- unplugin에 `initialState` 옵션을 추가해요 — 번들러 설정에서 초기 mock 상태(IAP 상품 카탈로그 등)를 선언적으로 구성할 수 있어요. 객체는 재귀 병합되고 배열은 통째로 교체돼요.
|
|
16
|
-
- README에만 있던 `forceEnable`을 실제로 구현하고, 비표준 엔트리 파일명에서도 패널을 주입할 수 있는 `entryPattern` 옵션을 추가해요.
|
|
17
|
-
- 기본 IAP mock 카탈로그에 SUBSCRIPTION 상품(`mock-sub-monthly`)을 추가해요 — 상품 목록 조회만으로 구독 결제 플로우를 테스트할 수 있어요.
|
|
18
|
-
- Floating Panel IAP 탭에 상품 카탈로그 추가/편집 UI를 추가해요.
|
|
19
|
-
- `setScreenAwakeMode`가 Screen Wake Lock API를 지원하는 브라우저에서 실제로 화면 꺼짐 방지를 적용해요(미지원·거부 시 기존 동작 유지).
|
|
20
|
-
- `partner.addAccessoryButton`이 placeholder 버튼을 렌더하고, 탭하면 `tdsEvent.navigationAccessoryEvent`로 `{ id }`를 전달해요.
|
|
21
|
-
|
|
22
|
-
## 3.0.3
|
|
23
|
-
|
|
24
|
-
## 3.0.2
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- 5519b6f: feat: `@apps-in-toss/devtools` 패키지를 추가해요 — 브라우저에서 미니앱을 개발할 수 있는 mock SDK, devtools 패널, 번들러 unplugin(vite/webpack/rspack/rollup/esbuild)을 제공해요. `ait init`과 `ait migrate v3`가 devtools를 devDependencies에 추가하고, 번들러 설정의 plugins 맨 앞에 unplugin을 자동으로 꽂은 뒤 의존성 설치까지 실행해요.
|
|
29
|
-
- Updated dependencies [5519b6f]
|
|
30
|
-
- Updated dependencies [c50c421]
|
|
31
|
-
- Updated dependencies [c50c421]
|
|
32
|
-
- @apps-in-toss/web-framework@3.0.2
|