Преглед на файлове

Backport PR #10846: Fix Publish Check (#10850)

Co-authored-by: Afshin Taylor Darian <git@darian.af>
MeeseeksMachine преди 3 години
родител
ревизия
d5b714ea18
променени са 2 файла, в които са добавени 23 реда и са изтрити 31 реда
  1. 22 30
      buildutils/src/publish.ts
  2. 1 1
      testutils/src/jest-config.ts

+ 22 - 30
buildutils/src/publish.ts

@@ -5,23 +5,10 @@
 
 import commander from 'commander';
 import * as path from 'path';
+import * as os from 'os';
 import { handlePackage } from './update-dist-tag';
 import * as utils from './utils';
 
-/**
- * Verify that a package specifier is published and available on npm.
- *
- * @param specifier The package specifier to verify.
- */
-function verifyPublished(specifier: string): void {
-  const cmd = `npm info ${specifier}`;
-  const output = utils.run(cmd, { stdio: 'pipe' }, true);
-  console.log(specifier);
-  if (output.indexOf('dist-tags') === -1) {
-    throw new Error(`${specifier} is not yet available`);
-  }
-}
-
 /**
  * Sleep for a specified period.
  *
@@ -101,28 +88,33 @@ commander
     }
 
     // Make sure all current JS packages are published.
+    // Try and install them into a temporary local npm package.
     console.log('Checking for published packages...');
+    const installDir = os.tmpdir();
+    utils.run('npm init -y', { cwd: installDir, stdio: 'pipe' }, true);
+    const specifiers: string[] = [];
     utils.getCorePaths().forEach(async pkgPath => {
       const pkgJson = path.join(pkgPath, 'package.json');
       const pkgData = utils.readJSONFile(pkgJson);
-      const specifier = `${pkgData.name}@${pkgData.version}`;
-      let attempt = 0;
-      while (attempt < 10) {
-        try {
-          verifyPublished(specifier);
-          break;
-        } catch (e) {
-          console.error(e);
-          console.log('Sleeping for one minute...');
-          await sleep(1 * 60 * 1000);
-          attempt += 1;
-        }
-      }
-      if (attempt == 10) {
-        throw new Error(`Could not find package ${specifier}`);
-      }
+      specifiers.push(`${pkgData.name}@${pkgData.version}`);
     });
 
+    let attempt = 0;
+    while (attempt < 10) {
+      try {
+        utils.run(`npm install ${specifiers}`, { cwd: installDir });
+        break;
+      } catch (e) {
+        console.error(e);
+        console.log('Sleeping for one minute...');
+        await sleep(1 * 60 * 1000);
+        attempt += 1;
+      }
+    }
+    if (attempt == 10) {
+      throw new Error('Could not install packages');
+    }
+
     // Emit a system beep.
     process.stdout.write('\x07');
   });

+ 1 - 1
testutils/src/jest-config.ts

@@ -33,7 +33,7 @@ module.exports = function (baseDir: string) {
     testRegex: '/test/.*.spec.ts[x]?$',
     globals: {
       'ts-jest': {
-        tsConfig: `./tsconfig.test.json`
+        tsconfig: `./tsconfig.test.json`
       }
     }
   };