From 33682989255dbceeab2ce67775b8f0c7a05b55de Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 12 Sep 2024 14:04:35 +0200 Subject: [PATCH] Switch from UglifyJS to Terser to build the polyfill script (#65278) Co-authored-by: jsnajdr Co-authored-by: tyxla Co-authored-by: sgomes --- package-lock.json | 19 ++++++++++--------- package.json | 2 +- packages/babel-preset-default/bin/index.js | 14 +++++++------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32819be602f72..c3ae05f3a6bbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -245,9 +245,9 @@ "storybook-source-link": "2.0.9", "strip-json-comments": "5.0.0", "style-loader": "3.2.1", + "terser": "5.32.0", "terser-webpack-plugin": "5.3.9", "typescript": "5.5.3", - "uglify-js": "3.13.7", "uuid": "9.0.1", "webdriverio": "8.16.20", "webpack": "5.88.2", @@ -48431,10 +48431,9 @@ } }, "node_modules/terser": { - "version": "5.31.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.31.2.tgz", - "integrity": "sha512-LGyRZVFm/QElZHy/CPr/O4eNZOZIzsrQ92y4v9UJe/pFJjypje2yI3C2FmPtvUEnhadlSbmG2nXtdcjHOjCfxw==", - "license": "BSD-2-Clause", + "version": "5.32.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.32.0.tgz", + "integrity": "sha512-v3Gtw3IzpBJ0ugkxEX8U0W6+TnPKRRCWGh1jC/iM/e3Ki5+qvO1L1EAZ56bZasc64aXHwRHNIQEzm6//i5cemQ==", "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", @@ -49267,6 +49266,7 @@ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.7.tgz", "integrity": "sha512-1Psi2MmnZJbnEsgJJIlfnd7tFlJfitusmR7zDI8lXlFI0ACD4/Rm/xdrU8bh6zF0i74aiVoBtkRiFulkrmh3AA==", "dev": true, + "optional": true, "bin": { "uglifyjs": "bin/uglifyjs" }, @@ -93531,9 +93531,9 @@ } }, "terser": { - "version": "5.31.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.31.2.tgz", - "integrity": "sha512-LGyRZVFm/QElZHy/CPr/O4eNZOZIzsrQ92y4v9UJe/pFJjypje2yI3C2FmPtvUEnhadlSbmG2nXtdcjHOjCfxw==", + "version": "5.32.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.32.0.tgz", + "integrity": "sha512-v3Gtw3IzpBJ0ugkxEX8U0W6+TnPKRRCWGh1jC/iM/e3Ki5+qvO1L1EAZ56bZasc64aXHwRHNIQEzm6//i5cemQ==", "requires": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", @@ -94155,7 +94155,8 @@ "version": "3.13.7", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.7.tgz", "integrity": "sha512-1Psi2MmnZJbnEsgJJIlfnd7tFlJfitusmR7zDI8lXlFI0ACD4/Rm/xdrU8bh6zF0i74aiVoBtkRiFulkrmh3AA==", - "dev": true + "dev": true, + "optional": true }, "unbox-primitive": { "version": "1.0.2", diff --git a/package.json b/package.json index 29e5f10b6f7a5..46d2b42f267ab 100644 --- a/package.json +++ b/package.json @@ -257,9 +257,9 @@ "storybook-source-link": "2.0.9", "strip-json-comments": "5.0.0", "style-loader": "3.2.1", + "terser": "5.32.0", "terser-webpack-plugin": "5.3.9", "typescript": "5.5.3", - "uglify-js": "3.13.7", "uuid": "9.0.1", "webdriverio": "8.16.20", "webpack": "5.88.2", diff --git a/packages/babel-preset-default/bin/index.js b/packages/babel-preset-default/bin/index.js index 54c35564d43d7..0e0e66b450c1d 100755 --- a/packages/babel-preset-default/bin/index.js +++ b/packages/babel-preset-default/bin/index.js @@ -4,7 +4,7 @@ * External dependencies */ const builder = require( 'core-js-builder' ); -const { minify } = require( 'uglify-js' ); +const { minify } = require( 'terser' ); const { writeFile } = require( 'fs' ).promises; builder( { @@ -18,15 +18,15 @@ builder( { targets: require( '@wordpress/browserslist-config' ), filename: './build/polyfill.js', } ) - .then( async ( code ) => { - const output = minify( code, { + .then( ( code ) => + minify( code, { output: { comments: ( node, comment ) => - comment.value.indexOf( 'License' ) >= 0, + comment.value.toLowerCase().includes( 'license' ), }, - } ); - await writeFile( './build/polyfill.min.js', output.code ); - } ) + } ) + ) + .then( ( output ) => writeFile( './build/polyfill.min.js', output.code ) ) .catch( ( error ) => { // eslint-disable-next-line no-console console.log( error );