Skip to content

fix: bundle schema-utils without errors or warnings - #238

Merged
alexander-akait merged 2 commits into
mainfrom
fix/precompile-bundle
Oct 19, 2026
Merged

alexander-akait merged 2 commits into
mainfrom
fix/precompile-bundle

Conversation

@alexander-akait

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

Copy link
Copy Markdown
Member

Summary

#235 added two requests to src/precompile.js that a bundler can't follow. Some tools bundle schema-utils into their own code, and webpack's test cases do too. In 4.8.0 the precompile export makes a bundler reach this file even though it only runs at build time:

  • require(`ajv/dist/runtime/${name}`) becomes a context over ajv/dist/runtime, and webpack fails to parse its .d.ts and .map files.
  • require(WEBPACK) warns that "the request of a dependency is an expression".

This is what makes test/cases/large/big-assets fail on webpack/webpack#22774, which moves webpack's schema build to schema-utils precompile --minify.

Bundling dist/index.js with webpack (mode: "none", target: "node"):

Errors Warnings minify from the bundle
4.8.0 10 1 fails: Cannot find module 'ajv'
This PR 0 0 works
  • The two inlined helpers are now required by name.
  • webpack is loaded with Node.js's own require, so a bundler neither bundles webpack nor warns:
    • inside a webpack bundle, through the require webpack keeps as __non_webpack_require__;
    • elsewhere, through module.require via an alias, which resolves the same way as a plain require there.
  • createRequire would also work outside a bundle, but it needs Node.js 12.2 and this package supports 10.13.
  • The minified check for webpack's options is byte-identical to 4.8.0's.

Tests

test/precompile.test.js bundles a fixture that calls precompile(schema, { minify: true }). It expects no errors or warnings, then runs the bundle and checks the minified check it produces. It fails without the change in src/precompile.js. npm run lint and the full suite (1045 tests) pass locally.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed precompiled schema validation with minification when bundled for webpack, including access to Ajv runtime helpers.
  • Tests
    • Added a webpack bundling check that runs a minified precompiled schema against valid and invalid inputs and verifies the build completes without errors or warnings.

precompile required the ajv helpers it inlines with a request built from
their name and webpack with a variable request. A bundler that bundles
schema-utils, as webpack's own test cases do, turned the first into a
context over ajv/dist/runtime and failed to parse its .d.ts and .map
files, and warned about the second.

The helpers are now required by name and webpack through an alias of
module, so bundling schema-utils reports nothing. The minified output is
byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6946e8db-5884-4e97-80c2-148ff472f476
📥 Commits

Reviewing files that changed from the base of the PR and between 4385103 and 64d5ce7.

📒 Files selected for processing: 4
  • .changeset/precompile-bundle.md
  • src/precompile.js
  • test/fixtures/bundled-precompile.js
  • test/precompile.test.js
🚧 Files skipped from review as they are similar to previous changes: 3
  • .changeset/precompile-bundle.md
  • src/precompile.js
  • test/precompile.test.js

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

Walkthrough

precompile now uses named loaders for Ajv’s equal and ucs2length helpers. Minification loads webpack’s printer through Node’s native require. A new webpack integration test bundles and runs a fixture with minification enabled, then checks the results for an empty string and "a". A patch changeset records the changes.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 64d5c

The change supports minification from a webpack bundle, and the added integration test exercises that path. No merge-blocking risk is evident.

Pre-merge checks: Passed 5
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 …
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: bundling schema-utils without errors or warnings.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 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

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 561e21c6-7d07-40ff-a20b-2aae6eacf353
📥 Commits

Reviewing files that changed from the base of the PR and between b4b44eb and 4385103.

📒 Files selected for processing: 3
  • .changeset/precompile-bundle.md
  • src/precompile.js
  • test/precompile.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.

Comment thread src/precompile.js
@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 97.22%. Comparing base (b4b44eb) to head (64d5ce7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #238   +/-   ##
=======================================
  Coverage   97.21%   97.22%           
=======================================
  Files          13       13           
  Lines        1220     1224    +4     
  Branches      471      474    +3     
=======================================
+ Hits         1186     1190    +4     
  Misses         32       32           
  Partials        2        2           
Flag Coverage Δ
integration 97.22% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Inside a webpack bundle, module is webpack's module object, which has no
require, so minify reported that webpack was missing. Use the require
webpack keeps as __non_webpack_require__ there, and module.require
outside a bundle. The bundled test now also minifies a check from the
bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
@alexander-akait
alexander-akait merged commit 518887b into main Oct 19, 2026
33 checks passed
@alexander-akait
alexander-akait deleted the fix/precompile-bundle branch October 19, 2026 01:39
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