Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ jobs:
- run: ~/.local/bin/semverator validate 1.0.0

# tests shims do not shim deps
- run: ./pkgm.ts shim node
- run: ./pkgm.ts shim node@20
- run: test ! -d ~/.local/bin/openssl
- run: if [[ $(~/.local/bin/node --version) != v20* ]]; then false; fi

- run: ./pkgm.ts i hyperfine@1.18
- run: ./pkgm.ts outdated | grep hyperfine
Expand Down
29 changes: 15 additions & 14 deletions pkgm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
semver,
utils,
} from "https://deno.land/x/libpkgx@v0.21.0/mod.ts";
import { basename, dirname, join } from "jsr:@std/path@^1";
import { dirname, join } from "jsr:@std/path@^1";
import { ensureDir, existsSync, walk } from "jsr:@std/fs@^1";
import { parseArgs } from "jsr:@std/cli@^1";
const { hydrate } = plumbing;
Expand Down Expand Up @@ -211,17 +211,16 @@ async function shim(args: string[], basePath: string) {

const json = (await query_pkgx(pkgx, args))[0];

const projects_we_care_about = [];
for (const pkg of json.pkgs) {
const cmds = await hooks.usePantry().project(pkg.pkg.project).provides();
const set = new Set(cmds.map((x) => basename(x)));
if (!args.some((x) => set.has(x))) continue;
const companions = await hooks.usePantry().project(pkg.pkg.project)
.companions();
projects_we_care_about.push(
pkg.pkg.project,
...companions.map((x) => x.project),
);
const args_pkgs: Record<string, semver.Range> = {};
const projects_we_care_about: string[] = [];
for (const arg of args) {
const pkgs = await hooks.usePantry().find(arg);
if (pkgs.length == 0) throw new Error(`no such pkg: ${arg}`);
if (pkgs.length > 1) throw new Error(`ambiguous pkg: ${arg}`);
args_pkgs[pkgs[0].project] = utils.pkg.parse(arg).constraint;
projects_we_care_about.push(pkgs[0].project);
const companions = await hooks.usePantry().project(pkgs[0]).companions();
Copy link

Copilot AI Mar 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project() call is passed pkgs[0] instead of pkgs[0].project; this may cause runtime errors if the function expects a project identifier string.

Suggested change
const companions = await hooks.usePantry().project(pkgs[0]).companions();
const companions = await hooks.usePantry().project(pkgs[0].project).companions();

Copilot uses AI. Check for mistakes.
projects_we_care_about.push(...companions.map((x) => x.project));
}

for (const pkg of json.pkgs) {
Expand All @@ -239,8 +238,10 @@ async function shim(args: string[], basePath: string) {
? "/usr/local/bin/pkgx"
: "/usr/bin/env -S pkgx";

const shim =
`#!${interpreter} --shebang --quiet +${pkg.pkg.project}=${pkg.pkg.version} -- ${name}`;
const range = args_pkgs[pkg.pkg.project];
const arg = `${pkg.pkg.project}${`${range}` == "*" ? "" : `${range}`}`;

const shim = `#!${interpreter} --shebang --quiet +${arg} -- ${name}`;

if (existsSync(join(basePath, "bin", name))) {
await Deno.remove(join(basePath, "bin", name));
Expand Down
Loading