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 3ef01ca
Browse filesBrowse the repository at this point in the historyBrowse files
refactor(errors): move every error and warning class into lib/errors/ (#22340)
* refactor(errors): move every error and warning class into lib/errors/
AGENTS.md says error and warning classes live in `lib/errors/` whatever
raises them, but sixteen did not: ten sat beside the plugin that raised
them, and six were declared inline inside one.
Ten files move as they are -- `ESMLinkingError`, `FalseIIFEUmdWarning`,
`MinMaxSizeWarning`, the four `SizeLimitsPlugin` warnings,
`DuplicatePackagesWarning`, `UnsupportedWebAssemblyFeatureError` and
`WebAssemblyInInitialChunkError`.
Six are extracted from the plugin that declared them: `NoModeWarning`,
`DeprecatedOptionWarning`, `CaseSensitiveModulesWarning` (with the two
helpers only it reads), `DllManifestError`,
`RequireIncludeDeprecationWarning` and `SystemImportDeprecationWarning`.
Each raising plugin stays where it is and imports the class.
The last two are serializable, so each registers under its new request
and keeps both historical requests open with `registerLegacyRequest` --
they had already moved once -- or a pre-move cache pack stops loading.
`SystemPlugin.SystemImportDeprecationWarning` stays as it was.
No re-export is owed: `find-deep-imports:check` records no published
package importing any of the sixteen paths. `types.d.ts` regenerates
byte-identical, and `WebAssemblyInInitialChunkError` gains a marker, as
it is raised only from `lib/wasm-sync/` and no longer sits there.
* refactor(serialization): let makeSerializable take the legacy requests too
A moved class needed a `registerLegacyRequest` call per request it had
been written under, so 102 files repeated the class name and the `name`
argument two or three times over -- 119 call sites in all.
`makeSerializable` now takes an array instead: the first entry is the
request the class is written under, the rest are the ones it stays
readable under. It registers the first exactly as before and hands the
rest to `registerLegacyRequest`, so nothing about the wire format moves.
Each array marks the legacy entries `TODO in the next major release`, so
the whole cleanup is one grep, and the reason a given request exists
stays next to it where it was already written down.
`registerLegacyRequest` stays exported and is still used once, where the
array cannot say it: `ModuleExternalInitFragment` registers with
`register` and a serializer of its own. The two deprecation warnings
moved to `lib/errors/` in the previous commit now carry the `name` their
older requests always had, rather than registering under none.
`generate-internal-serializables.js` read only the first request of a
call, so it now reads them all; it regenerates `internalSerializables.js`
byte-identical, all 262 entries. Dumping the serializer maps before and
after shows the 282 read keys and 163 registrations unchanged but for
those two names.
* test(errors): cover the case-conflict warning on a case-sensitive disk
The existing case has it backwards by necessity: it runs only where
`FILE.js` resolves to the committed `file.js`, so the warning is
exercised on a case-insensitive filesystem and the Linux branch asserts
the module-not-found error instead. Every coverage uploader is
ubuntu-latest, so `CaseSensitiveModulesWarning` read 21% -- its message
builder never ran in a run that reported.
Write the colliding pair to a temporary directory instead, which a
checkout cannot hold, and assert the warning a real build emits. Where
the two names are one file the case above already covers it, so the test
returns. Statements, lines and functions go 21% -> 100%.
* chore(changeset): give this PR its own entry instead of stretching 007
Folding into `007-export-module-type-and-target-plugins` took an entry
that was already 189 characters to 244, the longest pending one. That
entry belongs to the change that exposed `util.makeSerializable`; this
PR widens it, which is its own line.
The new entry is 69 characters, inside the 80 `.coderabbit.yaml` asks
for, and 007 goes back to what main has.
* test: replace fs.rmSync with explicit cleanup in casing warning test
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,13 +65,13 @@ This is the canonical repository map. **When you add, rename or remove a top-lev
65
65
-`lib/css/` — CSS Modules, parsing, generation. `syntax.js` reaches `syntax-parser.js` (reads) and `syntax-printer.js` (writes) through getters, like `javascript`, so a walk that never prints never loads the printer. It publishes those two plus `SourceProcessor` only — read a former re-export off `parser` or `printer`. `topologicalSort` (Kahn's algorithm, source-order tie-breaking) lives here because only `CssParser` calls it, to order the `composes … from` files and give each one's first import dependency its `sourceOrder`.
66
66
-`lib/debug/` — debug helpers.
67
67
-`lib/define/` — replacing a free identifier with a constant at parse time: `DefinePlugin`, plus `EnvironmentPlugin` (fed from `process.env`) and `DotenvPlugin` (from `.env`). `ProvidePlugin` substitutes an import, not a value → `lib/provide/`.
68
-
- `lib/dependencies/` — concrete `Dependency` subclasses and their templates (ESMImport, CommonJsRequire, RequireContext, …); the base `Dependency` is in `lib/graph/`, `DependencyTemplate` in `lib/template/`. Its root holds only the re-exports old paths owe (`NullDependency`, `ConstDependency` and `ContextElementDependency`, each imported by a published webpack 5 package). Everything else is a directory: `core/` for what every family builds on — the bases, both `ModuleDependencyTemplateAs*`, `ImportPhase` and the shared `ConstDependency` family — and `helpers/` for the parse-time helpers two or more families read; a family owning a set of dependencies gets its own directory: `amd/` (with the `LocalModule` a named `define` records, `RequireJsStuffPlugin`, and the generically named `UnsupportedDependency`, which only AMD emits), `commonjs/` (with `require.resolve`, `require.ensure`, `require.include` and `ModuleDecoratorDependency`), `context/`, `css/`, `esm/` (with `TopLevelAwaitDependency`), `html/`, `hmr/`, `import/`, `import-meta/`, `system/`, `url/` (`new URL(asset, import.meta.url)`, with the `URLParserPlugin` that reads it and the `ImportMetaResolveDependency` extending its base), `wasm/`, `worker/` (with the `CreateScriptUrlDependency` only it constructs). Two group by what a request asks for rather than by syntax: `context/` (the `ContextDependency` base every family's context variant extends, plus `require.context`, `import.meta.webpackContext` and the glob form) and `hmr/` (the `module.hot` and `import.meta.webpackHot` accept/decline pairs). What decides the directory is which plugin applies it, not the language it names: `CreateRequireParserPlugin` reads a CommonJS `require` out of an ESM module, so it sits in `esm/`, because `ESMModulesPlugin` applies it. `import.meta` is `import-meta/`, not `esm/`, for the same reason: `WebpackOptionsApply` applies `ImportMetaPlugin` unconditionally and it taps `javascript/auto` as well as `javascript/esm`. That directory holds only what nothing else reads — `ImportMetaMainDependency` and the generically named `BuildTimeConstDependency`; its context, hot and resolve dependencies follow their own applier into `context/`, `hmr/` and `url/`, and `lib/node/`, `lib/hmr/`, `esm/`, `url/` and `worker/` read its hooks from outside. `import()` sits in `import/`, not `esm/`, on the same evidence: `ImportPlugin` is applied by `WebpackOptionsApply` and taps `javascript/dynamic` too, since the expression is legal in a script. Its `ImportPhase` enum is `core/`, read by `graph/`, `optimize/`, `externals/` and more. A dependency a single feature owns is not here at all but with that feature, by the same rule: `LoaderDependency` in `lib/loaders/`, `JsonExportsDependency` in `lib/json/`, `DllEntryDependency` in `lib/dll/`, the `ExternalModule*` three in `lib/node/`, `EntryDependency` in `lib/entry/`, `PrefetchDependency` in `lib/prefetch/`, `ProvidedDependency` in `lib/provide/`, `PureExpressionDependency` in `lib/optimize/`, and `ExportsInfoDependency` and `WebpackIsIncludedDependency` in `lib/javascript/`. A class leaving this root moves its `makeSerializable` request with it and holds the old one open with `registerLegacyRequest`, or a pre-move cache pack stops loading — one that moved twice keeps a registration per old request, which is why the `esm/` classes carry both an `ESM` and a `Harmony` one. `ContextElementDependency`, `NullDependency` and `ConstDependency` also keep a re-export at their old path, the three moved paths a published webpack 5 package imports.
68
+
- `lib/dependencies/` — concrete `Dependency` subclasses and their templates (ESMImport, CommonJsRequire, RequireContext, …); the base `Dependency` is in `lib/graph/`, `DependencyTemplate` in `lib/template/`. Its root holds only the re-exports old paths owe (`NullDependency`, `ConstDependency` and `ContextElementDependency`, each imported by a published webpack 5 package). Everything else is a directory: `core/` for what every family builds on — the bases, both `ModuleDependencyTemplateAs*`, `ImportPhase` and the shared `ConstDependency` family — and `helpers/` for the parse-time helpers two or more families read; a family owning a set of dependencies gets its own directory: `amd/` (with the `LocalModule` a named `define` records, `RequireJsStuffPlugin`, and the generically named `UnsupportedDependency`, which only AMD emits), `commonjs/` (with `require.resolve`, `require.ensure`, `require.include` and `ModuleDecoratorDependency`), `context/`, `css/`, `esm/` (with `TopLevelAwaitDependency`), `html/`, `hmr/`, `import/`, `import-meta/`, `system/`, `url/` (`new URL(asset, import.meta.url)`, with the `URLParserPlugin` that reads it and the `ImportMetaResolveDependency` extending its base), `wasm/`, `worker/` (with the `CreateScriptUrlDependency` only it constructs). Two group by what a request asks for rather than by syntax: `context/` (the `ContextDependency` base every family's context variant extends, plus `require.context`, `import.meta.webpackContext` and the glob form) and `hmr/` (the `module.hot` and `import.meta.webpackHot` accept/decline pairs). What decides the directory is which plugin applies it, not the language it names: `CreateRequireParserPlugin` reads a CommonJS `require` out of an ESM module, so it sits in `esm/`, because `ESMModulesPlugin` applies it. `import.meta` is `import-meta/`, not `esm/`, for the same reason: `WebpackOptionsApply` applies `ImportMetaPlugin` unconditionally and it taps `javascript/auto` as well as `javascript/esm`. That directory holds only what nothing else reads — `ImportMetaMainDependency` and the generically named `BuildTimeConstDependency`; its context, hot and resolve dependencies follow their own applier into `context/`, `hmr/` and `url/`, and `lib/node/`, `lib/hmr/`, `esm/`, `url/` and `worker/` read its hooks from outside. `import()` sits in `import/`, not `esm/`, on the same evidence: `ImportPlugin` is applied by `WebpackOptionsApply` and taps `javascript/dynamic` too, since the expression is legal in a script. Its `ImportPhase` enum is `core/`, read by `graph/`, `optimize/`, `externals/` and more. A dependency a single feature owns is not here at all but with that feature, by the same rule: `LoaderDependency` in `lib/loaders/`, `JsonExportsDependency` in `lib/json/`, `DllEntryDependency` in `lib/dll/`, the `ExternalModule*` three in `lib/node/`, `EntryDependency` in `lib/entry/`, `PrefetchDependency` in `lib/prefetch/`, `ProvidedDependency` in `lib/provide/`, `PureExpressionDependency` in `lib/optimize/`, and `ExportsInfoDependency` and `WebpackIsIncludedDependency` in `lib/javascript/`. A class leaving this root moves its `makeSerializable` request with it and keeps the old one open by listing it after the new one, or a pre-move cache pack stops loading — one that moved twice lists both, which is why the `esm/` classes carry an `ESM` and a `Harmony` request. `ContextElementDependency`, `NullDependency` and `ConstDependency` also keep a re-export at their old path, the three moved paths a published webpack 5 package imports.
69
69
-`lib/devtool/` — source maps: the `devtool` plugins and their filename helpers.
70
70
-`lib/diagnostics/` — plugins raising a build-wide error/warning of their own (case-insensitive filesystem collision, deprecated option, missing `mode`), `IgnoreWarningsPlugin` (filters them) and `NoEmitOnErrorsPlugin` (reacts to errors). Their classes live in `lib/errors/`; `performance` hints in `lib/performance/`.
71
71
-`lib/dll/` — DllPlugin / DllReferencePlugin, and the two dependencies they own, `DllEntryDependency` and `DelegatedSourceDependency`.
72
72
-`lib/deno/`, `lib/electron/`, `lib/node/`, `lib/web/`, `lib/webworker/` — target-specific runtime templates and externals presets. `lib/node/` also holds the three `ExternalModule*` dependencies, which only `NodeStuffPlugin` applies: they import a host module inline (`fileURLToPath` from `node:url` for `__dirname`) and are unrelated to `lib/externals/ExternalModule`, despite the name.
73
73
-`lib/entry/` — the `entry` option: `EntryPlugin` with the `EntryDependency` it builds one from, `EntryOptionPlugin` (reads the option into it), `DynamicEntryPlugin` (function entry). `Entrypoint` is a `ChunkGroup` → `lib/graph/`.
74
-
-`lib/errors/` — error and warning class hierarchy.
74
+
-`lib/errors/` — every error and warning class, whatever raises them, and the helpers that shape them (`ErrorHelpers`, `deriveStackFromNestedError`). The raising plugin stays in its own directory and imports the class from here, so a diagnostic is found by kind rather than by which subsystem happened to emit it.
-`lib/externals/` — the `externals` option's module, factory plugin and presets.
77
77
-`lib/fs/` — the filesystem webpack reads/writes through: `fs.js` declares the `InputFileSystem`/`OutputFileSystem` surface callers are typed against, plus path helpers; `FileSystemInfo` records the snapshots, timestamps and build dependencies watch and cache judge staleness from. `StackedCacheMap` is here for the same reason: `FileSystemInfo` alone keeps its timestamps in one, and it trades `delete`/`has` away to add whole maps at once. A target-supplied filesystem stays with its target (`NodeWatchFileSystem` in `lib/node/`). `lib/FileSystemInfo` stays a re-export (html-webpack-plugin types against it).
@@ -230,7 +230,7 @@ They are documentation only (stripped from precompiled validators). A pure `$ref
230
230
2.`@import … from "…"` in JSDoc.
231
231
3.`@typedef {import("…")}` — a different form; missing it silently drops the type from the public surface.
232
232
4.`tsType` in `schemas/**/*.json` — fails loudly in `fix:special` or silently degrades a public type to `any`.
233
-
5.`makeSerializable(Class, "webpack/lib/…")` — the request moves with the class and the old one stays restorable via `registerLegacyRequest`, or pre-move cache packs stop loading.
233
+
5.`makeSerializable(Class, "webpack/lib/…")` — the request moves with the class, and every request it was written under before goes in an array after the new one (current first), or pre-move cache packs stop loading. Reach for `registerLegacyRequest` only where the array cannot say it: a class registered with `register` and a serializer of its own, or an old request carrying a different `name`.
234
234
6. A path in a config or generator outside `lib/` — the input list in `tooling/generate-runtime-code.js`, an `ignores` entry in `eslint.config.mjs`. Both silently stop matching; the second fails as style errors in a file nobody edited.
235
235
236
236
`yarn fix:special` leaving `types.d.ts` byte-identical confirms 3 and 4; `ConfigCacheTestCases` reporting no `Pack got invalid` line confirms 5; nothing static catches 1 — only building `lib/index.js` does.
@@ -247,7 +247,7 @@ This applies equally to moves **between** `lib/` directories, where 6 is what ha
247
247
248
248
A hint reuses existing reporting: `SizeLimitsPlugin` and `DuplicatePackagesPlugin` both end in `hints === "error" ? compilation.errors : compilation.warnings`; hardcoding one list makes a hint impossible to escalate. Prefer an option saying _whether_ to run the check and leave severity to `performance.hints`.
249
249
250
-
**`makeSerializable` follows from where a diagnostic is created.** Anything reachable from a module (`ModuleError`, `ModuleWarning`, `ModuleBuildError`) is serialized with the module graph and must register. One built after seal and pushed onto `compilation.warnings` never enters the pack (why nothing in `lib/performance/` registers). A wrong guess is silent except for `Pack got invalid because of write to:` under `ConfigCacheTestCases`, so cover a new diagnostic there.
250
+
**`makeSerializable` follows from where a diagnostic is created.** Anything reachable from a module (`ModuleError`, `ModuleWarning`, `ModuleBuildError`) is serialized with the module graph and must register. One built after seal and pushed onto `compilation.warnings` never enters the pack, which is why the size-limit and duplicate-package warnings register nothing. A wrong guess is silent except for `Pack got invalid because of write to:` under `ConfigCacheTestCases`, so cover a new diagnostic there.
0 commit comments