message: chore: use async-await in buildTs script
diff: @@ -21,6 +21,7 @@ const {getPackages} = require('./buildUtils');
  const readFilePromise = util.promisify(fs.readFile);
  +(async () => {
  const packages = getPackages();
  const packagesWithTs = packages.filter(p =>
  @@ -44,7 +45,7 @@ const args = ['tsc', '-b', ...packagesWithTs, ...process.argv.slice(2)];
  console.log(chalk.inverse(' Building TypeScript definition files '));
  try {
  - execa.sync('yarn', args, {stdio: 'inherit'});
  + await execa('yarn', args, {stdio: 'inherit'});
  console.log(
  chalk.inverse.green(' Successfully built TypeScript definition files '),
  );
  @@ -52,15 +53,16 @@ try {
  console.error(
  chalk.inverse.red(' Unable to build TypeScript definition files '),
  );
  - console.error(e.stack);
  - process.exitCode = 1;
  - return;
  + throw e;
  }
  + console.log(chalk.inverse(' Validating TypeScript definition files '));
  +
  // we want to limit the number of processes we spawn
  const cpus = Math.max(1, os.cpus().length - 1);
  -Promise.all(
  + try {
  + await Promise.all(
  packagesWithTs.map(
  throat(cpus, async pkgDir => {
  const buildDir = path.resolve(pkgDir, 'build/**/*.d.ts');
  @@ -69,7 +71,9 @@ Promise.all(
  const globbed = await globby([buildDir, `!${ts3dot4}`]);
  const files = await Promise.all(
  - globbed.map(file => Promise.all([file, readFilePromise(file, 'utf8')])),
  + globbed.map(file =>
  + Promise.all([file, readFilePromise(file, 'utf8')]),
  + ),
  );
  const filesWithTypeReferences = files
  @@ -97,9 +101,7 @@ Promise.all(
  .join('\n\n');
  if (filesWithReferences) {
  - console.error(filesWithReferences);
  -
  - process.exit(1);
  + throw new Error(filesWithReferences);
  }
  const filesWithNodeReference = filesWithTypeReferences.map(
  @@ -121,10 +123,19 @@ Promise.all(
  }
  }),
  ),
  -).catch(e => {
  + );
  + } catch (e) {
  console.error(
  chalk.inverse.red(' Unable to validate TypeScript definition files '),
  );
  - console.error(e.stack);
  +
  + throw e;
  + }
  +
  + console.log(
  + chalk.inverse.green(' Successfully validated TypeScript definition files '),
  + );
  +})().catch(error => {
  + console.error('Got error', error.stack);
  process.exitCode = 1;
  });
  