Skip to content

Commit b36cdf2

Browse files
authored
refactor: Replace _.flatten with Array.prototype.flat (#11271)
1 parent 4f7e129 commit b36cdf2

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

lib/plugins/aws/deploy/lib/check-for-changes.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ module.exports = {
255255
const partition = account.partition;
256256

257257
const functionNames = await this.serverless.service.getAllFunctions();
258-
const cloudwatchLogEvents = _.flatten(
259-
functionNames.map((functionName) => {
258+
259+
const cloudwatchLogEvents = functionNames
260+
.map((functionName) => {
260261
const functionObj = this.serverless.service.getFunction(functionName);
261262
const FunctionName = functionObj.name;
262263
const events = functionObj.events;
@@ -272,7 +273,7 @@ module.exports = {
272273
return { FunctionName, functionName, logGroupName, logSubscriptionSerialNumber };
273274
});
274275
})
275-
);
276+
.flat();
276277

277278
const cloudwatchLogEventsMap = _.groupBy(cloudwatchLogEvents, 'logGroupName');
278279
const logGroupNames = Object.keys(cloudwatchLogEventsMap);

lib/plugins/aws/metrics.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ class AwsMetrics {
113113

114114
if (metrics && metrics.length > 0) {
115115
const getDatapointsByLabel = (Label) =>
116-
_.flatten(
117-
_.flatten(metrics)
118-
.filter((metric) => metric.Label === Label)
119-
.map((metric) => metric.Datapoints)
120-
);
116+
metrics
117+
.flat(2)
118+
.filter((metric) => metric.Label === Label)
119+
.map((metric) => metric.Datapoints);
121120

122121
const invocationsCount = _.sumBy(getDatapointsByLabel('Invocations'), 'Sum');
123122
const throttlesCount = _.sumBy(getDatapointsByLabel('Throttles'), 'Sum');

lib/plugins/aws/package/compile/events/api-gateway/lib/api-keys.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ module.exports = {
4343
if (
4444
_.isObject(apiKeyDefinition) &&
4545
Array.isArray(usagePlan) &&
46-
_.flatten(usagePlan.map((item) => Object.keys(item))).includes(name)
46+
usagePlan
47+
.map((item) => Object.keys(item))
48+
.flat()
49+
.includes(name)
4750
) {
4851
keyNumber = 0;
4952
apiKeyDefinition[name].forEach((key) => {

lib/plugins/aws/package/compile/events/websockets/lib/deployment.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ const pickWebsocketsTemplatePart = require('./pick-websockets-template-part');
66

77
module.exports = {
88
compileDeployment() {
9-
const dependentResourceIds = _.flatten(
10-
this.validated.events.map((event) => {
9+
const dependentResourceIds = this.validated.events
10+
.map((event) => {
1111
const result = [];
1212
if (event.routeResponseSelectionExpression) {
1313
result.push(this.provider.naming.getWebsocketsRouteResponseLogicalId(event.route));
1414
}
1515
result.push(this.provider.naming.getWebsocketsRouteLogicalId(event.route));
1616
return result;
1717
})
18-
);
18+
.flat();
19+
1920
const websocketsTemplatePart = pickWebsocketsTemplatePart(
2021
this.serverless.service.provider.compiledCloudFormationTemplate,
2122
this.provider.naming.getWebsocketsApiLogicalId()
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

3-
const _ = require('lodash');
4-
53
module.exports = (stacks, prefix, service, stage) =>
6-
_.flatten(stacks).map((entry) => ({
4+
stacks.flat().map((entry) => ({
75
Key: `${prefix}/${service}/${stage}/${entry.directory}/${entry.file}`,
86
}));

0 commit comments

Comments
 (0)