fnva 0.0.12 → 0.0.14

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
@@ -43,6 +43,11 @@ function buildBinaryPath() {
43
43
  return null;
44
44
  }
45
45
 
46
+ // 如果设置了 FNVA_AUTO_MODE,自动使用 Node.js 模式
47
+ if (process.env.FNVA_AUTO_MODE === '1') {
48
+ return null;
49
+ }
50
+
46
51
  const platform = resolvePlatform();
47
52
  const binaryCandidates = [];
48
53
 
@@ -314,28 +319,50 @@ function handleNodeOnlyMode(args) {
314
319
  } else {
315
320
  console.log('Available java environments:');
316
321
  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})`);
322
+ const versionDir = path.join(fnvaDir, version);
323
+ const jdkSubdirs = fs.readdirSync(versionDir, { withFileTypes: true })
324
+ .filter(dirent => dirent.isDirectory())
325
+ .map(dirent => dirent.name);
326
+
327
+ if (jdkSubdirs.length > 0) {
328
+ const jdkSubdir = jdkSubdirs[0];
329
+ const fullJdkPath = path.join(versionDir, jdkSubdir);
330
+
331
+ if (fs.existsSync(path.join(fullJdkPath, 'release'))) {
332
+ try {
333
+ const releaseContent = fs.readFileSync(path.join(fullJdkPath, 'release'), 'utf8');
334
+ const versionMatch = releaseContent.match(/JAVA_VERSION="(.+)"/);
335
+ const javaVersion = versionMatch ? versionMatch[1].replace(/"/g, '') : 'Unknown';
336
+ console.log(` ${version} (current): Java ${javaVersion} (${fullJdkPath})`);
337
+ } catch (e) {
338
+ console.log(` ${version} (${fullJdkPath})`);
339
+ }
326
340
  }
327
341
  }
328
342
  });
329
343
  }
330
344
  } else if (args[1] === 'use' && args[2]) {
331
345
  const version = args[2];
332
- const jdkPath = path.join(fnvaDir, version);
346
+ const versionDir = path.join(fnvaDir, version);
333
347
 
334
- if (!fs.existsSync(jdkPath)) {
348
+ if (!fs.existsSync(versionDir)) {
335
349
  console.error(`Java environment '${version}' not found`);
336
350
  process.exit(1);
337
351
  }
338
352
 
353
+ // 查找实际的 JDK 目录
354
+ const jdkSubdirs = fs.readdirSync(versionDir, { withFileTypes: true })
355
+ .filter(dirent => dirent.isDirectory())
356
+ .map(dirent => dirent.name);
357
+
358
+ if (jdkSubdirs.length === 0) {
359
+ console.error(`No JDK installation found in ${versionDir}`);
360
+ process.exit(1);
361
+ }
362
+
363
+ const jdkPath = path.join(versionDir, jdkSubdirs[0]);
364
+ const jdkBinPath = path.join(jdkPath, 'bin');
365
+
339
366
  // 生成环境切换脚本
340
367
  const envVars = {
341
368
  JAVA_HOME: jdkPath
@@ -357,7 +384,7 @@ function run() {
357
384
  const binaryPath = buildBinaryPath();
358
385
 
359
386
  if (!binaryPath) {
360
- if (process.env.FNVA_SKIP_NATIVE === '1') {
387
+ if (process.env.FNVA_SKIP_NATIVE === '1' || process.env.FNVA_AUTO_MODE === '1') {
361
388
  // 纯 Node.js 模式 - 实现基本的环境切换功能
362
389
  const args = process.argv.slice(2);
363
390
  handleNodeOnlyMode(args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
package/platforms/fnva CHANGED
Binary file
Binary file