fnva 0.0.29 → 0.0.31
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 +0 -6
- package/package.json +3 -1
- package/scripts/build-platforms.js +82 -0
- package/scripts/build-platforms.sh +43 -0
- package/scripts/ensure-executable-permissions.js +1 -6
- package/scripts/install-shell-integration.js +8 -6
- package/platforms/fnva +0 -0
- package/platforms/fnva.exe +0 -0
- package/platforms/skip.txt +0 -1
package/bin/fnva.js
CHANGED
|
@@ -55,12 +55,6 @@ function buildBinaryPath() {
|
|
|
55
55
|
// 1. Prebuilt binary shipped with the npm package
|
|
56
56
|
binaryCandidates.push(platformBinaryPath(platform));
|
|
57
57
|
|
|
58
|
-
// Flat legacy structure: platforms/fnva(.exe)
|
|
59
|
-
const scriptDir = __dirname;
|
|
60
|
-
const projectRoot = path.resolve(scriptDir, '..');
|
|
61
|
-
const flatBinaryName = platform === 'win32' ? 'fnva.exe' : 'fnva';
|
|
62
|
-
binaryCandidates.push(path.join(projectRoot, 'platforms', flatBinaryName));
|
|
63
|
-
|
|
64
58
|
// 2. User-provided override via environment variable
|
|
65
59
|
if (process.env.FNVA_NATIVE_PATH) {
|
|
66
60
|
binaryCandidates.push(process.env.FNVA_NATIVE_PATH);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnva",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
|
|
5
5
|
"author": "protagonistss",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"install-shell": "node scripts/install-shell-integration.js",
|
|
14
14
|
"uninstall-shell": "node scripts/uninstall-shell-integration.js",
|
|
15
15
|
"build": "scripts/build-local.sh",
|
|
16
|
+
"build:platforms": "node scripts/build-platforms.js",
|
|
17
|
+
"build:platforms:sh": "bash scripts/build-platforms.sh",
|
|
16
18
|
"build:all": "scripts/build-all.sh",
|
|
17
19
|
"check-permissions": "node scripts/check-permissions.js",
|
|
18
20
|
"postuninstall": "echo 'Uninstalling fnva shell integration...' && node scripts/uninstall-shell-integration.js"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cross-platform build helper to compile fnva binaries for common targets.
|
|
5
|
+
* Uses the current host toolchain; make sure required targets are installed via `rustup target add ...`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { spawnSync } = require('child_process');
|
|
11
|
+
|
|
12
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
13
|
+
|
|
14
|
+
const TARGETS = [
|
|
15
|
+
{ target: 'aarch64-apple-darwin', platform: 'darwin-arm64', bin: 'fnva' },
|
|
16
|
+
{ target: 'x86_64-apple-darwin', platform: 'darwin-x64', bin: 'fnva' },
|
|
17
|
+
{ target: 'x86_64-unknown-linux-gnu', platform: 'linux-x64', bin: 'fnva' },
|
|
18
|
+
{ target: 'x86_64-pc-windows-msvc', platform: 'win32-x64', bin: 'fnva.exe' },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
function run(cmd, args, options = {}) {
|
|
22
|
+
const result = spawnSync(cmd, args, { stdio: 'inherit', ...options });
|
|
23
|
+
if (result.error) {
|
|
24
|
+
throw result.error;
|
|
25
|
+
}
|
|
26
|
+
if (result.status !== 0) {
|
|
27
|
+
throw new Error(`${cmd} ${args.join(' ')} exited with code ${result.status}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function commandExists(cmd) {
|
|
32
|
+
const probe = spawnSync(cmd, ['--version'], { stdio: 'ignore' });
|
|
33
|
+
return probe.error == null && probe.status === 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function targetInstalled(target) {
|
|
37
|
+
const res = spawnSync('rustup', ['target', 'list', '--installed'], {
|
|
38
|
+
encoding: 'utf8',
|
|
39
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
40
|
+
});
|
|
41
|
+
if (res.error || typeof res.stdout !== 'string') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return res.stdout.split(/\r?\n/).some((line) => line.trim() === target);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function buildTarget(entry) {
|
|
48
|
+
const { target, platform, bin } = entry;
|
|
49
|
+
console.log(`==> Building ${target} -> platforms/${platform}/${bin}`);
|
|
50
|
+
|
|
51
|
+
if (!commandExists('cargo')) {
|
|
52
|
+
console.error('!! cargo not found; install Rust toolchain first');
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!targetInstalled(target)) {
|
|
58
|
+
console.warn(`!! target ${target} not installed; run: rustup target add ${target}`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
run('cargo', ['build', '--release', '--target', target], { cwd: ROOT });
|
|
63
|
+
|
|
64
|
+
const source = path.join(ROOT, 'target', target, 'release', bin);
|
|
65
|
+
const destDir = path.join(ROOT, 'platforms', platform);
|
|
66
|
+
const dest = path.join(destDir, bin);
|
|
67
|
+
|
|
68
|
+
if (!fs.existsSync(source)) {
|
|
69
|
+
console.warn(`!! Missing build output: ${source}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
74
|
+
fs.copyFileSync(source, dest);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function main() {
|
|
78
|
+
TARGETS.forEach(buildTarget);
|
|
79
|
+
console.log('==> Done. Binaries are in platforms/<os>-<arch>/');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Build platform-specific fnva binaries and place them under platforms/<os>-<arch>/
|
|
3
|
+
# Requires the corresponding Rust targets to be installed.
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
8
|
+
|
|
9
|
+
targets=(
|
|
10
|
+
"aarch64-apple-darwin:darwin-arm64:fnva"
|
|
11
|
+
"x86_64-apple-darwin:darwin-x64:fnva"
|
|
12
|
+
"x86_64-unknown-linux-gnu:linux-x64:fnva"
|
|
13
|
+
"x86_64-pc-windows-msvc:win32-x64:fnva.exe"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
for entry in "${targets[@]}"; do
|
|
17
|
+
IFS=: read -r target triple_dir bin_name <<<"${entry}"
|
|
18
|
+
echo "==> Building ${target} -> platforms/${triple_dir}/${bin_name}"
|
|
19
|
+
if ! command -v cargo >/dev/null 2>&1; then
|
|
20
|
+
echo "!! cargo not found; install Rust toolchain first" >&2
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
if ! rustup target list --installed | grep -q "^${target}$"; then
|
|
25
|
+
echo "!! target ${target} not installed; run: rustup target add ${target}" >&2
|
|
26
|
+
continue
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
cargo build --release --target "${target}"
|
|
30
|
+
|
|
31
|
+
src="${ROOT}/target/${target}/release/${bin_name}"
|
|
32
|
+
dest_dir="${ROOT}/platforms/${triple_dir}"
|
|
33
|
+
|
|
34
|
+
if [[ ! -f "${src}" ]]; then
|
|
35
|
+
echo "!! Missing build output: ${src}" >&2
|
|
36
|
+
continue
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
mkdir -p "${dest_dir}"
|
|
40
|
+
cp "${src}" "${dest_dir}/${bin_name}"
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
echo "==> Done. Binaries are in ${ROOT}/platforms/<os>-<arch>/"
|
|
@@ -49,7 +49,6 @@ function ensureExecutablePermissions() {
|
|
|
49
49
|
const platformDir = `${platform}-${arch}`;
|
|
50
50
|
const binaryName = platform === 'win32' ? 'fnva.exe' : 'fnva';
|
|
51
51
|
const archBinaryPath = path.join(platformsDir, platformDir, binaryName);
|
|
52
|
-
const flatBinaryPath = path.join(platformsDir, binaryName);
|
|
53
52
|
|
|
54
53
|
if (platform === 'win32') {
|
|
55
54
|
log('Info: Windows detected; chmod not required; skipping permission changes');
|
|
@@ -58,12 +57,8 @@ function ensureExecutablePermissions() {
|
|
|
58
57
|
|
|
59
58
|
if (fs.existsSync(archBinaryPath)) {
|
|
60
59
|
ensureExecutable(archBinaryPath, platformDir);
|
|
61
|
-
} else if (fs.existsSync(flatBinaryPath)) {
|
|
62
|
-
log('Info: falling back to legacy platforms/fnva layout');
|
|
63
|
-
ensureExecutable(flatBinaryPath, 'platforms/fnva');
|
|
64
60
|
} else {
|
|
65
61
|
log(`Warning: binary not found: ${archBinaryPath}`);
|
|
66
|
-
log(` Also checked: ${flatBinaryPath}`);
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
if (process.env.npm_config_global === 'true') {
|
|
@@ -79,4 +74,4 @@ function ensureExecutablePermissions() {
|
|
|
79
74
|
}
|
|
80
75
|
}
|
|
81
76
|
|
|
82
|
-
ensureExecutablePermissions();
|
|
77
|
+
ensureExecutablePermissions();
|
|
@@ -7,6 +7,9 @@ const fs = require('fs');
|
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const os = require('os');
|
|
9
9
|
|
|
10
|
+
// Absolute path to the packaged fnva shim (bin/fnva.js)
|
|
11
|
+
const FNVA_SHIM = path.resolve(__dirname, '..', 'bin', 'fnva.js');
|
|
12
|
+
|
|
10
13
|
function detectShell() {
|
|
11
14
|
if (process.platform === 'win32') {
|
|
12
15
|
return 'powershell';
|
|
@@ -82,9 +85,8 @@ function getBashFunction() {
|
|
|
82
85
|
return `
|
|
83
86
|
# fnva auto integration (added by npm install)
|
|
84
87
|
fnva() {
|
|
85
|
-
local __fnva_bin
|
|
86
|
-
|
|
87
|
-
if [[ -z "$__fnva_bin" || ! -x "$__fnva_bin" ]]; then
|
|
88
|
+
local __fnva_bin="${FNVA_SHIM}"
|
|
89
|
+
if [[ ! -x "$__fnva_bin" ]]; then
|
|
88
90
|
echo "fnva: binary not found in PATH" >&2
|
|
89
91
|
return 127
|
|
90
92
|
fi
|
|
@@ -108,8 +110,8 @@ function getFishFunction() {
|
|
|
108
110
|
return `
|
|
109
111
|
# fnva auto integration (added by npm install)
|
|
110
112
|
function fnva
|
|
111
|
-
set __fnva_bin
|
|
112
|
-
if test -
|
|
113
|
+
set __fnva_bin "${FNVA_SHIM}"
|
|
114
|
+
if test ! -x "$__fnva_bin"
|
|
113
115
|
echo "fnva: binary not found in PATH" >&2
|
|
114
116
|
return 127
|
|
115
117
|
end
|
|
@@ -239,4 +241,4 @@ module.exports = {
|
|
|
239
241
|
getShellFunction,
|
|
240
242
|
isFunctionInstalled,
|
|
241
243
|
installShellIntegration,
|
|
242
|
-
};
|
|
244
|
+
};
|
package/platforms/fnva
DELETED
|
Binary file
|
package/platforms/fnva.exe
DELETED
|
Binary file
|
package/platforms/skip.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Skipping cross-compiled build for aarch64-unknown-linux-gnu
|