Skip to content

Commit

Permalink
Revert "feat(core): deprecate "Construct.node" in favor of "Construct…
Browse files Browse the repository at this point in the history
….construct" (#9557)"

This reverts commit aa4c5b7.
  • Loading branch information
rix0rrr committed Aug 12, 2020
1 parent 7005a03 commit b6c1c80
Show file tree
Hide file tree
Showing 43 changed files with 279 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Vpc } from '@aws-cdk/aws-ec2';
import { Cluster, ContainerImage } from '@aws-cdk/aws-ecs';
import { ApplicationProtocol } from '@aws-cdk/aws-elasticloadbalancingv2';
import { HostedZone } from '@aws-cdk/aws-route53';
import { App, Stack } from '@aws-cdk/core';

import { ApplicationLoadBalancedFargateService } from '../../lib';
Expand All @@ -21,10 +20,13 @@ new ApplicationLoadBalancedFargateService(stack, 'myService', {
protocol: ApplicationProtocol.HTTPS,
enableECSManagedTags: true,
domainName: 'test.example.com',
domainZone: HostedZone.fromHostedZoneAttributes(stack, 'HostedZone', {
domainZone: {
hostedZoneId: 'fakeId',
zoneName: 'example.com',
}),
zoneName: 'example.com.',
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
},
});

app.synth();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import { ApplicationLoadBalancer, ApplicationProtocol, NetworkLoadBalancer } from '@aws-cdk/aws-elasticloadbalancingv2';
import * as iam from '@aws-cdk/aws-iam';
import * as route53 from '@aws-cdk/aws-route53';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as ecsPatterns from '../../lib';
Expand Down Expand Up @@ -371,10 +370,13 @@ export = {
cluster,
protocol: ApplicationProtocol.HTTPS,
domainName: 'domain.com',
domainZone: route53.HostedZone.fromHostedZoneAttributes(stack, 'MyHostedZone', {
domainZone: {
hostedZoneId: 'fakeId',
zoneName: 'domain.com',
}),
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
},
taskImageOptions: {
containerPort: 2015,
image: ecs.ContainerImage.fromRegistry('abiosoft/caddy'),
Expand Down Expand Up @@ -406,10 +408,13 @@ export = {
cluster,
protocol: ApplicationProtocol.HTTPS,
domainName: 'test.domain.com',
domainZone: route53.HostedZone.fromHostedZoneAttributes(stack, 'MyHostedZone', {
domainZone: {
hostedZoneId: 'fakeId',
zoneName: 'domain.com.',
}),
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
},
taskImageOptions: {
containerPort: 2015,
image: ecs.ContainerImage.fromRegistry('abiosoft/caddy'),
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-lambda/lib/function-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ export abstract class FunctionBase extends Resource implements IFunction {
return { statementAdded: true, policyDependable: this._functionNode().findChild(identifier) } as iam.AddToResourcePolicyResult;
},
node: this.node,
construct: this.construct,
},
});
}
Expand Down
4 changes: 0 additions & 4 deletions packages/@aws-cdk/aws-route53/test/test.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export = {
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
construct: stack.construct,
});

// THEN
Expand All @@ -46,7 +45,6 @@ export = {
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
construct: stack.construct,
});

// THEN
Expand All @@ -66,7 +64,6 @@ export = {
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
construct: stack.construct,
});

// THEN
Expand All @@ -86,7 +83,6 @@ export = {
hostedZoneArn: 'arn:aws:route53:::hostedzone/fakeId',
stack,
node: stack.node,
construct: stack.construct,
});

// THEN
Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ you.

If you need to add an ordering dependency that is not automatically inferred,
you do so by adding a dependency relationship using
`constructA.construct.addDependency(constructB)`. This will add a dependency
`constructA.node.addDependency(constructB)`. This will add a dependency
relationship between all resources in the scope of `constructA` and all
resources in the scope of `constructB`.

Expand All @@ -230,7 +230,7 @@ bAndC.add(constructB);
bAndC.add(constructC);

