roxify 1.5.10 → 1.5.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.
@@ -19,79 +19,29 @@ catch {
19
19
  moduleDir = process.cwd();
20
20
  }
21
21
  function findRustBinary() {
22
- const candidates = [];
23
22
  const binNames = process.platform === 'win32'
24
- ? ['roxify-cli.exe', 'roxify_cli.exe', 'roxify_native.exe']
25
- : ['roxify-cli', 'roxify_cli', 'roxify_native'];
23
+ ? ['roxify_native.exe', 'roxify-cli.exe', 'roxify_cli.exe']
24
+ : ['roxify_native', 'roxify-cli', 'roxify_cli'];
26
25
  const baseDir = typeof moduleDir !== 'undefined' ? moduleDir : process.cwd();
27
- // Possible locations relative to this file (works in repo and in packaged dist)
28
- const relativeDirs = [
29
- join(baseDir, '..', '..', 'target', 'release'),
30
- join(baseDir, '..', '..', 'dist'),
31
- join(baseDir, '..'),
32
- join(baseDir, '..', '..'),
33
- join(baseDir, '..', 'target', 'release'),
34
- ];
35
- for (const dir of relativeDirs) {
36
- for (const name of binNames) {
37
- candidates.push(join(dir, name));
26
+ // Check immediate locations (for packaged CLI)
27
+ for (const name of binNames) {
28
+ const local = join(baseDir, name);
29
+ if (existsSync(local)) {
30
+ return local;
38
31
  }
39
- }
40
- // Walk up parents to find a workspace-level target/release (repo root may contain target)
41
- try {
42
- let cur = baseDir;
43
- for (let i = 0; i < 8; i++) {
44
- for (const name of binNames) {
45
- candidates.push(join(cur, '..', '..', '..', '..', '..', '..', '..', 'target', 'release', name));
46
- candidates.push(join(cur, '..', '..', '..', '..', '..', 'target', 'release', name));
47
- candidates.push(join(cur, '..', '..', '..', 'target', 'release', name));
48
- candidates.push(join(cur, '..', '..', 'target', 'release', name));
49
- candidates.push(join(cur, '..', 'target', 'release', name));
50
- candidates.push(join(cur, 'target', 'release', name));
51
- }
52
- const parent = join(cur, '..');
53
- if (parent === cur)
54
- break;
55
- cur = parent;
56
- }
57
- }
58
- catch (e) { }
59
- // Common global paths (last resort)
60
- if (process.platform !== 'win32') {
61
- candidates.push('/usr/local/bin/roxify_native');
62
- candidates.push('/usr/bin/roxify_native');
63
- }
64
- for (const p of candidates) {
65
- try {
66
- if (existsSync(p)) {
67
- // eslint-disable-next-line no-console
68
- console.log(`Found Rust binary candidate: ${p}`);
69
- return p;
70
- }
32
+ const parentLocal = join(baseDir, '..', name);
33
+ if (existsSync(parentLocal)) {
34
+ return parentLocal;
71
35
  }
72
- catch (e) { }
73
36
  }
74
- // Search in PATH for common binary names
75
- try {
76
- const which = process.platform === 'win32' ? 'where' : 'which';
77
- const { execSync } = require('child_process');
78
- for (const name of binNames) {
79
- try {
80
- const out = execSync(`${which} ${name}`, { encoding: 'utf-8' })
81
- .split('\n')[0]
82
- .trim();
83
- if (out && existsSync(out)) {
84
- // eslint-disable-next-line no-console
85
- console.debug(`Found Rust binary in PATH: ${out}`);
86
- return out;
87
- }
88
- }
89
- catch (e) {
90
- // ignore
91
- }
37
+ // Check target/release (for development)
38
+ const targetRelease = join(baseDir, '..', '..', 'target', 'release');
39
+ for (const name of binNames) {
40
+ const targetPath = join(targetRelease, name);
41
+ if (existsSync(targetPath)) {
42
+ return targetPath;
92
43
  }
93
44
  }
94
- catch (e) { }
95
45
  return null;
96
46
  }
97
47
  export function isRustBinaryAvailable() {
@@ -100,69 +50,27 @@ export function isRustBinaryAvailable() {
100
50
  export async function encodeWithRustCLI(inputPath, outputPath, compressionLevel = 3, passphrase, encryptType = 'aes', name) {
101
51
  const cliPath = findRustBinary();
102
52
  if (!cliPath) {
103
- throw new Error('Rust CLI binary not found. Run: cargo build --release');
53
+ throw new Error('Rust CLI binary not found');
104
54
  }
105
55
  return new Promise((resolve, reject) => {
106
- const baseArgs = ['encode', '--level', String(compressionLevel)];
107
- const addNameArgs = (arr) => {
108
- if (name) {
109
- arr.push('--name', name);
110
- }
111
- };
112
- const addPassArgs = (arr) => {
113
- if (passphrase) {
114
- arr.push('--passphrase', passphrase);
115
- arr.push('--encrypt', encryptType);
116
- }
117
- };
118
- const args = [...baseArgs];
119
- addNameArgs(args);
120
- addPassArgs(args);
56
+ const args = ['encode', '--level', String(compressionLevel)];
57
+ if (name) {
58
+ args.push('--name', name);
59
+ }
60
+ if (passphrase) {
61
+ args.push('--passphrase', passphrase);
62
+ args.push('--encrypt', encryptType);
63
+ }
121
64
  args.push(inputPath, outputPath);
122
- const spawnAndWait = (argsToUse) => {
123
- return new Promise((res, rej) => {
124
- const proc = spawn(cliPath, argsToUse);
125
- let stderr = '';
126
- proc.stderr.on('data', (data) => {
127
- stderr += data.toString();
128
- });
129
- proc.on('error', (err) => rej(err));
130
- proc.on('close', (code) => res({ code, stderr }));
131
- });
132
- };
133
- (async () => {
134
- try {
135
- const debugMsg = `Rust CLI: ${cliPath} ${args.join(' ')}`;
136
- // eslint-disable-next-line no-console
137
- console.log(debugMsg);
138
- let result = await spawnAndWait(args);
139
- if (result.code === 0)
140
- return resolve();
141
- // If the error mentions an unexpected '--name' arg (older binary), retry without name
142
- if (name &&
143
- result.stderr &&
144
- (/unexpected argument.*--name/.test(result.stderr) ||
145
- /unexpected argument .*'--name'/.test(result.stderr) ||
146
- result.stderr.includes("'--name'"))) {
147
- const argsNoName = [...baseArgs];
148
- addPassArgs(argsNoName);
149
- argsNoName.push(inputPath, outputPath);
150
- // eslint-disable-next-line no-console
151
- console.log('Rust CLI rejected --name; retrying without --name');
152
- const retryDebug = `Retrying Rust CLI: ${cliPath} ${argsNoName.join(' ')}`;
153
- // eslint-disable-next-line no-console
154
- console.log(retryDebug);
155
- result = await spawnAndWait(argsNoName);
156
- // eslint-disable-next-line no-console
157
- console.log(`Rust retry exited with code ${result.code}`);
158
- if (result.code === 0)
159
- return resolve();
160
- }
161
- reject(new Error(`Rust CLI exited with code ${result.code}: ${result.stderr}`));
65
+ const proc = spawn(cliPath, args, { stdio: 'inherit' });
66
+ proc.on('error', (err) => reject(err));
67
+ proc.on('close', (code) => {
68
+ if (code === 0) {
69
+ resolve();
162
70
  }
163
- catch (err) {
164
- reject(new Error(`Failed to spawn Rust CLI: ${err.message || err}`));
71
+ else {
72
+ reject(new Error(`Rust encoder exited with status ${code}`));
165
73
  }
166
- })();
74
+ });
167
75
  });
168
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxify",
3
- "version": "1.5.10",
3
+ "version": "1.5.11",
4
4
  "description": "Ultra-lightweight PNG steganography with native Rust acceleration. Encode binary data into PNG images with zstd compression.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",