Skip to content

Commit 6b15260

Browse files
refactor: group the graph, the define plugins and three stragglers out of lib/ root (#22213)
* refactor: group the module graph's nodes and edges into lib/graph/ `lib/graph/` already held the two graphs a compilation carries; it now holds what they are graphs of. The edges join it — `Dependency`, the `DependenciesBlock` holding them and the `AsyncDependenciesBlock` for a block loaded on demand — and so does the chunk side, `Chunk`, `ChunkGroup`, `Entrypoint` and `HotUpdateChunk`. `lib/dependencies/` keeps the concrete subclasses and `lib/template/` the `DependencyTemplate` they print through; these are the base classes every build has. Root goes from 49 files to 45. Three re-exports are owed and kept. `ignore-webpack-plugin` requires `lib/Dependency` at the top level and peers webpack >=5; `external-svg-sprite-loader` and its pixolith fork require `lib/Chunk` the same way; `@vue/preload-webpack-plugin` requires `lib/Entrypoint` at module scope and peers webpack 5. `lib/Chunk`'s and `lib/Entrypoint`'s `tsType` in the schema point at the real path, since a type cannot be read through the re-export. `lib/AsyncDependenciesBlock` is recorded as unreachable instead: its only importer is hard-source-webpack-plugin, which also imports `lib/DependenciesBlockVariable` and `lib/JavascriptGenerator`, both removed in webpack 5. The two serializable classes keep their old request restorable through `registerLegacyRequest`, so a cache pack written before this loads. `AsyncDependenciesBlock`'s removed-property tombstone gains the JSDoc its `Dependency` counterpart already carried — without it the getter infers an implicit `any` that `tsc` reports once the file moves. * refactor: group the define plugins into lib/define/ `DefinePlugin` replaces a free identifier with a constant at parse time, and `EnvironmentPlugin` and `DotenvPlugin` are each that same plugin fed from somewhere else — one from `process.env`, one from a `.env` file, both constructing a `DefinePlugin` and handing it definitions. The three move together. `ProvidePlugin` substitutes an import rather than a value, so it stays out. Root goes from 45 files to 42. No re-export is owed: the ecosystem scan records no package importing any of the three paths, and none of them is serializable or named by a `tsType`. `DotenvPlugin` reads `schemas/WebpackOptions.json` relative to itself to validate its own options, so that request moves down a level with it. * refactor: move the last three stragglers into the directories that own them `ModuleInfoHeaderPlugin` prints the per-module comment header into the generated bundle through `Template`, so it joins `lib/template/`. `LazyBarrel` finds the barrel files worth deferring and is required only by `Compilation`, and `ConcatenationScope` is the protocol scope hoisting runs on — `lib/optimize/ConcatenatedModule.js` is the only thing that constructs one, while generators across `lib/` render through it — so both join `lib/optimize/`. Root goes from 42 files to 39. `lib/errors/` needed nothing: `WebpackError` and `ModuleNotFoundError` were moved there already and the root files are re-exports, as are `InitFragment` and `DependencyTemplate` for `lib/template/`. No re-export is owed for these three — the ecosystem scan records no package importing them — and none is serializable or named by a `tsType`. * refactor: record every path this moves that the scan finds no importer for The three-way classification the guide describes leaves a path nobody imports in neither map, which reads as an omission rather than as a decision. Record those nine under `removed` with the reason, so the record answers for every path that left `lib/` root in this change rather than only for the ones an importer was found for. The consequence is worth stating: `--write` skips a path `removed` names, so a package that starts importing one of these later is no longer recorded, and `--check` no longer learns a re-export is owed. * test(css): expect an escaped at-keyword to join like the name it spells `mergeDistantRules` landed with two expectations written before #22201 made an at-keyword read as the name its escapes spell. They assert that `@\6d edia` is left as it stands and that an escaped `@keyframes` keeps `from` — both of which were only true while the tables were keyed by the raw spelling, so they have failed on `main` since #22174 merged. The behaviour is the one #22201 established and is what the plain spelling already gets: the two escaped conditions join, the sheet echoes the spelling back as written, and the keyframe selector shortens. Added alongside is the refusal under an escaped name, since reading the name is what reaches it.
1 parent 8a404c6 commit 6b15260

286 files changed

Lines changed: 2251 additions & 2148 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: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ The directory listings below are the canonical map of the repository. **Whenever
7171
- `lib/context/` — Context modules (`require.context`, dynamic request directories) and the plugins narrowing them.
7272
- `lib/css/` — CSS Modules, CSS parsing and generation.
7373
- `lib/debug/` — Debug helpers.
74-
- `lib/dependencies/` — `Dependency` classes and their templates (HarmonyImport, CommonJsRequire, RequireContext, …).
74+
- `lib/define/` — Replacing a free identifier with a constant at parse time:
75+
`DefinePlugin`, and the two plugins that are a `DefinePlugin` fed from somewhere
76+
else — `EnvironmentPlugin` from `process.env` and `DotenvPlugin` from a `.env`
77+
file. `ProvidePlugin` substitutes an import rather than a value, so it is not one
78+
of these.
79+
- `lib/dependencies/` — The concrete `Dependency` subclasses and their templates
80+
(HarmonyImport, CommonJsRequire, RequireContext, …); the `Dependency` they extend is
81+
in `lib/graph/` and the `DependencyTemplate` in `lib/template/`.
7582
- `lib/devtool/` — Source maps: the `devtool` plugins and the filename helpers they template with.
7683
- `lib/diagnostics/` — Plugins that raise a build-wide error or warning of their own:
7784
a case-insensitive filesystem collision, a deprecated option, a missing `mode`, and
@@ -82,13 +89,18 @@ The directory listings below are the canonical map of the repository. **Whenever
8289
- `lib/deno/`, `lib/electron/`, `lib/node/`, `lib/web/`, `lib/webworker/` — Target-specific runtime templates and externals presets.
8390
- `lib/entry/` — The `entry` option: `EntryPlugin`, the `EntryOptionPlugin` that reads
8491
the option into it, and `DynamicEntryPlugin` for a function entry. `Entrypoint` is a
85-
`ChunkGroup` rather than one of these, so it stays beside `ChunkGroup`.
92+
`ChunkGroup` rather than one of these, so it lives beside `ChunkGroup` in `lib/graph/`.
8693
- `lib/errors/` — Error and warning class hierarchy.
8794
- `lib/esm/` — ESM-specific output (e.g. `import.meta`).
8895
- `lib/externals/` — External modules: the `externals` option's module, factory plugin and the presets built on them.
89-
- `lib/graph/` — The module and chunk graphs a compilation holds: `ModuleGraph` and its
90-
connections, `ChunkGraph` and the `buildChunkGraph` that fills it, and the `ExportsInfo`
91-
recording what each module exports and who uses it.
96+
- `lib/graph/` — The module and chunk graphs a compilation holds, and the things they
97+
are graphs of: `ModuleGraph` and its connections, `ChunkGraph` and the
98+
`buildChunkGraph` that fills it, and the `ExportsInfo` recording what each module
99+
exports and who uses it. The edges are `Dependency`, held by a `DependenciesBlock`
100+
(`AsyncDependenciesBlock` where the block is loaded on demand); the chunk side holds
101+
`Chunk`, `ChunkGroup`, `Entrypoint` and `HotUpdateChunk`. A `Dependency` subclass a
102+
plugin owns lives in `lib/dependencies/` and the `DependencyTemplate` it prints
103+
through in `lib/template/` — this holds the base classes every build has.
92104
- `lib/hmr/` — Hot Module Replacement: `HotModuleReplacementPlugin` and the runtime
93105
modules, lazy-compilation backend and helpers it drives.
94106
- `lib/html/` — Experimental HTML support.
@@ -110,7 +122,11 @@ The directory listings below are the canonical map of the repository. **Whenever
110122
that plugin — `ExternalModule` in `lib/externals/`, `CssModule` in `lib/css/` — so
111123
this holds the ones every build has.
112124
- `lib/optimize/` — Optimization plugins (`SplitChunksPlugin`, `ConcatenatedModule`, …),
113-
including `CircularModulesPlugin`, which flags the import cycles the others reason about.
125+
including `CircularModulesPlugin`, which flags the import cycles the others reason
126+
about, and `LazyBarrel`, which finds the barrel files worth deferring.
127+
`ConcatenationScope` is the protocol scope hoisting runs on: `ConcatenatedModule`
128+
is the only thing that constructs one, and a generator anywhere in `lib/` renders
129+
through it.
114130
- `lib/performance/` — Asset/entrypoint size hints.
115131
- `lib/prefetch/` — Prefetch and preload, which are two mechanisms sharing a word:
116132
the runtime modules emitting `<link rel="prefetch">` for a chunk, and `PrefetchPlugin`
@@ -128,7 +144,9 @@ The directory listings below are the canonical map of the repository. **Whenever
128144
- `lib/stats/` — Stats output (default printer, JSON factories).
129145
- `lib/template/` — Source templates and init fragments the generators print through,
130146
including `RuntimeTemplate`, the printing helper every generator and dependency
131-
template is handed.
147+
template is handed, the `DependencyTemplate` base class, and
148+
`ModuleInfoHeaderPlugin`, which prints the per-module comment header into the
149+
generated bundle.
132150
- `lib/typescript/` — Experimental TypeScript module support (strip types via the Node.js TypeScript API).
133151
- `lib/url/` — `new URL(asset, import.meta.url)` references.
134152
- `lib/util/` — Utility helpers, including `RequestShortener`, which renders a request

‎lib/BannerPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Template = require("./template/Template");
1919
*/
2020
/** @import { PathDataChunk } from "./Compilation" */
2121
/** @import Compiler from "./Compiler" */
22-
/** @import Chunk from "./Chunk" */
22+
/** @import Chunk from "./graph/Chunk" */
2323

2424
/** @typedef {(data: { hash?: string, chunk: Chunk, filename: string }) => string} BannerFunction */
2525

0 commit comments

Comments
 (0)