From e9c598cf469486b12e6834e62d1d53ed8406f0d7 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Tue, 7 Nov 2023 04:04:33 -0800 Subject: [PATCH] Chore: Mobile: Remove duplicate bundle minification (#9221) --- packages/app-mobile/package.json | 2 -- packages/app-mobile/tools/buildInjectedJs.ts | 32 ++------------------ yarn.lock | 2 -- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/packages/app-mobile/package.json b/packages/app-mobile/package.json index 284468857..587065079 100644 --- a/packages/app-mobile/package.json +++ b/packages/app-mobile/package.json @@ -101,7 +101,6 @@ "@types/tar-stream": "2.2.3", "babel-jest": "29.7.0", "babel-plugin-module-resolver": "4.1.0", - "execa": "4.1.0", "fs-extra": "11.1.1", "gulp": "4.0.2", "jest": "29.7.0", @@ -109,7 +108,6 @@ "jetifier": "2.0.0", "js-draw": "1.5.0", "jsdom": "22.1.0", - "md5-file": "5.0.0", "metro-react-native-babel-preset": "0.73.9", "nodemon": "3.0.1", "react-test-renderer": "18.2.0", diff --git a/packages/app-mobile/tools/buildInjectedJs.ts b/packages/app-mobile/tools/buildInjectedJs.ts index 7f96ed35b..d6da0e204 100644 --- a/packages/app-mobile/tools/buildInjectedJs.ts +++ b/packages/app-mobile/tools/buildInjectedJs.ts @@ -3,10 +3,8 @@ // files: First here we convert the JS file to a plain string, and that string // is then loaded by eg. the Mermaid plugin, and finally injected in the WebView. -import { mkdirp, pathExists, readFile, writeFile } from 'fs-extra'; +import { mkdirp, readFile, writeFile } from 'fs-extra'; import { dirname, extname, basename } from 'path'; -const md5File = require('md5-file'); -const execa = require('execa'); // We need this to be transpiled to `const webpack = require('webpack')`. // As such, do a namespace import. See https://www.typescriptlang.org/tsconfig#esModuleInterop @@ -30,7 +28,6 @@ async function copyJs(name: string, filePath: string) { class BundledFile { private readonly bundleOutputPath: string; - private readonly bundleMinifiedPath: string; private readonly bundleBaseName: string; private readonly rootFileDirectory: string; @@ -41,7 +38,6 @@ class BundledFile { this.rootFileDirectory = dirname(sourceFilePath); this.bundleBaseName = basename(sourceFilePath, extname(sourceFilePath)); this.bundleOutputPath = `${this.rootFileDirectory}/${this.bundleBaseName}.bundle.js`; - this.bundleMinifiedPath = `${this.rootFileDirectory}/${this.bundleBaseName}.bundle.min.js`; } private getWebpackOptions(mode: 'production' | 'development'): webpack.Configuration { @@ -86,28 +82,6 @@ class BundledFile { return config; } - private async uglify() { - const md5Path = `${this.bundleOutputPath}.md5`; - const newMd5 = await md5File(this.bundleOutputPath); - const previousMd5 = await pathExists(md5Path) ? await readFile(md5Path, 'utf8') : ''; - - if (newMd5 === previousMd5 && await pathExists(this.bundleMinifiedPath)) { - console.info('Bundle has not changed - skipping minifying...'); - return; - } - - console.info(`Minifying bundle: ${this.bundleName}...`); - - await execa('yarn', [ - 'run', 'uglifyjs', - '--compress', - '-o', this.bundleMinifiedPath, - this.bundleOutputPath, - ]); - - await writeFile(md5Path, newMd5, 'utf8'); - } - private handleErrors(error: Error | undefined | null, stats: webpack.Stats | undefined): boolean { let failed = false; @@ -163,7 +137,6 @@ class BundledFile { failed = true; } if (!failed) { - await this.uglify(); resolve(); } else { reject(); @@ -183,7 +156,6 @@ class BundledFile { compiler.watch(watchOptions, async (error, stats) => { const failed = this.handleErrors(error, stats); if (!failed) { - await this.uglify(); await this.copyToImportableFile(); } }); @@ -192,7 +164,7 @@ class BundledFile { // Creates a file that can be imported by React native. This file contains the // bundled JS as a string. public async copyToImportableFile() { - await copyJs(`${this.bundleBaseName}.bundle`, this.bundleMinifiedPath); + await copyJs(`${this.bundleBaseName}.bundle`, this.bundleOutputPath); } } diff --git a/yarn.lock b/yarn.lock index a4e34ac7a..f3d4cfe77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6318,7 +6318,6 @@ __metadata: crypto-browserify: 3.12.0 deprecated-react-native-prop-types: 4.2.3 events: 3.3.0 - execa: 4.1.0 fs-extra: 11.1.1 gulp: 4.0.2 jest: 29.7.0 @@ -6329,7 +6328,6 @@ __metadata: jsdom: 22.1.0 lodash: 4.17.21 md5: 2.3.0 - md5-file: 5.0.0 metro-react-native-babel-preset: 0.73.9 nodemon: 3.0.1 path-browserify: 1.0.1