GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(commonjs): let each require handler take an ESTree node or a path by alexander-akait · Pull Request #23576 · webpack/webpack

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Nov 26, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

Follow-up to #23574. Four handler factories in CommonJsImportsParserPlugin had a *ByPath copy for { path: true } taps. Each pair called the same shared code; the two versions differed only in how they read the call's fields. Now each factory returns one handler that reads either form.

// before
const processResolve = createProcessResolveHandlerByPath(parser, options, getContext);
processResolve(path, node, false);
// after: the same handler serves object taps and path taps
const processResolve = createProcessResolveHandler(parser, options, getContext);
processResolve(path, node, false); // or processResolve(expr, false)
  • createRequireCacheDependency: the *ByPath copy had been byte-identical since refactor(javascript): let each parser helper take an ESTree node or a path #23574, so it is deleted.
  • createRequireAsExpressionHandler, createRequireHandler (createRequireCallHandler inside the file) and createProcessResolveHandler: a second argument that is a number means a path and a node id. For the resolve handler, that argument is otherwise the weak boolean.
  • Removes the four *ByPath statics from the class, and switches CreateRequireParserPlugin to the plain names.
  • Net: 2 files, +81 / −135.

What kind of change does this PR introduce?

refactor

Did you add tests for your changes?

No new tests. Existing cases cover both forms: test/configCases/parsing/object-api-plugins covers object taps, and the CommonJS and createRequire cases cover path taps (4704 cases pass locally).

Does this PR introduce a breaking change?

No. The object-form statics keep their names and behavior. The removed *ByPath statics were never released.

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 found the duplicate pairs, wrote the refactor and ran yarn lint and the targeted configCases, at the requester's direction.


Generated by Claude Code

Summary by CodeRabbit

  • Refactor
    • Consolidated handling of CommonJS module imports and require expressions, including when used through different parser inputs.
    • Updated related module parsing to use the shared handling, keeping behavior consistent across these cases.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-akait
refactor(commonjs): let each require handler take an ESTree node or a…
c62fffe
… path

Merge the createRequire*, createProcessResolveHandler and require cache
handlers with their *ByPath copies; each reads either tap form.

Claude-Session: https://claude.ai/code/session_013FhutQkPZ3CbsdxRa56o4m
@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c62fffe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies) label Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Reports for c62fffe, computed by this pull request's own code. Each section updates when its workflow finishes.


Preview package

This PR is packaged and the instant preview of its latest commit is available.

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@23576
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@23576
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@23576

From Preview package run #14100.


Generated code size

Comparing base (8e4e46b) to head (c62fffe). Merging this pull request will not change the code webpack generates.

What moved Tests Assets Gzip Raw Test edit
Changed, test untouched 0 0 — — —
Changed, test edited 0 0 — — —
New 0 0 — — —
Deleted 0 0 — — —
Unchanged — 11080 — — —

Read Changed, test untouched first: the test is byte-identical on both sides, so webpack generated the difference. Changed, test edited moved partly because the test did — Test edit is how many bytes the test gained, and a bundle that grew by less is not a regression. New and Deleted are whole files, not deltas — a new asset was created, not grown, so it reads gray (⚪ added) — and adding tests cannot bury a real change. Gzip decides, because that is what users download; raw is the tiebreak, and brotli and zstd are per asset below.

Sample apps

No sample app changed size.

