From ed0dbf37e235eec83b3cf739c213d8e3e4da5c0a Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Wed, 9 Jun 2021 15:39:09 +0200 Subject: [PATCH] feat(release): Update package lock for private packages during publishing --- package.json | 1 + scripts/monorepo/publish-all.js | 34 ++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9820bf1fa82..8a760611a08 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "packages-version": "lerna version --no-private --no-push -m \"chore(release): bump package versions\"", "postpackages-version": "npm run amend-compass-version && git push && git push --tags", "packages-publish": "node scripts/monorepo/publish-all.js", + "postpackages-publish": "git add packages/*/package-lock.json && git commit -m \"chore(release): Update package-lock files after a release\" && git push", "packages-test-version": "lerna version --no-private --allow-branch=* --no-git-tag-version --no-push", "postpackages-test-version": "node scripts/bump-compass-dependencies.js", "packages-test-publish": "node scripts/monorepo/publish-all.js --local --no-pristine-check --no-branch-check", diff --git a/scripts/monorepo/publish-all.js b/scripts/monorepo/publish-all.js index 5b5fd86361f..c2e00b7cc3b 100644 --- a/scripts/monorepo/publish-all.js +++ b/scripts/monorepo/publish-all.js @@ -41,8 +41,7 @@ function main() { fail('The repo is not pristine'); } - const packages = JSON.parse(childProcess.execSync('lerna list --json --toposort')) - .filter(package => !package.private); + const packages = JSON.parse(childProcess.execSync('lerna list --json --toposort')); let i = 0; for (const package of packages) { publishPackage(package, [++i, packages.length].join(' of ')); @@ -50,13 +49,24 @@ function main() { } function publishPackage( - { location: packageLocation, name: packageName, version: packageVersion }, + { + location: packageLocation, + name: packageName, + version: packageVersion, + private: isPackagePrivate + }, progress ) { console.log('\n'); const packageNameAndVersion = `${packageName}@${packageVersion}`; console.log(packageNameAndVersion, `(${progress})`); + + if (isPackagePrivate) { + console.log('Updating package-lock only ...'); + updatePackageLockOnly(packageLocation); + return; + } if (alreadyPublished(packageLocation, packageNameAndVersion)) { console.log('Already published, skipping ...'); @@ -86,6 +96,24 @@ function installAndPublish(packageLocation) { } } +function updatePackageLockOnly(packageLocation) { + const proc = childProcess.spawnSync( + 'npm', + ['install', '--package-lock-only', ...npmRegistrySpawnArgs], + { + cwd: packageLocation, + stdio: 'inherit', + stdin: 'inherit' + } + ); + + const { status: installExitCode } = proc; + + if (installExitCode !== 0) { + throw new Error(`npm install failed with exit code = ${installExitCode}`); + } +} + function alreadyPublished(packageLocation, packageNameAndVersion) { try { const stdout = childProcess.execSync(`npm view ${packageNameAndVersion} --json`, { cwd: packageLocation });