Skip to content

Commit

Permalink
FIX race condition in startup of verdaccio && FIX typos (#6956)
Browse files Browse the repository at this point in the history
FIX race condition in startup of verdaccio && FIX typos
  • Loading branch information
shilman committed Jun 4, 2019
2 parents f43a9b2 + 7c59cbf commit 829bf39
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions scripts/run-registry.js
Expand Up @@ -4,6 +4,7 @@ import inquirer from 'inquirer';
import chalk from 'chalk';
import detectFreePort from 'detect-port';
import { stripIndents } from 'common-tags';
import fs from 'fs';

import nodeCleanup from 'node-cleanup';

Expand All @@ -15,28 +16,40 @@ let verdaccioProcess;

const startVerdaccio = port => {
let resolved = false;
return new Promise((res, rej) => {
verdaccioProcess = spawn('npx', [
'verdaccio@4.0.0-beta.1',
'-c',
'scripts/verdaccio.yaml',
'-l',
port,
]);
verdaccioProcess.stdout.on('data', data => {
if (!resolved && data && data.toString().match(/http address/)) {
const [url] = data.toString().match(/(http:.*\d\/)/);
res(url);
resolved = true;
}
});

setTimeout(() => {
rej(new Error(`TIMEOUT - verdaccio didn't start within 60s`));
resolved = true;
verdaccioProcess.kill();
}, 60000);
});
return Promise.race([
new Promise(res => {
verdaccioProcess = spawn('npx', [
'verdaccio@4.0.1',
'-c',
'scripts/verdaccio.yaml',
'-l',
port,
]);
verdaccioProcess.stdout.on('data', data => {
if (!resolved && data && data.toString().match(/http address/)) {
const [url] = data.toString().match(/(http:.*\d\/)/);
res(url);
resolved = true;
}
fs.appendFile('verdaccio.log', data, err => {
if (err) {
throw err;
}
});
});
}),
new Promise((res, rej) => {
setTimeout(() => {
if (!resolved) {
rej(new Error(`TIMEOUT - verdaccio didn't start within 60s`));

resolved = true;

verdaccioProcess.kill();
}
}, 60000);
}),
]);
};
const registryUrl = (command, url) =>
new Promise((res, rej) => {
Expand Down Expand Up @@ -145,7 +158,7 @@ const askForReset = () =>
type: 'confirm',
message: `${chalk.red(
'THIS IS BAD'
)} looks like something bad hapened, OR you're already using a local registry, shall we reset to the default registry https://registry.npmjs.org/ ?`,
)} looks like something bad happened, OR you're already using a local registry, shall we reset to the default registry https://registry.npmjs.org/ ?`,
name: 'sure',
},
])
Expand Down

0 comments on commit 829bf39

Please sign in to comment.