const fs = require('fs');
const webpack = require('webpack');
const fancyLog = require('fancy-log');
const ansiColors = require('ansi-colors');
const { Mangler } = require('../build/lib/mangle/index');
const mangleMap = new Map();
function getMangledFileContents(projectPath) {
let entry = mangleMap.get(projectPath);
if (!entry) {
const log = (...data) => fancyLog(ansiColors.blue('[mangler]'), ...data);
log(`Mangling ${projectPath}`);
const ts2tsMangler = new Mangler(projectPath, log, { mangleExports: true, manglePrivateFields: true });
entry = ts2tsMangler.computeNewFileContents();
mangleMap.set(projectPath, entry);
}
return entry;
}
module.exports = async function (source, sourceMap, meta) {
if (this.mode !== 'production') {
return source;
}
if (true) {
return source;
}
const options = this.getOptions();
if (options.disabled) {
return source;
}
if (source !== fs.readFileSync(this.resourcePath).toString()) {
return source;
}
const callback = this.async();
const fileContentsMap = await getMangledFileContents(options.configFile);
const newContents = fileContentsMap.get(this.resourcePath);
callback(null, newContents?.out ?? source, sourceMap, meta);
};