Skip to content

Commit

Permalink
Handle no devenv situations gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 7, 2025
1 parent 7bab45e commit be3650f
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ switch (Deno.args[0]) {

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

if (snuff.pkgs.length === 0 && Object.keys(snuff.env).length === 0) {
console.error("no devenv detected");
Deno.exit(1);
}

let env = '';
const pkgspecs = snuff.pkgs.map((pkg) => `+${utils.pkg.str(pkg)}`);

const cmd = new Deno.Command("pkgx", {
args: [...pkgspecs],
stdout: "piped",
env: { CLICOLOR_FORCE: "1" }, // unfortunate
}).spawn();
if (snuff.pkgs.length > 0) {
const cmd = new Deno.Command("pkgx", {
args: [...pkgspecs],
stdout: "piped",
env: { CLICOLOR_FORCE: "1" }, // unfortunate
}).spawn();

await cmd.status;
await cmd.status;

const stdout = (await cmd.output()).stdout;
let env = new TextDecoder().decode(stdout);
const stdout = (await cmd.output()).stdout;
env = new TextDecoder().decode(stdout);
}

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

let undo = "";
for (const envln of env.trim().split("\n")) {
if (!envln) continue;

const [key] = envln.split("=", 2);
const value = Deno.env.get(key);

if (value) {
undo += ` export ${key}=${shell_escape(value)}\n`;
} else {
Expand Down

0 comments on commit be3650f

Please sign in to comment.