plugins_analyze_progress.js

// @ts-check
/**
 * @file plugins/analyze/progress.js
 * @copyright @spmhome @_2025
 * @author Scott Meesseman @spmeesseman
 *//** */

 const SpmhWebpackConsole = require("../../log/wpconsole");
const WpwAnalyzePlugin = require("./base");


/**
 * @augments WpwAnalyzePlugin
 */
class WpwProgressAnalyzePlugin extends WpwAnalyzePlugin
{
	/**
	 * @param {WpwPluginOptions} options Plugin options to be applied
	 */
	constructor(options)
	{
		super(options);
        this.buildOptions = /** @type {WpwProgressAnalyzePluginOptions} */(this.buildOptions);
	}

    /**
     * @override
     * @static
     */
    static create = WpwProgressAnalyzePlugin.wrap.bind(this);


    // /**
    //  * @override
    //  * @returns {WpwPluginTapOptions | undefined}
    //  */
    // onApply()
    // {
    //     if (this.buildOptions.type === "wpw")
    //     {
    //         return {
    //             updateProgress: {
    //                 hook: "afterEnvironment",
    //                 callback: (...args) => this.updateProgress(1, ...args)
    //             }
    //         };
    //     }
    // }


	/**
	 * @param {number} percent 0 to 1, 2-digit decimal representing percentage
	 * @param {string} msg
	 * @param {...any} _args
	 */
	vendorPluginProgress(percent, msg, ..._args)
	{
		const pct = Math.floor(percent * 100), key = `progress-plugin-${pct}`;
		if (!this.store.data[key])
		{
			this.store.data[key] = true;
			const l = this.build.logger, sMsg = `${l.tag("webpack.progress", "white")} ${msg}`;
			l.valuestar(sMsg, `progress::[italic(${pct.toString().padStart(2, "0")}%)]`, 1);
		}
	}

	/**
	 * @override
     * @param {WebpackCompiler} compiler
     * @param {boolean} [applyFirst]
	 * @returns {WebpackPluginInstance | undefined}
	 */
	getVendorPlugin(compiler, applyFirst)
	{
		if (!applyFirst)
		{
            const { ProgressPlugin } = this.build.wp || compiler.webpack;
			const logger = this.logger.level >= 2 ? new SpmhWebpackConsole(this.logger) : undefined;
			return new ProgressPlugin(
			{   profile: false,
				modulesCount: 5000,
				dependenciesCount: 10000,
				modules: true,dependencies: true,
				activeModules: false, entries: true,
				handler: !logger ? this.vendorPluginProgress : ProgressPlugin.createDefaultHandler(true, logger)
			});
		}
	};
}


module.exports = WpwProgressAnalyzePlugin.create;