Repository navigation
fix: bundle schema-utils without errors or warnings - #238
Conversation
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 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
561e21c6-7d07-40ff-a20b-2aae6eacf353
📒 Files selected for processing: 3
.changeset/precompile-bundle.mdsrc/precompile.jstest/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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
Summary
#235 added two requests to
src/precompile.jsthat a bundler can't follow. Some tools bundleschema-utilsinto their own code, and webpack's test cases do too. In 4.8.0 theprecompileexport makes a bundler reach this file even though it only runs at build time:require(`ajv/dist/runtime/${name}`)becomes a context overajv/dist/runtime, and webpack fails to parse its.d.tsand.mapfiles.require(WEBPACK)warns that "the request of a dependency is an expression".This is what makes
test/cases/large/big-assetsfail on webpack/webpack#22774, which moves webpack's schema build toschema-utils precompile --minify.Bundling
dist/index.jswith webpack (mode: "none",target: "node"):minifyfrom the bundleCannot find module 'ajv'require, so a bundler neither bundles webpack nor warns:requirewebpack keeps as__non_webpack_require__;module.requirevia an alias, which resolves the same way as a plainrequirethere.createRequirewould also work outside a bundle, but it needs Node.js 12.2 and this package supports 10.13.Tests
test/precompile.test.jsbundles a fixture that callsprecompile(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 insrc/precompile.js.npm run lintand the full suite (1045 tests) pass locally.Generated by Claude Code
Summary by CodeRabbit