Unverified Commit 392c4d0b authored by Javi Velasco's avatar Javi Velasco Committed by GitHub

Update @types/node to 14.14.31 (#41634)

This PR updates `@types/node` to `14.14.31`. The most important type is
that `ParsedUrlQuery` can hold `undefined` so we are updating the code
here to explicitly handle those cases. Aside from it we are adding a
global definition taken from NodeJS for `AsyncLocalStorage` that we
export in `server.d.ts`
parent b5251604
......@@ -79,7 +79,7 @@
"@types/html-validator": "5.0.3",
"@types/http-proxy": "1.17.3",
"@types/jest": "24.0.13",
"@types/node": "13.11.0",
"@types/node": "14.14.31",
"@types/node-fetch": "2.6.1",
"@types/react": "16.9.17",
"@types/react-dom": "16.9.4",
......
......@@ -108,19 +108,19 @@ export function interpolateDynamicPath(
if (paramIdx > -1) {
let paramValue: string
const value = params[param]
if (Array.isArray(params[param])) {
paramValue = (params[param] as string[])
.map((v) => v && encodeURIComponent(v))
.join('/')
if (Array.isArray(value)) {
paramValue = value.map((v) => v && encodeURIComponent(v)).join('/')
} else if (value) {
paramValue = encodeURIComponent(value)
} else {
paramValue =
params[param] && encodeURIComponent(params[param] as string)
paramValue = ''
}
pathname =
pathname.slice(0, paramIdx) +
(paramValue || '') +
paramValue +
pathname.slice(paramIdx + builtParam.length)
}
}
......@@ -293,7 +293,7 @@ export function getUtils({
// favor named matches if available
const routeKeyNames = Object.keys(routeKeys || {})
const filterLocaleItem = (val: string | string[]) => {
const filterLocaleItem = (val: string | string[] | undefined) => {
if (i18n) {
// locale items can be included in route-matches
// for fallback SSG pages so ensure they are
......@@ -604,7 +604,7 @@ export function getUtils({
),
interpolateDynamicPath: (
pathname: string,
params: Record<string, string | string[]>
params: Record<string, undefined | string | string[]>
) => interpolateDynamicPath(pathname, params, defaultRouteRegex),
}
}
This diff is collapsed.
......@@ -324,7 +324,7 @@ export default async function exportPage({
results.fromBuildExportRevalidate = revalidate
if (revalidate !== 0) {
await promises.writeFile(htmlFilepath, html, 'utf8')
await promises.writeFile(htmlFilepath, html ?? '', 'utf8')
await promises.writeFile(
htmlFilepath.replace(/\.html$/, '.rsc'),
flightData
......
......@@ -44,7 +44,7 @@ export class Worker {
})
}
let hangingTimer: number | false = false
let hangingTimer: NodeJS.Timeout | false = false
const onActivity = () => {
if (hangingTimer) clearTimeout(hangingTimer)
......
import type { AsyncLocalStorage as NodeAsyncLocalStorage } from 'async_hooks'
declare global {
var AsyncLocalStorage: typeof NodeAsyncLocalStorage
}
export { NextFetchEvent } from 'next/dist/server/web/spec-extension/fetch-event'
export { NextRequest } from 'next/dist/server/web/spec-extension/request'
export { NextResponse } from 'next/dist/server/web/spec-extension/response'
......
......@@ -103,14 +103,13 @@ export const createHeaderRoute = ({
// values from rewrites/redirects
export const stringifyQuery = (req: BaseNextRequest, query: ParsedUrlQuery) => {
const initialQuery = getRequestMeta(req, '__NEXT_INIT_QUERY') || {}
const initialQueryValues: Array<string | string[]> =
Object.values(initialQuery)
const initialQueryValues = Object.values(initialQuery)
return stringifyQs(query, undefined, undefined, {
encodeURIComponent(value) {
if (
value in initialQuery ||
initialQueryValues.some((initialQueryVal: string | string[]) => {
initialQueryValues.some((initialQueryVal) => {
// `value` always refers to a query value, even if it's nested in an array
return Array.isArray(initialQueryVal)
? initialQueryVal.includes(value)
......
......@@ -197,7 +197,7 @@ export function prepareDestination(args: {
destQuery[key] = strOrArray.map((value) =>
compileNonPath(unescapeSegments(value), args.params)
)
} else {
} else if (typeof strOrArray === 'string') {
destQuery[key] = compileNonPath(unescapeSegments(strOrArray), args.params)
}
}
......
......@@ -16,7 +16,7 @@ export function searchParamsToUrlQuery(
return query
}
function stringifyUrlQueryParam(param: string): string {
function stringifyUrlQueryParam(param: unknown): string {
if (
typeof param === 'string' ||
(typeof param === 'number' && !isNaN(param)) ||
......
......@@ -55,7 +55,7 @@ let batch: ReturnType<typeof batcher> | undefined
const writeStreamOptions = {
flags: 'a',
encoding: 'utf8',
encoding: 'utf8' as const,
}
class RotatingWriteStream {
file: string
......
This diff is collapsed.
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