Skip to content

Commit e6c477b

Browse files
chore: removed ts-ignore on ContainerEntryModule (#2542)
Co-authored-by: Zack Jackson <[email protected]>
1 parent c6c2f93 commit e6c477b

File tree

5 files changed

+44
-57
lines changed

5 files changed

+44
-57
lines changed

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55

66
'use strict';
77
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
8-
import type { Dependency, Compilation } from 'webpack';
9-
import ContainerExposedDependency from './ContainerExposedDependency';
8+
import type { Compilation, Dependency } from 'webpack';
109
import type {
10+
InputFileSystem,
1111
LibIdentOptions,
1212
NeedBuildContext,
13-
RequestShortener,
1413
ObjectDeserializerContext,
1514
ObjectSerializerContext,
16-
WebpackOptions,
17-
InputFileSystem,
15+
RequestShortener,
1816
ResolverWithOptions,
17+
WebpackOptions,
1918
} from 'webpack/lib/Module';
2019
import type WebpackError from 'webpack/lib/WebpackError';
21-
import { getFederationGlobalScope } from './runtime/utils';
2220
import { JAVASCRIPT_MODULE_TYPE_DYNAMIC } from '../Constants';
21+
import ContainerExposedDependency from './ContainerExposedDependency';
22+
import { getFederationGlobalScope } from './runtime/utils';
2323

2424
const makeSerializable = require(
2525
normalizeWebpackPath('webpack/lib/util/makeSerializable'),
2626
) as typeof import('webpack/lib/util/makeSerializable');
27-
const { sources: webpackSources } = require(
28-
normalizeWebpackPath('webpack'),
29-
) as typeof import('webpack');
30-
const { AsyncDependenciesBlock, Template, Module, RuntimeGlobals } = require(
31-
normalizeWebpackPath('webpack'),
32-
) as typeof import('webpack');
27+
const {
28+
sources: webpackSources,
29+
AsyncDependenciesBlock,
30+
Template,
31+
Module,
32+
RuntimeGlobals,
33+
} = require(normalizeWebpackPath('webpack')) as typeof import('webpack');
3334
const StaticExportsDependency = require(
3435
normalizeWebpackPath('webpack/lib/dependencies/StaticExportsDependency'),
3536
) as typeof import('webpack/lib/dependencies/StaticExportsDependency');
@@ -79,7 +80,6 @@ class ContainerEntryModule extends Module {
7980
static deserialize(context: ObjectDeserializerContext): ContainerEntryModule {
8081
const { read } = context;
8182
const obj = new ContainerEntryModule(read(), read(), read(), read());
82-
//@ts-ignore
8383
obj.deserialize(context);
8484
return obj;
8585
}
@@ -119,7 +119,7 @@ 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-ignore typeof webpack/lib !== typeof webpack/types
122+
// @ts-expect-error typeof webpack/lib !== typeof webpack/types
123123
override needBuild(
124124
context: NeedBuildContext,
125125
callback: (
@@ -138,7 +138,7 @@ class ContainerEntryModule extends Module {
138138
* @param {function(WebpackError): void} callback callback function
139139
* @returns {void}
140140
*/
141-
// @ts-ignore typeof webpack/lib !== typeof webpack/types
141+
// @ts-expect-error typeof webpack/lib !== typeof webpack/types
142142
override build(
143143
options: WebpackOptions,
144144
compilation: Compilation,
@@ -152,7 +152,6 @@ class ContainerEntryModule extends Module {
152152
topLevelDeclarations: new Set(['moduleMap', 'get', 'init']),
153153
};
154154
this.buildMeta.exportsType = 'namespace';
155-
//@ts-ignore
156155
this.clearDependenciesAndBlocks();
157156

158157
for (const [name, options] of this._exposes) {
@@ -170,23 +169,19 @@ class ContainerEntryModule extends Module {
170169
name,
171170
index: idx++,
172171
};
173-
//@ts-ignore
174172
block.addDependency(dep);
175173
}
176-
//@ts-ignore
177174
this.addBlock(block);
178175
}
179-
//@ts-ignore
180176
this.addDependency(
181-
//@ts-ignore
182177
new StaticExportsDependency(
183178
['get', 'init'],
184179
false,
185180
) as unknown as Dependency,
186181
);
187182

188183
this.addDependency(
189-
// @ts-ignore
184+
// @ts-expect-error flaky type for EntryDependency
190185
new EntryDependency(this._injectRuntimeEntry),
191186
);
192187

@@ -197,8 +192,7 @@ class ContainerEntryModule extends Module {
197192
* @param {CodeGenerationContext} context context for code generation
198193
* @returns {CodeGenerationResult} result
199194
*/
200-
//@ts-ignore
201-
override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }) {
195+
override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }: any) {
202196
const sources = new Map();
203197
const runtimeRequirements = new Set([
204198
RuntimeGlobals.definePropertyGetters,
@@ -232,7 +226,6 @@ class ContainerEntryModule extends Module {
232226
})}.then(${runtimeTemplate.returningFunction(
233227
runtimeTemplate.returningFunction(
234228
`(${modules
235-
//@ts-ignore
236229
.map(({ module, request }) =>
237230
runtimeTemplate.moduleRaw({
238231
module,
@@ -259,7 +252,7 @@ class ContainerEntryModule extends Module {
259252
const initRuntimeModuleGetter = runtimeTemplate.moduleRaw({
260253
module: moduleGraph.getModule(initRuntimeDep),
261254
chunkGraph,
262-
// @ts-expect-error
255+
// @ts-expect-error flaky type definition for Dependency
263256
request: initRuntimeDep.userRequest,
264257
weak: false,
265258
runtimeRequirements,

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

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

3535
callback(null, {
36-
// @ts-ignore
36+
// @ts-expect-error missing some deps
3737
module: new ContainerEntryModule(
3838
dep.name,
3939
dep.exposes,

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
'use strict';
77

88
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
9-
import type { ChunkGraph, Chunk } from 'webpack';
9+
import type { Chunk, ChunkGraph } from 'webpack';
1010
import type {
11-
RequestShortener,
12-
LibIdentOptions,
1311
CodeGenerationContext,
1412
CodeGenerationResult,
15-
NeedBuildContext,
16-
WebpackError,
17-
ResolverWithOptions,
18-
InputFileSystem,
1913
Compilation,
20-
WebpackOptions,
14+
InputFileSystem,
15+
LibIdentOptions,
16+
NeedBuildContext,
2117
ObjectDeserializerContext,
2218
ObjectSerializerContext,
19+
RequestShortener,
20+
ResolverWithOptions,
21+
WebpackError,
22+
WebpackOptions,
2323
} from 'webpack/lib/Module';
24-
import FallbackItemDependency from './FallbackItemDependency';
2524
import { WEBPACK_MODULE_TYPE_FALLBACK } from '../Constants';
25+
import FallbackItemDependency from './FallbackItemDependency';
2626

2727
const { sources: webpackSources } = require(
2828
normalizeWebpackPath('webpack'),
@@ -92,7 +92,7 @@ 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-ignore
95+
// @ts-expect-error incompatible context types
9696
override needBuild(
9797
context: NeedBuildContext,
9898
callback: (error: WebpackError | null, result?: boolean) => void,
@@ -108,7 +108,7 @@ class FallbackModule extends Module {
108108
* @param {function(WebpackError=): void} callback callback function
109109
* @returns {void}
110110
*/
111-
// @ts-ignore
111+
// @ts-expect-error incompatible option types
112112
override build(
113113
options: WebpackOptions,
114114
compilation: Compilation,
@@ -147,14 +147,14 @@ class FallbackModule extends Module {
147147
* @param {CodeGenerationContext} context context for code generation
148148
* @returns {CodeGenerationResult} result
149149
*/
150-
// @ts-ignore
150+
// @ts-expect-error incompatible CodeGenerationContext
151151
override codeGeneration({
152152
runtimeTemplate,
153153
moduleGraph,
154154
chunkGraph,
155155
}: CodeGenerationContext): CodeGenerationResult {
156156
const ids = this.dependencies.map((dep) =>
157-
//@ts-ignore
157+
// @ts-expect-error incompatible dependency type
158158
chunkGraph.getModuleId(moduleGraph.getModule(dep)),
159159
);
160160
const code = Template.asString([

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55

66
'use strict';
7+
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
78
import type {
89
ModuleFactoryCreateData,
910
ModuleFactoryResult,
1011
} from 'webpack/lib/ModuleFactory';
11-
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
1212
import FallbackModule from './FallbackModule';
1313

1414
const ModuleFactory = require(
@@ -27,7 +27,7 @@ export default class FallbackModuleFactory extends ModuleFactory {
2727
): void {
2828
const dependency = data.dependencies[0];
2929
callback(null, {
30-
// @ts-ignore
30+
// @ts-expect-error Module !== FallbackModule
3131
module: new FallbackModule(dependency.requests),
3232
});
3333
}

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
*/
55

66
'use strict';
7-
import type { Compiler, WebpackPluginInstance } from 'webpack';
8-
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
7+
import { DtsPlugin } from '@module-federation/dts-plugin';
8+
import { ContainerManager, utils } from '@module-federation/managers';
9+
import { StatsPlugin } from '@module-federation/manifest';
910
import {
1011
composeKeyWithSeparator,
1112
type moduleFederationPlugin,
1213
} from '@module-federation/sdk';
13-
import { StatsPlugin } from '@module-federation/manifest';
14-
import { ContainerManager, utils } from '@module-federation/managers';
15-
import { DtsPlugin } from '@module-federation/dts-plugin';
14+
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
15+
import type { Compiler, WebpackPluginInstance } from 'webpack';
16+
import schema from '../../schemas/container/ModuleFederationPlugin';
1617
import SharePlugin from '../sharing/SharePlugin';
1718
import ContainerPlugin from './ContainerPlugin';
1819
import ContainerReferencePlugin from './ContainerReferencePlugin';
19-
import schema from '../../schemas/container/ModuleFederationPlugin';
2020
import FederationRuntimePlugin from './runtime/FederationRuntimePlugin';
21-
import HoistContainerReferencesPlugin from './HoistContainerReferencesPlugin';
2221

2322
const isValidExternalsType = require(
2423
normalizeWebpackPath(
@@ -70,7 +69,6 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
7069
*/
7170
apply(compiler: Compiler): void {
7271
const { _options: options } = this;
73-
// @ts-ignore
7472
new FederationRuntimePlugin(options).apply(compiler);
7573
const library = options.library || { type: 'var', name: options.name };
7674
const remoteType =
@@ -87,8 +85,7 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
8785

8886
let disableManifest = options.manifest === false;
8987
if (useContainerPlugin) {
90-
// @ts-ignore
91-
ContainerPlugin.patchChunkSplit(compiler, this._options.name);
88+
ContainerPlugin.patchChunkSplit(compiler, this._options.name!);
9289
}
9390
this._patchBundlerConfig(compiler);
9491
if (!disableManifest && useContainerPlugin) {
@@ -118,16 +115,13 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
118115
compiler.hooks.afterPlugins.tap('ModuleFederationPlugin', () => {
119116
if (useContainerPlugin) {
120117
new ContainerPlugin({
121-
//@ts-ignore
122-
name: options.name,
118+
name: options.name!,
123119
library,
124120
filename: options.filename,
125121
runtime: options.runtime,
126122
shareScope: options.shareScope,
127-
//@ts-ignore
128-
exposes: options.exposes,
123+
exposes: options.exposes!,
129124
runtimePlugins: options.runtimePlugins,
130-
//@ts-ignore
131125
}).apply(compiler);
132126
}
133127
if (
@@ -137,7 +131,7 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
137131
: Object.keys(options.remotes).length > 0)
138132
) {
139133
new ContainerReferencePlugin({
140-
//@ts-ignore
134+
// @ts-expect-error this should not be a string
141135
remoteType,
142136
shareScope: options.shareScope,
143137
remotes: options.remotes,

0 commit comments

Comments
 (0)