(url: string, appDirectory: string, fileExists: (name: string) => boolean, importSource?: string)
| 1054 | } |
| 1055 | |
| 1056 | export function resolveFileNameFromUrl(url: string, appDirectory: string, fileExists: (name: string) => boolean, importSource?: string): string { |
| 1057 | let fileName: string = typeof url === 'string' ? url.trim() : ''; |
| 1058 | if (fileName.indexOf('~/') === 0) { |
| 1059 | fileName = fileName.replace('~/', ''); |
| 1060 | } |
| 1061 | |
| 1062 | const isAbsolutePath = fileName.indexOf('/') === 0; |
| 1063 | const absolutePath = isAbsolutePath ? fileName : path.join(appDirectory, fileName); |
| 1064 | if (fileExists(absolutePath)) { |
| 1065 | return absolutePath; |
| 1066 | } |
| 1067 | |
| 1068 | if (!isAbsolutePath) { |
| 1069 | if (fileName[0] === '~' && fileName[1] !== '/' && fileName[1] !== '"') { |
| 1070 | fileName = fileName.substring(1); |
| 1071 | } |
| 1072 | |
| 1073 | if (importSource) { |
| 1074 | const importFile = resolveFilePathFromImport(importSource, fileName); |
| 1075 | if (fileExists(importFile)) { |
| 1076 | return importFile; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | const external = path.join(appDirectory, 'tns_modules', fileName); |
| 1081 | if (fileExists(external)) { |
| 1082 | return external; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | return null; |
| 1087 | } |
| 1088 | |
| 1089 | function resolveFilePathFromImport(importSource: string, fileName: string): string { |
| 1090 | const importSourceParts = importSource.split(path.separator); |
no test coverage detected