()
| 80 | } |
| 81 | |
| 82 | export function loadNative(): NativeBinding { |
| 83 | if (nativeBinding !== undefined) { |
| 84 | if (nativeBinding) { |
| 85 | return nativeBinding |
| 86 | } |
| 87 | throw new Error('Native @formatjs/cli-lib binding is unavailable') |
| 88 | } |
| 89 | |
| 90 | const overridePath = process.env.FORMATJS_CLI_LIB_NATIVE_PATH |
| 91 | const packageCandidates = getNativePackageCandidates() |
| 92 | const installedPackageCandidates = |
| 93 | getInstalledNativePackageCandidates(packageCandidates) |
| 94 | const candidates = [ |
| 95 | overridePath, |
| 96 | ...(installedPackageCandidates.length |
| 97 | ? installedPackageCandidates |
| 98 | : packageCandidates), |
| 99 | ].filter(Boolean) as string[] |
| 100 | const loadErrors: string[] = [] |
| 101 | |
| 102 | for (const candidate of candidates) { |
| 103 | try { |
| 104 | nativeBinding = require(candidate) as NativeBinding |
| 105 | return nativeBinding |
| 106 | } catch (e) { |
| 107 | loadErrors.push(`${candidate}: ${(e as Error).message}`) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | nativeBinding = null |
| 112 | throw new Error( |
| 113 | `Native @formatjs/cli-lib binding is unavailable.\n${loadErrors.join('\n')}` |
| 114 | ) |
| 115 | } |
| 116 | |
| 117 | export function compileWithNative( |
| 118 | inputFiles: string[], |
no test coverage detected