Skip to content

Commit f9cdbc6

Browse files
committed
fix(preview): skip check if local plugin version is invalid
If the local version of the plugin cannot be parsed by `semver`, the check should be skipped and no warning shown. fixes #4043
1 parent b9bfc68 commit f9cdbc6

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

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

+15-10
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,25 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
7474
private getWarningForPluginCore(localPlugin: string, localPluginVersion: string, devicePluginVersion: string, deviceId: string): string {
7575
this.$logger.trace(`Comparing plugin ${localPlugin} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);
7676

77-
if (devicePluginVersion) {
78-
const localPluginVersionData = semver.coerce(localPluginVersion);
79-
const devicePluginVersionData = semver.coerce(devicePluginVersion);
80-
81-
if (localPluginVersionData.major !== devicePluginVersionData.major) {
82-
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
83-
} else if (localPluginVersionData.minor > devicePluginVersionData.minor) {
84-
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
85-
}
77+
if (!devicePluginVersion) {
78+
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
79+
}
8680

81+
const shouldSkipCheck = !semver.valid(localPluginVersion) && !semver.validRange(localPluginVersion);
82+
if (shouldSkipCheck) {
8783
return null;
8884
}
8985

90-
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
86+
const localPluginVersionData = semver.coerce(localPluginVersion);
87+
const devicePluginVersionData = semver.coerce(devicePluginVersion);
88+
89+
if (localPluginVersionData.major !== devicePluginVersionData.major) {
90+
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
91+
} else if (localPluginVersionData.minor > devicePluginVersionData.minor) {
92+
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
93+
}
94+
95+
return null;
9196
}
9297

9398
private hasNativeCode(localPlugin: string, platform: string, projectDir: string): boolean {

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

+10
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ describe("previewAppPluginsService", () => {
243243
"nativescript-theme-core": "3.5.0"
244244
},
245245
expectedWarnings: []
246+
},
247+
{
248+
name: "should not show warning when the local plugin version is tag",
249+
localPlugins: {
250+
"tns-core-modules": "rc"
251+
},
252+
previewAppPlugins: {
253+
"tns-core-modules": "5.0.0"
254+
},
255+
expectedWarnings: <string[]>[]
246256
}
247257
];
248258

0 commit comments

Comments
 (0)