Skip to content

Commit 77e3e6e

Browse files
authored
Merge pull request #30 from pkgxdev/libpkgx-semver
Use libpkgx semver
2 parents f741fa5 + b8234aa commit 77e3e6e

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,37 @@ jobs:
2222
- run: deno lint .
2323
- run: deno check ./pkgm.ts
2424

25+
#TODO test on linux! we are currently broken due to rpath issues
26+
# https://github.com/pkgxdev/pkgm/pull/30#issuecomment-2678957666
2527
test:
26-
runs-on: ubuntu-latest
28+
runs-on: macos-latest
2729
steps:
2830
- uses: actions/checkout@v4
2931
- uses: pkgxdev/setup@v3
32+
33+
- run: |
34+
if [[ "$(/usr/local/bin/pkgx --version)" != "pkgx 2"* ]]; then
35+
exit 1
36+
fi
37+
3038
- run: ./pkgm.ts i git
3139
- run: /usr/local/bin/git --version
3240

3341
- run: ./pkgm.ts i pkgx.sh/brewkit
3442
- run: /usr/local/bin/bk --help
3543

44+
# check repeats work
3645
- run: rm /usr/local/bin/bk
3746
- run: test ! -f /usr/local/bin/bk
3847
- run: ./pkgm.ts i pkgx.sh/brewkit
3948
- run: /usr/local/bin/bk --help
4049

41-
- run: ./pkgm.ts li pkgx.sh/brewkit
42-
- run: ~/.local/bin/bk --help
50+
- run: ./pkgm.ts li gum
51+
- run: ~/.local/bin/gum --version
4352

44-
- run: |
45-
if [[ "$(/usr/local/bin/pkgx --version)" != "pkgx 2"* ]]; then
46-
exit 1
47-
fi
53+
# https://github.com/pkgxdev/pkgm/issues/24
54+
- run: ./pkgm.ts i curl
55+
- run: /usr/local/bin/curl -L pkgx.sh
4856

4957
# TODO pending: https://github.com/pkgxdev/pantry/issues/8487
5058
# - run: ./pkgm.ts i xpra.org # https://github.com/pkgxdev/pkgm/issues/13

pkgm.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/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
2+
import { SemVer, semver } from "https://deno.land/x/libpkgx@v0.20.3/mod.ts";
23
import { dirname, fromFileUrl, join } from "jsr:@std/path@^1";
34
import { ensureDir, existsSync } from "jsr:@std/fs@^1";
45
import { parseArgs } from "jsr:@std/cli@^1";
5-
import * as semver from "jsr:@std/semver@^1";
66

77
function standardPath() {
88
let path = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
@@ -283,32 +283,31 @@ async function create_v_symlinks(prefix: string) {
283283
const shelf = dirname(prefix);
284284

285285
const versions = [];
286-
for await (const entry of Deno.readDir(shelf)) {
287-
if (
288-
entry.isDirectory && !entry.isSymlink && entry.name.startsWith("v") &&
289-
entry.name != "var"
290-
) {
291-
try {
292-
versions.push(semver.parse(entry.name));
293-
} catch {
294-
//ignore
295-
}
286+
for await (const { name, isDirectory, isSymlink } of Deno.readDir(shelf)) {
287+
console.log(name, isDirectory, isSymlink);
288+
if (isSymlink) continue;
289+
if (!isDirectory) continue;
290+
if (!name.startsWith("v")) continue;
291+
if (name == "var") continue;
292+
const version = semver.parse(name);
293+
if (version) {
294+
versions.push(version);
296295
}
297296
}
298297

299298
// collect an Record of versions per major version
300-
const major_versions: Record<number, semver.SemVer> = {};
299+
const major_versions: Record<number, SemVer> = {};
301300
for (const version of versions) {
302301
if (
303302
major_versions[version.major] === undefined ||
304-
semver.greaterThan(version, major_versions[version.major])
303+
version.gt(major_versions[version.major])
305304
) {
306305
major_versions[version.major] = version;
307306
}
308307
}
309308

310-
for (const [key, value] of Object.entries(major_versions)) {
311-
symlink_with_overwrite(`v${semver.format(value)}`, join(shelf, `v${key}`));
309+
for (const [key, semver] of Object.entries(major_versions)) {
310+
symlink_with_overwrite(`v${semver}`, join(shelf, `v${key}`));
312311
}
313312
}
314313

0 commit comments

Comments
 (0)