Skip to content

Commit eae04f6

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

33 files changed

Lines changed: 299 additions & 221 deletions

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This is the canonical repository map. **When you add, rename or remove a top-lev
7171
- `lib/dll/` — DllPlugin / DllReferencePlugin, and the two dependencies they own, `DllEntryDependency` and `DelegatedSourceDependency`.
7272
- `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.
7373
- `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.
7575
- `lib/esm/` — ESM-specific output (e.g. `import.meta`).
7676
- `lib/externals/` — the `externals` option's module, factory plugin and presets.
7777
- `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).
@@ -244,7 +244,7 @@ This applies equally to moves **between** `lib/` directories, where 6 is what ha
244244

245245
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`.
246246

247-
**`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.
247+
**`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.
248248

249249
## Code conventions
250250

‎lib/dependencies/commonjs/RequireIncludeDependencyParserPlugin.js‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
"use strict";
77

8-
const WebpackError = require("../../errors/WebpackError");
8+
const RequireIncludeDeprecationWarning = require("../../errors/RequireIncludeDeprecationWarning");
99
const {
1010
evaluateToString,
1111
toConstantDependency
1212
} = require("../../javascript/JavascriptParserHelpers");
13-
const makeSerializable = require("../../util/makeSerializable");
14-
const { registerLegacyRequest } = require("../../util/serialization");
1513
const RequireIncludeDependency = require("./RequireIncludeDependency");
1614

17-
/** @import { DependencyLocation } from "../../graph/Dependency" */
1815
/** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */
1916

2017
const PLUGIN_NAME = "RequireIncludeDependencyParserPlugin";
@@ -75,30 +72,3 @@ module.exports = class RequireIncludeDependencyParserPlugin {
7572
});
7673
}
7774
};
78-
79-
class RequireIncludeDeprecationWarning extends WebpackError {
80-
/**
81-
* Creates an instance of RequireIncludeDeprecationWarning.
82-
* @param {DependencyLocation} loc location
83-
*/
84-
constructor(loc) {
85-
super("require.include() is deprecated and will be removed soon.");
86-
87-
/** @type {string} */
88-
this.name = "RequireIncludeDeprecationWarning";
89-
90-
/** @type {DependencyLocation} */
91-
this.loc = loc;
92-
}
93-
}
94-
95-
makeSerializable(
96-
RequireIncludeDeprecationWarning,
97-
"webpack/lib/dependencies/commonjs/RequireIncludeDependencyParserPlugin",
98-
"RequireIncludeDeprecationWarning"
99-
);
100-
registerLegacyRequest(
101-
RequireIncludeDeprecationWarning,
102-
"webpack/lib/dependencies/RequireIncludeDependencyParserPlugin",
103-
"RequireIncludeDeprecationWarning"
104-
);

‎lib/dependencies/esm/ESMExportImportedSpecifierDependency.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"use strict";
77

