|
1 | 1 | import * as cxschema from '@aws-cdk/cloud-assembly-schema';
|
2 | 2 | import * as cxapi from '@aws-cdk/cx-api';
|
3 |
| -import { IConstruct, Node } from 'constructs'; |
4 |
| - |
5 |
| -const DEPRECATIONS_SYMBOL = Symbol.for('@aws-cdk/core.deprecations'); |
| 3 | +import { IConstruct } from 'constructs'; |
6 | 4 |
|
7 | 5 | /**
|
8 | 6 | * Includes API for attaching annotations such as warning messages to constructs.
|
@@ -77,38 +75,23 @@ export class Annotations {
|
77 | 75 |
|
78 | 76 | // throw if CDK_BLOCK_DEPRECATIONS is set
|
79 | 77 | if (process.env.CDK_BLOCK_DEPRECATIONS) {
|
80 |
| - throw new Error(`${Node.of(this.scope).path}: ${text}`); |
81 |
| - } |
82 |
| - |
83 |
| - // de-dup based on api key |
84 |
| - const set = this.deprecationsReported; |
85 |
| - if (set.has(api)) { |
86 |
| - return; |
| 78 | + throw new Error(`${this.scope.node.path}: ${text}`); |
87 | 79 | }
|
88 | 80 |
|
89 | 81 | this.addWarning(text);
|
90 |
| - set.add(api); |
91 | 82 | }
|
92 | 83 |
|
93 | 84 | /**
|
94 | 85 | * Adds a message metadata entry to the construct node, to be displayed by the CDK CLI.
|
| 86 | + * |
| 87 | + * Records the message once per construct. |
95 | 88 | * @param level The message level
|
96 | 89 | * @param message The message itself
|
97 | 90 | */
|
98 | 91 | private addMessage(level: string, message: string) {
|
99 |
| - Node.of(this.scope).addMetadata(level, message, { stackTrace: this.stackTraces }); |
100 |
| - } |
101 |
| - |
102 |
| - /** |
103 |
| - * Returns the set of deprecations reported on this construct. |
104 |
| - */ |
105 |
| - private get deprecationsReported() { |
106 |
| - let set = (this.scope as any)[DEPRECATIONS_SYMBOL]; |
107 |
| - if (!set) { |
108 |
| - set = new Set(); |
109 |
| - Object.defineProperty(this.scope, DEPRECATIONS_SYMBOL, { value: set }); |
| 92 | + const isNew = !this.scope.node.metadata.find((x) => x.data === message); |
| 93 | + if (isNew) { |
| 94 | + this.scope.node.addMetadata(level, message, { stackTrace: this.stackTraces }); |
110 | 95 | }
|
111 |
| - |
112 |
| - return set; |
113 | 96 | }
|
114 | 97 | }
|
0 commit comments