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.
- package/dist/utils/rust-cli-wrapper.js +33 -125
- package/package.json +1 -1
|
@@ -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
|
-
? ['
|
|
25
|
-
: ['roxify-cli', 'roxify_cli'
|
|
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
|
-
//
|
|
28
|
-
const
|
|
29
|
-
join(baseDir,
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
53
|
+
throw new Error('Rust CLI binary not found');
|
|
104
54
|
}
|
|
105
55
|
return new Promise((resolve, reject) => {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
164
|
-
reject(new Error(`
|
|
71
|
+
else {
|
|
72
|
+
reject(new Error(`Rust encoder exited with status ${code}`));
|
|
165
73
|
}
|
|
166
|
-
})
|
|
74
|
+
});
|
|
167
75
|
});
|
|
168
76
|
}
|
package/package.json
CHANGED