26 unchanged app(s)
App Gzip Gzip change Raw Raw change
library amd 1.37 KiB — 2.64 KiB —
library amd-require 1.37 KiB — 2.63 KiB —
library assign 1.37 KiB — 2.63 KiB —
library assign-properties 1.41 KiB — 2.75 KiB —
library commonjs 1.37 KiB — 2.62 KiB —
library commonjs-module 1.37 KiB — 2.63 KiB —
library commonjs-static 1.54 KiB — 3.50 KiB —
library commonjs2 1.37 KiB — 2.63 KiB —
library global 1.37 KiB — 2.62 KiB —
library jsonp 1.37 KiB — 2.62 KiB —
library module 1.20 KiB — 2.30 KiB —
library self 1.37 KiB — 2.62 KiB —
library system 1.40 KiB — 2.69 KiB —
library this 1.37 KiB — 2.62 KiB —
library umd 1.43 KiB — 2.82 KiB —
library umd2 1.43 KiB — 2.82 KiB —
library var 1.37 KiB — 2.63 KiB —
library window 1.37 KiB — 2.62 KiB —
node-ssr 96.21 KiB — 370.39 KiB —
node-ssr-esm 96.56 KiB — 370.95 KiB —
react-100 32.83 KiB — 151.45 KiB —
react-1k 73.38 KiB — 897.75 KiB —
react-1k-esm 72.87 KiB — 896.58 KiB —
react-5k 188.96 KiB — 4.02 MiB —
webworker 36.75 KiB — 95.18 KiB —
webworker-esm 35.89 KiB — 93.90 KiB —

No asset changed size.

No runtime gained or lost a runtime module.

Built test/configCases with the defaults a user gets, and the apps in test/sizeCoreReports (apps/): 2527 test(s), 11080 asset(s), 112 emitted nothing.

From Generated code size run #8735.


Types Coverage

Typed lines: 99.66% (213066 of 213783)

Kind Base Head Change
any 41 41 —
unknown 20 20 —
object 13 13 —
Function 0 0 —
untyped 1 1 —

any counts EXPECTED_ANY, a written any and JSDoc's * and ? for any type. unknown counts a written unknown; ThrownValue, the unknown a throw or a rejected promise hands on, is left out. object counts EXPECTED_OBJECT and Object, Function counts EXPECTED_FUNCTION. Untyped counts the any TypeScript infers where no type is written: a type argument a call leaves to inference that comes out any, whether a lib signature defaults it, as in const map = new Map() and Array(5), or a generic call infers it from an any argument; and const list = []. An identifier that only holds an any written in the project's files is not counted again, as the any row counts it where it is written; an any a lib signature returns, such as JSON.parse's, is counted in neither row.

This pull request adds or removes no escape hatch, any or untyped identifier.

34 file(s) in lib/, hot/, declarations/ and bin/ still have an escape hatch, `any` or untyped identifiers
File Typed lines any unknown object Function untyped
declarations/WebpackOptions.ts 100.00% 7
lib/Compilation.js 99.97% 5 2
lib/module/NormalModule.js 100.00% 4 1
lib/loaders/LoaderOptionsPlugin.js 100.00% 4
lib/serialization/ObjectMiddleware.js 100.00% 4
lib/util/SortableSet.js 100.00% 4
lib/hmr/HotModuleReplacement.runtime.js 100.00% 2 1
lib/javascript/syntax-printer.js 99.99% 1 2
lib/module/NormalModuleFactory.js 100.00% 3
lib/stats/StatsFactory.js 100.00% 2 1
lib/Compiler.js 99.89% 2
lib/config/defineConfig.js 100.00% 2
lib/hmr/JavascriptHotModuleReplacement.runtime.js 100.00% 2
lib/index.js 100.00% 2
lib/loaders/LoaderRunner.js 100.00% 2
lib/module/Module.js 100.00% 2
lib/module/Parser.js 100.00% 2
lib/node/nodeConsole.js 100.00% 2
lib/config/cli.js 100.00% 1
lib/dll/DllReferencePlugin.js 100.00% 1
lib/graph/ModuleGraph.js 100.00% 1
lib/hmr/HotModuleReplacementPlugin.js 100.00% 1
lib/javascript/JavascriptParser.js 100.00% 1
lib/javascript/syntax-parser.js 100.00% 1
lib/logging/Logger.js 100.00% 1
lib/logging/createConsoleLogger.js 100.00% 1
lib/output/ManifestPlugin.js 100.00% 1
lib/serialization/types.js 100.00% 1
lib/stats/DefaultStatsFactoryPlugin.js 100.00% 1
lib/stats/StatsPrinter.js 100.00% 1
lib/util/SourceProcessor.js 100.00% 1
lib/util/makeSerializable.js 100.00% 1
lib/util/terminalColors.js 100.00% 1
lib/worker/Worker.js 100.00% 1

