From da99081ccf8dda6d0788dd4a466cf6b1eb7ba10b Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 22 Feb 2024 16:42:33 +0800 Subject: [PATCH] fix(cli): allow more platform & arch fallback to wasm (#1969) --- cli/src/api/templates/js-binding.ts | 45 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/cli/src/api/templates/js-binding.ts b/cli/src/api/templates/js-binding.ts index b466ecb4..665e917b 100644 --- a/cli/src/api/templates/js-binding.ts +++ b/cli/src/api/templates/js-binding.ts @@ -93,7 +93,7 @@ switch (platform) { } break default: - throw new Error(\`Unsupported architecture on Android \${arch}\`) + loadError = new Error(\`Unsupported architecture on Android \${arch}\`) } break case 'win32': @@ -141,7 +141,7 @@ switch (platform) { } break default: - throw new Error(\`Unsupported architecture on Windows: \${arch}\`) + loadError = new Error(\`Unsupported architecture on Windows: \${arch}\`) } break case 'darwin': @@ -182,22 +182,37 @@ switch (platform) { } break default: - throw new Error(\`Unsupported architecture on macOS: \${arch}\`) + loadError = new Error(\`Unsupported architecture on macOS: \${arch}\`) } break case 'freebsd': - if (arch !== 'x64') { - throw new Error(\`Unsupported architecture on FreeBSD: \${arch}\`) - } - localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-x64.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.freebsd-x64.node') - } else { - nativeBinding = require('${pkgName}-freebsd-x64') - } - } catch (e) { - loadError = e + switch (arch) { + case 'x64': + localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./${localName}.freebsd-x64.node') + } else { + nativeBinding = require('${pkgName}-freebsd-x64') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-arm64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./${localName}.freebsd-arm64.node') + } else { + nativeBinding = require('${pkgName}-freebsd-arm64') + } + } catch (e) { + loadError = e + } + break + default: + loadError = new Error(\`Unsupported architecture on FreeBSD: \${arch}\`) } break case 'linux':