Skip to content

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

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

Closed
sis0k0 opened this issue Oct 19, 2018 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@sis0k0
Copy link
Contributor

sis0k0 commented Oct 19, 2018

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.

@Fatme
Copy link
Contributor

Fatme commented Oct 19, 2018

We discussed the problem personally and decided to skip the check if the version is not valid semver version. The same approach is used here: https://github.com/NativeScript/nativescript-cli/blob/master/lib/helpers/bundle-validator-helper.ts#L27

sis0k0 added a commit that referenced this issue Oct 19, 2018
If the local version of the plugin cannot be parsed by `semver`, the
check should be skipped and no warning shown.

fixes #4043
@Fatme Fatme added this to the 5.0.1 milestone Oct 25, 2018
DimitarTachev pushed a commit that referenced this issue Nov 2, 2018
If the local version of the plugin cannot be parsed by `semver`, the
check should be skipped and no warning shown.

fixes #4043
@endarova endarova self-assigned this Nov 5, 2018
@endarova endarova closed this as completed Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants