fnva 0.0.11 → 0.0.12

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/bin/fnva.js CHANGED
@@ -38,6 +38,11 @@ function platformBinaryPath(platformOverride) {
38
38
  }
39
39
 
40
40
  function buildBinaryPath() {
41
+ // 如果设置了 FNVA_SKIP_NATIVE,跳过原生二进制查找
42
+ if (process.env.FNVA_SKIP_NATIVE === '1') {
43
+ return null;
44
+ }
45
+
41
46
  const platform = resolvePlatform();
42
47
  const binaryCandidates = [];
43
48
 
@@ -272,16 +277,100 @@ function generateSimpleScript(envVars, envType, envName) {
272
277
  return lines.join('\n');
273
278
  }
274
279
 
280
+ function handleNodeOnlyMode(args) {
281
+ const fs = require('fs');
282
+ const path = require('path');
283
+ const os = require('os');
284
+
285
+ // 简单的命令处理
286
+ if (args.length === 0) {
287
+ console.log('fnva - 环境管理工具 (Node.js 模式)');
288
+ console.log('');
289
+ console.log('支持的命令:');
290
+ console.log(' java list - 列出 Java 环境');
291
+ console.log(' java use <n> - 切换 Java 环境');
292
+ console.log('');
293
+ console.log('注意: Node.js 模式功能有限,建议使用原生二进制版本。');
294
+ return;
295
+ }
296
+
297
+ if (args[0] === 'java') {
298
+ const homeDir = os.homedir();
299
+ const fnvaDir = path.join(homeDir, '.fnva', 'java-packages');
300
+
301
+ if (args[1] === 'list') {
302
+ if (!fs.existsSync(fnvaDir)) {
303
+ console.log('No Java environments found');
304
+ return;
305
+ }
306
+
307
+ const versions = fs.readdirSync(fnvaDir, { withFileTypes: true })
308
+ .filter(dirent => dirent.isDirectory())
309
+ .map(dirent => dirent.name)
310
+ .sort();
311
+
312
+ if (versions.length === 0) {
313
+ console.log('No Java environments found');
314
+ } else {
315
+ console.log('Available java environments:');
316
+ versions.forEach(version => {
317
+ const jdkPath = path.join(fnvaDir, version);
318
+ if (fs.existsSync(path.join(jdkPath, 'release'))) {
319
+ try {
320
+ const releaseContent = fs.readFileSync(path.join(jdkPath, 'release'), 'utf8');
321
+ const versionMatch = releaseContent.match(/JAVA_VERSION="(.+)"/);
322
+ const javaVersion = versionMatch ? versionMatch[1].replace(/"/g, '') : 'Unknown';
323
+ console.log(` ${version}: Java ${javaVersion} (${jdkPath})`);
324
+ } catch (e) {
325
+ console.log(` ${version}: (${jdkPath})`);
326
+ }
327
+ }
328
+ });
329
+ }
330
+ } else if (args[1] === 'use' && args[2]) {
331
+ const version = args[2];
332
+ const jdkPath = path.join(fnvaDir, version);
333
+
334
+ if (!fs.existsSync(jdkPath)) {
335
+ console.error(`Java environment '${version}' not found`);
336
+ process.exit(1);
337
+ }
338
+
339
+ // 生成环境切换脚本
340
+ const envVars = {
341
+ JAVA_HOME: jdkPath
342
+ };
343
+
344
+ const script = generateSimpleScript(envVars, 'java', version);
345
+ console.log(script);
346
+ } else {
347
+ console.error('Usage: fnva java <list|use <version>>');
348
+ process.exit(1);
349
+ }
350
+ } else {
351
+ console.error(`Command '${args[0]}' not supported in Node.js mode`);
352
+ process.exit(1);
353
+ }
354
+ }
355
+
275
356
  function run() {
276
357
  const binaryPath = buildBinaryPath();
277
358
 
278
359
  if (!binaryPath) {
360
+ if (process.env.FNVA_SKIP_NATIVE === '1') {
361
+ // 纯 Node.js 模式 - 实现基本的环境切换功能
362
+ const args = process.argv.slice(2);
363
+ handleNodeOnlyMode(args);
364
+ return;
365
+ }
366
+
279
367
  console.error('Error: fnva native binary not found.');
280
368
  console.error('');
281
369
  console.error("Please either:");
282
370
  console.error(" 1) Run 'npm run build' (or 'npm run build:all') to produce platform binaries,");
283
371
  console.error(" 2) Install a release package that includes the platforms directory, or");
284
372
  console.error(" 3) Set FNVA_NATIVE_PATH to the full path of an existing fnva executable.");
373
+ console.error(" 4) Set FNVA_SKIP_NATIVE=1 to use Node.js mode (limited functionality).");
285
374
  process.exit(1);
286
375
  }
287
376
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
package/platforms/fnva CHANGED
Binary file
Binary file