prepublish-check.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* -----------------------------------------------------------------------------
  2. | Copyright (c) Jupyter Development Team.
  3. | Distributed under the terms of the Modified BSD License.
  4. |----------------------------------------------------------------------------*/
  5. import * as fs from 'fs-extra';
  6. import * as glob from 'glob';
  7. import * as path from 'path';
  8. import * as utils from './utils';
  9. utils.exitOnUuncaughtException();
  10. utils.run('npm run build:packages');
  11. utils.getLernaPaths().forEach(pkgPath => {
  12. const pkgData = utils.readJSONFile(path.join(pkgPath, 'package.json'));
  13. const name = pkgData.name;
  14. // Skip private packages.
  15. if (!pkgData.public) {
  16. return;
  17. }
  18. console.debug(`Checking ${name}...`);
  19. // Make sure each glob resolves to at least one file.
  20. pkgData.files.forEach((fGlob: string) => {
  21. const result = glob.sync(fGlob);
  22. if (result.length === 0) {
  23. throw new Error(`${name} has missing file(s) "${fGlob}"`);
  24. }
  25. });
  26. // Make sure there is a main and that it exists.
  27. const main = pkgData.main;
  28. if (!main) {
  29. throw new Error(`No "main" entry for ${name}`);
  30. }
  31. const mainPath = path.join(pkgPath, main);
  32. if (!fs.existsSync(mainPath)) {
  33. throw new Error(`"main" entry "${main}" not found for ${name}`);
  34. }
  35. });