Skip to content

Commit 71ab7ba

Browse files
refactor: merge all utils
1 parent 3ef2985 commit 71ab7ba

20 files changed

Lines changed: 727 additions & 943 deletions

src/index.js

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const memfs = require("memfs");
44
const mime = require("mime-types");
55

66
const middleware = require("./middleware");
7-
const getFilenameFromUrl = require("./utils/getFilenameFromUrl");
8-
const ready = require("./utils/ready");
97

108
const noop = () => {};
119

@@ -16,6 +14,12 @@ const noop = () => {};
1614
/** @typedef {import("webpack").Stats} Stats */
1715
/** @typedef {import("webpack").MultiStats} MultiStats */
1816
/** @typedef {import("fs").ReadStream} ReadStream */
17+
/** @typedef {import("./middleware").Extra} Extra */
18+
19+
// eslint-disable-next-line jsdoc/reject-any-type
20+
/** @typedef {any} EXPECTED_ANY */
21+
// eslint-disable-next-line jsdoc/reject-function-type
22+
/** @typedef {Function} EXPECTED_FUNCTION */
1923

2024
/**
2125
* @typedef {object} ExtendedServerResponse
@@ -25,33 +29,16 @@ const noop = () => {};
2529
/** @typedef {import("http").IncomingMessage} IncomingMessage */
2630
/** @typedef {import("http").ServerResponse & ExtendedServerResponse} ServerResponse */
2731

28-
// eslint-disable-next-line jsdoc/reject-any-type
29-
/** @typedef {any} EXPECTED_ANY */
30-
// eslint-disable-next-line jsdoc/reject-function-type
31-
/** @typedef {Function} EXPECTED_FUNCTION */
32-
3332
/**
3433
* @callback NextFunction
3534
* @param {EXPECTED_ANY=} err error
3635
* @returns {void}
3736
*/
3837

39-
/**
40-
* @typedef {NonNullable<Configuration["watchOptions"]>} WatchOptions
41-
*/
42-
43-
/**
44-
* @typedef {Compiler["watching"]} Watching
45-
*/
46-
47-
/**
48-
* @typedef {ReturnType<MultiCompiler["watch"]>} MultiWatching
49-
*/
50-
51-
/**
52-
* @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem
53-
*/
54-
38+
/** @typedef {NonNullable<Configuration["watchOptions"]>} WatchOptions */
39+
/** @typedef {Compiler["watching"]} Watching */
40+
/** @typedef {ReturnType<MultiCompiler["watch"]>} MultiWatching */
41+
/** @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem */
5542
/** @typedef {ReturnType<Compiler["getInfrastructureLogger"]>} Logger */
5643

5744
/**
@@ -136,8 +123,6 @@ const noop = () => {};
136123
* @returns {Promise<void>}
137124
*/
138125

139-
/** @typedef {import("./utils/getFilenameFromUrl").Extra} Extra */
140-
141126
/**
142127
* @callback GetFilenameFromUrl
143128
* @param {string} url request URL
@@ -583,14 +568,15 @@ function wdm(compiler, options = {}, isPlugin = false) {
583568
(middleware(filledContext));
584569

585570
// API
586-
instance.getFilenameFromUrl = (url) => getFilenameFromUrl(filledContext, url);
571+
instance.getFilenameFromUrl = (url) =>
572+
middleware.getFilenameFromUrl(filledContext, url);
587573

588574
instance.waitUntilValid = (callback = noop) => {
589-
ready(filledContext, callback);
575+
middleware.ready(filledContext, callback);
590576
};
591577

592578
instance.invalidate = (callback = noop) => {
593-
ready(filledContext, callback);
579+
middleware.ready(filledContext, callback);
594580

595581
filledContext.watching.invalidate();
596582
};
@@ -707,7 +693,7 @@ function koaWrapper(compiler, options = {}, usePlugin = false) {
707693
const devMiddleware = wdm(compiler, options, usePlugin);
708694

709695
/**
710-
* @param {{ req: RequestInternal, res: ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse, status: number, body: string | Buffer | import("fs").ReadStream | { message: string }, state: object }} ctx context
696+
* @param {{ req: RequestInternal, res: ResponseInternal & import("./utils").ExpectedServerResponse, status: number, body: string | Buffer | import("fs").ReadStream | { message: string }, state: object }} ctx context
711697
* @param {EXPECTED_FUNCTION} next next
712698
* @returns {Promise<void>}
713699
*/
@@ -850,7 +836,7 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
850836
const devMiddleware = wdm(compiler, options, usePlugin);
851837

852838
/**
853-
* @param {{ env: EXPECTED_ANY, body: EXPECTED_ANY, json: EXPECTED_ANY, status: EXPECTED_ANY, set: EXPECTED_ANY, req: RequestInternal & import("./utils/compatibleAPI").ExpectedIncomingMessage & { header: (name: string) => string }, res: ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY } }} context context
839+
* @param {{ env: EXPECTED_ANY, body: EXPECTED_ANY, json: EXPECTED_ANY, status: EXPECTED_ANY, set: EXPECTED_ANY, req: RequestInternal & import("./utils").ExpectedIncomingMessage & { header: (name: string) => string }, res: ResponseInternal & import("./utils").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY } }} context context
854840
* @param {EXPECTED_FUNCTION} next next function
855841
* @returns {Promise<void>}
856842
*/
@@ -898,7 +884,7 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
898884
/**
899885
* @param {string} name header name
900886
* @param {string | number | Readonly<string[]>} value value
901-
* @returns {ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY }} response
887+
* @returns {ResponseInternal & import("./utils").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY }} response
902888
*/
903889
res.setHeader = (name, value) => {
904890
context.res.headers.append(name, value);

0 commit comments

Comments
 (0)