From 65734c3161fe732ec9bfea3b1cfdadf388d9b126 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Thu, 22 May 2025 23:33:28 -0300 Subject: [PATCH 1/5] feat: updated filesize --- .github/dependabot.yml | 2 -- extension/chrome/elements/pgp_block.htm | 1 - .../pgp-block-attachments-module.ts | 6 ++-- extension/types/file-size.d.ts | 31 +++++++++++++++++++ package-lock.json | 8 ++--- package.json | 2 +- scripts/build.js | 2 +- tsconfig.json | 2 +- 8 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 extension/types/file-size.d.ts diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 08875ac9b1f..75f53724143 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -32,5 +32,3 @@ updates: update-types: ["version-update:semver-major"] - dependency-name: "chai-as-promised" update-types: ["version-update:semver-major"] - - dependency-name: "filesize" - versions: [ ">= 10.1.3" ] diff --git a/extension/chrome/elements/pgp_block.htm b/extension/chrome/elements/pgp_block.htm index f8f07a16198..ed3c39c3bfb 100644 --- a/extension/chrome/elements/pgp_block.htm +++ b/extension/chrome/elements/pgp_block.htm @@ -41,7 +41,6 @@ - diff --git a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts index add3d36856c..cbf605db2eb 100644 --- a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts +++ b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts @@ -14,8 +14,7 @@ import { XssSafeFactory } from '../../../js/common/xss-safe-factory.js'; import { Str } from '../../../js/common/core/common.js'; import { AttachmentWarnings } from '../shared/attachment_warnings.js'; import { MsgUtil } from '../../../js/common/core/crypto/pgp/msg-util.js'; - -declare const filesize: { filesize: (size: number) => number }; +import { fileSize } from 'filesize'; export class PgpBlockViewAttachmentsModule { public includedAttachments: Attachment[] = []; @@ -28,7 +27,8 @@ export class PgpBlockViewAttachmentsModule { for (const i of attachments.keys()) { const name = attachments[i].name ? Str.stripPgpOrGpgExtensionIfPresent(attachments[i].name) : 'noname'; const nameVisible = name.length > 100 ? name.slice(0, 100) + '…' : name; - const size = filesize.filesize(attachments[i].length); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call + const size = fileSize(attachments[i].length); const htmlContent = `${Xss.escape(nameVisible)}   ${size}`; const attachment = $(``); attachment.attr('title', name); diff --git a/extension/types/file-size.d.ts b/extension/types/file-size.d.ts new file mode 100644 index 00000000000..b77fdfd2da4 --- /dev/null +++ b/extension/types/file-size.d.ts @@ -0,0 +1,31 @@ +declare module 'filesize' { + interface Options { + fixed?: number | undefined; + spacer?: string | undefined; + } + + type Spec = "si" | "iec" | "jedec"; + + type Unit = "B" | "KB" | "MB" | "GB" | "TB" | "PB" | "EB" | "ZB" | "YB"; + + interface Bits { + result: number; + fixed: string; + } + + interface Calculated { + suffix: string; + magnitude: number; + result: number; + fixed: string; + bits: Bits; + } + + interface Result { + human(spec?: Spec): string; + to(unit: Unit, spec?: Spec): string; + calculate(spec?: Spec): Calculated; + } + + export function fileSize(bytes: number, options?: T): Required & Result; +} diff --git a/package-lock.json b/package-lock.json index c3257df0399..18c5a03e0ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "bootstrap": "4.6.2", "clipboard": "2.0.11", "dompurify": "3.2.5", - "filesize": "10.1.2", + "filesize": "10.1.6", "fs-extra": "^11.3.0", "globby": "^14.1.0", "iso-8859-2": "1.0.0", @@ -5101,9 +5101,9 @@ } }, "node_modules/filesize": { - "version": "10.1.2", - "resolved": "https://registry.npmjs.org/filesize/-/filesize-10.1.2.tgz", - "integrity": "sha512-Dx770ai81ohflojxhU+oG+Z2QGvKdYxgEr9OSA8UVrqhwNHjfH9A8f5NKfg83fEH8ZFA5N5llJo5T3PIoZ4CRA==", + "version": "10.1.6", + "resolved": "https://registry.npmjs.org/filesize/-/filesize-10.1.6.tgz", + "integrity": "sha512-sJslQKU2uM33qH5nqewAwVB2QgR6w1aMNsYUp3aN5rMRyXEwJGmZvaWzeJFNTOXWlHQyBFCWrdj3fV/fsTOX8w==", "license": "BSD-3-Clause", "engines": { "node": ">= 10.4.0" diff --git a/package.json b/package.json index a2fbbc0967c..807fe40a487 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "bootstrap": "4.6.2", "clipboard": "2.0.11", "dompurify": "3.2.5", - "filesize": "10.1.2", + "filesize": "10.1.6", "fs-extra": "^11.3.0", "globby": "^14.1.0", "iso-8859-2": "1.0.0", diff --git a/scripts/build.js b/scripts/build.js index ceecdb1091e..2cde8736111 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -62,7 +62,7 @@ const copyDependencies = async () => { ['squire-rte/dist/squire.js', 'lib/squire.js'], ['clipboard/dist/clipboard.js', 'lib/clipboard.js'], ['@flowcrypt/fine-uploader/fine-uploader/fine-uploader.js', 'lib/fine-uploader.js'], - ['filesize/dist/filesize.js', 'lib/filesize.js'], + ['filesize/dist/filesize.esm.js', 'lib/filesize.js'], // Using legacy build due to Puppeteer compatibility issue (Promise.withResolvers error) // Reference: https://github.com/mozilla/pdf.js/issues/18006#issuecomment-2078739672 ['pdfjs-dist/legacy/build/pdf.min.mjs', 'lib/pdf.min.mjs'], diff --git a/tsconfig.json b/tsconfig.json index 2aad19adba8..b2ec691b5e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,7 @@ "dompurify": ["../node_modules/dompurify/dist/purify.cjs.d.ts", "lib/purify.js", "COMMENT"], "fine-uploader": ["lib/fine-uploader.js", "COMMENT"], "clipboard": ["lib/clipboard.js", "COMMENT"], - "filesize": ["lib/filesize.js", "COMMENT"], + "filesize": ["lib/filesize.js", "./extension/types/file-size.d.ts"], "iso-8859-2": ["lib/iso-8859-2.js", "COMMENT"], "zxcvbn": ["lib/zxcvbn.js", "COMMENT"], "emailjs-mime-parser": ["lib/emailjs/emailjs-mime-parser.js", "COMMENT"], From b0e1768a1b52fedd889c5089247c8ae0c6ce0f48 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Thu, 22 May 2025 23:38:45 -0300 Subject: [PATCH 2/5] fix: type error --- .../pgp-block-attachments-module.ts | 3 +- extension/types/file-size.d.ts | 34 +++---------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts index cbf605db2eb..75ce5a57b49 100644 --- a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts +++ b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts @@ -27,8 +27,7 @@ export class PgpBlockViewAttachmentsModule { for (const i of attachments.keys()) { const name = attachments[i].name ? Str.stripPgpOrGpgExtensionIfPresent(attachments[i].name) : 'noname'; const nameVisible = name.length > 100 ? name.slice(0, 100) + '…' : name; - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call - const size = fileSize(attachments[i].length); + const size = fileSize(attachments[i].length) as string; const htmlContent = `${Xss.escape(nameVisible)}   ${size}`; const attachment = $(``); attachment.attr('title', name); diff --git a/extension/types/file-size.d.ts b/extension/types/file-size.d.ts index b77fdfd2da4..40c0025a244 100644 --- a/extension/types/file-size.d.ts +++ b/extension/types/file-size.d.ts @@ -1,31 +1,5 @@ declare module 'filesize' { - interface Options { - fixed?: number | undefined; - spacer?: string | undefined; - } - - type Spec = "si" | "iec" | "jedec"; - - type Unit = "B" | "KB" | "MB" | "GB" | "TB" | "PB" | "EB" | "ZB" | "YB"; - - interface Bits { - result: number; - fixed: string; - } - - interface Calculated { - suffix: string; - magnitude: number; - result: number; - fixed: string; - bits: Bits; - } - - interface Result { - human(spec?: Spec): string; - to(unit: Unit, spec?: Spec): string; - calculate(spec?: Spec): Calculated; - } - - export function fileSize(bytes: number, options?: T): Required & Result; -} + export function fileSize( + bytes: number, + ): string; +} \ No newline at end of file From eba7c843f49b58055a0ed7354568170932e3ff17 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Thu, 22 May 2025 23:41:18 -0300 Subject: [PATCH 3/5] fix --- .../elements/pgp_block_modules/pgp-block-attachments-module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts index 75ce5a57b49..b16c337958f 100644 --- a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts +++ b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts @@ -27,7 +27,8 @@ export class PgpBlockViewAttachmentsModule { for (const i of attachments.keys()) { const name = attachments[i].name ? Str.stripPgpOrGpgExtensionIfPresent(attachments[i].name) : 'noname'; const nameVisible = name.length > 100 ? name.slice(0, 100) + '…' : name; - const size = fileSize(attachments[i].length) as string; + const size = fileSize(attachments[i].length); + // eslint-disable-next-line @typescript-eslint/no-base-to-string const htmlContent = `${Xss.escape(nameVisible)}   ${size}`; const attachment = $(``); attachment.attr('title', name); From af095f114c073bbde4b88935352867866c85a73c Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Fri, 23 May 2025 06:05:07 -0300 Subject: [PATCH 4/5] fix: test --- .../pgp_block_modules/pgp-block-attachments-module.ts | 7 ++++--- extension/types/file-size.d.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts index b16c337958f..11829a30b7f 100644 --- a/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts +++ b/extension/chrome/elements/pgp_block_modules/pgp-block-attachments-module.ts @@ -14,7 +14,7 @@ import { XssSafeFactory } from '../../../js/common/xss-safe-factory.js'; import { Str } from '../../../js/common/core/common.js'; import { AttachmentWarnings } from '../shared/attachment_warnings.js'; import { MsgUtil } from '../../../js/common/core/crypto/pgp/msg-util.js'; -import { fileSize } from 'filesize'; +import { filesize } from 'filesize'; export class PgpBlockViewAttachmentsModule { public includedAttachments: Attachment[] = []; @@ -27,8 +27,9 @@ export class PgpBlockViewAttachmentsModule { for (const i of attachments.keys()) { const name = attachments[i].name ? Str.stripPgpOrGpgExtensionIfPresent(attachments[i].name) : 'noname'; const nameVisible = name.length > 100 ? name.slice(0, 100) + '…' : name; - const size = fileSize(attachments[i].length); - // eslint-disable-next-line @typescript-eslint/no-base-to-string + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call + const size = filesize(attachments[i].length); + const htmlContent = `${Xss.escape(nameVisible)}   ${size}`; const attachment = $(``); attachment.attr('title', name); diff --git a/extension/types/file-size.d.ts b/extension/types/file-size.d.ts index 40c0025a244..e1d6c913e23 100644 --- a/extension/types/file-size.d.ts +++ b/extension/types/file-size.d.ts @@ -1,5 +1,5 @@ declare module 'filesize' { - export function fileSize( + export function filesize( bytes: number, ): string; } \ No newline at end of file From fea5142bf0438c9eddbc92a5c017c33fb63088c8 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Fri, 23 May 2025 07:50:39 -0300 Subject: [PATCH 5/5] fix: pr reviews --- extension/types/file-size.d.ts | 5 ----- tsconfig.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 extension/types/file-size.d.ts diff --git a/extension/types/file-size.d.ts b/extension/types/file-size.d.ts deleted file mode 100644 index e1d6c913e23..00000000000 --- a/extension/types/file-size.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module 'filesize' { - export function filesize( - bytes: number, - ): string; -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index b2ec691b5e4..aff23c223e6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,7 @@ "dompurify": ["../node_modules/dompurify/dist/purify.cjs.d.ts", "lib/purify.js", "COMMENT"], "fine-uploader": ["lib/fine-uploader.js", "COMMENT"], "clipboard": ["lib/clipboard.js", "COMMENT"], - "filesize": ["lib/filesize.js", "./extension/types/file-size.d.ts"], + "filesize": ["lib/filesize.js", "../node_modules/filesize/types/filesize.d.ts"], "iso-8859-2": ["lib/iso-8859-2.js", "COMMENT"], "zxcvbn": ["lib/zxcvbn.js", "COMMENT"], "emailjs-mime-parser": ["lib/emailjs/emailjs-mime-parser.js", "COMMENT"],