Skip to content

Commit be3650f

Browse files
committed
Handle no devenv situations gracefully
1 parent 7bab45e commit be3650f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

app.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,26 @@ switch (Deno.args[0]) {
2424

2525
const snuff = await sniff(Path.cwd());
2626

27+
if (snuff.pkgs.length === 0 && Object.keys(snuff.env).length === 0) {
28+
console.error("no devenv detected");
29+
Deno.exit(1);
30+
}
31+
32+
let env = '';
2733
const pkgspecs = snuff.pkgs.map((pkg) => `+${utils.pkg.str(pkg)}`);
2834

29-
const cmd = new Deno.Command("pkgx", {
30-
args: [...pkgspecs],
31-
stdout: "piped",
32-
env: { CLICOLOR_FORCE: "1" }, // unfortunate
33-
}).spawn();
35+
if (snuff.pkgs.length > 0) {
36+
const cmd = new Deno.Command("pkgx", {
37+
args: [...pkgspecs],
38+
stdout: "piped",
39+
env: { CLICOLOR_FORCE: "1" }, // unfortunate
40+
}).spawn();
3441

35-
await cmd.status;
42+
await cmd.status;
3643

37-
const stdout = (await cmd.output()).stdout;
38-
let env = new TextDecoder().decode(stdout);
44+
const stdout = (await cmd.output()).stdout;
45+
env = new TextDecoder().decode(stdout);
46+
}
3947

4048
// add any additional env that we sniffed
4149
for (const [key, value] of Object.entries(snuff.env)) {
@@ -46,8 +54,11 @@ env = env.trim();
4654

4755
let undo = "";
4856
for (const envln of env.trim().split("\n")) {
57+
if (!envln) continue;
58+
4959
const [key] = envln.split("=", 2);
5060
const value = Deno.env.get(key);
61+
5162
if (value) {
5263
undo += ` export ${key}=${shell_escape(value)}\n`;
5364
} else {

0 commit comments

Comments
 (0)