@@ -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,32 @@ 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
+ 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
+
99
128
return platformFilePath ;
100
129
}
101
130
0 commit comments