diff --git a/CHANGELOG.md b/CHANGELOG.md index ce5df488..ac97d5a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. ## [Unreleased] +### Fixed +- Avoid relying on direnv's internal representations ## [0.12.1] - 2023-04-24 ### Fixed diff --git a/src/direnv.ts b/src/direnv.ts index 1633e363..017aa1aa 100644 --- a/src/direnv.ts +++ b/src/direnv.ts @@ -20,7 +20,10 @@ export class CommandNotFoundError extends Error { export type Data = Map -export type Watch = Record<'Path', string> +type Watch = { + path?: string + ['Path']?: string +} export type Stdio = { stdout: string @@ -128,9 +131,10 @@ export function isInternal(key: string) { return key.startsWith('DIRENV_') } -export function watches(data?: Data): Watch[] { +export function watchedPaths(data?: Data): string[] { if (data === undefined) return [] - return decode(data.get('DIRENV_WATCHES')) ?? [] + const watches: Watch[] = decode(data.get('DIRENV_WATCHES')) ?? [] + return watches.map((it) => it.path ?? it.Path).filter((it): it is string => !!it) } function decode(gzenv?: string): T | undefined { diff --git a/src/extension.ts b/src/extension.ts index 8afbe7ec..040d34bd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -160,7 +160,7 @@ class Direnv implements vscode.Disposable { private updateWatchers(data?: Data) { this.watchers.dispose() this.watchers = vscode.Disposable.from( - ...direnv.watches(data).map((it) => this.createWatcher(it.Path)), + ...direnv.watchedPaths(data).map((it) => this.createWatcher(it)), ) } diff --git a/src/test/suite/direnv.test.ts b/src/test/suite/direnv.test.ts index c2c7a218..d33be864 100644 --- a/src/test/suite/direnv.test.ts +++ b/src/test/suite/direnv.test.ts @@ -55,7 +55,7 @@ describe('direnv', () => { it('lists the .envrc file as watched', async () => { await direnv.allow(file) const data = await direnv.dump() - const paths = direnv.watches(data).map((it) => it.Path) + const paths = direnv.watchedPaths(data) assert.ok(paths.includes(file)) })