@contrast/route-coverage 1.20.0 → 1.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/install/express.js +14 -8
- package/package.json +1 -1
package/lib/install/express.js
CHANGED
|
@@ -41,6 +41,7 @@ module.exports = function init(core) {
|
|
|
41
41
|
const regExpToPath = (regex) => regex?.source?.split('/?')[0].replace(/\\/g, '').replace('^', ''); //TODO: replaceAll when v14 deprecated
|
|
42
42
|
const format = (url) => Array.isArray(url) ? `/[${join(url)}]` : url instanceof RegExp ? `/{${url.toString().slice(1, -1)}}` : url;
|
|
43
43
|
const getHandleMethod = (layer) => fnInspect.funcInfo(layer.__handle)?.file.includes('express-async-errors') ? '__handle' : 'handle';
|
|
44
|
+
const getLastLayer = (router) => router?.stack[router.stack.length - 1];
|
|
44
45
|
|
|
45
46
|
function parseRoute(route) {
|
|
46
47
|
const { path } = route;
|
|
@@ -103,13 +104,17 @@ module.exports = function init(core) {
|
|
|
103
104
|
const fn = args[len - 1];
|
|
104
105
|
const path = len > 1 ? args[0] : '';
|
|
105
106
|
if (!isValidPath(path)) return;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
const handlers = Array.isArray(fn) ? fn : [fn];
|
|
108
|
+
handlers.forEach((layer) => {
|
|
109
|
+
if (isRouter(layer)) {
|
|
110
|
+
traverse(path, layer.stack);
|
|
111
|
+
} else {
|
|
112
|
+
const routeInfo = createRouteInfo(format(path), 'use', 'App');
|
|
113
|
+
discover(routeInfo);
|
|
114
|
+
const lastLayer = getLastLayer(result._router);
|
|
115
|
+
if (lastLayer) patchHandle(lastLayer, routeInfo);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
113
118
|
}
|
|
114
119
|
});
|
|
115
120
|
|
|
@@ -122,7 +127,8 @@ module.exports = function init(core) {
|
|
|
122
127
|
if (!url || !fn || !isValidPath(url)) return;
|
|
123
128
|
const routeInfo = createRouteInfo(format(url), method, 'App');
|
|
124
129
|
discover(routeInfo);
|
|
125
|
-
|
|
130
|
+
const lastLayer = getLastLayer(result._router);
|
|
131
|
+
if (lastLayer) patchHandle(lastLayer, routeInfo);
|
|
126
132
|
}
|
|
127
133
|
});
|
|
128
134
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/route-coverage",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.2",
|
|
4
4
|
"description": "Handles route discovery and observation",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|