## Summary - Adds a `--upgrade [version]` CLI flag that upgrades the global CodeNomad CLI server package and exits. - Uses `bun add --global` for the package upgrade path and includes server-side tests. - Rebased onto the latest `dev` because we do not have permission to push to the original fork branch. ## Credits - Original PR: #363 - Original author: Pascal André (@pascalandr) ## Testing - Not run; this PR only recreates the rebased branch from #363. --------- Co-authored-by: Pascal André <pascalandr@gmail.com>
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { describe, it } from "node:test"
|
|
import { buildUpgradeCommand, detectPackageManager, formatUpgradeCommand } from "./cli-upgrade"
|
|
|
|
describe("cli upgrade", () => {
|
|
it("defaults to npm when no package manager can be detected", () => {
|
|
assert.equal(detectPackageManager({}), "npm")
|
|
})
|
|
|
|
it("detects package managers from npm user agent", () => {
|
|
assert.equal(detectPackageManager({ npm_config_user_agent: "pnpm/9.0.0 node/v22" }), "pnpm")
|
|
assert.equal(detectPackageManager({ npm_config_user_agent: "bun/1.0.0" }), "bun")
|
|
assert.equal(detectPackageManager({ npm_config_user_agent: "npm/10.0.0 node/v22" }), "npm")
|
|
})
|
|
|
|
it("builds latest upgrade command by default", () => {
|
|
const command = buildUpgradeCommand(undefined, "npm")
|
|
|
|
assert.equal(command.packageSpec, "@neuralnomads/codenomad@latest")
|
|
assert.deepEqual(command.args, ["install", "-g", "@neuralnomads/codenomad@latest"])
|
|
assert.equal(formatUpgradeCommand(command), "npm install -g @neuralnomads/codenomad@latest")
|
|
})
|
|
|
|
it("builds a versioned upgrade command", () => {
|
|
const command = buildUpgradeCommand("0.10.5", "pnpm")
|
|
|
|
assert.equal(command.packageSpec, "@neuralnomads/codenomad@0.10.5")
|
|
assert.deepEqual(command.args, ["install", "-g", "@neuralnomads/codenomad@0.10.5"])
|
|
assert.equal(formatUpgradeCommand(command), "pnpm install -g @neuralnomads/codenomad@0.10.5")
|
|
})
|
|
|
|
it("uses bun add for Bun installs", () => {
|
|
const command = buildUpgradeCommand("0.10.5", "bun")
|
|
|
|
assert.equal(command.packageSpec, "@neuralnomads/codenomad@0.10.5")
|
|
assert.deepEqual(command.args, ["add", "-g", "@neuralnomads/codenomad@0.10.5"])
|
|
assert.equal(formatUpgradeCommand(command), "bun add -g @neuralnomads/codenomad@0.10.5")
|
|
})
|
|
})
|