From c2db0cd3700d29aef682b3be482dcb82d262b0b6 Mon Sep 17 00:00:00 2001 From: Ben Callaghan <44448874+bcallaghan-et@users.noreply.github.com> Date: Thu, 21 Apr 2022 08:42:11 -0600 Subject: [PATCH] fix(dotnet): expand env vars in cli parameters (#422) Co-authored-by: Ben Callaghan --- packages/dotnet/src/lib/core/dotnet.client.spec.ts | 11 +++++++++++ packages/dotnet/src/lib/core/dotnet.client.ts | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/packages/dotnet/src/lib/core/dotnet.client.spec.ts b/packages/dotnet/src/lib/core/dotnet.client.spec.ts index aa92ed78..355c64df 100644 --- a/packages/dotnet/src/lib/core/dotnet.client.spec.ts +++ b/packages/dotnet/src/lib/core/dotnet.client.spec.ts @@ -65,6 +65,17 @@ describe('dotnet client', () => { `); expect(spawnSyncSpy).toHaveBeenCalledTimes(1); }); + + it('should expand environment variables', () => { + process.env.FOO = 'bar'; + dotnetClient.publish( + 'my-project', + undefined, + undefined, + '-p:Name=$FOO', + ); + expect(spawnSyncSpy.mock.calls[0][1]).toContain('-p:Name=bar'); + }); }); }); }); diff --git a/packages/dotnet/src/lib/core/dotnet.client.ts b/packages/dotnet/src/lib/core/dotnet.client.ts index ec4c7989..7ea1f0f2 100644 --- a/packages/dotnet/src/lib/core/dotnet.client.ts +++ b/packages/dotnet/src/lib/core/dotnet.client.ts @@ -166,8 +166,13 @@ export class DotNetClient { } private logAndExecute(params: string[]): void { + params = params.map((param) => + param.replace(/\$(\w+)/, (match, varName) => process.env[varName] ?? ''), + ); + const cmd = `${this.cliCommand.command} "${params.join('" "')}"`; console.log(`Executing Command: ${cmd}`); + const res = spawnSync(this.cliCommand.command, params, { cwd: this.cwd || process.cwd(), stdio: 'inherit',