Skip to content

Commit 40e8763

Browse files
authored
fix(camelcase): remove camelcase dependency (chimurai#516)
1 parent ba3391f commit 40e8763

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## next
44

5+
- refactor(dependency): remove `camelcase`
56
- fix(option): optional `target` when `router` is used ([#512](https://github.com/chimurai/http-proxy-middleware/pull/512))
67

78
## [v1.1.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.0)

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-proxy-middleware",
3-
"version": "1.1.0",
3+
"version": "1.1.1-alpha.1",
44
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -78,7 +78,6 @@
7878
},
7979
"dependencies": {
8080
"@types/http-proxy": "^1.17.5",
81-
"camelcase": "^6.2.0",
8281
"http-proxy": "^1.18.1",
8382
"is-glob": "^4.0.1",
8483
"is-plain-obj": "^3.0.0",

src/handlers.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type * as express from 'express';
22
import type { Options } from './types';
33
import type * as httpProxy from 'http-proxy';
4-
import camelcase = require('camelcase');
54
import { getInstance } from './logger';
65
const logger = getInstance();
76

@@ -15,20 +14,29 @@ export function init(proxy: httpProxy, option: Options): void {
1514
logger.debug('[HPM] Subscribed to http-proxy events:', Object.keys(handlers));
1615
}
1716

17+
type HttpProxyEventName = 'error' | 'proxyReq' | 'proxyReqWs' | 'proxyRes' | 'open' | 'close';
18+
1819
export function getHandlers(options: Options) {
1920
// https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events
20-
const proxyEvents = ['error', 'proxyReq', 'proxyReqWs', 'proxyRes', 'open', 'close'];
21+
const proxyEventsMap: Record<HttpProxyEventName, string> = {
22+
error: 'onError',
23+
proxyReq: 'onProxyReq',
24+
proxyReqWs: 'onProxyReqWs',
25+
proxyRes: 'onProxyRes',
26+
open: 'onOpen',
27+
close: 'onClose',
28+
};
29+
2130
const handlers: any = {};
2231

23-
for (const event of proxyEvents) {
32+
for (const [eventName, onEventName] of Object.entries(proxyEventsMap)) {
2433
// all handlers for the http-proxy events are prefixed with 'on'.
2534
// loop through options and try to find these handlers
2635
// and add them to the handlers object for subscription in init().
27-
const eventName = camelcase('on ' + event);
28-
const fnHandler = options ? options[eventName] : null;
36+
const fnHandler = options ? options[onEventName] : null;
2937

3038
if (typeof fnHandler === 'function') {
31-
handlers[event] = fnHandler;
39+
handlers[eventName] = fnHandler;
3240
}
3341
}
3442

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,11 +1691,6 @@ camelcase@^6.0.0:
16911691
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.0.0.tgz#5259f7c30e35e278f1bdc2a4d91230b37cad981e"
16921692
integrity sha512-8KMDF1Vz2gzOq54ONPJS65IvTUaB1cHJ2DMM7MbPmLZljDH1qpzzLsWdiN9pHh6qvkRVDTi/07+eNGch/oLU4w==
16931693

1694-
camelcase@^6.2.0:
1695-
version "6.2.0"
1696-
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809"
1697-
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==
1698-
16991694
capture-exit@^2.0.0:
17001695
version "2.0.0"
17011696
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"

0 commit comments

Comments
 (0)