Skip to content

Commit 0af51c4

Browse files
refactor: group more loose lib/ sources into directories (#22191)
* refactor(config): move the options pipeline into lib/config/ `validateSchema`, `WebpackOptionsDefaulter`, `WebpackOptionsApply` and its `OptionsApply` base class are the steps between a user's config object and a `Compiler`, and sat in `lib/` root beside the plugins they apply. They join `defaults.js` and `normalization.js`, the two steps already in `lib/config/`. Paths only: `types.d.ts` regenerates byte-identical and no deep path the recorded ecosystem scan names stops resolving, so nothing needs a re-export. The scan is refreshed here too (2026-09-17 to 2026-09-19) — download counts moved, no path came or went. * refactor: group resolving, loader, node, id and util sources Eight more files leave `lib/` root: a new `lib/resolve/` takes `ResolverFactory` and the two plugins that redirect a request before it reaches one (`IgnorePlugin`, `NormalModuleReplacementPlugin`), while `LoaderOptionsPlugin` and `LoaderTargetPlugin` join `lib/loaders/`, `NodeStuffPlugin` `lib/node/`, `RecordIdsPlugin` `lib/ids/` and `RequestShortener` `lib/util/`. `RequestShortener` keeps a re-export at its old path: `@nuxt/`- and `@soda/friendly-errors-webpack-plugin` both declare webpack 5 support and require it at the top level, for 1.6M weekly downloads. Nothing else here is imported from outside — `LoaderTargetPlugin`'s one importer also requires `lib/FunctionModulePlugin` and `lib/MultiEntryPlugin`, removed in webpack 5, so it is recorded as unreachable rather than shimmed. `schemas/plugins/IgnorePlugin.json` follows the file its `tsType` points at. `types.d.ts` regenerates byte-identical. * fix: point the moved WebpackOptionsApply at hot/ from its new depth `hot/` is at the repo root, so the three `require.resolve` specifiers reaching it need one more level from `lib/config/` than from `lib/` root. They were missed because two sit inside a ternary and one is a template literal, none of them adjacent to `require(`, which is what the path rewrite matched on. Bundling `lib/index.js` reported each as a failed resolve, leaving only the three optional image encoders `test/cases/large/big-assets` already expects.
1 parent 91590d3 commit 0af51c4

62 files changed

Lines changed: 464 additions & 447 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ The directory listings below are the canonical map of the repository. **Whenever
6060
- `lib/async-modules/` — Top-level await.
6161
- `lib/bun/` — Bun target externals preset (`bun:*` and node.js built-in modules).
6262
- `lib/cache/` — Filesystem and memory caches.
63-
- `lib/config/` — Config defaults, normalization, target presets.
63+
- `lib/config/` — Everything between a user's config object and a `Compiler`:
64+
`validateSchema` checks it against the schema, `normalization.js` canonicalizes its
65+
shape, `defaults.js` fills values in, and `WebpackOptionsApply` reads the result into
66+
the plugins it implies. `WebpackOptionsDefaulter` is the normalize-then-default pair
67+
under one deprecated name, and `OptionsApply` the base class the apply step extends.
68+
Also holds the target presets and `defineConfig`.
6469
- `lib/container/` — Module Federation.
6570
- `lib/context/` — Context modules (`require.context`, dynamic request directories) and the plugins narrowing them.
6671
- `lib/css/` — CSS Modules, CSS parsing and generation.
@@ -80,17 +85,23 @@ The directory listings below are the canonical map of the repository. **Whenever
8085
recording what each module exports and who uses it.
8186
- `lib/hmr/` — Hot Module Replacement plugins.
8287
- `lib/html/` — Experimental HTML support.
83-
- `lib/ids/` — Module/chunk id assignment plugins.
88+
- `lib/ids/` — Module/chunk id assignment plugins, and `RecordIdsPlugin`, which persists
89+
the assignment across builds through `recordsPath`.
8490
- `lib/javascript/` — JavaScript parsing (webpack's own ECMAScript parser, ported from acorn), generation, exports analysis. `syntax.js` serves every production a build reaches, so `grammar.js` (the full grammar) and `regexp.js` (the pattern validator) are installed onto the parser's prototype only when something asks for one — keep it that way and never `require` either from a path a build takes.
8591
- `lib/json/` — JSON modules.
8692
- `lib/library/` — UMD/AMD/ESM/CommonJS library output formats.
87-
- `lib/loaders/` — Loader execution runtime (vendored loader-runner): pitching/normal loader iteration and loader module loading.
93+
- `lib/loaders/` — Loader execution runtime (vendored loader-runner): pitching/normal loader
94+
iteration and loader module loading, plus the `LoaderOptionsPlugin` and
95+
`LoaderTargetPlugin` that feed the loader context.
8896
- `lib/logging/` — Logger API and console formatting.
8997
- `lib/optimize/` — Optimization plugins (`SplitChunksPlugin`, `ConcatenatedModule`, …).
9098
- `lib/performance/` — Asset/entrypoint size hints.
9199
- `lib/prefetch/` — Prefetch and preload, which are two mechanisms sharing a word:
92100
the runtime modules emitting `<link rel="prefetch">` for a chunk, and `PrefetchPlugin`
93101
and `AutomaticPrefetchPlugin`, which resolve a module eagerly at build time instead.
102+
- `lib/resolve/` — Turning a request into a file: the `ResolverFactory` every resolve goes
103+
through, and the two plugins that redirect a request before it gets there —
104+
`IgnorePlugin` and `NormalModuleReplacementPlugin`.
94105
- `lib/rules/` — `module.rules` matching engine.
95106
- `lib/runtime/` — Runtime modules emitted into bundles (chunk loaders, public-path, …),
96107
the `RuntimeModule` base class they extend, the `RuntimeGlobals` symbols they declare,
@@ -104,7 +115,8 @@ The directory listings below are the canonical map of the repository. **Whenever
104115
template is handed.
105116
- `lib/typescript/` — Experimental TypeScript module support (strip types via the Node.js TypeScript API).
106117
- `lib/url/` — `new URL(asset, import.meta.url)` references.
107-
- `lib/util/` — Utility helpers.
118+
- `lib/util/` — Utility helpers, including `RequestShortener`, which renders a request
119+
relative to the context for every message a user reads.
108120
- `lib/wasm/`, `lib/wasm-async/`, `lib/wasm-sync/` — WebAssembly module support.
109121
- `lib/watch/` — Watch mode: the watching handles a compiler returns, and `WatchIgnorePlugin`.
110122
- `hot/` — Runtime code shipped to browsers for HMR (browser-side, not Node tooling).

‎lib/CircularModulesPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { compareModulesByIdentifier } = require("./util/comparators");
1515
/** @import ModuleGraph from "./graph/ModuleGraph" */
1616
/** @import ModuleGraphConnection from "./graph/ModuleGraphConnection" */
1717
/** @import Module, { BuildInfo } from "./Module" */
18-
/** @import RequestShortener from "./RequestShortener" */
18+
/** @import RequestShortener from "./util/RequestShortener" */
1919

2020
const PLUGIN_NAME = "CircularModulesPlugin";
2121

‎lib/Compilation.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const { toError } = ErrorHelpers;
168168
*/
169169
/** @import { ModuleId } from "./graph/ChunkGraph" */
170170
/** @import ModuleGraphConnection from "./graph/ModuleGraphConnection" */
171-
/** @import RequestShortener from "./RequestShortener" */
171+
/** @import RequestShortener from "./util/RequestShortener" */
172172
/** @import RuntimeModule from "./runtime/RuntimeModule" */
173173
/** @import { RenderManifestEntry, RenderManifestOptions } from "./template/Template" */
174174

‎lib/Compiler.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const {
1414
const { SizeOnlySource } = require("webpack-sources");
1515
const Compilation = require("./Compilation");
1616
const NormalModuleFactory = require("./NormalModuleFactory");
17-
const RequestShortener = require("./RequestShortener");
18-
const ResolverFactory = require("./ResolverFactory");
1917
const Stats = require("./Stats");
2018
const Cache = require("./cache/Cache");
2119
const CacheFacade = require("./cache/CacheFacade");
@@ -24,6 +22,8 @@ const WebpackError = require("./errors/WebpackError");
2422
const ChunkGraph = require("./graph/ChunkGraph");
2523
const ModuleGraph = require("./graph/ModuleGraph");
2624
const { Logger } = require("./logging/Logger");
25+
const ResolverFactory = require("./resolve/ResolverFactory");
26+
const RequestShortener = require("./util/RequestShortener");
2727
const asyncLib = require("./util/async");
2828
const { PERMISSIONS_MASK, dirname, join, mkdirp } = require("./util/fs");
2929
const {
@@ -69,7 +69,7 @@ const getConcurrentCompilationError = memoize(() =>
6969
*/
7070
/** @import Module, { BuildInfo } from "./Module" */
7171
/** @import Watching from "./watch/Watching" */
72-
/** @import { RecordsChunks, RecordsModules } from "./RecordIdsPlugin" */
72+
/** @import { RecordsChunks, RecordsModules } from "./ids/RecordIdsPlugin" */
7373
/** @import { PlatformTargetProperties } from "./config/target" */
7474
/** @import { LoggingFunction } from "./logging/createConsoleLogger" */
7575
/** @import { SplitData } from "./optimize/AggressiveSplittingPlugin" */

‎lib/Generator.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const memoize = require("./util/memoize");
2424
* } from "./Module"
2525
*/
2626
/** @import ModuleGraph from "./graph/ModuleGraph" */
27-
/** @import RequestShortener from "./RequestShortener" */
27+
/** @import RequestShortener from "./util/RequestShortener" */
2828
/** @import NormalModule from "./NormalModule" */
2929
/** @import RuntimeTemplate from "./template/RuntimeTemplate" */
3030
/** @import Hash from "./util/Hash" */

‎lib/Module.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const makeSerializable = require("./util/makeSerializable");
4747
/** @import { OptimizationBailouts } from "./graph/ModuleGraph" */
4848
/** @import ModuleProfile from "./ModuleProfile" */
4949
/** @import NormalModuleFactory from "./NormalModuleFactory" */
50-
/** @import RequestShortener from "./RequestShortener" */
51-
/** @import { ResolverWithOptions } from "./ResolverFactory" */
50+
/** @import RequestShortener from "./util/RequestShortener" */
51+
/** @import { ResolverWithOptions } from "./resolve/ResolverFactory" */
5252
/** @import RuntimeTemplate from "./template/RuntimeTemplate" */
5353
/**
5454
* Defines the init fragment type used by this module.

‎lib/ModuleInfoHeaderPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Template = require("./template/Template");
1616
/** @import ExportsInfo, { ExportInfo } from "./graph/ExportsInfo" */
1717
/** @import Module, { BuildMeta } from "./Module" */
1818
/** @import ModuleGraph from "./graph/ModuleGraph" */
19-
/** @import RequestShortener from "./RequestShortener" */
19+
/** @import RequestShortener from "./util/RequestShortener" */
2020

2121
/**
2222
* Join iterable with comma.

‎lib/NormalModule.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ const getModuleBuildError = memoize(() => require("./errors/ModuleBuildError"));
137137
* } from "./NormalModuleFactory"
138138
*/
139139
/** @import Parser, { PreparsedAst } from "./Parser" */
140-
/** @import RequestShortener from "./RequestShortener" */
140+
/** @import RequestShortener from "./util/RequestShortener" */
141141
/** @import Compiler from "./Compiler" */
142142
/** @import { Logger } from "./logging/Logger" */
143143
/**
144144
* @import {
145145
* ResolverWithOptions,
146146
* ResolveOptionsWithDependencyType
147-
* } from "./ResolverFactory"
147+
* } from "./resolve/ResolverFactory"
148148
*/
149149
/**
150150
* @import {

‎lib/NormalModuleFactory.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const matchAlias = require("./util/matchAlias");
8585
* } from "./NormalModule"
8686
*/
8787
/** @import Parser from "./Parser" */
88-
/** @import ResolverFactory, { ResolverWithOptions } from "./ResolverFactory" */
88+
/** @import ResolverFactory, { ResolverWithOptions } from "./resolve/ResolverFactory" */
8989
/** @import ModuleDependency from "./dependencies/ModuleDependency" */
9090
/**
9191
* @import {

‎lib/RawModule.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const makeSerializable = require("./util/makeSerializable");
3535
*/
3636
/** @import ModuleGraph from "./graph/ModuleGraph" */
3737
/** @import { ConnectionState } from "./graph/ModuleGraphConnection" */
38-
/** @import RequestShortener from "./RequestShortener" */
39-
/** @import { ResolverWithOptions } from "./ResolverFactory" */
38+
/** @import RequestShortener from "./util/RequestShortener" */
39+
/** @import { ResolverWithOptions } from "./resolve/ResolverFactory" */
4040
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext<[string, string, string, ReadOnlyRuntimeRequirements | null]>} ObjectDeserializerContext */
4141
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext<[string, string, string, ReadOnlyRuntimeRequirements | null]>} ObjectSerializerContext */
4242
/** @import Hash from "./util/Hash" */

0 commit comments

Comments
 (0)