Skip to content

Commit a4db208

Browse files
refactor: code
1 parent 9e1cc76 commit a4db208

2 files changed

Lines changed: 7 additions & 85 deletions

File tree

src/index.js

Lines changed: 6 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ function wdm(compiler, options = {}, isPlugin = false) {
323323
/**
324324
* @template HapiServer
325325
* @template {HapiOptions} HapiOptionsInternal
326-
* @param {boolean} usePlugin whether to use as webpack plugin
326+
* @param {boolean=} usePlugin true when need to use as a plugin, otherwise false
327327
* @returns {HapiPlugin<HapiServer, HapiOptionsInternal>} hapi wrapper
328328
*/
329-
function createHapiWrapper(usePlugin = false) {
329+
function hapiWrapper(usePlugin = false) {
330330
return {
331331
pkg: {
332332
name: "webpack-dev-middleware",
@@ -397,36 +397,17 @@ function createHapiWrapper(usePlugin = false) {
397397
};
398398
}
399399

400-
/**
401-
* @template HapiServer
402-
* @template {HapiOptions} HapiOptionsInternal
403-
* @returns {HapiPlugin<HapiServer, HapiOptionsInternal>} hapi wrapper
404-
*/
405-
function hapiWrapper() {
406-
return createHapiWrapper(false);
407-
}
408-
409-
/**
410-
* @template HapiServer
411-
* @template {HapiOptions} HapiOptionsInternal
412-
* @returns {HapiPlugin<HapiServer, HapiOptionsInternal>} hapi plugin wrapper
413-
*/
414-
function hapiPluginWrapper() {
415-
return createHapiWrapper(true);
416-
}
417-
418400
wdm.hapiWrapper = hapiWrapper;
419-
wdm.hapiPluginWrapper = hapiPluginWrapper;
420401

421402
/**
422403
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
423404
* @template {ServerResponse} [ResponseInternal=ServerResponse]
424405
* @param {Compiler | MultiCompiler} compiler compiler
425406
* @param {Options<RequestInternal, ResponseInternal>=} options options
426-
* @param {boolean} usePlugin whether to use as webpack plugin
407+
* @param {boolean=} usePlugin whether to use as webpack plugin
427408
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} kow wrapper
428409
*/
429-
function createKoaWrapper(compiler, options, usePlugin = false) {
410+
function koaWrapper(compiler, options, usePlugin) {
430411
const devMiddleware = wdm(compiler, options, usePlugin);
431412

432413
if (usePlugin) {
@@ -542,40 +523,17 @@ function createKoaWrapper(compiler, options, usePlugin = false) {
542523
return webpackDevMiddleware;
543524
}
544525

545-
/**
546-
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
547-
* @template {ServerResponse} [ResponseInternal=ServerResponse]
548-
* @param {Compiler | MultiCompiler} compiler compiler
549-
* @param {Options<RequestInternal, ResponseInternal>=} options options
550-
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} kow wrapper
551-
*/
552-
function koaWrapper(compiler, options) {
553-
return createKoaWrapper(compiler, options, false);
554-
}
555-
556-
/**
557-
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
558-
* @template {ServerResponse} [ResponseInternal=ServerResponse]
559-
* @param {Compiler | MultiCompiler} compiler compiler
560-
* @param {Options<RequestInternal, ResponseInternal>=} options options
561-
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} kow plugin wrapper
562-
*/
563-
function koaPluginWrapper(compiler, options) {
564-
return createKoaWrapper(compiler, options, true);
565-
}
566-
567526
wdm.koaWrapper = koaWrapper;
568-
wdm.koaPluginWrapper = koaPluginWrapper;
569527

570528
/**
571529
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
572530
* @template {ServerResponse} [ResponseInternal=ServerResponse]
573531
* @param {Compiler | MultiCompiler} compiler compiler
574532
* @param {Options<RequestInternal, ResponseInternal>=} options options
575-
* @param {boolean} usePlugin whether to use as webpack plugin
533+
* @param {boolean=} usePlugin true when need to use as a plugin, otherwise false
576534
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} hono wrapper
577535
*/
578-
function createHonoWrapper(compiler, options, usePlugin = false) {
536+
function honoWrapper(compiler, options, usePlugin) {
579537
const devMiddleware = wdm(compiler, options, usePlugin);
580538

581539
/**
@@ -743,42 +701,6 @@ function createHonoWrapper(compiler, options, usePlugin = false) {
743701
return webpackDevMiddleware;
744702
}
745703

746-
/**
747-
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
748-
* @template {ServerResponse} [ResponseInternal=ServerResponse]
749-
* @param {Compiler | MultiCompiler} compiler compiler
750-
* @param {Options<RequestInternal, ResponseInternal>=} options options
751-
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} hono wrapper
752-
*/
753-
function honoWrapper(compiler, options) {
754-
return createHonoWrapper(compiler, options, false);
755-
}
756-
757-
/**
758-
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
759-
* @template {ServerResponse} [ResponseInternal=ServerResponse]
760-
* @param {Compiler | MultiCompiler} compiler compiler
761-
* @param {Options<RequestInternal, ResponseInternal>=} options options
762-
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} hono plugin wrapper
763-
*/
764-
function honoPluginWrapper(compiler, options) {
765-
return createHonoWrapper(compiler, options, true);
766-
}
767-
768704
wdm.honoWrapper = honoWrapper;
769-
wdm.honoPluginWrapper = honoPluginWrapper;
770-
771-
/**
772-
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
773-
* @template {ServerResponse} [ResponseInternal=ServerResponse]
774-
* @param {Compiler | MultiCompiler} compiler compiler
775-
* @param {Options<RequestInternal, ResponseInternal>=} options options
776-
* @returns {API<RequestInternal, ResponseInternal>} webpack dev middleware
777-
*/
778-
function plugin(compiler, options = {}) {
779-
return wdm(compiler, options, true);
780-
}
781-
782-
wdm.plugin = plugin;
783705

784706
module.exports = wdm;

test/helpers/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ if (isPlugin) {
156156
let app;
157157

158158
compiler.hooks.done.tap("webpack-dev-middleware-test", () => {
159-
const instance = middleware(compiler, configMiddleware);
159+
const instance = middleware(compiler, configMiddleware, true);
160160

161161
app = express();
162162
app.use(instance);

0 commit comments

Comments
 (0)