Skip to content

Commit 72f4623

Browse files
committed
fix: rollout and execa usage
1 parent b8a82ff commit 72f4623

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

packages/cli-core/GitUtilities.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ const path = require('path');
33
const slash = require('slash');
44

55
function hasTag(tag) {
6-
return execa
7-
.stdout('git', ['rev-parse', '-q', '--verify', `refs/tags/${tag}`])
8-
.then(() => true, () => false);
6+
return execa('git', [
7+
'rev-parse',
8+
'-q',
9+
'--verify',
10+
`refs/tags/${tag}`,
11+
]).then(() => true, () => false);
912
}
1013
const repoName = name => name.replace(/^@.+\//, '');
1114

1215
exports.repoName = repoName;
1316

1417
exports.getRemoteUrl = cwd =>
15-
execa
16-
.stdout('git', ['config', 'remote.origin.url'], { cwd })
18+
execa('git', ['config', 'remote.origin.url'], { cwd })
19+
.then(r => r.stdout)
1720
.catch(() => '');
1821

1922
exports.remoteUrl = (name, org = '4Catalyzer') =>
@@ -44,21 +47,25 @@ exports.commit = message =>
4447
exports.removeLastCommit = () => execa('git', ['reset', 'HEAD~1', '--hard']);
4548

4649
exports.assertClean = async () => {
47-
if ((await execa.stdout('git', ['status', '--porcelain'])) !== '')
50+
const result = await execa('git', ['status', '--porcelain']).then(
51+
d => d.stdout,
52+
);
53+
54+
if (result !== '')
4855
throw new Error(
4956
'Git working tree is not clean, please commit or stash any unstaged changes',
5057
);
5158
};
5259

5360
exports.assertMatchesRemote = async () => {
54-
if (
55-
(await execa.stdout('git', [
56-
'rev-list',
57-
'--count',
58-
'--left-only',
59-
'@{u}...HEAD',
60-
])) !== '0'
61-
)
61+
const result = await execa('git', [
62+
'rev-list',
63+
'--count',
64+
'--left-only',
65+
'@{u}...HEAD',
66+
]).then(d => d.stdout);
67+
68+
if (result !== '0')
6269
throw new Error('The remote differs from the local working tree');
6370
};
6471

@@ -78,6 +85,8 @@ exports.addTag = async tag => {
7885

7986
exports.removeTag = tag => execa('git', ['tag', '-d', tag]);
8087
exports.getCurrentBranch = opts =>
81-
execa.stdout('git', ['rev-parse', '--abbrev-ref', 'HEAD'], opts);
88+
execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], opts).then(
89+
r => r.stdout,
90+
);
8291

8392
exports.pushWithTags = () => execa('git', ['push', '--follow-tags']);

packages/rollout/command.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ exports.builder = _ =>
215215
const handler = async argv => {
216216
const cwd = process.cwd();
217217
const changelogPath = path.join(cwd, 'CHANGELOG.md');
218-
const { path: pkgPath, package: pkg } = await readPackageJson({ cwd });
218+
const { path: pkgPath, packageJson } = await readPackageJson({ cwd });
219219

220220
const {
221221
otp,
@@ -228,7 +228,7 @@ const handler = async argv => {
228228
conventionalCommits,
229229
public: isPublic,
230230
allowBranch = ['master'],
231-
} = { ...pkg.release, ...argv };
231+
} = { ...packageJson.release, ...argv };
232232

233233
let { publishDir, nextVersion: version } = argv;
234234
const useYarn = hasYarn(cwd);
@@ -237,11 +237,11 @@ const handler = async argv => {
237237
);
238238

239239
// lerna
240-
if (!publishDir && pkg.publishConfig)
241-
publishDir = pkg.publishConfig.directory;
240+
if (!publishDir && packageJson.publishConfig)
241+
publishDir = packageJson.publishConfig.directory;
242242
// older rollout
243-
if (!publishDir && pkg.release) {
244-
publishDir = pkg.release.publishDir;
243+
if (!publishDir && packageJson.release) {
244+
publishDir = packageJson.release.publishDir;
245245
if (publishDir)
246246
ConsoleUtilities.warn(
247247
'publishDir in package.json `release` field is deprecated. Use the `publishConfig.directory` field instead.',
@@ -305,23 +305,25 @@ const handler = async argv => {
305305
},
306306
]);
307307

308-
let nextVersion = pkg.version;
308+
let nextVersion = packageJson.version;
309309

310310
if (!skipVersion) {
311311
if (conventionalCommits) {
312-
version = (await recommendedBump(pkg.version)) || version; // eslint-disable-line no-param-reassign
312+
version = (await recommendedBump(packageJson.version)) || version; // eslint-disable-line no-param-reassign
313313
}
314314

315-
nextVersion = await getNextVersion(version, pkg.version, preid);
315+
nextVersion = await getNextVersion(version, packageJson.version, preid);
316316
}
317317

318-
const isSameVersion = nextVersion === pkg.version;
318+
const isSameVersion = nextVersion === packageJson.version;
319319

320320
const isPrerelease = !!semver.prerelease(nextVersion);
321321
const tag = npmTag || isPrerelease ? 'next' : 'latest';
322322

323323
const confirmed = await PromptUtilities.confirm(
324-
`Are you sure you want to publish version: ${nextVersion}@${tag}?`,
324+
`Are you sure you want to publish version ${chalk.bold(
325+
`${nextVersion}@${tag}`,
326+
)}${publishDir ? ` from sub-directory ${chalk.bold(publishDir)}` : ''}`,
325327
);
326328

327329
if (!confirmed) return;
@@ -333,12 +335,12 @@ const handler = async argv => {
333335
title: isSameVersion
334336
? 'Bumping package version'
335337
: `Bumping version to: ${chalk.bold(nextVersion)} (${chalk.dim(
336-
`was ${pkg.version}`,
338+
`was ${packageJson.version}`,
337339
)})`,
338340
skip: () => skipVersion || (isSameVersion && 'Version is unchanged'),
339341
task: () =>
340342
writeJson(path.join(cwd, 'package.json'), {
341-
...pkg,
343+
...packageJson,
342344
version: nextVersion,
343345
}),
344346
},
@@ -375,12 +377,12 @@ const handler = async argv => {
375377
task: (context, task) => {
376378
const input = { otp, publishDir, isPublic, tag };
377379

378-
return from(npmPublish(pkg, input)).pipe(
380+
return from(npmPublish(packageJson, input)).pipe(
379381
catchError(error =>
380382
handleNpmError(error, task, nextOtp => {
381383
// eslint-disable-next-line no-param-reassign
382384
context.otp = nextOtp;
383-
return npmPublish(pkg, { ...input, otp: nextOtp });
385+
return npmPublish(packageJson, { ...input, otp: nextOtp });
384386
}),
385387
),
386388
);
@@ -401,7 +403,7 @@ const handler = async argv => {
401403
`\n\n🎉 Published v${nextVersion}@${tag}: ${chalk.blue(
402404
skipNpm
403405
? await GitUtilities.getRemoteUrl()
404-
: `https://npm.im/${pkg.name}`,
406+
: `https://npm.im/${packageJson.name}`,
405407
)} \n`,
406408
);
407409
};

0 commit comments

Comments
 (0)