@layerzerolabs/stellar-ts-bindings-gen 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/generate.ts +31 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/stellar-ts-bindings-gen",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "private": false,
5
5
  "description": "Generates TypeScript bindings from Stellar Soroban contract WASM files",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "tsx": "^4.21.0",
12
- "@layerzerolabs/vm-tooling-stellar": "1.2.10"
12
+ "@layerzerolabs/vm-tooling-stellar": "1.2.11"
13
13
  },
14
14
  "publishConfig": {
15
15
  "access": "public",
package/src/generate.ts CHANGED
@@ -1,21 +1,41 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import { execSync } from 'child_process';
3
+ import { execFileSync } from 'child_process';
4
4
  import path from 'path';
5
5
  import { fileURLToPath } from 'url';
6
6
 
7
7
  const __filename = fileURLToPath(import.meta.url);
8
8
  const __dirname = path.dirname(__filename);
9
9
 
10
- const args = process.argv.slice(2);
11
- const configIdx = args.indexOf('--config');
10
+ const DEFAULT_RUST_TOOLCHAIN = '1.90.0';
12
11
 
13
- if (configIdx === -1 || !args[configIdx + 1]) {
14
- console.error('Usage: stellar-ts-bindings-gen --config <path>');
12
+ const args = process.argv.slice(2);
13
+ const exitWithUsage = (): never => {
14
+ console.error('Usage: stellar-ts-bindings-gen --config <path> [--rust-toolchain <version>]');
15
15
  process.exit(1);
16
+ };
17
+
18
+ const parseOptionValue = (option: string): string | undefined => {
19
+ const optionIdx = args.indexOf(option);
20
+ if (optionIdx === -1) {
21
+ return undefined;
22
+ }
23
+
24
+ const value = args[optionIdx + 1];
25
+ if (!value || value.startsWith('--')) {
26
+ exitWithUsage();
27
+ }
28
+
29
+ return value;
30
+ };
31
+
32
+ const configPath = parseOptionValue('--config');
33
+ if (!configPath) {
34
+ exitWithUsage();
16
35
  }
17
36
 
18
- const configPath = args[configIdx + 1];
37
+ const requestedRustToolchain = parseOptionValue('--rust-toolchain');
38
+ const rustToolchain = requestedRustToolchain ?? DEFAULT_RUST_TOOLCHAIN;
19
39
 
20
40
  // Compute relative path from CWD to this package's Cargo.toml
21
41
  const cargoManifest = path.relative(process.cwd(), path.resolve(__dirname, '..', 'Cargo.toml'));
@@ -24,7 +44,11 @@ const script = `cargo run --manifest-path ${cargoManifest} -- --config ${configP
24
44
 
25
45
  try {
26
46
  const lzTool = path.resolve(__dirname, '..', 'node_modules', '.bin', 'lz-tool');
27
- execSync(`${lzTool} --script "${script}" stellar`, { stdio: 'inherit' });
47
+ execFileSync(
48
+ lzTool,
49
+ ['--env', `RUSTUP_TOOLCHAIN=${rustToolchain}`, '--script', script, 'stellar'],
50
+ { stdio: 'inherit' },
51
+ );
28
52
  } catch (e) {
29
53
  process.exit((e as { status?: number }).status || 1);
30
54
  }