Skip to content

refactor(precompile): minify with webpack's SourceProcessor where webpack has one - #241

Merged
alexander-akait merged 2 commits into
mainfrom
refactor/precompile-source-processor
Oct 31, 2026
Merged

alexander-akait merged 2 commits into
mainfrom
refactor/precompile-source-processor

Conversation

@alexander-akait

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

Copy link
Copy Markdown
Member

Summary

precompile --minify calls webpack.javascript.syntax.printer.load(), an experimental shim webpack keeps only for this. webpack minifies JavaScript in one SourceProcessor run now and is going to remove load(). This PR uses SourceProcessor when webpack exports it, and falls back to load() only for webpack 5.112.x, which has no SourceProcessor.

// before
const minifier = await webpack.javascript.syntax.printer.load();
(await minifier.minify(code, options)).code;

// after, where webpack has it
new webpack.javascript.syntax.SourceProcessor().process(code, {
  ...options,
  sourceType: esm ? "module" : "script",
  mode: "minify",
}).code;

Checked end to end against webpack main: a CommonJS and an ES module check both minify (1779 B and 1778 B), and the minified check accepts and rejects the same values as before.

What kind of change does this PR introduce?

refactor

Did you add tests for your changes?

Yes, test/precompile.test.js: the SourceProcessor path with the options it receives. The existing minify tests cover the load() fallback with the installed webpack 5.112.0.

Does this PR introduce a breaking change?

No. webpack 5.112.0 or later is still enough.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Claude Code wrote the change and the test and ran them against the installed webpack and webpack main. A maintainer directed the work and reviews it.


Generated by Claude Code

Summary by CodeRabbit

  • Improvements
    • Precompiled output is now minified using webpack’s source processor when available, with a fallback to the existing minifier. The generated output continues to support both module and script formats.
  • Tests
    • Added coverage verifying that precompilation uses the source processor’s minified output and applies the expected options.

…pack has one

webpack's `javascript.syntax.printer.load()` is an experimental shim over
the one `SourceProcessor` minify pass and is going away; webpack 5.112.x,
which has no `SourceProcessor`, still minifies through it.

Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.23%. Comparing base (17b5696) to head (d88d6e7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
+ Coverage   97.22%   97.23%   +0.01%     
==========================================
  Files          13       13              
  Lines        1224     1231       +7     
  Branches      473      477       +4     
==========================================
+ Hits         1190     1197       +7     
  Misses         32       32              
  Partials        2        2              
Flag Coverage Δ
integration 97.23% <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.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

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: 9c14e342-59af-47f4-b514-b2d2092f5efd
Commits

Reviewing files that changed from the base of the PR and between 17b5696 and e498789.

Files selected for processing: 3
  • .changeset/precompile-source-processor.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.

Walkthrough

When webpack’s SourceProcessor is available, minify uses it to process the source in minify mode, with the source type based on the ESM setting. Otherwise, minify uses the printer fallback. The function returns the selected implementation’s result, which can be a string or a promise. A test covers ESM minification with SourceProcessor, and a changeset declares a patch release.

Merge Risk: Minimal · up to e4987

No merge-blocking issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using webpack's SourceProcessor for precompile minification when available.
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 with cyclomatic complexity of at least 2. Documentat…
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: 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 with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 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

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.

test/precompile.test.js

Oops! Something went wrong! :(

ESLint: 10.14.0

Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly
Occurred while linting /test/precompile.test.js
at detectJestVersion (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/utils/detectJestVersion.js:22:9)
at create (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:31:107)
at Object.create (/.eslint-tmp/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:39:20)
at createRuleListeners (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:502:15)
at /.eslint-tmp/node_modules/eslint/lib/linter/linter.js:628:7
at Array.forEach ()
at runRules (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:562:31)
at #flatVerifyWithoutProcessors (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1297:4)
at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1382:43)
at Linter._verifyWithFlatConfigArray (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1449:15)

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

Ports dependabot's #240 so the Lint job's `npm audit` passes.

Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
@alexander-akait
alexander-akait merged commit 94b5338 into main Oct 31, 2026
33 checks passed
@alexander-akait
alexander-akait deleted the refactor/precompile-source-processor branch October 31, 2026 16:47
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