fix(@schematics/update): guard against null value for semver check

This commit is contained in:
Filipe Silva 2019-04-02 16:45:10 +01:00 committed by Alex Eagle
parent 413a35bd56
commit 54e6924f74
2 changed files with 8 additions and 1 deletions

View File

@ -28,6 +28,7 @@ ts_library(
"//packages/angular_devkit/schematics",
"//packages/angular_devkit/schematics:tasks",
"@npm//rxjs",
"@npm//semver",
"@npm//@types/node",
"@npm//@types/semver",

View File

@ -528,7 +528,7 @@ function _buildPackageInfo(
// Find out the currently installed version. Either from the package.json or the node_modules/
// TODO: figure out a way to read package-lock.json and/or yarn.lock.
let installedVersion: string | undefined;
let installedVersion: string | undefined | null;
const packageContent = tree.read(`/node_modules/${name}/package.json`);
if (packageContent) {
const content = JSON.parse(packageContent.toString()) as JsonSchemaForNpmPackageJsonFiles;
@ -542,6 +542,12 @@ function _buildPackageInfo(
);
}
if (!installedVersion) {
throw new SchematicsException(
`An unexpected error happened; could not determine version for package ${name}.`,
);
}
const installedPackageJson = npmPackageJson.versions[installedVersion] || packageContent;
if (!installedPackageJson) {
throw new SchematicsException(