@ttmg/cli 0.4.6-vibe-beta.24 → 0.4.6
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/CHANGELOG.md +16 -0
- package/README.md +46 -17
- package/dist/index.js +312 -134
- package/dist/index.js.map +1 -1
- package/dist/package.json +8 -4
- package/dist/public/assets/{Card-CN2lxY0Y.js → Card-D4FjfZC9.js} +1 -1
- package/dist/public/assets/{Detail-CELZZ-4h.js → Detail-m3nH8XXe.js} +1 -1
- package/dist/public/assets/Detail-m3nH8XXe.js.br +0 -0
- package/dist/public/assets/{MonetizationMode-C7DNqium.js → MonetizationMode-1rShmN0o.js} +1 -1
- package/dist/public/assets/{MonetizationModeSummary-DYE7XUq1.js → MonetizationModeSummary-CVfWOth1.js} +1 -1
- package/dist/public/assets/{SectionHeader-BKc3BWXP.js → SectionHeader-CAuUcT9Q.js} +1 -1
- package/dist/public/assets/{baseForm-I9suIiQn.js → baseForm-C3PqJ30b.js} +1 -1
- package/dist/public/assets/baseForm-C3PqJ30b.js.br +0 -0
- package/dist/public/assets/{col-w9Q-2mgM.js → col-CcZ10DdH.js} +1 -1
- package/dist/public/assets/{compass-D6waJ52O.js → compass-H7uPUHxP.js} +1 -1
- package/dist/public/assets/{index-mjEeEQcC.js → index-B0xVTiB7.js} +1 -1
- package/dist/public/assets/index-B0xVTiB7.js.br +0 -0
- package/dist/public/assets/{index-CgXOkYrX.js → index-BAbIp3cP.js} +1 -1
- package/dist/public/assets/index-BAbIp3cP.js.br +0 -0
- package/dist/public/assets/{index-DDecPuod.js → index-BESASZaa.js} +1 -1
- package/dist/public/assets/{index-YVB9ZW00.js → index-BIZgIFOe.js} +1 -1
- package/dist/public/assets/{index-BIrFkB6r.js → index-BX17swkm.js} +1 -1
- package/dist/public/assets/index-BX17swkm.js.br +0 -0
- package/dist/public/assets/{index-BqwflQml.js → index-Bbsc4UYr.js} +1 -1
- package/dist/public/assets/{index-B6hY5GdS.js → index-BhswTE7o.js} +1 -1
- package/dist/public/assets/{index-DGkgqtgJ.js → index-BntW17GH.js} +1 -1
- package/dist/public/assets/{index-BY3eQmfP.js → index-BswJGTPK.js} +1 -1
- package/dist/public/assets/index-BswJGTPK.js.br +0 -0
- package/dist/public/assets/{index-BvPolBSn.js → index-CCX74BCm.js} +1 -1
- package/dist/public/assets/{index-Q0GC8Irj.js → index-CQ3yj6IA.js} +1 -1
- package/dist/public/assets/index-CQ3yj6IA.js.br +0 -0
- package/dist/public/assets/{index-Csmg5oyu.js → index-CRqInRg3.js} +1 -1
- package/dist/public/assets/{index-BegU9LBT.js → index-C_G_C9eS.js} +10 -10
- package/dist/public/assets/index-C_G_C9eS.js.br +0 -0
- package/dist/public/assets/{index-rLkONFpx.js → index-CqDAcAbN.js} +1 -1
- package/dist/public/assets/{index-Cb4Ja0tZ.js → index-CrRxN4us.js} +1 -1
- package/dist/public/assets/{index-CcUgN29Y.js → index-CyDpw03-.js} +1 -1
- package/dist/public/assets/{index-BrOFdVbv.js → index-D8BnlF58.js} +1 -1
- package/dist/public/assets/{index-DDy4PkWT.js → index-DAY6FKtH.js} +1 -1
- package/dist/public/assets/{index-CsiIrLKY.js → index-DKcAZ6VY.js} +1 -1
- package/dist/public/assets/{index-M8jf-YAZ.js → index-DS5Uafh7.js} +1 -1
- package/dist/public/assets/{index-FVHabbDB.js → index-DdxoW9oQ.js} +1 -1
- package/dist/public/assets/{index-CLKKui8G.js → index-O0yoYI51.js} +1 -1
- package/dist/public/assets/{index-DEQ2hVPA.js → index-aQ98LrVv.js} +1 -1
- package/dist/public/assets/index-aQ98LrVv.js.br +0 -0
- package/dist/public/assets/{index-8sDAOAcS.js → index-ivwHgxUB.js} +1 -1
- package/dist/public/assets/index-ivwHgxUB.js.br +0 -0
- package/dist/public/assets/{index-BwrZjkCc.js → index-sIdIkg5O.js} +1 -1
- package/dist/public/assets/{index-BLWgpW64.js → index-wTaBRIal.js} +1 -1
- package/dist/public/assets/{layers-Dbwq9AyL.js → layers-Bw-W5e-K.js} +1 -1
- package/dist/public/assets/{list-checks-og1usOZf.js → list-checks-ClFMgLBy.js} +1 -1
- package/dist/public/assets/{sparkles-p-dZbjGb.js → sparkles-JXa7CZhS.js} +1 -1
- package/dist/public/assets/{triangle-alert-BZVAEUiL.js → triangle-alert--wDqk97a.js} +1 -1
- package/dist/public/assets/{zap-BAhZUPPa.js → zap-D27jUGUv.js} +1 -1
- package/dist/public/index.html +1 -1
- package/dist/scripts/dev-remote-resources-smoke.js +80 -0
- package/dist/scripts/remoteResources.js +54 -0
- package/dist/scripts/verify-agent-contract.js +28 -0
- package/dist/scripts/wasm-collect-smoke.js +8 -2
- package/dist/scripts/worker.js +5 -1
- package/package.json +8 -4
- package/vibe-upload.md +4 -4
- package/dist/public/assets/Detail-CELZZ-4h.js.br +0 -0
- package/dist/public/assets/baseForm-I9suIiQn.js.br +0 -0
- package/dist/public/assets/index-8sDAOAcS.js.br +0 -0
- package/dist/public/assets/index-BIrFkB6r.js.br +0 -0
- package/dist/public/assets/index-BY3eQmfP.js.br +0 -0
- package/dist/public/assets/index-BegU9LBT.js.br +0 -0
- package/dist/public/assets/index-CgXOkYrX.js.br +0 -0
- package/dist/public/assets/index-DEQ2hVPA.js.br +0 -0
- package/dist/public/assets/index-Q0GC8Irj.js.br +0 -0
- package/dist/public/assets/index-mjEeEQcC.js.br +0 -0
package/dist/index.js
CHANGED
|
@@ -44,8 +44,8 @@ var got = require('got');
|
|
|
44
44
|
var ttmgPack = require('ttmg-pack');
|
|
45
45
|
var expressStaticGzip = require('express-static-gzip');
|
|
46
46
|
var fileUpload = require('express-fileupload');
|
|
47
|
-
var crypto$1 = require('node:crypto');
|
|
48
47
|
var fs$1 = require('node:fs');
|
|
48
|
+
var crypto$1 = require('node:crypto');
|
|
49
49
|
var zlib = require('zlib');
|
|
50
50
|
var promises$1 = require('fs/promises');
|
|
51
51
|
var os$1 = require('node:os');
|
|
@@ -6621,20 +6621,17 @@ function verboseWarn(...args) {
|
|
|
6621
6621
|
console.warn(...args);
|
|
6622
6622
|
}
|
|
6623
6623
|
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
* 自动不带这两个 header)。
|
|
6636
|
-
*/
|
|
6637
|
-
const CLI_PPE_ENV = 'ppe_role_perm'; // 走权限体系 PPE 环境
|
|
6624
|
+
// Ordinary platform requests use production unless a developer explicitly
|
|
6625
|
+
// selects a PPE lane. Vibe's opt-in trial supplies its own per-request headers.
|
|
6626
|
+
function getPlatformEnvironmentHeaders() {
|
|
6627
|
+
const lane = process.env.TTMG_PPE_ENV?.trim();
|
|
6628
|
+
if (!lane)
|
|
6629
|
+
return {};
|
|
6630
|
+
if (!/^ppe_[a-zA-Z0-9_-]{1,64}$/.test(lane)) {
|
|
6631
|
+
throw new Error('TTMG_PPE_ENV must be a PPE lane such as ppe_example');
|
|
6632
|
+
}
|
|
6633
|
+
return { 'x-use-ppe': '1', 'x-tt-env': lane };
|
|
6634
|
+
}
|
|
6638
6635
|
const NETWORK_PROXY_ERROR_CODE = -1001;
|
|
6639
6636
|
function getAxiosProxyConfig() {
|
|
6640
6637
|
const config = getTTMGRC();
|
|
@@ -6781,6 +6778,7 @@ function printApiResponseLog(title, result) {
|
|
|
6781
6778
|
]);
|
|
6782
6779
|
}
|
|
6783
6780
|
async function request({ url, method, data, headers, params, logRequestBody = true, logApiCalls = true, signal, }) {
|
|
6781
|
+
const environmentHeaders = getPlatformEnvironmentHeaders();
|
|
6784
6782
|
const config = getTTMGRC();
|
|
6785
6783
|
const cookie = sanitizeCookieHeader(config?.cookie);
|
|
6786
6784
|
const proxyConfig = getAxiosProxyConfig();
|
|
@@ -6802,11 +6800,7 @@ async function request({ url, method, data, headers, params, logRequestBody = tr
|
|
|
6802
6800
|
signal,
|
|
6803
6801
|
headers: {
|
|
6804
6802
|
Cookie: cookie,
|
|
6805
|
-
|
|
6806
|
-
// 显式传 `x-tt-env` 来覆盖本次请求(例如某个接口还没在 PPE 上发布)。
|
|
6807
|
-
...(CLI_PPE_ENV
|
|
6808
|
-
? { 'x-use-ppe': '1', 'x-tt-env': CLI_PPE_ENV }
|
|
6809
|
-
: {}),
|
|
6803
|
+
...environmentHeaders,
|
|
6810
6804
|
...(headers || {}),
|
|
6811
6805
|
},
|
|
6812
6806
|
...proxyConfig,
|
|
@@ -16386,7 +16380,7 @@ async function authStatus(options = {}) {
|
|
|
16386
16380
|
return result;
|
|
16387
16381
|
}
|
|
16388
16382
|
|
|
16389
|
-
var version = "0.4.6
|
|
16383
|
+
var version = "0.4.6";
|
|
16390
16384
|
var engines = {
|
|
16391
16385
|
node: ">=20.19.1 <21 || >=22"
|
|
16392
16386
|
};
|
|
@@ -20895,6 +20889,9 @@ const store = Store.getInstance({
|
|
|
20895
20889
|
nodeHttpPort: DEV_PORT,
|
|
20896
20890
|
nodeWsPort: DEV_WS_PORT,
|
|
20897
20891
|
packages: {},
|
|
20892
|
+
remoteCdnResources: undefined,
|
|
20893
|
+
nodeResourceHost: '',
|
|
20894
|
+
previewRemoteResources: undefined,
|
|
20898
20895
|
isUnderCompiling: false,
|
|
20899
20896
|
isUnderUploading: false,
|
|
20900
20897
|
isWaitingForUpload: false,
|
|
@@ -21044,6 +21041,139 @@ function formatHostForUrl(host) {
|
|
|
21044
21041
|
return net$1.isIPv6(host) ? `[${host}]` : host;
|
|
21045
21042
|
}
|
|
21046
21043
|
|
|
21044
|
+
const DEV_REMOTE_RESOURCE_PATH = '/game/remote-resources';
|
|
21045
|
+
const DEV_REMOTE_RESOURCE_CACHE = '__TTMG_TEMP__/remote-cdn';
|
|
21046
|
+
function isRelativeDirectory(value) {
|
|
21047
|
+
return typeof value === 'string' && value.length > 0 &&
|
|
21048
|
+
!/[\\:\x00-\x1f]/.test(value) &&
|
|
21049
|
+
value.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
21050
|
+
}
|
|
21051
|
+
function readDevRemoteCdnResources(value) {
|
|
21052
|
+
if (value == null)
|
|
21053
|
+
return undefined;
|
|
21054
|
+
const config = value;
|
|
21055
|
+
const source = new URL(config.base_url);
|
|
21056
|
+
if (!['http:', 'https:'].includes(source.protocol) || source.username ||
|
|
21057
|
+
source.password || source.search || source.hash ||
|
|
21058
|
+
!Array.isArray(config.resources) || config.resources.length === 0 ||
|
|
21059
|
+
!config.resources.every(item => item && isRelativeDirectory(item.root) &&
|
|
21060
|
+
isRelativeDirectory(item.output))) {
|
|
21061
|
+
throw new Error('Invalid compiled remote CDN resource declaration.');
|
|
21062
|
+
}
|
|
21063
|
+
return {
|
|
21064
|
+
base_url: config.base_url,
|
|
21065
|
+
resources: config.resources.map(({ root, output }) => ({ root, output })),
|
|
21066
|
+
};
|
|
21067
|
+
}
|
|
21068
|
+
function buildDevRemoteCdnResources(value, localBaseUrl) {
|
|
21069
|
+
const config = readDevRemoteCdnResources(value);
|
|
21070
|
+
if (!config)
|
|
21071
|
+
return undefined;
|
|
21072
|
+
const target = new URL(localBaseUrl || '');
|
|
21073
|
+
if (!['http:', 'https:'].includes(target.protocol) || target.username ||
|
|
21074
|
+
target.password || target.search || target.hash) {
|
|
21075
|
+
throw new Error('Invalid local remote resource service URL.');
|
|
21076
|
+
}
|
|
21077
|
+
return { ...config, platform_cdn_base_url: target.href.replace(/\/+$/, '') + '/' };
|
|
21078
|
+
}
|
|
21079
|
+
|
|
21080
|
+
const VIRTUAL_INTERFACE_PREFIX = /^(lo\d*|utun\d*|tun\d*|tap\d*|ppp\d*|ipsec\d*|wg\d*|tailscale\d*|zerotier\d*|veth|docker|br-|bridge|vmnet|vbox|anpi|awdl|llw|npf)/i;
|
|
21081
|
+
const VIRTUAL_INTERFACE_KEYWORDS = [
|
|
21082
|
+
'vmware',
|
|
21083
|
+
'virtual',
|
|
21084
|
+
'hyper-v',
|
|
21085
|
+
'vethernet',
|
|
21086
|
+
'anyconnect',
|
|
21087
|
+
'teleport',
|
|
21088
|
+
'npcap',
|
|
21089
|
+
'hamachi',
|
|
21090
|
+
];
|
|
21091
|
+
const WIRELESS_INTERFACE = /^(wl|wlan|wlp|wifi|wi-fi|airport)|无线|无线网络连接/i;
|
|
21092
|
+
const WIRED_INTERFACE = /^(en\d+|enp\w+|eno\w+|ens\w+|eth\w+)$|ethernet|\blan\b|以太网|本地连接/i;
|
|
21093
|
+
function isVirtualInterface(name) {
|
|
21094
|
+
const lowerName = name.toLowerCase();
|
|
21095
|
+
return (VIRTUAL_INTERFACE_PREFIX.test(lowerName) ||
|
|
21096
|
+
VIRTUAL_INTERFACE_KEYWORDS.some(keyword => lowerName.includes(keyword)));
|
|
21097
|
+
}
|
|
21098
|
+
function getInterfaceRank(name) {
|
|
21099
|
+
if (WIRELESS_INTERFACE.test(name))
|
|
21100
|
+
return 0;
|
|
21101
|
+
if (WIRED_INTERFACE.test(name))
|
|
21102
|
+
return 1;
|
|
21103
|
+
return 2;
|
|
21104
|
+
}
|
|
21105
|
+
function isPhysicalInterface(name) {
|
|
21106
|
+
return getInterfaceRank(name) < 2;
|
|
21107
|
+
}
|
|
21108
|
+
function isPrivateIPv4(ip) {
|
|
21109
|
+
return (ip.startsWith('10.') ||
|
|
21110
|
+
ip.startsWith('192.168.') ||
|
|
21111
|
+
/^172\.(1[6-9]|2\d|3[01])\./.test(ip));
|
|
21112
|
+
}
|
|
21113
|
+
function isUsableFallbackIPv4(ip) {
|
|
21114
|
+
const parts = ip.split('.').map(Number);
|
|
21115
|
+
if (parts.length !== 4 ||
|
|
21116
|
+
parts.some(part => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
21117
|
+
return false;
|
|
21118
|
+
}
|
|
21119
|
+
const [first, second] = parts;
|
|
21120
|
+
return (first !== 0 &&
|
|
21121
|
+
first !== 127 &&
|
|
21122
|
+
first < 224 &&
|
|
21123
|
+
!(first === 169 && second === 254));
|
|
21124
|
+
}
|
|
21125
|
+
function isIPv4Family(family) {
|
|
21126
|
+
return family === 4 || family === 'IPv4';
|
|
21127
|
+
}
|
|
21128
|
+
function selectLocalIPs(nets) {
|
|
21129
|
+
const privateResults = [];
|
|
21130
|
+
const physicalFallbacks = [];
|
|
21131
|
+
for (const [name, addrs] of Object.entries(nets)) {
|
|
21132
|
+
if (!addrs || isVirtualInterface(name) || !isPhysicalInterface(name)) {
|
|
21133
|
+
continue;
|
|
21134
|
+
}
|
|
21135
|
+
for (const net of addrs) {
|
|
21136
|
+
if (!isIPv4Family(net.family) ||
|
|
21137
|
+
net.internal ||
|
|
21138
|
+
!net.address) {
|
|
21139
|
+
continue;
|
|
21140
|
+
}
|
|
21141
|
+
const target = isPrivateIPv4(net.address)
|
|
21142
|
+
? privateResults
|
|
21143
|
+
: physicalFallbacks;
|
|
21144
|
+
if (isPrivateIPv4(net.address) ||
|
|
21145
|
+
isUsableFallbackIPv4(net.address)) {
|
|
21146
|
+
target.push({ name, address: net.address });
|
|
21147
|
+
}
|
|
21148
|
+
}
|
|
21149
|
+
}
|
|
21150
|
+
const candidates = privateResults.length > 0 ? privateResults : physicalFallbacks;
|
|
21151
|
+
const seen = new Set();
|
|
21152
|
+
return candidates
|
|
21153
|
+
.sort((a, b) => {
|
|
21154
|
+
const rankDiff = getInterfaceRank(a.name) - getInterfaceRank(b.name);
|
|
21155
|
+
return (rankDiff ||
|
|
21156
|
+
a.name.localeCompare(b.name, undefined, { numeric: true }));
|
|
21157
|
+
})
|
|
21158
|
+
.filter(item => {
|
|
21159
|
+
if (seen.has(item.address))
|
|
21160
|
+
return false;
|
|
21161
|
+
seen.add(item.address);
|
|
21162
|
+
return true;
|
|
21163
|
+
})
|
|
21164
|
+
.map(item => item.address);
|
|
21165
|
+
}
|
|
21166
|
+
function getLocalIPs() {
|
|
21167
|
+
return selectLocalIPs(os.networkInterfaces());
|
|
21168
|
+
}
|
|
21169
|
+
|
|
21170
|
+
function getRemoteResourceBaseUrl() {
|
|
21171
|
+
const { nodeResourceHost, nodeHttpPort } = store.getState();
|
|
21172
|
+
const host = nodeResourceHost || getLocalIPs()[0] || '127.0.0.1';
|
|
21173
|
+
const formattedHost = host.includes(':') ? `[${host}]` : host;
|
|
21174
|
+
return `http://${formattedHost}:${nodeHttpPort}${DEV_REMOTE_RESOURCE_PATH}/`;
|
|
21175
|
+
}
|
|
21176
|
+
|
|
21047
21177
|
function normalizeRuntimeDiscoveryMessage(message, peerAddress) {
|
|
21048
21178
|
if (!message || typeof message !== 'object')
|
|
21049
21179
|
return null;
|
|
@@ -21206,6 +21336,7 @@ class WsServer {
|
|
|
21206
21336
|
}
|
|
21207
21337
|
if (isSuccess) {
|
|
21208
21338
|
store.setState({
|
|
21339
|
+
nodeResourceHost: (request.socket.localAddress || '').replace(/^::ffff:/, ''),
|
|
21209
21340
|
clientHttpPort: port,
|
|
21210
21341
|
clientHost: host,
|
|
21211
21342
|
clientWsPort: wsPort,
|
|
@@ -21247,6 +21378,7 @@ class WsServer {
|
|
|
21247
21378
|
const payload = clientMessage.payload || {};
|
|
21248
21379
|
const { host, port, wsPort } = payload;
|
|
21249
21380
|
store.setState({
|
|
21381
|
+
nodeResourceHost: (request.socket.localAddress || '').replace(/^::ffff:/, ''),
|
|
21250
21382
|
clientHttpPort: port,
|
|
21251
21383
|
clientHost: host,
|
|
21252
21384
|
clientWsPort: wsPort,
|
|
@@ -21323,10 +21455,15 @@ class WsServer {
|
|
|
21323
21455
|
});
|
|
21324
21456
|
}
|
|
21325
21457
|
sendUploadStatus(status, payload) {
|
|
21458
|
+
const { remoteCdnResources } = store.getState();
|
|
21326
21459
|
this.send({
|
|
21327
21460
|
method: 'uploadStatus',
|
|
21328
21461
|
status,
|
|
21329
|
-
payload
|
|
21462
|
+
payload: status === 'success' ? {
|
|
21463
|
+
...payload,
|
|
21464
|
+
remoteCdnResources: remoteCdnResources || null,
|
|
21465
|
+
remoteResourceBaseUrl: remoteCdnResources ? getRemoteResourceBaseUrl() : null,
|
|
21466
|
+
} : payload,
|
|
21330
21467
|
});
|
|
21331
21468
|
}
|
|
21332
21469
|
}
|
|
@@ -21427,6 +21564,7 @@ async function compile(context) {
|
|
|
21427
21564
|
store.setState({
|
|
21428
21565
|
isUnderCompiling: false,
|
|
21429
21566
|
packages,
|
|
21567
|
+
remoteCdnResources: msg.remoteCdnResources,
|
|
21430
21568
|
});
|
|
21431
21569
|
/**
|
|
21432
21570
|
* 编译成功后,需要触发上传
|
|
@@ -21903,96 +22041,6 @@ function listen$1() {
|
|
|
21903
22041
|
});
|
|
21904
22042
|
}
|
|
21905
22043
|
|
|
21906
|
-
const VIRTUAL_INTERFACE_PREFIX = /^(lo\d*|utun\d*|tun\d*|tap\d*|ppp\d*|ipsec\d*|wg\d*|tailscale\d*|zerotier\d*|veth|docker|br-|bridge|vmnet|vbox|anpi|awdl|llw|npf)/i;
|
|
21907
|
-
const VIRTUAL_INTERFACE_KEYWORDS = [
|
|
21908
|
-
'vmware',
|
|
21909
|
-
'virtual',
|
|
21910
|
-
'hyper-v',
|
|
21911
|
-
'vethernet',
|
|
21912
|
-
'anyconnect',
|
|
21913
|
-
'teleport',
|
|
21914
|
-
'npcap',
|
|
21915
|
-
'hamachi',
|
|
21916
|
-
];
|
|
21917
|
-
const WIRELESS_INTERFACE = /^(wl|wlan|wlp|wifi|wi-fi|airport)|无线|无线网络连接/i;
|
|
21918
|
-
const WIRED_INTERFACE = /^(en\d+|enp\w+|eno\w+|ens\w+|eth\w+)$|ethernet|\blan\b|以太网|本地连接/i;
|
|
21919
|
-
function isVirtualInterface(name) {
|
|
21920
|
-
const lowerName = name.toLowerCase();
|
|
21921
|
-
return (VIRTUAL_INTERFACE_PREFIX.test(lowerName) ||
|
|
21922
|
-
VIRTUAL_INTERFACE_KEYWORDS.some(keyword => lowerName.includes(keyword)));
|
|
21923
|
-
}
|
|
21924
|
-
function getInterfaceRank(name) {
|
|
21925
|
-
if (WIRELESS_INTERFACE.test(name))
|
|
21926
|
-
return 0;
|
|
21927
|
-
if (WIRED_INTERFACE.test(name))
|
|
21928
|
-
return 1;
|
|
21929
|
-
return 2;
|
|
21930
|
-
}
|
|
21931
|
-
function isPhysicalInterface(name) {
|
|
21932
|
-
return getInterfaceRank(name) < 2;
|
|
21933
|
-
}
|
|
21934
|
-
function isPrivateIPv4(ip) {
|
|
21935
|
-
return (ip.startsWith('10.') ||
|
|
21936
|
-
ip.startsWith('192.168.') ||
|
|
21937
|
-
/^172\.(1[6-9]|2\d|3[01])\./.test(ip));
|
|
21938
|
-
}
|
|
21939
|
-
function isUsableFallbackIPv4(ip) {
|
|
21940
|
-
const parts = ip.split('.').map(Number);
|
|
21941
|
-
if (parts.length !== 4 ||
|
|
21942
|
-
parts.some(part => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
21943
|
-
return false;
|
|
21944
|
-
}
|
|
21945
|
-
const [first, second] = parts;
|
|
21946
|
-
return (first !== 0 &&
|
|
21947
|
-
first !== 127 &&
|
|
21948
|
-
first < 224 &&
|
|
21949
|
-
!(first === 169 && second === 254));
|
|
21950
|
-
}
|
|
21951
|
-
function isIPv4Family(family) {
|
|
21952
|
-
return family === 4 || family === 'IPv4';
|
|
21953
|
-
}
|
|
21954
|
-
function selectLocalIPs(nets) {
|
|
21955
|
-
const privateResults = [];
|
|
21956
|
-
const physicalFallbacks = [];
|
|
21957
|
-
for (const [name, addrs] of Object.entries(nets)) {
|
|
21958
|
-
if (!addrs || isVirtualInterface(name) || !isPhysicalInterface(name)) {
|
|
21959
|
-
continue;
|
|
21960
|
-
}
|
|
21961
|
-
for (const net of addrs) {
|
|
21962
|
-
if (!isIPv4Family(net.family) ||
|
|
21963
|
-
net.internal ||
|
|
21964
|
-
!net.address) {
|
|
21965
|
-
continue;
|
|
21966
|
-
}
|
|
21967
|
-
const target = isPrivateIPv4(net.address)
|
|
21968
|
-
? privateResults
|
|
21969
|
-
: physicalFallbacks;
|
|
21970
|
-
if (isPrivateIPv4(net.address) ||
|
|
21971
|
-
isUsableFallbackIPv4(net.address)) {
|
|
21972
|
-
target.push({ name, address: net.address });
|
|
21973
|
-
}
|
|
21974
|
-
}
|
|
21975
|
-
}
|
|
21976
|
-
const candidates = privateResults.length > 0 ? privateResults : physicalFallbacks;
|
|
21977
|
-
const seen = new Set();
|
|
21978
|
-
return candidates
|
|
21979
|
-
.sort((a, b) => {
|
|
21980
|
-
const rankDiff = getInterfaceRank(a.name) - getInterfaceRank(b.name);
|
|
21981
|
-
return (rankDiff ||
|
|
21982
|
-
a.name.localeCompare(b.name, undefined, { numeric: true }));
|
|
21983
|
-
})
|
|
21984
|
-
.filter(item => {
|
|
21985
|
-
if (seen.has(item.address))
|
|
21986
|
-
return false;
|
|
21987
|
-
seen.add(item.address);
|
|
21988
|
-
return true;
|
|
21989
|
-
})
|
|
21990
|
-
.map(item => item.address);
|
|
21991
|
-
}
|
|
21992
|
-
function getLocalIPs() {
|
|
21993
|
-
return selectLocalIPs(os.networkInterfaces());
|
|
21994
|
-
}
|
|
21995
|
-
|
|
21996
22044
|
async function init(options = {}) {
|
|
21997
22045
|
const providedClientKey = options.clientKey?.trim();
|
|
21998
22046
|
if (providedClientKey) {
|
|
@@ -22245,10 +22293,58 @@ async function listen(app, options) {
|
|
|
22245
22293
|
}
|
|
22246
22294
|
// @ts-ignore
|
|
22247
22295
|
const port = server.address().port;
|
|
22296
|
+
store.setState({ nodeHttpPort: port });
|
|
22248
22297
|
const url = `http://localhost:${port}?v=${encodeURIComponent(version)}`;
|
|
22249
22298
|
return { server, port, url, version };
|
|
22250
22299
|
}
|
|
22251
22300
|
|
|
22301
|
+
function isInside(root, target) {
|
|
22302
|
+
const relative = path$1.relative(root, target);
|
|
22303
|
+
return relative !== '' && relative !== '..' &&
|
|
22304
|
+
!relative.startsWith(`..${path$1.sep}`) && !path$1.isAbsolute(relative);
|
|
22305
|
+
}
|
|
22306
|
+
function remoteResourceMiddleware(getResources) {
|
|
22307
|
+
return (req, res) => {
|
|
22308
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS');
|
|
22309
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Range');
|
|
22310
|
+
if (req.method === 'OPTIONS') {
|
|
22311
|
+
res.sendStatus(204);
|
|
22312
|
+
return;
|
|
22313
|
+
}
|
|
22314
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
22315
|
+
res.setHeader('Allow', 'GET, HEAD, OPTIONS');
|
|
22316
|
+
res.sendStatus(405);
|
|
22317
|
+
return;
|
|
22318
|
+
}
|
|
22319
|
+
try {
|
|
22320
|
+
const { directory, declaration } = getResources();
|
|
22321
|
+
const relative = decodeURIComponent(req.path).replace(/^\//, '');
|
|
22322
|
+
const parts = relative.split('/');
|
|
22323
|
+
if (!declaration || /[\\\x00-\x1f]/.test(relative) ||
|
|
22324
|
+
parts.some(part => !part || part === '.' || part === '..' || part.startsWith('.')) ||
|
|
22325
|
+
!declaration.resources.some(({ root }) => relative.startsWith(`${root}/`))) {
|
|
22326
|
+
res.sendStatus(404);
|
|
22327
|
+
return;
|
|
22328
|
+
}
|
|
22329
|
+
const base = fs$1.realpathSync(directory);
|
|
22330
|
+
const file = path$1.resolve(base, ...parts);
|
|
22331
|
+
const realFile = fs$1.realpathSync(file);
|
|
22332
|
+
// Do not follow links added after compilation, including directory links.
|
|
22333
|
+
if (!isInside(base, realFile) || realFile !== file || !fs$1.statSync(realFile).isFile()) {
|
|
22334
|
+
res.sendStatus(404);
|
|
22335
|
+
return;
|
|
22336
|
+
}
|
|
22337
|
+
res.sendFile(realFile, { cacheControl: false, dotfiles: 'deny' }, error => {
|
|
22338
|
+
if (error && !res.headersSent)
|
|
22339
|
+
res.sendStatus(error.statusCode || 404);
|
|
22340
|
+
});
|
|
22341
|
+
}
|
|
22342
|
+
catch {
|
|
22343
|
+
res.sendStatus(404);
|
|
22344
|
+
}
|
|
22345
|
+
};
|
|
22346
|
+
}
|
|
22347
|
+
|
|
22252
22348
|
function setupMiddlewares(app, options) {
|
|
22253
22349
|
const { publicPath, outputDir } = options;
|
|
22254
22350
|
app.use(fileUpload());
|
|
@@ -22267,6 +22363,13 @@ function setupMiddlewares(app, options) {
|
|
|
22267
22363
|
});
|
|
22268
22364
|
app.use(express.json());
|
|
22269
22365
|
app.use(express.urlencoded({ extended: true }));
|
|
22366
|
+
app.use(DEV_REMOTE_RESOURCE_PATH, remoteResourceMiddleware(() => {
|
|
22367
|
+
const state = store.getState();
|
|
22368
|
+
return state.previewRemoteResources || {
|
|
22369
|
+
directory: path$1.join(outputDir, DEV_REMOTE_RESOURCE_CACHE),
|
|
22370
|
+
declaration: state.remoteCdnResources,
|
|
22371
|
+
};
|
|
22372
|
+
}));
|
|
22270
22373
|
app.use('/game/files', express.static(outputDir));
|
|
22271
22374
|
}
|
|
22272
22375
|
|
|
@@ -22445,7 +22548,6 @@ function buildCheckPkgsOptions(outputDir) {
|
|
|
22445
22548
|
};
|
|
22446
22549
|
}
|
|
22447
22550
|
|
|
22448
|
-
const outputDir$2 = getOutputDir();
|
|
22449
22551
|
const devToolVersion = getDevToolVersion();
|
|
22450
22552
|
const gameConfigRoute = {
|
|
22451
22553
|
method: 'get',
|
|
@@ -22453,7 +22555,7 @@ const gameConfigRoute = {
|
|
|
22453
22555
|
handler: async (req, res) => {
|
|
22454
22556
|
const [basic, checkResult] = await Promise.all([
|
|
22455
22557
|
ttmgPack.getPkgs({ entryDir: process.cwd() }),
|
|
22456
|
-
ttmgPack.checkPkgs(buildCheckPkgsOptions(
|
|
22558
|
+
ttmgPack.checkPkgs(buildCheckPkgsOptions(getOutputDir()), {
|
|
22457
22559
|
lang: getCurrentLanguage(),
|
|
22458
22560
|
}),
|
|
22459
22561
|
]);
|
|
@@ -22476,6 +22578,8 @@ const gameConfigRoute = {
|
|
|
22476
22578
|
checkResult,
|
|
22477
22579
|
lang: localLang,
|
|
22478
22580
|
nodeStaticBaseUrl: `http://localhost:${store.getState().nodeHttpPort}/game/files`,
|
|
22581
|
+
remoteCdnResources: store.getState().remoteCdnResources || null,
|
|
22582
|
+
remoteResourceBaseUrl: store.getState().remoteCdnResources ? getRemoteResourceBaseUrl() : null,
|
|
22479
22583
|
},
|
|
22480
22584
|
});
|
|
22481
22585
|
},
|
|
@@ -22519,12 +22623,12 @@ const gameConfigFillbackRoute = {
|
|
|
22519
22623
|
},
|
|
22520
22624
|
};
|
|
22521
22625
|
|
|
22522
|
-
const outputDir
|
|
22626
|
+
const outputDir = getOutputDir();
|
|
22523
22627
|
const gameCheckRoute = {
|
|
22524
22628
|
method: 'get',
|
|
22525
22629
|
path: '/game/check',
|
|
22526
22630
|
handler: async (req, res) => {
|
|
22527
|
-
const checkResult = await ttmgPack.checkPkgs(buildCheckPkgsOptions(store.getState().previewOutputDirectory || outputDir
|
|
22631
|
+
const checkResult = await ttmgPack.checkPkgs(buildCheckPkgsOptions(store.getState().previewOutputDirectory || outputDir), {
|
|
22528
22632
|
lang: getCurrentLanguage(),
|
|
22529
22633
|
});
|
|
22530
22634
|
res.send({ code: successCode, data: checkResult });
|
|
@@ -22532,6 +22636,51 @@ const gameCheckRoute = {
|
|
|
22532
22636
|
};
|
|
22533
22637
|
|
|
22534
22638
|
const changelog = [
|
|
22639
|
+
{
|
|
22640
|
+
title: '0.4.6',
|
|
22641
|
+
target: { iOS: '>=46.0', Android: '>=45.9' },
|
|
22642
|
+
changes: {
|
|
22643
|
+
bugfix: [
|
|
22644
|
+
{
|
|
22645
|
+
desc: {
|
|
22646
|
+
'zh-CN': '修复已声明 CDN 托管的远程资源仍被计入主包和代码包总大小的问题。',
|
|
22647
|
+
'en-US': 'Fix declared CDN-hosted resources being counted toward main-package and total code-package size.',
|
|
22648
|
+
},
|
|
22649
|
+
module: 'check',
|
|
22650
|
+
},
|
|
22651
|
+
{
|
|
22652
|
+
desc: {
|
|
22653
|
+
'zh-CN': '修复调试日志、截图和历史构建被带入代码打包、上传或包体检查的问题。',
|
|
22654
|
+
'en-US': 'Fix debug logs, screenshots and previous build outputs being included in code packaging, upload or package-size checks.',
|
|
22655
|
+
},
|
|
22656
|
+
module: 'upload',
|
|
22657
|
+
},
|
|
22658
|
+
{
|
|
22659
|
+
desc: {
|
|
22660
|
+
'zh-CN': '修复缺少 Wasm 分包组件时 CLI 无法启动的问题,项目检查等普通命令不再依赖该组件。',
|
|
22661
|
+
'en-US': 'Fix CLI startup failing when the Wasm splitting component is unavailable. Ordinary commands such as project checks no longer require it.',
|
|
22662
|
+
},
|
|
22663
|
+
module: 'new',
|
|
22664
|
+
},
|
|
22665
|
+
],
|
|
22666
|
+
feature: [
|
|
22667
|
+
{
|
|
22668
|
+
desc: {
|
|
22669
|
+
'zh-CN': '新增项目检查、本地构建、环境诊断和登录态查询的 JSON 输出,便于 AI 工具和自动化脚本调用。',
|
|
22670
|
+
'en-US': 'Add JSON output for project checks, local builds, environment diagnostics and authentication status for AI tools and automation scripts.',
|
|
22671
|
+
},
|
|
22672
|
+
module: 'new',
|
|
22673
|
+
},
|
|
22674
|
+
{
|
|
22675
|
+
desc: {
|
|
22676
|
+
'zh-CN': '新增上传预览选项,可在上传后等待平台处理结果,并通过本地预览页扫码打开游戏。',
|
|
22677
|
+
'en-US': 'Add an upload-preview option to wait for platform processing and open the game by scanning a QR code on the local preview page.',
|
|
22678
|
+
},
|
|
22679
|
+
module: 'upload',
|
|
22680
|
+
},
|
|
22681
|
+
],
|
|
22682
|
+
},
|
|
22683
|
+
},
|
|
22535
22684
|
{
|
|
22536
22685
|
title: '0.4.5',
|
|
22537
22686
|
target: {
|
|
@@ -23691,17 +23840,11 @@ const gameUploadRoute = {
|
|
|
23691
23840
|
},
|
|
23692
23841
|
};
|
|
23693
23842
|
|
|
23694
|
-
// 历史遗留:`remotePipeline.ts` 里的老远程分包接口 spread 了 `DEV_HEADERS`。
|
|
23695
|
-
// 目前全局 PPE 走的是 `libs/api/request.ts` 里的 `CLI_PPE_ENV`,这里保持
|
|
23696
|
-
// 相同的值是为了:一旦以后需要按接口粒度覆盖 PPE(例如远程走 PPE、本地
|
|
23697
|
-
// 走线上),只需在这里填回 header、两处值天然一致。
|
|
23698
23843
|
const BASE_URL = 'https://developers.tiktok.com';
|
|
23699
23844
|
const WASM_COLLECT_BASE_URL = `${BASE_URL}/api/wasm-collect/v1`;
|
|
23700
|
-
|
|
23701
|
-
//
|
|
23702
|
-
|
|
23703
|
-
// 'x-tt-target-idc': 'sg',
|
|
23704
|
-
};
|
|
23845
|
+
// Legacy remote-split calls retain this extension point. Shared request()
|
|
23846
|
+
// handles the explicit TTMG_PPE_ENV setting for all platform APIs.
|
|
23847
|
+
const DEV_HEADERS = {};
|
|
23705
23848
|
const TTMG_TEMP_DIR = '__TTMG_TEMP__';
|
|
23706
23849
|
const WASM_SPLIT_CACHE_DIR = `${TTMG_TEMP_DIR}/wasmcode/`;
|
|
23707
23850
|
const WASM_SYMBOL_FILE_NAME = 'webgl.symbols.json';
|
|
@@ -26689,15 +26832,16 @@ function registerRoutes(app, options) {
|
|
|
26689
26832
|
}
|
|
26690
26833
|
}
|
|
26691
26834
|
|
|
26692
|
-
const outputDir = getOutputDir();
|
|
26693
26835
|
const publicPath = path.join(__dirname, 'public');
|
|
26694
26836
|
async function start(options = {}) {
|
|
26695
26837
|
const startTime = Date.now();
|
|
26838
|
+
// Resolve after init has selected the current Client Key, not at module load.
|
|
26839
|
+
const outputDir = options.outputDirectory || getOutputDir();
|
|
26696
26840
|
const app = express();
|
|
26697
26841
|
// Before the IDE fallback and permissive game-resource CORS middleware.
|
|
26698
26842
|
if (options.scanPageHandler)
|
|
26699
26843
|
app.use(options.scanPageHandler);
|
|
26700
|
-
setupMiddlewares(app, { publicPath, outputDir
|
|
26844
|
+
setupMiddlewares(app, { publicPath, outputDir });
|
|
26701
26845
|
registerRoutes(app, { publicPath });
|
|
26702
26846
|
const result = await listen(app, {
|
|
26703
26847
|
maxRetries: 20,
|
|
@@ -27825,6 +27969,7 @@ function assertDevRuntimePackages(value) {
|
|
|
27825
27969
|
}
|
|
27826
27970
|
function buildDevMeta(options) {
|
|
27827
27971
|
assertDevRuntimePackages(options.packages);
|
|
27972
|
+
const remoteResources = buildDevRemoteCdnResources(options.remoteCdnResources, options.remoteResourceBaseUrl);
|
|
27828
27973
|
const { scopes, update_time, display_icon_url, request_allowed_domains, name, terms_of_service_link, privacy_policy_link, description, } = options.gameDetail || DEBUG_META_DATA;
|
|
27829
27974
|
return {
|
|
27830
27975
|
...DEBUG_META_DATA,
|
|
@@ -27835,8 +27980,13 @@ function buildDevMeta(options) {
|
|
|
27835
27980
|
icon_big_url: display_icon_url || DEBUG_META_DATA.icon_url,
|
|
27836
27981
|
client_key: options.clientKey,
|
|
27837
27982
|
minis_url: `https://minis-${options.clientKey}-vdebug-minigame.tiktok-minis.us/`,
|
|
27838
|
-
package_config: JSON.stringify({
|
|
27839
|
-
|
|
27983
|
+
package_config: JSON.stringify({
|
|
27984
|
+
packages: options.packages,
|
|
27985
|
+
...(remoteResources ? { remote_cdn_resources: remoteResources } : {}),
|
|
27986
|
+
}),
|
|
27987
|
+
allowed_domains: remoteResources
|
|
27988
|
+
? [...new Set([...(request_allowed_domains || []), new URL(remoteResources.platform_cdn_base_url).origin])]
|
|
27989
|
+
: request_allowed_domains || [],
|
|
27840
27990
|
status_code: 0,
|
|
27841
27991
|
status_msg: '',
|
|
27842
27992
|
update_time,
|
|
@@ -27875,7 +28025,11 @@ function capturePreviewBuild(sourceDirectory = getOutputDir(), packages = store.
|
|
|
27875
28025
|
recursive: true,
|
|
27876
28026
|
dereference: true,
|
|
27877
28027
|
});
|
|
27878
|
-
|
|
28028
|
+
const configPath = path$1.join(directory, 'packageConfig.json');
|
|
28029
|
+
const remoteCdnResources = fs$1.existsSync(configPath)
|
|
28030
|
+
? readDevRemoteCdnResources(JSON.parse(fs$1.readFileSync(configPath, 'utf8')).remote_cdn_resources)
|
|
28031
|
+
: undefined;
|
|
28032
|
+
return { directory, packages: metadata, remoteCdnResources, dispose };
|
|
27879
28033
|
}
|
|
27880
28034
|
catch {
|
|
27881
28035
|
dispose();
|
|
@@ -27918,6 +28072,7 @@ class ClientPreviewOrchestrator {
|
|
|
27918
28072
|
this.settingsDelivery = 'pending';
|
|
27919
28073
|
this.settingsRevision = 0;
|
|
27920
28074
|
this.latestBuild = null;
|
|
28075
|
+
this.resourceBuild = null;
|
|
27921
28076
|
this.activeDeployment = null;
|
|
27922
28077
|
this.pendingDeployment = null;
|
|
27923
28078
|
this.deployment = null;
|
|
@@ -28018,7 +28173,7 @@ class ClientPreviewOrchestrator {
|
|
|
28018
28173
|
this.deploymentFailure = null;
|
|
28019
28174
|
const previous = this.latestBuild;
|
|
28020
28175
|
this.latestBuild = build;
|
|
28021
|
-
if (previous && previous !== this.activeDeployment?.build)
|
|
28176
|
+
if (previous && previous !== this.activeDeployment?.build && previous !== this.resourceBuild)
|
|
28022
28177
|
previous.dispose();
|
|
28023
28178
|
// Retain successful compiles before scan and during connection setup too.
|
|
28024
28179
|
if (!this.initialized)
|
|
@@ -28111,7 +28266,7 @@ class ClientPreviewOrchestrator {
|
|
|
28111
28266
|
}
|
|
28112
28267
|
finally {
|
|
28113
28268
|
clearTimeout(deadline);
|
|
28114
|
-
if (request.build !== this.latestBuild)
|
|
28269
|
+
if (request.build !== this.latestBuild && request.build !== this.resourceBuild)
|
|
28115
28270
|
request.build.dispose();
|
|
28116
28271
|
this.activeDeployment = null;
|
|
28117
28272
|
}
|
|
@@ -28164,6 +28319,8 @@ class ClientPreviewOrchestrator {
|
|
|
28164
28319
|
clientKey: this.options.clientKey,
|
|
28165
28320
|
packages: build.packages,
|
|
28166
28321
|
gameDetail: gameInfo,
|
|
28322
|
+
remoteCdnResources: build.remoteCdnResources,
|
|
28323
|
+
remoteResourceBaseUrl: build.remoteCdnResources ? getRemoteResourceBaseUrl() : undefined,
|
|
28167
28324
|
});
|
|
28168
28325
|
}
|
|
28169
28326
|
catch (error) {
|
|
@@ -28172,7 +28329,23 @@ class ClientPreviewOrchestrator {
|
|
|
28172
28329
|
: 'Compiled package metadata is invalid.');
|
|
28173
28330
|
}
|
|
28174
28331
|
store.setState({ appId: gameInfo?.app_id });
|
|
28175
|
-
|
|
28332
|
+
const previousResources = this.resourceBuild;
|
|
28333
|
+
this.resourceBuild = build.remoteCdnResources ? build : null;
|
|
28334
|
+
store.setState({
|
|
28335
|
+
previewRemoteResources: build.remoteCdnResources ? {
|
|
28336
|
+
directory: path$1.join(build.directory, DEV_REMOTE_RESOURCE_CACHE),
|
|
28337
|
+
declaration: build.remoteCdnResources,
|
|
28338
|
+
} : undefined,
|
|
28339
|
+
});
|
|
28340
|
+
try {
|
|
28341
|
+
await this.runtime.post('/game/meta', meta, 30000, signal);
|
|
28342
|
+
}
|
|
28343
|
+
finally {
|
|
28344
|
+
if (previousResources && previousResources !== build &&
|
|
28345
|
+
previousResources !== this.latestBuild && previousResources !== this.activeDeployment?.build) {
|
|
28346
|
+
previousResources.dispose();
|
|
28347
|
+
}
|
|
28348
|
+
}
|
|
28176
28349
|
}
|
|
28177
28350
|
async logsSnapshot(options) {
|
|
28178
28351
|
return this.runtime.snapshot(options);
|
|
@@ -28236,10 +28409,15 @@ class ClientPreviewOrchestrator {
|
|
|
28236
28409
|
this.deployment = null;
|
|
28237
28410
|
this.initialized = false;
|
|
28238
28411
|
this.cancelPending();
|
|
28239
|
-
if (this.latestBuild && this.latestBuild !== this.activeDeployment?.build
|
|
28412
|
+
if (this.latestBuild && this.latestBuild !== this.activeDeployment?.build &&
|
|
28413
|
+
this.latestBuild !== this.resourceBuild) {
|
|
28240
28414
|
this.latestBuild.dispose();
|
|
28241
28415
|
}
|
|
28242
28416
|
this.latestBuild = null;
|
|
28417
|
+
if (this.resourceBuild && this.resourceBuild !== this.activeDeployment?.build)
|
|
28418
|
+
this.resourceBuild.dispose();
|
|
28419
|
+
this.resourceBuild = null;
|
|
28420
|
+
store.setState({ previewRemoteResources: undefined });
|
|
28243
28421
|
this.runtime.close();
|
|
28244
28422
|
}
|
|
28245
28423
|
}
|