Skip to content

Commit e51a919

Browse files
scratchyoneclaude
andcommitted
fix(web): psql -f and deno --env-file no longer hide later scripts
`psql -f schema.sql -c 'select 1'` stopped reading at -f, although psql runs both. `deno eval --env-file '…'` took the script as the env file, although a bare --env-file takes no value. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent f532f8f commit e51a919

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎apps/web/src/lib/embeddedScripts.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ describe("embeddedScripts", () => {
5858
[`bun -e 'console.log(Bun.version)'`, "typescript", "console.log(Bun.version)"],
5959
[`deno eval 'console.log(1)'`, "typescript", "console.log(1)"],
6060
[`deno eval --config deno.json 'console.log(1)'`, "typescript", "console.log(1)"],
61+
[`deno eval --env-file 'console.log(1)'`, "typescript", "console.log(1)"],
62+
[`psql -f schema.sql -c 'select 1'`, "sql", "select 1"],
6163
[`node -C development -e 'console.log(1)'`, "javascript", "console.log(1)"],
6264
[`ruby -e 'puts 1'`, "ruby", "puts 1"],
6365
[`ruby -I lib -e 'puts 1'`, "ruby", "puts 1"],

‎apps/web/src/lib/embeddedScripts.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ const INTERPRETERS: Record<string, Interpreter> = {
107107
deno: {
108108
language: "typescript",
109109
inline: () => false,
110-
valueOptions: new Set(["-c", "--config", "--import-map", "--ext", "--env-file"]),
110+
// `--env-file` takes its optional path only as `--env-file=path`.
111+
valueOptions: new Set(["-c", "--config", "--import-map", "--ext"]),
111112
stdin: "never",
112113
subcommand: "eval",
113114
},
@@ -359,6 +360,7 @@ function interpreterArgs(
359360
const scripts: ScriptArgument[] = [];
360361
const whole = (word: Word): ScriptArgument => ({ word, inValue: false });
361362
let optionsEnded = false;
363+
let scriptFromFile = false;
362364
for (let index = 0; index < args.length; index += 1) {
363365
const arg = args[index]!;
364366
const flag = interpreter.ignoreCase ? arg.value.toLowerCase() : arg.value;
@@ -369,7 +371,13 @@ function interpreterArgs(
369371
if (!optionsEnded && flag.startsWith("-") && flag !== "-") {
370372
// `--eval=code` and `--file=path` carry their value in the same word.
371373
const [name = flag, value] = flag.startsWith("--") ? flag.split(/=(.*)/su) : [flag];
372-
if (interpreter.scriptFileOptions?.has(name)) return { scripts, scriptFromFile: true };
374+
if (interpreter.scriptFileOptions?.has(name)) {
375+
if (!interpreter.repeatable) return { scripts, scriptFromFile: true };
376+
// SQL shells run `-f` files and `-c` statements alike, in order.
377+
scriptFromFile = true;
378+
if (value === undefined) index += 1;
379+
continue;
380+
}
373381
if (interpreter.inline(name)) {
374382
const next = args[index + 1];
375383
if (value !== undefined) scripts.push({ word: arg, inValue: true });
@@ -394,7 +402,7 @@ function interpreterArgs(
394402
scripts.push(...positionals.slice(interpreter.positionalScript).map(whole));
395403
}
396404
// SQL shells take databases as positional arguments, not script files.
397-
if (interpreter.stdin === "always") return { scripts, scriptFromFile: false };
405+
if (interpreter.stdin === "always") return { scripts, scriptFromFile };
398406
const first = positionals[0];
399407
return { scripts, scriptFromFile: first !== undefined && first.value !== "-" };
400408
}

0 commit comments

Comments
 (0)