Skip to content

Commit e26d457

Browse files
committed
fix: compare the major versions between the local and preview app dependencies and show warnings
1 parent 5b6d659 commit e26d457

File tree

3 files changed

+86
-24
lines changed

3 files changed

+86
-24
lines changed

lib/services/livesync/playground/preview-app-constants.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export class PlaygroundStoreUrls {
1313
public static APP_STORE_URL = "https://itunes.apple.com/us/app/nativescript-playground/id1263543946?mt=8&ls=1";
1414
}
1515

16-
export class PreviewAppMessages {
16+
export class PluginComparisonMessages {
1717
public static PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP = "Plugin %s is not included in preview app on device %s and will not work.";
18-
public static PLUGIN_WITH_LOWER_VERSION_IN_PREVIEW_APP = "Plugin %s has local version %s but preview app on device %s has version %s. Some functionalities may not work.";
18+
public static LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION = "Local plugin %s differs in major version from plugin in preview app. The local plugin has version %s and the plugin in preview app has version %s. Some features might not work as expected.";
19+
public static LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION = "Local plugin %s differs in minor version from plugin in preview app. The local plugin has version %s and the plugin in preview app has version %s. Some features might not work as expected.";
1920
}

lib/services/livesync/playground/preview-app-plugins-service.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from "path";
22
import * as semver from "semver";
33
import * as util from "util";
44
import { Device } from "nativescript-preview-sdk";
5-
import { PreviewAppMessages } from "./preview-app-constants";
5+
import { PluginComparisonMessages } from "./preview-app-constants";
66

77
export class PreviewAppPluginsService implements IPreviewAppPluginsService {
88
constructor(private $fs: IFileSystem,
@@ -19,12 +19,19 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
1919

2020
this.$logger.trace(`Comparing plugin ${localPlugin} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);
2121

22-
if (!devicePluginVersion) {
23-
this.$logger.warn(util.format(PreviewAppMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, device.id));
24-
}
22+
if (devicePluginVersion) {
23+
const localPluginVersionData = semver.coerce(localPluginVersion);
24+
const devicePluginVersionData = semver.coerce(devicePluginVersion);
25+
26+
if (localPluginVersionData.major !== devicePluginVersionData.major) {
27+
this.$logger.warn(util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion));
28+
}
2529

26-
if (devicePluginVersion && semver.gt(semver.coerce(localPluginVersion), semver.coerce(devicePluginVersion))) {
27-
this.$logger.warn(util.format(PreviewAppMessages.PLUGIN_WITH_LOWER_VERSION_IN_PREVIEW_APP, localPlugin, localPluginVersion, device.id, devicePluginVersion));
30+
if (localPluginVersionData.major === devicePluginVersionData.major && localPluginVersionData.minor > devicePluginVersionData.minor) {
31+
this.$logger.warn(util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion));
32+
}
33+
} else {
34+
this.$logger.warn(util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, device.id));
2835
}
2936
});
3037
}

test/services/playground/preview-app-plugins-service.ts

+70-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PreviewAppPluginsService } from "../../../lib/services/livesync/playgro
33
import { Device } from "nativescript-preview-sdk";
44
import { assert } from "chai";
55
import * as util from "util";
6-
import { PreviewAppMessages } from "../../../lib/services/livesync/playground/preview-app-constants";
6+
import { PluginComparisonMessages } from "../../../lib/services/livesync/playground/preview-app-constants";
77

88
let readJsonParams: string[] = [];
99
let warnParams: string[] = [];
@@ -32,7 +32,7 @@ function createTestInjector(localPlugins: IStringDictionary): IInjector {
3232
const deviceId = "myTestDeviceId";
3333

3434
function createDevice(plugins: string): Device {
35-
return {
35+
return {
3636
id: deviceId,
3737
platform: "iOS",
3838
model: "myTestDeviceModel",
@@ -71,7 +71,7 @@ describe("previewAppPluginsService", () => {
7171
"tns-core-modules": "~4.2.0"
7272
},
7373
expectedWarnings: [
74-
util.format(PreviewAppMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "nativescript-facebook", deviceId)
74+
util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "nativescript-facebook", deviceId)
7575
]
7676
},
7777
{
@@ -84,34 +84,88 @@ describe("previewAppPluginsService", () => {
8484
previewAppPlugins: {
8585
},
8686
expectedWarnings: [
87-
util.format(PreviewAppMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "nativescript-facebook", deviceId),
88-
util.format(PreviewAppMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "nativescript-theme-core", deviceId),
89-
util.format(PreviewAppMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "tns-core-modules", deviceId)
87+
util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "nativescript-facebook", deviceId),
88+
util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "nativescript-theme-core", deviceId),
89+
util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, "tns-core-modules", deviceId)
9090
]
9191
},
9292
{
93-
name: "should show warning for plugin which local version is greater than preview app's version",
93+
name: "should not show warnings when all plugins are included in preview app",
94+
localPlugins: {
95+
"nativescript-theme-core": "1.0.4",
96+
"nativescript-facebook": "2.2.3"
97+
},
98+
previewAppPlugins: {
99+
"nativescript-theme-core": "1.1.4",
100+
"nativescript-facebook": "2.2.3"
101+
},
102+
expectedWarnings: <string[]>[]
103+
},
104+
{
105+
name: "should show warning when local plugin has lower major version",
94106
localPlugins: {
95-
"nativescript-theme-core": "1.1.4"
107+
"nativescript-theme-core": "2.0.0"
96108
},
97109
previewAppPlugins: {
98-
"nativescript-theme-core": "1.0.4"
110+
"nativescript-theme-core": "3.4.0"
99111
},
100112
expectedWarnings: [
101-
util.format(PreviewAppMessages.PLUGIN_WITH_LOWER_VERSION_IN_PREVIEW_APP, "nativescript-theme-core", "1.1.4", deviceId, "1.0.4")
113+
util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, "nativescript-theme-core", "2.0.0", "3.4.0")
102114
]
103115
},
104116
{
105-
name: "should not show warnings when all plugins are included in preview app",
117+
name: "should show warning when local plugin has greater major version",
106118
localPlugins: {
107-
"nativescript-theme-core": "1.0.4",
108-
"nativescript-facebook": "2.2.3"
119+
"nativescript-theme-core": "4.0.0"
109120
},
110121
previewAppPlugins: {
111-
"nativescript-theme-core": "1.1.4",
112-
"nativescript-facebook": "2.2.3"
122+
"nativescript-theme-core": "3.0.0"
113123
},
114-
expectedWarnings: <string[]>[]
124+
expectedWarnings: [
125+
util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, "nativescript-theme-core", "4.0.0", "3.0.0")
126+
]
127+
},
128+
{
129+
name: "should show warning when local plugin has greater minor version and the same major version",
130+
localPlugins: {
131+
"nativescript-theme-core": "3.5.0"
132+
},
133+
previewAppPlugins: {
134+
"nativescript-theme-core": "3.0.0"
135+
},
136+
expectedWarnings: [
137+
util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, "nativescript-theme-core", "3.5.0", "3.0.0")
138+
]
139+
},
140+
{
141+
name: "should not show warning when local plugin has lower minor version and the same major version",
142+
localPlugins: {
143+
"nativescript-theme-core": "3.1.0"
144+
},
145+
previewAppPlugins: {
146+
"nativescript-theme-core": "3.2.0"
147+
},
148+
expectedWarnings: []
149+
},
150+
{
151+
name: "should not show warning when plugins differ only in patch versions (lower local patch version)",
152+
localPlugins: {
153+
"nativescript-theme-core": "3.5.0"
154+
},
155+
previewAppPlugins: {
156+
"nativescript-theme-core": "3.5.1"
157+
},
158+
expectedWarnings: []
159+
},
160+
{
161+
name: "should not show warning when plugins differ only in patch versions (greater local patch version)",
162+
localPlugins: {
163+
"nativescript-theme-core": "3.5.1"
164+
},
165+
previewAppPlugins: {
166+
"nativescript-theme-core": "3.5.0"
167+
},
168+
expectedWarnings: []
115169
}
116170
];
117171

0 commit comments

Comments
 (0)