Skip to content

Commit 0604830

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

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

pkgm.ts

Lines changed: 27 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,25 @@ 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+
[ -f "${datadir}/pkgx/dev/$d/dev.pkgx.activated" ] && return 0
741+
d="$(dirname "$d")"
742+
done
743+
return 1
744+
}
745+
746+
if dev_check; then
747+
eval "$(/usr/local/bin/dev --quiet)"
748+
[ "$(command -v ${name} 2>/dev/null)" != "${selfpath}" ] && exec ${name} "$@"
749+
fi
750+
751+
exec ${bin_prefix}/${name} "$@"
752+
`.trim();
753+
}

0 commit comments

Comments
 (0)