@@ -22,6 +22,8 @@ export class NativeScriptPathTransformer extends UrlPathTransformer {
22
22
return ;
23
23
}
24
24
25
+ const isAndroid = this . targetPlatform === 'android' ;
26
+
25
27
if ( _ . startsWith ( scriptUrl , 'mdha:' ) ) {
26
28
scriptUrl = _ . trimStart ( scriptUrl , 'mdha:' ) ;
27
29
}
@@ -37,7 +39,7 @@ export class NativeScriptPathTransformer extends UrlPathTransformer {
37
39
let relativePath = scriptUrl ;
38
40
39
41
if ( matches ) {
40
- relativePath = this . targetPlatform === 'android' ? matches [ 3 ] : matches [ 2 ] ;
42
+ relativePath = isAndroid ? matches [ 3 ] : matches [ 2 ] ;
41
43
}
42
44
43
45
const nodePath = path . join ( '..' , 'node_modules' ) ;
@@ -48,22 +50,41 @@ export class NativeScriptPathTransformer extends UrlPathTransformer {
48
50
relativePath = relativePath . replace ( 'app' , this . appDirPath ) ;
49
51
}
50
52
51
- const absolutePath = path . resolve ( path . join ( webRoot , relativePath ) ) ;
53
+ let absolutePath = path . resolve ( path . join ( webRoot , relativePath ) ) ;
54
+ let platformSpecificPath = this . getPlatformSpecificPath ( absolutePath ) ;
52
55
53
- if ( fs . existsSync ( absolutePath ) ) {
54
- return Promise . resolve ( absolutePath ) ;
56
+ if ( platformSpecificPath ) {
57
+ return Promise . resolve ( platformSpecificPath ) ;
55
58
}
56
59
57
- const fileExtension = path . extname ( absolutePath ) ;
60
+ if ( isAndroid ) {
61
+ // handle files like /data/data/internal/ts_helpers.ts
62
+ absolutePath = path . resolve ( path . join ( webRoot , 'platforms' , this . targetPlatform . toLowerCase ( ) , 'app' , 'src' , 'main' , 'assets' , relativePath ) ) ;
63
+ platformSpecificPath = this . getPlatformSpecificPath ( absolutePath ) ;
64
+
65
+ if ( platformSpecificPath ) {
66
+ return Promise . resolve ( platformSpecificPath ) ;
67
+ }
68
+ }
69
+
70
+ return Promise . resolve ( scriptUrl ) ;
71
+ }
72
+
73
+ private getPlatformSpecificPath ( rawPath : string ) : string {
74
+ if ( fs . existsSync ( rawPath ) ) {
75
+ return rawPath ;
76
+ }
77
+
78
+ const fileExtension = path . extname ( rawPath ) ;
58
79
59
80
if ( fileExtension ) {
60
- const platformSpecificPath = absolutePath . replace ( fileExtension , `.${ this . targetPlatform } ${ fileExtension } ` ) ;
81
+ const platformSpecificPath = rawPath . replace ( fileExtension , `.${ this . targetPlatform } ${ fileExtension } ` ) ;
61
82
62
83
if ( fs . existsSync ( platformSpecificPath ) ) {
63
- return Promise . resolve ( platformSpecificPath ) ;
84
+ return platformSpecificPath ;
64
85
}
65
86
}
66
87
67
- return Promise . resolve ( scriptUrl ) ;
88
+ return null ;
68
89
}
69
90
}
0 commit comments