Unverified Commit d510204f authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

types: leverage webpack types and remove casting (#42104)

* Use webpack types directly through webpack namespace
* Remove webpack types casting to any
parent dc3cd950
...@@ -31,12 +31,12 @@ export class AppBuildManifestPlugin { ...@@ -31,12 +31,12 @@ export class AppBuildManifestPlugin {
PLUGIN_NAME, PLUGIN_NAME,
(compilation: any, { normalModuleFactory }: any) => { (compilation: any, { normalModuleFactory }: any) => {
compilation.dependencyFactories.set( compilation.dependencyFactories.set(
(webpack as any).dependencies.ModuleDependency, webpack.dependencies.ModuleDependency,
normalModuleFactory normalModuleFactory
) )
compilation.dependencyTemplates.set( compilation.dependencyTemplates.set(
(webpack as any).dependencies.ModuleDependency, webpack.dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template() new webpack.dependencies.NullDependency.Template()
) )
} }
) )
......
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 { stringify } from 'querystring'
import path from 'path' import path from 'path'
import { webpack, sources } from 'next/dist/compiled/webpack/webpack' import { sources } from 'next/dist/compiled/webpack/webpack'
import { import {
getInvalidator, getInvalidator,
entries, entries,
EntryTypes, EntryTypes,
} from '../../../server/dev/on-demand-entry-handler' } 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_DIR_ALIAS, WEBPACK_LAYERS } from '../../../lib/constants'
import { import {
APP_CLIENT_INTERNALS, APP_CLIENT_INTERNALS,
...@@ -52,12 +53,12 @@ export class FlightClientEntryPlugin { ...@@ -52,12 +53,12 @@ export class FlightClientEntryPlugin {
PLUGIN_NAME, PLUGIN_NAME,
(compilation, { normalModuleFactory }) => { (compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set( compilation.dependencyFactories.set(
(webpack as any).dependencies.ModuleDependency, webpack.dependencies.ModuleDependency,
normalModuleFactory normalModuleFactory
) )
compilation.dependencyTemplates.set( compilation.dependencyTemplates.set(
(webpack as any).dependencies.ModuleDependency, webpack.dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template() new webpack.dependencies.NullDependency.Template()
) )
} }
) )
...@@ -464,8 +465,8 @@ export class FlightClientEntryPlugin { ...@@ -464,8 +465,8 @@ export class FlightClientEntryPlugin {
clientComponentImports, clientComponentImports,
bundlePath, bundlePath,
}: { }: {
compiler: any compiler: webpack.Compiler
compilation: any compilation: webpack.Compilation
entryName: string entryName: string
clientComponentImports: ClientComponentImports clientComponentImports: ClientComponentImports
bundlePath: string bundlePath: string
...@@ -524,11 +525,12 @@ export class FlightClientEntryPlugin { ...@@ -524,11 +525,12 @@ export class FlightClientEntryPlugin {
} }
// Inject the entry to the server compiler (__sc_client__). // Inject the entry to the server compiler (__sc_client__).
const clientComponentEntryDep = ( const clientComponentEntryDep = webpack.EntryPlugin.createDependency(
webpack as any clientSSRLoader,
).EntryPlugin.createDependency(clientSSRLoader, { {
name: bundlePath, name: bundlePath,
}) }
)
// Add the dependency to the server compiler. // Add the dependency to the server compiler.
await this.addEntry( await this.addEntry(
...@@ -552,8 +554,8 @@ export class FlightClientEntryPlugin { ...@@ -552,8 +554,8 @@ export class FlightClientEntryPlugin {
addEntry( addEntry(
compilation: any, compilation: any,
context: string, context: string,
dependency: any /* Dependency */, dependency: webpack.Dependency,
options: any /* EntryOptions */ options: webpack.EntryOptions
): Promise<any> /* Promise<module> */ { ): Promise<any> /* Promise<module> */ {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const entry = compilation.entries.get(options.name) const entry = compilation.entries.get(options.name)
......
...@@ -96,12 +96,12 @@ export class FlightManifestPlugin { ...@@ -96,12 +96,12 @@ export class FlightManifestPlugin {
PLUGIN_NAME, PLUGIN_NAME,
(compilation, { normalModuleFactory }) => { (compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set( compilation.dependencyFactories.set(
(webpack as any).dependencies.ModuleDependency, webpack.dependencies.ModuleDependency,
normalModuleFactory normalModuleFactory
) )
compilation.dependencyTemplates.set( compilation.dependencyTemplates.set(
(webpack as any).dependencies.ModuleDependency, webpack.dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template() new webpack.dependencies.NullDependency.Template()
) )
} }
) )
......
...@@ -861,7 +861,7 @@ export default class MiddlewarePlugin { ...@@ -861,7 +861,7 @@ export default class MiddlewarePlugin {
compilation.hooks.processAssets.tap( compilation.hooks.processAssets.tap(
{ {
name: 'NextJsMiddlewareManifest', name: 'NextJsMiddlewareManifest',
stage: (webpack as any).Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
}, },
getCreateAssets({ getCreateAssets({
compilation, compilation,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment