Update runtime checks and installer behavior
This commit is contained in:
35
scripts/check-node-version.mjs
Normal file
35
scripts/check-node-version.mjs
Normal file
@@ -0,0 +1,35 @@
|
||||
const MIN_NODE_VERSION = "20.18.1";
|
||||
|
||||
function parseNodeVersion(version) {
|
||||
const [major = "0", minor = "0", patch = "0"] = version.replace(/^v/, "").split(".");
|
||||
return {
|
||||
major: Number.parseInt(major, 10) || 0,
|
||||
minor: Number.parseInt(minor, 10) || 0,
|
||||
patch: Number.parseInt(patch, 10) || 0,
|
||||
};
|
||||
}
|
||||
|
||||
function compareNodeVersions(left, right) {
|
||||
if (left.major !== right.major) return left.major - right.major;
|
||||
if (left.minor !== right.minor) return left.minor - right.minor;
|
||||
return left.patch - right.patch;
|
||||
}
|
||||
|
||||
function isSupportedNodeVersion(version = process.versions.node) {
|
||||
return compareNodeVersions(parseNodeVersion(version), parseNodeVersion(MIN_NODE_VERSION)) >= 0;
|
||||
}
|
||||
|
||||
function getUnsupportedNodeVersionLines(version = process.versions.node) {
|
||||
return [
|
||||
`feynman requires Node.js ${MIN_NODE_VERSION} or later (detected ${version}).`,
|
||||
"Switch to Node 20 with `nvm install 20 && nvm use 20`, or use the standalone installer:",
|
||||
"curl -fsSL https://feynman.is/install | bash",
|
||||
];
|
||||
}
|
||||
|
||||
if (!isSupportedNodeVersion()) {
|
||||
for (const line of getUnsupportedNodeVersionLines()) {
|
||||
console.error(line);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -146,6 +146,16 @@ Workarounds:
|
||||
Write-Host "$installBinDir is already on PATH."
|
||||
}
|
||||
|
||||
$resolvedCommand = Get-Command feynman -ErrorAction SilentlyContinue
|
||||
if ($resolvedCommand -and $resolvedCommand.Source -ne $shimPath) {
|
||||
Write-Warning "Current shell resolves feynman to $($resolvedCommand.Source)"
|
||||
Write-Host "Run in a new shell, or run: `$env:Path = '$installBinDir;' + `$env:Path"
|
||||
Write-Host "Then run: feynman"
|
||||
if ($resolvedCommand.Source -like "*node_modules*@companion-ai*feynman*") {
|
||||
Write-Host "If that path is an old global npm install, remove it with: npm uninstall -g @companion-ai/feynman"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Feynman $resolvedVersion installed successfully."
|
||||
} finally {
|
||||
if (Test-Path $tmpDir) {
|
||||
|
||||
@@ -160,6 +160,27 @@ require_command() {
|
||||
fi
|
||||
}
|
||||
|
||||
warn_command_conflict() {
|
||||
expected_path="$INSTALL_BIN_DIR/feynman"
|
||||
resolved_path="$(command -v feynman 2>/dev/null || true)"
|
||||
|
||||
if [ -z "$resolved_path" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$resolved_path" != "$expected_path" ]; then
|
||||
step "Warning: current shell resolves feynman to $resolved_path"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && hash -r && feynman"
|
||||
step "Or launch directly: $expected_path"
|
||||
|
||||
case "$resolved_path" in
|
||||
*"/node_modules/@companion-ai/feynman/"* | *"/node_modules/.bin/feynman")
|
||||
step "If that path is an old global npm install, remove it with: npm uninstall -g @companion-ai/feynman"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
resolve_release_metadata() {
|
||||
normalized_version="$(normalize_version "$VERSION")"
|
||||
|
||||
@@ -290,20 +311,22 @@ add_to_path
|
||||
case "$path_action" in
|
||||
added)
|
||||
step "PATH updated for future shells in $path_profile"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && feynman"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && hash -r && feynman"
|
||||
;;
|
||||
configured)
|
||||
step "PATH is already configured for future shells in $path_profile"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && feynman"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && hash -r && feynman"
|
||||
;;
|
||||
skipped)
|
||||
step "PATH update skipped"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && feynman"
|
||||
step "Run now: export PATH=\"$INSTALL_BIN_DIR:\$PATH\" && hash -r && feynman"
|
||||
;;
|
||||
*)
|
||||
step "$INSTALL_BIN_DIR is already on PATH"
|
||||
step "Run: feynman"
|
||||
step "Run: hash -r && feynman"
|
||||
;;
|
||||
esac
|
||||
|
||||
warn_command_conflict
|
||||
|
||||
printf 'Feynman %s installed successfully.\n' "$resolved_version"
|
||||
|
||||
Reference in New Issue
Block a user