Skip to content

Commit

Permalink
Bump @types/node (vercel#50940)
Browse files Browse the repository at this point in the history
This bumps @types/node to 20.2.5 to prepare for upgrades to other packages requiring updated Node.js typescript types.
  • Loading branch information
wyattjoh authored Jun 8, 2023
1 parent b8e08ab commit ea63e92
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 95 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@types/html-validator": "5.0.3",
"@types/http-proxy": "1.17.3",
"@types/jest": "24.0.13",
"@types/node": "14.14.31",
"@types/node": "20.2.5",
"@types/node-fetch": "2.6.1",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"@types/ci-info": "2.0.0",
"@types/cross-spawn": "6.0.0",
"@types/glob": "7.1.1",
"@types/node": "^16.8.0",
"@types/node": "^20.2.5",
"@types/prompts": "2.0.1",
"@types/tar": "4.0.3",
"@types/tar": "6.1.5",
"@types/validate-npm-package-name": "3.0.0",
"@vercel/ncc": "0.34.0",
"async-retry": "1.3.1",
Expand All @@ -49,7 +49,7 @@
"got": "10.7.0",
"prettier-plugin-tailwindcss": "0.2.4",
"prompts": "2.1.0",
"tar": "4.4.10",
"tar": "6.1.15",
"update-check": "1.5.4",
"validate-npm-package-name": "3.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"@types/semver": "7.3.1",
"@types/send": "0.14.4",
"@types/shell-quote": "1.7.1",
"@types/tar": "4.0.3",
"@types/tar": "6.1.5",
"@types/text-table": "0.2.1",
"@types/ua-parser-js": "0.7.36",
"@types/uuid": "8.3.1",
Expand Down Expand Up @@ -291,7 +291,7 @@
"string-hash": "1.1.3",
"string_decoder": "1.3.0",
"strip-ansi": "6.0.0",
"tar": "6.1.11",
"tar": "6.1.15",
"taskr": "1.1.0",
"terser": "5.14.1",
"text-table": "0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/compiled/tar/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/src/compiled/tar/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"tar","main":"index.js","author":"Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)","license":"ISC"}
{"name":"tar","main":"index.js","author":"GitHub Inc.","license":"ISC"}
2 changes: 1 addition & 1 deletion packages/next/src/server/api-utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export async function apiResolver(
)
}

endResponse.apply(apiRes, args)
return endResponse.apply(apiRes, args)
}
apiRes.status = (statusCode) => sendStatusCode(apiRes, statusCode)
apiRes.send = (data) => sendData(apiReq, apiRes, data)
Expand Down
8 changes: 5 additions & 3 deletions packages/next/src/server/dev/hot-reloader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { webpack, StringXor } from 'next/dist/compiled/webpack/webpack'
import type { NextConfigComplete } from '../config-shared'
import type { CustomRoutes } from '../../lib/load-custom-routes'
import type { Duplex } from 'stream'
import type { Telemetry } from '../../telemetry/storage'

import { webpack, StringXor } from 'next/dist/compiled/webpack/webpack'
import { getOverlayMiddleware } from 'next/dist/compiled/@next/react-dev-overlay/dist/middleware'
import { IncomingMessage, ServerResponse } from 'http'
import { WebpackHotMiddleware } from './hot-middleware'
Expand Down Expand Up @@ -56,7 +59,6 @@ import { promises as fs } from 'fs'
import { UnwrapPromise } from '../../lib/coalesced-function'
import { getRegistry } from '../../lib/helpers/get-registry'
import { RouteMatch } from '../future/route-matches/route-match'
import type { Telemetry } from '../../telemetry/storage'
import { parseVersionInfo, VersionInfo } from './parse-version-info'
import { isAPIRoute } from '../../lib/is-api-route'
import { getRouteLoaderEntry } from '../../build/webpack/loaders/next-route-loader'
Expand Down Expand Up @@ -325,7 +327,7 @@ export default class HotReloader {
return { finished }
}

public onHMR(req: IncomingMessage, _res: ServerResponse, head: Buffer) {
public onHMR(req: IncomingMessage, _socket: Duplex, head: Buffer) {
wsServer.handleUpgrade(req, req.socket, head, (client) => {
this.webpackHotMiddleware?.onHMR(client)
this.onDemandEntries?.onHMR(client)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ export default class DevServer extends Server {
this.hotReloader?.onHMR(req, socket, head)
}
} else {
this.handleUpgrade(req, socket, head)
this.handleUpgrade(req as any as NodeNextRequest, socket, head)
}
})
}
Expand Down
90 changes: 81 additions & 9 deletions packages/next/src/server/lib/mock-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import type { Socket } from 'net'
import type { TLSSocket } from 'tls'

import Stream from 'stream'
import { toNodeOutgoingHttpHeaders } from '../web/utils'
import {
fromNodeOutgoingHttpHeaders,
toNodeOutgoingHttpHeaders,
} from '../web/utils'

interface MockedRequestOptions {
url: string
Expand Down Expand Up @@ -56,6 +59,17 @@ export class MockedRequest extends Stream.Readable implements IncomingMessage {
}
}

