tenebrous-dicebot/api/node_modules/clean-webpack-plugin/dist/clean-webpack-plugin.js.map

1 line
16 KiB
Plaintext

{"version":3,"sources":["../src/clean-webpack-plugin.ts"],"names":["isPlainObject","value","Object","prototype","toString","call","getPrototypeOf","CleanWebpackPlugin","constructor","options","Error","allowExternal","dangerouslyAllowCleanPatternsOutsideProject","dry","console","warn","verbose","cleanStaleWebpackAssets","protectWebpackAssets","cleanAfterEveryBuildPatterns","Array","isArray","cleanOnceBeforeBuildPatterns","currentAssets","initialClean","outputPath","apply","bind","handleInitial","handleDone","removeFiles","compiler","output","path","hooks","length","emit","tap","compilation","plugin","callback","error","done","stats","getStats","hasErrors","assets","toJson","assetList","map","asset","name","staleFiles","filter","previousAsset","assetCurrent","includes","sort","removePatterns","push","patterns","deleted","force","cwd","dryRun","dot","ignore","forEach","file","filename","relative","process","message","needsForce","test"],"mappings":";;;;;;;AAAA;;AACA;;;;AAiEA;AACA,SAASA,aAAT,CAAuBC,KAAvB,EAAgD;AAC5C,MAAIC,MAAM,CAACC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BJ,KAA/B,MAA0C,iBAA9C,EAAiE;AAC7D,WAAO,KAAP;AACH;;AAED,QAAME,SAAS,GAAGD,MAAM,CAACI,cAAP,CAAsBL,KAAtB,CAAlB;AACA,SAAOE,SAAS,KAAK,IAAd,IAAsBA,SAAS,KAAKD,MAAM,CAACI,cAAP,CAAsB,EAAtB,CAA3C;AACH;;AAED,MAAMC,kBAAN,CAAyB;AAYrBC,EAAAA,WAAW,CAACC,OAAgB,GAAG,EAApB,EAAwB;AAC/B,QAAIT,aAAa,CAACS,OAAD,CAAb,KAA2B,KAA/B,EAAsC;AAClC,YAAM,IAAIC,KAAJ,CAAW;2FAAX,CAAN;AAEH,KAJ8B,CAM/B;;;AACA,QAAID,OAAO,CAACE,aAAZ,EAA2B;AACvB,YAAM,IAAID,KAAJ,CACF,qHADE,CAAN;AAGH;;AAED,QACID,OAAO,CAACG,2CAAR,KA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AAM,IAAI9D,KAAJ,CAAU8D,OAAV,CAAN;AACH;;AAED,YAAM/B,KAAN;AACH;AACJ;;AA9QoB","sourcesContent":["import path from 'path';\nimport { sync as delSync } from 'del';\nimport { Compiler, Stats, compilation as compilationType } from 'webpack';\n\ntype Compilation = compilationType.Compilation;\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 */\n const hooks = compiler.hooks;\n\n if (this.cleanOnceBeforeBuildPatterns.length !== 0) {\n if (hooks) {\n hooks.emit.tap('clean-webpack-plugin', (compilation) => {\n this.handleInitial(compilation);\n });\n } else {\n compiler.plugin('emit', (compilation, callback) => {\n try {\n this.handleInitial(compilation);\n\n callback();\n } catch (error) {\n callback(error);\n }\n });\n }\n }\n\n if (hooks) {\n hooks.done.tap('clean-webpack-plugin', (stats) => {\n this.handleDone(stats);\n });\n } else {\n compiler.plugin('done', (stats) => {\n this.handleDone(stats);\n });\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 assets = stats.toJson().assets || [];\n const assetList = assets.map((asset: { name: string }) => {\n return asset.name;\n });\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 throw error;\n }\n }\n}\n\nexport { CleanWebpackPlugin };\n"],"file":"clean-webpack-plugin.js"}