Skip to content

Commit f0b3540

Browse files
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.
1 parent eae04f6 commit f0b3540

107 files changed

Lines changed: 491 additions & 837 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.

‎.changeset/007-export-module-type-and-target-plugins.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": minor
33
---
44

5-
Export more plugins under their scope, move eleven loose exports under theirs, deprecate the old, and expose `template.DependencyTemplate`, `module.NullFactory` and `util.makeSerializable`.
5+
Export more plugins under their scope, move eleven loose exports under theirs, deprecate the old, and expose `template.DependencyTemplate`, `module.NullFactory` and `util.makeSerializable`, which now accepts several requests, current one first.

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This is the canonical repository map. **When you add, rename or remove a top-lev
6565
- `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`.
6666
- `lib/debug/` — debug helpers.
6767
- `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.
6969
- `lib/devtool/` — source maps: the `devtool` plugins and their filename helpers.
7070
- `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/`.
7171
- `lib/dll/` — DllPlugin / DllReferencePlugin, and the two dependencies they own, `DllEntryDependency` and `DelegatedSourceDependency`.
@@ -227,7 +227,7 @@ They are documentation only (stripped from precompiled validators). A pure `$ref
227227
2. `@import … from "…"` in JSDoc.
228228
3. `@typedef {import("…")}` — a different form; missing it silently drops the type from the public surface.
229229
4. `tsType` in `schemas/**/*.json` — fails loudly in `fix:special` or silently degrades a public type to `any`.
230-
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.
230+
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`.
231231
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.
232232

233233
`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.

‎lib/asset/RawDataUrlModule.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const {
1616
} = require("../module/ModuleTypeConstants");
1717
const RuntimeGlobals = require("../runtime/RuntimeGlobals");
1818
const makeSerializable = require("../util/makeSerializable");
19-
const { registerLegacyRequest } = require("../util/serialization");
2019