8+
const ESMLinkingError = require("../../errors/ESMLinkingError");
89
const Dependency = require("../../graph/Dependency");
910
const { UsageState } = require("../../graph/ExportsInfo");
1011
const {
@@ -35,7 +36,6 @@ const { ImportPhaseUtils } = require("../core/ImportPhase");
3536
const processExportInfo = require("../helpers/processExportInfo");
3637
const ESMExportInitFragment = require("./ESMExportInitFragment");
3738
const ESMImportDependency = require("./ESMImportDependency");
38-
const ESMLinkingError = require("./ESMLinkingError");
3939

4040
const { ExportBindingType } = ESMExportInitFragment;
4141

‎lib/dependencies/esm/ESMImportDependency.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
const AwaitDependenciesInitFragment = require("../../async-modules/AwaitDependenciesInitFragment");
99
const isGeneratorLowered = require("../../async-modules/isGeneratorLowered");
10+
const ESMLinkingError = require("../../errors/ESMLinkingError");
1011
const Dependency = require("../../graph/Dependency");
1112
const ConditionalInitFragment = require("../../template/ConditionalInitFragment");
1213
const InitFragment = require("../../template/InitFragment");
@@ -15,7 +16,6 @@ const memoize = require("../../util/memoize");
1516
const { filterRuntime, mergeRuntime } = require("../../util/runtime");
1617
const { ImportPhase, ImportPhaseUtils } = require("../core/ImportPhase");
1718
const ModuleDependency = require("../core/ModuleDependency");
18-
const ESMLinkingError = require("./ESMLinkingError");
1919

2020
const getExternalModule = memoize(() =>
2121
require("../../externals/ExternalModule")

‎lib/dependencies/system/SystemPlugin.js‎

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"use strict";
77

8-
const WebpackError = require("../../errors/WebpackError");
8+
const SystemImportDeprecationWarning = require("../../errors/SystemImportDeprecationWarning");
99
const {
1010
evaluateToString,
1111
expressionIsUnsupported,
@@ -16,8 +16,6 @@ const {
1616
JAVASCRIPT_MODULE_TYPE_DYNAMIC
1717
} = require("../../module/ModuleTypeConstants");
1818
const RuntimeGlobals = require("../../runtime/RuntimeGlobals");
19-
const makeSerializable = require("../../util/makeSerializable");
20-
const { registerLegacyRequest } = require("../../util/serialization");
2119
const ConstDependency = require("../core/ConstDependency");
2220
const SystemRuntimeModule = require("./SystemRuntimeModule");
2321

@@ -27,7 +25,6 @@ const SystemRuntimeModule = require("./SystemRuntimeModule");
2725
* } from "../../../declarations/WebpackOptions"
2826
*/
2927
/** @import Compiler from "../../Compiler" */
30-
/** @import { DependencyLocation } from "../../graph/Dependency" */
3128
/** @import Parser, { Range } from "../../javascript/JavascriptParser" */
3229

3330
const PLUGIN_NAME = "SystemPlugin";
@@ -146,36 +143,6 @@ class SystemPlugin {
146143
}
147144
}
148145

149-
class SystemImportDeprecationWarning extends WebpackError {
150-
/**
151-
* Creates an instance of SystemImportDeprecationWarning.
152-
* @param {DependencyLocation} loc location
153-
*/
154-
constructor(loc) {
155-
super(
156-
"System.import() is deprecated and will be removed soon. Use import() instead.\n" +
157-
"For more info visit https://webpack.js.org/guides/code-splitting/"
158-
);
159-
160-
/** @type {string} */
161-
this.name = "SystemImportDeprecationWarning";
162-
163-
/** @type {DependencyLocation} */
164-
this.loc = loc;
165-
}
166-
}
167-
168-
makeSerializable(
169-
SystemImportDeprecationWarning,
170-
"webpack/lib/dependencies/system/SystemPlugin",
171-
"SystemImportDeprecationWarning"
172-
);
173-
registerLegacyRequest(
174-
SystemImportDeprecationWarning,
175-
"webpack/lib/dependencies/SystemPlugin",
176-
"SystemImportDeprecationWarning"
177-
);
178-
179146
SystemPlugin.SystemImportDeprecationWarning = SystemImportDeprecationWarning;
180147

181148
module.exports = SystemPlugin;

‎lib/dependencies/wasm/WebAssemblyImportDependency.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
"use strict";
77

8+
const UnsupportedWebAssemblyFeatureError = require("../../errors/UnsupportedWebAssemblyFeatureError");
89
const makeSerializable = require("../../util/makeSerializable");
910
const { registerLegacyRequest } = require("../../util/serialization");
10-
const UnsupportedWebAssemblyFeatureError = require("../../wasm-sync/UnsupportedWebAssemblyFeatureError");
1111
const ModuleDependency = require("../core/ModuleDependency");
1212

1313
/** @import { ModuleImportDescription } from "@webassemblyjs/ast" */

‎lib/diagnostics/WarnCaseSensitiveModulesPlugin.js‎

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,9 @@
77

88
/** @import Compiler from "../Compiler" */
99
/** @import Module from "../module/Module" */
10-
/** @import ModuleGraph from "../graph/ModuleGraph" */
1110
/** @import NormalModule from "../module/NormalModule" */
1211

13-
const WebpackError = require("../errors/WebpackError");
14-
15-
/**
16-
* Sorts the conflicting modules by identifier to keep warning output stable.
17-
* @param {Module[]} modules the modules to be sorted
18-
* @returns {Module[]} sorted version of original modules
19-
*/
20-
const sortModules = (modules) =>
21-
modules.sort((a, b) => {
22-
const aIdent = a.identifier();
23-
const bIdent = b.identifier();
24-
/* istanbul ignore next */
25-
if (aIdent < bIdent) return -1;
26-
/* istanbul ignore next */
27-
if (aIdent > bIdent) return 1;
28-
/* istanbul ignore next */
29-
return 0;
30-
});
31-
32-
/**
33-
* Formats the conflicting modules and one representative incoming reason for
34-
* each module into the warning body.
35-
* @param {Module[]} modules each module from throw
36-
* @param {ModuleGraph} moduleGraph the module graph
37-
* @returns {string} each message from provided modules
38-
*/
39-
const createModulesListMessage = (modules, moduleGraph) =>
40-
modules
41-
.map((m) => {
42-
let message = `* ${m.identifier()}`;
43-
const validReasons = [
44-
...moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
45-
].filter(Boolean);
46-
47-
if (validReasons.length > 0) {
48-
message += `\n Used by ${validReasons.length} module(s), i. e.`;
49-
message += `\n ${
50-
/** @type {Module[]} */ (validReasons)[0].identifier()
51-
}`;
52-
}
53-
return message;
54-
})
55-
.join("\n");
56-
57-
/**
58-
* Warning emitted when webpack finds modules whose identifiers differ only by
59-
* letter casing, which can behave inconsistently across filesystems.
60-
*/
61-
class CaseSensitiveModulesWarning extends WebpackError {
62-
/**
63-
* Builds a warning message that lists the case-conflicting modules and
64-
* representative importers that caused them to be included.
65-
* @param {Iterable<Module>} modules modules that were detected
66-
* @param {ModuleGraph} moduleGraph the module graph
67-
*/
68-
constructor(modules, moduleGraph) {
69-
const sortedModules = sortModules([...modules]);
70-
const modulesList = createModulesListMessage(sortedModules, moduleGraph);
71-
super(`There are multiple modules with names that only differ in casing.
72-
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
73-
Use equal casing. Compare these module identifiers:
74-
${modulesList}`);
75-
76-
/** @type {string} */
77-
this.name = "CaseSensitiveModulesWarning";
78-
/** @type {Module} */
79-
this.module = sortedModules[0];
80-
}
81-
}
12+
const CaseSensitiveModulesWarning = require("../errors/CaseSensitiveModulesWarning");
8213

8314
const PLUGIN_NAME = "WarnCaseSensitiveModulesPlugin";
8415

‎lib/diagnostics/WarnDeprecatedOptionPlugin.js‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"use strict";
77

8-
const WebpackError = require("../errors/WebpackError");
8+
const DeprecatedOptionWarning = require("../errors/DeprecatedOptionWarning");
99

1010
/** @import Compiler from "../Compiler" */
1111

@@ -41,24 +41,4 @@ class WarnDeprecatedOptionPlugin {
4141
}
4242
}
4343

