Патчи к code mode и доки по его настройке
This commit is contained in:
+31
-3
@@ -44,7 +44,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AssetTools = void 0;
|
||||
const package_json_1 = __importDefault(require("../../../package.json"));
|
||||
const sharp_1 = __importDefault(require("sharp"));
|
||||
let sharp_1;
|
||||
/**
|
||||
* Cocos Creator keeps its own sharp (0.32.6) resident in this process. On
|
||||
* Windows a second libvips cannot be loaded beside it, so the copy bundled with
|
||||
* this extension binds against the editor's older DLL and throws while loading.
|
||||
* Prefer the editor's build, fall back to the bundled one, and tolerate neither
|
||||
* being usable - asset previews fall back to the renderer-based path.
|
||||
*/
|
||||
function getSharp() {
|
||||
if (sharp_1 !== undefined)
|
||||
return sharp_1;
|
||||
const { join } = require('path');
|
||||
const candidates = [];
|
||||
if (process.resourcesPath)
|
||||
candidates.push(join(process.resourcesPath, 'app.asar.unpacked', 'node_modules', 'sharp'));
|
||||
candidates.push('sharp');
|
||||
for (const candidate of candidates) {
|
||||
try {
|
||||
sharp_1 = require(candidate);
|
||||
return sharp_1;
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`[cocos-code-mode] sharp not loadable from ${candidate}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
sharp_1 = null;
|
||||
return sharp_1;
|
||||
}
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const decorators_1 = require("../decorators");
|
||||
const schemas_1 = require("../schemas");
|
||||
@@ -333,9 +360,10 @@ class AssetTools {
|
||||
sourcePath = fileInfo.file;
|
||||
}
|
||||
}
|
||||
if (sourcePath && fs_extra_1.default.existsSync(sourcePath)) {
|
||||
const sharp = sourcePath ? getSharp() : null;
|
||||
if (sharp && fs_extra_1.default.existsSync(sourcePath)) {
|
||||
try {
|
||||
const image = (0, sharp_1.default)(sourcePath);
|
||||
const image = sharp(sourcePath);
|
||||
const metadata = await image.metadata();
|
||||
const requestedSize = args.imageSize || 512;
|
||||
let processed = image;
|
||||
|
||||
Reference in New Issue
Block a user