Skip to content

Commit

Permalink
refactor: Replace _.flatten with Array.prototype.flat (#11271)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmattingly committed Jul 28, 2022
1 parent 4f7e129 commit b36cdf2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
7 changes: 4 additions & 3 deletions lib/plugins/aws/deploy/lib/check-for-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ module.exports = {
const partition = account.partition;

const functionNames = await this.serverless.service.getAllFunctions();
const cloudwatchLogEvents = _.flatten(
functionNames.map((functionName) => {

const cloudwatchLogEvents = functionNames
.map((functionName) => {
const functionObj = this.serverless.service.getFunction(functionName);
const FunctionName = functionObj.name;
const events = functionObj.events;
Expand All @@ -272,7 +273,7 @@ module.exports = {
return { FunctionName, functionName, logGroupName, logSubscriptionSerialNumber };
});
})
);
.flat();

const cloudwatchLogEventsMap = _.groupBy(cloudwatchLogEvents, 'logGroupName');
const logGroupNames = Object.keys(cloudwatchLogEventsMap);
Expand Down
9 changes: 4 additions & 5 deletions lib/plugins/aws/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ class AwsMetrics {

if (metrics && metrics.length > 0) {
const getDatapointsByLabel = (Label) =>
_.flatten(
_.flatten(metrics)
.filter((metric) => metric.Label === Label)
.map((metric) => metric.Datapoints)
);
metrics
.flat(2)
.filter((metric) => metric.Label === Label)
.map((metric) => metric.Datapoints);

const invocationsCount = _.sumBy(getDatapointsByLabel('Invocations'), 'Sum');
const throttlesCount = _.sumBy(getDatapointsByLabel('Throttles'), 'Sum');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ module.exports = {
if (
_.isObject(apiKeyDefinition) &&
Array.isArray(usagePlan) &&
_.flatten(usagePlan.map((item) => Object.keys(item))).includes(name)
usagePlan
.map((item) => Object.keys(item))
.flat()
.includes(name)
) {
keyNumber = 0;
apiKeyDefinition[name].forEach((key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ const pickWebsocketsTemplatePart = require('./pick-websockets-template-part');

module.exports = {
compileDeployment() {
const dependentResourceIds = _.flatten(
this.validated.events.map((event) => {
const dependentResourceIds = this.validated.events
.map((event) => {
const result = [];
if (event.routeResponseSelectionExpression) {
result.push(this.provider.naming.getWebsocketsRouteResponseLogicalId(event.route));
}
result.push(this.provider.naming.getWebsocketsRouteLogicalId(event.route));
return result;
})
);
.flat();

const websocketsTemplatePart = pickWebsocketsTemplatePart(
this.serverless.service.provider.compiledCloudFormationTemplate,
this.provider.naming.getWebsocketsApiLogicalId()
Expand Down
4 changes: 1 addition & 3 deletions lib/plugins/aws/utils/get-s3-objects-from-stacks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const _ = require('lodash');

module.exports = (stacks, prefix, service, stage) =>
_.flatten(stacks).map((entry) => ({
stacks.flat().map((entry) => ({
Key: `${prefix}/${service}/${stage}/${entry.directory}/${entry.file}`,
}));

0 comments on commit b36cdf2

Please sign in to comment.