mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 15:02:11 +08:00
fix(@schematics/update): guard against null value for semver check
This commit is contained in:
parent
413a35bd56
commit
54e6924f74
@ -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",
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user