check-angular-versions.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* eslint-disable no-console */
  2. /**
  3. * Checks the versions of the Angular compiler packages between the `admin-ui` and `ui-devkit` packages.
  4. * These must match exactly since using different packages can introduce errors when compiling
  5. * with the ui-devkit.
  6. * See https://github.com/vendurehq/vendure/issues/758 for more on this issue.
  7. */
  8. async function checkAngularVersions() {
  9. const adminUiPackageJson = require('../packages/admin-ui/package.json');
  10. const uiDevkitPackageJson = require('../packages/ui-devkit/package.json');
  11. const angularCompilerPackages = ['@angular/cli', '@angular/compiler-cli', '@angular/compiler'];
  12. const illegalSemverPrefixes = /^[~^]/;
  13. const errors: string[] = [];
  14. for (const pkg of angularCompilerPackages) {
  15. const uiVersion =
  16. adminUiPackageJson.devDependencies[pkg as keyof typeof adminUiPackageJson.devDependencies];
  17. const devkitVersion =
  18. uiDevkitPackageJson.dependencies[pkg as keyof typeof uiDevkitPackageJson.dependencies];
  19. // Removing this restriction to allow more flexibility in keeping angular versions
  20. // current for end-users, and also preventing issues in monorepos.
  21. // if (illegalSemverPrefixes.test(uiVersion)) {
  22. // errors.push(`Angular compiler versions must be exact, got "${uiVersion}" in admin-ui package`);
  23. // }
  24. // if (illegalSemverPrefixes.test(devkitVersion)) {
  25. // errors.push(
  26. // `Angular compiler versions must be exact, got "${devkitVersion}" in ui-devkit package`,
  27. // );
  28. // }
  29. if (uiVersion !== devkitVersion) {
  30. errors.push(
  31. `Angular compiler package mismatch [${pkg}] admin-ui: "${uiVersion}", ui-devkit: "${devkitVersion}"`,
  32. );
  33. }
  34. }
  35. if (errors.length) {
  36. for (const error of errors) {
  37. console.log(`ERROR: ${error}`);
  38. }
  39. process.exit(1);
  40. } else {
  41. console.log(`Angular compiler package check passed`);
  42. process.exit(0);
  43. }
  44. }
  45. checkAngularVersions();