Repository navigation
feat(cli): add hunk update self-update command
#788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "hunkdiff": minor | ||
| --- | ||
|
|
||
| Add `hunk update` to self-update Hunk with the package manager that installed it (npm or Homebrew), with guidance for Nix, mise, and source installs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { join } from "node:path"; | ||
| import { detectInstallSource, detectNpmClient, resolveDevInstallDir } from "./installSource"; | ||
|
|
||
| const HOME_DIR = join("/", "home", "reviewer"); | ||
|
|
||
| describe("install source detection", () => { | ||
| test("honors an explicitly declared install source", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: { HUNK_INSTALL_SOURCE: "nix" }, | ||
| executablePath: join("/", "usr", "local", "bin", "hunk"), | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("nix"); | ||
| }); | ||
|
|
||
| test("accepts dev as a declared install source", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: { HUNK_INSTALL_SOURCE: "dev" }, | ||
| executablePath: join("/", "opt", "hunk", "bin", "hunk"), | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("dev"); | ||
| }); | ||
|
|
||
| test("ignores unknown declared install sources", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: { HUNK_INSTALL_SOURCE: "chocolatey" }, | ||
| executablePath: join("/", "opt", "hunk", "bin", "hunk"), | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("npm"); | ||
| }); | ||
|
|
||
| test("detects nixpkgs installs from their store path", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: "/nix/store/hash-hunk/bin/hunk", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("nix"); | ||
| }); | ||
|
|
||
| test("detects mise installs from their install directory", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: "/home/reviewer/.local/share/mise/installs/aqua-modem-dev-hunk/1.2.3/hunk", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("mise"); | ||
| }); | ||
|
|
||
| test("detects Homebrew installs from a resolved Cellar path", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: "/usr/local/bin/hunk", | ||
| realpath: () => "/usr/local/Cellar/hunk/1.2.3/bin/hunk", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("homebrew"); | ||
| }); | ||
|
|
||
| test("detects Homebrew installs under the Apple silicon and Linux prefixes", () => { | ||
| for (const executablePath of [ | ||
| "/opt/homebrew/bin/hunk", | ||
| "/home/linuxbrew/.linuxbrew/bin/hunk", | ||
| ]) { | ||
| expect(detectInstallSource({ env: {}, executablePath, homeDir: HOME_DIR })).toBe("homebrew"); | ||
| } | ||
| }); | ||
|
|
||
| test("does not classify a Homebrew-installed Bun running Hunk from source as Homebrew", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: "/opt/homebrew/Cellar/bun/1.1.42/bin/bun", | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("npm"); | ||
| }); | ||
|
|
||
| test("keeps npm for global npm packages under a Homebrew-installed Node", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: "/opt/homebrew/lib/node_modules/hunkdiff-darwin-arm64/bin/hunk", | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("npm"); | ||
| }); | ||
|
|
||
| test("detects local source builds installed into the default install directory", () => { | ||
| // Built from this platform's own default so the check tracks `scripts/install-bin.ts`. | ||
| const installDir = resolveDevInstallDir({}, HOME_DIR); | ||
| expect(installDir).toBeDefined(); | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: join(installDir!, "hunk"), | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("dev"); | ||
| }); | ||
|
|
||
| test("detects local source builds inside an overridden install directory", () => { | ||
| const installDir = join(HOME_DIR, "tools", "bin"); | ||
| expect( | ||
| detectInstallSource({ | ||
| env: { HUNK_INSTALL_DIR: installDir }, | ||
| executablePath: join(installDir, "hunk"), | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("dev"); | ||
| }); | ||
|
|
||
| test("detects local source builds from an untagged version", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: join("/", "opt", "hunk", "bin", "hunk"), | ||
| version: "0.0.0-unknown", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("dev"); | ||
| }); | ||
|
|
||
| test("falls back to the npm package path", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: join(HOME_DIR, ".nvm", "versions", "node", "v22", "bin", "hunk"), | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("npm"); | ||
| }); | ||
|
|
||
| test("keeps npm for paths that only mention mise outside an install directory", () => { | ||
| expect( | ||
| detectInstallSource({ | ||
| env: {}, | ||
| executablePath: "/home/mise/projects/hunk/node_modules/.bin/hunk", | ||
| version: "1.2.3", | ||
| homeDir: HOME_DIR, | ||
| }), | ||
| ).toBe("npm"); | ||
| }); | ||
|
|
||
| test("resolves the install:bin target directory from the environment", () => { | ||
| expect(resolveDevInstallDir({ HUNK_INSTALL_DIR: "/srv/bin" }, HOME_DIR)).toBe("/srv/bin"); | ||
| expect(resolveDevInstallDir({}, undefined)).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("npm client detection", () => { | ||
| test("picks bun for bun global installs", () => { | ||
| expect(detectNpmClient(join(HOME_DIR, ".bun", "bin", "hunk"))).toBe("bun"); | ||
| }); | ||
|
|
||
| test("picks pnpm for pnpm global installs", () => { | ||
| expect(detectNpmClient(join(HOME_DIR, ".local", "share", "pnpm", "hunk"))).toBe("pnpm"); | ||
| }); | ||
|
|
||
| test("picks npm for everything else", () => { | ||
| expect( | ||
| detectNpmClient(join("/", "usr", "lib", "node_modules", "hunkdiff", "bin", "hunk")), | ||
| ).toBe("npm"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.