Skip to content

Commit c51da02

Browse files
author
Fatme
authored
Merge pull request #3958 from NativeScript/fatme/preview-js-plugin-warnings
fix: don't show warnings for non-nativescript plugins on `tns preview --bundle` command
2 parents 8e6fdea + ade3575 commit c51da02

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
6565
}
6666

6767
private getWarningForPlugin(data: IPreviewAppLiveSyncData, localPlugin: string, localPluginVersion: string, devicePluginVersion: string, device: Device): string {
68-
if (data && data.appFilesUpdaterOptions && data.appFilesUpdaterOptions.bundle && this.isNativeScriptPluginWithoutNativeCode(localPlugin, device.platform, data.projectDir)) {
69-
return null;
68+
if (data && data.appFilesUpdaterOptions && data.appFilesUpdaterOptions.bundle) {
69+
const pluginPackageJsonPath = path.join(data.projectDir, NODE_MODULES_DIR_NAME, localPlugin, PACKAGE_JSON_FILE_NAME);
70+
const isNativeScriptPlugin = this.$pluginsService.isNativeScriptPlugin(pluginPackageJsonPath);
71+
if (!isNativeScriptPlugin || (isNativeScriptPlugin && !this.hasNativeCode(localPlugin, device.platform, data.projectDir))) {
72+
return null;
73+
}
7074
}
7175

7276
return this.getWarningForPluginCore(localPlugin, localPluginVersion, devicePluginVersion, device.id);
@@ -91,11 +95,6 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
9195
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
9296
}
9397

94-
private isNativeScriptPluginWithoutNativeCode(localPlugin: string, platform: string, projectDir: string): boolean {
95-
const pluginPackageJsonPath = path.join(projectDir, NODE_MODULES_DIR_NAME, localPlugin, PACKAGE_JSON_FILE_NAME);
96-
return this.$pluginsService.isNativeScriptPlugin(pluginPackageJsonPath) && !this.hasNativeCode(localPlugin, platform, projectDir);
97-
}
98-
9998
private hasNativeCode(localPlugin: string, platform: string, projectDir: string): boolean {
10099
const nativeFolderPath = path.join(projectDir, NODE_MODULES_DIR_NAME, localPlugin, PLATFORMS_DIR_NAME, platform.toLowerCase());
101100
return this.$fs.exists(nativeFolderPath) && !this.$fs.isEmptyDir(nativeFolderPath);

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

+5-11
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ describe("previewAppPluginsService", () => {
265265
describe("comparePluginsOnDevice with bundle", () => {
266266
const testCases = [
267267
{
268-
name: "should show warning for non nativescript plugin that has lower major version",
268+
name: "should not show warning for non nativescript plugin that has lower major version",
269269
localPlugins: {
270270
lodash: "1.2.3"
271271
},
@@ -274,12 +274,10 @@ describe("previewAppPluginsService", () => {
274274
},
275275
isNativeScriptPlugin: false,
276276
hasPluginNativeCode: false,
277-
expectedWarnings: [
278-
util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, "lodash", "1.2.3", "2.3.3")
279-
]
277+
expectedWarnings: <string[]>[]
280278
},
281279
{
282-
name: "should show warning for non nativescript plugin that has greather major version",
280+
name: "should not show warning for non nativescript plugin that has greather major version",
283281
localPlugins: {
284282
lodash: "3.2.3"
285283
},
@@ -288,9 +286,7 @@ describe("previewAppPluginsService", () => {
288286
},
289287
isNativeScriptPlugin: false,
290288
hasPluginNativeCode: false,
291-
expectedWarnings: [
292-
util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, "lodash", "3.2.3", "2.3.3")
293-
]
289+
expectedWarnings: []
294290
},
295291
{
296292
name: "should show warning for non nativescript plugin that has greather minor version",
@@ -302,9 +298,7 @@ describe("previewAppPluginsService", () => {
302298
},
303299
isNativeScriptPlugin: false,
304300
hasPluginNativeCode: false,
305-
expectedWarnings: [
306-
util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, "lodash", "3.4.5", "3.3.0")
307-
]
301+
expectedWarnings: []
308302
},
309303
{
310304
name: "should not show warning for non nativescript plugin that has the same version",

0 commit comments

Comments
 (0)