Skip to content

Commit

Permalink
types: update types for webpack-dev-middleware@5
Browse files Browse the repository at this point in the history
  • Loading branch information
serhalp committed Sep 24, 2024
1 parent 7a350ee commit a956da4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby/src/services/start-webpack-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,7 +29,7 @@ export async function startWebpackServer({
}: Partial<IBuildContext>): Promise<{
compiler: Compiler
websocketManager: WebsocketManager
webpackWatching: IWebpackWatchingPauseResume
webpackWatching: WebpackWatching
}> {
if (!program || !app || !store) {
report.panic(`Missing required params`)
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -46,7 +46,7 @@ export interface IBuildContext {
nodeMutationBatch?: Array<IMutationAction>
compiler?: Compiler
websocketManager?: WebsocketManager
webpackWatching?: IWebpackWatchingPauseResume
webpackWatching?: WebpackWatching
webpackListener?: Actor<unknown, AnyEventObject>
queryFilesDirty?: boolean
sourceFilesDirty?: boolean
Expand Down
14 changes: 6 additions & 8 deletions packages/gatsby/src/utils/start-server.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<Watching>

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(
Expand Down Expand Up @@ -895,6 +892,7 @@ export async function startServer(
webpackActivity,
websocketManager,
workerPool,
webpackWatching: webpackDevMiddlewareInstance.context.watching,
webpackWatching: webpackDevMiddlewareInstance.context
.watching as WebpackWatching,
}
}

0 comments on commit a956da4

Please sign in to comment.