2120
/**
2221
* @import {
@@ -195,10 +194,11 @@ class RawDataUrlModule extends Module {
195194
}
196195
}
197196

198-
makeSerializable(RawDataUrlModule, "webpack/lib/asset/RawDataUrlModule");
199-
200-
// TODO in the next major release: remove
201-
// Restores caches written before moved into lib/asset/
202-
registerLegacyRequest(RawDataUrlModule, "webpack/lib/RawDataUrlModule");
197+
makeSerializable(RawDataUrlModule, [
198+
"webpack/lib/asset/RawDataUrlModule",
199+
// TODO in the next major release: remove, it restores caches written
200+
// before this moved into lib/asset/
201+
"webpack/lib/RawDataUrlModule"
202+
]);
203203

204204
module.exports = RawDataUrlModule;

‎lib/context/ContextModule.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const {
4040
} = require("../util/identifier");
4141
const makeSerializable = require("../util/makeSerializable");
4242
const { propertyAccess } = require("../util/property");
43-
const { registerLegacyRequest } = require("../util/serialization");
4443

4544
/** @import { Source } from "webpack-sources" */
4645
/** @import { ResolveOptions } from "../../declarations/WebpackOptions" */
@@ -1730,10 +1729,11 @@ module.exports = webpackEmptyAsyncContext;`;
17301729
}
17311730
}
17321731

1733-
makeSerializable(ContextModule, "webpack/lib/context/ContextModule");
1734-
1735-
// TODO in the next major release: remove
1736-
// Restores caches written before this moved into lib/context/
1737-
registerLegacyRequest(ContextModule, "webpack/lib/ContextModule");
1732+
makeSerializable(ContextModule, [
1733+
"webpack/lib/context/ContextModule",
1734+
// TODO in the next major release: remove, it restores caches written
1735+
// before this moved into lib/context/
1736+
"webpack/lib/ContextModule"
1737+
]);
17381738

17391739
module.exports = ContextModule;

‎lib/dependencies/amd/AMDDefineDependency.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
const RuntimeGlobals = require("../../runtime/RuntimeGlobals");
99
const makeSerializable = require("../../util/makeSerializable");
10-
const { registerLegacyRequest } = require("../../util/serialization");
1110
const NullDependency = require("../core/NullDependency");
1211

1312
/** @import { ReplaceSource } from "webpack-sources" */
@@ -189,14 +188,11 @@ class AMDDefineDependency extends NullDependency {
189188
}
190189
}
191190

192-
makeSerializable(
193-
AMDDefineDependency,
194-
"webpack/lib/dependencies/amd/AMDDefineDependency"
195-
);
196-
registerLegacyRequest(
197-
AMDDefineDependency,
191+
makeSerializable(AMDDefineDependency, [
192+
"webpack/lib/dependencies/amd/AMDDefineDependency",
193+
// TODO in the next major release: remove, they restore pre-move cache packs
198194
"webpack/lib/dependencies/AMDDefineDependency"
199-
);
195+
]);
200196

201197
AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
202198
NullDependency.Template

‎lib/dependencies/amd/AMDRequireArrayDependency.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
const DependencyTemplate = require("../../template/DependencyTemplate");
99
const makeSerializable = require("../../util/makeSerializable");
10-
const { registerLegacyRequest } = require("../../util/serialization");
1110
const NullDependency = require("../core/NullDependency");
1211
const LocalModuleDependency = require("./LocalModuleDependency");
1312

@@ -63,14 +62,11 @@ class AMDRequireArrayDependency extends NullDependency {
6362
}
6463
}
6564

66-
makeSerializable(
67-
AMDRequireArrayDependency,
68-
"webpack/lib/dependencies/amd/AMDRequireArrayDependency"
69-
);
70-
registerLegacyRequest(
71-
AMDRequireArrayDependency,
65+
makeSerializable(AMDRequireArrayDependency, [
66+
"webpack/lib/dependencies/amd/AMDRequireArrayDependency",
67+
// TODO in the next major release: remove, they restore pre-move cache packs
7268
"webpack/lib/dependencies/AMDRequireArrayDependency"
73-
);
69+
]);
7470

7571
AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate extends (
7672
DependencyTemplate

‎lib/dependencies/amd/AMDRequireContextDependency.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"use strict";
77

88
const makeSerializable = require("../../util/makeSerializable");
9-
const { registerLegacyRequest } = require("../../util/serialization");
109
const ContextDependency = require("../context/ContextDependency");
1110

1211
/** @import { Range } from "../../javascript/JavascriptParser" */
@@ -59,14 +58,11 @@ class AMDRequireContextDependency extends ContextDependency {
5958
}
6059
}
6160

62-
makeSerializable(
63-
AMDRequireContextDependency,
64-
"webpack/lib/dependencies/amd/AMDRequireContextDependency"
65-
);
66-
registerLegacyRequest(
67-
AMDRequireContextDependency,
61+
makeSerializable(AMDRequireContextDependency, [
62+
"webpack/lib/dependencies/amd/AMDRequireContextDependency",
63+
// TODO in the next major release: remove, they restore pre-move cache packs
6864
"webpack/lib/dependencies/AMDRequireContextDependency"
69-
);
65+
]);
7066

7167
AMDRequireContextDependency.Template = require("../context/ContextDependencyTemplateAsRequireCall");
7268

‎lib/dependencies/amd/AMDRequireDependenciesBlock.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
const AsyncDependenciesBlock = require("../../graph/AsyncDependenciesBlock");
99
const makeSerializable = require("../../util/makeSerializable");
10-
const { registerLegacyRequest } = require("../../util/serialization");
1110

1211
/** @import { DependencyLocation } from "../../graph/Dependency" */
1312

@@ -22,13 +21,10 @@ class AMDRequireDependenciesBlock extends AsyncDependenciesBlock {
2221
}
2322
}
2423

25-
makeSerializable(
26-
AMDRequireDependenciesBlock,
27-
"webpack/lib/dependencies/amd/AMDRequireDependenciesBlock"
28-
);
29-
registerLegacyRequest(
30-
AMDRequireDependenciesBlock,
24+
makeSerializable(AMDRequireDependenciesBlock, [
25+
"webpack/lib/dependencies/amd/AMDRequireDependenciesBlock",
26+
// TODO in the next major release: remove, they restore pre-move cache packs
3127
"webpack/lib/dependencies/AMDRequireDependenciesBlock"
32-
);
28+
]);
3329

3430
module.exports = AMDRequireDependenciesBlock;

‎lib/dependencies/amd/AMDRequireDependency.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
const RuntimeGlobals = require("../../runtime/RuntimeGlobals");
99
const makeSerializable = require("../../util/makeSerializable");
10-
const { registerLegacyRequest } = require("../../util/serialization");
1110
const NullDependency = require("../core/NullDependency");
1211

1312
/** @import { ReplaceSource } from "webpack-sources" */
@@ -80,14 +79,11 @@ class AMDRequireDependency extends NullDependency {
8079
}
8180
}
8281

83-
makeSerializable(
84-
AMDRequireDependency,
85-
"webpack/lib/dependencies/amd/AMDRequireDependency"
86-
);
87-
registerLegacyRequest(
88-
AMDRequireDependency,
82+
makeSerializable(AMDRequireDependency, [
83+
"webpack/lib/dependencies/amd/AMDRequireDependency",
84+
// TODO in the next major release: remove, they restore pre-move cache packs
8985
"webpack/lib/dependencies/AMDRequireDependency"
90-
);
86+
]);
9187

9288
AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
9389
NullDependency.Template

‎lib/dependencies/amd/AMDRequireItemDependency.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"use strict";
77

88
const makeSerializable = require("../../util/makeSerializable");
9-
const { registerLegacyRequest } = require("../../util/serialization");
109
const ModuleDependency = require("../core/ModuleDependency");
1110
const ModuleDependencyTemplateAsRequireId = require("../core/ModuleDependencyTemplateAsRequireId");
1211

@@ -33,14 +32,11 @@ class AMDRequireItemDependency extends ModuleDependency {
3332
}
3433
}
3534

36-
makeSerializable(
37-
AMDRequireItemDependency,
38-
"webpack/lib/dependencies/amd/AMDRequireItemDependency"
39-
);
40-
registerLegacyRequest(
41-
AMDRequireItemDependency,
35+
makeSerializable(AMDRequireItemDependency, [
36+
"webpack/lib/dependencies/amd/AMDRequireItemDependency",
37+
// TODO in the next major release: remove, they restore pre-move cache packs
4238
"webpack/lib/dependencies/AMDRequireItemDependency"
43-
);
39+
]);
4440

4541
AMDRequireItemDependency.Template = ModuleDependencyTemplateAsRequireId;
4642

0 commit comments

Comments
 (0)