cleanup(environment): remove unused layer inventory
This commit is contained in:
@@ -35,13 +35,6 @@ export interface EnvironmentEntry {
|
||||
path?: string
|
||||
}
|
||||
|
||||
/** One environment layer's identity, for diagnostics. */
|
||||
export interface EnvironmentLayer {
|
||||
source: EnvironmentSource
|
||||
/** Absolute path of the file behind this layer; absent for `process`. */
|
||||
path?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The frozen environment of one launch. Construct through
|
||||
* {@link createEnvironmentSnapshot}; nothing mutates it afterwards, so a
|
||||
@@ -65,8 +58,6 @@ export interface EnvironmentSnapshot {
|
||||
* @returns the first matching entry, or `undefined`.
|
||||
*/
|
||||
getFrom(name: string, sources: readonly EnvironmentSource[]): EnvironmentEntry | undefined
|
||||
/** The layers this snapshot was built from, most trusted first. */
|
||||
readonly layers: readonly EnvironmentLayer[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,12 +112,6 @@ export function createEnvironmentSnapshot(layers: readonly EnvironmentLayerInput
|
||||
return {
|
||||
get: name => getFrom(name, ENVIRONMENT_SOURCES),
|
||||
getFrom,
|
||||
layers: ENVIRONMENT_SOURCES
|
||||
.filter(source => bySource.has(source))
|
||||
.map((source): EnvironmentLayer => {
|
||||
const path = bySource.get(source)?.path
|
||||
return { source, ...path === undefined ? {} : { path } }
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,15 +28,6 @@ describe('createEnvironmentSnapshot', () => {
|
||||
expect(layered.getFrom('SHARED', [])).toBeUndefined()
|
||||
})
|
||||
|
||||
it('lists its layers in trust order with their paths', () => {
|
||||
expect(layered.layers).toEqual([
|
||||
{ source: 'process' },
|
||||
{ source: 'project-env', path: '/work/.env' },
|
||||
{ source: 'user-env', path: '/home/.dsh/.env' },
|
||||
])
|
||||
expect(createEnvironmentSnapshot([{ source: 'process', values: {} }]).layers).toEqual([{ source: 'process' }])
|
||||
})
|
||||
|
||||
it('copies each layer, so a later mutation of the source object cannot change it', () => {
|
||||
const values: Record<string, string> = { KEY: 'first' }
|
||||
const snapshot = createEnvironmentSnapshot([{ source: 'process', values }])
|
||||
@@ -76,7 +67,6 @@ describe('environmentOf', () => {
|
||||
// A host that discovered no files has exactly one layer, so the trusted
|
||||
// lookups every consumer makes still find what it was launched with.
|
||||
expect(snapshot.getFrom('DSH_ENV_SPEC_FALLBACK', ['process', 'user-env'])?.value).toBe('ambient')
|
||||
expect(snapshot.layers).toEqual([{ source: 'process' }])
|
||||
} finally {
|
||||
vi.unstubAllEnvs()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user