source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/webpack/plugins/any-component-style-budget-checker.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.8 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.AnyComponentStyleBudgetChecker = void 0;
30const path = __importStar(require("path"));
31const webpack_1 = require("webpack");
32const schema_1 = require("../../browser/schema");
33const bundle_calculator_1 = require("../../utils/bundle-calculator");
34const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
35const PLUGIN_NAME = 'AnyComponentStyleBudgetChecker';
36/**
37 * Check budget sizes for component styles by emitting a warning or error if a
38 * budget is exceeded by a particular component's styles.
39 */
40class AnyComponentStyleBudgetChecker {
41 constructor(budgets) {
42 this.budgets = budgets.filter((budget) => budget.type === schema_1.Type.AnyComponentStyle);
43 }
44 apply(compiler) {
45 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
46 compilation.hooks.processAssets.tap({
47 name: PLUGIN_NAME,
48 stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
49 }, () => {
50 // In AOT compilations component styles get processed in child compilations.
51 if (!compilation.compiler.parentCompilation) {
52 return;
53 }
54 const cssExtensions = ['.css', '.scss', '.less', '.styl', '.sass'];
55 const componentStyles = Object.keys(compilation.assets)
56 .filter((name) => cssExtensions.includes(path.extname(name)))
57 .map((name) => ({
58 size: compilation.assets[name].size(),
59 label: name,
60 }));
61 const thresholds = this.budgets.flatMap((budget) => [...bundle_calculator_1.calculateThresholds(budget)]);
62 for (const { size, label } of componentStyles) {
63 for (const { severity, message } of bundle_calculator_1.checkThresholds(thresholds[Symbol.iterator](), size, label)) {
64 switch (severity) {
65 case bundle_calculator_1.ThresholdSeverity.Warning:
66 webpack_diagnostics_1.addWarning(compilation, message);
67 break;
68 case bundle_calculator_1.ThresholdSeverity.Error:
69 webpack_diagnostics_1.addError(compilation, message);
70 break;
71 default:
72 assertNever(severity);
73 }
74 }
75 }
76 });
77 });
78 }
79}
80exports.AnyComponentStyleBudgetChecker = AnyComponentStyleBudgetChecker;
81function assertNever(input) {
82 throw new Error(`Unexpected call to assertNever() with input: ${JSON.stringify(input, null /* replacer */, 4 /* tabSize */)}`);
83}
Note: See TracBrowser for help on using the repository browser.