diff --git a/CHANGELOG.md b/CHANGELOG.md index 874853f7..360bc210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/extension.ts b/src/extension.ts index efb058cb..1f1f99e9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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] ?? '']), ), ) } @@ -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) }) } diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 7c16ccbc..f2964e32 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -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) diff --git a/test/workspace/.envrc b/test/workspace/.envrc index bc3c74d5..d81472e2 100644 --- a/test/workspace/.envrc +++ b/test/workspace/.envrc @@ -1,2 +1,3 @@ # shellcheck shell=bash export VARIABLE=value +unset PREDEFINED diff --git a/test/workspace/.vscode/tasks.json b/test/workspace/.vscode/tasks.json index 4194c5d6..9863ebde 100644 --- a/test/workspace/.vscode/tasks.json +++ b/test/workspace/.vscode/tasks.json @@ -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": [] }, ]