check-angular-versions.ts 2.1 KB

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