1 | ;
|
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 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
12 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
13 | desc = { enumerable: true, get: function() { return m[k]; } };
|
14 | }
|
15 | Object.defineProperty(o, k2, desc);
|
16 | }) : (function(o, m, k, k2) {
|
17 | if (k2 === undefined) k2 = k;
|
18 | o[k2] = m[k];
|
19 | }));
|
20 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
21 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
22 | }) : function(o, v) {
|
23 | o["default"] = v;
|
24 | });
|
25 | var __importStar = (this && this.__importStar) || function (mod) {
|
26 | if (mod && mod.__esModule) return mod;
|
27 | var result = {};
|
28 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
29 | __setModuleDefault(result, mod);
|
30 | return result;
|
31 | };
|
32 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
33 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
34 | };
|
35 | Object.defineProperty(exports, "__esModule", { value: true });
|
36 | exports.UnknownPackageManagerException = void 0;
|
37 | const core_1 = require("@angular-devkit/core");
|
38 | const child_process_1 = require("child_process");
|
39 | const ora_1 = __importDefault(require("ora"));
|
40 | const path = __importStar(require("path"));
|
41 | const rxjs_1 = require("rxjs");
|
42 | const src_1 = require("../../src");
|
43 | const packageManagers = {
|
44 | 'npm': {
|
45 | commands: {
|
46 | installAll: 'install',
|
47 | installPackage: 'install',
|
48 | },
|
49 | },
|
50 | 'cnpm': {
|
51 | commands: {
|
52 | installAll: 'install',
|
53 | installPackage: 'install',
|
54 | },
|
55 | },
|
56 | 'yarn': {
|
57 | commands: {
|
58 | installPackage: 'add',
|
59 | },
|
60 | },
|
61 | 'pnpm': {
|
62 | commands: {
|
63 | installAll: 'install',
|
64 | installPackage: 'install',
|
65 | },
|
66 | },
|
67 | };
|
68 | class UnknownPackageManagerException extends core_1.BaseException {
|
69 | constructor(name) {
|
70 | super(`Unknown package manager "${name}".`);
|
71 | }
|
72 | }
|
73 | exports.UnknownPackageManagerException = UnknownPackageManagerException;
|
74 | function default_1(factoryOptions = {}) {
|
75 | const packageManagerName = factoryOptions.packageManager || 'npm';
|
76 | const packageManagerProfile = packageManagers[packageManagerName];
|
77 | if (!packageManagerProfile) {
|
78 | throw new UnknownPackageManagerException(packageManagerName);
|
79 | }
|
80 | const rootDirectory = factoryOptions.rootDirectory || process.cwd();
|
81 | return (options = { command: 'install' }) => {
|
82 | let taskPackageManagerProfile = packageManagerProfile;
|
83 | let taskPackageManagerName = packageManagerName;
|
84 | if (factoryOptions.allowPackageManagerOverride && options.packageManager) {
|
85 | taskPackageManagerProfile = packageManagers[options.packageManager];
|
86 | if (!taskPackageManagerProfile) {
|
87 | throw new UnknownPackageManagerException(options.packageManager);
|
88 | }
|
89 | taskPackageManagerName = options.packageManager;
|
90 | }
|
91 | const bufferedOutput = [];
|
92 | const spawnOptions = {
|
93 | shell: true,
|
94 | cwd: path.join(rootDirectory, options.workingDirectory || ''),
|
95 | };
|
96 | if (options.hideOutput) {
|
97 | spawnOptions.stdio = options.quiet ? ['ignore', 'ignore', 'pipe'] : 'pipe';
|
98 | }
|
99 | else {
|
100 | spawnOptions.stdio = options.quiet ? ['ignore', 'ignore', 'inherit'] : 'inherit';
|
101 | }
|
102 | const args = [];
|
103 | if (options.packageName) {
|
104 | if (options.command === 'install') {
|
105 | args.push(taskPackageManagerProfile.commands.installPackage);
|
106 | }
|
107 | args.push(options.packageName);
|
108 | }
|
109 | else if (options.command === 'install' && taskPackageManagerProfile.commands.installAll) {
|
110 | args.push(taskPackageManagerProfile.commands.installAll);
|
111 | }
|
112 | if (!options.allowScripts) {
|
113 | // Yarn requires special handling since Yarn 2+ no longer has the `--ignore-scripts` flag
|
114 | if (taskPackageManagerName === 'yarn') {
|
115 | spawnOptions.env = {
|
116 | ...process.env,
|
117 | // Supported with yarn 1
|
118 | 'npm_config_ignore_scripts': 'true',
|
119 | // Supported with yarn 2+
|
120 | 'YARN_ENABLE_SCRIPTS': 'false',
|
121 | };
|
122 | }
|
123 | else {
|
124 | args.push('--ignore-scripts');
|
125 | }
|
126 | }
|
127 | if (factoryOptions.registry) {
|
128 | args.push(`--registry="${factoryOptions.registry}"`);
|
129 | }
|
130 | if (factoryOptions.force) {
|
131 | args.push('--force');
|
132 | }
|
133 | return new rxjs_1.Observable((obs) => {
|
134 | var _a, _b;
|
135 | const spinner = (0, ora_1.default)({
|
136 | text: `Installing packages (${taskPackageManagerName})...`,
|
137 | // Workaround for https://github.com/sindresorhus/ora/issues/136.
|
138 | discardStdin: process.platform != 'win32',
|
139 | }).start();
|
140 | const childProcess = (0, child_process_1.spawn)(taskPackageManagerName, args, spawnOptions).on('close', (code) => {
|
141 | if (code === 0) {
|
142 | spinner.succeed('Packages installed successfully.');
|
143 | spinner.stop();
|
144 | obs.next();
|
145 | obs.complete();
|
146 | }
|
147 | else {
|
148 | if (options.hideOutput) {
|
149 | bufferedOutput.forEach(({ stream, data }) => stream.write(data));
|
150 | }
|
151 | spinner.fail('Package install failed, see above.');
|
152 | obs.error(new src_1.UnsuccessfulWorkflowExecution());
|
153 | }
|
154 | });
|
155 | if (options.hideOutput) {
|
156 | (_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => bufferedOutput.push({ stream: process.stdout, data: data }));
|
157 | (_b = childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => bufferedOutput.push({ stream: process.stderr, data: data }));
|
158 | }
|
159 | });
|
160 | };
|
161 | }
|
162 | exports.default = default_1;
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