diff --git a/lib/entry-points.js b/lib/entry-points.js index 0cf4dc2bc..2fcf8c198 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -141488,6 +141488,10 @@ var ReadOnlyEnv = class { this.vars = vars; } vars; + /** Clones the object while detaching the underlying environment from the original. */ + clone() { + return Object.create(this, { vars: { value: { ...this.vars } } }); + } /** Tries to get the value for `name` and throws if there isn't one. */ getRequired(name) { return getRequiredEnvVar(this.vars, name); diff --git a/src/environment.ts b/src/environment.ts index 9d52a903f..1b00ab7cf 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -265,6 +265,11 @@ export function getOptionalEnvVar(paramName: string): string | undefined { export class ReadOnlyEnv { constructor(protected readonly vars: Record) {} + /** Clones the object while detaching the underlying environment from the original. */ + public clone(): this { + return Object.create(this, { vars: { value: { ...this.vars } } }) as this; + } + /** Tries to get the value for `name` and throws if there isn't one. */ public getRequired(name: string): string { return getRequiredEnvVar(this.vars, name); diff --git a/src/testing-utils.ts b/src/testing-utils.ts index f630082be..92fad068e 100644 --- a/src/testing-utils.ts +++ b/src/testing-utils.ts @@ -240,7 +240,7 @@ abstract class BaseEnvBuilder< cloneFrom !== undefined ? ({ ...cloneFrom.state, - env: Object.create(cloneFrom.state.env), + env: cloneFrom.state.env.clone(), actions: Object.create(cloneFrom.state.actions), logger: this.logger, } satisfies ActionState)