source: trip-planner-front/node_modules/@angular/cli/commands/version-impl.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 7.3 KB
RevLine 
[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 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.VersionCommand = void 0;
30const child_process_1 = require("child_process");
31const path = __importStar(require("path"));
32const command_1 = require("../models/command");
33const color_1 = require("../utilities/color");
34const package_manager_1 = require("../utilities/package-manager");
35/**
36 * Major versions of Node.js that are officially supported by Angular.
37 */
38const SUPPORTED_NODE_MAJORS = [12, 14];
39class VersionCommand extends command_1.Command {
40 async run() {
41 const cliPackage = require('../package.json');
42 let workspacePackage;
43 try {
44 workspacePackage = require(path.resolve(this.context.root, 'package.json'));
45 }
46 catch { }
47 const [nodeMajor] = process.versions.node.split('.').map((part) => Number(part));
48 const unsupportedNodeVersion = !SUPPORTED_NODE_MAJORS.includes(nodeMajor);
49 const patterns = [
50 /^@angular\/.*/,
51 /^@angular-devkit\/.*/,
52 /^@bazel\/.*/,
53 /^@ngtools\/.*/,
54 /^@nguniversal\/.*/,
55 /^@schematics\/.*/,
56 /^rxjs$/,
57 /^typescript$/,
58 /^ng-packagr$/,
59 /^webpack$/,
60 ];
61 const packageNames = [
62 ...Object.keys(cliPackage.dependencies || {}),
63 ...Object.keys(cliPackage.devDependencies || {}),
64 ...Object.keys((workspacePackage === null || workspacePackage === void 0 ? void 0 : workspacePackage.dependencies) || {}),
65 ...Object.keys((workspacePackage === null || workspacePackage === void 0 ? void 0 : workspacePackage.devDependencies) || {}),
66 ];
67 const versions = packageNames
68 .filter((x) => patterns.some((p) => p.test(x)))
69 .reduce((acc, name) => {
70 if (name in acc) {
71 return acc;
72 }
73 acc[name] = this.getVersion(name);
74 return acc;
75 }, {});
76 const ngCliVersion = cliPackage.version;
77 let angularCoreVersion = '';
78 const angularSameAsCore = [];
79 if (workspacePackage) {
80 // Filter all angular versions that are the same as core.
81 angularCoreVersion = versions['@angular/core'];
82 if (angularCoreVersion) {
83 for (const angularPackage of Object.keys(versions)) {
84 if (versions[angularPackage] == angularCoreVersion &&
85 angularPackage.startsWith('@angular/')) {
86 angularSameAsCore.push(angularPackage.replace(/^@angular\//, ''));
87 delete versions[angularPackage];
88 }
89 }
90 // Make sure we list them in alphabetical order.
91 angularSameAsCore.sort();
92 }
93 }
94 const namePad = ' '.repeat(Object.keys(versions).sort((a, b) => b.length - a.length)[0].length + 3);
95 const asciiArt = `
96 _ _ ____ _ ___
97 / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
98 / △ \\ | '_ \\ / _\` | | | | |/ _\` | '__| | | | | | |
99 / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |
100 /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|
101 |___/
102 `
103 .split('\n')
104 .map((x) => color_1.colors.red(x))
105 .join('\n');
106 this.logger.info(asciiArt);
107 this.logger.info(`
108 Angular CLI: ${ngCliVersion}
109 Node: ${process.versions.node}${unsupportedNodeVersion ? ' (Unsupported)' : ''}
110 Package Manager: ${await this.getPackageManager()}
111 OS: ${process.platform} ${process.arch}
112
113 Angular: ${angularCoreVersion}
114 ... ${angularSameAsCore
115 .reduce((acc, name) => {
116 // Perform a simple word wrap around 60.
117 if (acc.length == 0) {
118 return [name];
119 }
120 const line = acc[acc.length - 1] + ', ' + name;
121 if (line.length > 60) {
122 acc.push(name);
123 }
124 else {
125 acc[acc.length - 1] = line;
126 }
127 return acc;
128 }, [])
129 .join('\n... ')}
130
131 Package${namePad.slice(7)}Version
132 -------${namePad.replace(/ /g, '-')}------------------
133 ${Object.keys(versions)
134 .map((module) => `${module}${namePad.slice(module.length)}${versions[module]}`)
135 .sort()
136 .join('\n')}
137 `.replace(/^ {6}/gm, ''));
138 if (unsupportedNodeVersion) {
139 this.logger.warn(`Warning: The current version of Node (${process.versions.node}) is not supported by Angular.`);
140 }
141 }
142 getVersion(moduleName) {
143 let packagePath;
144 let cliOnly = false;
145 // Try to find the package in the workspace
146 try {
147 packagePath = require.resolve(`${moduleName}/package.json`, { paths: [this.context.root] });
148 }
149 catch { }
150 // If not found, try to find within the CLI
151 if (!packagePath) {
152 try {
153 packagePath = require.resolve(`${moduleName}/package.json`);
154 cliOnly = true;
155 }
156 catch { }
157 }
158 let version;
159 // If found, attempt to get the version
160 if (packagePath) {
161 try {
162 version = require(packagePath).version + (cliOnly ? ' (cli-only)' : '');
163 }
164 catch { }
165 }
166 return version || '<error>';
167 }
168 async getPackageManager() {
169 try {
170 const manager = await package_manager_1.getPackageManager(this.context.root);
171 const version = child_process_1.execSync(`${manager} --version`, {
172 encoding: 'utf8',
173 stdio: ['ignore', 'pipe', 'ignore'],
174 env: {
175 ...process.env,
176 // NPM updater notifier will prevents the child process from closing until it timeout after 3 minutes.
177 NO_UPDATE_NOTIFIER: '1',
178 NPM_CONFIG_UPDATE_NOTIFIER: 'false',
179 },
180 }).trim();
181 return `${manager} ${version}`;
182 }
183 catch {
184 return '<error>';
185 }
186 }
187}
188exports.VersionCommand = VersionCommand;
189VersionCommand.aliases = ['v'];
Note: See TracBrowser for help on using the repository browser.