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 f0b3540
Browse filesBrowse the repository at this point in the historyBrowse 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.
Copy file name to clipboardExpand all lines: .changeset/007-export-module-type-and-target-plugins.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,4 @@
2
2
"webpack": minor
3
3
---
4
4
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.
Copy file name to clipboardExpand all lines: AGENTS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ 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`.
@@ -227,7 +227,7 @@ They are documentation only (stripped from precompiled validators). A pure `$ref
227
227
2.`@import … from "…"` in JSDoc.
228
228
3.`@typedef {import("…")}` — a different form; missing it silently drops the type from the public surface.
229
229
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`.
231
231
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.
232
232
233
233
`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.
0 commit comments