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

feat: lock versions with npm overrides #12635

Merged
merged 21 commits into from
Jan 7, 2022
Merged

feat: lock versions with npm overrides #12635

merged 21 commits into from
Jan 7, 2022

Conversation

haijian-vaadin
Copy link
Contributor

@haijian-vaadin haijian-vaadin commented Dec 23, 2021

Description

How it works?

  1. generate versions.json also for npm mode
  2. if npm mode, create an "overrides" section in the package.json file if the file does not exist.
  3. iterate through dependencies in the version.json file, add each dependency to the overrides section as @vaadin/xxx: $@vaadin/xxx if there is no @vaadin/xxx in the "overrides" section.

Requires npm 8.3.0 or newer which has the "overrids" feature.
Fixes vaadin/hilla#164

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@haijian-vaadin haijian-vaadin added the hilla Issues related to Hilla label Dec 23, 2021
@github-actions
Copy link

github-actions bot commented Dec 23, 2021

Unit Test Results

   769 files  ±0     769 suites  ±0   26m 46s ⏱️ + 3m 38s
5 742 tests +2  5 690 ✔️ +2  52 💤 ±0  0 ±0 
5 780 runs  +8  5 727 ✔️ +8  53 💤 ±0  0 ±0 

Results for commit 9660ba3. ± Comparison against base commit 9a5dbe9.

♻️ This comment has been updated with latest results.

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 7 issues

  1. CRITICAL TaskRunNpmInstall.java#L25: Remove this unused import 'java.nio.file.Path'. rule
  2. MAJOR TaskRunNpmInstall.java#L238: Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. rule
  3. MAJOR TaskUpdatePackages.java#L87: Constructor has 9 parameters, which is greater than 7 authorized. rule
  4. MAJOR TaskUpdatePackages.java#L105: Correct this "|" to "||". rule
  5. MAJOR TaskUpdatePackages.java#L198: Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. rule
  6. MAJOR TaskUpdatePackages.java#L250: Take the required action to fix the issue indicated by this comment. rule
  7. MINOR TaskRunNpmInstall.java#L476: Remove the declaration of thrown exception 'java.lang.IllegalStateException' which is a runtime exception. rule

@haijian-vaadin haijian-vaadin marked this pull request as ready for review January 5, 2022 08:04
@joheriks
Copy link
Contributor

joheriks commented Jan 7, 2022

Requires npm 8.3.0 or newer which has the "overrids" feature.

Should the version validation be updated then?

private static final int SUPPORTED_NPM_MAJOR_VERSION = 6;
private static final int SUPPORTED_NPM_MINOR_VERSION = 14;

@haijian-vaadin
Copy link
Contributor Author

Requires npm 8.3.0 or newer which has the "overrids" feature.

Should the version validation be updated then?

private static final int SUPPORTED_NPM_MAJOR_VERSION = 6;
private static final int SUPPORTED_NPM_MINOR_VERSION = 14;

@Artur- did a change to upgrade to Node 17 + npm 8.3. Is that enough?
I think npm 6.14 is still supported, as in V14, just that it doesn't have the overrides feature available.

@Artur-
Copy link
Member

Artur- commented Jan 7, 2022

It would be nice to let the users know that it will work better if you upgrade to npm 8.3+ if they are using an older globally installed node/npm. We cannot really require the latest version of npm though and we need to make sure that node 16 with its bundled npm works in a standard (i.e no addons) project

@joheriks
Copy link
Contributor

joheriks commented Jan 7, 2022

So if I have an older npm version that doesn't support overrides the section will be ignored, and there will be no version locking (as it is currently working when using npm instead of pnpm). Is there a risk of a silent regression if I have been relying on pnpm now that the default switched to npm but my pre-installed version is too old?

@haijian-vaadin
Copy link
Contributor Author

haijian-vaadin commented Jan 7, 2022

Is it enough to mention this in the upgrade guide? For people relying on the pnpm locking and cannot upgrade to npm 8.3, they can keep using pnpm. Could also make it a warning message in the code.

@Artur-
Copy link
Member

Artur- commented Jan 7, 2022

The place you would run into this is most of the time when you get a browser warning that a custom element has already been defined. This would be the best place to provide additional info on how the solve the problem but it feels like a separate issue/pr

@caalador
Copy link
Contributor

caalador commented Jan 7, 2022

Also missing is cleaning of the override in CleanFrontendMojo

@haijian-vaadin
Copy link
Contributor Author

Also missing is cleaning of the override in CleanFrontendMojo

Good catch, done

joheriks
joheriks previously approved these changes Jan 7, 2022
Co-authored-by: Anton Platonov <anton@vaadin.com>
@joheriks joheriks dismissed stale reviews from platosha and themself via ea93bcd January 7, 2022 15:14
Johannes Eriksson and others added 2 commits January 7, 2022 18:44
Co-authored-by: Anton Platonov <anton@vaadin.com>
Co-authored-by: Anton Platonov <anton@vaadin.com>
@sonarcloud
Copy link

sonarcloud bot commented Jan 7, 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

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Artur- Artur- requested review from Artur- and removed request for platosha January 7, 2022 15:32
@Artur- Artur- enabled auto-merge (squash) January 7, 2022 15:33
@Artur- Artur- merged commit 5a2d6c3 into master Jan 7, 2022
@Artur- Artur- deleted the haijian/npm-lock branch January 7, 2022 16:09
@imsys
Copy link

imsys commented Jan 24, 2022

now that it will work better if you upgrade to npm 8.3+ if they are using an older globally installed node/npm. We cannot really require the latest version of npm though and we need to make sure that node 16 with its bundled npm works in a standard (i.e no addons) project

As someone who fell in this thread almost by accident, when I saw the issue at pnpm/pnpm#4190, and I don't know much about this project, but I thought to give my two cents, that you could add some version specification in the package.json

"engines": {
    "npm": ">=8.3.0",
    "pnpm": ">=5.10.1"
}

"Unless the user has set the engine-strict config flag (see .npmrc), this field is advisory only and will only produce warnings when your package is installed as a dependency." - from npmjs documentation

@haijian-vaadin
Copy link
Contributor Author

Hi @imsys, thanks a lot for the proposal, that's a very good idea, I made an enhancement ticket out of your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hilla Issues related to Hilla +1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lock version with overrides feature when in npm mode
8 participants