Repository navigation
feat: precompile into an ES module for a "type": "module" package - #233
Conversation
A check written as CommonJS cannot be loaded from a package with "type": "module" (less-loader, sass-loader, stylus-loader). `schema-utils precompile` now writes an ES module there, the way Node.js reads a .js file, and `precompile` takes an `esm` option. ajv keeps `require` for its runtime helpers in an ES module, so they are imported from `schema-utils/dist/runtime.js`, with the extension Node.js needs in a package without an `exports` field. CommonJS output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthroughprecompile now supports ES module output through an optional 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:
03dda01a-a489-41b9-a5ef-ae26e667c820
📒 Files selected for processing: 6
.changeset/precompile-esm.mdREADME.mddeclarations/precompile.d.tssrc/cli.jssrc/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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 97.11% 97.17% +0.05%
==========================================
Files 13 13
Lines 1180 1204 +24
Branches 458 466 +8
==========================================
+ Hits 1146 1170 +24
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:
|
Summary
schema-utils precompilewrites a CommonJS module. In a package with"type": "module", Node.js loadsoptions.check.jsas an ES module, somodule.exportsthrows. That blocks less-loader, sass-loader and stylus-loader from using a precompiled check.package.jsonhas"type": "module", the way Node.js reads a.jsfile there. Otherwise it stays CommonJS. Apackage.jsonthat can't be parsed counts as CommonJS.precompile(schema, { esm: true }).requirefor its helpers even in ES module output. These are imported once withimport schemaUtilsRuntime from "schema-utils/dist/runtime.js", and only when the check uses one. The.jsextension is needed because schema-utils has noexportsfield, and Node.js won't resolve the path in an ES module without it.Tests
requireormodule.exports. When no helper is used, there's no import."type": "module"package.json, symlinked to this package, and imported by a real Node.js process. This runs on Node.js 14+. It caught the missing.jsextension, which would have broken every ES module check that uses a helper."type": "module", CommonJS under"type": "commonjs"in the same run, and CommonJS whenpackage.jsoncan't be read.npm run lintand the full suite (1038 tests) pass. Coverage is 100% statements incli.jsand 98.9% inprecompile.js.Generated by Claude Code
Summary by CodeRabbit
precompileAPI offers anesmoption to select the output format; without it, output remains CommonJS.package.jsonsets"type": "module"; otherwise, it generates CommonJS, including when the package configuration is missing or invalid.esmoption.