fix: remove useless CJS module dump, simplify code.ts to pass through extract names

This commit is contained in:
user 2026-07-20 13:38:02 -03:00
parent 8ef8e224a5
commit 9988515dc8
3 changed files with 4 additions and 59 deletions

View file

@ -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;

View file

@ -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<number, string>();
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<Map<string, number>> {
const files = new Map<string, number>();
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<string, number>();
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)));
}),

View file

@ -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) {