Skip to content

Commit 1f0ab08

Browse files
refactor: fix some types
1 parent 655fe2a commit 1f0ab08

21 files changed

+216
-67
lines changed

.changeset/huge-paws-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Fix some types.

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ updates:
2828
groups:
2929
dependencies:
3030
patterns:
31+
- "*"
3132
- package-ecosystem: "gitsubmodule"
3233
directory: "/"
3334
schedule:
@@ -38,3 +39,4 @@ updates:
3839
groups:
3940
dependencies:
4041
patterns:
42+
- "*"

examples/build-common.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,31 @@ const tc = require("./template-common");
1212

1313
const extraArgs = "";
1414

15-
// @ts-expect-error we are touching global
16-
const targetArgs = global.NO_TARGET_ARGS
15+
/**
16+
* @typedef {object} GlobalObj
17+
* @property {boolean=} NO_TARGET_ARGS no target args flag
18+
* @property {boolean=} NO_REASONS no stats reasons flag
19+
* @property {boolean=} NO_STATS_OPTIONS no stats options flag
20+
* @property {boolean=} NO_PUBLIC_PATH no public path flag
21+
* @property {boolean=} STATS_COLORS no stats color flag
22+
*/
23+
24+
const globalObj = /** @type {typeof globalThis & GlobalObj} */ (global);
25+
26+
const targetArgs = globalObj
1727
? ""
1828
: "--entry ./example.js --output-filename output.js";
19-
// @ts-expect-error we are touching global
20-
const displayReasons = global.NO_REASONS
29+
const displayReasons = globalObj
2130
? ""
2231
: "--stats-reasons --stats-used-exports --stats-provided-exports";
23-
// @ts-expect-error we are touching global
24-
const statsArgs = global.NO_STATS_OPTIONS
32+
const statsArgs = globalObj
2533
? ""
2634
: "--stats-chunks --stats-modules-space 99999 --stats-chunk-origins";
27-
// @ts-expect-error we are touching global
28-
const publicPathArgs = global.NO_PUBLIC_PATH
35+
const publicPathArgs = globalObj.NO_PUBLIC_PATH
2936
? ""
3037
: '--output-public-path "dist/"';
31-
// @ts-expect-error we are touching global
32-
const statsColorsArg = global.STATS_COLORS ? "" : "--no-color";
38+
const statsColorsArg = globalObj.STATS_COLORS ? "" : "--no-color";
39+
3340
const commonArgs = `${statsColorsArg} ${statsArgs} ${publicPathArgs} ${extraArgs} ${targetArgs}`;
3441

3542
let readme = fs.readFileSync(

examples/examples.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function findInFolder(folder, depth) {
1313
return [folder];
1414
} else if (depth > 0) {
1515
const files = fs.readdirSync(folder);
16+
/** @type {string[]} */
1617
const results = [];
1718
for (const file of files) {
1819
const innerPath = path.join(folder, file);

examples/template-common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ const replaceBase = (template) => {
7171
.replace(/\.chunkhash\./g, ".[chunkhash].")
7272
.replace(
7373
runtimeModulesRegexp,
74+
/**
75+
* @param {string} match match
76+
* @param {string} content content
77+
* @returns {string} new content
78+
*/
7479
(match, content) =>
7580
"```\n\n<details><summary>" +
7681
"<code>/* webpack runtime code */</code>" +

lib/CleanPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ class CleanPlugin {
369369
/** @param {CleanOptions} options options */
370370
constructor(options = {}) {
371371
validate(options);
372+
/** @type {CleanOptions & { dry: boolean }} */
372373
this.options = { dry: false, ...options };
373374
}
374375

lib/ContextModule.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const makeSerializable = require("./util/makeSerializable");
119119

120120
/** @typedef {Record<ModuleId, FakeMapType>} FakeMap */
121121
/** @typedef {Record<string, ModuleId>} UserRequestMap */
122+
/** @typedef {Record<ModuleId, ModuleId[]>} UserRequestsMap */
122123

123124
class ContextModule extends Module {
124125
/**
@@ -711,7 +712,7 @@ class ContextModule extends Module {
711712
/**
712713
* @param {Dependency[]} dependencies all dependencies
713714
* @param {ChunkGraph} chunkGraph chunk graph
714-
* @returns {Map<string, ModuleId[] | undefined>} map with user requests
715+
* @returns {UserRequestsMap} map with user requests
715716
*/
716717
getModuleDeferredAsyncDepsMap(dependencies, chunkGraph) {
717718
const moduleGraph = chunkGraph.moduleGraph;
@@ -726,6 +727,7 @@ class ContextModule extends Module {
726727
)
727728
.filter(Boolean)
728729
.sort(comparator);
730+
/** @type {UserRequestsMap} */
729731
const map = Object.create(null);
730732
for (const module of sortedModules) {
731733
if (!(/** @type {BuildMeta} */ (module.buildMeta).async)) {
@@ -740,7 +742,7 @@ class ContextModule extends Module {
740742
}
741743

742744
/**
743-
* @param {false | Map<string, ModuleId[] | undefined>} asyncDepsMap fake map
745+
* @param {false | UserRequestsMap} asyncDepsMap fake map
744746
* @returns {string} async deps map init statement
745747
*/
746748
getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap) {

lib/EnvironmentNotSupportAsyncWarning.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ As a result, the code may not run as expected or may cause runtime errors.`;
2626

2727
/** @type {string} */
2828
this.name = "EnvironmentNotSupportAsyncWarning";
29+
/** @type {Module} */
2930
this.module = module;
3031
}
3132

lib/EvalDevToolModulePlugin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ class EvalDevToolModulePlugin {
4343
* @param {EvalDevToolModulePluginOptions=} options options
4444
*/
4545
constructor(options = {}) {
46+
/** @type {DevtoolNamespace} */
4647
this.namespace = options.namespace || "";
48+
/** @type {string} */
4749
this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
50+
/** @type {DevtoolModuleFilenameTemplate} */
4851
this.moduleFilenameTemplate =
4952
options.moduleFilenameTemplate ||
5053
"webpack://[namespace]/[resourcePath]?[loaders]";

lib/EvalSourceMapDevToolPlugin.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ const { makePathsAbsolute } = require("./util/identifier");
1717

1818
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
1919
/** @typedef {import("webpack-sources").Source} Source */
20+
/** @typedef {import("../declarations/WebpackOptions").DevtoolNamespace} DevtoolNamespace */
21+
/** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */
2022
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
2123
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
22-
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
2324
/** @typedef {import("./Compiler")} Compiler */
25+
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
26+
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
2427

2528
/** @type {WeakMap<Source, Source>} */
2629
const cache = new WeakMap();
@@ -51,14 +54,18 @@ class EvalSourceMapDevToolPlugin {
5154
} else {
5255
options = inputOptions;
5356
}
57+
/** @type {string} */
5458
this.sourceMapComment =
5559
options.append && typeof options.append !== "function"
5660
? options.append
5761
: "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
62+
/** @type {DevtoolModuleFilenameTemplate} */
5863
this.moduleFilenameTemplate =
5964
options.moduleFilenameTemplate ||
6065
"webpack://[namespace]/[resource-path]?[hash]";
66+
/** @type {DevtoolNamespace} */
6167
this.namespace = options.namespace || "";
68+
/** @type {SourceMapDevToolPluginOptions} */
6269
this.options = options;
6370
}
6471

0 commit comments

Comments
 (0)