diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-24 03:10:44 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-24 03:10:44 +0800 |
commit | 39a06e1d3b977b88225b18e171338196b17691df (patch) | |
tree | 6d6864673f547822ccfdbe3ba0e5b458ee799312 | |
parent | bfe57b84d600c0d4aaa8b7a22323de6051f0751c (diff) | |
download | dexon-sol-tools-39a06e1d3b977b88225b18e171338196b17691df.tar.gz dexon-sol-tools-39a06e1d3b977b88225b18e171338196b17691df.tar.zst dexon-sol-tools-39a06e1d3b977b88225b18e171338196b17691df.zip |
Add timeout before writing to stdin
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 15 |
1 files changed, 11 insertions, 4 deletions
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)) { |