Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide support for .env files injects via API #1034

Merged
merged 5 commits into from
Dec 27, 2024

Conversation

easymikey
Copy link
Contributor

Fixes #975

/// './path/prod.env'
FOO=BAR

---
/// index.js
$.env = './path/prod.env'
await $`echo $FOO`.stdout // BAR
  • Tests pass
  • Appropriate changes to README are included in PR

@easymikey
Copy link
Contributor Author

Screenshot 2024-12-25 at 18 05 07

@easymikey easymikey changed the title Feat add envpath to core feat: provide support for .env files injects via API Dec 25, 2024
@antongolub
Copy link
Collaborator

What's about this way instead?

const loadDotenv = (...files: string[]) => files.reverse().reduce<env>((m, f) => Object.assign(m, parseDotenv(fs.readFileSync(f))), {})

$.env = loadDotenv('.env', '.env.default')

test/core.test.js Outdated Show resolved Hide resolved
@easymikey
Copy link
Contributor Author

What's about this way instead?

const loadDotenv = (...files: string[]) => files.reverse().reduce<env>((m, f) => Object.assign(m, parseDotenv(fs.readFileSync(f))), {})

$.env = loadDotenv('.env', '.env.default')

Maybe replace it with spread?

const loadDotenv = (...files: string[]) =>
  files
    .reverse()
    .reduce<env>((m, f) => ({ ...m, ...parseDotenv(fs.readFileSync(f)) }), {});

And why the reverse?

$.env = loadDotenv('.env.default', '.env')

Are you suggesting we consider an array of strings as well?

type Env = NodeJs.Process | string | string[]

@antongolub
Copy link
Collaborator

I suggest keeping the $.env contract as is, and just export loadDotenv helper

@easymikey easymikey force-pushed the feat-add-envpath-to-core branch from 6fae7d2 to 28a2661 Compare December 26, 2024 13:41
@easymikey easymikey force-pushed the feat-add-envpath-to-core branch from 28a2661 to bb09653 Compare December 26, 2024 14:36
@easymikey easymikey requested a review from antongolub December 26, 2024 18:19
Copy link
Collaborator

@antongolub antongolub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Thanks.

@antongolub antongolub merged commit efc4800 into google:main Dec 27, 2024
19 checks passed
antongolub added a commit to antongolub/zx that referenced this pull request Dec 28, 2024
@antongolub antongolub mentioned this pull request Dec 28, 2024
2 tasks
antongolub added a commit that referenced this pull request Dec 28, 2024
* refactor: assemble dotenv utils

continues #1034

* chore: prettier
@easymikey easymikey deleted the feat-add-envpath-to-core branch December 30, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: provide support for .env files injects via API
2 participants