-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
What's your idea?
Add a small helper env() to simplify running commands with temporary environment variables.
Currently this requires repeating ...process.env:
await $({
env: { ...process.env, FOO: "hello" }
})`echo $FOO`Proposed usage:
await env({ FOO: "hello" })`echo $FOO`The helper would internally wrap $ options.
Why is that needed? How it may be useful?
✨ Improves ergonomics for a common scripting pattern
🐚 Closer to shell syntax (FOO=bar command)
📖 Reduces boilerplate in scripts
This seems consistent with existing helpers like cd(), sleep(), echo(), etc.
Maybe you have a demo or example?
Current:
await $({
env: { ...process.env, NODE_ENV: "production" }
})`node build.js`
Proposed:
await env({ NODE_ENV: "production" })`node build.js`
Possible minimal implementation:
export function env(vars: Record<string, string>) {
return $({
env: {
...process.env,
...vars,
},
})
}Reactions are currently unavailable