Skip to content

Commit

Permalink
build(deps-dev): bump pdfjs-dist from 3.11.174 to 4.2.67 (#5701)
Browse files Browse the repository at this point in the history
* fix: update pdfjs to v4

* update package

* fix: test

---------

Co-authored-by: Ioan Moldovan <[email protected]>
  • Loading branch information
dependabot[bot] and ioanmo226 authored May 28, 2024
1 parent 4252b8b commit 7438fdb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
1 change: 0 additions & 1 deletion extension/chrome/elements/attachment_preview.htm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<script src="/lib/jquery.min.js"></script>
<script src="/lib/sweetalert2.js"></script>
<script src="/lib/openpgp.js"></script>
<script src="/lib/pdf.js"></script>
<script src="attachment_preview.js" type="module"></script>
</body>
</html>
15 changes: 7 additions & 8 deletions extension/chrome/elements/attachment_preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
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';
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() {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/ui/attachment_preview_pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>;
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 7438fdb

Please sign in to comment.