@anrans001/ttmg-cli 0.3.6-beta.wasmcode.split.3 → 0.3.6-beta.wasmcode.split.4
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/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9134,6 +9134,26 @@ function keepCacheSync({ entryDir, originalWasmPath, originalSplitConfigPath, })
|
|
|
9134
9134
|
if (!fs__namespace.existsSync(gameJsonCachePath)) {
|
|
9135
9135
|
fs__namespace.copyFileSync(gameJsonPath, gameJsonCachePath);
|
|
9136
9136
|
}
|
|
9137
|
+
/**
|
|
9138
|
+
* 保存 wasmcode/game.js(如果存在)
|
|
9139
|
+
*
|
|
9140
|
+
* 抖音 / 微信 mini-game 平台对 game.json.subpackages 里声明的每个子包
|
|
9141
|
+
* 都要求根目录有 `game.js`(哪怕是空文件)作为 `tt.loadSubpackage` 的
|
|
9142
|
+
* 入口锚点,否则子包加载直接失败。很多 Unity 项目把 wasmcode 当成
|
|
9143
|
+
* 一个内置子包(参考真实工程的 game.json),原始 wasmcode/ 里就有
|
|
9144
|
+
* 一个空 game.js。split 阶段虽然也会重写它,但回退时如果不把这个
|
|
9145
|
+
* 占位文件还原回来,mini-game 启动会因为找不到 wasmcode/game.js
|
|
9146
|
+
* 而崩。
|
|
9147
|
+
*
|
|
9148
|
+
* 这里只在源文件存在时才备份,避免给"原始就没有 game.js"的工程
|
|
9149
|
+
* 偷偷塞一个空文件污染回退状态。
|
|
9150
|
+
*/
|
|
9151
|
+
const originGameJsPath = path__namespace.join(entryDir, WASM_SPLIT_SUBPACKAGE_CONFIG.origin.root, 'game.js');
|
|
9152
|
+
const originGameJsCachePath = path__namespace.join(cacheDir, 'wasmcode-game.js');
|
|
9153
|
+
if (fs__namespace.existsSync(originGameJsPath) &&
|
|
9154
|
+
!fs__namespace.existsSync(originGameJsCachePath)) {
|
|
9155
|
+
fs__namespace.copyFileSync(originGameJsPath, originGameJsCachePath);
|
|
9156
|
+
}
|
|
9137
9157
|
return {
|
|
9138
9158
|
cacheDir,
|
|
9139
9159
|
};
|
|
@@ -9158,6 +9178,11 @@ function restoreSplitConfigFromCache(entryDir = process.cwd()) {
|
|
|
9158
9178
|
* - original (unmodified) wasm file back into its `wasmcode/<file>.br` location
|
|
9159
9179
|
* - webgl-wasm-split.js back to its template (with placeholders)
|
|
9160
9180
|
* - game.json back to its pre-split version
|
|
9181
|
+
* - wasmcode/game.js — restore from cache if backed up, otherwise write empty
|
|
9182
|
+
* (mini-game runtime requires every subpackage root to contain `game.js` as
|
|
9183
|
+
* a `tt.loadSubpackage` entry anchor; many Unity projects ship with
|
|
9184
|
+
* wasmcode declared as a subpackage in game.json, so a missing wasmcode/game.js
|
|
9185
|
+
* after rollback breaks subpackage loading at boot)
|
|
9161
9186
|
* - remove ALL generated sub-package directories (see SPLIT_OUTPUT_DIRS) —
|
|
9162
9187
|
* includes both legacy (wasmcode-android / wasmcode1-android / wasmcode-ios /
|
|
9163
9188
|
* wasmcode1-ios) and archive-mode (wasmcode1 / wasmcode-archive) outputs
|
|
@@ -9206,6 +9231,28 @@ function restoreFromCache(entryDir = process.cwd()) {
|
|
|
9206
9231
|
if (fs.existsSync(gameJsonCachePath)) {
|
|
9207
9232
|
fs.copyFileSync(gameJsonCachePath, path.join(entryDir, 'game.json'));
|
|
9208
9233
|
}
|
|
9234
|
+
// Restore wasmcode/game.js. We just deleted whatever was there in step 1,
|
|
9235
|
+
// so we always need to put something back when wasmcode is a subpackage.
|
|
9236
|
+
// Strategy:
|
|
9237
|
+
// - Prefer the cache (keepCacheSync stashes pre-split contents to
|
|
9238
|
+
// `__unity_cache__/wasmcode-game.js` when the original existed)
|
|
9239
|
+
// - Fall back to writing an empty file. Rationale: if we got here the
|
|
9240
|
+
// dir exists, the .br is in place, and the project's game.json — now
|
|
9241
|
+
// restored above — likely still lists wasmcode as a subpackage (true
|
|
9242
|
+
// for every Unity template we ship). An empty game.js is exactly what
|
|
9243
|
+
// downloadSplited.ts also writes; it satisfies the platform requirement
|
|
9244
|
+
// without changing semantics for projects that don't use wasmcode as
|
|
9245
|
+
// a subpackage (the file is harmless empty).
|
|
9246
|
+
const originGameJsCachePath = path.join(cacheDir, 'wasmcode-game.js');
|
|
9247
|
+
const originGameJsDestPath = path.join(originDir, 'game.js');
|
|
9248
|
+
if (fs.existsSync(originDir)) {
|
|
9249
|
+
if (fs.existsSync(originGameJsCachePath)) {
|
|
9250
|
+
fs.copyFileSync(originGameJsCachePath, originGameJsDestPath);
|
|
9251
|
+
}
|
|
9252
|
+
else {
|
|
9253
|
+
fs.writeFileSync(originGameJsDestPath, '', 'utf-8');
|
|
9254
|
+
}
|
|
9255
|
+
}
|
|
9209
9256
|
for (const subDir of SPLIT_OUTPUT_DIRS) {
|
|
9210
9257
|
const full = path.join(entryDir, subDir);
|
|
9211
9258
|
if (fs.existsSync(full)) {
|
|
@@ -11732,7 +11779,7 @@ async function upload({ clientKey, note = '--', dir, }) {
|
|
|
11732
11779
|
}
|
|
11733
11780
|
}
|
|
11734
11781
|
|
|
11735
|
-
var version = "0.3.6-beta.wasmcode.split.
|
|
11782
|
+
var version = "0.3.6-beta.wasmcode.split.4";
|
|
11736
11783
|
var pkg = {
|
|
11737
11784
|
version: version};
|
|
11738
11785
|
|