Skip to content

Commit

Permalink
refactor: pass env to exec
Browse files Browse the repository at this point in the history
  • Loading branch information
ZauberNerd committed Feb 2, 2022
1 parent d3dfcd1 commit 0a5d2d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/__tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('command execution', () => {
const result = execute(
'true',
'/dev/null',
process.env,
(debug as unknown) as Debugger
);

Expand Down
8 changes: 5 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ExecSyncError = SpawnSyncReturns<Buffer> & ExecException;
export function execute(
command: string,
cwd: string,
env: NodeJS.ProcessEnv = process.env,
debug?: Debugger
): boolean {
debug && debug('running command: "%s" in "%s"', command, cwd);
Expand All @@ -17,6 +18,7 @@ export function execute(
execSync(command, {
stdio: debug ? 'inherit' : 'pipe',
cwd,
env,
});

debug && debug('done');
Expand Down Expand Up @@ -58,7 +60,7 @@ export function cloneRepositories(
branch ? '#' + branch : ''
}" into "${target}"`
);
if (!execute(command, cwd, debug)) {
if (!execute(command, cwd, process.env, debug)) {
throw new Error('Failed to clone repositories');
}
});
Expand All @@ -68,7 +70,7 @@ export function yarn(config: Config, debug?: Debugger): void {
const command = `yarn ${config.yarnArguments}`.trim();

console.log('[canarist] installing dependencies with yarn');
if (!execute(command, config.targetDirectory, debug)) {
if (!execute(command, config.targetDirectory, process.env, debug)) {
throw new Error('Failed to install dependencies');
}
}
Expand All @@ -84,7 +86,7 @@ export function executeCommands(config: Config, debug?: Debugger): void {
const cwd = join(config.targetDirectory, repo.directory);

console.log('[canarist] executing command "%s" in "%s"', command, cwd);
if (!execute(command, cwd, debug)) {
if (!execute(command, cwd, process.env, debug)) {
throw new Error('Failed to run configured commands');
}
});
Expand Down

0 comments on commit 0a5d2d9

Please sign in to comment.