From 9988515dc8e8574cb3578166ea48bbc71271d9c4 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 20 Jul 2026 13:38:02 -0300 Subject: [PATCH] fix: remove useless CJS module dump, simplify code.ts to pass through extract names --- src/update/shared.ts | 1 - src/update/tasks/code.ts | 52 ++--------------------------------- src/update/tasks/decompile.ts | 10 +------ 3 files changed, 4 insertions(+), 59 deletions(-) diff --git a/src/update/shared.ts b/src/update/shared.ts index deb016731d6..6d4c3028c1e 100644 --- a/src/update/shared.ts +++ b/src/update/shared.ts @@ -7,7 +7,6 @@ export const workFolder = "tmp"; export const apksFolder = join(workFolder, "apks"); export const codePath = join(workFolder, "code.js"); export const modulesPath = join(workFolder, "modules"); -export const moduleMapPath = join(workFolder, "module-map.json"); export const apkSplits = ["base", "config.hdpi", "config.xxhdpi"] as const; export const oprevFiles = ["source.jsonl"] as const; diff --git a/src/update/tasks/code.ts b/src/update/tasks/code.ts index 4e86547490b..8bcc6036fe7 100644 --- a/src/update/tasks/code.ts +++ b/src/update/tasks/code.ts @@ -2,23 +2,9 @@ import { mkdir, rm, readdir, stat } from "node:fs/promises"; import { join as pathJoin } from "node:path"; import { commit } from "../git"; import type { Progress } from "../progress"; -import { commitAnyway, cuteVersion, moduleMapPath, modulesPath } from "../shared"; +import { commitAnyway, cuteVersion, modulesPath } from "../shared"; import { join, sortEntries } from "../utils"; -const moduleIdRegex = /^module_(\d+)\.js$/; -const idPrefixRegex = /^(\d+)_(.+)$/; - -function extractModuleId(filename: string): number | undefined { - let m = filename.match(moduleIdRegex); - if (m) return Number.parseInt(m[1], 10); - m = filename.match(idPrefixRegex); - if (m) return Number.parseInt(m[1], 10); -} - -function sanitizePath(name: string): string { - return name.replace(/[<>:"|?*]/g, "_").replace(/\.\./g, "__"); -} - export default async function code(progress: Progress, _code: string[]) { progress.start("code_getting"); @@ -26,24 +12,6 @@ export default async function code(progress: Progress, _code: string[]) { throw new Error(`Modules directory not found at ${modulesPath}`); } - const moduleMap = new Map(); - try { - const mapRaw = await Bun.file(moduleMapPath).json(); - if (Array.isArray(mapRaw)) { - for (const entry of mapRaw) { - if (entry.name?.trim()) moduleMap.set(entry.id, entry.name); - } - } else if (mapRaw && typeof mapRaw === "object") { - for (const [key, value] of Object.entries(mapRaw)) { - const id = Number(key); - if (!Number.isNaN(id) && typeof value === "string" && value.trim()) { - moduleMap.set(id, value); - } - } - } - } catch {} - console.log(`Loaded ${moduleMap.size} module name mappings`); - async function scanDir(dir: string, basePath: string): Promise> { const files = new Map(); const entries = await readdir(dir, { withFileTypes: true }); @@ -63,23 +31,9 @@ export default async function code(progress: Progress, _code: string[]) { const rawFiles = await scanDir(modulesPath, modulesPath); - function resolveDest(relativePath: string): string { - const id = extractModuleId(relativePath); - if (id !== undefined) { - const mappedName = moduleMap.get(id); - if (mappedName) return sanitizePath(mappedName) + ".js"; - } - return relativePath; - } - - const files = new Map(); - for (const [relativePath, fileSize] of rawFiles) { - files.set(resolveDest(relativePath), fileSize); - } - await Bun.write( "../data/source.jsonl", - sortEntries([...files.entries()]) + sortEntries([...rawFiles.entries()]) .map(([file, size]) => `{ "file": ${JSON.stringify(file)}, "size": ${size} }`) .join("\n"), ); @@ -94,7 +48,7 @@ export default async function code(progress: Progress, _code: string[]) { await Promise.all( [...rawFiles.entries()].map(async ([relativePath]) => { - const dest = join(filePrefix, resolveDest(relativePath)); + const dest = join(filePrefix, relativePath); await mkdir(pathJoin(dest, ".."), { recursive: true }); await Bun.write(dest, Bun.file(join(modulesPath, relativePath))); }), diff --git a/src/update/tasks/decompile.ts b/src/update/tasks/decompile.ts index c1e8f2917fc..c8d4048c0d6 100644 --- a/src/update/tasks/decompile.ts +++ b/src/update/tasks/decompile.ts @@ -1,7 +1,7 @@ import { exists } from "node:fs/promises"; import { commit } from "../git"; import type { Progress } from "../progress"; -import { codePath, commitAnyway, cuteVersion, moduleMapPath, modulesPath, workFolder } from "../shared"; +import { codePath, commitAnyway, cuteVersion, modulesPath, workFolder } from "../shared"; import { handleShellErr, join } from "../utils"; const gzipWorkerURL = new URL("decompile-gzip.ts", import.meta.url).href; @@ -45,14 +45,6 @@ export default async function decompile(progress: Progress, pathToBundle: string .then(handleShellErr); } - if (!(await Bun.file(moduleMapPath).exists())) { - await Bun.$`${decompilerBin} dump ${pathToBundle} --kind cjs-modules --json` - .quiet() - .nothrow() - .then(handleShellErr) - .then((out) => Bun.write(moduleMapPath, out.stdout)); - } - progress.update("decompile_decompiling", true); if (process.env.NODE_ENV !== "test" && !commitAnyway) {