| 39 | * @returns The resolved file path or undefined if not found. |
| 40 | */ |
| 41 | export function resolveNativeScriptPlatformFile(id: string, platform: string): string | undefined { |
| 42 | const ext = path.extname(id); |
| 43 | const base = id.slice(0, -ext.length); |
| 44 | |
| 45 | let platformFile = `${base}.${platform}${ext}`; |
| 46 | if (fs.existsSync(platformFile)) { |
| 47 | return platformFile; |
| 48 | } |
| 49 | |
| 50 | // core uses indices for many barrels |
| 51 | platformFile = `${base}/index.${platform}${ext}`; |
| 52 | if (fs.existsSync(platformFile)) { |
| 53 | return platformFile; |
| 54 | } |
| 55 | |
| 56 | // fallback to non-platform file |
| 57 | return fs.existsSync(id) ? id : undefined; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Utility to get all dependencies from the project package.json. |