@@ -4,20 +4,19 @@ import * as util from "util";
44import { Device } from "nativescript-preview-sdk" ;
55import { PluginComparisonMessages } from "./preview-app-constants" ;
66import { NODE_MODULES_DIR_NAME } from "../../../common/constants" ;
7- import { PLATFORMS_DIR_NAME } from "../../../constants" ;
7+ import { PLATFORMS_DIR_NAME , PACKAGE_JSON_FILE_NAME } from "../../../constants" ;
88
99export class PreviewAppPluginsService implements IPreviewAppPluginsService {
1010 private previewAppVersionWarnings : IDictionary < string [ ] > = { } ;
1111
1212 constructor ( private $fs : IFileSystem ,
1313 private $logger : ILogger ,
14- private $pluginsService : IPluginsService ,
15- private $projectData : IProjectData ) { }
14+ private $pluginsService : IPluginsService ) { }
1615
1716 public async comparePluginsOnDevice ( data : IPreviewAppLiveSyncData , device : Device ) : Promise < void > {
1817 if ( ! this . previewAppVersionWarnings [ device . previewAppVersion ] ) {
1918 const devicePlugins = this . getDevicePlugins ( device ) ;
20- const localPlugins = this . getLocalPlugins ( ) ;
19+ const localPlugins = this . getLocalPlugins ( data . projectDir ) ;
2120 const warnings = _ . keys ( localPlugins )
2221 . map ( localPlugin => {
2322 const localPluginVersion = localPlugins [ localPlugin ] ;
@@ -55,8 +54,8 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
5554 }
5655 }
5756
58- private getLocalPlugins ( ) : IStringDictionary {
59- const projectFilePath = path . join ( this . $projectData . projectDir , "package.json" ) ;
57+ private getLocalPlugins ( projectDir : string ) : IStringDictionary {
58+ const projectFilePath = path . join ( projectDir , PACKAGE_JSON_FILE_NAME ) ;
6059 try {
6160 return this . $fs . readJson ( projectFilePath ) . dependencies ;
6261 } catch ( err ) {
@@ -66,7 +65,7 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
6665 }
6766
6867 private getWarningForPlugin ( data : IPreviewAppLiveSyncData , localPlugin : string , localPluginVersion : string , devicePluginVersion : string , device : Device ) : string {
69- if ( data && data . appFilesUpdaterOptions && data . appFilesUpdaterOptions . bundle && this . isNativeScriptPluginWithoutNativeCode ( localPlugin , device . platform ) ) {
68+ if ( data && data . appFilesUpdaterOptions && data . appFilesUpdaterOptions . bundle && this . isNativeScriptPluginWithoutNativeCode ( localPlugin , device . platform , data . projectDir ) ) {
7069 return null ;
7170 }
7271
@@ -92,12 +91,13 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
9291 return util . format ( PluginComparisonMessages . PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP , localPlugin , deviceId ) ;
9392 }
9493
95- private isNativeScriptPluginWithoutNativeCode ( localPlugin : string , platform : string ) : boolean {
96- return this . $pluginsService . isNativeScriptPlugin ( localPlugin , this . $projectData ) && ! this . hasNativeCode ( localPlugin , platform ) ;
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 ) ;
9797 }
9898
99- private hasNativeCode ( localPlugin : string , platform : string ) : boolean {
100- const nativeFolderPath = path . join ( this . $projectData . projectDir , NODE_MODULES_DIR_NAME , localPlugin , PLATFORMS_DIR_NAME , platform . toLowerCase ( ) ) ;
99+ private hasNativeCode ( localPlugin : string , platform : string , projectDir : string ) : boolean {
100+ const nativeFolderPath = path . join ( projectDir , NODE_MODULES_DIR_NAME , localPlugin , PLATFORMS_DIR_NAME , platform . toLowerCase ( ) ) ;
101101 return this . $fs . exists ( nativeFolderPath ) && ! this . $fs . isEmptyDir ( nativeFolderPath ) ;
102102 }
103103}
0 commit comments