@@ -26,6 +26,7 @@ export class TnsModulesCopy {
2626
2727 // Remove .ts files
2828 const allFiles = this . $fs . enumerateFilesInDirectorySync ( tnsCoreModulesResourcePath ) ;
29+ // TODO: Remove usage of $options here.
2930 const matchPattern = this . $options . release ? "**/*.ts" : "**/*.d.ts" ;
3031 allFiles . filter ( file => minimatch ( file , matchPattern , { nocase : true } ) ) . map ( file => this . $fs . deleteFile ( file ) ) ;
3132
@@ -48,6 +49,32 @@ export class TnsModulesCopy {
4849 shelljs . rm ( "-rf" , path . join ( targetPackageDir , "platforms" ) ) ;
4950
5051 this . removeNonProductionDependencies ( dependency , targetPackageDir ) ;
52+ this . removeDependenciesPlatformsDirs ( targetPackageDir ) ;
53+ }
54+ }
55+
56+ private removeDependenciesPlatformsDirs ( dependencyDir : string ) : void {
57+ const dependenciesFolder = path . join ( dependencyDir , constants . NODE_MODULES_FOLDER_NAME ) ;
58+ if ( ! this . $fs . exists ( dependenciesFolder ) ) {
59+ return ;
60+ }
61+
62+ if ( this . $fs . exists ( dependenciesFolder ) ) {
63+ const dependencies = this . getDependencies ( dependenciesFolder ) ;
64+
65+ dependencies
66+ . forEach ( d => {
67+ const pathToDependency = path . join ( dependenciesFolder , d ) ;
68+ const pathToPackageJson = path . join ( pathToDependency , constants . PACKAGE_JSON_FILE_NAME ) ;
69+
70+ // TODO: Reuse pluginsService.isNativeScriptPlugin after making it work with full path.
71+ const pluginPackageJsonContent = this . $fs . readJson ( pathToPackageJson ) ;
72+ if ( pluginPackageJsonContent && pluginPackageJsonContent . nativescript ) {
73+ this . $fs . deleteDirectory ( path . join ( pathToDependency , constants . PLATFORMS_DIR_NAME ) ) ;
74+ }
75+
76+ this . removeDependenciesPlatformsDirs ( pathToDependency ) ;
77+ } ) ;
5178 }
5279 }
5380
@@ -62,21 +89,27 @@ export class TnsModulesCopy {
6289
6390 const dependenciesFolder = path . join ( targetPackageDir , constants . NODE_MODULES_FOLDER_NAME ) ;
6491 if ( this . $fs . exists ( dependenciesFolder ) ) {
65- const dependencies = _ . flatten ( this . $fs . readDirectory ( dependenciesFolder )
66- . map ( dir => {
67- if ( _ . startsWith ( dir , "@" ) ) {
68- const pathToDir = path . join ( dependenciesFolder , dir ) ;
69- const contents = this . $fs . readDirectory ( pathToDir ) ;
70- return _ . map ( contents , subDir => `${ dir } /${ subDir } ` ) ;
71- }
72-
73- return dir ;
74- } ) ) ;
92+ const dependencies = this . getDependencies ( dependenciesFolder ) ;
7593
7694 dependencies . filter ( dir => ! productionDependencies || ! productionDependencies . hasOwnProperty ( dir ) )
7795 . forEach ( dir => shelljs . rm ( "-rf" , path . join ( dependenciesFolder , dir ) ) ) ;
7896 }
7997 }
98+
99+ private getDependencies ( dependenciesFolder : string ) : string [ ] {
100+ const dependencies = _ . flatten ( this . $fs . readDirectory ( dependenciesFolder )
101+ . map ( dir => {
102+ if ( _ . startsWith ( dir , "@" ) ) {
103+ const pathToDir = path . join ( dependenciesFolder , dir ) ;
104+ const contents = this . $fs . readDirectory ( pathToDir ) ;
105+ return _ . map ( contents , subDir => `${ dir } /${ subDir } ` ) ;
106+ }
107+
108+ return dir ;
109+ } ) ) ;
110+
111+ return dependencies ;
112+ }
80113}
81114
82115export class NpmPluginPrepare {
@@ -160,7 +193,7 @@ export class NpmPluginPrepare {
160193 public async prepareJSPlugins ( dependencies : IDependencyData [ ] , platform : string , projectData : IProjectData , projectFilesConfig : IProjectFilesConfig ) : Promise < void > {
161194 if ( _ . isEmpty ( dependencies ) || this . allPrepared ( dependencies , platform , projectData ) ) {
162195 return ;
163- }
196+ }
164197
165198 for ( const dependencyKey in dependencies ) {
166199 const dependency = dependencies [ dependencyKey ] ;
0 commit comments