44-
class DeprecatedOptionWarning extends WebpackError {
45-
/**
46-
* Create an instance deprecated option warning
47-
* @param {string} option the target option
48-
* @param {string | number} value the deprecated option value
49-
* @param {string} suggestion the suggestion replacement
50-
*/
51-
constructor(option, value, suggestion) {
52-
super();
53-
54-
/** @type {string} */
55-
this.name = "DeprecatedOptionWarning";
56-
/** @type {string} */
57-
this.message =
58-
"configuration\n" +
59-
`The value '${value}' for option '${option}' is deprecated. ` +
60-
`Use '${suggestion}' instead.`;
61-
}
62-
}
63-
6444
module.exports = WarnDeprecatedOptionPlugin;

‎lib/diagnostics/WarnNoModeSetPlugin.js‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,7 @@
55

66
"use strict";
77

8-
const WebpackError = require("../errors/WebpackError");
9-
10-
class NoModeWarning extends WebpackError {
11-
constructor() {
12-
super();
13-
14-
/** @type {string} */
15-
this.name = "NoModeWarning";
16-
/** @type {string} */
17-
this.message =
18-
"configuration\n" +
19-
"The 'mode' option has not been set, webpack will fallback to 'production' for this value.\n" +
20-
"Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\n" +
21-
"You can also set it to 'none' to disable any default behavior. " +
22-
"Learn more: https://webpack.js.org/configuration/mode/";
23-
}
24-
}
8+
const NoModeWarning = require("../errors/NoModeWarning");
259

2610
/** @import Compiler from "../Compiler" */
2711

‎lib/dll/DllReferencePlugin.js‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"use strict";
77

8-
const WebpackError = require("../errors/WebpackError");
8+
const DllManifestError = require("../errors/DllManifestError");
99
const ExternalModuleFactoryPlugin = require("../externals/ExternalModuleFactoryPlugin");
1010
const { fileUrlToPath, makePathsRelative } = require("../util/identifier");
1111
const parseJson = require("../util/parseJson");
@@ -186,20 +186,4 @@ class DllReferencePlugin {
186186
}
187187
}
188188

189-
class DllManifestError extends WebpackError {
190-
/**
191-
* Creates an instance of DllManifestError.
192-
* @param {string} filename filename of the manifest
193-
* @param {string} message error message
194-
*/
195-
constructor(filename, message) {
196-
super();
197-
198-
/** @type {string} */
199-
this.name = "DllManifestError";
200-
/** @type {string} */
201-
this.message = `Dll manifest ${filename}\n${message}`;
202-
}
203-
}
204-
205189
module.exports = DllReferencePlugin;

0 commit comments

Comments
 (0)