Skip to content

Commit

Permalink
use lodash flatten instead of Array.prototype.flat
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Jun 19, 2021
1 parent b2782a7 commit b92fad8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/constructs/StaticWebsite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import chalk from "chalk";
import { CreateInvalidationRequest, CreateInvalidationResult } from "aws-sdk/clients/cloudfront";
import { S3Origin } from "@aws-cdk/aws-cloudfront-origins";
import * as acm from "@aws-cdk/aws-certificatemanager";
import { flatten } from "lodash";
import { log } from "../utils/logger";
import { s3Sync } from "../utils/s3-sync";
import AwsProvider from "../classes/AwsProvider";
Expand Down Expand Up @@ -86,7 +87,7 @@ export class StaticWebsite extends CdkConstruct implements Construct {
bucket.grantRead(cloudFrontOAI);

// Cast the domains to an array
const domains = configuration.domain !== undefined ? [configuration.domain].flat() : undefined;
const domains = configuration.domain !== undefined ? flatten([configuration.domain]) : undefined;
const certificate =
configuration.certificate !== undefined
? acm.Certificate.fromCertificateArn(this, "Certificate", configuration.certificate)
Expand Down
8 changes: 4 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Stack } from "@aws-cdk/core";
import { get, has, merge } from "lodash";
import { flatten, get, has, merge } from "lodash";
import chalk from "chalk";
import { AwsIamPolicyStatements } from "@serverless/typescript";
import * as path from "path";
Expand Down Expand Up @@ -191,11 +191,11 @@ class LiftPlugin {
}

private appendPermissions(): void {
const statements = Object.entries(this.constructs)
.map(([, construct]) => {
const statements = flatten(
Object.entries(this.constructs).map(([, construct]) => {
return ((construct.permissions ? construct.permissions() : []) as unknown) as AwsIamPolicyStatements;
})
.flat(1);
);
if (statements.length === 0) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/s3-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as util from "util";
import * as path from "path";
import * as crypto from "crypto";
import { lookup } from "mime-types";
import { chunk } from "lodash";
import { chunk, flatten } from "lodash";
import chalk from "chalk";
import AwsProvider from "../classes/AwsProvider";

Expand Down Expand Up @@ -96,7 +96,7 @@ async function listFilesRecursively(directory: string): Promise<string[]> {
})
);

return files.flat(1);
return flatten(files);
}

async function s3ListAll(aws: AwsProvider, bucketName: string): Promise<S3Objects> {
Expand Down

0 comments on commit b92fad8

Please sign in to comment.