@@ -8,7 +8,7 @@ export interface PlatformFSPluginOptions {
8
8
platform ?: string ;
9
9
10
10
/**
11
- * A list of all platforms. By default it is `["ios", "android"]`.
11
+ * A list of all platforms. By default it is `["ios", "android", "desktop" ]`.
12
12
*/
13
13
platforms ?: string [ ] ;
14
14
@@ -18,6 +18,8 @@ export interface PlatformFSPluginOptions {
18
18
ignore ?: string [ ] ;
19
19
}
20
20
21
+ const internalPlatforms = [ "ios" , "android" ] ;
22
+
21
23
export class PlatformFSPlugin {
22
24
protected readonly platform : string ;
23
25
protected readonly platforms : ReadonlyArray < string > ;
@@ -26,7 +28,7 @@ export class PlatformFSPlugin {
26
28
27
29
constructor ( { platform, platforms, ignore } : PlatformFSPluginOptions ) {
28
30
this . platform = platform || "" ;
29
- this . platforms = platforms || [ "ios" , "android" ] ;
31
+ this . platforms = platforms || internalPlatforms ;
30
32
this . ignore = ignore || [ ] ;
31
33
}
32
34
@@ -58,6 +60,8 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
58
60
const fs = compiler . inputFileSystem ;
59
61
ignore = args . ignore || [ ] ;
60
62
63
+ const isExternal = internalPlatforms . indexOf ( platform ) === - 1 ;
64
+
61
65
const minimatchFileFilters = ignore . map ( pattern => {
62
66
const minimatchFilter = minimatch . filter ( pattern ) ;
63
67
return file => minimatchFilter ( relative ( context , file ) ) ;
@@ -80,7 +84,7 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
80
84
return join ( dir , name . substr ( 0 , name . length - currentPlatformExt . length ) + ext ) ;
81
85
}
82
86
return file ;
83
- }
87
+ } ;
84
88
85
89
const isNotIgnored = file => ! isIgnored ( file ) ;
86
90
@@ -95,7 +99,28 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
95
99
96
100
function platformSpecificFile ( file : string ) : string {
97
101
const { dir, name, ext} = parseFile ( file ) ;
98
- const platformFilePath = join ( dir , `${ name } .${ platform } ${ ext } ` ) ;
102
+ let platformFilePath = join ( dir , `${ name } .${ platform } ${ ext } ` ) ;
103
+
104
+ if ( isExternal && dir . indexOf ( "/@nativescript/core/" ) !== - 1 ) {
105
+ let replacedPath ;
106
+ try {
107
+ replacedPath = dir . replace (
108
+ / n o d e _ m o d u l e s ( \/ [ ^ / ] + ) ? \/ @ n a t i v e s c r i p t \/ c o r e / ,
109
+ `node_modules/nativescript-platform-${ platform } `
110
+ ) ;
111
+
112
+ platformFilePath = require . resolve ( join ( replacedPath , `${ name } .${ platform } ${ ext } ` ) ) ;
113
+ } catch ( e ) {
114
+ if ( replacedPath ) {
115
+ if ( ext === ".d" ) {
116
+ platformFilePath = undefined ;
117
+ } else {
118
+ platformFilePath = join ( replacedPath , `${ name } ${ ext } ` ) ;
119
+ }
120
+ }
121
+ }
122
+ }
123
+
99
124
return platformFilePath ;
100
125
}
101
126
0 commit comments