Skip to content

Commit fa87b1b

Browse files
committed
Install dev aware stubs
1 parent 4ece506 commit fa87b1b

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ jobs:
9090
env:
9191
XDG_DATA_HOME: /tmp/foo
9292
93+
- run: |
94+
sudo ./pkgm.ts i node@22 dev
95+
[[ $(node --version) = v22* ]] || exit 2
96+
mkdir foo
97+
cd foo
98+
echo "dependencies: node@20" > pkgx.yaml
99+
mkdir -p /tmp/foo/pkgx/dev$PWD/
100+
touch /tmp/foo/pkgx/dev$PWD/dev.pkgx.activated # `dev .` doesn’t work in CI (fix in dev^2)
101+
[[ $(node --version) = v20* ]] || exit 3
102+
env:
103+
XDG_DATA_HOME: /tmp/foo
104+
93105
# https://github.com/pkgxdev/pkgm/issues/62
94106
- run: |
95107
./pkgm.ts i spotify_player

pkgm.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,13 @@ async function install(args: string[], basePath: string) {
178178
for (const [key, value] of Object.entries(env)) {
179179
sh += `export ${key}="${value}"\n`;
180180
}
181-
sh += `exec "${bin_prefix}/${entry.name}" "$@"\n`;
181+
182+
sh += "\n";
183+
//TODO should be specific with the project
184+
sh += dev_stub_text(to_stub, bin_prefix, entry.name);
182185

183186
await Deno.remove(to_stub); //FIXME inefficient to symlink for no reason
184-
await Deno.writeTextFile(to_stub, sh);
187+
await Deno.writeTextFile(to_stub, sh.trim() + "\n");
185188
await Deno.chmod(to_stub, 0o755);
186189

187190
rv.push(to_stub);
@@ -726,3 +729,53 @@ function install_prefix() {
726729
return Path.home().join(".local");
727730
}
728731
}
732+
733+
function dev_stub_text(selfpath: string, bin_prefix: string, name: string) {
734+
const datadir = "$HOME/Library/Application Support";
735+
return `
736+
dev_check() {
737+
[ -x /usr/local/bin/dev ] || return 1
738+
local d="$PWD"
739+
until [ "$d" = / ]; do
740+
if [ -f "${datadir}/pkgx/dev/$d/dev.pkgx.activated" ]; then
741+
echo $d
742+
return 0
743+
fi
744+
d="$(dirname "$d")"
745+
done
746+
return 1
747+
}
748+
749+
if d="$(dev_check)"; then
750+
eval "$(/usr/local/bin/dev "$d" 2>/dev/null)"
751+
[ "$(command -v ${name} 2>/dev/null)" != "${selfpath}" ] && exec ${name} "$@"
752+
fi
753+
754+
exec ${bin_prefix}/${name} "$@"
755+
`.trim();
756+
}
757+
758+
759+
function datadir() {
760+
const default_data_home = Deno.build.os == 'darwin' ? "/Library/Application Support" : "/.local/share";
761+
return `\${XDG_DATA_HOME:-$HOME${default_data_home}`;
762+
}
763+
764+
function platform_data_home_default() {
765+
const home = Path.home();
766+
switch (Deno.build.os) {
767+
case "darwin":
768+
return home.join("Library/Application Support");
769+
case "windows": {
770+
const LOCALAPPDATA = Deno.env.get("LOCALAPPDATA");
771+
if (LOCALAPPDATA) {
772+
return new Path(LOCALAPPDATA);
773+
} else {
774+
return home.join("AppData/Local");
775+
}
776+
}
777+
default:
778+
return home.join(".local/share");
779+
}
780+
}
781+

0 commit comments

Comments
 (0)