1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Chore: Mobile: Remove duplicate bundle minification (#9221)

This commit is contained in:
Henry Heino 2023-11-07 04:04:33 -08:00 committed by GitHub
parent 02361e37f0
commit e9c598cf46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 34 deletions

View File

@ -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",

View File

@ -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);
}
}

View File

@ -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