Skip to content

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

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 with schema-utils precompile, which validates valid options without either step:

import check from "./options.check.js"; // schema-utils precompile --minify src/options.json
import schema from "./options.json" with { type: "json" };

const options = this.getOptions(schema, check);
  • Valid options go through the check only.
  • Invalid options still get the full schema-utils validation, so the error messages are unchanged.
  • src/options.check.js is an ES module, generated by npm run fix:schema. npm run lint:schema fails when it is out of date. Babel builds it into both dist/esm and dist/cjs.
First validation, fresh Node 22 process Before (schema-utils) After (check)
sass-loader options ~85–115 ms ~0.7–1.1 ms

Tests

  • validate-options.test.js: the check agrees with the schema on every value there, and options that are not an object never pass it.
  • The webpack devDependency is now ^5.113.0, so the tests run the check. That release names CSS module sources without the css prefix, so the eight built-in CSS source map snapshots are updated.
  • I built both dists and ran them in webpack with valid and invalid options. Both compile the valid options, and both report the same ValidationError for invalid ones.
  • npm run lint (types and schema check included) and the full test suite pass locally.

Breaking change?

No. The peer range is unchanged. Older webpack ignores the second argument and validates against the schema as before.


Generated by Claude Code

Summary by CodeRabbit

  • Improvements
    • Loader options are validated using a precompiled check when supported by webpack. Valid options remain accepted, while invalid values and unrecognized options are rejected.
    • Validation behavior is now tested against the options schema, including checks for non-object inputs and the expected results for individual option values.

Generate src/options.check.js with `schema-utils precompile --minify` and
pass it to `this.getOptions`, so webpack 5.113.0 and later validate valid
options without loading schema-utils or compiling the schema. Older webpack
ignores the extra argument.

Bump the webpack devDependency to ^5.113.0 so the tests run the check, and
update the built-in CSS source map snapshots for its source names.
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: da7add9

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

This PR includes changesets to release 1 package
Name Type
sass-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.106.2 ⏵ 5.113.091 -31009397100
Updatedschema-utils@​4.3.3 ⏵ 4.8.599 +110010097100
Updatedenhanced-resolve@​5.21.5 ⏵ 5.27.0100 +110010098100

View full report

@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 precompiled options checker to this.getOptions alongside the schema. The checker validates the supported option keys and value types. Tests compare checker results with schema validation and cover invalid top-level inputs. Package scripts and development configuration support generating and checking the validator.

Merge Risk: Minimal · up to da7ad

This change speeds up first-time option validation in newer webpack versions. Invalid options keep their existing error messages, and older webpack versions behave as before. 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" names the main change. The PR generates src/options.check.js from src/options.json and passes it as the second argument to this.getOp…
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" names the main change. The PR generates src/options.check.js from src/options.json and passes it as the second argument to this.getOptions in src/index.js. The stated goal is faster first validation, which the title's perf prefix conveys.

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.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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: 51629a30-db03-4f66-86f7-266fb116c417
Commits

Reviewing files that changed from the base of the PR and between b4b1e1c and da7add9.

Files ignored due to path filters: 2

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

  • .changeset/precompiled-options-check.md
  • .cspell.json
  • .prettierignore
  • eslint.config.js
  • 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 8 included reviews per hour; 7 remain after this review.

@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.72%. Comparing base (b4b1e1c) to head (da7add9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1357   +/-   ##
=======================================
  Coverage   96.72%   96.72%           
=======================================
  Files           2        2           
  Lines        1037     1038    +1     
=======================================
+ Hits         1003     1004    +1     
  Misses         34       34           

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