Skip to content

Commit ecd60f2

Browse files
refactor: remove outdated code
1 parent 71c0358 commit ecd60f2

2 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/middleware.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,26 +259,11 @@ const CACHE_CONTROL_NO_CACHE_REGEXP = /(?:^|,)\s*?no-cache\s*?(?:,|$)/;
259259
* @returns {void}
260260
*/
261261
function destroyStream(stream, suppress) {
262-
if (typeof stream.destroy === "function") {
263-
stream.destroy();
262+
if (stream.destroyed) {
263+
return;
264264
}
265265

266-
if (typeof stream.close === "function") {
267-
// Node.js core bug workaround
268-
stream.on(
269-
"open",
270-
/**
271-
* @this {import("fs").ReadStream}
272-
*/
273-
function onOpenClose() {
274-
// @ts-expect-error
275-
if (typeof this.fd === "number") {
276-
// actually close down the fd
277-
this.close();
278-
}
279-
},
280-
);
281-
}
266+
stream.destroy();
282267

283268
if (typeof stream.addListener === "function" && suppress) {
284269
stream.removeAllListeners("error");

types/middleware.d.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare namespace wrapper {
1515
export {
1616
getFilenameFromUrl,
1717
ready,
18+
FilenameWithExtra,
1819
SendErrorOptions,
1920
ReadStream,
2021
Compiler,
@@ -25,28 +26,25 @@ declare namespace wrapper {
2526
IncomingMessage,
2627
ServerResponse,
2728
NormalizedHeaders,
29+
OutputFileSystem,
2830
Extra,
2931
};
3032
}
33+
/** @typedef {{ filename: string, extra: Extra }} FilenameWithExtra */
3134
/**
3235
* @template {IncomingMessage} Request
3336
* @template {ServerResponse} Response
3437
* @param {import("./index.js").FilledContext<Request, Response>} context context
3538
* @param {string} url url
36-
* @returns {{ filename: string, extra: Extra } | undefined} result of get filename from url
39+
* @returns {FilenameWithExtra | undefined} result of get filename from url
3740
*/
3841
declare function getFilenameFromUrl<
3942
Request extends IncomingMessage,
4043
Response extends ServerResponse,
4144
>(
4245
context: import("./index.js").FilledContext<Request, Response>,
4346
url: string,
44-
):
45-
| {
46-
filename: string;
47-
extra: Extra;
48-
}
49-
| undefined;
47+
): FilenameWithExtra | undefined;
5048
/**
5149
* @template {IncomingMessage} Request
5250
* @template {ServerResponse} Response
@@ -70,6 +68,10 @@ declare function ready<
7068
callback: import("./index.js").Callback,
7169
req?: Request | undefined,
7270
): void;
71+
type FilenameWithExtra = {
72+
filename: string;
73+
extra: Extra;
74+
};
7375
/**
7476
* send error options
7577
*/
@@ -97,6 +99,7 @@ type NextFunction = import("./index.js").NextFunction;
9799
type IncomingMessage = import("./index.js").IncomingMessage;
98100
type ServerResponse = import("./index.js").ServerResponse;
99101
type NormalizedHeaders = import("./index.js").NormalizedHeaders;
102+
type OutputFileSystem = import("./index.js").OutputFileSystem;
100103
type Extra = {
101104
/**
102105
* stats
@@ -106,4 +109,8 @@ type Extra = {
106109
* true when immutable, otherwise false
107110
*/
108111
immutable?: boolean | undefined;
112+
/**
113+
* outputFileSystem
114+
*/
115+
outputFileSystem: OutputFileSystem;
109116
};

0 commit comments

Comments
 (0)