Skip to content

Commit 865c00b

Browse files
chore: fix package types with webpack (#2882)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent b90fa7d commit 865c00b

File tree

17 files changed

+453
-2066
lines changed

17 files changed

+453
-2066
lines changed

packages/enhanced/src/lib/container/ContainerEntryModule.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class ContainerEntryModule extends Module {
119119
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
120120
* @returns {void}
121121
*/
122-
// @ts-expect-error typeof webpack/lib !== typeof webpack/types
123122
override needBuild(
124123
context: NeedBuildContext,
125124
callback: (
@@ -138,7 +137,6 @@ class ContainerEntryModule extends Module {
138137
* @param {function(WebpackError): void} callback callback function
139138
* @returns {void}
140139
*/
141-
// @ts-expect-error typeof webpack/lib !== typeof webpack/types
142140
override build(
143141
options: WebpackOptions,
144142
compilation: Compilation,
@@ -180,10 +178,7 @@ class ContainerEntryModule extends Module {
180178
) as unknown as Dependency,
181179
);
182180

183-
this.addDependency(
184-
// @ts-expect-error flaky type for EntryDependency
185-
new EntryDependency(this._injectRuntimeEntry),
186-
);
181+
this.addDependency(new EntryDependency(this._injectRuntimeEntry));
187182

188183
callback();
189184
}

packages/enhanced/src/lib/container/ContainerEntryModuleFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export default class ContainerEntryModuleFactory extends ModuleFactory {
3333
const dep = containerDependencies[0];
3434

3535
callback(null, {
36-
// @ts-expect-error missing some deps
3736
module: new ContainerEntryModule(
3837
dep.name,
3938
dep.exposes,

packages/enhanced/src/lib/container/ContainerPlugin.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import ContainerEntryDependency from './ContainerEntryDependency';
77
import ContainerEntryModuleFactory from './ContainerEntryModuleFactory';
88
import ContainerExposedDependency from './ContainerExposedDependency';
99
import { parseOptions } from './options';
10-
import type { optimize, Compiler, Compilation } from 'webpack';
10+
import type {
11+
optimize,
12+
Compiler,
13+
Compilation,
14+
WebpackError,
15+
WebpackPluginInstance,
16+
} from 'webpack';
1117
import type { containerPlugin } from '@module-federation/sdk';
1218
import FederationRuntimePlugin from './runtime/FederationRuntimePlugin';
1319
import checkOptions from '../../schemas/container/ContainerPlugin.check';
@@ -148,13 +154,15 @@ class ContainerPlugin {
148154
}
149155

150156
apply(compiler: Compiler): void {
151-
const useModuleFederationPlugin = compiler.options.plugins.find((p) => {
152-
if (typeof p !== 'object' || !p) {
153-
return false;
154-
}
157+
const useModuleFederationPlugin = compiler.options.plugins.find(
158+
(p: WebpackPluginInstance) => {
159+
if (typeof p !== 'object' || !p) {
160+
return false;
161+
}
155162

156-
return p['name'] === 'ModuleFederationPlugin';
157-
});
163+
return p['name'] === 'ModuleFederationPlugin';
164+
},
165+
);
158166

159167
if (!useModuleFederationPlugin) {
160168
ContainerPlugin.patchChunkSplit(compiler, this._options.name);

packages/enhanced/src/lib/container/FallbackModule.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class FallbackModule extends Module {
9292
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
9393
* @returns {void}
9494
*/
95-
// @ts-expect-error incompatible context types
9695
override needBuild(
9796
context: NeedBuildContext,
9897
callback: (error: WebpackError | null, result?: boolean) => void,
@@ -108,7 +107,6 @@ class FallbackModule extends Module {
108107
* @param {function(WebpackError=): void} callback callback function
109108
* @returns {void}
110109
*/
111-
// @ts-expect-error incompatible option types
112110
override build(
113111
options: WebpackOptions,
114112
compilation: Compilation,
@@ -147,7 +145,6 @@ class FallbackModule extends Module {
147145
* @param {CodeGenerationContext} context context for code generation
148146
* @returns {CodeGenerationResult} result
149147
*/
150-
// @ts-expect-error incompatible CodeGenerationContext
151148
override codeGeneration({
152149
runtimeTemplate,
153150
moduleGraph,

packages/enhanced/src/lib/container/ModuleFederationPlugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ContainerPlugin from './ContainerPlugin';
1919
import ContainerReferencePlugin from './ContainerReferencePlugin';
2020
import FederationRuntimePlugin from './runtime/FederationRuntimePlugin';
2121
import { RemoteEntryPlugin } from './runtime/RemoteEntryPlugin';
22+
import { ExternalsType } from 'webpack/declarations/WebpackOptions';
2223

2324
const isValidExternalsType = require(
2425
normalizeWebpackPath(
@@ -53,7 +54,7 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
5354
private _patchBundlerConfig(compiler: Compiler): void {
5455
const { name } = this._options;
5556
const MFPluginNum = compiler.options.plugins.filter(
56-
(p) => p && p.name === 'ModuleFederationPlugin',
57+
(p: WebpackPluginInstance) => p && p['name'] === 'ModuleFederationPlugin',
5758
).length;
5859
if (name && MFPluginNum < 2) {
5960
new compiler.webpack.DefinePlugin({
@@ -85,8 +86,8 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
8586
const remoteType =
8687
options.remoteType ||
8788
(options.library && isValidExternalsType(options.library.type)
88-
? options.library.type
89-
: 'script');
89+
? (options.library.type as ExternalsType)
90+
: ('script' as ExternalsType));
9091

9192
const useContainerPlugin =
9293
options.exposes &&
@@ -138,7 +139,6 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
138139
: Object.keys(options.remotes).length > 0)
139140
) {
140141
new ContainerReferencePlugin({
141-
// @ts-expect-error this should not be a string
142142
remoteType,
143143
shareScope: options.shareScope,
144144
remotes: options.remotes,

packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Compiler } from 'webpack';
1+
import type { Compiler, WebpackPluginInstance } from 'webpack';
22
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
33
import FederationRuntimeModule from './FederationRuntimeModule';
44
import {
@@ -244,25 +244,29 @@ class FederationRuntimePlugin {
244244
}
245245

246246
apply(compiler: Compiler) {
247-
const useModuleFederationPlugin = compiler.options.plugins.find((p) => {
248-
if (typeof p !== 'object' || !p) {
249-
return false;
250-
}
251-
return p['name'] === 'ModuleFederationPlugin';
252-
});
247+
const useModuleFederationPlugin = compiler.options.plugins.find(
248+
(p: WebpackPluginInstance) => {
249+
if (typeof p !== 'object' || !p) {
250+
return false;
251+
}
252+
return p['name'] === 'ModuleFederationPlugin';
253+
},
254+
);
253255

254256
if (useModuleFederationPlugin && !this.options) {
255257
// @ts-ignore
256258
this.options = useModuleFederationPlugin._options;
257259
}
258260

259-
const useContainerPlugin = compiler.options.plugins.find((p) => {
260-
if (typeof p !== 'object' || !p) {
261-
return false;
262-
}
261+
const useContainerPlugin = compiler.options.plugins.find(
262+
(p: WebpackPluginInstance) => {
263+
if (typeof p !== 'object' || !p) {
264+
return false;
265+
}
263266

264-
return p['name'] === 'ContainerPlugin';
265-
});
267+
return p['name'] === 'ContainerPlugin';
268+
},
269+
);
266270

267271
if (useContainerPlugin && !this.options) {
268272
// @ts-ignore

packages/enhanced/src/wrapper/ModuleFederationPlugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export default class ModuleFederationPlugin implements WebpackPluginInstance {
2121
}
2222

2323
apply(compiler: Compiler) {
24-
if (!compiler.options.plugins.find((p) => p && p.name === PLUGIN_NAME)) {
24+
if (
25+
!compiler.options.plugins.find(
26+
(p: WebpackPluginInstance) => p && p['name'] === PLUGIN_NAME,
27+
)
28+
) {
2529
compiler.options.plugins.push(this);
2630
}
2731
process.env['FEDERATION_WEBPACK_PATH'] =

packages/nextjs-mf/src/plugins/NextFederationPlugin/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
NextFederationPluginExtraOptions,
1010
NextFederationPluginOptions,
1111
} from '@module-federation/utilities';
12-
import type { Compiler } from 'webpack';
12+
import type { Compiler, WebpackPluginInstance } from 'webpack';
1313
import { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
1414
import CopyFederationPlugin from '../CopyFederationPlugin';
1515
import { exposeNextjsPages } from '../../loaders/nextPageMapLoader';
@@ -88,7 +88,8 @@ export class NextFederationPlugin {
8888

8989
private validateOptions(compiler: Compiler): boolean {
9090
const manifestPlugin = compiler.options.plugins.find(
91-
(p) => p?.constructor.name === 'BuildManifestPlugin',
91+
(p: WebpackPluginInstance) =>
92+
p?.constructor.name === 'BuildManifestPlugin',
9293
);
9394

9495
if (manifestPlugin) {

packages/typescript/src/plugins/FederatedTypesPlugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import axios from 'axios';
4-
import { Compiler } from 'webpack';
4+
import { Compiler, WebpackPluginInstance } from 'webpack';
55
import { startServer, stopServer } from '../lib/server';
66
import { TypescriptCompiler } from '../lib/TypescriptCompiler';
77
import {
@@ -40,7 +40,8 @@ export class FederatedTypesPlugin {
4040

4141
if (
4242
!compiler.options.plugins.some(
43-
(p) => SUPPORTED_PLUGINS.indexOf(p?.constructor.name ?? '') !== -1,
43+
(p: WebpackPluginInstance) =>
44+
SUPPORTED_PLUGINS.indexOf(p?.constructor.name ?? '') !== -1,
4445
)
4546
) {
4647
this.logger.error(

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)