Skip to content

Use ^ not >= in devDependencies of generated package.json files and…#389

Merged
santam85 merged 4 commits intomainfrom
bugfix/angular-dev-dependencies
Nov 10, 2022
Merged

Use ^ not >= in devDependencies of generated package.json files and…#389
santam85 merged 4 commits intomainfrom
bugfix/angular-dev-dependencies

Conversation

@daiscog
Copy link
Copy Markdown
Contributor

@daiscog daiscog commented Nov 9, 2022

…fix version of typescript used for Angular 11.

Also fix issues running npm install in the generated project when using npm v8.

…ix version of typescript used for Angular 11
Copy link
Copy Markdown
Contributor

@brianvabb brianvabb left a comment

Choose a reason for hiding this comment

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

So the problem was if the generated client was built with ngVersion = angular@12. BOAT was defining dev dependencies with range>= which would result in the latest versions being installed during npm i? (e.g, instead of typescript@4.3.2 dev dependency being installed, it would install whatever the latest version was here)

@daiscog
Copy link
Copy Markdown
Contributor Author

daiscog commented Nov 9, 2022

So the problem was if the generated client was built with ngVersion = angular@12. BOAT was defining dev dependencies with range>= which would result in the latest versions being installed during npm i? (e.g, instead of typescript@4.3.2 dev dependency being installed, it would install whatever the latest version was here)

Yeah, sorry, should have added a detailed explaination.

This affects people using BOAT to generate stand-alone clients for the specs, as opposed to people like us who generate the clients as libs within a bigger nx project (where the lib's devDependencies are ignored as we only install from the root package.json).

The problem is that our instructions for generating custom clients with BOAT say to do this to build the client package after generating it:

cd target/generated-sources/openapi
npm install
npm run build

Problem here is because of >= in the versions, npm install will install the latest version of dev dependencies like @angular/cli and ng-packagr instead of the target major version the user intended. This means the client is built using the Angular package format for the latest version of Angular which is not backwards compatible to older versions. Then, when you try to use the lib in an app that uses the older version of Angular, you get an error like this:

.../fesm2015/xxx-http-ang.mjs: This application depends upon a library published using Angular version 14.2.9, which requires Angular version 14.0.0 or newer to work correctly.
Consider upgrading your application to use a more recent version of Angular.

@brianvabb
Copy link
Copy Markdown
Contributor

So the problem was if the generated client was built with ngVersion = angular@12. BOAT was defining dev dependencies with range>= which would result in the latest versions being installed during npm i? (e.g, instead of typescript@4.3.2 dev dependency being installed, it would install whatever the latest version was here)

Yeah, sorry, should have added a detailed explaination.

This affects people using BOAT to generate stand-alone clients for the specs, as opposed to people like us who generate the clients as libs within a bigger nx project (where the lib's devDependencies are ignored as we only install from the root package.json).

The problem is that our instructions for generating custom clients with BOAT say to do this to build the client package after generating it:

cd target/generated-sources/openapi
npm install
npm run build

Problem here is because of >= in the versions, npm install will install the latest version of dev dependencies like @angular/cli and ng-packagr instead of the target major version the user intended. This means the client is built using the Angular package format for the latest version of Angular which is not backwards compatible to older versions. Then, when you try to use the lib in an app that uses the older version of Angular, you get an error like this:

.../fesm2015/xxx-http-ang.mjs: This application depends upon a library published using Angular version 14.2.9, which requires Angular version 14.0.0 or newer to work correctly.
Consider upgrading your application to use a more recent version of Angular.

Ok this makes sense, we didn't think of this when making the change earlier this year.

@santam85
Copy link
Copy Markdown
Contributor

santam85 commented Nov 9, 2022

LGTM, apart from a small conflict in the zone.js version used in tests it seems (as it's 0.x):

[INFO] [INFO] Running 'npm install' in /home/runner/work/backbase-openapi-tools/backbase-openapi-tools/boat-maven-plugin/target/it/example/boat-generate/angular/target/http-module
[INFO] [INFO] npm ERR! code ERESOLVE
[INFO] [INFO] npm ERR! ERESOLVE unable to resolve dependency tree
[INFO] [INFO] npm ERR! 
[INFO] [INFO] npm ERR! While resolving: @boat/petstore-http-ang@2.2.0
[INFO] [INFO] npm ERR! Found: zone.js@0.11.8
[INFO] [INFO] npm ERR! node_modules/zone.js
[INFO] [INFO] npm ERR!   dev zone.js@"^0.11.4" from the root project
[INFO] [INFO] npm ERR! 
[INFO] [INFO] npm ERR! Could not resolve dependency:
[INFO] [INFO] npm ERR! peer zone.js@"~0.10.3" from @angular/core@10.2.5
[INFO] [INFO] npm ERR! node_modules/@angular/core
[INFO] [INFO] npm ERR!   dev @angular/core@"^10.0.0" from the root project
[INFO] [INFO] npm ERR!   peer @angular/core@"10.2.5" from @angular/common@10.2.5
[INFO] [INFO] npm ERR!   node_modules/@angular/common
[INFO] [INFO] npm ERR!     dev @angular/common@"^10.0.0" from the root project
[INFO] [INFO] npm ERR! 
[INFO] [INFO] npm ERR! Fix the upstream dependency conflict, or retry
[INFO] [INFO] npm ERR! this command with --force, or --legacy-peer-deps
[INFO] [INFO] npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
[INFO] [INFO] npm ERR! 
[INFO] [INFO] npm ERR! See /home/runner/.npm/eresolve-report.txt for a full report.```

@daiscog
Copy link
Copy Markdown
Contributor Author

daiscog commented Nov 9, 2022

@santam85 yeah, just fixed those :)

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Nov 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@santam85 santam85 merged commit 9b56d03 into main Nov 10, 2022
@santam85 santam85 deleted the bugfix/angular-dev-dependencies branch November 10, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants