in src/utils/cordovaProjectHelper.ts [275:390]
public static determineIonicMajorVersion(projectRoot: string): number | undefined {
// Ionic 1 check
// First look for "ionic.project" at the project root
if (fs.existsSync(path.join(projectRoot, CordovaProjectHelper.IONIC_PROJECT_FILE))) {
return 1;
// If not found, fall back to looking for "www/lib/ionic" folder. This isn't a 100% guarantee though: an Ionic project doesn't necessarily have an "ionic.project" and could have the Ionic lib
// files in a non-default location
} else if (fs.existsSync(path.join(projectRoot, CordovaProjectHelper.IONIC_LIB_DEFAULT_PATH))) {
return 1;
}
const packageJsonPath = path.join(projectRoot, "package.json");
if (!fs.existsSync(packageJsonPath)) {
return;
}
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
const dependencies = packageJson.dependencies || {};
const devDependencies = packageJson.devDependencies || {};
// Ionic 2 & 3 check
const highestNotSupportedIonic2BetaVersion = "2.0.0-beta.9";
const highestNotSupportedIonic3BetaVersion = "3.0.0-beta.3";
if ((dependencies["ionic-angular"]) && (devDependencies["@ionic/app-scripts"] || dependencies["@ionic/app-scripts"])) {
const ionicVersion = dependencies["ionic-angular"];
// If it's a valid version let's check it's greater than highest not supported Ionic major version beta
if (semver.valid(ionicVersion)) {
if (CordovaProjectHelper.versionSatisfiesInterval(
ionicVersion,
highestNotSupportedIonic2BetaVersion,
"3.0.0")
) {
return 2;
}
if (semver.gt(ionicVersion, highestNotSupportedIonic3BetaVersion)) {
return 3;
}
}
// If it's a valid range we check that the entire range is greater than highest not supported Ionic major version beta
if (semver.validRange(ionicVersion)) {
if (CordovaProjectHelper.versionRangeSatisfiesInterval(
ionicVersion,
highestNotSupportedIonic2BetaVersion,
"3.0.0")
) {
return 2;
}
if (semver.ltr(highestNotSupportedIonic3BetaVersion, ionicVersion)) {
return 3;
}
}
// Assuming for now that latest version is 3
if (ionicVersion === "latest" || ionicVersion === "nightly") {
return 3;
}
}
// Ionic 4, 5, 6 check
const highestNotSupportedIonic4BetaVersion = "4.0.0-beta.19";
const highestNotSupportedIonic5BetaVersion = "5.0.0-beta.6";
const highestNotSupportedIonic6BetaVersion = "6.0.0-beta.7";
if (dependencies["@ionic/angular"]) {
const ionicVersion = dependencies["@ionic/angular"];
// If it's a valid version let's check it's greater than highest not supported Ionic major version beta
if (semver.valid(ionicVersion)) {
if (CordovaProjectHelper.versionSatisfiesInterval(
ionicVersion,
highestNotSupportedIonic4BetaVersion,
"5.0.0")
) {
return 4;
}
if (CordovaProjectHelper.versionSatisfiesInterval(
ionicVersion,
highestNotSupportedIonic5BetaVersion,
"6.0.0")
) {
return 5;
}
if (semver.gt(ionicVersion, highestNotSupportedIonic6BetaVersion)) {
return 6;
}
}
// If it's a valid range we check that the entire range is greater than highest not supported Ionic major version beta
if (semver.validRange(ionicVersion)) {
if (CordovaProjectHelper.versionRangeSatisfiesInterval(
ionicVersion,
highestNotSupportedIonic4BetaVersion,
"5.0.0")
) {
return 4;
}
if (CordovaProjectHelper.versionRangeSatisfiesInterval(
ionicVersion,
highestNotSupportedIonic5BetaVersion,
"6.0.0")
) {
return 5;
}
if (semver.ltr(highestNotSupportedIonic6BetaVersion, ionicVersion)) {
return 6;
}
}
// Assuming for now that latest version is 6
if (ionicVersion === "latest" || ionicVersion === "nightly") {
return 6;
}
}
}