Fix Turbopack module resolution for lzma and restore path imports
This commit is contained in:
1 parent
a5044c80d7
commit
e06596391e
35 files changed
+392
-333
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { existsSync, promises as fs } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import { extractFurniIconPng } from "@/lib/services/clone-icon";
|
||||
@@ -16,6 +15,7 @@ import {
|
||||
} from "@/lib/services/furni-asset-dirs";
|
||||
import { downloadFile } from "@/lib/services/import/core/download";
|
||||
import { classifyCatalogItem, NO_ASSET_KINDS } from "@/lib/services/item-kind";
|
||||
import { getRuntimePath } from "@/lib/utils/runtime-path";
|
||||
import { ensureDirectories } from "./furni-import";
|
||||
|
||||
const REPAIR_CONCURRENCY = 6;
|
||||
@@ -61,7 +61,7 @@ async function writeIconToDirs(
|
||||
for (const dir of dirs) {
|
||||
try {
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
await fs.writeFile(path.join(dir, fileName), icon);
|
||||
await fs.writeFile(getRuntimePath(dir, fileName), icon);
|
||||
} catch (err) {
|
||||
errors.push(`write icon to ${dir} failed: ${(err as Error).message}`);
|
||||
}
|
||||
@@ -75,12 +75,12 @@ async function copyIconAcrossDirs(
|
||||
fileName: string,
|
||||
): Promise<string[]> {
|
||||
const errors: string[] = [];
|
||||
const src = path.join(srcDir, fileName);
|
||||
const src = getRuntimePath(srcDir, fileName);
|
||||
for (const dir of destDirs) {
|
||||
if (dir === srcDir) continue;
|
||||
try {
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
await fs.copyFile(src, path.join(dir, fileName));
|
||||
await fs.copyFile(src, getRuntimePath(dir, fileName));
|
||||
} catch (err) {
|
||||
errors.push(`copy icon to ${dir} failed: ${(err as Error).message}`);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ export async function repairMissingIcons(
|
||||
const gamedataRoot = await getGamedataRoot();
|
||||
if (gamedataRoot) {
|
||||
const badgeFiles = await fs
|
||||
.readdir(path.join(gamedataRoot, "album1584"))
|
||||
.readdir(getRuntimePath(gamedataRoot, "album1584"))
|
||||
.catch(() => [] as string[]);
|
||||
const albumBadgeSet = new Set(
|
||||
badgeFiles.filter((f) => f.endsWith(".gif")).map((f) => f.slice(0, -4)),
|
||||
@@ -214,7 +214,7 @@ export async function repairMissingIcons(
|
||||
// Badge items store icons as badge_<code>_icon.png (the classname already
|
||||
// includes the `badge_` prefix, so fileName matches correctly).
|
||||
const presentDirs = iconDirs.filter((dir) =>
|
||||
existsSync(path.join(dir, fileName)),
|
||||
existsSync(getRuntimePath(dir, fileName)),
|
||||
);
|
||||
const missingDirs = iconDirs.filter((dir) => !presentDirs.includes(dir));
|
||||
|
||||
@@ -247,7 +247,7 @@ export async function repairMissingIcons(
|
||||
if (!ok) {
|
||||
let foundNitro = false;
|
||||
for (const dir of nitroDirs) {
|
||||
const nitroPath = path.join(dir, `${classname}.nitro`);
|
||||
const nitroPath = getRuntimePath(dir, `${classname}.nitro`);
|
||||
if (!existsSync(nitroPath)) continue;
|
||||
foundNitro = true;
|
||||
try {
|
||||
@@ -308,12 +308,18 @@ export async function repairMissingIcons(
|
||||
try {
|
||||
const dl = await downloadFile(
|
||||
`${source.iconBaseUrl}/${iconName}`,
|
||||
path.join(targets.iconDir, fileName),
|
||||
/*turbopackIgnore: true*/ getRuntimePath(
|
||||
targets.iconDir,
|
||||
fileName,
|
||||
),
|
||||
{ maxRetries: 1, validate: "png" },
|
||||
);
|
||||
if (dl.ok) {
|
||||
const icon = await fs.readFile(
|
||||
path.join(targets.iconDir, fileName),
|
||||
/*turbopackIgnore: true*/ getRuntimePath(
|
||||
targets.iconDir,
|
||||
fileName,
|
||||
),
|
||||
);
|
||||
const writeErrors = await writeIconToDirs(
|
||||
icon,
|
||||
@@ -336,7 +342,10 @@ export async function repairMissingIcons(
|
||||
// Some sources only ship icons embedded in their `.nitro` bundles —
|
||||
// grab the bundle and extract the catalog icon from it.
|
||||
if (source.nitroBaseUrl) {
|
||||
const nitroTmp = path.join(os.tmpdir(), `.repair_${classname}.nitro`);
|
||||
const nitroTmp = getRuntimePath(
|
||||
os.tmpdir(),
|
||||
`.repair_${classname}.nitro`,
|
||||
);
|
||||
try {
|
||||
const dl = await downloadFile(
|
||||
`${source.nitroBaseUrl}/${classname}.nitro`,
|
||||
|
||||
Reference in new issue
Block a user