Skip to content

fix: load CWD .env explicitly with correct precedence#28

Merged
c99e merged 4 commits intomainfrom
fix/env-loading-precedence
Mar 28, 2026
Merged

fix: load CWD .env explicitly with correct precedence#28
c99e merged 4 commits intomainfrom
fix/env-loading-precedence

Conversation

@c99e
Copy link
Copy Markdown
Owner

@c99e c99e commented Mar 28, 2026

Follow-up to #26. Fixes test failures caused by the initial XDG config implementation.

Changes

  • Split into loadEnvFile helper + loadConfigEnv orchestrator
  • Load CWD .env explicitly (needed since --target=node build doesn't get Bun's auto-load)
  • Never override existing env vars — fixes tests that set explicit env vars via Bun.spawn
  • Use node: protocol for imports (fixes lint)

Precedence (highest → lowest)

  1. Real environment variables
  2. CWD .env
  3. ~/.config/shopq/.env

c99e added 4 commits March 28, 2026 14:40
- Split into loadEnvFile helper + loadConfigEnv orchestrator
- Precedence: real env > CWD .env > ~/.config/shopq/.env
- Never override existing env vars (fixes test failures)
- Use node: protocol for imports (fixes lint)
Tests set SHOPIFY_STORE='' to simulate missing credentials.
Using 'in' check instead of falsy check preserves that intent.
The root cause was building with --target=node and #!/usr/bin/env node,
which meant Bun's native .env loading never kicked in at runtime.

Fix: target bun directly. Bun auto-loads CWD .env — no custom code needed.
For global use without a local .env, users export vars in their shell profile.
@c99e c99e merged commit 2bfc955 into main Mar 28, 2026
4 checks passed
@c99e c99e deleted the fix/env-loading-precedence branch March 28, 2026 11:00
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.

1 participant