From c28e771e4c73e98df0a41a224ecc9b5a3fbe4b79 Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Tue, 24 Sep 2024 08:12:59 -0400 Subject: [PATCH] types: update types for webpack-dev-middleware@5 --- .../gatsby/src/services/start-webpack-server.ts | 4 ++-- packages/gatsby/src/services/types.ts | 4 ++-- packages/gatsby/src/utils/start-server.ts | 14 ++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/gatsby/src/services/start-webpack-server.ts b/packages/gatsby/src/services/start-webpack-server.ts index 444256798a896..73d8b58e0aa22 100644 --- a/packages/gatsby/src/services/start-webpack-server.ts +++ b/packages/gatsby/src/services/start-webpack-server.ts @@ -12,7 +12,7 @@ import { import { showExperimentNotices } from "../utils/show-experiment-notice" import { printInstructions } from "../utils/print-instructions" import { prepareUrls } from "../utils/prepare-urls" -import { startServer, IWebpackWatchingPauseResume } from "../utils/start-server" +import { startServer, WebpackWatching } from "../utils/start-server" import { WebsocketManager } from "../utils/websocket-manager" import { IBuildContext } from "./" import { @@ -29,7 +29,7 @@ export async function startWebpackServer({ }: Partial): Promise<{ compiler: Compiler websocketManager: WebsocketManager - webpackWatching: IWebpackWatchingPauseResume + webpackWatching: WebpackWatching }> { if (!program || !app || !store) { report.panic(`Missing required params`) diff --git a/packages/gatsby/src/services/types.ts b/packages/gatsby/src/services/types.ts index 520db6b2e7abf..4e5c68defb6d5 100644 --- a/packages/gatsby/src/services/types.ts +++ b/packages/gatsby/src/services/types.ts @@ -10,7 +10,7 @@ import type { GatsbyWorkerPool } from "../utils/worker/pool" import { Actor, AnyEventObject } from "xstate" import { Compiler } from "webpack" import { WebsocketManager } from "../utils/websocket-manager" -import { IWebpackWatchingPauseResume } from "../utils/start-server" +import { type WebpackWatching } from "../utils/start-server" type Reporter = typeof reporter @@ -46,7 +46,7 @@ export interface IBuildContext { nodeMutationBatch?: Array compiler?: Compiler websocketManager?: WebsocketManager - webpackWatching?: IWebpackWatchingPauseResume + webpackWatching?: WebpackWatching webpackListener?: Actor queryFilesDirty?: boolean sourceFilesDirty?: boolean diff --git a/packages/gatsby/src/utils/start-server.ts b/packages/gatsby/src/utils/start-server.ts index 2e3d177ca00c7..65ac90d0901de 100644 --- a/packages/gatsby/src/utils/start-server.ts +++ b/packages/gatsby/src/utils/start-server.ts @@ -1,5 +1,5 @@ import webpackHotMiddleware from "@gatsbyjs/webpack-hot-middleware" -import webpackDevMiddleware from "webpack-dev-middleware" +import webpackDevMiddleware, { type Watching } from "webpack-dev-middleware" import got, { Method } from "got" import webpack, { Compilation } from "webpack" import express from "express" @@ -54,18 +54,15 @@ import { isFileInsideCompilations } from "./webpack/utils/is-file-inside-compila type ActivityTracker = any // TODO: Replace this with proper type once reporter is typed +export type WebpackWatching = NonNullable + interface IServer { compiler: webpack.Compiler listener: http.Server | https.Server webpackActivity: ActivityTracker websocketManager: WebsocketManager workerPool: WorkerPool.GatsbyWorkerPool - webpackWatching: IWebpackWatchingPauseResume -} - -export interface IWebpackWatchingPauseResume { - suspend: () => void - resume: () => void + webpackWatching: WebpackWatching } export async function startServer( @@ -895,6 +892,7 @@ export async function startServer( webpackActivity, websocketManager, workerPool, - webpackWatching: webpackDevMiddlewareInstance.context.watching, + webpackWatching: webpackDevMiddlewareInstance.context + .watching as WebpackWatching, } }