Skip to content

Commit feba0c6

Browse files
committed
fix(@schematics/update): ng update ignores packages it cannot find
Fix #10167
1 parent 4de4db9 commit feba0c6

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/schematics/update/update/index.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,29 @@ export default function(options: UpdateSchema): Rule {
656656

657657
// Build a map of all dependencies and their packageJson.
658658
reduce<NpmRepositoryPackageJson, Map<string, NpmRepositoryPackageJson>>(
659-
(acc, npmPackageJson) => acc.set(npmPackageJson.name, npmPackageJson),
659+
(acc, npmPackageJson) => {
660+
// If the package was not found on the registry. It could be private, so we will just
661+
// ignore. If the package was part of the list, we will error out, but will simply ignore
662+
// if it's either not requested (so just part of package.json. silently) or if it's a
663+
// `--all` situation. There is an edge case here where a public package peer depends on a
664+
// private one, but it's rare enough.
665+
if (!npmPackageJson.name) {
666+
if (packages.has(npmPackageJson.requestedName)) {
667+
if (options.all) {
668+
logger.warn(`Package ${JSON.stringify(npmPackageJson.requestedName)} was not `
669+
+ 'found on the registry. Skipping.');
670+
} else {
671+
throw new SchematicsException(
672+
`Package ${JSON.stringify(npmPackageJson.requestedName)} was not found on the `
673+
+ 'registry. Cannot continue as this may be an error.');
674+
}
675+
}
676+
} else {
677+
acc.set(npmPackageJson.name, npmPackageJson);
678+
}
679+
680+
return acc;
681+
},
660682
new Map<string, NpmRepositoryPackageJson>(),
661683
),
662684

packages/schematics/update/update/npm-package-json.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { JsonSchemaForNpmPackageJsonFiles } from './package-json';
99

1010
export interface NpmRepositoryPackageJson {
1111
name: string;
12+
requestedName: string;
1213
description: string;
1314

1415
'dist-tags': {

packages/schematics/update/update/npm.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function getNpmPackageJson(
2828
packageName: string,
2929
registryUrl: string,
3030
logger: logging.LoggerApi,
31-
): Observable<NpmRepositoryPackageJson> {
31+
): Observable<Partial<NpmRepositoryPackageJson>> {
3232
let fullUrl = new url.URL(`http://${registryUrl}/${packageName.replace(/\//g, '%2F')}`);
3333
try {
3434
const registry = new url.URL(registryUrl);
@@ -53,6 +53,7 @@ export function getNpmPackageJson(
5353
response.on('end', () => {
5454
try {
5555
const json = JSON.parse(data);
56+
json.requestedName = packageName;
5657
subject.next(json as NpmRepositoryPackageJson);
5758
subject.complete();
5859
} catch (err) {

0 commit comments

Comments
 (0)