@cjkihl/turbo-env
v1.0.10
Published
Set environment variables for a turbo build from a .env file
Downloads
82
Maintainers
Readme
turbo-env
A CLI tool and library for automatically syncing environment variables from .env files to your Turborepo configuration.
Features
- 🔄 Automatically syncs environment variables from
.envfiles toturbo.json - 📝 Supports multiple environment files with priority order
- 🛠️ Available as both a CLI tool and a library
- 🔍 Intelligently finds your project root
- ✨ Zero configuration needed for basic usage
Installation
# Using npm
npm install @cjkihl/turbo-env
# Using yarn
yarn add @cjkihl/turbo-env
# Using pnpm
pnpm add @cjkihl/turbo-envUsage
CLI
The CLI tool can be used to quickly sync your environment variables:
# Use default env files (.env.local, .env)
turbo-env
# Specify custom env files
turbo-env -e .env.production .env.staging .envProgrammatic Usage
You can also use the package programmatically in your Node.js code:
import setTurboEnv from '@cjkihl/turbo-env';
// Use default env files (.env.local, .env)
await setTurboEnv({});
// Specify custom env files
await setTurboEnv({
envFile: ['.env.production', '.env.staging', '.env']
});API Reference
setTurboEnv(config: TurboEnvConfig)
Synchronizes environment variables from .env files to your Turborepo configuration.
Parameters
config(optional): Configuration objectenvFile(optional): Array of environment file paths to check in order of priority- Default:
['.env.local', '.env']
- Default:
Returns
Promise<void>
Throws
Errorif no environment variables are found in any of the specified env filesErrorifturbo.jsonfile doesn't exist
How It Works
- The tool searches for environment files in your project root
- It reads the first existing environment file from the provided list
- Extracts all environment variable keys
- Updates the
globalEnvarray in yourturbo.jsonconfiguration - Saves the updated configuration back to
turbo.json
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