From Types Coverage run #4720.


Module loading

How many files a fresh Node.js process loads (require or import) to do each thing below; a change from the pull request's base is marked 🔴 when it grew and 🟢 when it shrank. Every file is startup time, so fewer is better. webpack files are this package's own (lib/, hot/); node_modules files are its dependencies'.

What the process does webpack files node_modules files
require("webpack") 2 0
import "webpack" 2 0
JavaScript syntax 12 0
CSS syntax 12 0
HTML syntax 11 0
XML syntax 11 0
JavaScript minifier 13 0
CSS minifier 14 0
HTML minifier 19 0
XML minifier 14 0
JSON minifier 1 0
development build 422 103
production build 430 131
watch with HMR, one rebuild 446 110

From Module loading run #1964.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

CommonJS require handlers now accept AST expressions or reader paths through shared factories. Parser hooks and CreateRequireParserPlugin use those factories. The path-specific helper implementations and their static exports were removed.

Changes: CommonJS require handlers

Layer / File(s) Summary
Unify handler inputs
lib/dependencies/commonjs/CommonJsImportsParserPlugin.js
The require-cache, require-as-expression, require-call, and process.resolve handlers accept expression or reader-path inputs. The separate path-specific implementations were removed.
Update parser wiring
lib/dependencies/commonjs/CommonJsImportsParserPlugin.js, lib/dependencies/esm/CreateRequireParserPlugin.js
CommonJS parser hooks and CreateRequireParserPlugin use the shared handlers. The static exports for the removed path-specific helpers were removed.

Possibly related PRs

  • webpack/webpack#23574: It applies the same expression-or-reader-path pattern to JavascriptParserHelpers and removes path-specific helpers.

Suggested labels: area: parser

Suggested reviewers: hai-x

Change: Refactor

Merge Risk: Minimal · up to c62ff

This refactor merges duplicate CommonJS require handler implementations into shared ones without intended behavior change. No concrete defect was found, and the existing configCases cover both tap forms, so merge risk is minimal.

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 uses the conventional-commit form with the type refactor and scope commonjs, which matches the required format. The change merges the node-form and path-form handlers in CommonJsImportsParse…
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 uses the conventional-commit form with the type refactor and scope commonjs, which matches the required format. The change merges the node-form and path-form handlers in CommonJsImportsParserPlugin and removes the four *ByPath statics, so the title describes the main change. The type refactor is in the allowed list. The title's branch-prefix match could not be verified from the provided context, so it is not confirmed here.

  • 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

  • X
  • Mastodon
  • Reddit
  • LinkedIn
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: webpack/webpack
  • Branch: refactor/commonjs-require-handlers-estree-or-path
  • File: .coderabbit.yaml
  • Commit: c62fffe
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f730d89-6294-4a75-8f82-0f388153f3a6
Commits

Reviewing files that changed from the base of the PR and between 8e4e46b and c62fffe.

Files selected for processing: 2

  • lib/dependencies/commonjs/CommonJsImportsParserPlugin.js
  • lib/dependencies/esm/CreateRequireParserPlugin.js

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait merged commit c41cf5c into main Nov 26, 2026
54 of 55 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait deleted the refactor/commonjs-require-handlers-estree-or-path branch November 26, 2026 15:37
@codspeed

codspeed Bot commented Nov 26, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 27.96%

2 warnings, 1 note

⚠️ 117 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 26 benchmarks have no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

❌ 1 regressed benchmark
✅ 350 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory benchmark "devtool-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 246.6 KB 342.3 KB -27.96%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing refactor/commonjs-require-handlers-estree-or-path (c62fffe) with main (8e4e46b)

Open in CodSpeed
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@alexander-akait
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.