fix(deps): libxmljs2 is now an optional dependency and can be handled if missing

This commit is contained in:
lowlighter
2022-07-04 19:58:37 -04:00
parent dade2cd2bd
commit 71c4e48d6c
3 changed files with 233 additions and 260 deletions

466
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -78,6 +78,7 @@
"transform": {}
},
"optionalDependencies": {
"gifencoder": "^2.0.1"
"gifencoder": "^2.0.1",
"libxmljs2": "^0.30.1"
}
}

View File

@@ -186,12 +186,20 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
//Verify svg
if (verify) {
console.debug(`metrics/compute/${login} > verify SVG`)
const libxmljs = (await import("libxmljs2")).default
let libxmljs = null
try {
libxmljs = (await import("libxmljs2")).default
}
catch (error) {
console.debug(`metrics/compute/${login} > failed to import libxmljs2 (${error}), ignoring SVG verification`)
}
if (!libxmljs) {
const parsed = libxmljs.parseXml(rendered)
if (parsed.errors.length)
throw new Error(`Malformed SVG : \n${parsed.errors.join("\n")}`)
console.debug(`metrics/compute/${login} > verified SVG, no parsing errors found`)
}
}
//Resizing
const {resized, mime} = await imports.svg.resize(rendered, {paddings: q["config.padding"] || conf.settings.padding, convert: convert === "svg" ? null : convert, scripts: [...data.postscripts, extras.js || null].filter(x => x)})
rendered = resized