NativeScript / NativeScript/nativescript-cli

Protect against `runtimePackage.version` returning null

Ouverte
#5,444 3 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
JavaScript
Étoiles
1.1k
Forks
204
Merge moyen
1 j 9 h
PR mergées (30 j)
8

Description

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 7.0.11
  • Cross-platform modules: 7.0.13
  • Android Runtime: 7.0.1 (present in node_modules but tns info and tns doctor say "is not installed")
  • iOS Runtime: N/A
  • XCode Version: N/A
  • Android Studio Version: 4.1.1
  • Plugin(s): None

Describe the bug
Build-time error, as documented fully, along with my environment setup, here: https://github.com/NativeScript/nativescript-cli/issues/4451#issuecomment-736152533

In a demo app made from the official NativeScript plugin seed, whenever I run tns plugin add ../../dist/packages/my-cool-plugin on my demo app, I get the nondescript error:

Invalid Version: null

... with no stack trace. I determined that this was from the semver package, as it was in the previous issue. Here's the output of a console.trace() a line before the thrown error:

    at new SemVer (/usr/local/lib/node_modules/nativescript/node_modules/semver/classes/semver.js:22:15)
    at compare (/usr/local/lib/node_modules/nativescript/node_modules/semver/functions/compare.js:3:32)
    at Object.gt (/usr/local/lib/node_modules/nativescript/node_modules/semver/functions/gt.js:2:29)
    at PluginsService.isPluginDataValidForPlatform (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:415:29)
    at PluginsService.<anonymous> (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:66:26)
    at Generator.next (<anonymous>)
    at /usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:4:12)
    at action (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:65:83)

As I document in this comment, I think the root of the problem is that CLI can't find @nativescript/android even though I have it installed. Thus, runtimePackage returns { name: '@nativescript/android', version: null } here:

https://github.com/NativeScript/nativescript-cli/blob/6de0c3e513da0b91f4deef84748417a842c4bbf0/lib/services/plugins-service.ts#L805

To Reproduce
From a demo project in the official NativeScript plugin seed, run tns plugin add ../../dist/packages/my-cool-plugin.

I'm not confident that it will reproduce for users with different environments to my own, however.

Expected behavior
Plugin should install successfully and no error should be thrown at all. If an error is thrown, at least a stack trace should be presented. Above all, CLI needs to be able to find @nativescript/android when it is clearly present in node_modules.

Sample project
Any project using the plugin seed.

Additional context

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par lib/services/plugins-service.ts, en particulier isPluginDataValidForPlatform à la ligne 415 et la recherche de runtimePackage autour de la ligne 805. Reproduisez le problème avec tns plugin add ../../dist/packages/my-cool-plugin depuis un projet basé sur le plugin seed officiel, puis vérifiez que la présence d’un package @nativescript/android ne produit plus Invalid Version: null et que le plugin s’installe correctement.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
cli
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.