From 7a8fcd5ecf5ccbe760c22be7fa924f9cb7c2fe1e Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Mon, 26 Jun 2023 04:20:00 -0700 Subject: [PATCH] Remove `metro-minify-uglify` (#1013) Summary: Pull Request resolved: https://github.com/facebook/metro/pull/1013 `metro-minify-terser` has been Metro's default JS minifier since Metro [0.73.0](https://github.com/facebook/metro/releases/tag/v0.73.0) (https://github.com/facebook/metro/pull/871). However, we have continued to publish the deprecated `metro-minify-uglify` and included it in `metro`'s dependencies for a time for convenience. (Consequently, package managers have displayed a confusing warning for the use of the deprecated `uglify-es`, even when it isn't actually used.) This PR removes `metro-minify-uglify` from the main branch and from `metro`'s dependencies. If any critical patches are required in future, they may be published from the `0.76.x` branch. Users wishing to use `metro-minify-uglify` as of the latest version published may still do so by adding `metro-minify-uglify@^0.76.0` to their project's dependencies and configuring [`transformer.minifierPath`](https://facebook.github.io/metro/docs/configuration/#minifierpath): ``` minifierPath: require.resolve('metro-minify-uglify') ``` Changelog: ``` - **[Breaking]**: Remove `metro-minify-uglify` from `metro` dependencies. ``` Reviewed By: motiz88 Differential Revision: D47000809 fbshipit-source-id: aa3ab28ba6fc1cb35415247ef07aace952aa47f8 --- packages/metro-minify-uglify/.npmignore | 6 -- packages/metro-minify-uglify/package.json | 21 ---- .../src/__tests__/minify-test.js | 100 ------------------ packages/metro-minify-uglify/src/index.js | 16 --- packages/metro-minify-uglify/src/minifier.js | 69 ------------ packages/metro/package.json | 1 - yarn.lock | 15 +-- 7 files changed, 1 insertion(+), 227 deletions(-) delete mode 100644 packages/metro-minify-uglify/.npmignore delete mode 100644 packages/metro-minify-uglify/package.json delete mode 100644 packages/metro-minify-uglify/src/__tests__/minify-test.js delete mode 100644 packages/metro-minify-uglify/src/index.js delete mode 100644 packages/metro-minify-uglify/src/minifier.js diff --git a/packages/metro-minify-uglify/.npmignore b/packages/metro-minify-uglify/.npmignore deleted file mode 100644 index 0ec3b99a14..0000000000 --- a/packages/metro-minify-uglify/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -**/__mocks__/ -**/__tests__/ -/build/ -/src.real/ -/types/ -yarn.lock diff --git a/packages/metro-minify-uglify/package.json b/packages/metro-minify-uglify/package.json deleted file mode 100644 index 3d7bf3c494..0000000000 --- a/packages/metro-minify-uglify/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "metro-minify-uglify", - "version": "0.76.7", - "description": "🚇 Minifier for Metro based on Uglify.", - "main": "src/index.js", - "repository": { - "type": "git", - "url": "git@github.com:facebook/metro.git" - }, - "scripts": { - "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", - "cleanup-release": "test ! -e build && mv src build && mv src.real src" - }, - "license": "MIT", - "dependencies": { - "uglify-es": "^3.1.9" - }, - "engines": { - "node": ">=18" - } -} diff --git a/packages/metro-minify-uglify/src/__tests__/minify-test.js b/packages/metro-minify-uglify/src/__tests__/minify-test.js deleted file mode 100644 index dfe51864d0..0000000000 --- a/packages/metro-minify-uglify/src/__tests__/minify-test.js +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - * @oncall react_native - */ - -'use strict'; - -import type {BasicSourceMap} from 'metro-source-map'; - -const minify = require('..'); - -jest.mock('uglify-es', () => ({ - minify: jest.fn(code => { - return { - code: code.replace(/(^|\W)\s+/g, '$1'), - map: {}, - }; - }), -})); -const {objectContaining} = expect; - -function getFakeMap(): BasicSourceMap { - return { - version: 3, - sources: ['?'], - mappings: '', - names: [], - }; -} - -const baseOptions = { - code: '', - map: getFakeMap(), - filename: '', - reserved: [], - config: {}, -}; - -describe('Minification:', () => { - const filename = '/arbitrary/file.js'; - const code = 'arbitrary(code)'; - let map: BasicSourceMap; - let uglify; - - beforeEach(() => { - uglify = require('uglify-es'); - /* $FlowFixMe(>=0.99.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.99 was deployed. To see the error, delete this - * comment and run Flow. */ - uglify.minify.mockClear(); - /* $FlowFixMe(>=0.99.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.99 was deployed. To see the error, delete this - * comment and run Flow. */ - uglify.minify.mockReturnValue({code: '', map: '{}'}); - map = getFakeMap(); - }); - - it('passes file name, code, and source map to `uglify`', () => { - minify({ - ...baseOptions, - code, - map, - filename, - config: {sourceMap: {includeSources: false}}, - }); - expect(uglify.minify).toBeCalledWith( - code, - objectContaining({ - sourceMap: { - content: map, - includeSources: false, - }, - }), - ); - }); - - it('returns the code provided by uglify', () => { - /* $FlowFixMe(>=0.99.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.99 was deployed. To see the error, delete this - * comment and run Flow. */ - uglify.minify.mockReturnValue({code, map: '{}'}); - const result = minify(baseOptions); - expect(result.code).toBe(code); - }); - - it('parses the source map object provided by uglify and sets the sources property', () => { - /* $FlowFixMe(>=0.99.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.99 was deployed. To see the error, delete this - * comment and run Flow. */ - uglify.minify.mockReturnValue({map: JSON.stringify(map), code: ''}); - const result = minify({...baseOptions, filename}); - expect(result.map).toEqual({...map, sources: [filename]}); - }); -}); diff --git a/packages/metro-minify-uglify/src/index.js b/packages/metro-minify-uglify/src/index.js deleted file mode 100644 index 0080f3c840..0000000000 --- a/packages/metro-minify-uglify/src/index.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - * @oncall react_native - */ - -'use strict'; - -const minifier = require('./minifier'); - -module.exports = minifier; diff --git a/packages/metro-minify-uglify/src/minifier.js b/packages/metro-minify-uglify/src/minifier.js deleted file mode 100644 index 17d6bd5c97..0000000000 --- a/packages/metro-minify-uglify/src/minifier.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - * @oncall react_native - */ - -'use strict'; - -import type {BasicSourceMap} from 'metro-source-map'; -import type {MinifierOptions, MinifierResult} from 'metro-transform-worker'; - -const uglify = require('uglify-es'); - -function minifier(options: MinifierOptions): MinifierResult { - const result = minify(options); - - if (!options.map || result.map == null) { - return {code: result.code}; - } - - const map: BasicSourceMap = JSON.parse(result.map); - - return {code: result.code, map: {...map, sources: [options.filename]}}; -} - -function minify({code, map, reserved, config}: MinifierOptions): { - code: string, - map: ?string, - ... -} { - const options = { - ...config, - mangle: - config.mangle === false - ? false - : { - ...config.mangle, - reserved, - }, - sourceMap: - config.sourceMap === false - ? false - : { - ...config.sourceMap, - content: map, - }, - }; - - /* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.111 was deployed. To see the error, delete this - * comment and run Flow. */ - const result = uglify.minify(code, options); - - if (result.error) { - throw result.error; - } - - return { - code: result.code, - map: result.map, - }; -} - -module.exports = minifier; diff --git a/packages/metro/package.json b/packages/metro/package.json index 5200f0d479..4de2f0abf6 100644 --- a/packages/metro/package.json +++ b/packages/metro/package.json @@ -43,7 +43,6 @@ "metro-file-map": "0.76.7", "metro-inspector-proxy": "0.76.7", "metro-minify-terser": "0.76.7", - "metro-minify-uglify": "0.76.7", "metro-react-native-babel-preset": "0.76.7", "metro-resolver": "0.76.7", "metro-runtime": "0.76.7", diff --git a/yarn.lock b/yarn.lock index fbd541ab2b..7cdd861b80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2152,11 +2152,6 @@ commander@^2.20.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@~2.13.0: - version "2.13.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" - integrity sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA== - commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" @@ -5846,7 +5841,7 @@ source-map@^0.5.6: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= -source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: +source-map@^0.6.0, source-map@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -6275,14 +6270,6 @@ typescript@5.0.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== -uglify-es@^3.1.9: - version "3.3.9" - resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677" - integrity sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ== - dependencies: - commander "~2.13.0" - source-map "~0.6.1" - unbox-primitive@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"