diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..f021d69 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "target": "es6", + "module": "commonjs", + "paths": { + "@components/*": ["./src/components/*"], + "@constants/*": ["./src/constants/*"], + "@helpers/*": ["./src/helpers/*"] + } + }, + "typeAcquisition": { + "include": ["jest"] + }, + "include": ["src/**/*"] +} diff --git a/src/commands/amend.js b/src/commands/amend.js index 62c7e9b..79b7c6c 100644 --- a/src/commands/amend.js +++ b/src/commands/amend.js @@ -22,11 +22,12 @@ export default () => { const { coAuthors } = pairingConfig const trailers = coAuthoringTrailers(coAuthors) - const rawCommitMessage = stripCoAuthorship(run('git log -1 --pretty=%B')) - const command = `GITPAIR_RUNNING=1 git commit --amend -m"${rawCommitMessage}\n\n${trailers}"` + const rawCommitMessage = stripCoAuthorship(run('git', 'log', '-1', '--pretty=%B')) log(bold('Rewriting last commit with the following info:')) log(trailers) - run(command) + run('git', ['commit', '--amend', `${rawCommitMessage}\n\n${trailers}`], { + GITPAIR_RUNNING: 1, + }) log(bold('👥 Last commit was rewritten! 😎')) } diff --git a/src/utils/__tests__/run.test.js b/src/utils/__tests__/run.test.js new file mode 100644 index 0000000..8bda6ef --- /dev/null +++ b/src/utils/__tests__/run.test.js @@ -0,0 +1,16 @@ +import run from '../run' + +it('run a command and returns its output', () => { + expect(run('echo', ['toto'])).toEqual('toto') +}) + +it('properly escapes arguments', () => { + const commitMessage = `feat(seoblock): add "search for more" tip in default select options` + expect(run('printf', ['[%s]', commitMessage])).toEqual( + '[feat(seoblock): add "search for more" tip in default select options]' + ) +}) + +it('passes optional ENV variables to the process', () => { + expect(run('sh', ['-c', 'echo $VAR'], { VAR: 'toto' })).toEqual('toto') +}) diff --git a/src/utils/run.js b/src/utils/run.js index 2fa980b..25eeaa2 100644 --- a/src/utils/run.js +++ b/src/utils/run.js @@ -1,3 +1,6 @@ -import { execSync } from 'child_process' +import { spawnSync } from 'child_process' -export default (command) => execSync(command).toString().trim() +export default (command, args, env) => + spawnSync(command, args, { env: { ...process.env, ...env } }) + .stdout.toString() + .trim()