Skip to content

Commit d812303

Browse files
committed
fix(deps): use built-in isReadable (available since v17.4)
1 parent 903cc41 commit d812303

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/lib/functions/synchronous.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ import express from 'express'
55
import type { LambdaEvent } from 'lambda-local'
66

77
import { chalk, logPadded, NETLIFYDEVERR } from '../../utils/command-helpers.js'
8-
import { isStream as baseIsReadableStream } from '../../utils/is-stream.js'
98
import renderErrorTemplate from '../render-error-template.js'
109

1110
import { detectAwsSdkError } from './utils.js'
1211
import type { InvocationError } from './netlify-function.js'
13-
14-
// Annoyingly, `isReadableStream` refines to the `Readable` interface rather than the
15-
// `ReadableStream` class. Refining to the class makes further refinements work as expected.
16-
const isReadableStream = (value: unknown): value is NodeJS.ReadableStream => baseIsReadableStream(value)
12+
import { isReadable } from 'stream'
1713

1814
const addHeaders = (headers: undefined | Record<string, string | string[]>, response: express.Response): void => {
1915
if (!headers) {
@@ -89,13 +85,12 @@ export const handleSynchronousFunction = async function ({
8985
}
9086

9187
if (result.body) {
92-
if (isReadableStream(result.body)) {
93-
result.body.pipe(response)
88+
if (isReadable(result.body as NodeJS.ReadableStream)) {
89+
(result.body as NodeJS.ReadableStream).pipe(response)
9490

9591
return
9692
}
97-
98-
response.write(result.isBase64Encoded ? Buffer.from(result.body, 'base64') : result.body)
93+
response.write(result.isBase64Encoded ? Buffer.from(result.body as string, 'base64') : result.body)
9994
}
10095
response.end()
10196
}
@@ -182,7 +177,7 @@ const validateLambdaResponse = (lambdaResponse: undefined | null | LambdaEvent):
182177
error: `Your function response must have a numerical statusCode. You gave: ${inspect(lambdaResponse.statusCode)}`,
183178
}
184179
}
185-
if (lambdaResponse.body && typeof lambdaResponse.body !== 'string' && !isReadableStream(lambdaResponse.body)) {
180+
if (lambdaResponse.body && typeof lambdaResponse.body !== 'string' && !isReadable(lambdaResponse.body)) {
186181
return {
187182
error: `Your function response must have a string or a stream body. You gave: ${inspect(lambdaResponse.body)}`,
188183
}

0 commit comments

Comments
 (0)