function upgradeToBrotli(mem) {
	// console.log(`Upgrading ${mem.module}/${mem.path} to compressed version...`);
	// const start = Date.now();
	mem.upgrading = true;
	let error;
	return minify(mem.code, {
		mangle: {
			// Temporary workaround for duplicate identifier bug in Terser 4/5:
			// https://github.com/terser/terser/issues/800#issuecomment-701017137
			keep_fnames: true
		},
		compress: true,
		module: true,
		ecma: 2018,
		safari10: true,
		sourceMap: false
	})
		.catch(err => {
			console.error(err);
			error = err;
			return { code: undefined };
		})
		.then(result => {
			mem.code = result.code || mem.code;
			const cacheFile = getCachePath(mem, mem.cwd);
			fs.writeFile(cacheFile, mem.code);
			return new Promise((resolve, reject) => {
				zlib.brotliCompress(mem.code, BROTLI_OPTS, (err, data) => {
					mem.upgrading = false;
					if (err && error) {
						return reject(Error(`Minification and Brotli compression failed for ${mem.module}/${mem.path}.`));
					}
					mem.brotli = data;
					fs.writeFile(cacheFile + '.br', data);
					// console.log(`  > ${mem.module}/${mem.path} upgraded in ${Date.now() - start}ms`);
					resolve(null);
				});
			});
		});
}
Create a minified+compressed version of a bundle in the in-memory and disk caches
@param {Mem} mem
@TODO move this into a Worker