Skip to content

Commit

Permalink
fix(@schematics/update): guard against null value for semver check
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and alexeagle committed Apr 15, 2019
1 parent 413a35b commit 54e6924
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/schematics/update/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion packages/schematics/update/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 54e6924

Please sign in to comment.