[6a3a178] | 1 | "use strict";
|
---|
| 2 | /**
|
---|
| 3 | * @license
|
---|
| 4 | * Copyright Google LLC All Rights Reserved.
|
---|
| 5 | *
|
---|
| 6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 7 | * found in the LICENSE file at https://angular.io/license
|
---|
| 8 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.assertCompatibleAngularVersion = void 0;
|
---|
| 11 | /* eslint-disable no-console */
|
---|
| 12 | const core_1 = require("@angular-devkit/core");
|
---|
| 13 | const semver_1 = require("semver");
|
---|
| 14 | function assertCompatibleAngularVersion(projectRoot) {
|
---|
| 15 | let angularCliPkgJson;
|
---|
| 16 | let angularPkgJson;
|
---|
| 17 | let rxjsPkgJson;
|
---|
| 18 | const resolveOptions = { paths: [projectRoot] };
|
---|
| 19 | try {
|
---|
| 20 | const angularPackagePath = require.resolve('@angular/core/package.json', resolveOptions);
|
---|
| 21 | const rxjsPackagePath = require.resolve('rxjs/package.json', resolveOptions);
|
---|
| 22 | angularPkgJson = require(angularPackagePath);
|
---|
| 23 | rxjsPkgJson = require(rxjsPackagePath);
|
---|
| 24 | }
|
---|
| 25 | catch {
|
---|
| 26 | console.error(core_1.tags.stripIndents `
|
---|
| 27 | You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.
|
---|
| 28 | `);
|
---|
| 29 | process.exit(2);
|
---|
| 30 | }
|
---|
| 31 | if (!(angularPkgJson && angularPkgJson['version'] && rxjsPkgJson && rxjsPkgJson['version'])) {
|
---|
| 32 | console.error(core_1.tags.stripIndents `
|
---|
| 33 | Cannot determine versions of "@angular/core" and/or "rxjs".
|
---|
| 34 | This likely means your local installation is broken. Please reinstall your packages.
|
---|
| 35 | `);
|
---|
| 36 | process.exit(2);
|
---|
| 37 | }
|
---|
| 38 | try {
|
---|
| 39 | const angularCliPkgPath = require.resolve('@angular/cli/package.json', resolveOptions);
|
---|
| 40 | angularCliPkgJson = require(angularCliPkgPath);
|
---|
| 41 | if (!(angularCliPkgJson && angularCliPkgJson['version'])) {
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | catch {
|
---|
| 46 | // Not using @angular-devkit/build-angular with @angular/cli is ok too.
|
---|
| 47 | // In this case we don't provide as many version checks.
|
---|
| 48 | return;
|
---|
| 49 | }
|
---|
| 50 | if (angularCliPkgJson['version'] === '0.0.0' || angularPkgJson['version'] === '0.0.0') {
|
---|
| 51 | // Internal CLI testing version or integration testing in the angular/angular
|
---|
| 52 | // repository with the generated development @angular/core npm package which is versioned "0.0.0".
|
---|
| 53 | return;
|
---|
| 54 | }
|
---|
| 55 | const angularVersion = new semver_1.SemVer(angularPkgJson['version']);
|
---|
| 56 | const cliMajor = new semver_1.SemVer(angularCliPkgJson['version']).major;
|
---|
| 57 | // e.g. CLI 8.0 supports '>=8.0.0 <9.0.0', including pre-releases (next, rcs, snapshots)
|
---|
| 58 | // of both 8 and 9.
|
---|
| 59 | const supportedAngularSemver = `^${cliMajor}.0.0-next || >=${cliMajor}.0.0 <${cliMajor + 1}.0.0`;
|
---|
| 60 | if (!semver_1.satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
|
---|
| 61 | console.error(core_1.tags.stripIndents `
|
---|
| 62 | This version of CLI is only compatible with Angular versions ${supportedAngularSemver},
|
---|
| 63 | but Angular version ${angularVersion} was found instead.
|
---|
| 64 |
|
---|
| 65 | Please visit the link below to find instructions on how to update Angular.
|
---|
| 66 | https://update.angular.io/
|
---|
| 67 | ` + '\n');
|
---|
| 68 | process.exit(3);
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | exports.assertCompatibleAngularVersion = assertCompatibleAngularVersion;
|
---|