Skip to content

fix(preview): skip check if local plugin version is invalid #4044

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

Merged
merged 3 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/man_pages/lib-management/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Lets you manage the plugins for your project.
* `add` - Installs the specified plugin and its dependencies.
* `remove` - Uninstalls the specified plugin and its dependencies.
* `update` - Uninstalls and installs the specified plugin(s) and its dependencies.
* `find` - Finds NativeScript plugins in npm.
* `search` - Finds NativeScript plugins in npm.
* `build` - Builds the Android parts of a NativeScript plugin.
* `create` - Creates a project for building a new NativeScript plugin.

Expand Down
25 changes: 15 additions & 10 deletions lib/services/livesync/playground/preview-app-plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,25 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
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);
}
if (!devicePluginVersion) {
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
}

const shouldSkipCheck = !semver.valid(localPluginVersion) && !semver.validRange(localPluginVersion);
if (shouldSkipCheck) {
return null;
}

return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
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;
}

private hasNativeCode(localPlugin: string, platform: string, projectDir: string): boolean {
Expand Down
10 changes: 10 additions & 0 deletions test/services/playground/preview-app-plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ describe("previewAppPluginsService", () => {
"nativescript-theme-core": "3.5.0"
},
expectedWarnings: []
},
{
name: "should not show warning when the local plugin version is tag",
localPlugins: {
"tns-core-modules": "rc"
},
previewAppPlugins: {
"tns-core-modules": "5.0.0"
},
expectedWarnings: <string[]>[]
}
];

Expand Down