please bro just find ts
This commit is contained in:
@@ -10,26 +10,22 @@ async function getSharp(): Promise<typeof import("sharp") extends { default: inf
|
|||||||
return _sharp!;
|
return _sharp!;
|
||||||
} catch (bareErr) {
|
} catch (bareErr) {
|
||||||
try {
|
try {
|
||||||
const { createRequire } = await import("node:module");
|
const fs = await import("node:fs");
|
||||||
const path = await import("node:path");
|
const path = await import("node:path");
|
||||||
|
const url = await import("node:url");
|
||||||
const root = process.env.OVERLORD_ROOT || process.cwd();
|
const root = process.env.OVERLORD_ROOT || process.cwd();
|
||||||
const req = createRequire(path.join(root, "noop.js"));
|
const sharpDir = path.join(root, "node_modules", "sharp");
|
||||||
const candidates = [
|
const pkgJsonPath = path.join(sharpDir, "package.json");
|
||||||
path.join(root, "node_modules", "sharp"),
|
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
||||||
"sharp",
|
const entryRel: string =
|
||||||
];
|
(pkg.exports && (pkg.exports["."]?.require ?? pkg.exports["."]?.default ?? pkg.exports["."])) ||
|
||||||
let lastErr: unknown = bareErr;
|
pkg.main ||
|
||||||
for (const id of candidates) {
|
"lib/index.js";
|
||||||
try {
|
const entryAbs = path.resolve(sharpDir, typeof entryRel === "string" ? entryRel : "lib/index.js");
|
||||||
const mod = req(id);
|
const entryUrl = url.pathToFileURL(entryAbs).href;
|
||||||
_sharp = (mod && (mod.default ?? mod)) as any;
|
const mod: any = await import(entryUrl);
|
||||||
return _sharp!;
|
_sharp = (mod && (mod.default ?? mod)) as any;
|
||||||
} catch (err) {
|
return _sharp!;
|
||||||
lastErr = err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", lastErr);
|
|
||||||
throw lastErr;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", err);
|
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", err);
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
Reference in New Issue
Block a user