Skip to content

Commit 68463cf

Browse files
chore: fix type issues in other plugins (#2901)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 8d9e1b6 commit 68463cf

File tree

10 files changed

+57
-37
lines changed

10 files changed

+57
-37
lines changed

.github/workflows/e2e-next.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ jobs:
4646
run: |
4747
pnpm run --filter @module-federation/3002-checkout --filter @module-federation/3000-home --filter @module-federation/3001-shop build &&
4848
pnpm run app:next:prod &
49-
sleep 2 &&
49+
sleep 4 &&
5050
npx wait-on tcp:3001 &&
5151
npx wait-on tcp:3002 &&
5252
npx wait-on tcp:3000 &&
53-
npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=3 &&
53+
npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=1 &&
5454
lsof -ti tcp:3000,3001,3002 | xargs kill
5555
5656
- name: E2E Test for Next.js Dev

packages/enhanced/src/declarations/plugins/container/WebpackError.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Module } from 'webpack';
2+
13
declare class WebpackError extends Error {
24
/**
35
* Creates an instance of WebpackError.
@@ -17,7 +19,6 @@ declare class WebpackError extends Error {
1719
*/
1820
static captureStackTrace(
1921
targetObject: object,
20-
// eslint-disable-next-line @typescript-eslint/ban-types
2122
constructorOpt?: Function,
2223
): void;
2324

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const PLUGIN_NAME = 'ContainerPlugin';
4343
class ContainerPlugin {
4444
_options: containerPlugin.ContainerPluginOptions;
4545
name: string;
46+
4647
/**
4748
* @param {containerPlugin.ContainerPluginOptions} options options
4849
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
44
*/
55
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
6-
import type { Compilation } from 'webpack';
6+
import type { Compilation, Chunk } from 'webpack';
77
import RemoteModule from './RemoteModule';
88
import { getFederationGlobalScope } from './runtime/utils';
99
import type ExternalModule from 'webpack/lib/ExternalModule';

packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getWebpackPath,
99
normalizeWebpackPath,
1010
} from '@module-federation/sdk/normalize-webpack-path';
11-
import type { Compiler } from 'webpack';
11+
import type { Compiler, Compilation } from 'webpack';
1212
import { parseOptions } from '../container/options';
1313
import { ConsumeOptions } from './ConsumeSharedModule';
1414
import { ConsumeSharedPluginOptions } from '../../declarations/plugins/sharing/ConsumeSharedPlugin';
@@ -18,7 +18,10 @@ import {
1818
getDescriptionFile,
1919
getRequiredVersionFromDescriptionFile,
2020
} from './utils';
21-
import type { ResolveOptionsWithDependencyType } from 'webpack/lib/ResolverFactory';
21+
import type {
22+
ResolveOptionsWithDependencyType,
23+
ResolverWithOptions,
24+
} from 'webpack/lib/ResolverFactory';
2225
import ConsumeSharedFallbackDependency from './ConsumeSharedFallbackDependency';
2326
import ConsumeSharedModule from './ConsumeSharedModule';
2427
import ConsumeSharedRuntimeModule from './ConsumeSharedRuntimeModule';
@@ -136,7 +139,7 @@ class ConsumeSharedPlugin {
136139

137140
compiler.hooks.thisCompilation.tap(
138141
PLUGIN_NAME,
139-
(compilation, { normalModuleFactory }) => {
142+
(compilation: Compilation, { normalModuleFactory }) => {
140143
compilation.dependencyFactories.set(
141144
ConsumeSharedFallbackDependency,
142145
normalModuleFactory,
@@ -152,11 +155,9 @@ class ConsumeSharedPlugin {
152155
prefixedConsumes = prefixed;
153156
},
154157
);
155-
156-
const resolver = compilation.resolverFactory.get(
158+
const resolver: ResolverWithOptions = compilation.resolverFactory.get(
157159
'normal',
158-
//@ts-ignore
159-
RESOLVE_OPTIONS,
160+
RESOLVE_OPTIONS as ResolveOptionsWithDependencyType,
160161
);
161162

162163
const createConsumeSharedModule = (

packages/enhanced/src/lib/sharing/ProvideSharedDependency.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const { Dependency } = require(
1212
normalizeWebpackPath('webpack'),
1313
) as typeof import('webpack');
1414

15-
import {
15+
import type {
1616
ObjectDeserializerContext,
1717
ObjectSerializerContext,
18-
} from '../../declarations/plugins/container/Dependency';
18+
} from 'webpack/lib/Dependency';
1919

2020
class ProvideSharedDependency extends Dependency {
2121
shareScope: string;

packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
getWebpackPath,
99
normalizeWebpackPath,
1010
} from '@module-federation/sdk/normalize-webpack-path';
11-
import type { Compiler, Compilation } from 'webpack';
11+
import type {
12+
Compiler,
13+
Compilation,
14+
WebpackError as WebpackErrorType,
15+
} from 'webpack';
1216
import { parseOptions } from '../container/options';
1317
import ProvideForSharedDependency from './ProvideForSharedDependency';
1418
import ProvideSharedDependency from './ProvideSharedDependency';
@@ -243,7 +247,7 @@ class ProvideSharedPlugin {
243247
{
244248
name: undefined,
245249
},
246-
(err: WebpackError | null | undefined) => {
250+
(err?: WebpackErrorType | null | undefined) => {
247251
if (err) return reject(err);
248252
resolve();
249253
},
@@ -263,7 +267,6 @@ class ProvideSharedPlugin {
263267
);
264268

265269
compilation.dependencyFactories.set(
266-
//@ts-ignore
267270
ProvideSharedDependency,
268271
// @ts-ignore
269272
new ProvideSharedModuleFactory(),

packages/manifest/src/StatsManager.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import {
1313
moduleFederationPlugin,
1414
RemoteEntryType,
1515
} from '@module-federation/sdk';
16-
import { Compilation, Compiler, StatsCompilation, StatsModule } from 'webpack';
16+
import {
17+
Compilation,
18+
Compiler,
19+
StatsCompilation,
20+
StatsModule,
21+
Chunk,
22+
} from 'webpack';
1723
import {
1824
isDev,
1925
getAssetsByChunk,
@@ -86,8 +92,10 @@ class StatsManager {
8692
const remoteEntryNameChunk = compilation.namedChunks.get(name);
8793

8894
assert(remoteEntryNameChunk, 'Can not get remoteEntry chunk!');
89-
const files = Array.from(remoteEntryNameChunk.files).filter(
90-
(f) => !f.includes(HOT_UPDATE_SUFFIX) && !f.endsWith('.css'),
95+
const files = Array.from(
96+
remoteEntryNameChunk.files as Iterable<string>,
97+
).filter(
98+
(f: string) => !f.includes(HOT_UPDATE_SUFFIX) && !f.endsWith('.css'),
9199
);
92100
assert(files.length > 0, 'no files found for remoteEntry chunk');
93101
assert(
@@ -209,25 +217,31 @@ class StatsManager {
209217
const [sharedModuleName, sharedModule] = item;
210218
if (!manifestOverrideChunkIDMap[sharedModuleName]) {
211219
manifestOverrideChunkIDMap[sharedModuleName] = {
212-
async: new Set(),
213-
sync: new Set(),
220+
async: new Set<string | number>(),
221+
sync: new Set<string | number>(),
214222
};
215223
}
216-
sharedModule.chunks!.forEach((chunkID) => {
224+
sharedModule.chunks!.forEach((chunkID: string | number) => {
217225
const chunk = findChunk(chunkID, compilation.chunks);
218226

219227
manifestOverrideChunkIDMap[sharedModuleName].sync.add(chunkID);
220-
Array.from(chunk!.getAllInitialChunks()).forEach((syncChunk) => {
221-
syncChunk.id &&
222-
manifestOverrideChunkIDMap[sharedModuleName].sync.add(syncChunk.id);
223-
});
228+
Array.from(chunk!.getAllInitialChunks() as Iterable<Chunk>).forEach(
229+
(syncChunk: Chunk) => {
230+
syncChunk.id &&
231+
manifestOverrideChunkIDMap[sharedModuleName].sync.add(
232+
syncChunk.id,
233+
);
234+
},
235+
);
224236

225-
Array.from(chunk!.getAllAsyncChunks()).forEach((asyncChunk) => {
226-
asyncChunk.id &&
227-
manifestOverrideChunkIDMap[sharedModuleName].async.add(
228-
asyncChunk.id,
229-
);
230-
});
237+
Array.from(chunk!.getAllAsyncChunks() as Iterable<Chunk>).forEach(
238+
(asyncChunk: Chunk) => {
239+
asyncChunk.id &&
240+
manifestOverrideChunkIDMap[sharedModuleName].async.add(
241+
asyncChunk.id,
242+
);
243+
},
244+
);
231245
});
232246
});
233247

packages/manifest/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function getAssetsByChunkIDs(
4949
compilation: Compilation,
5050
chunkIDMap: Record<string, Set<string | number>>,
5151
): Record<string, { js: string[]; css: string[] }> {
52-
const arrayChunks = Array.from(compilation.chunks);
52+
const arrayChunks = Array.from(compilation.chunks) as Chunk[];
5353
const assetMap: Record<string, { css: Set<string>; js: Set<string> }> = {};
5454

5555
Object.keys(chunkIDMap).forEach((key) => {

packages/typescript/src/plugins/FederatedTypesPlugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ export class FederatedTypesPlugin {
6464
this.normalizeOptions.ignoredWatchOptions;
6565

6666
if (!disableTypeCompilation) {
67-
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (_) => {
67+
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (_: unknown) => {
6868
this.generateTypes({ outputPath: compiler.outputPath });
6969
});
7070

7171
this.handleTypeServing(compiler, this.normalizeOptions.typeServeOptions);
7272

7373
// TODO - this is not ideal, but it will repopulate types if clean is enabled
7474
if (compiler.options.output.clean) {
75-
compiler.hooks.afterEmit.tap(PLUGIN_NAME, (_) => {
75+
compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => {
7676
this.generateTypes({ outputPath: compiler.outputPath });
7777
});
7878
}
@@ -81,7 +81,7 @@ export class FederatedTypesPlugin {
8181
if (!disableDownloadingRemoteTypes) {
8282
compiler.hooks.beforeCompile.tapAsync(
8383
PLUGIN_NAME,
84-
async (_, callback) => {
84+
async (params: unknown, callback: InnerCallback<Error, void>) => {
8585
if (typeDownloadCompleted) {
8686
callback();
8787
return;
@@ -112,7 +112,7 @@ export class FederatedTypesPlugin {
112112

113113
compiler.hooks.beforeCompile.tapAsync(
114114
PLUGIN_NAME,
115-
async (_, callback) => {
115+
async (params: unknown, callback: InnerCallback<Error, void>) => {
116116
this.logger.log('Preparing to serve types');
117117

118118
try {

0 commit comments

Comments
 (0)