From 126a7121064a17a0508c24c1d6ed63f4ad121bb7 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Mon, 26 Nov 2018 00:54:56 +0100 Subject: [PATCH 1/2] refactor(cli): rename old husky git params to husky prefix --- @commitlint/cli/src/cli.js | 14 +++++++------- @commitlint/cli/src/cli.test.js | 14 ++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index a82724f2b3..4ca0739eef 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -224,20 +224,20 @@ function getEditValue(flags) { if (typeof edit === 'boolean') { return edit; } - // The recommended method to specify -e with husky was `commitlint -e $GIT_PARAMS` + // The recommended method to specify -e with husky was `commitlint -e $HUSKY_GIT_PARAMS` // This does not work properly with win32 systems, where env variable declarations // use a different syntax // See https://github.com/marionebl/commitlint/issues/103 for details - // This has been superceded by the `-E GIT_PARAMS` / `-E HUSKY_GIT_PARAMS` - if (edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%') { + // This has been superceded by the `-E HUSKY_GIT_PARAMS` / `-E HUSKY_GIT_PARAMS` + if (edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%') { console.warn(`Using environment variable syntax (${edit}) in -e |\ ---edit is deprecated. Use '{-E|--env} GIT_PARAMS instead'`); - if (!('GIT_PARAMS' in process.env)) { +--edit is deprecated. Use '{-E|--env} HUSKY_GIT_PARAMS instead'`); + if (!('HUSKY_GIT_PARAMS' in process.env)) { throw new Error( - `Received ${edit} as value for -e | --edit, but GIT_PARAMS is not available globally.` + `Received ${edit} as value for -e | --edit, but HUSKY_GIT_PARAMS is not available globally.` ); } - return process.env.GIT_PARAMS; + return process.env.HUSKY_GIT_PARAMS; } return edit; } diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.js index 4a5bd64ec2..34f1ebd72a 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -109,18 +109,24 @@ test('should work with husky commitmsg hook in sub packages', async () => { await execa('git', ['commit', '-m', '"test: this should work"'], {cwd}); }); -test('should work with husky via commitlint -e $GIT_PARAMS', async () => { +test('should work with husky via commitlint -e $HUSKY_GIT_PARAMS', async () => { const cwd = await git.bootstrap('fixtures/husky/integration'); - await writePkg({scripts: {commitmsg: `'${bin}' -e $GIT_PARAMS`}}, {cwd}); + await writePkg( + {scripts: {commitmsg: `'${bin}' -e $HUSKY_GIT_PARAMS`}}, + {cwd} + ); await execa('npm', ['install'], {cwd}); await execa('git', ['add', 'package.json'], {cwd}); await execa('git', ['commit', '-m', '"test: this should work"'], {cwd}); }); -test('should work with husky via commitlint -e %GIT_PARAMS%', async () => { +test('should work with husky via commitlint -e %HUSKY_GIT_PARAMS%', async () => { const cwd = await git.bootstrap('fixtures/husky/integration'); - await writePkg({scripts: {commitmsg: `'${bin}' -e %GIT_PARAMS%`}}, {cwd}); + await writePkg( + {scripts: {commitmsg: `'${bin}' -e %HUSKY_GIT_PARAMS%`}}, + {cwd} + ); await execa('npm', ['install'], {cwd}); await execa('git', ['add', 'package.json'], {cwd}); From d231b4a7e608c5e35b72169083aeda27c1bd687f Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 27 Nov 2018 23:01:37 +0100 Subject: [PATCH 2/2] fix(cli): add old git params as alias to husky params --- @commitlint/cli/src/cli.js | 22 +++++++++++++++------- @commitlint/cli/src/cli.test.js | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index 4ca0739eef..a0b31a47b5 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -228,16 +228,24 @@ function getEditValue(flags) { // This does not work properly with win32 systems, where env variable declarations // use a different syntax // See https://github.com/marionebl/commitlint/issues/103 for details - // This has been superceded by the `-E HUSKY_GIT_PARAMS` / `-E HUSKY_GIT_PARAMS` - if (edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%') { + // This has been superceded by the `-E GIT_PARAMS` / `-E HUSKY_GIT_PARAMS` + const isGitParams = edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%'; + const isHuskyParams = + edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%'; + + if (isGitParams || isHuskyParams) { console.warn(`Using environment variable syntax (${edit}) in -e |\ --edit is deprecated. Use '{-E|--env} HUSKY_GIT_PARAMS instead'`); - if (!('HUSKY_GIT_PARAMS' in process.env)) { - throw new Error( - `Received ${edit} as value for -e | --edit, but HUSKY_GIT_PARAMS is not available globally.` - ); + + if (isGitParams && 'GIT_PARAMS' in process.env) { + return process.env.GIT_PARAMS; + } + if ('HUSKY_GIT_PARAMS' in process.env) { + return process.env.HUSKY_GIT_PARAMS; } - return process.env.HUSKY_GIT_PARAMS; + throw new Error( + `Received ${edit} as value for -e | --edit, but GIT_PARAMS or HUSKY_GIT_PARAMS are not available globally.` + ); } return edit; } diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.js index 34f1ebd72a..2462ca56c0 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -109,6 +109,24 @@ test('should work with husky commitmsg hook in sub packages', async () => { await execa('git', ['commit', '-m', '"test: this should work"'], {cwd}); }); +test('should work with husky via commitlint -e $GIT_PARAMS', async () => { + const cwd = await git.bootstrap('fixtures/husky/integration'); + await writePkg({scripts: {commitmsg: `'${bin}' -e $GIT_PARAMS`}}, {cwd}); + + await execa('npm', ['install'], {cwd}); + await execa('git', ['add', 'package.json'], {cwd}); + await execa('git', ['commit', '-m', '"test: this should work"'], {cwd}); +}); + +test('should work with husky via commitlint -e %GIT_PARAMS%', async () => { + const cwd = await git.bootstrap('fixtures/husky/integration'); + await writePkg({scripts: {commitmsg: `'${bin}' -e %GIT_PARAMS%`}}, {cwd}); + + await execa('npm', ['install'], {cwd}); + await execa('git', ['add', 'package.json'], {cwd}); + await execa('git', ['commit', '-m', '"test: this should work"'], {cwd}); +}); + test('should work with husky via commitlint -e $HUSKY_GIT_PARAMS', async () => { const cwd = await git.bootstrap('fixtures/husky/integration'); await writePkg(