// Take the dependency
constructA.construct.addDependency(bAndC);
constructA.node.addDependency(bAndC);
```

### Stack Dependencies
Expand Down Expand Up @@ -319,7 +319,7 @@ examples ensures that only a single SNS topic is defined:
function getOrCreate(scope: Construct): sns.Topic {
const stack = Stack.of(this);
const uniqueid = 'GloballyUniqueIdForSingleton';
return stack.construct.tryFindChild(uniqueid) as sns.Topic ?? new sns.Topic(stack, uniqueid);
return stack.node.tryFindChild(uniqueid) as sns.Topic ?? new sns.Topic(stack, uniqueid);
}
```

Expand Down Expand Up @@ -675,7 +675,7 @@ accessing those through the `cfnOptions` property:
```ts
const rawBucket = new s3.CfnBucket(this, 'Bucket', { /* ... */ });
// -or-
const rawBucket = bucket.construct.defaultChild as s3.CfnBucket;
const rawBucket = bucket.node.defaultChild as s3.CfnBucket;

// then
rawBucket.cfnOptions.condition = new CfnCondition(this, 'EnableBucket', { /* ... */ });
Expand Down Expand Up @@ -734,7 +734,7 @@ const stage = Fn.conditionIf(isProd.logicalId, 'Beta', 'Prod').toString();
// Make Bucket creation condition to IsProduction by accessing
// and overriding the CloudFormation resource
const bucket = new s3.Bucket(this, 'Bucket');
const cfnBucket = bucket.construct.defaultChild as s3.CfnBucket;
const cfnBucket = bucket.node.defaultChild as s3.CfnBucket;
cfnBucket.cfnOptions.condition = isProd;
```

Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/core/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ export class App extends Stage {
this.loadContext(props.context);

if (props.stackTraces === false) {
this.construct.setContext(cxapi.DISABLE_METADATA_STACK_TRACE, true);
this.node.setContext(cxapi.DISABLE_METADATA_STACK_TRACE, true);
}

if (props.runtimeInfo === false) {
this.construct.setContext(cxapi.DISABLE_VERSION_REPORTING, true);
this.node.setContext(cxapi.DISABLE_VERSION_REPORTING, true);
}

const autoSynth = props.autoSynth !== undefined ? props.autoSynth : cxapi.OUTDIR_ENV in process.env;
Expand All @@ -120,7 +120,7 @@ export class App extends Stage {
private loadContext(defaults: { [key: string]: string } = { }) {
// prime with defaults passed through constructor
for (const [ k, v ] of Object.entries(defaults)) {
this.construct.setContext(k, v);
this.node.setContext(k, v);
}

// read from environment
Expand All @@ -130,7 +130,7 @@ export class App extends Stage {
: { };

for (const [ k, v ] of Object.entries(contextFromEnvironment)) {
this.construct.setContext(k, v);
this.node.setContext(k, v);
}
}
}
8 changes: 4 additions & 4 deletions packages/@aws-cdk/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as cxapi from '@aws-cdk/cx-api';
import * as fs from 'fs-extra';
import { AssetHashType, AssetOptions } from './assets';
import { BundlingOptions } from './bundling';
import { Construct } from './construct-compat';
import { FileSystem, FingerprintOptions } from './fs';
import { Stage } from './stage';
import { Construct } from './construct-compat';

const STAGING_TMP = '.cdk.staging';

Expand Down Expand Up @@ -95,7 +95,7 @@ export class AssetStaging extends Construct {

this.assetHash = this.calculateHash(props);

const stagingDisabled = this.construct.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT);
const stagingDisabled = this.node.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT);
if (stagingDisabled) {
this.stagedPath = this.bundleDir ?? this.sourcePath;
} else {
Expand Down Expand Up @@ -180,7 +180,7 @@ export class AssetStaging extends Construct {

let localBundling: boolean | undefined;
try {
process.stderr.write(`Bundling asset ${this.construct.path}...\n`);
process.stderr.write(`Bundling asset ${this.node.path}...\n`);

localBundling = options.local?.tryBundle(bundleDir, options);
if (!localBundling) {
Expand All @@ -193,7 +193,7 @@ export class AssetStaging extends Construct {
});
}
} catch (err) {
throw new Error(`Failed to bundle asset ${this.construct.path}: ${err}`);
throw new Error(`Failed to bundle asset ${this.node.path}: ${err}`);
}

if (FileSystem.isEmpty(bundleDir)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/core/lib/cfn-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export abstract class CfnElement extends Construct {
this.stack = Stack.of(this);

this.logicalId = Lazy.stringValue({ produce: () => this.synthesizeLogicalId() }, {
displayHint: `${notTooLong(this.construct.path)}.LogicalID`,
displayHint: `${notTooLong(this.node.path)}.LogicalID`,
});

this.construct.addMetadata(cxschema.ArtifactMetadataEntryType.LOGICAL_ID, this.logicalId, this.constructor);
this.node.addMetadata(cxschema.ArtifactMetadataEntryType.LOGICAL_ID, this.logicalId, this.constructor);
}

/**
Expand All @@ -78,7 +78,7 @@ export abstract class CfnElement extends Construct {
* node +internal+ entries filtered.
*/
public get creationStack(): string[] {
const trace = this.construct.metadata.find(md => md.type === cxschema.ArtifactMetadataEntryType.LOGICAL_ID)!.trace;
const trace = this.node.metadata.find(md => md.type === cxschema.ArtifactMetadataEntryType.LOGICAL_ID)!.trace;
if (!trace) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/core/lib/cfn-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class CfnOutput extends CfnElement {
super(scope, id);

if (props.value === undefined) {
throw new Error(`Missing value for CloudFormation output at path "${this.construct.path}"`);
throw new Error(`Missing value for CloudFormation output at path "${this.node.path}"`);
}

this._description = props.description;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/core/lib/cfn-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class CfnParser {
if (!depResource) {
throw new Error(`Resource '${logicalId}' depends on '${dep}' that doesn't exist`);
}
resource.construct.addDependency(depResource);
resource.node.addDependency(depResource);
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/core/lib/cfn-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export class CfnResource extends CfnRefElement {
// if aws:cdk:enable-path-metadata is set, embed the current construct's
// path in the CloudFormation template, so it will be possible to trace
// back to the actual construct path.
if (this.construct.tryGetContext(cxapi.PATH_METADATA_ENABLE_CONTEXT)) {
this.addMetadata(cxapi.PATH_METADATA_KEY, this.construct.path);
if (this.node.tryGetContext(cxapi.PATH_METADATA_ENABLE_CONTEXT)) {
this.addMetadata(cxapi.PATH_METADATA_KEY, this.node.path);
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ export class CfnResource extends CfnRefElement {
return;
}

addDependency(this, target, `"${this.construct.path}" depends on "${target.construct.path}"`);
addDependency(this, target, `"${this.node.path}" depends on "${target.node.path}"`);
}

/**
Expand Down Expand Up @@ -312,7 +312,7 @@ export class CfnResource extends CfnRefElement {
return ret;
} catch (e) {
// Change message
e.message = `While synthesizing ${this.construct.path}: ${e.message}`;
e.message = `While synthesizing ${this.node.path}: ${e.message}`;
// Adjust stack trace (make it look like node built it, too...)
const trace = this.creationStack;
if (trace) {
Expand All @@ -330,7 +330,7 @@ export class CfnResource extends CfnRefElement {
function renderDependsOn(dependsOn: Set<CfnResource>) {
return Array
.from(dependsOn)
.sort((x, y) => x.construct.path.localeCompare(y.construct.path))
.sort((x, y) => x.node.path.localeCompare(y.node.path))
.map(r => r.logicalId);
}

Expand Down
23 changes: 4 additions & 19 deletions packages/@aws-cdk/core/lib/construct-compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export interface IConstruct extends constructs.IConstruct, IDependable {
* The construct tree node for this construct.
*/
readonly node: ConstructNode;

/**
* The construct tree node for this construct.
*/
readonly construct: ConstructNode;
}

/**
Expand Down Expand Up @@ -66,18 +61,9 @@ export class Construct extends constructs.Construct implements IConstruct {

/**
* The construct tree node associated with this construct.
*
* @deprecate `Construct.node` is being deprecated in favor of
* `Construct.construct`. This API will be removed in the next major version
* of the AWS CDK, please migrate your code to use `construct` instead.
*/
public readonly node: ConstructNode;

/**
* Construct API.
*/
public readonly construct: ConstructNode;

constructor(scope: Construct, id: string) {
super(scope, id, {
nodeFactory: {
Expand All @@ -92,16 +78,15 @@ export class Construct extends constructs.Construct implements IConstruct {

Object.defineProperty(this, CONSTRUCT_SYMBOL, { value: true });
this.node = ConstructNode._unwrap(constructs.Node.of(this));
this.construct = this.node;

const disableTrace =
this.construct.tryGetContext(cxapi.DISABLE_METADATA_STACK_TRACE) ||
this.construct.tryGetContext(constructs.ConstructMetadata.DISABLE_STACK_TRACE_IN_METADATA) ||
this.node.tryGetContext(cxapi.DISABLE_METADATA_STACK_TRACE) ||
this.node.tryGetContext(constructs.ConstructMetadata.DISABLE_STACK_TRACE_IN_METADATA) ||
process.env.CDK_DISABLE_STACK_TRACE;

if (disableTrace) {
this.construct.setContext(cxapi.DISABLE_METADATA_STACK_TRACE, true);
this.construct.setContext(constructs.ConstructMetadata.DISABLE_STACK_TRACE_IN_METADATA, true);
this.node.setContext(cxapi.DISABLE_METADATA_STACK_TRACE, true);
this.node.setContext(constructs.ConstructMetadata.DISABLE_STACK_TRACE_IN_METADATA, true);
process.env.CDK_DISABLE_STACK_TRACE = '1';
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/core/lib/context-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ContextProvider {
}

const { key, props } = this.getKey(scope, options);
const value = scope.construct.tryGetContext(key);
const value = scope.node.tryGetContext(key);
const providerError = extractProviderError(value);

// if context is missing or an error occurred during context retrieval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class CustomResourceProvider extends Construct {
public static getOrCreate(scope: Construct, uniqueid: string, props: CustomResourceProviderProps) {
const id = `${uniqueid}CustomResourceProvider`;
const stack = Stack.of(scope);
const provider = stack.construct.tryFindChild(id) as CustomResourceProvider
const provider = stack.node.tryFindChild(id) as CustomResourceProvider
?? new CustomResourceProvider(stack, id, props);

return provider.serviceToken;
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/core/lib/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function addDependency<T extends Element>(source: T, target: T, reason?:
const targetStage = Stage.of(targetStack);
if (sourceStage !== targetStage) {
// eslint-disable-next-line max-len
throw new Error(`You cannot add a dependency from '${source.construct.path}' (in ${describeStage(sourceStage)}) to '${target.construct.path}' (in ${describeStage(targetStage)}): dependency cannot cross stage boundaries`);
throw new Error(`You cannot add a dependency from '${source.node.path}' (in ${describeStage(sourceStage)}) to '${target.node.path}' (in ${describeStage(targetStage)}): dependency cannot cross stage boundaries`);
}

// find the deepest common stack between the two elements
Expand Down Expand Up @@ -70,7 +70,7 @@ export function addDependency<T extends Element>(source: T, target: T, reason?:
// `source` is a direct or indirect nested stack of `target`, and this is not
// possible (nested stacks cannot depend on their parents).
if (commonStack === target) {
throw new Error(`Nested stack '${sourceStack.construct.path}' cannot depend on a parent stack '${targetStack.construct.path}': ${reason}`);
throw new Error(`Nested stack '${sourceStack.node.path}' cannot depend on a parent stack '${targetStack.node.path}': ${reason}`);
}

// we have a common stack from which we can reach both `source` and `target`
Expand Down Expand Up @@ -103,5 +103,5 @@ export function addDependency<T extends Element>(source: T, target: T, reason?:
function describeStage(assembly: Stage | undefined): string {
if (!assembly) { return 'an unrooted construct tree'; }
if (!assembly.parentStage) { return 'the App'; }
return `Stage '${assembly.construct.path}'`;
return `Stage '${assembly.node.path}'`;
}
Loading

0 comments on commit b6c1c80

Please sign in to comment.