source: trip-planner-front/node_modules/@angular/cli/utilities/package-manager.js@ 8d391a1

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

initial commit

  • Property mode set to 100644
File size: 2.9 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 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.ensureCompatibleNpm = exports.getPackageManager = exports.supportsNpm = exports.supportsYarn = void 0;
11const child_process_1 = require("child_process");
12const fs_1 = require("fs");
13const path_1 = require("path");
14const semver_1 = require("semver");
15const workspace_schema_1 = require("../lib/config/workspace-schema");
16const config_1 = require("./config");
17function supports(name) {
18 try {
19 child_process_1.execSync(`${name} --version`, { stdio: 'ignore' });
20 return true;
21 }
22 catch {
23 return false;
24 }
25}
26function supportsYarn() {
27 return supports('yarn');
28}
29exports.supportsYarn = supportsYarn;
30function supportsNpm() {
31 return supports('npm');
32}
33exports.supportsNpm = supportsNpm;
34async function getPackageManager(root) {
35 let packageManager = (await config_1.getConfiguredPackageManager());
36 if (packageManager) {
37 return packageManager;
38 }
39 const hasYarn = supportsYarn();
40 const hasYarnLock = fs_1.existsSync(path_1.join(root, 'yarn.lock'));
41 const hasNpm = supportsNpm();
42 const hasNpmLock = fs_1.existsSync(path_1.join(root, 'package-lock.json'));
43 if (hasYarn && hasYarnLock && !hasNpmLock) {
44 packageManager = workspace_schema_1.PackageManager.Yarn;
45 }
46 else if (hasNpm && hasNpmLock && !hasYarnLock) {
47 packageManager = workspace_schema_1.PackageManager.Npm;
48 }
49 else if (hasYarn && !hasNpm) {
50 packageManager = workspace_schema_1.PackageManager.Yarn;
51 }
52 else if (hasNpm && !hasYarn) {
53 packageManager = workspace_schema_1.PackageManager.Npm;
54 }
55 // TODO: This should eventually inform the user of ambiguous package manager usage.
56 // Potentially with a prompt to choose and optionally set as the default.
57 return packageManager || workspace_schema_1.PackageManager.Npm;
58}
59exports.getPackageManager = getPackageManager;
60/**
61 * Checks if the npm version is a supported 7.x version. If not, display a warning.
62 */
63async function ensureCompatibleNpm(root) {
64 if ((await getPackageManager(root)) !== workspace_schema_1.PackageManager.Npm) {
65 return;
66 }
67 try {
68 const versionText = child_process_1.execSync('npm --version', { encoding: 'utf8', stdio: 'pipe' }).trim();
69 const version = semver_1.valid(versionText);
70 if (!version) {
71 return;
72 }
73 if (semver_1.satisfies(version, '>=7 <7.5.6')) {
74 // eslint-disable-next-line no-console
75 console.warn(`npm version ${version} detected.` +
76 ' When using npm 7 with the Angular CLI, npm version 7.5.6 or higher is recommended.');
77 }
78 }
79 catch {
80 // npm is not installed
81 }
82}
83exports.ensureCompatibleNpm = ensureCompatibleNpm;
Note: See TracBrowser for help on using the repository browser.