From b8234aafd38833233065b82fb7e32c49a2aa6c2b Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 24 Feb 2025 10:44:11 -0500 Subject: [PATCH] Use libpkgx semver Fixes #24 --- .github/workflows/ci.yml | 22 +++++++++++++++------- pkgm.ts | 29 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abad516..f338980 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,29 +22,37 @@ jobs: - run: deno lint . - run: deno check ./pkgm.ts + #TODO test on linux! we are currently broken due to rpath issues + # https://github.com/pkgxdev/pkgm/pull/30#issuecomment-2678957666 test: - runs-on: ubuntu-latest + runs-on: macos-latest steps: - uses: actions/checkout@v4 - uses: pkgxdev/setup@v3 + + - run: | + if [[ "$(/usr/local/bin/pkgx --version)" != "pkgx 2"* ]]; then + exit 1 + fi + - run: ./pkgm.ts i git - run: /usr/local/bin/git --version - run: ./pkgm.ts i pkgx.sh/brewkit - run: /usr/local/bin/bk --help + # check repeats work - run: rm /usr/local/bin/bk - run: test ! -f /usr/local/bin/bk - run: ./pkgm.ts i pkgx.sh/brewkit - run: /usr/local/bin/bk --help - - run: ./pkgm.ts li pkgx.sh/brewkit - - run: ~/.local/bin/bk --help + - run: ./pkgm.ts li gum + - run: ~/.local/bin/gum --version - - run: | - if [[ "$(/usr/local/bin/pkgx --version)" != "pkgx 2"* ]]; then - exit 1 - fi + # https://github.com/pkgxdev/pkgm/issues/24 + - run: ./pkgm.ts i curl + - run: /usr/local/bin/curl -L pkgx.sh # TODO pending: https://github.com/pkgxdev/pantry/issues/8487 # - run: ./pkgm.ts i xpra.org # https://github.com/pkgxdev/pkgm/issues/13 diff --git a/pkgm.ts b/pkgm.ts index 53af169..2e5d84a 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -1,8 +1,8 @@ #!/usr/bin/env -S pkgx --quiet deno^2.1 run --ext=ts --allow-sys=uid --allow-run --allow-env=PKGX_DIR,HOMEBREW_PREFIX,HOME --allow-read=/usr/local/pkgs,${HOME}/.local/pkgs +import { SemVer, semver } from "https://deno.land/x/libpkgx@v0.20.3/mod.ts"; import { dirname, fromFileUrl, join } from "jsr:@std/path@^1"; import { ensureDir, existsSync } from "jsr:@std/fs@^1"; import { parseArgs } from "jsr:@std/cli@^1"; -import * as semver from "jsr:@std/semver@^1"; function standardPath() { let path = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"; @@ -283,32 +283,31 @@ async function create_v_symlinks(prefix: string) { const shelf = dirname(prefix); const versions = []; - for await (const entry of Deno.readDir(shelf)) { - if ( - entry.isDirectory && !entry.isSymlink && entry.name.startsWith("v") && - entry.name != "var" - ) { - try { - versions.push(semver.parse(entry.name)); - } catch { - //ignore - } + for await (const { name, isDirectory, isSymlink } of Deno.readDir(shelf)) { + console.log(name, isDirectory, isSymlink); + if (isSymlink) continue; + if (!isDirectory) continue; + if (!name.startsWith("v")) continue; + if (name == "var") continue; + const version = semver.parse(name); + if (version) { + versions.push(version); } } // collect an Record of versions per major version - const major_versions: Record = {}; + const major_versions: Record = {}; for (const version of versions) { if ( major_versions[version.major] === undefined || - semver.greaterThan(version, major_versions[version.major]) + version.gt(major_versions[version.major]) ) { major_versions[version.major] = version; } } - for (const [key, value] of Object.entries(major_versions)) { - symlink_with_overwrite(`v${semver.format(value)}`, join(shelf, `v${key}`)); + for (const [key, semver] of Object.entries(major_versions)) { + symlink_with_overwrite(`v${semver}`, join(shelf, `v${key}`)); } }