diff --git a/.changes/features-separator.md b/.changes/features-separator.md new file mode 100644 index 000000000000..02277d87e07d --- /dev/null +++ b/.changes/features-separator.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:bug +"@tauri-apps/cli": patch:bug +--- + +Support comma-separated list of Cargo features on all commands. diff --git a/crates/tauri-cli/src/acl/permission/new.rs b/crates/tauri-cli/src/acl/permission/new.rs index cb17fa35714a..f4c52b079c13 100644 --- a/crates/tauri-cli/src/acl/permission/new.rs +++ b/crates/tauri-cli/src/acl/permission/new.rs @@ -24,10 +24,10 @@ pub struct Options { #[clap(long)] description: Option, /// List of commands to allow - #[clap(short, long, use_value_delimiter = true)] + #[clap(short, long, value_delimiter = ',')] allow: Option>, /// List of commands to deny - #[clap(short, long, use_value_delimiter = true)] + #[clap(short, long, value_delimiter = ',')] deny: Option>, /// Output file format. #[clap(long, default_value_t = FileFormat::Json)] diff --git a/crates/tauri-cli/src/build.rs b/crates/tauri-cli/src/build.rs index 627fd763ac90..2819bc3fcd6d 100644 --- a/crates/tauri-cli/src/build.rs +++ b/crates/tauri-cli/src/build.rs @@ -39,7 +39,7 @@ pub struct Options { #[clap(short, long)] pub target: Option, /// Space or comma separated list of features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// Space or comma separated list of bundles to package. #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] @@ -117,7 +117,7 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> { let bin_path = interface.build(interface_options, &dirs)?; - log::info!(action ="Built"; "application at: {}", tauri_utils::display_path(bin_path)); + log::info!(action = "Built"; "application at: {}", tauri_utils::display_path(bin_path)); let app_settings = interface.app_settings(); diff --git a/crates/tauri-cli/src/bundle.rs b/crates/tauri-cli/src/bundle.rs index 4d3637ab58ba..3db831c1849a 100644 --- a/crates/tauri-cli/src/bundle.rs +++ b/crates/tauri-cli/src/bundle.rs @@ -70,7 +70,7 @@ pub struct Options { #[clap(short, long)] pub config: Vec, /// Space or comma separated list of features, should be the same features passed to `tauri build` if any. - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// Target triple to build against. /// diff --git a/crates/tauri-cli/src/dev.rs b/crates/tauri-cli/src/dev.rs index d175c4c18774..3a6d58140547 100644 --- a/crates/tauri-cli/src/dev.rs +++ b/crates/tauri-cli/src/dev.rs @@ -54,7 +54,7 @@ pub struct Options { #[clap(short, long)] pub target: Option, /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// Exit on panic #[clap(short, long)] diff --git a/crates/tauri-cli/src/icon.rs b/crates/tauri-cli/src/icon.rs index 4945fb8266aa..e5863b1a31ec 100644 --- a/crates/tauri-cli/src/icon.rs +++ b/crates/tauri-cli/src/icon.rs @@ -94,7 +94,7 @@ pub struct Options { output: Option, /// Custom PNG icon sizes to generate. When set, the default icons are not generated. - #[clap(short, long, use_value_delimiter = true)] + #[clap(short, long, value_delimiter = ',')] png: Option>, /// The background color of the iOS icon - string as defined in the W3C's CSS Color Module Level 4 . diff --git a/crates/tauri-cli/src/mobile/android/build.rs b/crates/tauri-cli/src/mobile/android/build.rs index 8113ace54e32..e19a7c3769d9 100644 --- a/crates/tauri-cli/src/mobile/android/build.rs +++ b/crates/tauri-cli/src/mobile/android/build.rs @@ -48,7 +48,7 @@ pub struct Options { )] pub targets: Option>, /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file /// diff --git a/crates/tauri-cli/src/mobile/android/dev.rs b/crates/tauri-cli/src/mobile/android/dev.rs index 7387eb831a1c..3e143b7b5728 100644 --- a/crates/tauri-cli/src/mobile/android/dev.rs +++ b/crates/tauri-cli/src/mobile/android/dev.rs @@ -44,7 +44,7 @@ use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf}; )] pub struct Options { /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// Exit on panic #[clap(short, long)] diff --git a/crates/tauri-cli/src/mobile/android/run.rs b/crates/tauri-cli/src/mobile/android/run.rs index c77596b03877..2e6c7ba012fe 100644 --- a/crates/tauri-cli/src/mobile/android/run.rs +++ b/crates/tauri-cli/src/mobile/android/run.rs @@ -29,7 +29,7 @@ pub struct Options { #[clap(short, long)] pub release: bool, /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file /// diff --git a/crates/tauri-cli/src/mobile/ios/build.rs b/crates/tauri-cli/src/mobile/ios/build.rs index 7e75ca462af7..1489417c0836 100644 --- a/crates/tauri-cli/src/mobile/ios/build.rs +++ b/crates/tauri-cli/src/mobile/ios/build.rs @@ -59,7 +59,7 @@ pub struct Options { )] pub targets: Option>, /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file /// diff --git a/crates/tauri-cli/src/mobile/ios/dev.rs b/crates/tauri-cli/src/mobile/ios/dev.rs index 0ef7fc083e37..4fe2c4dbecae 100644 --- a/crates/tauri-cli/src/mobile/ios/dev.rs +++ b/crates/tauri-cli/src/mobile/ios/dev.rs @@ -53,7 +53,7 @@ environment variable to determine whether the public network should be used or n )] pub struct Options { /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// Exit on panic #[clap(short, long)] diff --git a/crates/tauri-cli/src/mobile/ios/run.rs b/crates/tauri-cli/src/mobile/ios/run.rs index 61e696ef94a1..d80828d1c660 100644 --- a/crates/tauri-cli/src/mobile/ios/run.rs +++ b/crates/tauri-cli/src/mobile/ios/run.rs @@ -26,7 +26,7 @@ pub struct Options { #[clap(short, long)] pub release: bool, /// List of cargo features to activate - #[clap(short, long, action = ArgAction::Append, num_args(0..))] + #[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')] pub features: Vec, /// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file /// diff --git a/crates/tauri-cli/templates/mobile/android/app/.gitignore b/crates/tauri-cli/templates/mobile/android/app/.gitignore index 439b71f0e392..6c4d56b4a287 100644 --- a/crates/tauri-cli/templates/mobile/android/app/.gitignore +++ b/crates/tauri-cli/templates/mobile/android/app/.gitignore @@ -1,4 +1,4 @@ -/src/main/{{package-path}}/generated +/src/main/**/generated /src/main/jniLibs/**/*.so /src/main/assets/tauri.conf.json /tauri.build.gradle.kts diff --git a/packages/cli/index.js b/packages/cli/index.js index ab5cfc87f97a..c9e399696117 100644 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -7,9 +7,6 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { createRequire } = require('node:module') -require = createRequire(__filename) - const { readFileSync } = require('node:fs') let nativeBinding = null const loadErrors = [] @@ -70,7 +67,7 @@ const isMuslFromChildProcess = () => { function requireNative() { if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) { try { - nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); + return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); } catch (err) { loadErrors.push(err) } @@ -82,7 +79,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-android-arm64') + const binding = require('@tauri-apps/cli-android-arm64') + const bindingPackageVersion = require('@tauri-apps/cli-android-arm64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -93,7 +95,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-android-arm-eabi') + const binding = require('@tauri-apps/cli-android-arm-eabi') + const bindingPackageVersion = require('@tauri-apps/cli-android-arm-eabi/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -102,16 +109,39 @@ function requireNative() { } } else if (process.platform === 'win32') { if (process.arch === 'x64') { + if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') { + try { + return require('./cli.win32-x64-gnu.node') + } catch (e) { + loadErrors.push(e) + } try { + const binding = require('@tauri-apps/cli-win32-x64-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-win32-x64-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding + } catch (e) { + loadErrors.push(e) + } + } else { + try { return require('./cli.win32-x64-msvc.node') } catch (e) { loadErrors.push(e) } try { - return require('@tauri-apps/cli-win32-x64-msvc') + const binding = require('@tauri-apps/cli-win32-x64-msvc') + const bindingPackageVersion = require('@tauri-apps/cli-win32-x64-msvc/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } + } } else if (process.arch === 'ia32') { try { return require('./cli.win32-ia32-msvc.node') @@ -119,7 +149,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-win32-ia32-msvc') + const binding = require('@tauri-apps/cli-win32-ia32-msvc') + const bindingPackageVersion = require('@tauri-apps/cli-win32-ia32-msvc/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -130,7 +165,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-win32-arm64-msvc') + const binding = require('@tauri-apps/cli-win32-arm64-msvc') + const bindingPackageVersion = require('@tauri-apps/cli-win32-arm64-msvc/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -144,7 +184,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-darwin-universal') + const binding = require('@tauri-apps/cli-darwin-universal') + const bindingPackageVersion = require('@tauri-apps/cli-darwin-universal/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -155,7 +200,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-darwin-x64') + const binding = require('@tauri-apps/cli-darwin-x64') + const bindingPackageVersion = require('@tauri-apps/cli-darwin-x64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -166,7 +216,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-darwin-arm64') + const binding = require('@tauri-apps/cli-darwin-arm64') + const bindingPackageVersion = require('@tauri-apps/cli-darwin-arm64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -181,7 +236,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-freebsd-x64') + const binding = require('@tauri-apps/cli-freebsd-x64') + const bindingPackageVersion = require('@tauri-apps/cli-freebsd-x64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -192,7 +252,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-freebsd-arm64') + const binding = require('@tauri-apps/cli-freebsd-arm64') + const bindingPackageVersion = require('@tauri-apps/cli-freebsd-arm64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -208,7 +273,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-x64-musl') + const binding = require('@tauri-apps/cli-linux-x64-musl') + const bindingPackageVersion = require('@tauri-apps/cli-linux-x64-musl/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -219,7 +289,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-x64-gnu') + const binding = require('@tauri-apps/cli-linux-x64-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-linux-x64-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -232,7 +307,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-arm64-musl') + const binding = require('@tauri-apps/cli-linux-arm64-musl') + const bindingPackageVersion = require('@tauri-apps/cli-linux-arm64-musl/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -243,7 +323,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-arm64-gnu') + const binding = require('@tauri-apps/cli-linux-arm64-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-linux-arm64-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -256,7 +341,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-arm-musleabihf') + const binding = require('@tauri-apps/cli-linux-arm-musleabihf') + const bindingPackageVersion = require('@tauri-apps/cli-linux-arm-musleabihf/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -267,7 +357,46 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-arm-gnueabihf') + const binding = require('@tauri-apps/cli-linux-arm-gnueabihf') + const bindingPackageVersion = require('@tauri-apps/cli-linux-arm-gnueabihf/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding + } catch (e) { + loadErrors.push(e) + } + } + } else if (process.arch === 'loong64') { + if (isMusl()) { + try { + return require('./cli.linux-loong64-musl.node') + } catch (e) { + loadErrors.push(e) + } + try { + const binding = require('@tauri-apps/cli-linux-loong64-musl') + const bindingPackageVersion = require('@tauri-apps/cli-linux-loong64-musl/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding + } catch (e) { + loadErrors.push(e) + } + } else { + try { + return require('./cli.linux-loong64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + const binding = require('@tauri-apps/cli-linux-loong64-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-linux-loong64-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -280,7 +409,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-riscv64-musl') + const binding = require('@tauri-apps/cli-linux-riscv64-musl') + const bindingPackageVersion = require('@tauri-apps/cli-linux-riscv64-musl/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -291,7 +425,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-riscv64-gnu') + const binding = require('@tauri-apps/cli-linux-riscv64-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-linux-riscv64-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -303,7 +442,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-ppc64-gnu') + const binding = require('@tauri-apps/cli-linux-ppc64-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-linux-ppc64-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -314,7 +458,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-s390x-gnu') + const binding = require('@tauri-apps/cli-linux-s390x-gnu') + const bindingPackageVersion = require('@tauri-apps/cli-linux-s390x-gnu/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -324,34 +473,49 @@ function requireNative() { } else if (process.platform === 'openharmony') { if (process.arch === 'arm64') { try { - return require('./cli.linux-arm64-ohos.node') + return require('./cli.openharmony-arm64.node') } catch (e) { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-arm64-ohos') + const binding = require('@tauri-apps/cli-openharmony-arm64') + const bindingPackageVersion = require('@tauri-apps/cli-openharmony-arm64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } } else if (process.arch === 'x64') { try { - return require('./cli.linux-x64-ohos.node') + return require('./cli.openharmony-x64.node') } catch (e) { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-x64-ohos') + const binding = require('@tauri-apps/cli-openharmony-x64') + const bindingPackageVersion = require('@tauri-apps/cli-openharmony-x64/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } } else if (process.arch === 'arm') { try { - return require('./cli.linux-arm-ohos.node') + return require('./cli.openharmony-arm.node') } catch (e) { loadErrors.push(e) } try { - return require('@tauri-apps/cli-linux-arm-ohos') + const binding = require('@tauri-apps/cli-openharmony-arm') + const bindingPackageVersion = require('@tauri-apps/cli-openharmony-arm/package.json').version + if (bindingPackageVersion !== '2.10.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 2.10.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -366,22 +530,32 @@ function requireNative() { nativeBinding = requireNative() if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { + let wasiBinding = null + let wasiBindingError = null try { - nativeBinding = require('./cli.wasi.cjs') + wasiBinding = require('./cli.wasi.cjs') + nativeBinding = wasiBinding } catch (err) { if (process.env.NAPI_RS_FORCE_WASI) { - loadErrors.push(err) + wasiBindingError = err } } if (!nativeBinding) { try { - nativeBinding = require('@tauri-apps/cli-wasm32-wasi') + wasiBinding = require('@tauri-apps/cli-wasm32-wasi') + nativeBinding = wasiBinding } catch (err) { if (process.env.NAPI_RS_FORCE_WASI) { + wasiBindingError.cause = err loadErrors.push(err) } } } + if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) { + const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error') + error.cause = wasiBindingError + throw error + } } if (!nativeBinding) { @@ -390,7 +564,12 @@ if (!nativeBinding) { `Cannot find native binding. ` + `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + 'Please try `npm i` again after removing both package-lock.json and node_modules directory.', - { cause: loadErrors } + { + cause: loadErrors.reduce((err, cur) => { + cur.cause = err + return cur + }), + }, ) } throw new Error(`Failed to load native binding`)