Skip to content

Commit

Permalink
refactor: Replace _.flatMap with Array.prototype.flatMap (#11272)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmattingly committed Jul 28, 2022
1 parent 4f6194c commit 4f7e129
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
30 changes: 14 additions & 16 deletions lib/cli/commands-schema/resolve-final.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ module.exports = (loadedPlugins, { providerName, configuration }) => {
// It's good enough if hooks for command lifecycle events are setup
// and our detection confirms on that.
const optionalServiceCommandsHooksMap = new Map(
_.flattenDepth(
Array.from(awsServiceCommands)
.filter(([name]) => !serviceCommands.has(name))
.map(([name, schema]) => {
const lifecycleEventNamePrefix = name.split(' ').join(':');
return (schema.lifecycleEvents || []).map((lifecycleEventBaseName) => {
const lifecycleEventName = `${lifecycleEventNamePrefix}:${lifecycleEventBaseName}`;
return [
[`before:${lifecycleEventName}`, name],
[lifecycleEventName, name],
[`after:${lifecycleEventName}`, name],
];
});
}),
2
)
Array.from(awsServiceCommands)
.filter(([name]) => !serviceCommands.has(name))
.map(([name, schema]) => {
const lifecycleEventNamePrefix = name.split(' ').join(':');
return (schema.lifecycleEvents || []).map((lifecycleEventBaseName) => {
const lifecycleEventName = `${lifecycleEventNamePrefix}:${lifecycleEventBaseName}`;
return [
[`before:${lifecycleEventName}`, name],
[lifecycleEventName, name],
[`after:${lifecycleEventName}`, name],
];
});
})
.flat(2)
);

const awsSpecificOptionNames = new Set(
Expand Down
8 changes: 6 additions & 2 deletions lib/plugins/aws/invoke-local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,11 @@ class AwsInvokeLocal {
configuredEnvVars,
envVarsFromOptions
);
const envVarsDockerArgs = _.flatMap(envVars, (value, key) => ['--env', `${key}=${value}`]);

const envVarsDockerArgs = Object.entries(envVars).flatMap((currentValue) => [
'--env',
`${currentValue[0]}=${currentValue[1]}`,
]);

const dockerArgsFromOptions = this.getDockerArgsFromOptions();
const dockerArgs = ['run', '--rm', '-v', `${artifactPath}:/var/task:ro,delegated`].concat(
Expand Down Expand Up @@ -571,7 +575,7 @@ class AwsInvokeLocal {

getDockerArgsFromOptions() {
const dockerArgOptions = this.options['docker-arg'];
return _.flatMap([].concat(dockerArgOptions || []), (dockerArgOption) => {
return [].concat(dockerArgOptions || []).flatMap((dockerArgOption) => {
const splitItems = dockerArgOption.split(' ');
return [splitItems[0], splitItems.slice(1).join(' ')];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module.exports = {
)
.then((items) =>
BbPromise.all(
_.flattenDeep(
items.map((item) =>
// #7747 replaced _.flattenDeep() with flat(Infinity)
items
.map((item) =>
item.apiStages.map((apiStage) =>
this.provider.request('APIGateway', 'updateUsagePlan', {
usagePlanId: item.id,
Expand All @@ -42,7 +43,7 @@ module.exports = {
})
)
)
)
.flat(Infinity)
)
);
}
Expand Down

0 comments on commit 4f7e129

Please sign in to comment.