-
Notifications
You must be signed in to change notification settings - Fork 1
Add ability to load development-only environment variables #22
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
Conversation
- Added `addDevEnvVariables` util function to allow the extension to load the local `.env` file from the project root if it exists, using Node's `loadEnvFile` API, and load the environment variables into `process.env`. The `.env` file will only exist on the development machine and is crucial to properly test the extension in vscode's extension testing environment. This fixes the ability to mistakenly commit the dev testing path to git. As seen in commit be9d972 and removed in commit 9ff0857 of PR #20. With the .env file, this will never happen again. - Added the `addDevEnvVariables` function call to the top of the `extension.ts` file so it is the first thing it does and the env variables will be available in all files in development. - Added the usage of the `DEV_USER_EXTENSIONS_PATH` env variable to `ExtensionData::setExtensionDiscoveryPaths` method. So that when its available to use, it will override the `userExtensionsPath` variable with the path set in the env variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds developer-focused configuration hooks by loading local .env variables and allowing an environment-variable override for the user extensions discovery path.
Changes:
- Introduces
addDevEnvVariables()to load a local.envfile at startup. - Allows overriding the computed
userExtensionsPathviaDEV_USER_EXTENSIONS_PATH. - Ignores
.envin git to avoid committing local secrets.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/utils.ts |
Adds .env loading helper using process.loadEnvFile. |
src/extension.ts |
Invokes .env loading during extension module initialization. |
src/extensionData.ts |
Uses DEV_USER_EXTENSIONS_PATH to override extension discovery path. |
.gitignore |
Adds .env to ignored files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@yCodeTech I've opened a new pull request, #23, to work on those changes. Once the pull request is ready, I'll request review from you. |
A duplicate output channel is sometimes created when logging. Possibly because it is setup after `ExtensionData`, and any logs from that class or earlier in the run, will create additional channels, without realising there's one already created. - Fixed by moving `logger.setupOutputChannel` call up the run order to before the `addDevEnvVariables` call in the extension file. This should help prevent duplicate channels, and log to only one channel.
- Added `validateDevEnvVariables` util function to validate and sanitize the `DEV_USER_EXTENSIONS_PATH` env variable value. Added it's function call to `addDevEnvVariables` util function. This function is based on the code Copilot created in PR #23, but with significant improvement.
- Added `validateDevEnvVariables` util function to validate and sanitize the `DEV_USER_EXTENSIONS_PATH` env variable value. Added it's function call to `addDevEnvVariables` util function. This function is based on the code Copilot created in PR #23, but with significant improvement.
- Fixed `errorMsg` variable in `validateDevEnvVariables` util function to be initialised as an empty string. This avoids errors when trying to call `.length` on it later.
This pull request introduces support for loading and validating development environment variables from a
.envfile, allowing for easier local development and testing. The most important changes are grouped below by theme:Development environment support:
addDevEnvVariablesfunction insrc/utils.tsthat loads environment variables from a local.envfile and validates them, specifically focusing onDEV_USER_EXTENSIONS_PATH.src/extension.tsto calladdDevEnvVariablesduring extension startup, ensuring development environment variables are loaded before initializing extension data.Environment variable validation:
src/utils.tsto sanitizeDEV_USER_EXTENSIONS_PATH, removing it from the environment and logging errors if the path is invalid or inaccessible.Extension discovery paths:
ExtensionData.setExtensionDiscoveryPathsinsrc/extensionData.tsto use theDEV_USER_EXTENSIONS_PATHenvironment variable if present, allowing custom user extension paths during development.Dependency updates:
pathmodule import insrc/utils.tsto support path resolution and validation for environment variables.~ Summary generated by Copilot