Skip to content

Commit

Permalink
types: leverage webpack types and remove casting (#42104)
Browse files Browse the repository at this point in the history
* Use webpack types directly through webpack namespace
* Remove webpack types casting to any
  • Loading branch information
huozhi committed Oct 29, 2022
1 parent dc3cd95 commit d510204
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
Expand Up @@ -31,12 +31,12 @@ export class AppBuildManifestPlugin {
PLUGIN_NAME,
(compilation: any, { normalModuleFactory }: any) => {
compilation.dependencyFactories.set(
(webpack as any).dependencies.ModuleDependency,
webpack.dependencies.ModuleDependency,
normalModuleFactory
)
compilation.dependencyTemplates.set(
(webpack as any).dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template()
webpack.dependencies.ModuleDependency,
new webpack.dependencies.NullDependency.Template()
)
}
)
Expand Down
38 changes: 20 additions & 18 deletions packages/next/build/webpack/plugins/flight-client-entry-plugin.ts
@@ -1,16 +1,17 @@
import type {
CssImports,
ClientComponentImports,
NextFlightClientEntryLoaderOptions,
} from '../loaders/next-flight-client-entry-loader'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { stringify } from 'querystring'
import path from 'path'
import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import { sources } from 'next/dist/compiled/webpack/webpack'
import {
getInvalidator,
entries,
EntryTypes,
} from '../../../server/dev/on-demand-entry-handler'
import type {
CssImports,
ClientComponentImports,
NextFlightClientEntryLoaderOptions,
} from '../loaders/next-flight-client-entry-loader'
import { APP_DIR_ALIAS, WEBPACK_LAYERS } from '../../../lib/constants'
import {
APP_CLIENT_INTERNALS,
Expand Down Expand Up @@ -52,12 +53,12 @@ export class FlightClientEntryPlugin {
PLUGIN_NAME,
(compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set(
(webpack as any).dependencies.ModuleDependency,
webpack.dependencies.ModuleDependency,
normalModuleFactory
)
compilation.dependencyTemplates.set(
(webpack as any).dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template()
webpack.dependencies.ModuleDependency,
new webpack.dependencies.NullDependency.Template()
)
}
)
Expand Down Expand Up @@ -464,8 +465,8 @@ export class FlightClientEntryPlugin {
clientComponentImports,
bundlePath,
}: {
compiler: any
compilation: any
compiler: webpack.Compiler
compilation: webpack.Compilation
entryName: string
clientComponentImports: ClientComponentImports
bundlePath: string
Expand Down Expand Up @@ -524,11 +525,12 @@ export class FlightClientEntryPlugin {
}

// Inject the entry to the server compiler (__sc_client__).
const clientComponentEntryDep = (
webpack as any
).EntryPlugin.createDependency(clientSSRLoader, {
name: bundlePath,
})
const clientComponentEntryDep = webpack.EntryPlugin.createDependency(
clientSSRLoader,
{
name: bundlePath,
}
)

// Add the dependency to the server compiler.
await this.addEntry(
Expand All @@ -552,8 +554,8 @@ export class FlightClientEntryPlugin {
addEntry(
compilation: any,
context: string,
dependency: any /* Dependency */,
options: any /* EntryOptions */
dependency: webpack.Dependency,
options: webpack.EntryOptions
): Promise<any> /* Promise<module> */ {
return new Promise((resolve, reject) => {
const entry = compilation.entries.get(options.name)
Expand Down
6 changes: 3 additions & 3 deletions packages/next/build/webpack/plugins/flight-manifest-plugin.ts
Expand Up @@ -96,12 +96,12 @@ export class FlightManifestPlugin {
PLUGIN_NAME,
(compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set(
(webpack as any).dependencies.ModuleDependency,
webpack.dependencies.ModuleDependency,
normalModuleFactory
)
compilation.dependencyTemplates.set(
(webpack as any).dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template()
webpack.dependencies.ModuleDependency,
new webpack.dependencies.NullDependency.Template()
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/plugins/middleware-plugin.ts
Expand Up @@ -861,7 +861,7 @@ export default class MiddlewarePlugin {
compilation.hooks.processAssets.tap(
{
name: 'NextJsMiddlewareManifest',
stage: (webpack as any).Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
},
getCreateAssets({
compilation,
Expand Down

0 comments on commit d510204

Please sign in to comment.