Skip to content

perf: pass a precompiled options check to getOptions - #240

Merged
alexander-akait merged 3 commits into
mainfrom
perf/precompiled-options-check
Nov 20, 2026
Merged

alexander-akait merged 3 commits into
mainfrom
perf/precompiled-options-check

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Summary

this.getOptions(schema) makes webpack load schema-utils and compile the options schema with ajv the first time the loader runs. webpack/webpack#22745 lets a loader pass a precompiled check as the second argument: this.getOptions(schema, check). When the check passes, the schema isn't compiled. Invalid options still get full validation, so the error messages stay the same.

  • src/options.check.js is generated from src/options.json by schema-utils precompile (schema-utils 4.6.0, a new devDependency). It's 708 bytes and requires nothing at runtime.
  • npm run lint now includes lint:schema, which fails when the check is out of date. npm run fix regenerates it.
  • ESLint, Prettier, cspell and coverage ignore the generated file.
  • Older webpack versions ignore the second argument and validate as before, so the webpack peer range doesn't change.

Tests

test/validate-options.test.js now also asserts that the check and the full schema-utils validation agree on every value it tests. webpack skips the schema when the check passes, so they must never disagree. npm run lint, the full test suite (17 tests, 44 snapshots, coverage 100%) and the build pass locally.


Generated by Claude Code

Summary by CodeRabbit

  • Improvements
    • On compatible webpack versions, option validation can use a precompiled check instead of compiling the validation schema, reducing validation setup work.
    • Existing option validation behavior, accepted options, and error reporting are preserved. On other supported webpack versions, validation continues to work as before.

this.getOptions(schema, check) skips compiling the options schema when
the check passes (webpack/webpack#22745). Older webpack versions ignore
the second argument and validate as before.

src/options.check.js is generated by `schema-utils precompile`;
`npm run lint` fails when it is out of date with options.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
@socket-security

socket-security Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedwebpack@​5.104.1 ⏵ 5.113.091 -31009397 -1100
Updatedschema-utils@​4.3.3 ⏵ 4.8.599 +110010097100

View full report

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The loader imports a generated options checker and passes it with the options schema to this.getOptions. Schema tooling adds lint and precompile scripts, and tests compare checker results with schema validation. Configuration excludes the generated checker from linting, formatting, spell checking, and coverage.

Merge Risk: Minimal · up to 96334

The loader now passes a precompiled options check to webpack to skip schema compilation on the first run. Older webpack versions ignore it and validate as before. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "perf: pass a precompiled options check to getOptions" matches the main change. The PR passes a generated options check (src/options.check.js) as the second argument to this.getOptions in …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf: pass a precompiled options check to getOptions" matches the main change. The PR passes a generated options check (src/options.check.js) as the second argument to this.getOptions in src/index.js, so webpack can skip compiling the options schema. The title is specific, concise, and uses a conventional commit prefix.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

package.json

typescript-eslint does not support TS 7.0.
Please see https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0 to run typescript-eslint using the TS 6 API.
See also typescript-eslint/typescript-eslint#10940 for tracking typescript-eslint's support for TS >=7.1

Oops! Something went wrong! :(

ESLint: 9.39.5

Error: typescript-eslint does not support TS 7.0.
at Object. (/.eslint-tmp/node_modules/@typescript-eslint/eslint-plugin/dist/index.js:50:11)
at Module._compile (node:internal/modules/cjs/loader:1929:14)
at Object..js (node:internal/modules/cjs/loader:2060:10)
at Module.load (node:internal/modules/cjs/loader:1651:32)
at Module._load (node:internal/modules/cjs/loader:1443:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:261:19)
at Module.require (node:internal/modules/cjs/loader:1674:12)
at require (node:internal/modules/helpers:157:16)
at /.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/unbound-method.js:13:28
at Object. (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/unbound-method.js:22:3)

src/options.check.js

ESLint skipped: the matched ESLint configuration already failed (config-incompatibility).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 343dce5f-d706-4e3c-bd1d-cea0e8c0a983
Commits

Reviewing files that changed from the base of the PR and between ca6342b and 9633402.

Files ignored due to path filters: 1

  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 2

  • package.json
  • src/options.check.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments: 1
test/validate-options.test.js: 1

49-51: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add invalid root values to the parity test.

The current cases always pass an object to check, so they never exercise the check-false path. The existing invalid-options loader test also passes an object, which the permissive schema accepts. Add root values such as [] and "invalid" to detect a checker regression that could make webpack skip validation.

Suggested fix
 describe("validate options", () => {
+  for (const value of [[], "invalid", 42, null]) {
+    it(`should reject the invalid root value "${value}"`, () => {
+      expect(check(value)).toBe(false);
+      expect(check(value)).toBe(isValid(value));
+    });
+  }
+
   const tests = {

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c7e0baf-1774-4560-bcab-cdd8e837dc14
📥 Commits

Reviewing files that changed from the base of the PR and between a388010 and eedd20d.

⛔ Files ignored due to path filters: 1
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing: 8
  • .changeset/precompiled-options-check.md
  • .cspell.json
  • .prettierignore
  • eslint.config.mjs
  • package.json
  • src/index.js
  • src/options.check.js
  • test/validate-options.test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a388010) to head (9633402).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #240   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           18        18           
  Branches         2         2           
=========================================
  Hits            18        18           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

alexander-akait and others added 2 commits October 18, 2026 15:52
Generate it with `schema-utils precompile --minify` and test against webpack 5.113.0, the first release that uses the check.
@alexander-akait
alexander-akait merged commit f2a96e3 into main Nov 20, 2026
19 checks passed
@alexander-akait
alexander-akait deleted the perf/precompiled-options-check branch November 20, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant