Skip to content

Commit

Permalink
chore(aws-cdk-lib): strip out deprecated symbols from public API (#13815
Browse files Browse the repository at this point in the history
)

The jsii build the 'aws-cdk-lib' module will now run with the 'strip
deprecated' flag enabled. This ensures that the public API of this
module will contain no deprecated symbols.

This is enabled by a new option configured in the module's
`package.json` and recognized by `cdk-build`.

Previous commits - ca391b5 and a872e67 - have removed the majority of
deprecated symbols from public APIs. A few remain that are removed as
part of this change.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored Mar 26, 2021
1 parent 9cceb3f commit 88f2c5a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
2 changes: 0 additions & 2 deletions packages/@aws-cdk/aws-lambda/lib/log-retention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Construct } from 'constructs';

/**
* Retry options for all AWS API calls.
*
* @deprecated use `LogRetentionRetryOptions` from '@aws-cdk/aws-logs' instead
*/
export interface LogRetentionRetryOptions extends logs.LogRetentionRetryOptions {
}
Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-lambda/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,23 @@ export class Runtime {
public readonly family?: RuntimeFamily;

/**
* The bundling Docker image for this runtime.
* DEPRECATED
* @deprecated use `bundlingImage`
*/
public readonly bundlingDockerImage: BundlingDockerImage;

/**
* The bundling Docker image for this runtime.
*/
public readonly bundlingImage: DockerImage;

constructor(name: string, family?: RuntimeFamily, props: LambdaRuntimeProps = { }) {
this.name = name;
this.supportsInlineCode = !!props.supportsInlineCode;
this.family = family;
const imageName = props.bundlingDockerImage ?? `amazon/aws-sam-cli-build-image-${name}`;
this.bundlingDockerImage = DockerImage.fromRegistry(imageName);
this.bundlingImage = this.bundlingDockerImage;
this.supportsCodeGuruProfiling = props.supportsCodeGuruProfiling ?? false;

Runtime.ALL.push(this);
Expand Down
8 changes: 7 additions & 1 deletion packages/@aws-cdk/core/lib/construct-compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,17 @@ export class ConstructNode {
return this._actualNode.tryGetContext(key);
}

/**
* DEPRECATED
* @deprecated use `metadataEntry`
*/
public get metadata() { return this._actualNode.metadata as cxapi.MetadataEntry[]; }

/**
* An immutable array of metadata objects associated with this construct.
* This can be used, for example, to implement support for deprecation notices, source mapping, etc.
*/
public get metadata() { return this._actualNode.metadata as cxapi.MetadataEntry[]; }
public get metadataEntry() { return this._actualNode.metadata; }

/**
* Adds a metadata entry to this construct.
Expand Down
18 changes: 13 additions & 5 deletions packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ export class Stack extends CoreConstruct implements ITaggable {
return CloudFormationLang.toJSON(obj, space).toString();
}

/**
* DEPRECATED
* @deprecated use `reportMissingContextKey()`
*/
public reportMissingContext(report: cxapi.MissingContext) {
if (!Object.values(cxschema.ContextProvider).includes(report.provider as cxschema.ContextProvider)) {
throw new Error(`Unknown context provider requested in: ${JSON.stringify(report)}`);
}
this.reportMissingContextKey(report as cxschema.MissingContext);
}

/**
* Indicate that a context key was expected
*
Expand All @@ -432,11 +443,8 @@ export class Stack extends CoreConstruct implements ITaggable {
*
* @param report The set of parameters needed to obtain the context
*/
public reportMissingContext(report: cxapi.MissingContext) {
if (!Object.values(cxschema.ContextProvider).includes(report.provider as cxschema.ContextProvider)) {
throw new Error(`Unknown context provider requested in: ${JSON.stringify(report)}`);
}
this._missingContext.push(report as cxschema.MissingContext);
public reportMissingContextKey(report: cxschema.MissingContext) {
this._missingContext.push(report);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"cdk-build": {
"eslint": {
"disable": true
}
},
"stripDeprecated": true
},
"pkglint": {
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion tools/cdk-build-tools/lib/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Timers } from './timer';
*/
export async function compileCurrentPackage(options: CDKBuildOptions, timers: Timers, compilers: CompilerOverrides = {}): Promise<void> {
const env = options.env;
await shell(packageCompiler(compilers), { timers, env });
await shell(packageCompiler(compilers, options), { timers, env });

// Find files in bin/ that look like they should be executable, and make them so.
const scripts = currentPackageJson().bin || {};
Expand Down
14 changes: 12 additions & 2 deletions tools/cdk-build-tools/lib/package-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ export interface CompilerOverrides {
/**
* Return the compiler for this package (either tsc or jsii)
*/
export function packageCompiler(compilers: CompilerOverrides): string[] {
export function packageCompiler(compilers: CompilerOverrides, options?: CDKBuildOptions): string[] {
if (isJsii()) {
return [compilers.jsii || require.resolve('jsii/bin/jsii'), '--silence-warnings=reserved-word'];
const args = ['--silence-warnings=reserved-word'];
if (options?.stripDeprecated) {
args.push('--strip-deprecated');
}
return [compilers.jsii || require.resolve('jsii/bin/jsii'), ...args];
} else {
return [compilers.tsc || require.resolve('typescript/bin/tsc'), '--build'];
}
Expand Down Expand Up @@ -148,6 +152,12 @@ export interface CDKBuildOptions {
* Environment variables to be passed to 'cdk-build' and all of its child processes.
*/
env?: NodeJS.ProcessEnv;

/**
* Whether deprecated symbols should be stripped from the jsii assembly and typescript declaration files.
* @see https://aws.github.io/jsii/user-guides/lib-author/toolchain/jsii/#-strip-deprecated
*/
stripDeprecated?: boolean;
}

/**
Expand Down

0 comments on commit 88f2c5a

Please sign in to comment.