Skip to content

Commit

Permalink
chore: eliminate the use of xxx.Construct to reduce v2 merge confli…
Browse files Browse the repository at this point in the history
…cts (#12504)

Introduce an eslint rule & fix all instances in our code which refer to `@aws-cdk/core.Construct` using a qualified namespace (e.g. `core.Construct`, `cdk.Construct`, etc). In v2, `Construct` will refer to `constructs.Construct` so it will reduce the chances for merge issues.

The rule fixer automatically adds an `import` statement (separated from the main import group) and replaces the usage. If the file already imports `constructs.Construct`, then the new import will alias as `CoreConstruct`.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Elad Ben-Israel authored Jan 15, 2021
1 parent 737bab3 commit 83b8df8
Show file tree
Hide file tree
Showing 89 changed files with 639 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import * as ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';
import { EnvironmentCapacityType } from './extensions/extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* Settings for the environment you want to deploy.
* services within.
Expand Down Expand Up @@ -64,11 +68,11 @@ export interface IEnvironment {
* or it can create it's own VPC and cluster. By default it will create
* a cluster with Fargate capacity.
*/
export class Environment extends cdk.Construct implements IEnvironment {
export class Environment extends Construct implements IEnvironment {
/**
* Import an existing environment from its attributes.
*/
public static fromEnvironmentAttributes(scope: cdk.Construct, id: string, attrs: EnvironmentAttributes): IEnvironment {
public static fromEnvironmentAttributes(scope: Construct, id: string, attrs: EnvironmentAttributes): IEnvironment {
return new ImportedEnvironment(scope, id, attrs);
}

Expand All @@ -94,7 +98,7 @@ export class Environment extends cdk.Construct implements IEnvironment {

private readonly scope: cdk.Construct;

constructor(scope: cdk.Construct, id: string, props?: EnvironmentProps) {
constructor(scope: Construct, id: string, props?: EnvironmentProps) {
super(scope, id);

this.scope = scope;
Expand Down Expand Up @@ -139,13 +143,13 @@ export interface EnvironmentAttributes {
cluster: ecs.ICluster;
}

export class ImportedEnvironment extends cdk.Construct implements IEnvironment {
export class ImportedEnvironment extends Construct implements IEnvironment {
public readonly capacityType: EnvironmentCapacityType;
public readonly cluster: ecs.ICluster;
public readonly id: string;
public readonly vpc: ec2.IVpc;

constructor(scope: cdk.Construct, id: string, props: EnvironmentAttributes) {
constructor(scope: Construct, id: string, props: EnvironmentAttributes) {
super(scope, id);

this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { Service } from '../service';
import { Container } from './container';
import { ServiceExtension, ServiceBuild } from './extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

// The version of the App Mesh envoy sidecar to add to the task.
const APP_MESH_ENVOY_SIDECAR_VERSION = 'v1.15.1.0-prod';

Expand Down Expand Up @@ -63,7 +67,7 @@ export class AppMeshExtension extends ServiceExtension {
}
}

public prehook(service: Service, scope: cdk.Construct) {
public prehook(service: Service, scope: Construct) {
this.parentService = service;
this.scope = scope;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as route53 from '@aws-cdk/aws-route53';
import * as cdk from '@aws-cdk/core';
import { Service } from '../../service';
import { Container } from '../container';
import { ServiceExtension, ServiceBuild, EnvironmentCapacityType } from '../extension-interfaces';
import { TaskRecordManager } from './task-record-manager';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

export interface AssignPublicIpExtensionOptions {
/**
* Enable publishing task public IPs to a recordset in a Route 53 hosted zone.
Expand Down Expand Up @@ -52,7 +55,7 @@ export class AssignPublicIpExtension extends ServiceExtension {
return Boolean(this.dns);
}

public prehook(service: Service, _scope: cdk.Construct) {
public prehook(service: Service, _scope: Construct) {
super.prehook(service, _scope);

if (service.capacityType != EnvironmentCapacityType.FARGATE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import * as sqs from '@aws-cdk/aws-sqs';
import * as cdk from '@aws-cdk/core';
import * as customresources from '@aws-cdk/custom-resources';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

export interface TaskRecordManagerProps {
service: ecs.Ec2Service | ecs.FargateService;
dnsZone: route53.IHostedZone;
Expand All @@ -21,8 +25,8 @@ export interface TaskRecordManagerProps {
* An event-driven serverless app to maintain a list of public ips in a Route 53
* hosted zone.
*/
export class TaskRecordManager extends cdk.Construct {
constructor(scope: cdk.Construct, id: string, props: TaskRecordManagerProps) {
export class TaskRecordManager extends Construct {
constructor(scope: Construct, id: string, props: TaskRecordManagerProps) {
super(scope, id);

// Poison pills go here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as ecs from '@aws-cdk/aws-ecs';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Service } from '../service';
import { ServiceExtension } from './extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

const CLOUDWATCH_AGENT_IMAGE = 'amazon/cloudwatch-agent:latest';

/**
Expand All @@ -28,7 +31,7 @@ export class CloudwatchAgentExtension extends ServiceExtension {
super('cloudwatchAgent');
}

public prehook(service: Service, scope: cdk.Construct) {
public prehook(service: Service, scope: Construct) {
this.parentService = service;
this.scope = scope;
}
Expand Down Expand Up @@ -70,4 +73,4 @@ export class CloudwatchAgentExtension extends ServiceExtension {
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';
import { Service } from '../service';
import { ServiceExtension } from './extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* Setting for the main application container of a service
*/
Expand Down Expand Up @@ -59,7 +62,7 @@ export class Container extends ServiceExtension {
}

// @ts-ignore - Ignore unused params that are required for abstract class extend
public prehook(service: Service, scope: cdk.Construct) {
public prehook(service: Service, scope: Construct) {
this.parentService = service;
}

Expand Down Expand Up @@ -142,4 +145,4 @@ export class Container extends ServiceExtension {
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import * as ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';
import { Service } from '../service';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* A list of the capacity types that are supported. These
* capacity types may change the behavior of an extension.
Expand Down Expand Up @@ -154,7 +158,7 @@ export abstract class ServiceExtension {
* @param parent - The parent service which this extension has been added to
* @param scope - The scope that this extension should create resources in
*/
public prehook(parent: Service, scope: cdk.Construct) {
public prehook(parent: Service, scope: Construct) {
this.parentService = parent;
this.scope = scope;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { Service } from '../service';
import { Container } from './container';
import { ContainerMutatingHook, ServiceExtension } from './extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* Settings for the hook which mutates the application container
* to route logs through FireLens
Expand Down Expand Up @@ -63,7 +67,7 @@ export class FireLensExtension extends ServiceExtension {
super('firelens');
}

public prehook(service: Service, scope: cdk.Construct) {
public prehook(service: Service, scope: Construct) {
this.parentService = service;

// Create a log group for the service, into which FireLens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import * as cdk from '@aws-cdk/core';
import { Service } from '../service';
import { ServiceExtension, ServiceBuild } from './extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* This extension add a public facing load balancer for sending traffic
* to one or more replicas of the application container
Expand All @@ -17,7 +21,7 @@ export class HttpLoadBalancerExtension extends ServiceExtension {
}

// Before the service is created go ahead and create the load balancer itself.
public prehook(service: Service, scope: cdk.Construct) {
public prehook(service: Service, scope: Construct) {
this.parentService = service;

this.loadBalancer = new alb.ApplicationLoadBalancer(scope, `${this.parentService.id}-load-balancer`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import * as cdk from '@aws-cdk/core';
import { Service } from '../service';
import { ServiceExtension } from './extension-interfaces';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

const XRAY_DAEMON_IMAGE = 'amazon/aws-xray-daemon:latest';

/**
Expand All @@ -17,7 +21,7 @@ export class XRayExtension extends ServiceExtension {
}

// @ts-ignore - Ignore unused params that are required for abstract class extend
public prehook(service: Service, scope: cdk.Construct) {
public prehook(service: Service, scope: Construct) {
this.parentService = service;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { IEnvironment } from './environment';
import { EnvironmentCapacityType, ServiceBuild } from './extensions/extension-interfaces';
import { ServiceDescription } from './service-description';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* The settings for an ECS Service
*/
Expand All @@ -24,7 +28,7 @@ export interface ServiceProps {
* A service builder class. This construct support various extensions
* which can construct an ECS service progressively.
*/
export class Service extends cdk.Construct {
export class Service extends Construct {
/**
* The underlying ECS service that was created
*/
Expand Down Expand Up @@ -74,7 +78,7 @@ export class Service extends cdk.Construct {

private readonly scope: cdk.Construct;

constructor(scope: cdk.Construct, id: string, props: ServiceProps) {
constructor(scope: Construct, id: string, props: ServiceProps) {
super(scope, id);

this.scope = scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import * as iam from '@aws-cdk/aws-iam';
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
import * as cdk from '@aws-cdk/core';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

export interface PipelineDeployStackActionProps {
/**
* The CDK stack to be deployed.
Expand Down Expand Up @@ -147,7 +151,7 @@ export class PipelineDeployStackAction implements codepipeline.IAction {
});
}

public bind(scope: cdk.Construct, stage: codepipeline.IStage, options: codepipeline.ActionBindOptions):
public bind(scope: Construct, stage: codepipeline.IStage, options: codepipeline.ActionBindOptions):
codepipeline.ActionConfig {
if (this.stack.environment !== cdk.Stack.of(scope).environment) {
// FIXME: Add the necessary to extend to stacks in a different account
Expand Down
13 changes: 8 additions & 5 deletions packages/@aws-cdk/aws-apigateway/lib/api-definition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as s3 from '@aws-cdk/aws-s3';
import * as s3_assets from '@aws-cdk/aws-s3-assets';
import * as cdk from '@aws-cdk/core';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* Represents an OpenAPI definition asset.
Expand Down Expand Up @@ -80,7 +83,7 @@ export abstract class ApiDefinition {
* @param scope The binding scope. Don't be smart about trying to down-cast or
* assume it's initialized. You may just use it as a construct scope.
*/
public abstract bind(scope: cdk.Construct): ApiDefinitionConfig;
public abstract bind(scope: Construct): ApiDefinitionConfig;
}

/**
Expand Down Expand Up @@ -136,7 +139,7 @@ export class S3ApiDefinition extends ApiDefinition {
this.bucketName = bucket.bucketName;
}

public bind(_scope: cdk.Construct): ApiDefinitionConfig {
public bind(_scope: Construct): ApiDefinitionConfig {
return {
s3Location: {
bucket: this.bucketName,
Expand Down Expand Up @@ -164,7 +167,7 @@ export class InlineApiDefinition extends ApiDefinition {
}
}

public bind(_scope: cdk.Construct): ApiDefinitionConfig {
public bind(_scope: Construct): ApiDefinitionConfig {
return {
inlineDefinition: this.definition,
};
Expand All @@ -182,7 +185,7 @@ export class AssetApiDefinition extends ApiDefinition {
super();
}

public bind(scope: cdk.Construct): ApiDefinitionConfig {
public bind(scope: Construct): ApiDefinitionConfig {
// If the same AssetAPIDefinition is used multiple times, retain only the first instantiation.
if (this.asset === undefined) {
this.asset = new s3_assets.Asset(scope, 'APIDefinition', {
Expand Down
Loading

0 comments on commit 83b8df8

Please sign in to comment.