Unverified Commit d2f96f5f authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

partially migrate to webpack 5 types (#30189)

fix type declarations to avoid import from webpack/webpack4/webpack5 in type declarations
parent 864d5c6b
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import type webpack5 from 'webpack5' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { Span } from '../trace' import { Span } from '../trace'
export type CompilerResult = { export type CompilerResult = {
......
...@@ -12,7 +12,7 @@ import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-lo ...@@ -12,7 +12,7 @@ import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-lo
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader' import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import { LoadedEnvFiles } from '@next/env' import { LoadedEnvFiles } from '@next/env'
import { NextConfigComplete } from '../server/config-shared' import { NextConfigComplete } from '../server/config-shared'
import type webpack5 from 'webpack5' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
type ObjectValue<T> = T extends { [key: string]: infer V } ? V : never type ObjectValue<T> = T extends { [key: string]: infer V } ? V : never
type PagesMapping = { type PagesMapping = {
......
...@@ -98,6 +98,7 @@ import { NextConfigComplete } from '../server/config-shared' ...@@ -98,6 +98,7 @@ import { NextConfigComplete } from '../server/config-shared'
import isError, { NextError } from '../lib/is-error' import isError, { NextError } from '../lib/is-error'
import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin' import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import { MiddlewareManifest } from './webpack/plugins/middleware-plugin' import { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
const RESERVED_PAGE = /^\/(_app|_error|_document|api(\/|$))/ const RESERVED_PAGE = /^\/(_app|_error|_document|api(\/|$))/
...@@ -1777,7 +1778,9 @@ export default async function build( ...@@ -1777,7 +1778,9 @@ export default async function build(
}) })
) )
const telemetryPlugin = clientConfig.plugins?.find(isTelemetryPlugin) const telemetryPlugin = (
clientConfig as webpack.Configuration
).plugins?.find(isTelemetryPlugin)
if (telemetryPlugin) { if (telemetryPlugin) {
const events = eventBuildFeatureUsage(telemetryPlugin) const events = eventBuildFeatureUsage(telemetryPlugin)
telemetry.record(events) telemetry.record(events)
......
...@@ -4,13 +4,14 @@ import textTable from 'next/dist/compiled/text-table' ...@@ -4,13 +4,14 @@ import textTable from 'next/dist/compiled/text-table'
import createStore from 'next/dist/compiled/unistore' import createStore from 'next/dist/compiled/unistore'
import formatWebpackMessages from '../../client/dev/error-overlay/format-webpack-messages' import formatWebpackMessages from '../../client/dev/error-overlay/format-webpack-messages'
import { OutputState, store as consoleStore } from './store' import { OutputState, store as consoleStore } from './store'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
export function startedDevelopmentServer(appUrl: string, bindAddr: string) { export function startedDevelopmentServer(appUrl: string, bindAddr: string) {
consoleStore.setState({ appUrl, bindAddr }) consoleStore.setState({ appUrl, bindAddr })
} }
let previousClient: import('webpack').Compiler | null = null let previousClient: webpack5.Compiler | null = null
let previousServer: import('webpack').Compiler | null = null let previousServer: webpack5.Compiler | null = null
type CompilerDiagnostics = { type CompilerDiagnostics = {
modules: number modules: number
...@@ -207,8 +208,8 @@ export function ampValidation( ...@@ -207,8 +208,8 @@ export function ampValidation(
} }
export function watchCompilers( export function watchCompilers(
client: import('webpack').Compiler, client: webpack5.Compiler,
server: import('webpack').Compiler server: webpack5.Compiler
) { ) {
if (previousClient === client && previousServer === server) { if (previousClient === client && previousServer === server) {
return return
...@@ -229,29 +230,26 @@ export function watchCompilers( ...@@ -229,29 +230,26 @@ export function watchCompilers(
onEvent({ loading: true }) onEvent({ loading: true })
}) })
compiler.hooks.done.tap( compiler.hooks.done.tap(`NextJsDone-${key}`, (stats: webpack5.Stats) => {
`NextJsDone-${key}`, buildStore.setState({ amp: {} })
(stats: import('webpack5').Stats) => {
buildStore.setState({ amp: {} }) const { errors, warnings } = formatWebpackMessages(
stats.toJson({
const { errors, warnings } = formatWebpackMessages( preset: 'error-warnings',
stats.toJson({ moduleTrace: true,
preset: 'error-warnings',
moduleTrace: true,
})
)
const hasErrors = !!errors?.length
const hasWarnings = !!warnings?.length
onEvent({
loading: false,
modules: stats.compilation.modules.size,
errors: hasErrors ? errors : null,
warnings: hasWarnings ? warnings : null,
}) })
} )
)
const hasErrors = !!errors?.length
const hasWarnings = !!warnings?.length
onEvent({
loading: false,
modules: stats.compilation.modules.size,
errors: hasErrors ? errors : null,
warnings: hasWarnings ? warnings : null,
})
})
} }
tapCompiler('client', client, (status) => { tapCompiler('client', client, (status) => {
......
...@@ -5,7 +5,7 @@ import { readFileSync } from 'fs' ...@@ -5,7 +5,7 @@ import { readFileSync } from 'fs'
import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame' import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import semver from 'next/dist/compiled/semver' import semver from 'next/dist/compiled/semver'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import type webpack5 from 'webpack5' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import path, { join as pathJoin, relative as relativePath } from 'path' import path, { join as pathJoin, relative as relativePath } from 'path'
import escapeRegExp from 'next/dist/compiled/escape-string-regexp' import escapeRegExp from 'next/dist/compiled/escape-string-regexp'
import { import {
......
...@@ -2,6 +2,7 @@ import cssnanoSimple from 'cssnano-simple' ...@@ -2,6 +2,7 @@ import cssnanoSimple from 'cssnano-simple'
import postcssScss from 'next/dist/compiled/postcss-scss' import postcssScss from 'next/dist/compiled/postcss-scss'
import postcss, { Parser } from 'postcss' import postcss, { Parser } from 'postcss'
import { webpack, sources } from 'next/dist/compiled/webpack/webpack' import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { spans } from './profiling-plugin' import { spans } from './profiling-plugin'
// https://github.com/NMFR/optimize-css-assets-webpack-plugin/blob/0a410a9bf28c7b0e81a3470a13748e68ca2f50aa/src/index.js#L20 // https://github.com/NMFR/optimize-css-assets-webpack-plugin/blob/0a410a9bf28c7b0e81a3470a13748e68ca2f50aa/src/index.js#L20
...@@ -54,7 +55,7 @@ export class CssMinimizerPlugin { ...@@ -54,7 +55,7 @@ export class CssMinimizerPlugin {
}) })
} }
apply(compiler: webpack.Compiler) { apply(compiler: webpack5.Compiler) {
compiler.hooks.compilation.tap('CssMinimizerPlugin', (compilation: any) => { compiler.hooks.compilation.tap('CssMinimizerPlugin', (compilation: any) => {
const cache = compilation.getCache('CssMinimizerPlugin') const cache = compilation.getCache('CssMinimizerPlugin')
compilation.hooks.processAssets.tapPromise( compilation.hooks.processAssets.tapPromise(
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
} from 'next/dist/compiled/@vercel/nft' } from 'next/dist/compiled/@vercel/nft'
import { TRACE_OUTPUT_VERSION } from '../../../shared/lib/constants' import { TRACE_OUTPUT_VERSION } from '../../../shared/lib/constants'
import { webpack, sources } from 'next/dist/compiled/webpack/webpack' import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { import {
nextImageLoaderRegex, nextImageLoaderRegex,
NODE_ESM_RESOLVE_OPTIONS, NODE_ESM_RESOLVE_OPTIONS,
...@@ -26,11 +27,11 @@ const TRACE_IGNORES = [ ...@@ -26,11 +27,11 @@ const TRACE_IGNORES = [
function getModuleFromDependency( function getModuleFromDependency(
compilation: any, compilation: any,
dep: any dep: any
): webpack.Module & { resource?: string } { ): webpack5.Module & { resource?: string } {
return compilation.moduleGraph.getModule(dep) return compilation.moduleGraph.getModule(dep)
} }
export class TraceEntryPointsPlugin implements webpack.Plugin { export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
private appDir: string private appDir: string
private entryTraces: Map<string, Set<string>> private entryTraces: Map<string, Set<string>>
private excludeFiles: string[] private excludeFiles: string[]
...@@ -100,7 +101,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -100,7 +101,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
} }
tapfinishModules( tapfinishModules(
compilation: webpack.compilation.Compilation, compilation: webpack5.Compilation,
traceEntrypointsPluginSpan: Span, traceEntrypointsPluginSpan: Span,
doResolve?: ( doResolve?: (
request: string, request: string,
...@@ -126,9 +127,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -126,9 +127,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
const depModMap = new Map<string, any>() const depModMap = new Map<string, any>()
finishModulesSpan.traceChild('get-entries').traceFn(() => { finishModulesSpan.traceChild('get-entries').traceFn(() => {
compilation.entries.forEach((entry) => { compilation.entries.forEach((entry, name) => {
const name = entry.name || entry.options?.name
if (name?.replace(/\\/g, '/').startsWith('pages/')) { if (name?.replace(/\\/g, '/').startsWith('pages/')) {
for (const dep of entry.dependencies) { for (const dep of entry.dependencies) {
if (!dep) continue if (!dep) continue
...@@ -369,7 +368,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -369,7 +368,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
) )
} }
apply(compiler: webpack.Compiler) { apply(compiler: webpack5.Compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
const compilationSpan = spans.get(compilation) || spans.get(compiler)! const compilationSpan = spans.get(compilation) || spans.get(compiler)!
const traceEntrypointsPluginSpan = compilationSpan.traceChild( const traceEntrypointsPluginSpan = compilationSpan.traceChild(
...@@ -420,7 +419,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -420,7 +419,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
missingDependencies: compilation.missingDependencies, missingDependencies: compilation.missingDependencies,
contextDependencies: compilation.contextDependencies, contextDependencies: compilation.contextDependencies,
}, },
async (err: any, result: string, resContext: any) => { async (err: any, result?: string | false, resContext?: any) => {
if (err) return reject(err) if (err) return reject(err)
if (!result) { if (!result) {
......
import type { Compiler, WebpackPluginInstance } from 'webpack5' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { clearSandboxCache } from '../../../server/web/sandbox' import { clearSandboxCache } from '../../../server/web/sandbox'
import { realpathSync } from 'fs' import { realpathSync } from 'fs'
import path from 'path' import path from 'path'
import isError from '../../../lib/is-error' import isError from '../../../lib/is-error'
type Compiler = webpack5.Compiler
type WebpackPluginInstance = webpack5.WebpackPluginInstance
const originModules = [ const originModules = [
require.resolve('../../../server/require'), require.resolve('../../../server/require'),
require.resolve('../../../server/load-components'), require.resolve('../../../server/load-components'),
......
import { NormalModule } from 'next/dist/compiled/webpack/webpack' import { NormalModule } from 'next/dist/compiled/webpack/webpack'
import { Span } from '../../../trace' import { Span } from '../../../trace'
import type webpack from 'webpack' import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
const pluginName = 'ProfilingPlugin' const pluginName = 'ProfilingPlugin'
export const spans = new WeakMap<webpack.Compilation | webpack.Compiler, Span>() export const spans = new WeakMap<webpack.Compilation | webpack.Compiler, Span>()
......
import type { Compiler, Compilation } from 'webpack' import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
type Feature = 'next/image' | 'next/script' | 'next/dynamic' type Feature = 'next/image' | 'next/script' | 'next/dynamic'
...@@ -34,7 +34,7 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([ ...@@ -34,7 +34,7 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
* certain features (e.g. next/image and next/script) and record how many times * certain features (e.g. next/image and next/script) and record how many times
* they are imported. * they are imported.
*/ */
export class TelemetryPlugin { export class TelemetryPlugin implements webpack.WebpackPluginInstance {
private usageTracker = new Map<Feature, FeatureUsage>() private usageTracker = new Map<Feature, FeatureUsage>()
constructor() { constructor() {
...@@ -46,13 +46,13 @@ export class TelemetryPlugin { ...@@ -46,13 +46,13 @@ export class TelemetryPlugin {
} }
} }
apply(compiler: Compiler): void { apply(compiler: webpack.Compiler): void {
compiler.hooks.make.tapAsync( compiler.hooks.make.tapAsync(
TelemetryPlugin.name, TelemetryPlugin.name,
async (compilation: Compilation, callback: () => void) => { async (compilation: webpack.Compilation, callback: () => void) => {
compilation.hooks.finishModules.tapAsync( compilation.hooks.finishModules.tapAsync(
TelemetryPlugin.name, TelemetryPlugin.name,
async (modules: Set<Module>, modulesFinish: () => void) => { async (modules: Iterable<Module>, modulesFinish: () => void) => {
for (const module of modules) { for (const module of modules) {
const feature = findFeatureInModule(module) const feature = findFeatureInModule(module)
if (!feature) { if (!feature) {
......
import type webpack5 from 'webpack5' import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
import { getModuleBuildError } from './webpackModuleError' import { getModuleBuildError } from './webpackModuleError'
export class WellKnownErrorsPlugin { export class WellKnownErrorsPlugin {
apply(compiler: webpack5.Compiler) { apply(compiler: webpack.Compiler) {
compiler.hooks.compilation.tap('WellKnownErrorsPlugin', (compilation) => { compiler.hooks.compilation.tap('WellKnownErrorsPlugin', (compilation) => {
compilation.hooks.afterSeal.tapPromise( compilation.hooks.afterSeal.tapPromise(
'WellKnownErrorsPlugin', 'WellKnownErrorsPlugin',
......
import Chalk from 'chalk' import Chalk from 'chalk'
import { SimpleWebpackError } from './simpleWebpackError' import { SimpleWebpackError } from './simpleWebpackError'
import { createOriginalStackFrame } from '@next/react-dev-overlay/lib/middleware' import { createOriginalStackFrame } from '@next/react-dev-overlay/lib/middleware'
import type webpack5 from 'webpack5' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
const chalk = new Chalk.constructor({ enabled: true }) const chalk = new Chalk.constructor({ enabled: true })
......
import type webpack5 from 'webpack5' import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
// This class creates a simplified webpack error that formats nicely based on // This class creates a simplified webpack error that formats nicely based on
// webpack's build in serializer. // webpack's build in serializer.
// https://github.com/webpack/webpack/blob/c9d4ff7b054fc581c96ce0e53432d44f9dd8ca72/lib/Stats.js#L294-L356 // https://github.com/webpack/webpack/blob/c9d4ff7b054fc581c96ce0e53432d44f9dd8ca72/lib/Stats.js#L294-L356
export class SimpleWebpackError extends (Error as unknown as typeof webpack5.WebpackError) { export class SimpleWebpackError extends (Error as unknown as typeof webpack.WebpackError) {
file: string file: string
constructor(file: string, message: string) { constructor(file: string, message: string) {
......
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import * as path from 'path' import * as path from 'path'
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
import { getBabelError } from './parseBabel' import { getBabelError } from './parseBabel'
import { getCssError } from './parseCss' import { getCssError } from './parseCss'
import { getScssError } from './parseScss' import { getScssError } from './parseScss'
import { getNotFoundError } from './parseNotFoundError' import { getNotFoundError } from './parseNotFoundError'
import { SimpleWebpackError } from './simpleWebpackError' import { SimpleWebpackError } from './simpleWebpackError'
import isError from '../../../../lib/is-error' import isError from '../../../../lib/is-error'
import type webpack5 from 'webpack5'
function getFileData( function getFileData(
compilation: webpack5.Compilation, compilation: webpack.Compilation,
m: any m: any
): [string, string | null] { ): [string, string | null] {
let resolved: string let resolved: string
...@@ -41,7 +41,7 @@ function getFileData( ...@@ -41,7 +41,7 @@ function getFileData(
} }
export async function getModuleBuildError( export async function getModuleBuildError(
compilation: webpack5.Compilation, compilation: webpack.Compilation,
input: any input: any
): Promise<SimpleWebpackError | false> { ): Promise<SimpleWebpackError | false> {
if ( if (
......
import os from 'os' import os from 'os'
import type webpack5 from 'webpack5' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { Header, Redirect, Rewrite } from '../lib/load-custom-routes' import { Header, Redirect, Rewrite } from '../lib/load-custom-routes'
import { import {
ImageConfig, ImageConfig,
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import { webpack } from 'next/dist/compiled/webpack/webpack' import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
import type ws from 'ws' import type ws from 'ws'
export class WebpackHotMiddleware { export class WebpackHotMiddleware {
......
...@@ -4,6 +4,7 @@ import { WebpackHotMiddleware } from './hot-middleware' ...@@ -4,6 +4,7 @@ import { WebpackHotMiddleware } from './hot-middleware'
import { join, relative, isAbsolute } from 'path' import { join, relative, isAbsolute } from 'path'
import { UrlObject } from 'url' import { UrlObject } from 'url'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { import {
createEntrypoints, createEntrypoints,
createPagesMapping, createPagesMapping,
...@@ -103,14 +104,14 @@ function findEntryModule(issuer: any): any { ...@@ -103,14 +104,14 @@ function findEntryModule(issuer: any): any {
return issuer return issuer
} }
function erroredPages(compilation: webpack.compilation.Compilation) { function erroredPages(compilation: webpack5.Compilation) {
const failedPages: { [page: string]: any[] } = {} const failedPages: { [page: string]: any[] } = {}
for (const error of compilation.errors) { for (const error of compilation.errors) {
if (!error.origin) { if (!error.module) {
continue continue
} }
const entryModule = findEntryModule(error.origin) const entryModule = findEntryModule(error.module)
const { name } = entryModule const { name } = entryModule
if (!name) { if (!name) {
continue continue
...@@ -140,8 +141,8 @@ export default class HotReloader { ...@@ -140,8 +141,8 @@ export default class HotReloader {
private pagesDir: string private pagesDir: string
private webpackHotMiddleware?: WebpackHotMiddleware private webpackHotMiddleware?: WebpackHotMiddleware
private config: NextConfigComplete private config: NextConfigComplete
public clientStats: webpack.Stats | null public clientStats: webpack5.Stats | null
public serverStats: webpack.Stats | null public serverStats: webpack5.Stats | null
private clientError: Error | null = null private clientError: Error | null = null
private serverError: Error | null = null private serverError: Error | null = null
private serverPrevDocumentHash: string | null private serverPrevDocumentHash: string | null
...@@ -472,7 +473,7 @@ export default class HotReloader { ...@@ -472,7 +473,7 @@ export default class HotReloader {
// @ts-ignore webpack 5 // @ts-ignore webpack 5
configs.parallelism = 1 configs.parallelism = 1
const multiCompiler = webpack(configs) const multiCompiler = webpack(configs) as unknown as webpack5.MultiCompiler
watchCompilers(multiCompiler.compilers[0], multiCompiler.compilers[1]) watchCompilers(multiCompiler.compilers[0], multiCompiler.compilers[1])
...@@ -485,7 +486,7 @@ export default class HotReloader { ...@@ -485,7 +486,7 @@ export default class HotReloader {
const trackPageChanges = const trackPageChanges =
(pageHashMap: Map<string, string>, changedItems: Set<string>) => (pageHashMap: Map<string, string>, changedItems: Set<string>) =>
(stats: webpack.compilation.Compilation) => { (stats: webpack5.Compilation) => {
stats.entrypoints.forEach((entry, key) => { stats.entrypoints.forEach((entry, key) => {
if (key.startsWith('pages/')) { if (key.startsWith('pages/')) {
// TODO this doesn't handle on demand loaded chunks // TODO this doesn't handle on demand loaded chunks
...@@ -539,7 +540,7 @@ export default class HotReloader { ...@@ -539,7 +540,7 @@ export default class HotReloader {
// Initial value // Initial value
if (this.serverPrevDocumentHash === null) { if (this.serverPrevDocumentHash === null) {
this.serverPrevDocumentHash = documentChunk.hash this.serverPrevDocumentHash = documentChunk.hash || null
return return
} }
...@@ -550,7 +551,7 @@ export default class HotReloader { ...@@ -550,7 +551,7 @@ export default class HotReloader {
// Notify reload to reload the page, as _document.js was changed (different hash) // Notify reload to reload the page, as _document.js was changed (different hash)
this.send('reloadPage') this.send('reloadPage')
this.serverPrevDocumentHash = documentChunk.hash this.serverPrevDocumentHash = documentChunk.hash || null
} }
) )
multiCompiler.hooks.done.tap('NextjsHotReloaderForServer', () => { multiCompiler.hooks.done.tap('NextjsHotReloaderForServer', () => {
......
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { join, posix } from 'path' import { join, posix } from 'path'
import { webpack } from 'next/dist/compiled/webpack/webpack' import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
import { normalizePagePath, normalizePathSep } from '../normalize-page-path' import { normalizePagePath, normalizePathSep } from '../normalize-page-path'
import { pageNotFoundError } from '../require' import { pageNotFoundError } from '../require'
import { findPageFile } from '../lib/find-page-file' import { findPageFile } from '../lib/find-page-file'
...@@ -47,7 +47,7 @@ export default function onDemandEntryHandler( ...@@ -47,7 +47,7 @@ export default function onDemandEntryHandler(
for (const compiler of compilers) { for (const compiler of compilers) {
compiler.hooks.make.tap( compiler.hooks.make.tap(
'NextJsOnDemandEntries', 'NextJsOnDemandEntries',
(_compilation: webpack.compilation.Compilation) => { (_compilation: webpack.Compilation) => {
invalidator.startBuilding() invalidator.startBuilding()
} }
) )
......
...@@ -29,31 +29,26 @@ declare module 'next/dist/compiled/loader-utils' ...@@ -29,31 +29,26 @@ declare module 'next/dist/compiled/loader-utils'
declare module 'next/dist/compiled/webpack/webpack' { declare module 'next/dist/compiled/webpack/webpack' {
import webpackSources from 'webpack-sources1' import webpackSources from 'webpack-sources1'
import webpack4, { loader } from 'webpack4' import webpack4, { loader } from 'webpack4'
export { NormalModule, WebpackError } from 'webpack' import webpack5 from 'webpack5'
export { NormalModule } from 'webpack5'
export function init(): void export function init(): void
export let BasicEvaluatedExpression: any export let BasicEvaluatedExpression: any
export let GraphHelpers: any export let GraphHelpers: any
// TODO change this to webpack4 | webpack5
export let sources: typeof webpackSources export let sources: typeof webpackSources
// TODO change this to webpack // TODO change this to webpack5
export { webpack4 as webpack, loader } export { webpack4 as webpack, loader, webpack4, webpack5 }
} }
declare module 'webpack' { declare module 'webpack' {
import webpack4 from 'webpack4'
import webpack5 from 'webpack5'
export type Compiler = webpack4.Compiler | webpack5.Compiler
export type Compilation =
| webpack4.compilation.Compilation
| webpack5.Compilation
export type Module = webpack4.Module | webpack5.Module
export type Stats = webpack4.Stats | webpack5.Stats
export { export {
Compiler,
Compilation,
Module,
Stats,
Template, Template,
RuntimeModule, RuntimeModule,
RuntimeGlobals, RuntimeGlobals,
NormalModule, NormalModule,
WebpackError,
} from 'webpack5' } from 'webpack5'
} }
......
...@@ -30,6 +30,12 @@ ...@@ -30,6 +30,12 @@
}, },
"peerDependencies": { "peerDependencies": {
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2",
"webpack": "^4 || ^5"
},
"peerDependenciesMeta": {
"webpack": {
"optional": true
}
} }
} }
...@@ -11,7 +11,7 @@ import { StackFrame } from 'stacktrace-parser' ...@@ -11,7 +11,7 @@ import { StackFrame } from 'stacktrace-parser'
import url from 'url' import url from 'url'
// @ts-ignore // @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies // eslint-disable-next-line import/no-extraneous-dependencies
import type webpack from 'webpack4' import type webpack from 'webpack'
import { getRawSourceMap } from './internal/helpers/getRawSourceMap' import { getRawSourceMap } from './internal/helpers/getRawSourceMap'
import { launchEditor } from './internal/helpers/launchEditor' import { launchEditor } from './internal/helpers/launchEditor'
......
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