Skip to content

Commit 5913432

Browse files
Broccohansl
authored andcommitted
fix(@angular/cli): Update package manager logic to include v1.* global configuration
1 parent 6ccf465 commit 5913432

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

packages/@angular/cli/utilities/config.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, writeFileSync } from 'fs';
1+
import { existsSync, readFileSync, writeFileSync } from 'fs';
22
import * as os from 'os';
33
import * as path from 'path';
44
import {
@@ -155,9 +155,38 @@ export function getPackageManager(): string {
155155
}
156156
}
157157

158+
// Only check legacy if updated workspace is not found.
159+
if (!workspace) {
160+
const legacyPackageManager = getLegacyPackageManager();
161+
if (legacyPackageManager !== null) {
162+
return legacyPackageManager;
163+
}
164+
}
158165
return 'npm';
159166
}
160167

168+
// Fallback, check for packageManager in config file in v1.* global config.
169+
function getLegacyPackageManager(): string | null {
170+
const homeDir = os.homedir();
171+
if (homeDir) {
172+
const legacyGlobalConfigPath = path.join(homeDir, '.angular-cli.json');
173+
if (existsSync(legacyGlobalConfigPath)) {
174+
const content = readFileSync(legacyGlobalConfigPath, 'utf-8');
175+
176+
const ast = parseJsonAst(content, JsonParseMode.Loose);
177+
if (ast.kind != 'object') {
178+
return null;
179+
}
180+
const cfg = ast as JsonAstObject;
181+
if (cfg.value.packageManager && typeof cfg.value.packageManager === 'string' &&
182+
cfg.value.packageManager !== 'default') {
183+
return cfg.value.packageManager;
184+
}
185+
}
186+
}
187+
return null;
188+
}
189+
161190
export function getDefaultSchematicCollection(): string {
162191
let workspace = getWorkspace('local');
163192

0 commit comments

Comments
 (0)