revert: fix: revert to execa ^1.0.0

This reverts commit 6b3adf6bbe72d5c32335118e91ca32ec043bbc9e.
This commit is contained in:
Pierre Vanduynslager 2019-09-13 16:33:09 -04:00
parent f1d983ddb0
commit fa62d0ba0b
No known key found for this signature in database
GPG Key ID: E7684268B8C7E0A3
5 changed files with 57 additions and 57 deletions

View File

@ -64,7 +64,7 @@ async function getCommits(from, to, execaOpts) {
* @throws {Error} If the `git` command fails.
*/
async function getBranches(repositoryUrl, execaOpts) {
return (await execa.stdout('git', ['ls-remote', '--heads', repositoryUrl], execaOpts))
return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)).stdout
.split('\n')
.map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1])
.filter(Boolean);
@ -93,7 +93,7 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) {
await execa('git', ['merge-base', '--is-ancestor', ref, branch], execaOpts);
return true;
} catch (error) {
if (error.code === 1) {
if (error.exitCode === 1) {
if (findRebasedTags) {
const [tagCommit] = await getStream.array(
gitLogParser.parse({_: ref, n: '1'}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}})
@ -119,7 +119,7 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) {
*/
async function isRefExists(ref, execaOpts) {
try {
return (await execa('git', ['rev-parse', '--verify', ref], execaOpts)).code === 0;
return (await execa('git', ['rev-parse', '--verify', ref], execaOpts)).exitCode === 0;
} catch (error) {
debug(error);
}
@ -134,7 +134,7 @@ async function isRefExists(ref, execaOpts) {
*/
async function fetch(repositoryUrl, branch, execaOpts) {
const isLocalExists =
(await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).code === 0;
(await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).exitCode === 0;
try {
await execa(
@ -195,7 +195,7 @@ async function repoUrl(execaOpts) {
*/
async function isGitRepo(execaOpts) {
try {
return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).code === 0;
return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).exitCode === 0;
} catch (error) {
debug(error);
}
@ -254,7 +254,7 @@ async function push(repositoryUrl, execaOpts) {
*/
async function verifyTagName(tagName, execaOpts) {
try {
return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).code === 0;
return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).exitCode === 0;
} catch (error) {
debug(error);
}
@ -270,7 +270,7 @@ async function verifyTagName(tagName, execaOpts) {
*/
async function verifyBranchName(branch, execaOpts) {
try {
return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOpts)).code === 0;
return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOpts)).exitCode === 0;
} catch (error) {
debug(error);
}

View File

@ -31,7 +31,7 @@
"cosmiconfig": "^5.0.1",
"debug": "^4.0.0",
"env-ci": "^4.0.0",
"execa": "^1.0.0",
"execa": "^2.0.0",
"figures": "^3.0.0",
"find-versions": "^3.0.0",
"get-stream": "^5.0.0",

View File

@ -67,7 +67,7 @@ test.serial('Pass options to semantic-release API', async t => {
];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.deepEqual(run.args[0][0].branches, ['master', 'next']);
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
@ -85,7 +85,7 @@ test.serial('Pass options to semantic-release API', async t => {
t.is(run.args[0][0].debug, true);
t.is(run.args[0][0].dryRun, true);
t.is(code, 0);
t.is(exitCode, 0);
});
test.serial('Pass options to semantic-release API with alias arguments', async t => {
@ -109,7 +109,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.deepEqual(run.args[0][0].branches, ['master']);
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
@ -118,7 +118,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
t.deepEqual(run.args[0][0].extends, ['config1', 'config2']);
t.is(run.args[0][0].dryRun, true);
t.is(code, 0);
t.is(exitCode, 0);
});
test.serial('Pass unknown options to semantic-release API', async t => {
@ -126,13 +126,13 @@ test.serial('Pass unknown options to semantic-release API', async t => {
const argv = ['', '', '--bool', '--first-option', 'value1', '--second-option', 'value2', '--second-option', 'value3'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.is(run.args[0][0].bool, true);
t.is(run.args[0][0].firstOption, 'value1');
t.deepEqual(run.args[0][0].secondOption, ['value2', 'value3']);
t.is(code, 0);
t.is(exitCode, 0);
});
test.serial('Pass empty Array to semantic-release API for list option set to "false"', async t => {
@ -140,11 +140,11 @@ test.serial('Pass empty Array to semantic-release API for list option set to "fa
const argv = ['', '', '--publish', 'false'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.deepEqual(run.args[0][0].publish, []);
t.is(code, 0);
t.is(exitCode, 0);
});
test.serial('Do not set properties in option for which arg is not in command line', async t => {
@ -169,10 +169,10 @@ test.serial('Display help', async t => {
const argv = ['', '', '--help'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.regex(t.context.logs, /Run automated package publishing/);
t.is(code, 0);
t.is(exitCode, 0);
});
test.serial('Return error code and prints help if called with a command', async t => {
@ -180,11 +180,11 @@ test.serial('Return error code and prints help if called with a command', async
const argv = ['', '', 'pre'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.regex(t.context.errors, /Run automated package publishing/);
t.regex(t.context.errors, /Too many non-option arguments/);
t.is(code, 1);
t.is(exitCode, 1);
});
test.serial('Return error code if multiple plugin are set for single plugin', async t => {
@ -192,11 +192,11 @@ test.serial('Return error code if multiple plugin are set for single plugin', as
const argv = ['', '', '--analyze-commits', 'analyze1', 'analyze2'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.regex(t.context.errors, /Run automated package publishing/);
t.regex(t.context.errors, /Too many non-option arguments/);
t.is(code, 1);
t.is(exitCode, 1);
});
test.serial('Return error code if semantic-release throw error', async t => {
@ -204,10 +204,10 @@ test.serial('Return error code if semantic-release throw error', async t => {
const argv = ['', ''];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const code = await cli();
const exitCode = await cli();
t.regex(t.context.errors, /semantic-release error/);
t.is(code, 1);
t.is(exitCode, 1);
});
test.serial('Hide sensitive environment variable values from the logs', async t => {
@ -216,8 +216,8 @@ test.serial('Hide sensitive environment variable values from the logs', async t
const argv = ['', ''];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv, env: {...process.env, ...env}}});
const code = await cli();
const exitCode = await cli();
t.regex(t.context.errors, new RegExp(`Throw error: Exposing token ${escapeRegExp(SECRET_REPLACEMENT)}`));
t.is(code, 1);
t.is(exitCode, 1);
});

View File

@ -1,5 +1,5 @@
import execa from 'execa';
export async function npmView(packageName, env) {
return JSON.parse(await execa.stdout('npm', ['view', packageName, '--json'], {env}));
return JSON.parse((await execa('npm', ['view', packageName, '--json'], {env})).stdout);
}

View File

@ -83,9 +83,9 @@ test('Release patch, minor and major versions', async t => {
t.log('Commit a chore');
await gitCommits(['chore: Init repository'], {cwd});
t.log('$ semantic-release');
let {stdout, code} = await execa(cli, [], {env, cwd});
let {stdout, exitCode} = await execa(cli, [], {env, cwd});
t.regex(stdout, /There are no relevant changes, so no new version is released/);
t.is(code, 0);
t.is(exitCode, 0);
/* Initial release */
let version = '1.0.0';
@ -106,10 +106,10 @@ test('Release patch, minor and major versions', async t => {
t.log('Commit a feature');
await gitCommits(['feat: Initial commit'], {cwd});
t.log('$ semantic-release');
({stdout, code} = await execa(cli, [], {env, cwd}));
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and npm-shrinkwrap.json have been updated
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
@ -147,10 +147,10 @@ test('Release patch, minor and major versions', async t => {
t.log('Commit a fix');
await gitCommits(['fix: bar'], {cwd});
t.log('$ semantic-release');
({stdout, code} = await execa(cli, [], {env, cwd}));
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and npm-shrinkwrap.json have been updated
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
@ -188,10 +188,10 @@ test('Release patch, minor and major versions', async t => {
t.log('Commit a feature');
await gitCommits(['feat: baz'], {cwd});
t.log('$ semantic-release');
({stdout, code} = await execa(cli, [], {env, cwd}));
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and npm-shrinkwrap.json have been updated
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
@ -231,10 +231,10 @@ test('Release patch, minor and major versions', async t => {
await gitPush('origin', 'next', {cwd});
await gitCommits(['feat: foo\n\n BREAKING CHANGE: bar'], {cwd});
t.log('$ semantic-release');
({stdout, code} = await execa(cli, [], {env: {...env, TRAVIS_BRANCH: 'next'}, cwd}));
({stdout, exitCode} = await execa(cli, [], {env: {...env, TRAVIS_BRANCH: 'next'}, cwd}));
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and npm-shrinkwrap.json have been updated
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
@ -280,10 +280,10 @@ test('Release patch, minor and major versions', async t => {
await merge('next', {cwd});
await gitPush('origin', 'master', {cwd});
t.log('$ semantic-release');
({stdout, code} = await execa(cli, [], {env, cwd}));
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
t.regex(stdout, new RegExp(`Updated GitHub release: release-url/${version}`));
t.regex(stdout, new RegExp(`Adding version ${version} to npm registry on dist-tag latest`));
t.is(code, 0);
t.is(exitCode, 0);
// Wait for 3s as the change of dist-tag takes time to be reflected in the registry
await delay(3000);
@ -317,8 +317,8 @@ test('Exit with 1 if a plugin is not found', async t => {
release: {analyzeCommits: 'non-existing-path', success: false, fail: false},
});
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
t.is(code, 1);
const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
t.is(exitCode, 1);
t.regex(stderr, /Cannot find module/);
});
@ -335,8 +335,8 @@ test('Exit with 1 if a shareable config is not found', async t => {
release: {extends: 'non-existing-path', success: false, fail: false},
});
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
t.is(code, 1);
const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
t.is(exitCode, 1);
t.regex(stderr, /Cannot find module/);
});
@ -356,8 +356,8 @@ test('Exit with 1 if a shareable config reference a not found plugin', async t =
});
await writeJson(path.resolve(cwd, 'shareable.json'), shareable);
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
t.is(code, 1);
const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
t.is(exitCode, 1);
t.regex(stderr, /Cannot find module/);
});
@ -386,11 +386,11 @@ test('Dry-run', async t => {
t.log('Commit a feature');
await gitCommits(['feat: Initial commit'], {cwd});
t.log('$ semantic-release -d');
const {stdout, code} = await execa(cli, ['-d'], {env, cwd});
const {stdout, exitCode} = await execa(cli, ['-d'], {env, cwd});
t.regex(stdout, new RegExp(`There is no previous release, the next release version is ${version}`));
t.regex(stdout, new RegExp(`Release note for version ${version}`));
t.regex(stdout, /Initial commit/);
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and has not been modified
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '0.0.0-dev');
@ -434,10 +434,10 @@ test('Allow local releases with "noCi" option', async t => {
t.log('Commit a feature');
await gitCommits(['feat: Initial commit'], {cwd});
t.log('$ semantic-release --no-ci');
const {stdout, code} = await execa(cli, ['--no-ci'], {env: envNoCi, cwd});
const {stdout, exitCode} = await execa(cli, ['--no-ci'], {env: envNoCi, cwd});
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and has been updated
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
@ -474,7 +474,7 @@ test('Pass options via CLI arguments', async t => {
t.log('Commit a feature');
await gitCommits(['feat: Initial commit'], {cwd});
t.log('$ semantic-release');
const {stdout, code} = await execa(
const {stdout, exitCode} = await execa(
cli,
[
'--verify-conditions',
@ -490,7 +490,7 @@ test('Pass options via CLI arguments', async t => {
{env, cwd}
);
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
t.is(code, 0);
t.is(exitCode, 0);
// Verify package.json and has been updated
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
@ -581,14 +581,14 @@ test('Log unexpected errors from plugins and exit with 1', async t => {
t.log('Commit a feature');
await gitCommits(['feat: Initial commit'], {cwd});
t.log('$ semantic-release');
const {stderr, code} = await execa(cli, [], {env, cwd, reject: false});
const {stderr, exitCode} = await execa(cli, [], {env, cwd, reject: false});
// Verify the type and message are logged
t.regex(stderr, /Error: a/);
// Verify the the stacktrace is logged
t.regex(stderr, new RegExp(pluginError));
// Verify the Error properties are logged
t.regex(stderr, /errorProperty: 'errorProperty'/);
t.is(code, 1);
t.is(exitCode, 1);
});
test('Log errors inheriting SemanticReleaseError and exit with 1', async t => {
@ -608,10 +608,10 @@ test('Log errors inheriting SemanticReleaseError and exit with 1', async t => {
t.log('Commit a feature');
await gitCommits(['feat: Initial commit'], {cwd});
t.log('$ semantic-release');
const {stderr, code} = await execa(cli, [], {env, cwd, reject: false});
const {stderr, exitCode} = await execa(cli, [], {env, cwd, reject: false});
// Verify the type and message are logged
t.regex(stderr, /EINHERITED Inherited error/);
t.is(code, 1);
t.is(exitCode, 1);
});
test('Exit with 1 if missing permission to push to the remote repository', async t => {
@ -626,14 +626,14 @@ test('Exit with 1 if missing permission to push to the remote repository', async
await gitCommits(['feat: Initial commit'], {cwd});
await gitPush('origin', 'master', {cwd});
t.log('$ semantic-release');
const {stderr, code} = await execa(
const {stderr, exitCode} = await execa(
cli,
['--repository-url', 'http://user:wrong_pass@localhost:2080/git/unauthorized.git'],
{env: {...env, GH_TOKEN: 'user:wrong_pass'}, cwd, reject: false}
);
// Verify the type and message are logged
t.regex(stderr, /EGITNOPERMISSION/);
t.is(code, 1);
t.is(exitCode, 1);
});
test('Hide sensitive environment variable values from the logs', async t => {