Skip to content

Commit

Permalink
fix for promise limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Jul 27, 2020
1 parent d3b3043 commit 00aaa8f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions scripts/release.js
Expand Up @@ -5,6 +5,7 @@ const { join } = require('path');
const semver = require('semver');
const cp = require('child_process');
const npm = require('npm');
const limit = require('p-limit')(5);

function readWorkspaceInfo() {
const rawOutput = cp.execSync(`yarn workspaces info`).toString();
Expand Down Expand Up @@ -32,7 +33,7 @@ async function writePackage(path, content) {
}

async function getNewVersion() {
let version = argv._[0] || process.env.RELEASE_VERSION || await getMostRecentStable();
let version = argv._[0] || process.env.RELEASE_VERSION || await getMostRecentStable();

if (version.startsWith('v')) {
version = version.replace('v', '')
Expand Down Expand Up @@ -66,7 +67,11 @@ async function bumpDependencies(availableSiblings, newVersion, dependencies = {}
}));
}

async function publishDirectory(directory, attempt = 0) {
async function publishDirectory(directory) {
if (argv.dryrun) {
return;
}

return new Promise((resolve, reject) => {
npm.publish(directory, (err, result) => {
if (err) {
Expand Down Expand Up @@ -114,20 +119,20 @@ async function release() {
// Bump all package.json files and publish
const availableSiblings = Array.from(packages.keys());
await Promise.all(
Array.from(packages.entries()).map(async ([packageName, { path, content }]) => {
Array.from(packages.entries()).map(([packageName, { path, content }]) => limit(async () => {
console.info(`Updating and publishing package: ${packageName} from package; ${path}`)
content.version = version;
content.publishConfig = { access: 'public', tag: content.version.includes('alpha') ? 'alpha' : 'latest' };

bumpDependencies(availableSiblings, version, content.dependencies);

if (content.devDependencies) {
delete content.devDependencies;
}

await writePackage(path, content);
await publishDirectory(path);
})
}))
);

return version;
Expand Down

0 comments on commit 00aaa8f

Please sign in to comment.