mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-10-18 13:50:50 +02:00
fix: validate PDF.js syntax before publishing assets
This commit is contained in:
1 parent
b72631bbbe
commit
37426d0c48
2 files changed
+12
No files matched your search
@@ -8,6 +8,7 @@ const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const esbuild = require("esbuild");
|
||||
const { compileTemplate } = require("vue/compiler-sfc");
|
||||
const { Script } = require("node:vm");
|
||||
const { promisify } = require("node:util");
|
||||
|
||||
const coreJsFiles = [
|
||||
@@ -69,6 +70,9 @@ async function buildVendorJs() {
|
||||
await Promise.all(Object.entries(lazyGroups).map(async ([name, files]) => {
|
||||
// PDF.js is already minified upstream. Re-minifying it breaks rendering
|
||||
// for documents such as #857, even though page.render() resolves.
|
||||
if (name === "pdf") {
|
||||
for (const file of files) new Script(fs.readFileSync(file, "utf8"), { filename: file });
|
||||
}
|
||||
const transforms = name === "pdf" ? [] : [uglify()];
|
||||
await promisify(pipeline)(orderedSrc(files), concat(`${name}.min.js`), ...transforms, dest("public/script"));
|
||||
lazyAssets[name] = `/script/${name}.${hashFile(`public/script/${name}.min.js`)}.min.js`;
|
||||
|
||||
@@ -75,6 +75,14 @@ describe("asset build", function () {
|
||||
expect(bundled.equals(upstream)).to.equal(true);
|
||||
});
|
||||
|
||||
it("rejects invalid PDF.js without publishing a manifest", function () {
|
||||
fs.writeFileSync(path.join(directory, groups.pdfFiles[0]), "function {");
|
||||
const result = build();
|
||||
expect(result.status).not.to.equal(0);
|
||||
expect(result.stderr).to.include("SyntaxError");
|
||||
expect(fs.existsSync(path.join(directory, "public/asset-manifest.json"))).to.equal(false);
|
||||
});
|
||||
|
||||
it("fails on missing input without publishing a manifest", function () {
|
||||
fs.unlinkSync(path.join(directory, groups.coreJsFiles[0]));
|
||||
const result = build();
|
||||
|
||||
Reference in new issue
Block a user