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ugin.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/clean-webpack-plugin@4.0.0/dist/clean-webpack-plugin.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { sync as delSync } from 'del';\nimport path from 'path';\nimport { Compilation, Compiler, Stats } from 'webpack';\n\nexport interface Options {\n    /**\n     * Simulate the removal of files\n     *\n     * default: false\n     */\n    dry?: boolean;\n\n    /**\n     * Write Logs to Console\n     * (Always enabled when dry is true)\n     *\n     * default: false\n     */\n    verbose?: boolean;\n\n    /**\n     * Automatically remove all unused webpack assets on rebuild\n     *\n     * default: true\n     */\n    cleanStaleWebpackAssets?: boolean;\n\n    /**\n     * Do not allow removal of current webpack assets\n     *\n     * default: true\n     */\n    protectWebpackAssets?: boolean;\n\n    /**\n     * Removes files once prior to Webpack compilation\n     *   Not included in rebuilds (watch mode)\n     *\n     * Use !negative patterns to exclude files\n     *\n     * default: ['**\\/*']\n     */\n    cleanOnceBeforeBuildPatterns?: string[];\n\n    /**\n     * Removes files after every build (including watch mode) that match this pattern.\n     * Used for files that are not created directly by Webpack.\n     *\n     * Use !negative patterns to exclude files\n     *\n     * default: []\n     */\n    cleanAfterEveryBuildPatterns?: string[];\n\n    /**\n     * Allow clean patterns outside of process.cwd()\n     *\n     * requires dry option to be explicitly set\n     *\n     * default: false\n     */\n    dangerouslyAllowCleanPatternsOutsideProject?: boolean;\n}\n\n// Copied from https://github.com/sindresorhus/is-plain-obj/blob/97480673cf12145b32ec2ee924980d66572e8a86/index.js\nfunction isPlainObject(value: unknown): boolean {\n    if (Object.prototype.toString.call(value) !== '[object Object]') {\n        return false;\n    }\n\n    const prototype = Object.getPrototypeOf(value);\n    return prototype === null || prototype === Object.getPrototypeOf({});\n}\n\nclass CleanWebpackPlugin {\n    private readonly dry: boolean;\n    private readonly verbose: boolean;\n    private readonly cleanStaleWebpackAssets: boolean;\n    private readonly protectWebpackAssets: boolean;\n    private readonly cleanAfterEveryBuildPatterns: string[];\n    private readonly cleanOnceBeforeBuildPatterns: string[];\n    private readonly dangerouslyAllowCleanPatternsOutsideProject: boolean;\n    private currentAssets: string[];\n    private initialClean: boolean;\n    private outputPath: string;\n\n    constructor(options: Options = {}) {\n        if (isPlainObject(options) === false) {\n            throw new Error(`clean-webpack-plugin only accepts an options object. See:\n            https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional`);\n        }\n\n        // @ts-ignore\n        if (options.allowExternal) {\n            throw new Error(\n                'clean-webpack-plugin: `allowExternal` option no longer supported. Use `dangerouslyAllowCleanPatternsOutsideProject`',\n            );\n        }\n\n        if (\n            options.dangerouslyAllowCleanPatternsOutsideProject === true &&\n            options.dry !== true &&\n            options.dry !== false\n        ) {\n            // eslint-disable-next-line no-console\n            console.warn(\n                'clean-webpack-plugin: dangerouslyAllowCleanPatternsOutsideProject requires dry: false to be explicitly set. Enabling dry mode',\n            );\n        }\n\n        this.dangerouslyAllowCleanPatternsOutsideProject =\n            options.dangerouslyAllowCleanPatternsOutsideProject === true ||\n            false;\n\n        this.dry =\n            options.dry === true || options.dry === false\n                ? options.dry\n                : this.dangerouslyAllowCleanPatternsOutsideProject === true ||\n                  false;\n\n        this.verbose = this.dry === true || options.verbose === true || false;\n\n        this.cleanStaleWebpackAssets =\n            options.cleanStaleWebpackAssets === true ||\n            options.cleanStaleWebpackAssets === false\n                ? options.cleanStaleWebpackAssets\n                : true;\n\n        this.protectWebpackAssets =\n            options.protectWebpackAssets === true ||\n            options.protectWebpackAssets === false\n                ? options.protectWebpackAssets\n                : true;\n\n        this.cleanAfterEveryBuildPatterns = Array.isArray(\n            options.cleanAfterEveryBuildPatterns,\n        )\n            ? options.cleanAfterEveryBuildPatterns\n            : [];\n\n        this.cleanOnceBeforeBuildPatterns = Array.isArray(\n            options.cleanOnceBeforeBuildPatterns,\n        )\n            ? options.cleanOnceBeforeBuildPatterns\n            : ['**/*'];\n\n        /**\n         * Store webpack build assets\n         */\n        this.currentAssets = [];\n\n        /**\n         * Only used with cleanOnceBeforeBuildPatterns\n         */\n        this.initialClean = false;\n\n        this.outputPath = '';\n\n        this.apply = this.apply.bind(this);\n        this.handleInitial = this.handleInitial.bind(this);\n        this.handleDone = this.handleDone.bind(this);\n        this.removeFiles = this.removeFiles.bind(this);\n    }\n\n    apply(compiler: Compiler) {\n        if (!compiler.options.output || !compiler.options.output.path) {\n            // eslint-disable-next-line no-console\n            console.warn(\n                'clean-webpack-plugin: options.output.path not defined. Plugin disabled...',\n            );\n\n            return;\n        }\n\n        this.outputPath = compiler.options.output.path;\n\n        /**\n         * webpack 4+ comes with a new plugin system.\n         *\n         * Check for hooks in-order to support old plugin system\n         * webpack 5+ removed the old system, the check now breaks\n         */\n        const hooks = compiler.hooks;\n\n        if (this.cleanOnceBeforeBuildPatterns.length !== 0) {\n            hooks.emit.tap('clean-webpack-plugin', (compilation) => {\n                this.handleInitial(compilation);\n            });\n        }\n\n        hooks.done.tap('clean-webpack-plugin', (stats) => {\n            this.handleDone(stats);\n        });\n    }\n\n    /**\n     * Initially remove files from output directory prior to build.\n     *\n     * Only happens once.\n     *\n     * Warning: It is recommended to initially clean your build directory outside of webpack to minimize unexpected behavior.\n     */\n    handleInitial(compilation: Compilation) {\n        if (this.initialClean) {\n            return;\n        }\n\n        /**\n         * Do not remove files if there are compilation errors\n         *\n         * Handle logging inside this.handleDone\n         */\n        const stats = compilation.getStats();\n        if (stats.hasErrors()) {\n            return;\n        }\n\n        this.initialClean = true;\n\n        this.removeFiles(this.cleanOnceBeforeBuildPatterns);\n    }\n\n    handleDone(stats: Stats) {\n        /**\n         * Do nothing if there is a webpack error\n         */\n        if (stats.hasErrors()) {\n            if (this.verbose) {\n                // eslint-disable-next-line no-console\n                console.warn(\n                    'clean-webpack-plugin: pausing due to webpack errors',\n                );\n            }\n\n            return;\n        }\n\n        /**\n         * Fetch Webpack's output asset files\n         */\n        const assetList = Object.keys(stats.compilation.assets);\n\n        /**\n         * Get all files that were in the previous build but not the current\n         *\n         * (relies on del's cwd: outputPath option)\n         */\n        const staleFiles = this.currentAssets.filter((previousAsset) => {\n            const assetCurrent = assetList.includes(previousAsset) === false;\n\n            return assetCurrent;\n        });\n\n        /**\n         * Save assets for next compilation\n         */\n        this.currentAssets = assetList.sort();\n\n        const removePatterns = [];\n\n        /**\n         * Remove unused webpack assets\n         */\n        if (this.cleanStaleWebpackAssets === true && staleFiles.length !== 0) {\n            removePatterns.push(...staleFiles);\n        }\n\n        /**\n         * Remove cleanAfterEveryBuildPatterns\n         */\n        if (this.cleanAfterEveryBuildPatterns.length !== 0) {\n            removePatterns.push(...this.cleanAfterEveryBuildPatterns);\n        }\n\n        if (removePatterns.length !== 0) {\n            this.removeFiles(removePatterns);\n        }\n    }\n\n    removeFiles(patterns: string[]) {\n        try {\n            const deleted = delSync(patterns, {\n                force: this.dangerouslyAllowCleanPatternsOutsideProject,\n                // Change context to build directory\n                cwd: this.outputPath,\n                dryRun: this.dry,\n                dot: true,\n                ignore: this.protectWebpackAssets ? this.currentAssets : [],\n            });\n\n            /**\n             * Log if verbose is enabled\n             */\n            if (this.verbose) {\n                deleted.forEach((file) => {\n                    const filename = path.relative(process.cwd(), file);\n\n                    const message = this.dry ? 'dry' : 'removed';\n\n                    /**\n                     * Use console.warn over .log\n                     * https://github.com/webpack/webpack/issues/1904\n                     * https://github.com/johnagan/clean-webpack-plugin/issues/11\n                     */\n                    // eslint-disable-next-line no-console\n                    console.warn(\n                        `clean-webpack-plugin: ${message} ${filename}`,\n                    );\n                });\n            }\n        } catch (error) {\n            const needsForce = /Cannot delete files\\/folders outside the current working directory\\./.test(\n                error.message,\n            );\n\n            if (needsForce) {\n                const message =\n                    'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the `dangerouslyAllowCleanPatternsOutsideProject` option.';\n\n                throw new Error(message);\n            }\n\n            /* istanbul ignore next */\n            throw error;\n        }\n    }\n}\n\nexport { CleanWebpackPlugin };\n"]}