check-angular-versions.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* tslint: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 = await import('../packages/admin-ui/package.json');
  11. const uiDevkitPackageJson = await import('../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. if (illegalSemverPrefixes.test(uiVersion)) {
  21. errors.push(`Angular compiler versions must be exact, got "${uiVersion}" in admin-ui package`);
  22. }
  23. if (illegalSemverPrefixes.test(devkitVersion)) {
  24. errors.push(
  25. `Angular compiler versions must be exact, got "${devkitVersion}" in ui-devkit package`,
  26. );
  27. }
  28. if (uiVersion !== devkitVersion) {
  29. errors.push(
  30. `Angular compiler package mismatch [${pkg}] admin-ui: "${uiVersion}", ui-devkit: "${devkitVersion}"`,
  31. );
  32. }
  33. }
  34. if (errors.length) {
  35. for (const error of errors) {
  36. console.log(`ERROR: ${error}`);
  37. }
  38. process.exit(1);
  39. } else {
  40. console.log(`Angular compiler package check passed`);
  41. process.exit(0);
  42. }
  43. }
  44. checkAngularVersions();