Skip to content

Commit

Permalink
feat(pdf): Update closure compiler to Babel (#1458)
Browse files Browse the repository at this point in the history
* feat(pdf): Update closure compiler to Babel

* feat(pdf): Update babel config overrides and downgrade to 7.5.5

* feat(pdf): Update babel config and package versions per PR comments

* feat(pdf): Move babel plugin into third party specific override

* feat(pdf): Fix babel dependency version mismatch

* feat(pdf): Update babel depdendency versions to 7.18.6
  • Loading branch information
karelee7 committed Jun 30, 2022
1 parent 8345f7b commit 9d35e22
Show file tree
Hide file tree
Showing 5 changed files with 1,163 additions and 656 deletions.
13 changes: 13 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ module.exports = api => {
],
],
},
{
test: ['./src/third-party/doc/**'],
plugins: ['@babel/plugin-proposal-private-methods'],
presets: [
[
'@babel/preset-env',
{
exclude: ['@babel/plugin-transform-unicode-regex'],
include: ['@babel/plugin-proposal-unicode-property-regex'],
},
],
],
},
],
env: {
test: {
Expand Down
Binary file removed build/closure-compiler-v20200719.jar
Binary file not shown.
21 changes: 9 additions & 12 deletions build/upgrade_pdfjs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash
# Run with specific branch/tag (e.g. ./upgrade_pdfjs.sh tags/v2.2.228) or with no arguments to use master

DOC_COMPILER_BINARY="build/closure-compiler-v20200719.jar"
DOC_STATIC_ASSETS_BRANCH=${1:-master}
DOC_STATIC_ASSETS_VERSION=$(./build/current_version.sh)
DOC_STATIC_ASSETS_PATH="src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}"
Expand Down Expand Up @@ -30,12 +29,12 @@ git clone https://github.com/mozilla/pdfjs-dist.git --depth 1 --single-branch --
echo "-----------------------------------------------------------------------------------"
echo "Copying relevant files to third-party directory..."
echo "-----------------------------------------------------------------------------------"
\cp -rf pdfjs-dist/es5/build/pdf.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/es5/build/pdf.min.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/es5/build/pdf.worker.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/es5/build/pdf.worker.min.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/es5/web/pdf_viewer.css ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/es5/web/pdf_viewer.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/build/pdf.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/build/pdf.min.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/build/pdf.worker.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/build/pdf.worker.min.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/web/pdf_viewer.css ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/web/pdf_viewer.js ${DOC_STATIC_ASSETS_PATH}
\cp -rf pdfjs-dist/cmaps ${DOC_STATIC_ASSETS_PATH}/cmaps
rm -rf ./pdfjs-dist/

Expand All @@ -56,13 +55,11 @@ sed -e 's@;r.setFlags(o.AnnotationFlag.HIDDEN)@@' -i '' ${DOC_STATIC_ASSETS_PATH
# This fix may not need to be applied if next upgrade is >= 2.5.x
# See https://github.com/box/box-content-preview/pull/1414 for more details

# Minify using Google Closure Compiler, options:
# Output to ES5 (Box supports Chrome, Edge, IE11, Firefox, Safari, and newer versions of iOS, Android)
# Do not minify pdf.js or pdf.worker.js, as the closure compiler will mangle function names and cause bugs
# Minify using Babel
echo "-----------------------------------------------------------------------------------"
echo "Minifying pdf.js files with Google Closure... Warnings are okay!"
echo "Minifying pdf.js files with Babel"
echo "-----------------------------------------------------------------------------------"
java -jar ${DOC_COMPILER_BINARY} --rewrite_polyfills false --language_out ECMASCRIPT5 --js ${DOC_STATIC_ASSETS_PATH}/pdf_viewer.js --js_output_file ${DOC_STATIC_ASSETS_PATH}/pdf_viewer.min.js
babel ${DOC_STATIC_ASSETS_PATH}/pdf_viewer.js --out-file ${DOC_STATIC_ASSETS_PATH}/pdf_viewer.min.js

echo "-----------------------------------------------------------------------------------"
echo "Minifying pdf.js CSS with cssnano"
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
"url": "git@github.com:box/box-content-preview.git"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.7.7",
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-transform-object-assign": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@box/frontend": "^6.4.0",
"@box/languages": "^1.0.0",
"@box/react-virtualized": "9.22.3-rc-box.2",
Expand Down
Loading

0 comments on commit 9d35e22

Please sign in to comment.