Explorar el Código

chore: Add automated check of Angular compiler versions

Relates to #758. Prevents future updates to the Angular versions from introducing version
mismatch errors
Michael Bromley hace 4 años
padre
commit
34a7690b48
Se han modificado 3 ficheros con 55 adiciones y 3 borrados
  1. 3 2
      package.json
  2. 50 0
      scripts/check-angular-versions.ts
  3. 2 1
      tsconfig.json

+ 3 - 2
package.json

@@ -17,12 +17,13 @@
     "codegen": "tsc -p scripts/codegen/plugins && ts-node scripts/codegen/generate-graphql-types.ts",
     "generate-typescript-docs": "ts-node scripts/docs/generate-typescript-docs.ts",
     "generate-graphql-docs": "ts-node scripts/docs/generate-graphql-docs.ts --api=shop && ts-node scripts/docs/generate-graphql-docs.ts --api=admin",
-    "version": "yarn check-imports && yarn build && yarn generate-changelog && git add CHANGELOG.md && git add */version.ts",
+    "version": "yarn check-imports && yarn check-angular-versions && yarn build && yarn generate-changelog && git add CHANGELOG.md && git add */version.ts",
     "dev-server:start": "cd packages/dev-server && yarn start",
     "test": "lerna run test --stream --no-bail",
     "e2e": "lerna run e2e --stream --no-bail",
     "build": "lerna run build",
     "check-imports": "ts-node scripts/check-imports.ts",
+    "check-angular-versions": "ts-node scripts/check-angular-versions.ts",
     "generate-changelog": "ts-node scripts/changelogs/generate-changelog.ts",
     "publish-release": "lerna publish -m \"chore: Publish %s\" --no-push",
     "publish-local": "lerna version --no-git-tag-version && cd scripts && ./publish-to-verdaccio.sh"
@@ -88,7 +89,7 @@
       "commit-msg": "commitlint -e $HUSKY_GIT_PARAMS",
       "post-commit": "git update-index --again",
       "pre-commit": "lint-staged",
-      "pre-push": "yarn check-imports && yarn build && yarn test && yarn e2e"
+      "pre-push": "yarn check-imports && yarn check-angular-versions && yarn build && yarn test && yarn e2e"
     }
   }
 }

+ 50 - 0
scripts/check-angular-versions.ts

@@ -0,0 +1,50 @@
+/* tslint:disable:no-console */
+import path from 'path';
+
+/**
+ * Checks the versions of the Angular compiler packages between the `admin-ui` and `ui-devkit` packages.
+ * These must match exactly since using different packages can introduce errors when compiling
+ * with the ui-devkit.
+ * See https://github.com/vendure-ecommerce/vendure/issues/758 for more on this issue.
+ */
+async function checkAngularVersions() {
+    const adminUiPackageJson = await import('../packages/admin-ui/package.json');
+    const uiDevkitPackageJson = await import('../packages/ui-devkit/package.json');
+
+    const angularCompilerPackages = ['@angular/cli', '@angular/compiler-cli', '@angular/compiler'];
+    const illegalSemverPrefixes = /^[~^]/;
+    const errors: string[] = [];
+
+    for (const pkg of angularCompilerPackages) {
+        const uiVersion =
+            adminUiPackageJson.devDependencies[pkg as keyof typeof adminUiPackageJson.devDependencies];
+        const devkitVersion =
+            uiDevkitPackageJson.dependencies[pkg as keyof typeof uiDevkitPackageJson.dependencies];
+
+        if (illegalSemverPrefixes.test(uiVersion)) {
+            errors.push(`Angular compiler versions must be exact, got "${uiVersion}" in admin-ui package`);
+        }
+        if (illegalSemverPrefixes.test(devkitVersion)) {
+            errors.push(
+                `Angular compiler versions must be exact, got "${devkitVersion}" in ui-devkit package`,
+            );
+        }
+
+        if (uiVersion !== devkitVersion) {
+            errors.push(
+                `Angular compiler package mismatch [${pkg}] admin-ui: "${uiVersion}", ui-devkit: "${devkitVersion}"`,
+            );
+        }
+    }
+    if (errors.length) {
+        for (const error of errors) {
+            console.log(`ERROR: ${error}`);
+        }
+        process.exit(1);
+    } else {
+        console.log(`Angular compiler package check passed`);
+        process.exit(0);
+    }
+}
+
+checkAngularVersions();

+ 2 - 1
tsconfig.json

@@ -12,6 +12,7 @@
     "strict": true,
     "strictPropertyInitialization": false,
     "sourceMap": false,
-    "newLine": "LF"
+    "newLine": "LF",
+    "resolveJsonModule": true
   }
 }