Skip to content

Commit 8ae1cb4

Browse files
committed
fix: use lodash flatMap to stay compatible with node 10
1 parent 2802f82 commit 8ae1cb4

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/util.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as qs from 'qs';
1111
import { ResponseParsingError } from '../types/errors';
1212
import { ValidationResults } from '../types/validation';
1313
import * as rp from 'request-promise-native';
14+
import { flatMap } from 'lodash';
1415

1516
function isSwaggerV2(apiDoc: any): boolean {
1617
return apiDoc.swagger === '2.0';
@@ -254,13 +255,15 @@ export interface CliFlags {
254255
* @param flags
255256
*/
256257
export function buildCliArguments(flags: Array<CliFlags>): Array<string> {
257-
return flags
258-
.filter(({ value }) => typeof value === 'string' || value === true)
259-
.flatMap(({ flag, value }) => {
260-
const args = [flag];
261-
if (typeof value === 'string') {
262-
args.push(value);
263-
}
264-
return args;
265-
});
258+
const effectiveFlags = flags.filter(
259+
({ value }) => typeof value === 'string' || value === true,
260+
);
261+
262+
return flatMap(effectiveFlags, ({ flag, value }) => {
263+
const args = [flag];
264+
if (typeof value === 'string') {
265+
args.push(value);
266+
}
267+
return args;
268+
});
266269
}

test/util/process.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { exec as _exec } from 'child_process';
22
import * as util from 'util';
3+
import { flatMap } from 'lodash';
34
import findProcess = require('find-process');
45

56
const exec = util.promisify(_exec);
67

7-
export async function killNodeProcesses(ports: Array<string | number>): Promise<any> {
8+
export async function killNodeProcesses(
9+
ports: Array<string | number>,
10+
): Promise<any> {
811
const processResults = await Promise.all(
912
ports.map((port) => findProcess('port', port)),
1013
);
1114
return killProcesses(
12-
processResults.flatMap((results) =>
13-
results.flatMap((process) =>
15+
flatMap(processResults, (results) =>
16+
flatMap(results, (process) =>
1417
process.cmd.includes('node') ? process.pid : [],
1518
),
1619
),

0 commit comments

Comments
 (0)