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 1bebe75
Browse filesBrowse the repository at this point in the historyBrowse files
refactor: name three classes for what they do (#22361)
* refactor: name three classes for what they do
`HoistContainerReferences` is a plugin, so it takes the `Plugin` suffix.
`WebpackLogger` only restated its directory, so it becomes `Logger`.
`LazyBarrelController` needed the file renamed instead: it holds one
`WeakMap` of every module for the whole compilation, so it is not a lazy
barrel — `LazyBarrelInfo` is — and `LazyBarrels` says so, matching
`DependencyTemplates`. The field follows as `_lazyBarrels`.
None registers a serializer or is exported by name. The three
`No such label ... for WebpackLogger.timeX()` messages now say `Logger`,
and `types.d.ts` declares `Logger` in place of `WebpackLogger`.
* docs(agents): write down the naming rules for classes
Two rules the codebase already follows but nothing stated: a class is
named for what it does and carries its kind suffix, with the file
taking that name; and a name never invents a role suffix, prefixes
`Webpack` where the bare word is free, or repeats another class in
`lib/`.
* test(logging): cover the Logger timer error paths
The three `No such label` throws and the aggregate paths had no test, so
renaming `WebpackLogger` to `Logger` pulled uncovered lines into the diff.
Copy file name to clipboardExpand all lines: AGENTS.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ This is the canonical repository map. **When you add, rename or remove a top-lev
88
88
-`lib/loaders/` — loader execution (vendored loader-runner): pitching/normal iteration and loader loading, plus `LoaderOptionsPlugin` and `LoaderTargetPlugin`, which feed the loader context, and `LoaderPlugin` with the `LoaderDependency`/`LoaderImportDependency` it builds a loader's own imports from.
89
89
-`lib/logging/` — Logger API, console formatting, and `ProgressPlugin` (reports through it). `lib/ProgressPlugin` stays a re-export (webpack-stream requires it).
90
90
-`lib/module/` — what a module is and what makes one: `Module`, `NormalModule`, the factories (`NormalModuleFactory`, `NullFactory`, `SelfModuleFactory`), base `Parser`/`Generator`, `CodeGenerationResults`, `ModuleProfile`, and the two constants files naming module and source types. A plugin's module subclass lives with the plugin (`ExternalModule` → `lib/externals/`, `CssModule` → `lib/css/`).
91
-
-`lib/optimize/` — optimization plugins (`SplitChunksPlugin`, `ConcatenatedModule`, …), `CircularModulesPlugin` (flags import cycles), `LazyBarrel` (finds barrel files worth deferring) and the `PureExpressionDependency` only `InnerGraphPlugin` emits. The three data structures each of one plugin reads are here, not in `lib/util/`: `Queue` (`FlagDependencyExportsPlugin`), `TupleQueue` (`FlagDependencyUsagePlugin`) and `LazyBucketSortedSet` (`LimitChunkCountPlugin`). `ConcatenationScope` is scope hoisting's protocol: only `ConcatenatedModule` constructs one; any generator renders through it.
91
+
-`lib/optimize/` — optimization plugins (`SplitChunksPlugin`, `ConcatenatedModule`, …), `CircularModulesPlugin` (flags import cycles), `LazyBarrels` (finds barrel files worth deferring) and the `PureExpressionDependency` only `InnerGraphPlugin` emits. The three data structures each of one plugin reads are here, not in `lib/util/`: `Queue` (`FlagDependencyExportsPlugin`), `TupleQueue` (`FlagDependencyUsagePlugin`) and `LazyBucketSortedSet` (`LimitChunkCountPlugin`). `ConcatenationScope` is scope hoisting's protocol: only `ConcatenatedModule` constructs one; any generator renders through it.
92
92
-`lib/output/` — plugins shaping the set of files written to `output.path` (not the modules in them): `CopyPlugin` adds (`output.copy`), `CleanPlugin` prunes (`output.clean`), `BannerPlugin` rewrites an asset, `ManifestPlugin` describes the rest, and `SSRManifestPlugin` emits which client files each source module needs, so an SSR response can name the stylesheet of a route not yet requested. How names and formats are decided is `lib/template/`, `lib/library/`, `lib/devtool/`.
-`lib/prefetch/` — two mechanisms sharing a word: runtime modules emitting `<link rel="prefetch">` for a chunk, and `PrefetchPlugin`/`AutomaticPrefetchPlugin`, which resolve a module eagerly at build time through the `PrefetchDependency` they own.
@@ -266,6 +266,10 @@ When a function's output type depends on its input, use a generic (`@template`)
266
266
267
267
Spell names out in full (functions, variables, parameters, properties): `insertHtmlElement` not `insHtmlEl`, `attributeCount` not `attrCnt`, `current` not `cur`, `element` not `el`. Exceptions: abbreviations webpack already uses pervasively (`ast`, `ns`, `id`, `url`, `css`, `js`, `dir`, `env`, `fs`) or spec-defined ones (`afe` — the HTML spec's active formatting elements), and throwaway loop indices (`i`, `j`, `k`). Otherwise write the full word.
268
268
269
+
**Name a class for what it does, and the file for the class.** The name says the idea, and ends in the suffix its kind uses — `*Plugin`, `*Dependency`, `*RuntimeModule`, `*Warning`, `*Error`, `*Module`, `*Factory`, `*Generator`, `*Parser`, `*Template` (546 of 668 PascalCase files in `lib/`). A file exporting one class takes that name; where the two disagree, rename whichever is wrong — often the file. Exempt: core nouns (`Compiler`, `Chunk`), helper and data-structure modules, and any module exporting several things.
270
+
271
+
**A name never** invents a role suffix (`lib/` has no `*Controller`, `*Manager`, `*Service` or `*Util` — a class that controls a thing is the thing), carries a `Webpack` prefix where the bare word is free, or repeats another class in `lib/`, since a stack trace and `types.d.ts` show the name alone.
0 commit comments