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

use empty string to "unset" variables #263

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
## [Unreleased]
### Changed
- Require VSCode 1.66
- "Unset" variables by setting them to the empty string
### Fixed
- Avoid continuously asking to restart
If this keeps happening to you, please let us know!

## [0.6.1] - 2022-03-25
### Fixed
Expand Down
12 changes: 4 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Direnv implements vscode.Disposable {
await this.cache.update(
Cached.environment,
Object.fromEntries(
[...this.backup.entries()].map(([key]) => [key, process.env[key]]),
[...this.backup.entries()].map(([key]) => [key, process.env[key] ?? '']),
),
)
}
Expand All @@ -124,13 +124,9 @@ class Direnv implements vscode.Disposable {
this.backup.set(key, process.env[key])
}

if (value !== null) {
process.env[key] = value
this.environment.replace(key, value)
} else {
delete process.env[key]
this.environment.delete(key) // can't unset the variable
}
value ??= '' // can't unset, set to empty instead
process.env[key] = value
this.environment.replace(key, value)
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ async function main() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, '../../')
const extensionTestsPath = path.resolve(__dirname, './suite/index')
const extensionTestsEnv = { ['PREDEFINED']: 'value' }
const workspacePath = path.resolve(__dirname, '../../test/workspace')
const disableExtensions = '--disable-extensions'
const launchArgs = [workspacePath, disableExtensions]
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs })
await runTests({ extensionDevelopmentPath, extensionTestsPath, extensionTestsEnv, launchArgs })
} catch (err) {
console.error('Failed to run tests')
process.exit(1)
Expand Down
1 change: 1 addition & 0 deletions test/workspace/.envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# shellcheck shell=bash
export VARIABLE=value
unset PREDEFINED
4 changes: 2 additions & 2 deletions test/workspace/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"label": "test-task",
"detail": "test that the .envrc environment is available in the task shell",
"type": "shell",
"command": "test -n \"$VARIABLE\"",
"command": "test -n \"$VARIABLE\" && test -z \"$PREDEFINED\"",
"problemMatcher": []
},
{
"label": "test-process",
"detail": "test that the .envrc environment is available in process.env",
"type": "shell",
"command": "test -n \"${env:VARIABLE}\"",
"command": "test -n \"${env:VARIABLE}\" && test -z \"${env:PREDEFINED}\"",
"problemMatcher": []
},
]
Expand Down