diff --git a/.escheckrc b/.escheckrc index 37003a295a9..9e27a89e444 100644 --- a/.escheckrc +++ b/.escheckrc @@ -3,7 +3,8 @@ "modules": "false", "files": "./dist/**/*.js", "not": [ - "./dist/libraries/pdf.worker.js", + "./dist/libraries/pdf.worker.mjs", + "./dist/node_modules.pdfjs-dist.*", "./dist/libraries/worker-bundle.js", "./dist/serviceworker.js" ] diff --git a/package-lock.json b/package-lock.json index 6ba1d652a4b..f930a478ad6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ "material-design-icons-iconfont": "6.7.0", "material-react-table": "2.13.2", "native-promise-only": "0.8.1", - "pdfjs-dist": "3.11.174", + "pdfjs-dist": "4.2.67", "react": "18.3.1", "react-blurhash": "0.3.0", "react-dom": "18.3.1", @@ -119,6 +119,7 @@ "stylelint-no-browser-hacks": "1.3.0", "stylelint-order": "6.0.4", "stylelint-scss": "5.3.2", + "transform-async-modules-webpack-plugin": "1.1.1", "ts-loader": "9.5.1", "typescript": "5.5.4", "vitest": "2.0.5", @@ -1677,6 +1678,26 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-runtime": { + "version": "7.25.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.25.4.tgz", + "integrity": "sha512-8hsyG+KUYGY0coX6KUCDancA0Vw225KJ2HJO0yCNr1vq5r+lJTleDaJf0K7iOhjw4SWhu03TMBzYTJ9krmzULQ==", + "dev": true, + "dependencies": { + "@babel/helper-module-imports": "^7.24.7", + "@babel/helper-plugin-utils": "^7.24.8", + "babel-plugin-polyfill-corejs2": "^0.4.10", + "babel-plugin-polyfill-corejs3": "^0.10.6", + "babel-plugin-polyfill-regenerator": "^0.6.1", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-transform-shorthand-properties": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.7.tgz", @@ -16709,13 +16730,14 @@ "resolved": "https://registry.npmjs.org/path-webpack/-/path-webpack-0.0.3.tgz", "integrity": "sha1-/23sdJ7sWpRgXATV9j/FVgegOhY=" }, - "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.1", + "resolved": "https://registry.npmjs.org/path2d/-/path2d-0.2.1.tgz", + "integrity": "sha512-Fl2z/BHvkTNvkuBzYTpTuirHZg6wW9z8+4SND/3mDTEcYbbNKWAy21dz9D3ePNNwrrK8pqZO5vLPZ1hLF6T7XA==", + "license": "MIT", "optional": true, "engines": { - "node": ">=8" + "node": ">=6" } }, "node_modules/pathe": { @@ -16736,15 +16758,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==", + "license": "Apache-2.0", "engines": { "node": ">=18" }, "optionalDependencies": { "canvas": "^2.11.2", - "path2d-polyfill": "^2.0.1" + "path2d": "^0.2.0" } }, "node_modules/picocolors": { @@ -24690,6 +24713,31 @@ "node": ">=18" } }, + "node_modules/transform-async-modules-webpack-plugin": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/transform-async-modules-webpack-plugin/-/transform-async-modules-webpack-plugin-1.1.1.tgz", + "integrity": "sha512-hBr1zAid46Aa1y/iSHMl8uufw5NGgPtPhWlKrzUoc53fVguCzMu64eXFdKtnu86ZfhblOPl5oHafWlt+60uDCg==", + "dev": true, + "dependencies": { + "@babel/core": "^7.13.0", + "@babel/plugin-transform-runtime": "^7.13.0", + "@babel/preset-env": "^7.13.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/steverep" + }, + "peerDependencies": { + "@babel/core": "^7.13.0", + "@babel/plugin-transform-runtime": "^7.13.0", + "@babel/preset-env": "^7.13.0", + "@babel/runtime": "^7.13.0", + "webpack": "^5.0.0" + } + }, "node_modules/tree-dump": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tree-dump/-/tree-dump-1.0.1.tgz", @@ -27938,6 +27986,20 @@ "@babel/helper-plugin-utils": "^7.24.7" } }, + "@babel/plugin-transform-runtime": { + "version": "7.25.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.25.4.tgz", + "integrity": "sha512-8hsyG+KUYGY0coX6KUCDancA0Vw225KJ2HJO0yCNr1vq5r+lJTleDaJf0K7iOhjw4SWhu03TMBzYTJ9krmzULQ==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.24.7", + "@babel/helper-plugin-utils": "^7.24.8", + "babel-plugin-polyfill-corejs2": "^0.4.10", + "babel-plugin-polyfill-corejs3": "^0.10.6", + "babel-plugin-polyfill-regenerator": "^0.6.1", + "semver": "^6.3.1" + } + }, "@babel/plugin-transform-shorthand-properties": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.7.tgz", @@ -37839,10 +37901,10 @@ "resolved": "https://registry.npmjs.org/path-webpack/-/path-webpack-0.0.3.tgz", "integrity": "sha1-/23sdJ7sWpRgXATV9j/FVgegOhY=" }, - "path2d-polyfill": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz", - "integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==", + "path2d": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/path2d/-/path2d-0.2.1.tgz", + "integrity": "sha512-Fl2z/BHvkTNvkuBzYTpTuirHZg6wW9z8+4SND/3mDTEcYbbNKWAy21dz9D3ePNNwrrK8pqZO5vLPZ1hLF6T7XA==", "optional": true }, "pathe": { @@ -37858,12 +37920,12 @@ "dev": true }, "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==", "requires": { "canvas": "^2.11.2", - "path2d-polyfill": "^2.0.1" + "path2d": "^0.2.0" } }, "picocolors": { @@ -43194,6 +43256,17 @@ "punycode": "^2.3.1" } }, + "transform-async-modules-webpack-plugin": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/transform-async-modules-webpack-plugin/-/transform-async-modules-webpack-plugin-1.1.1.tgz", + "integrity": "sha512-hBr1zAid46Aa1y/iSHMl8uufw5NGgPtPhWlKrzUoc53fVguCzMu64eXFdKtnu86ZfhblOPl5oHafWlt+60uDCg==", + "dev": true, + "requires": { + "@babel/core": "^7.13.0", + "@babel/plugin-transform-runtime": "^7.13.0", + "@babel/preset-env": "^7.13.0" + } + }, "tree-dump": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tree-dump/-/tree-dump-1.0.1.tgz", diff --git a/package.json b/package.json index d98a9e98d8c..a678b6c6d73 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "stylelint-no-browser-hacks": "1.3.0", "stylelint-order": "6.0.4", "stylelint-scss": "5.3.2", + "transform-async-modules-webpack-plugin": "1.1.1", "ts-loader": "9.5.1", "typescript": "5.5.4", "vitest": "2.0.5", @@ -111,7 +112,7 @@ "material-design-icons-iconfont": "6.7.0", "material-react-table": "2.13.2", "native-promise-only": "0.8.1", - "pdfjs-dist": "3.11.174", + "pdfjs-dist": "4.2.67", "react": "18.3.1", "react-blurhash": "0.3.0", "react-dom": "18.3.1", diff --git a/src/plugins/pdfPlayer/plugin.js b/src/plugins/pdfPlayer/plugin.js index 0a7d2034151..df338d07e61 100644 --- a/src/plugins/pdfPlayer/plugin.js +++ b/src/plugins/pdfPlayer/plugin.js @@ -205,13 +205,10 @@ export class PdfPlayer { const downloadHref = apiClient.getItemDownloadUrl(item.Id); this.bindEvents(); - GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.js'; + GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.min.mjs'; const downloadTask = getDocument({ - url: downloadHref, - // Disable for PDF.js XSS vulnerability - // https://github.com/mozilla/pdf.js/security/advisories/GHSA-wgrm-67xf-hhpq - isEvalSupported: false + url: downloadHref }); return downloadTask.promise.then(book => { if (this.cancellationToken) return; diff --git a/webpack.common.js b/webpack.common.js index b58058f53f4..7f5da119030 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -4,6 +4,7 @@ const CopyPlugin = require('copy-webpack-plugin'); const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const { TransformAsyncModulesPlugin } = require('transform-async-modules-webpack-plugin'); const { DefinePlugin, IgnorePlugin } = require('webpack'); const packageJson = require('./package.json'); @@ -15,7 +16,7 @@ const Assets = [ '@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.js', '@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.wasm', '@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker-legacy.js', - 'pdfjs-dist/build/pdf.worker.js' + 'pdfjs-dist/build/pdf.worker.min.mjs' ]; const DEV_MODE = process.env.NODE_ENV !== 'production'; @@ -109,7 +110,9 @@ const config = { typescript: { configFile: path.resolve(__dirname, 'tsconfig.json') } - }) + }), + // Transform any modules using top-level await (pdf.js) + new TransformAsyncModulesPlugin() ], output: { filename: pathData => ( @@ -205,6 +208,7 @@ const config = { path.resolve(__dirname, 'node_modules/markdown-it'), path.resolve(__dirname, 'node_modules/material-react-table'), path.resolve(__dirname, 'node_modules/mdurl'), + path.resolve(__dirname, 'node_modules/pdfjs-dist'), path.resolve(__dirname, 'node_modules/punycode'), path.resolve(__dirname, 'node_modules/react-blurhash'), path.resolve(__dirname, 'node_modules/react-lazy-load-image-component'), @@ -268,7 +272,6 @@ const config = { { test: /\.js$/, include: [ - path.resolve(__dirname, 'node_modules/pdfjs-dist'), path.resolve(__dirname, 'node_modules/xmldom') ], use: [{