From 7438fdbf740418b78a5b07aa7cef08f2e49a0a9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 14:23:31 +0300 Subject: [PATCH] build(deps-dev): bump pdfjs-dist from 3.11.174 to 4.2.67 (#5701) * fix: update pdfjs to v4 * update package * fix: test --------- Co-authored-by: Ioan Moldovan --- .../chrome/elements/attachment_preview.htm | 1 - .../chrome/elements/attachment_preview.ts | 15 +++++++------- .../js/common/ui/attachment_preview_pdf.ts | 2 +- package-lock.json | 20 +++++++++---------- package.json | 2 +- scripts/build.sh | 6 ++++-- tsconfig.json | 1 + 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/extension/chrome/elements/attachment_preview.htm b/extension/chrome/elements/attachment_preview.htm index 906d1118abd..9f4d3c68e03 100644 --- a/extension/chrome/elements/attachment_preview.htm +++ b/extension/chrome/elements/attachment_preview.htm @@ -26,7 +26,6 @@ - diff --git a/extension/chrome/elements/attachment_preview.ts b/extension/chrome/elements/attachment_preview.ts index 04fc9f64b7c..6afaa8fe13c 100644 --- a/extension/chrome/elements/attachment_preview.ts +++ b/extension/chrome/elements/attachment_preview.ts @@ -5,10 +5,8 @@ import { Assert } from '../../js/common/assert.js'; import { Attachment } from '../../js/common/core/attachment.js'; import { AttachmentDownloadView } from './attachment.js'; -import { AttachmentPreviewPdf } from '../../js/common/ui/attachment_preview_pdf.js'; import { BrowserMsg } from '../../js/common/browser/browser-msg.js'; import { KeyStore } from '../../js/common/platform/store/key-store.js'; -import { PDFDocumentProxy } from '../../types/pdf.js'; import { MsgUtil, DecryptError, DecryptErrTypes, DecryptSuccess, DecryptionError } from '../../js/common/core/crypto/pgp/msg-util.js'; import { View } from '../../js/common/view.js'; import { Xss } from '../../js/common/platform/xss.js'; @@ -16,14 +14,16 @@ import { Ui } from '../../js/common/browser/ui.js'; import { Url } from '../../js/common/core/common.js'; import { Browser } from '../../js/common/browser/browser.js'; import { AttachmentWarnings } from './shared/attachment_warnings.js'; +import * as pdfjsLib from 'pdfjs'; +import { AttachmentPreviewPdf } from '../../js/common/ui/attachment_preview_pdf.js'; +pdfjsLib.GlobalWorkerOptions.workerSrc = chrome.runtime.getURL(`lib/pdf.worker.min.mjs`); type AttachmentType = 'img' | 'txt' | 'pdf'; -declare const pdfjsLib: { getDocument: Function }; // eslint-disable-line @typescript-eslint/ban-types - View.run( class AttachmentPreviewView extends AttachmentDownloadView { protected readonly initiatorFrameId?: string; + private attachmentPreviewContainer = $('#attachment-preview-container'); public constructor() { @@ -61,10 +61,9 @@ View.run( } else if (attachmentType === 'pdf') { // PDF // .slice() is used to copy attachment data https://github.com/FlowCrypt/flowcrypt-browser/issues/5408 - pdfjsLib.getDocument({ data: result.slice() }).promise.then(async (pdf: PDFDocumentProxy) => { - const previewPdf = new AttachmentPreviewPdf(this.attachmentPreviewContainer, pdf); - await previewPdf.render(); - }); + const pdf = await pdfjsLib.getDocument({ data: result.slice() }).promise; + const previewPdf = new AttachmentPreviewPdf(this.attachmentPreviewContainer, pdf); + await previewPdf.render(); } } else { // no preview available, download button diff --git a/extension/js/common/ui/attachment_preview_pdf.ts b/extension/js/common/ui/attachment_preview_pdf.ts index a81891340c2..7cfd9f80cc0 100644 --- a/extension/js/common/ui/attachment_preview_pdf.ts +++ b/extension/js/common/ui/attachment_preview_pdf.ts @@ -3,7 +3,7 @@ 'use strict'; import { Catch } from '../platform/catch.js'; -import { PDFDocumentProxy } from '../../../types/pdf.js'; +import { PDFDocumentProxy } from 'pdfjs'; export class AttachmentPreviewPdf { private attachmentPreviewContainer: JQuery; diff --git a/package-lock.json b/package-lock.json index bddd4d6b5b1..da262f0d2db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "mailparser": "3.7.1", "mkdirp": "3.0.1", "openpgp": "5.11.1", - "pdfjs-dist": "3.11.174", + "pdfjs-dist": "4.2.67", "prettier": "^3.2.5", "puppeteer": "20.9.0", "stylelint": "16.5.0", @@ -9271,14 +9271,14 @@ "node": ">=8" } }, - "node_modules/path2d-polyfill": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz", - "integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==", + "node_modules/path2d": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/path2d/-/path2d-0.2.0.tgz", + "integrity": "sha512-KdPAykQX6kmLSOO6Jpu2KNcCED7CKjmaBNGGNuctOsG0hgYO1OdYQaan6cYXJiG0WmXOwZZPILPBimu5QAIw3A==", "dev": true, "optional": true, "engines": { - "node": ">=8" + "node": ">=6" } }, "node_modules/pathval": { @@ -9291,16 +9291,16 @@ } }, "node_modules/pdfjs-dist": { - "version": "3.11.174", - "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-3.11.174.tgz", - "integrity": "sha512-TdTZPf1trZ8/UFu5Cx/GXB7GZM30LT+wWUNfsi6Bq8ePLnb+woNKtDymI2mxZYBpMbonNFqKmiz684DIfnd8dA==", + "version": "4.2.67", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.2.67.tgz", + "integrity": "sha512-rJmuBDFpD7cqC8WIkQUEClyB4UAH05K4AsyewToMTp2gSy3Rrx8c1ydAVqlJlGv3yZSOrhEERQU/4ScQQFlLHA==", "dev": true, "engines": { "node": ">=18" }, "optionalDependencies": { "canvas": "^2.11.2", - "path2d-polyfill": "^2.0.1" + "path2d": "^0.2.0" } }, "node_modules/peberminta": { diff --git a/package.json b/package.json index 3f12dbb9ee2..1bc2fcdd0da 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "mailparser": "3.7.1", "mkdirp": "3.0.1", "openpgp": "5.11.1", - "pdfjs-dist": "3.11.174", + "pdfjs-dist": "4.2.67", "prettier": "^3.2.5", "puppeteer": "20.9.0", "stylelint": "16.5.0", diff --git a/scripts/build.sh b/scripts/build.sh index a9b63f2cec4..8415f1d7fff 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -51,8 +51,10 @@ copy_dependencies() { cp node_modules/clipboard/dist/clipboard.js $OUTPUT_DIRECTORY/lib/clipboard.js cp node_modules/@flowcrypt/fine-uploader/fine-uploader/fine-uploader.js $OUTPUT_DIRECTORY/lib/fine-uploader.js cp node_modules/filesize/dist/filesize.js $OUTPUT_DIRECTORY/lib/filesize.js - cp node_modules/pdfjs-dist/build/pdf.js $OUTPUT_DIRECTORY/lib/pdf.js - cp node_modules/pdfjs-dist/build/pdf.worker.js $OUTPUT_DIRECTORY/lib/pdf.worker.js + # Had to use legacy build as puppeteer returns 'Promise.withResolvers is not a function' error + # https://github.com/mozilla/pdf.js/issues/18006#issuecomment-2078739672 + cp node_modules/pdfjs-dist/legacy/build/pdf.min.mjs $OUTPUT_DIRECTORY/lib/pdf.min.mjs + cp node_modules/pdfjs-dist/legacy/build/pdf.worker.min.mjs $OUTPUT_DIRECTORY/lib/pdf.worker.min.mjs cp node_modules/bootstrap/dist/js/bootstrap.min.js $OUTPUT_DIRECTORY/lib/bootstrap/bootstrap.min.js cp node_modules/bootstrap/dist/css/bootstrap.min.css $OUTPUT_DIRECTORY/lib/bootstrap/bootstrap.min.css cp node_modules/@openpgp/web-stream-tools/lib/*.js $OUTPUT_DIRECTORY/lib/streams diff --git a/tsconfig.json b/tsconfig.json index fe84521a49f..3fe1c226d81 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,7 @@ "jquery": ["lib/jquery.min.js", "COMMENT"], "sweetalert2": ["lib/sweetalert2.js", "COMMENT"], "openpgp": ["lib/openpgp.min.mjs", "../node_modules/openpgp/openpgp.d.js"], + "pdfjs": ["lib/pdf.min.mjs", "types/pdf.js.d.ts"], "squire-rte": ["../node_modules/squire-rte/dist/types/Squire.d.ts"], "@openpgp/web-stream-tools": ["../node_modules/@openpgp/web-stream-tools/types/index.v4.9.d.ts", "lib/streams/streams.js"], "dompurify": ["types/purify.d.ts", "lib/purify.js", "COMMENT"],