@@ -8,7 +8,7 @@ export interface PlatformFSPluginOptions {
88    platform ?: string ; 
99
1010    /** 
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" ]`. 
1212     */ 
1313    platforms ?: string [ ] ; 
1414
@@ -18,6 +18,8 @@ export interface PlatformFSPluginOptions {
1818    ignore ?: string [ ] ; 
1919} 
2020
21+ const  internalPlatforms  =  [ "ios" ,  "android" ] ; 
22+ 
2123export  class  PlatformFSPlugin  { 
2224    protected  readonly  platform : string ; 
2325    protected  readonly  platforms : ReadonlyArray < string > ; 
@@ -26,7 +28,7 @@ export class PlatformFSPlugin {
2628
2729    constructor ( {  platform,  platforms,  ignore } : PlatformFSPluginOptions )  { 
2830        this . platform  =  platform  ||  "" ; 
29-         this . platforms  =  platforms  ||  [ "ios" ,   "android" ] ; 
31+         this . platforms  =  platforms  ||  internalPlatforms ; 
3032        this . ignore  =  ignore  ||  [ ] ; 
3133    } 
3234
@@ -58,6 +60,8 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
5860    const  fs  =  compiler . inputFileSystem ; 
5961    ignore  =  args . ignore  ||  [ ] ; 
6062
63+     const  isExternal  =  internalPlatforms . indexOf ( platform )  ===  - 1 ; 
64+ 
6165    const  minimatchFileFilters  =  ignore . map ( pattern  =>  { 
6266        const  minimatchFilter  =  minimatch . filter ( pattern ) ; 
6367        return  file  =>  minimatchFilter ( relative ( context ,  file ) ) ; 
@@ -80,7 +84,7 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
8084            return  join ( dir ,  name . substr ( 0 ,  name . length  -  currentPlatformExt . length )  +  ext ) ; 
8185        } 
8286        return  file ; 
83-     } 
87+     } ; 
8488
8589    const  isNotIgnored  =  file  =>  ! isIgnored ( file ) ; 
8690
@@ -95,7 +99,32 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
9599
96100    function  platformSpecificFile ( file : string ) : string  { 
97101        const  { dir,  name,  ext}  =  parseFile ( file ) ; 
98-         const  platformFilePath  =  join ( dir ,  `${ name } ${ platform } ${ ext }  ) ; 
102+         let  platformFilePath  =  join ( dir ,  `${ name } ${ platform } ${ ext }  ) ; 
103+ 
104+         try  { 
105+             require . resolve ( platformFilePath ) ; 
106+         }  catch  ( e )  { 
107+             if  ( isExternal  &&  dir . indexOf ( "/@nativescript/core/" )  !==  - 1 )  { 
108+                 let  replacedPath ; 
109+                 try  { 
110+                     replacedPath  =  dir . replace ( 
111+                         / 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 / , 
112+                         `node_modules/nativescript-platform-${ platform }  
113+                     ) ; 
114+ 
115+                     platformFilePath  =  require . resolve ( join ( replacedPath ,  `${ name } ${ platform } ${ ext }  ) ) ; 
116+                 }  catch  ( e )  { 
117+                     if  ( replacedPath )  { 
118+                         if  ( ext  ===  ".d" )  { 
119+                             platformFilePath  =  undefined ; 
120+                         }  else  { 
121+                             platformFilePath  =  join ( replacedPath ,  `${ name } ${ ext }  ) ; 
122+                         } 
123+                     } 
124+                 } 
125+             } 
126+         } 
127+ 
99128        return  platformFilePath ; 
100129    } 
101130
0 commit comments