Skip to content

tns preview fails when local plugin is referenced with tag in package.json #4043

Closed
@sis0k0

Description

@sis0k0

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: 5.0.0-2018-10-11-12463
  • Cross-platform modules: rc

Describe the bug
If the version of some plugin in the package.json is specified with tag (f.e. rc) instead of version (f.e. 5.0.0), the tns preview command fails with:

TypeError: Cannot read property 'major' of null
    at PreviewAppPluginsService.getWarningForPluginCore (/home/sis0k0/nativescript-cli/lib/services/livesync/playground/preview-app-plugins-service.ts:82:30)

The PreviewAppPluginsService uses semver to check some stuff with the versions of the plugins in the package.json. However, semver.coerce('rc') returns null and breaks the following logic.

private getWarningForPluginCore(localPlugin: string, localPluginVersion: string, devicePluginVersion: string, deviceId: string): string {
this.$logger.trace(`Comparing plugin ${localPlugin} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);
if (devicePluginVersion) {
const localPluginVersionData = semver.coerce(localPluginVersion);
const devicePluginVersionData = semver.coerce(devicePluginVersion);
if (localPluginVersionData.major !== devicePluginVersionData.major) {
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
} else if (localPluginVersionData.minor > devicePluginVersionData.minor) {
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
}
return null;
}
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
}

To Reproduce

  1. Create a hello-world app.
  2. Add this dependency to your package.json:
...
"dependencies": {
	"tns-core-modules": "rc",
	...
}
  1. Run tns preview and scan the barcode.

Expected behavior
To ignore the above check if the tag is beta, rc or next.
I can submit a PR if you agree that's the correct behaviour.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions