Skip to content

Commit

Permalink
chore: fix build break caused by exported deprecated functions (#17719)
Browse files Browse the repository at this point in the history
Functions (not member methods) aren't acknowledged by jsii, so they are not
stripped out of the compiled source, even when deprecated. These two functions
are deprecated and reference deprecated interfaces. When running the init
template tests against JS/TS, the tests fail with:

```
node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.d.ts(110,62): error TS2304: Cannot find name 'FixedResponse'.
node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.d.ts(116,68): error TS2304: Cannot find name 'RedirectResponse'.
```

By -- on v2 only -- un-exporting the functions and inlining them in their
secondary usages, we can effectively "strip" these functions from the JS/TS.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*

(cherry picked from commit 12f60f5)
  • Loading branch information
njlynch authored and mergify-bot committed Nov 25, 2021
1 parent 9398f37 commit cf84d49
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class ApplicationListenerRule extends Construct {
* @internal
* @deprecated
*/
export function validateFixedResponse(fixedResponse: FixedResponse) {
function validateFixedResponse(fixedResponse: FixedResponse) {
if (fixedResponse.statusCode && !/^(2|4|5)\d\d$/.test(fixedResponse.statusCode)) {
throw new Error('`statusCode` must be 2XX, 4XX or 5XX.');
}
Expand All @@ -406,7 +406,7 @@ export function validateFixedResponse(fixedResponse: FixedResponse) {
* @internal
* @deprecated
*/
export function validateRedirectResponse(redirectResponse: RedirectResponse) {
function validateRedirectResponse(redirectResponse: RedirectResponse) {
if (redirectResponse.protocol && !/^(HTTPS?|#\{protocol\})$/i.test(redirectResponse.protocol)) {
throw new Error('`protocol` must be HTTP, HTTPS, or #{protocol}.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IListenerCertificate, ListenerCertificate } from '../shared/listener-ce
import { determineProtocolAndPort } from '../shared/util';
import { ListenerAction } from './application-listener-action';
import { ApplicationListenerCertificate } from './application-listener-certificate';
import { ApplicationListenerRule, FixedResponse, RedirectResponse, validateFixedResponse, validateRedirectResponse } from './application-listener-rule';
import { ApplicationListenerRule, FixedResponse, RedirectResponse } from './application-listener-rule';
import { IApplicationLoadBalancer } from './application-load-balancer';
import { ApplicationTargetGroup, IApplicationLoadBalancerTarget, IApplicationTargetGroup } from './application-target-group';
import { ListenerCondition } from './conditions';
Expand Down Expand Up @@ -377,7 +377,18 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
messageBody: props.messageBody,
};

validateFixedResponse(fixedResponse);
/**
* NOTE - Copy/pasted from `application-listener-rule.ts#validateFixedResponse`.
* This was previously a deprecated, exported function, which caused issues with jsii's strip-deprecated functionality.
* Inlining the duplication functionality in v2 only (for now).
*/
if (fixedResponse.statusCode && !/^(2|4|5)\d\d$/.test(fixedResponse.statusCode)) {
throw new Error('`statusCode` must be 2XX, 4XX or 5XX.');
}

if (fixedResponse.messageBody && fixedResponse.messageBody.length > 1024) {
throw new Error('`messageBody` cannot have more than 1024 characters.');
}

if (props.priority) {
new ApplicationListenerRule(this, id + 'Rule', {
Expand Down Expand Up @@ -410,7 +421,18 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
statusCode: props.statusCode,
};

validateRedirectResponse(redirectResponse);
/**
* NOTE - Copy/pasted from `application-listener-rule.ts#validateRedirectResponse`.
* This was previously a deprecated, exported function, which caused issues with jsii's strip-deprecated functionality.
* Inlining the duplication functionality in v2 only (for now).
*/
if (redirectResponse.protocol && !/^(HTTPS?|#\{protocol\})$/i.test(redirectResponse.protocol)) {
throw new Error('`protocol` must be HTTP, HTTPS, or #{protocol}.');
}

if (!redirectResponse.statusCode || !/^HTTP_30[12]$/.test(redirectResponse.statusCode)) {
throw new Error('`statusCode` must be HTTP_301 or HTTP_302.');
}

if (props.priority) {
new ApplicationListenerRule(this, id + 'Rule', {
Expand Down

0 comments on commit cf84d49

Please sign in to comment.