angular-bundle: budgets/webpack validators call methods that do not exist; the TypeError is swallowed and 'missing' is always reported

オープン
#423 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
angular, node.js, typescript
領域
testing, tooling

調査の方向性

Start with src/utils/angular/angular-bundle/angular-bundle-validation-patterns.ts, src/laws/performance/performance-budget-compliance.ts, and src/utils/angular/angular-bundle/angular-bundle-optimization-analyzer.ts to trace the validators and their callers. Add a regression test using an angular.json with configured production budgets, then run the relevant tests. Done means configured budgets no longer produce the “missing” suggestion and failures to read configuration are reported explicitly.

索引モデルが issue の本文から書いたものです。

説明

bug

Version: 7.29.1 (npm latest, 5fc54afe). Same code on develop (2d2fa9a).
Area: src/utils/angular/angular-bundle/angular-bundle-validation-patterns.ts (used by the Lazy Loading Implementation checker through AngularBundleOptimizationAnalyzer.checkBundleOptimization)

What happens

validatePerformanceBudgets and validateWebpackConfiguration cast PerformanceBudgetComplianceLaw with as unknown as { … } and call two methods it does not have:

// angular-bundle-validation-patterns.ts:94-99 (and :123-129 for the webpack one)
const law = PerformanceBudgetComplianceLaw as unknown as {
  checkAngularPerformanceBudgets: (projectRoot: string) => { configured: boolean };
};
const budgetAnalysis = law.checkAngularPerformanceBudgets(projectRoot);   // undefined is not a function
...
} catch {
  suggestions.push(PERFORMANCE_BUDGETS_MISSING().suggestionMessage);      // the TypeError lands here
}

PerformanceBudgetComplianceLaw only has static async check(context) (src/laws/performance/performance-budget-compliance.ts:30). Every call therefore throws a TypeError. The catch swallows it and adds the "missing" suggestion, whatever the project actually configures. The double cast is what keeps the compiler from reporting it.

Reproduction (published 7.29.1 dist)

A temp directory whose angular.json has a production budgets entry (initial, 500kb / 1mb), called directly against dist/utils/angular/angular-bundle/angular-bundle-validation-patterns.js:

PerformanceBudgetComplianceLaw own static members: [ 'check' ]
typeof checkAngularPerformanceBudgets: undefined | typeof checkWebpackPerformanceConfig: undefined
budgets configured in angular.json -> validatePerformanceBudgets suggestions: ["Add performance budgets in angular.json build configuration"]
validateWebpackConfiguration suggestions: ["Configure webpack performance settings and optimization"]

What I ruled out

  • This is not a test-only path: the Lazy Loading Implementation checker calls AngularBundleOptimizationAnalyzer.checkBundleOptimization, which calls both validators (angular-bundle-optimization-analyzer.ts:47,51).
  • I did not measure whether the suggestion changes the law's pass/fail verdict or only its suggestions text. I only proved that the output is independent of the project.

Why it matters

The output claims budgets are missing in a project that configures them, and the catch hides the reason. This is the opposite of the tool's own rule of saying when it could not judge something. It was found in the 8.0.0 self-audit triage: the No Double Cast law flags these two casts, and they are real debt, not a detector error.

Suggested direction

  1. Call real code: either expose a budget/webpack reader (for example in src/utils/angular/) that both this analyzer and PerformanceBudgetComplianceLaw use, or read angular.json budgets directly here.
  2. Drop the as unknown as casts and the bare catch. An unreadable angular.json should become an explicit "not read" note, not a "missing" suggestion.
  3. Add a regression test with a configured budget that expects no "missing" suggestion. Today it would fail.
主要言語
TypeScript
スター
0
フォーク
0
平均マージ
38分
マージ済み PR(30日)
96

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Rule-Of-Code/RoC のほかの issue

Rule-Of-Code/RoC の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。