@@ -26,6 +26,7 @@ export class TnsModulesCopy {
26
26
27
27
// Remove .ts files
28
28
const allFiles = this . $fs . enumerateFilesInDirectorySync ( tnsCoreModulesResourcePath ) ;
29
+ // TODO: Remove usage of $options here.
29
30
const matchPattern = this . $options . release ? "**/*.ts" : "**/*.d.ts" ;
30
31
allFiles . filter ( file => minimatch ( file , matchPattern , { nocase : true } ) ) . map ( file => this . $fs . deleteFile ( file ) ) ;
31
32
@@ -48,6 +49,32 @@ export class TnsModulesCopy {
48
49
shelljs . rm ( "-rf" , path . join ( targetPackageDir , "platforms" ) ) ;
49
50
50
51
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
+ } ) ;
51
78
}
52
79
}
53
80
@@ -62,21 +89,27 @@ export class TnsModulesCopy {
62
89
63
90
const dependenciesFolder = path . join ( targetPackageDir , constants . NODE_MODULES_FOLDER_NAME ) ;
64
91
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 ) ;
75
93
76
94
dependencies . filter ( dir => ! productionDependencies || ! productionDependencies . hasOwnProperty ( dir ) )
77
95
. forEach ( dir => shelljs . rm ( "-rf" , path . join ( dependenciesFolder , dir ) ) ) ;
78
96
}
79
97
}
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
+ }
80
113
}
81
114
82
115
export class NpmPluginPrepare {
@@ -160,7 +193,7 @@ export class NpmPluginPrepare {
160
193
public async prepareJSPlugins ( dependencies : IDependencyData [ ] , platform : string , projectData : IProjectData , projectFilesConfig : IProjectFilesConfig ) : Promise < void > {
161
194
if ( _ . isEmpty ( dependencies ) || this . allPrepared ( dependencies , platform , projectData ) ) {
162
195
return ;
163
- }
196
+ }
164
197
165
198
for ( const dependencyKey in dependencies ) {
166
199
const dependency = dependencies [ dependencyKey ] ;
0 commit comments