mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 15:31:16 +08:00
FIX race condition in startup of verdaccio && FIX typos (#6956)
FIX race condition in startup of verdaccio && FIX typos
This commit is contained in:
commit
829bf39dd4
@ -4,6 +4,7 @@ import inquirer from 'inquirer';
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import detectFreePort from 'detect-port';
|
import detectFreePort from 'detect-port';
|
||||||
import { stripIndents } from 'common-tags';
|
import { stripIndents } from 'common-tags';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
import nodeCleanup from 'node-cleanup';
|
import nodeCleanup from 'node-cleanup';
|
||||||
|
|
||||||
@ -15,28 +16,40 @@ let verdaccioProcess;
|
|||||||
|
|
||||||
const startVerdaccio = port => {
|
const startVerdaccio = port => {
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
return new Promise((res, rej) => {
|
return Promise.race([
|
||||||
verdaccioProcess = spawn('npx', [
|
new Promise(res => {
|
||||||
'verdaccio@4.0.0-beta.1',
|
verdaccioProcess = spawn('npx', [
|
||||||
'-c',
|
'verdaccio@4.0.1',
|
||||||
'scripts/verdaccio.yaml',
|
'-c',
|
||||||
'-l',
|
'scripts/verdaccio.yaml',
|
||||||
port,
|
'-l',
|
||||||
]);
|
port,
|
||||||
verdaccioProcess.stdout.on('data', data => {
|
]);
|
||||||
if (!resolved && data && data.toString().match(/http address/)) {
|
verdaccioProcess.stdout.on('data', data => {
|
||||||
const [url] = data.toString().match(/(http:.*\d\/)/);
|
if (!resolved && data && data.toString().match(/http address/)) {
|
||||||
res(url);
|
const [url] = data.toString().match(/(http:.*\d\/)/);
|
||||||
resolved = true;
|
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`));
|
||||||
|
|
||||||
setTimeout(() => {
|
resolved = true;
|
||||||
rej(new Error(`TIMEOUT - verdaccio didn't start within 60s`));
|
|
||||||
resolved = true;
|
verdaccioProcess.kill();
|
||||||
verdaccioProcess.kill();
|
}
|
||||||
}, 60000);
|
}, 60000);
|
||||||
});
|
}),
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
const registryUrl = (command, url) =>
|
const registryUrl = (command, url) =>
|
||||||
new Promise((res, rej) => {
|
new Promise((res, rej) => {
|
||||||
@ -145,7 +158,7 @@ const askForReset = () =>
|
|||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
message: `${chalk.red(
|
message: `${chalk.red(
|
||||||
'THIS IS BAD'
|
'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',
|
name: 'sure',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user