From 39a06e1d3b977b88225b18e171338196b17691df Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:10:44 +0200 Subject: Add timeout before writing to stdin --- packages/monorepo-scripts/src/publish.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index af707ca47..6e2f1c3b8 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -193,11 +193,11 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (shouldPrintOutput) { utils.log(output); } - const isVersionPrompt = _.includes(output, 'Select a new version'); + const isVersionPrompt = /^\? Select a new version .* (currently .*)$/.test(output); if (isVersionPrompt) { const outputStripLeft = output.split('new version for ')[1]; packageName = outputStripLeft.split(' ')[0]; - child.stdin.write(`${SemVerIndex.Custom}\n`); + sleepAndWrite(child.stdin, SemVerIndex.Custom); } const isCustomVersionPrompt = output === '? Enter a custom version '; if (isCustomVersionPrompt) { @@ -205,11 +205,11 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (_.isUndefined(versionChange)) { throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); } - child.stdin.write(`${versionChange}\n`); + sleepAndWrite(child.stdin, versionChange); } const isFinalPrompt = _.includes(output, 'Are you sure you want to publish the above changes?'); if (isFinalPrompt && !IS_DRY_RUN) { - child.stdin.write(`y\n`); + sleepAndWrite(child.stdin, 'y'); // After confirmations, we want to print the output to watch the `lerna publish` command shouldPrintOutput = true; } else if (isFinalPrompt && IS_DRY_RUN) { @@ -224,6 +224,13 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string }); } +function sleepAndWrite(fileDescriptor: any, input: string | number): void { + const TIMEOUT = 100; + setTimeout(() => { + fileDescriptor.write(`${input}\n`); + }, TIMEOUT); +} + function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { const updatedVersionIfValid = semver.inc(currentVersion, 'patch'); if (_.isNull(updatedVersionIfValid)) { -- cgit