Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): disallow import of internal cli libraries #33021

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Jan 20, 2025

Reason for this change

Previously it was possible to import any subpaths from the aws-cdk package ("the CLI"). This was never intended to be allowed, or supported. In practice, these subpaths imports allowed users to depend on internal CLI APIs that are not intended for public usage and do not receive the same backwards compatibility guarantees as other parts of the AWS CDK.

With this change we are explicitly disallowing unsanctioned subpath imports.

We are currently in the process of making most CLI features available through a new Programmatic Toolkit library. Please see the respective RFC and let us know if you have a use case that is not currently covered by the proposed feature set.

In order to not immediately break all customers using unsanctioned subpath imports, we have identified a subset of symbols that we will keep exporting in the short-time future. You are still very strongly encouraged to move off any of these features asap. We are actively considering to emit warnings and enact brown-outs to inform users of this removal.

Description of changes

Added the new legacy exports to aws-cdk.
Also change some imports in aws-cdk to use the lower-level path instead of lib/index.

In cli-lib-alpha we now import from the CLI package via file paths, instead of the package. This is intentional because we don't actually need or want to depended on the aws-cdk the package as cli-lib-alpha is bundling everything itself. Although we still have a dependency on aws-cdk at the moment because we need its build to run to produce some other artifacts. Soon these imports will change to ../../../tmp-aws-cdk/lib and import from the temporary package that holds all library code. We already do the same in the toolkit package.

Describe any new or updated permissions being added

none

Description of how you validated changes

Existing tests

Checklist


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

@github-actions github-actions bot added the p2 label Jan 20, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 20, 2025 14:24
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 20, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ CLI code has changed. A maintainer must run the code through the testing pipeline (git fetch origin pull/33021/head && git push -f origin FETCH_HEAD:test-main-pipeline), then add the 'pr-linter/cli-integ-tested' label when the pipeline succeeds.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

@@ -1,7 +1,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { exec as runCli } from 'aws-cdk/lib';
import { exec as runCli } from '../../../aws-cdk/lib';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely, not this?

Copy link
Contributor Author

@mrgrain mrgrain Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. We don't want to depended on aws-cdk the package, but on the local file. It works because cli-lib-alpha is bundling everything itself.

Tomorrow*, this will change to ../../../tmp-aws-cdk/lib to import from the temporary package that holds all library code. We already do the same in the toolkit package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make any practical difference. For me it's about conveying an intention. But happy to revert if you feel strongly otherwise.

packages/aws-cdk/lib/legacy-exports-source.ts Show resolved Hide resolved
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.46%. Comparing base (d4845ce) to head (66415a2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #33021      +/-   ##
==========================================
- Coverage   81.46%   81.46%   -0.01%     
==========================================
  Files         225      224       -1     
  Lines       13750    13748       -2     
  Branches     2412     2412              
==========================================
- Hits        11202    11200       -2     
  Misses       2273     2273              
  Partials      275      275              
Flag Coverage Δ
suite.unit 81.46% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.85% <ø> (-0.01%) ⬇️
packages/aws-cdk-lib/core 82.10% <ø> (ø)

@mrgrain mrgrain force-pushed the mrgrain/chore/fix-cli-exports branch from 1e0f5a7 to 0c8686f Compare January 20, 2025 16:43
Previously it was possible to import any subpaths from the `aws-cdk` package ("the CLI"). This was never intended to be allowed, or supported. In practice, these subpaths imports allowed users to depend on internal CLI APIs that are not intended for public usage and do not receive the same backwards compatibility guarantees as other parts of the AWS CDK.

**With this change we are explicitly disallowing unsanctioned subpath imports.**

We are currently in the process of making most CLI features available through a new Programmatic Toolkit library. Please see the [respective RFC](aws/aws-cdk-rfcs#654) and let us know if you have a use case that is not currently covered by the proposed feature set.

In order to not immediately break all customers using unsanctioned subpath imports, we have identified a subset of symbols that we will keep exporting in the short-time future. **You are still very strongly encouraged to move off any of these features asap.** We are actively considering to emit warnings and enact brown-outs to inform users of this removal.
@mrgrain mrgrain force-pushed the mrgrain/chore/fix-cli-exports branch from 0c8686f to 087c0ab Compare January 20, 2025 16:45
@mrgrain mrgrain added the pr-linter/exempt-test The PR linter will not require test changes label Jan 20, 2025
@mrgrain mrgrain marked this pull request as ready for review January 20, 2025 16:53
@mrgrain mrgrain requested a review from a team as a code owner January 20, 2025 16:53
@aws-cdk-automation
Copy link
Collaborator

➡️ PR build request submitted to test-main-pipeline ⬅️

A maintainer must now check the pipeline and add the pr-linter/cli-integ-tested label once the pipeline succeeds.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 66415a2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mrgrain mrgrain added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Jan 20, 2025
@mrgrain mrgrain merged commit e5ac918 into main Jan 20, 2025
21 of 22 checks passed
@mrgrain mrgrain deleted the mrgrain/chore/fix-cli-exports branch January 20, 2025 19:55
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants