Are you sure you want to delete this access key?
This implementation improves how build-time constants (specifically the PostHog key) are handled in the promptfoo project by using post-compilation injection instead of source file mutation.
Removed file mutation during build
generate-constants.js
would overwrite src/generated-constants.ts
during buildCreated scripts/inject-build-constants.js
dist/src/generated-constants.js
to replace environment variable references with actual valuesUpdated build process
generate-constants
script and postbuild
git checkout workaroundtsc && node scripts/inject-build-constants.js && ...
Added comprehensive tests
// src/generated-constants.ts
export const POSTHOG_KEY = process.env.PROMPTFOO_POSTHOG_KEY || '';
# 1. TypeScript compiles to JavaScript
tsc
# 2. Injection script modifies the compiled output
PROMPTFOO_POSTHOG_KEY="your-key" node scripts/inject-build-constants.js
# Result in dist/src/generated-constants.js:
exports.POSTHOG_KEY = 'your-key';
The distributed package contains the injected values, so runtime environment variables are not needed.
# Run tests
npm test -- test/generated-constants.test.ts
npm test -- test/inject-build-constants.test.ts
# Build with a key
PROMPTFOO_POSTHOG_KEY="test-key" npm run build
# Build without a key (defaults to empty string)
npm run build
Press p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?