Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix yarn upgrade causing dependency incompatibility (#33454)
### Issue # (if applicable) N/A The problem was `yarn upgrade` no longer worked. You can see the auto upgrade PR - #33299 - is having a failed build. After diving deep into the reason of failure, here are the findings: I first checked out the branch for #33299, then run the build locally. Here is the error in the build log: ``` > tsc --build aws-cdk/node_modules/@types/glob/index.d.ts:29:42 - error TS2694: Namespace '"<path skipped>/aws-cdk/node_modules/minimatch/dist/commonjs/index"' has no exported member 'IOptions'. 29 interface IOptions extends minimatch.IOptions { ~~~~~~~~ aws-cdk/node_modules/@types/glob/index.d.ts:74:30 - error TS2724: '"<path skipped>/aws-cdk/node_modules/minimatch/dist/commonjs/index"' has no exported member named 'IMinimatch'. Did you mean 'Minimatch'? 74 minimatch: minimatch.IMinimatch; ~~~~~~~~~~ ``` Pay attention to the file paths above. `aws-cdk/node_modules/@types/glob` is trying to reference a type from `aws-cdk/node_modules/minimatch` because yarn upgraded to a `minimatch` version that natively export minimatch types. But `@types/glob` is not compatible with these new `minimatch` types, causing the error seen above. Ideally, `@types/glob` should specify the `@types/minimatch` version it works with, but in reality, it has `"@types/minimatch": "*"`, which started pointing to the upgraded `aws-cdk/node_modules/minimatch` as yarn hoist dependencies into the top level `node_modules`. Some references: - igorshubovych/markdownlint-cli#508 <-- `aws-cdk/tools/@aws-cdk/cdk-build-tools` uses `markdownlint-cli`, which depend on `glob` and `minimatch` as well. - isaacs/rimraf#264 <-- New versions of `glob` and `minimatch` are written in Typescript, which is causing problem when these new version co-exist with the `@types/xxx` packages. ### Description of changes Use `nohoist` for `@types/glob` and `@types/minimatch` so that the different places that use these two packages do not conflict with each other at the top level `node_modules`. After doing the above, I noticed `cdk-build-tools` was actually relying on `@types/glob` but it does not declare the dependency in its `package.json`. It worked because it pulled the `@types/glob` at the top level `node_modules` (which is no longer available with `nohoist`). ### Describe any new or updated permissions being added None ### Description of how you validated changes Locally built and no error. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information