public get headersDistinct(): NodeJS.Dict<string[]> {
const headers: NodeJS.Dict<string[]> = {}
for (const [key, value] of Object.entries(this.headers)) {
if (!value) continue

headers[key] = Array.isArray(value) ? value : [value]
}

return headers
}

public _read(): void {
this.emit('end')
this.emit('close')
Expand Down Expand Up @@ -85,6 +99,10 @@ export class MockedRequest extends Stream.Readable implements IncomingMessage {
throw new Error('Method not implemented')
}

public get trailersDistinct(): NodeJS.Dict<string[]> {
throw new Error('Method not implemented')
}

public get rawTrailers(): string[] {
throw new Error('Method not implemented')
}
Expand All @@ -98,33 +116,49 @@ export class MockedRequest extends Stream.Readable implements IncomingMessage {
}
}

interface MockedResponseOptions {
export interface MockedResponseOptions {
statusCode?: number
socket?: Socket | null
headers?: OutgoingHttpHeaders
}

export class MockedResponse extends Stream.Writable implements ServerResponse {
public statusCode: number = 200
public statusCode: number
public statusMessage: string = ''
public readonly finished = false
public readonly headersSent = false
public finished = false
public headersSent = false
public readonly socket: Socket | null

/**
* A promise that resolves to `true` when the response has been streamed.
*
* @internal - used internally by Next.js
*/
public readonly hasStreamed: Promise<boolean>

/**
* A list of buffers that have been written to the response.
*
* @internal - used internally by Next.js
*/
public readonly buffers: Buffer[] = []

private readonly headers = new Headers()
/**
* The headers object that contains the headers that were initialized on the
* response and any that were added subsequently.
*
* @internal - used internally by Next.js
*/
public readonly headers: Headers

constructor({ socket = null }: MockedResponseOptions) {
constructor(res: MockedResponseOptions = {}) {
super()

this.socket = socket
this.statusCode = res.statusCode ?? 200
this.socket = res.socket ?? null
this.headers = res.headers
? fromNodeOutgoingHttpHeaders(res.headers)
: new Headers()

// Attach listeners for the `finish`, `end`, and `error` events to the
// `MockedResponse` instance.
Expand All @@ -135,6 +169,24 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
})
}

public appendHeader(name: string, value: string | string[]): this {
const values = Array.isArray(value) ? value : [value]
for (const v of values) {
this.headers.append(name, v)
}

return this
}

/**
* Returns true if the response has been sent, false otherwise.
*
* @internal - used internally by Next.js
*/
public get isSent() {
return this.finished || this.headersSent
}

/**
* The `connection` property is just an alias for the `socket` property.
*
Expand All @@ -150,6 +202,11 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
return true
}

public end() {
this.finished = true
return super.end(...arguments)
}

/**
* This method is a no-op because the `MockedResponse` instance is not
* actually connected to a socket. This method is not specified on the
Expand Down Expand Up @@ -227,6 +284,7 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
}

this.statusCode = statusCode
this.headersSent = true

return this
}
Expand All @@ -247,7 +305,7 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
return Array.from(this.headers.keys())
}

public setHeader(name: string, value: OutgoingHttpHeader): void {
public setHeader(name: string, value: OutgoingHttpHeader) {
if (Array.isArray(value)) {
// Because `set` here should override any existing values, we need to
// delete the existing values before setting the new ones via `append`.
Expand All @@ -261,6 +319,8 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
} else {
this.headers.set(name, value)
}

return this
}

public removeHeader(name: string): void {
Expand All @@ -270,6 +330,18 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
// The following methods are not implemented as they are not used in the
// Next.js codebase.

public get strictContentLength(): boolean {
throw new Error('Method not implemented.')
}

public writeEarlyHints() {
throw new Error('Method not implemented.')
}

public get req(): IncomingMessage {
throw new Error('Method not implemented.')
}

public assignSocket() {
throw new Error('Method not implemented.')
}
Expand Down
10 changes: 6 additions & 4 deletions packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { Duplex } from 'stream'
import type { IncomingMessage, ServerResponse } from 'http'
import type { ChildProcess } from 'child_process'

import http from 'http'
import { isIPv6 } from 'net'
import * as Log from '../../build/output/log'
import type { IncomingMessage, ServerResponse } from 'http'
import type { ChildProcess } from 'child_process'
import { normalizeRepeatedSlashes } from '../../shared/lib/utils'
import { initialEnv } from '@next/env'
import { genExecArgv, getNodeOptionsWithoutInspect } from './utils'
Expand Down Expand Up @@ -36,7 +38,7 @@ export async function startServer({
onStdout,
onStderr,
}: StartServerOptions): Promise<TeardownServer> {
const sockets = new Set<ServerResponse>()
const sockets = new Set<ServerResponse | Duplex>()
let worker: import('next/dist/compiled/jest-worker').Worker | undefined
let handlersReady = () => {}
let handlersError = () => {}
Expand Down Expand Up @@ -71,7 +73,7 @@ export async function startServer({
}
let upgradeHandler = async (
_req: IncomingMessage,
_socket: ServerResponse,
_socket: ServerResponse | Duplex,
_head: Buffer
): Promise<void> => {
if (handlersPromise) {
Expand Down
Loading

0 comments on commit ea63e92

Please sign in to comment.