You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8165624
Browse filesBrowse the repository at this point in the historyBrowse files
refactor: group the module model, the diagnostics and four more out of lib/ root (#22202)
* refactor: group the diagnostic plugins, and two more into their homes
A new `lib/diagnostics/` holds the plugins that raise a build-wide warning of
their own — a case-insensitive filesystem collision, a deprecated option, a
missing `mode` — plus `IgnoreWarningsPlugin`, which filters what they produced,
and `NoEmitOnErrorsPlugin`, which reacts to errors rather than raising one. The
classes they construct stay in `lib/errors/` and the `performance` hints in
`lib/performance/`. `CircularModulesPlugin` joins `lib/optimize/` beside the
passes that reason about the same cycles, and `LibraryTemplatePlugin`
`lib/library/`. `lib/` root goes from 66 files to 60.
`LibraryTemplatePlugin` keeps a re-export at its old path: `@aiot-toolkit/`
and `@hap-toolkit/dsl-xvm` depend on webpack 5 directly and
`@stylable/webpack-extensions` peers `^5.30.0`, and all three require it at the
top level, for 139k weekly downloads. Nothing else moved here is imported from
outside.
`schemas/WebpackOptions.json` follows the file its `tsType` points at, without
which `ignoreWarnings` regenerates as `any[]`. `types.d.ts` is byte-identical.
* refactor: group the module model into lib/module/
The `Module` base class and `NormalModule`, the `ModuleFactory` hierarchy that
builds them, the `Generator` base class and the `CodeGenerationResults` its
output lands in, `ModuleProfile`, and the two type-constant files leave `lib/`
root together. A module subclass a plugin owns stays with that plugin, so this
holds the ones every build has. Root goes from 60 files to 51.
Three classes carry a serialization request. Each moves to
`webpack/lib/module/<Name>` and keeps the old one restorable through
`registerLegacyRequest`, so a pack written before this still loads;
`internalSerializables` records both.
`NormalModule`, `RawModule` and `NullFactory` keep a re-export at their old
paths — webpack-5 packages require each at the top level, for 271k weekly
downloads between them. `Module` and `Generator` do not: their only importer is
hard-source-webpack-plugin, which also imports `lib/DependenciesBlockVariable`
and `lib/JavascriptGenerator`, both removed in webpack 5, so both paths are
recorded as unreachable instead.
Two `schemas/WebpackOptions.json` `tsType` paths follow the files they point at.
`types.d.ts` regenerates byte-identical.
* refactor: move PlatformPlugin and the HMR plugin into their directories
`PlatformPlugin` pins the target platform a `target: false` build cannot infer,
so it joins the rest of the option handling in `lib/config/`, and
`HotModuleReplacementPlugin` joins the runtime modules and backend it drives in
`lib/hmr/`. Neither is imported by any package the ecosystem scan reaches, so
neither needs a re-export. Root goes from 51 files to 49.
The scan itself gains a rule and loses an ambiguity: `--write` now skips a path
the `removed` map names instead of recording it as a request too, so the two
maps are disjoint and the request count means what it says. Refreshing the
record over today's registry moved 25 such paths out of `requests`.
AGENTS.md gains a required section on moving a file out of `lib/` root — run
the scan, what earns a re-export, and the five places a path hides, of which
only `require()` is obvious. Two references it already carried had gone stale
under earlier moves and are corrected.
-`lib/entry/` — The `entry` option: `EntryPlugin`, the `EntryOptionPlugin` that reads
@@ -83,18 +89,28 @@ The directory listings below are the canonical map of the repository. **Whenever
83
89
-`lib/graph/` — The module and chunk graphs a compilation holds: `ModuleGraph` and its
84
90
connections, `ChunkGraph` and the `buildChunkGraph` that fills it, and the `ExportsInfo`
85
91
recording what each module exports and who uses it.
86
-
-`lib/hmr/` — Hot Module Replacement plugins.
92
+
-`lib/hmr/` — Hot Module Replacement: `HotModuleReplacementPlugin` and the runtime
93
+
modules, lazy-compilation backend and helpers it drives.
87
94
-`lib/html/` — Experimental HTML support.
88
95
-`lib/ids/` — Module/chunk id assignment plugins, and `RecordIdsPlugin`, which persists
89
96
the assignment across builds through `recordsPath`.
90
97
-`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.
The loader context is not one of these: `LoaderContext` and the loader-definition types are JSDoc in `lib/` like every other type, declared where the code that adds each part lives (`lib/NormalModule.js`, `lib/loaders/LoaderRunner.js`, `lib/dependencies/LoaderPlugin.js`, `lib/HotModuleReplacementPlugin.js`) and re-exported from `lib/index.js`, which is the file `generate-types.js` reads webpack's public type surface from.
179
+
The loader context is not one of these: `LoaderContext` and the loader-definition types are JSDoc in `lib/` like every other type, declared where the code that adds each part lives (`lib/module/NormalModule.js`, `lib/loaders/LoaderRunner.js`, `lib/dependencies/LoaderPlugin.js`, `lib/hmr/HotModuleReplacementPlugin.js`) and re-exported from `lib/index.js`, which is the file `generate-types.js` reads webpack's public type surface from.
164
180
165
181
**Configuration**
166
182
@@ -207,6 +223,47 @@ The two config layers differ: **`normalization.js`** canonicalizes the user-supp
207
223
208
224
**Adding a runtime requirement:** declare the symbol in `lib/runtime/RuntimeGlobals.js`, emit its code with a `RuntimeModule` subclass, and inject it by tapping `runtimeRequirementInTree`/`additionalTreeRuntimeRequirements` on `compilation.hooks` (the `…InModule` variants for per-module needs).
209
225
226
+
### Moving a file out of `lib/` root
227
+
228
+
> [!REQUIRED]
229
+
230
+
**Run `yarn find-deep-imports:check` on every move, before the commit.** A path that
231
+
leaves `lib/` root breaks any published package importing it, and the recorded scan in
232
+
`tooling/deep-webpack-imports.json` is what says which those are. `--write` refreshes it
233
+
off the registry; `--check` needs no network and is what CI runs. Its `removed` map names
234
+
the paths no webpack 5 build can reach, and the two maps are disjoint — `--write` skips a
235
+
path `removed` names rather than recording it as a request.
236
+
237
+
**A re-export is owed only to a webpack-5 package that imports the path unconditionally.**
238
+
Read the importer's tarball, not its download count: a package whose `peerDependencies`
239
+
or `dependencies` name webpack 5 and which requires the path at the top level gets a
240
+
`// TODO remove in webpack 6` re-export at the old path. One that is webpack 4 only — it
241
+
imports something webpack 5 deleted — or that probes for the path inside a `try` to detect
242
+
webpack 4 gets an entry under `removed` with that reason instead, because a re-export
243
+
would send it down the wrong branch.
244
+
245
+
**Five things carry a path, and only the first is obvious.** Rewrite every one, then
246
+
confirm the move by regenerating rather than by reading:
247
+
248
+
1.`require("…")` and `require.resolve("…")`, including template literals and a string
249
+
sitting in a ternary branch lines away from its call.
250
+
2.`@import … from "…"` in a JSDoc block.
251
+
3.`@typedef {import("…")}` — a different form from the one above, and missing it drops
252
+
the type from webpack's public surface without failing anything.
253
+
4.`tsType` in `schemas/**/*.json`, which can fail loudly in `fix:special` or silently
254
+
degrade a public type to `any`.
255
+
5.`makeSerializable(Class, "webpack/lib/…")` — the request moves with the class and the
256
+
old one stays restorable through `registerLegacyRequest`, or a pre-move cache pack
257
+
stops loading.
258
+
259
+
`yarn fix:special` leaving `types.d.ts` byte-identical is the check that 3 and 4 are done;
260
+
`ConfigCacheTestCases` reporting no `Pack got invalid` line is the check that 5 is. Nothing
261
+
static catches 1 — only building `lib/index.js` does.
262
+
263
+
**Update the Architecture listing above in the same commit**, and grep it for the old path:
264
+
prose elsewhere in this guide names files too, and those references go stale just as
0 commit comments