Skip to content

chore(pkglint): disallow experimental dependencies - #14249

Merged
mergify[bot] merged 9 commits into
masterfrom
neta/ban-dep
May 5, 2021
Merged

mergify[bot] merged 9 commits into
masterfrom
neta/ban-dep

Conversation

@NetaNir

@NetaNir NetaNir commented Apr 19, 2021 •

Copy link
Copy Markdown
Contributor

blocked on #14291

This PR adds a pkglint rule to disallow @aws-cdk modules to depend on experimental @aws-cdk modules.

In v2 experimental modules will be released separately from aws-cdk-lib. This means that stable modules can not depend on experimental modules as it will create a cyclic dependency. The lint rule also ban exp->exp dependencies. The reasoning for the latter is that if an experimental module A, depends on experimental module B, in order to graduate module A, module B will also have to be graduated (to satisfy no stable->exp). Currently there are a few exp->exp dependencies, these might be removed as a part of the work to release the experimental modules separately from aws-cdk-lib. In the meantime we explicitly allow them by having an exclusion map.

The current implementation executes the check for each modules as a part of its pkglint phase, which is O(n^2) (for each module check the stability of all of its dependencies). This can be improved by executing the check only once, in the build of aws-cdk-lib (going over all the modules in a topological order and storing the stability). The disadvantage of executing it only on the build of aws-cdk-lib is that it will not be executed as a part of a typical developer flow, which is buildup from a specific package. I have testes it several times locally in the current implementation adds ~2 seconds to the root level yarn pkglint. Since it does not add significant time to our build, and gives better/earlier visibility to contributors I have decided to keep it simple and preform the check on each module build. Happy to discuss more if anyone have concerns or optimizations ideas I missed.


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

@gitpod-io

gitpod-io Bot commented Apr 19, 2021 •

Copy link
Copy Markdown

