Skip to content

Commit

Permalink
fix(dotnet): expand env vars in cli parameters (#422)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
  • Loading branch information
bcallaghan-et and Ben Callaghan committed Apr 21, 2022
1 parent 40ab979 commit c2db0cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/dotnet/src/lib/core/dotnet.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});
5 changes: 5 additions & 0 deletions packages/dotnet/src/lib/core/dotnet.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c2db0cd

Please sign in to comment.