Skip to content

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

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

alexander-akait merged 1 commit into
mainfrom
perf/precompiled-options-check

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

this.getOptions(schema) makes webpack load schema-utils and compile the options schema with ajv on the loader's first call. webpack 5.113.0 accepts a check precompiled from the schema, this.getOptions(schema, check). When the check passes, webpack skips the schema entirely.

  • src/options.check.js is generated by schema-utils precompile --minify src/options.json. It is an ES module, and babel builds it into both dist/esm and dist/cjs.
  • lint:schema fails when the check is out of date, and fix:schema regenerates it as part of npm run fix.
  • The generated file is ignored by eslint, prettier, cspell and coverage.
  • schema-utils ^4.8.5 is added as a devDependency, and the webpack devDependency is bumped to ^5.113.0.
First validation, fresh Node 22 process Full validation Precompiled check
less-loader options ~67–100 ms ~0.6–0.9 ms
ajv loaded for valid options yes no

Invalid options still get the full schema-utils validation, so the error messages are unchanged.

Tests

  • In test/validate-options.test.js, the check must agree with the schema on every value, and values that are not an object never pass it.
  • Lint, types and the full test suite pass.
  • I compiled through both dist/cjs and dist/esm with valid and invalid options. Valid options compile without loading ajv, and invalid options give the same ValidationError.
  • The unknown option snapshots changed only because schema-utils 4.8.5, which webpack 5.113.0 brings, prints the types of boolean properties.

Breaking change

No. The webpack peer range is unchanged. Older webpack versions and rspack ignore the extra argument and validate against the schema as before.


Generated by Claude Code

Summary by CodeRabbit

  • Improvements
    • Loader options are checked more efficiently on supported webpack versions, while preserving validation against the existing options schema.
    • Invalid option values and unrecognized options continue to be rejected consistently.

Generate src/options.check.js with `schema-utils precompile --minify` and pass it to `this.getOptions`. Valid options then skip loading and compiling the schema on webpack versions that accept the check; older webpack ignores it.
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 67977d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
less-loader Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security

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.107.0 ⏵ 5.113.091 -31009397100
Updatedschema-utils@​4.3.3 ⏵ 4.8.599 +110010097100

View full report

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.93%. Comparing base (9a00942) to head (67977d4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #625   +/-   ##
=======================================
  Coverage   96.93%   96.93%           
=======================================
  Files           2        2           
  Lines         652      653    +1     
=======================================
+ Hits          632      633    +1     
  Misses         20       20           

☔ 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.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The loader now passes a generated options validator to this.getOptions alongside the options schema. The validator checks the options object and its allowed properties. Tests compare its results with schema validation and cover invalid input types. Package scripts, development dependencies, declarations, and ignore settings support generating and checking the validator.

Merge Risk: Minimal · up to 67977

The change lets valid loader options skip schema compilation on supported webpack versions. Invalid options still go through full validation. No merge-blocking risk was found.

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 validator (src/options.check.js) to this.getOptions so valid options skip …
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 validator (src/options.check.js) to this.getOptions so valid options skip loading schema-utils and compiling the ajv schema on webpack 5.113.0 or later. The title is concise, specific, and follows a conventional commit prefix. It does not mention the supporting changes (types, tests, lint config), which is expected.

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

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: 00deb8ea-51e2-468e-8ffd-fb9fe33a393a
Commits

Reviewing files that changed from the base of the PR and between 9a00942 and 67977d4.

Files ignored due to path filters: 2

  • package-lock.json is excluded by !**/package-lock.json
  • test/__snapshots__/validate-options.test.js.snap is excluded by !**/*.snap
Files selected for processing: 9

  • .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
  • types/options.check.d.ts

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

@alexander-akait
alexander-akait merged commit 378f5a3 into main Nov 20, 2026
16 checks passed
@alexander-akait
alexander-akait deleted the perf/precompiled-options-check branch November 20, 2026 12:14
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