@@ -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,28 @@ 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+ 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+
99124 return platformFilePath ;
100125 }
101126
0 commit comments