Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace _.flatMap with Array.prototype.flatMap #11272

Merged
merged 4 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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