Skip to content

Commit b946565

Browse files
committed
Add and use clone method for ReadOnlyEnv
1 parent 205b37b commit b946565

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎lib/entry-points.js‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/environment.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ export function getOptionalEnvVar(paramName: string): string | undefined {
265265
export class ReadOnlyEnv<T extends string | undefined = string | undefined> {
266266
constructor(protected readonly vars: Record<string, T>) {}
267267

268+
/** Clones the object while detaching the underlying environment from the original. */
269+
public clone(): this {
270+
return Object.create(this, { vars: { value: { ...this.vars } } }) as this;
271+
}
272+
268273
/** Tries to get the value for `name` and throws if there isn't one. */
269274
public getRequired(name: string): string {
270275
return getRequiredEnvVar(this.vars, name);

‎src/testing-utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ abstract class BaseEnvBuilder<
240240
cloneFrom !== undefined
241241
? ({
242242
...cloneFrom.state,
243-
env: Object.create(cloneFrom.state.env),
243+
env: cloneFrom.state.env.clone(),
244244
actions: Object.create(cloneFrom.state.actions),
245245
logger: this.logger,
246246
} satisfies ActionState<AllState>)

0 commit comments

Comments
 (0)