Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export const SUPPORTED_PACKAGE_MANAGERS = {
saveExactFlag: '--exact',
saveTildeFlag: '--tilde',
saveDevFlag: '--dev',
noLockfileFlag: '--no-lockfile',
ignoreScriptsFlag: '--ignore-scripts',
getRegistryOptions: (registry: string) => ({ env: { NPM_CONFIG_REGISTRY: registry } }),
noLockfileFlag: '',
ignoreScriptsFlag: '--mode=skip-build',
getRegistryOptions: (registry: string) => ({ env: { YARN_NPM_REGISTRY_SERVER: registry } }),
versionCommand: ['--version'],
listDependenciesCommand: ['list', '--depth=0', '--json', '--recursive=false'],
getManifestCommand: ['npm', 'info', '--json'],
Expand Down
4 changes: 3 additions & 1 deletion packages/angular/cli/src/package-managers/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ export function parseNpmLikeManifest(stdout: string, logger?: Logger): PackageMa
return null;
}

return JSON.parse(stdout);
const result = JSON.parse(stdout);

return Array.isArray(result) ? result[result.length - 1] : result;
}

/**
Expand Down
21 changes: 20 additions & 1 deletion packages/angular/cli/src/package-managers/parsers_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { parseNpmLikeError, parseYarnClassicError } from './parsers';
import { parseNpmLikeError, parseNpmLikeManifest, parseYarnClassicError } from './parsers';

describe('parsers', () => {
describe('parseNpmLikeError', () => {
Expand Down Expand Up @@ -69,6 +69,25 @@ describe('parsers', () => {
});
});

describe('parseNpmLikeManifest', () => {
it('should parse a single manifest', () => {
const stdout = JSON.stringify({ name: 'foo', version: '1.0.0' });
expect(parseNpmLikeManifest(stdout)).toEqual({ name: 'foo', version: '1.0.0' });
});

it('should return the last manifest from an array', () => {
const stdout = JSON.stringify([
{ name: 'foo', version: '1.0.0' },
{ name: 'foo', version: '1.1.0' },
]);
expect(parseNpmLikeManifest(stdout)).toEqual({ name: 'foo', version: '1.1.0' });
});

it('should return null for empty stdout', () => {
expect(parseNpmLikeManifest('')).toBeNull();
});
});

describe('parseYarnClassicError', () => {
it('should parse a 404 from verbose logs', () => {
const stdout =
Expand Down