@NetaNir
NetaNir requested a review from nija-at April 19, 2021 09:39
@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label Apr 19, 2021
/**
* Should this package be included in the monolithic package.
*/
function isIncludedInMonolith(pkg: PackageJson): boolean {

@NetaNir NetaNir Apr 19, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eladb I ended up duplicating this logic from ubergen. The logic in ubergen relies on the fact that the ubergen.exclude is not set on all modules that needs to excluded :/ . It's kinda of tricky, the TL;DR is that if the module is not uber.exclude there is a special logic that checks if it needs to be considered deprecated: code.
(Open to ideas of course)

@NetaNir NetaNir changed the title chore(pkglint): ban experimental dependencies chore(pkglint): disallow experimental dependencies Apr 21, 2021
@NetaNir
NetaNir requested a review from a team April 21, 2021 04:04
Comment thread tools/pkglint/lib/rules.ts Outdated

const shortName = dep.split('/')[1];
// eslint-disable-next-line @typescript-eslint/no-require-imports
const stability = require(path.resolve('../', shortName, 'package.json')).stability;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't write these kinds of rules that rely on physical locations of files in the source repository.

Instead, if you must find a dependency's package.json, do something like this:

const dependencyPj = path.resolve(`${shortName}/package.json`, { paths: [searchPath] });
const packageJson = await readJson(dependencyPj);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So! We only need to read the package.json file of dependencies, which means they were already loaded during the build phase => we can require the dependency name, and we don't need a path:

const stability = require(`${dep}/package.json`).stability;

@gitpod-io

gitpod-io Bot commented May 5, 2021

Copy link
Copy Markdown

@NetaNir

NetaNir commented May 5, 2021 •

Copy link
Copy Markdown
Contributor Author

@rix0rrr thanks for the review, I have addressed your comment, can you have another look? 🦄

mergify Bot pushed a commit that referenced this pull request May 5, 2021
A previous [PR](#13823) added a dependency from the stable module `aws-events-targets` to the experimental module `aws-batch`. Depending on experimental modules is no longer allowed.  In fact, this PR build should have failed when attempting to build `aws-cdk-lib`, preventing it from being merged. However, since the dependency was added but not used, the build succeeded, and the PR was merged.

### Why did we expect the PR build of #13823 to fail?

In the build step of `aws-cdk-lib` we strip all the L2 of experimental modules. This means that when compiling `aws-cdk-lib` the L2 types of experimental modules does not exists, if a stable module reference such a type, the build of `aws-cdk-lib` will fail. 

### Why did the PR build of #13823 succeeded?

It added a dependency on the experimental `aws-batch` but didn't use it.

### What are we doing to prevent this from happening in the future?
 #14249 adds a lint rule that disallow depending on an experimental module.


----

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

Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 382d7c9
  • 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 2f8c8fd into master May 5, 2021
@mergify
mergify Bot deleted the neta/ban-dep branch May 5, 2021 05:40
@mergify

mergify Bot commented May 5, 2021

Copy link
Copy Markdown
Contributor

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).

john-tipper pushed a commit to john-tipper/aws-cdk that referenced this pull request May 10, 2021
A previous [PR](aws#13823) added a dependency from the stable module `aws-events-targets` to the experimental module `aws-batch`. Depending on experimental modules is no longer allowed.  In fact, this PR build should have failed when attempting to build `aws-cdk-lib`, preventing it from being merged. However, since the dependency was added but not used, the build succeeded, and the PR was merged.

### Why did we expect the PR build of aws#13823 to fail?

In the build step of `aws-cdk-lib` we strip all the L2 of experimental modules. This means that when compiling `aws-cdk-lib` the L2 types of experimental modules does not exists, if a stable module reference such a type, the build of `aws-cdk-lib` will fail. 

### Why did the PR build of aws#13823 succeeded?

It added a dependency on the experimental `aws-batch` but didn't use it.

### What are we doing to prevent this from happening in the future?
 aws#14249 adds a lint rule that disallow depending on an experimental module.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
john-tipper pushed a commit to john-tipper/aws-cdk that referenced this pull request May 10, 2021
> blocked on aws#14291

This PR adds a pkglint rule to disallow `@aws-cdk` modules to depend on experimental `@aws-cdk` modules. 

In v2 experimental modules will be released separately from `aws-cdk-lib`. This means that stable modules can not depend on experimental modules as it will create a cyclic dependency. The lint rule **also** ban exp->exp dependencies. The reasoning for the latter is that if an experimental module A, depends on experimental module B, in order to graduate module A, module B will also have to be graduated (to satisfy no stable->exp). Currently there are a few exp->exp dependencies, these might be removed as a part of the work to release the experimental modules separately from `aws-cdk-lib`. In the meantime we explicitly allow them by having an exclusion map.

The current implementation executes the check for each modules as a part of its `pkglint` phase, which is O(n^2) (for each module check the stability of all of its dependencies). This can be improved by executing the check only once, in the build of `aws-cdk-lib` (going over all the modules in a topological order and storing the stability). The disadvantage of executing it only on the build of `aws-cdk-lib` is that it will not be executed as a part of a typical developer flow, which is `buildup` from a specific package. I have testes it several times locally in the current implementation adds ~2 seconds to the root level `yarn pkglint`. Since it does not add significant time to our build, and gives better/earlier visibility to contributors I have decided to keep it simple and preform the check on each module build. Happy to discuss more if anyone have concerns or optimizations ideas I missed.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
A previous [PR](aws#13823) added a dependency from the stable module `aws-events-targets` to the experimental module `aws-batch`. Depending on experimental modules is no longer allowed.  In fact, this PR build should have failed when attempting to build `aws-cdk-lib`, preventing it from being merged. However, since the dependency was added but not used, the build succeeded, and the PR was merged.

### Why did we expect the PR build of aws#13823 to fail?

In the build step of `aws-cdk-lib` we strip all the L2 of experimental modules. This means that when compiling `aws-cdk-lib` the L2 types of experimental modules does not exists, if a stable module reference such a type, the build of `aws-cdk-lib` will fail. 

### Why did the PR build of aws#13823 succeeded?

It added a dependency on the experimental `aws-batch` but didn't use it.

### What are we doing to prevent this from happening in the future?
 aws#14249 adds a lint rule that disallow depending on an experimental module.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
> blocked on aws#14291

This PR adds a pkglint rule to disallow `@aws-cdk` modules to depend on experimental `@aws-cdk` modules. 

In v2 experimental modules will be released separately from `aws-cdk-lib`. This means that stable modules can not depend on experimental modules as it will create a cyclic dependency. The lint rule **also** ban exp->exp dependencies. The reasoning for the latter is that if an experimental module A, depends on experimental module B, in order to graduate module A, module B will also have to be graduated (to satisfy no stable->exp). Currently there are a few exp->exp dependencies, these might be removed as a part of the work to release the experimental modules separately from `aws-cdk-lib`. In the meantime we explicitly allow them by having an exclusion map.

The current implementation executes the check for each modules as a part of its `pkglint` phase, which is O(n^2) (for each module check the stability of all of its dependencies). This can be improved by executing the check only once, in the build of `aws-cdk-lib` (going over all the modules in a topological order and storing the stability). The disadvantage of executing it only on the build of `aws-cdk-lib` is that it will not be executed as a part of a typical developer flow, which is `buildup` from a specific package. I have testes it several times locally in the current implementation adds ~2 seconds to the root level `yarn pkglint`. Since it does not add significant time to our build, and gives better/earlier visibility to contributors I have decided to keep it simple and preform the check on each module build. Happy to discuss more if anyone have concerns or optimizations ideas I missed.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
ali-n4i pushed a commit to ali-n4i/aws-cdk that referenced this pull request Jul 29, 2026
A previous [PR](aws#13823) added a dependency from the stable module `aws-events-targets` to the experimental module `aws-batch`. Depending on experimental modules is no longer allowed.  In fact, this PR build should have failed when attempting to build `aws-cdk-lib`, preventing it from being merged. However, since the dependency was added but not used, the build succeeded, and the PR was merged.

### Why did we expect the PR build of aws#13823 to fail?

In the build step of `aws-cdk-lib` we strip all the L2 of experimental modules. This means that when compiling `aws-cdk-lib` the L2 types of experimental modules does not exists, if a stable module reference such a type, the build of `aws-cdk-lib` will fail. 

### Why did the PR build of aws#13823 succeeded?

It added a dependency on the experimental `aws-batch` but didn't use it.

### What are we doing to prevent this from happening in the future?
 aws#14249 adds a lint rule that disallow depending on an experimental module.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
ali-n4i pushed a commit to ali-n4i/aws-cdk that referenced this pull request Jul 29, 2026
> blocked on aws#14291

This PR adds a pkglint rule to disallow `@aws-cdk` modules to depend on experimental `@aws-cdk` modules. 

In v2 experimental modules will be released separately from `aws-cdk-lib`. This means that stable modules can not depend on experimental modules as it will create a cyclic dependency. The lint rule **also** ban exp->exp dependencies. The reasoning for the latter is that if an experimental module A, depends on experimental module B, in order to graduate module A, module B will also have to be graduated (to satisfy no stable->exp). Currently there are a few exp->exp dependencies, these might be removed as a part of the work to release the experimental modules separately from `aws-cdk-lib`. In the meantime we explicitly allow them by having an exclusion map.

The current implementation executes the check for each modules as a part of its `pkglint` phase, which is O(n^2) (for each module check the stability of all of its dependencies). This can be improved by executing the check only once, in the build of `aws-cdk-lib` (going over all the modules in a topological order and storing the stability). The disadvantage of executing it only on the build of `aws-cdk-lib` is that it will not be executed as a part of a typical developer flow, which is `buildup` from a specific package. I have testes it several times locally in the current implementation adds ~2 seconds to the root level `yarn pkglint`. Since it does not add significant time to our build, and gives better/earlier visibility to contributors I have decided to keep it simple and preform the check on each module build. Happy to discuss more if anyone have concerns or optimizations ideas I missed.

----

*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

contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants