/**
* @file plugins/merge.js
* @copyright @spmhome @_2025
* @author Scott Meesseman @spmeesseman\
*//** */
const WpwPlugin = require("./base");
/**
* @augments WpwPlugin
*/
class WpwMergePlugin extends WpwPlugin
{
/**
* @param {WpwPluginOptions} options
*/
constructor(options)
{
super(options);
// this.buildOptions = /** @type {WpwBuildOptionsConfig<"newpluginname">} */(this.buildOptions);
}
/**
* @override
*/
static create = WpwMergePlugin.wrap.bind(this);
/**
* @override
* @returns {WpwPluginTapOptions<any, any, any>}
*/
onApply()
{
return {
mergeFile: {
async: true,
hook: "thisCompilation",
// stage: "ANALYSE",
stage: "OPTIMIZE_COUNT",
hookCompilation: "processAssets",
callback: this.mergeFile.bind(this)
},
addMergedFile: {
async: true,
hook: "thisCompilation",
// stage: "ANALYSE",
stage: "ADDITIONAL",
hookCompilation: "processAssets",
callback: this.addMergedFile.bind(this)
}
};
}
/**
* @private
* @param {WebpackCompilation}_compilation
*/
addMergedFile = (_compilation) =>
{
const build = this.build,
l = this.hookstart();
try {
l.value(" add merged asset to compilation", build.name, 1);
l.write("...DO.WORK...", 2);
}
catch (e)
{ this.addMessage(
{ exception: e,
code: this.MsgCode.ERROR_PLUGIN_HOOK_FAILED,
message: "some error, see exception info for any detail"
}, true);
}
finally {
this.hookdone();
}
};
/**
* @private
* @param {any} chunks
* @param {any} _modules
* @returns {Promise<void | Error>}
*/
mergeFile(chunks, _modules)
{
return new Promise((ok, fail) =>
{
const // b = this.build,
l = this.hookstart();
try
{ chunks.forEach((chunk) =>
{
chunk.modules.slice().forEach((moduleName) =>
{
// this.compilation.rebuildModule(moduleName, (e) => { if (!e) { ok(); } else { fail(e); }});
l.value(" module name", moduleName, 1);
});
});
/* TEMPORARY TEST */ setTimeout(ok, 1); /* TEMPORARY TEST */
}
catch (e)
{ this.addMessage(
{ exception: e,
code: this.MsgCode.ERROR_PLUGIN_HOOK_FAILED,
message: "some error, see exception info for any detail"
}, true);
fail(e);
}
finally {
this.hookdone();
}
});
};
}
module.exports = WpwMergePlugin;