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

chore(aws-cdk-lib): prevent deep imports #17707

Merged
merged 11 commits into from
Nov 25, 2021
Merged

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Nov 25, 2021

Sometimes, IDEs like VSCode will autocomplete deep imports into the CDK
library. For example, they may generate the following:

import { Bucket } from 'aws-cdk-lib/aws-s3/lib/bucket';

Whereas the correct import should have been:

import { Bucket } from 'aws-cdk-lib/aws-s3';

If we allow people to write the former, they will be broken every time
we change the internal file layout of our module (or conversely, we
will not be allowed to change the file layout at all).

Use the package.json "exports" mechanism to advertise the select
paths that users are allowed to import from, and disallow the rest.


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

Sometimes, IDEs like VSCode will autocomplete deep imports into the CDK
library. For example, they may generate the following:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3/lib/bucket';
```

Whereas the correct import should have been:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3';
```

If we allow people to write the former, they will be broken every time
we change the internal file layout of our module (or conversely, we
will not be allowed to change the file layout at all).

Use the `package.json` `"exports"` mechanism to advertise the select
paths that users are allowed to import from, and disallow the rest.
@rix0rrr rix0rrr requested a review from a team November 25, 2021 13:19
@rix0rrr rix0rrr self-assigned this Nov 25, 2021
@gitpod-io
Copy link

gitpod-io bot commented Nov 25, 2021

@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Nov 25, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 25, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Why can I not find this documented here? https://docs.npmjs.com/cli/v8/configuring-npm/package-json

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 25, 2021

Because it's a Node.js feature: https://nodejs.org/api/packages.html#subpath-exports

@rix0rrr rix0rrr requested a review from a team November 25, 2021 13:54
@@ -361,5 +362,217 @@
"ubergen": {
"exclude": true,
"excludeExperimentalModules": true
},
"exports": {
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL nice!

@nija-at nija-at removed their assignment Nov 25, 2021
@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 80ba87a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 53620e9 into master Nov 25, 2021
@mergify mergify bot deleted the huijbers/prevent-deep-imports branch November 25, 2021 19:31
@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

beezly pushed a commit to beezly/aws-cdk that referenced this pull request Nov 29, 2021
Sometimes, IDEs like VSCode will autocomplete deep imports into the CDK
library. For example, they may generate the following:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3/lib/bucket';
```

Whereas the correct import should have been:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3';
```

If we allow people to write the former, they will be broken every time
we change the internal file layout of our module (or conversely, we
will not be allowed to change the file layout at all).

Use the `package.json` `"exports"` mechanism to advertise the select
paths that users are allowed to import from, and disallow the rest.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
pedrosola pushed a commit to pedrosola/aws-cdk that referenced this pull request Dec 1, 2021
Sometimes, IDEs like VSCode will autocomplete deep imports into the CDK
library. For example, they may generate the following:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3/lib/bucket';
```

Whereas the correct import should have been:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3';
```

If we allow people to write the former, they will be broken every time
we change the internal file layout of our module (or conversely, we
will not be allowed to change the file layout at all).

Use the `package.json` `"exports"` mechanism to advertise the select
paths that users are allowed to import from, and disallow the rest.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this pull request Dec 1, 2021
#17707 added an `exports` section to the `package.json` files of `aws-cdk-lib` and `monocdk` in order to prevent users from accidentally "deep importing" modules.

This broke a large number of `monocdk` users. Since these teams are going to migrate to v2 (`aws-cdk-lib`) soon anyway, we decided to revert this change for `monocdk` so they are unblocked in the meantime.

To do this, we introduced two new configuration options for `ubergen`: `libRoot`, which can be used to control where submodules are going to be collected (defaults to the root of the uber package) and `explicitExports` which controls whether the `exports` section is added or not (defaults to true).
mergify bot pushed a commit that referenced this pull request Dec 1, 2021
#17707 added an `exports` section to the `package.json` files of `aws-cdk-lib` and `monocdk` in order to prevent users from accidentally "deep importing" modules.

This broke a large number of `monocdk` users. Since these teams are going to migrate to v2 (`aws-cdk-lib`) soon anyway, we decided to revert this change for `monocdk` so they are unblocked in the meantime.

To do this, we introduced two new configuration options for `ubergen`: `libRoot`, which can be used to control where submodules are going to be collected (defaults to the root of the uber package) and `explicitExports` which controls whether the `exports` section is added or not (defaults to true).


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
Sometimes, IDEs like VSCode will autocomplete deep imports into the CDK
library. For example, they may generate the following:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3/lib/bucket';
```

Whereas the correct import should have been:

```ts
import { Bucket } from 'aws-cdk-lib/aws-s3';
```

If we allow people to write the former, they will be broken every time
we change the internal file layout of our module (or conversely, we
will not be allowed to change the file layout at all).

Use the `package.json` `"exports"` mechanism to advertise the select
paths that users are allowed to import from, and disallow the rest.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
aws#17707 added an `exports` section to the `package.json` files of `aws-cdk-lib` and `monocdk` in order to prevent users from accidentally "deep importing" modules.

This broke a large number of `monocdk` users. Since these teams are going to migrate to v2 (`aws-cdk-lib`) soon anyway, we decided to revert this change for `monocdk` so they are unblocked in the meantime.

To do this, we introduced two new configuration options for `ubergen`: `libRoot`, which can be used to control where submodules are going to be collected (defaults to the root of the uber package) and `explicitExports` which controls whether the `exports` section is added or not (defaults to true).


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants