diff --git a/scripts/publish.js b/scripts/publish.js index 0a6ac1340a130..5b5a38579a42d 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -72,9 +72,10 @@ const getPublishes = async ({ force }) => { } const main = async (opts) => { - const { isLocal, smokePublish, packDestination } = opts - const isPack = !!packDestination - const publishes = await getPublishes({ force: isPack }) + const { test, otp, dryRun, smokePublish, packDestination } = opts + + const hasPackDest = !!packDestination + const publishes = await getPublishes({ force: smokePublish }) if (!publishes.length) { throw new Error( @@ -88,13 +89,15 @@ const main = async (opts) => { table.push([publish.name, publish.version, publish.tag]) } + const preformOperations = hasPackDest ? ['publish', 'pack'] : ['publish'] + const confirmMessage = [ - `Ready to ${isPack ? 'pack' : 'publish'} the following packages:`, + `Ready to ${preformOperations.join(',')} the following packages:`, table.toString(), - isPack ? null : 'Ok to proceed? ', + smokePublish ? null : 'Ok to proceed? ', ].filter(Boolean).join('\n') - if (isPack) { + if (smokePublish) { log.info(confirmMessage) } else { const confirm = await read({ prompt: confirmMessage, default: 'y' }) @@ -109,7 +112,7 @@ const main = async (opts) => { await npm('rm', '--global', '--force', 'npm') await npm('link', '--force', '--ignore-scripts') - if (opts.test) { + if (test) { await npm('run', 'lint-all', '--ignore-scripts') await npm('run', 'postlint', '--ignore-scripts') await npm('run', 'test-all', '--ignore-scripts') @@ -117,30 +120,35 @@ const main = async (opts) => { await npm('prune', '--omit=dev', '--no-save', '--no-audit', '--no-fund') await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund') - if (isLocal && smokePublish) { + + if (smokePublish) { log.info(`Skipping git dirty check due to local smoke publish test being run`) } else { await git.dirty() } + let count = -1 for (const publish of publishes) { + log.info(`Publishing ${publish.name}@${publish.version} to ${publish.tag} ${count++}/${publishes.length}`) const workspace = publish.workspace && `--workspace=${publish.name}` const publishPkg = (...args) => npm('publish', workspace, `--tag=${publish.tag}`, ...args) - await npm('version', 'prerelease', workspace, '--preid=smoke') - if (isPack) { + if (hasPackDest) { await npm( 'pack', workspace, - opts.packDestination && `--pack-destination=${opts.packDestination}` + packDestination && `--pack-destination=${packDestination}` ) - if (smokePublish) { - await publishPkg('--dry-run') - } + } + + if (smokePublish) { + // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run + await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts', '--no-git-tag-version') + await publishPkg('--dry-run', '--ignore-scripts') } else { await publishPkg( - opts.dryRun && '--dry-run', - opts.otp && `--otp=${opts.otp === 'op' ? await op() : opts.otp}` + dryRun && '--dry-run', + otp && `--otp=${otp === 'op' ? await op() : otp}` ) } } diff --git a/scripts/smoke-publish-test.sh b/scripts/smoke-publish-test.sh index 1d08a0adf2bc8..5de4f32931cf7 100755 --- a/scripts/smoke-publish-test.sh +++ b/scripts/smoke-publish-test.sh @@ -66,7 +66,7 @@ fi # were publishing it to the registry. The only difference is in the # publish.js script which will only pack and not publish node . version $NPM_VERSION --ignore-scripts --git-tag-version="$IS_CI" -node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true --is-local="$IS_LOCAL" +node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true NPM_TARBALL="$RUNNER_TEMP/npm-$NPM_VERSION.tgz" node . install --global $NPM_TARBALL