askui
Version:
Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on
34 lines (33 loc) • 1.54 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
let lazilyInitializedSharpFactory;
class SharpImportError extends Error {
}
function dynamicallyImportSharp() {
return __awaiter(this, void 0, void 0, function* () {
try {
const sharp = yield import('sharp');
return sharp.default;
}
catch (err) {
throw new SharpImportError('Can\'t find "sharp" module to do resizing of image!'
+ ' Please, install sharp for resizing support with'
+ ' "npm install --save-dev sharp" or "npm install --save sharp".');
}
});
}
export function getSharpFactory() {
return __awaiter(this, void 0, void 0, function* () {
if (lazilyInitializedSharpFactory === undefined) {
lazilyInitializedSharpFactory = yield dynamicallyImportSharp();
}
return lazilyInitializedSharpFactory;
});
}