NativeScript / NativeScript/nativescript-cli

Protect against `runtimePackage.version` returning null

未关闭
#5,444 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
1.1k
派生
204
平均合并
1 天 9 小时
30 天内合并 PR
8

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 lib/services/plugins-service.ts 开始,重点查看第 415 行的 isPluginDataValidForPlatform,以及第 805 行附近的 runtimePackage 查找逻辑。使用基于官方 plugin seed 的项目执行 tns plugin add ../../dist/packages/my-cool-plugin 进行复现,然后验证已存在的 @nativescript/android package 不再产生 Invalid Version: null,并且 plugin 能够成功安装。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。