Migrate beta version to the main version field (#12246)
The main `version` field in `package.json` will now include the beta version (if present) rather than it being passed in via the CLI when building. The `version` field is now a fully SemVer-compatible version, with the added restriction that any prerelease portion of the version must match the format `<build type>.<build version>`. This brings the build in-line with the future release process we will be using for the beta version. The plan is for each future release to enter a "beta phase" where the version would get updated to reflect that it's a beta, and we would increment this beta version over time as we update the beta. The manifest gives us a place to store this beta version. It was also important to replace the automatic minor bump logic that was being used previously, because the version in beta might not be a minor bump. Additionally, the filename logic used for beta builds was updated to be generic across all build types rather than beta-specific. This will be useful for Flask builds in the future.feature/default_network_editable
parent
822ce5b8b0
commit
3a5538bd50
@ -1,32 +1,63 @@ |
||||
const semver = require('semver'); |
||||
const { version } = require('../../package.json'); |
||||
|
||||
const BuildTypes = { |
||||
beta: 'beta', |
||||
flask: 'flask', |
||||
main: 'main', |
||||
}; |
||||
|
||||
/** |
||||
* @returns {Object} An object with browser as key and next version of beta |
||||
* as the value. E.g. { firefox: '9.6.0.beta0', chrome: '9.6.0.1' } |
||||
* Map the current version to a format that is compatible with each browser. |
||||
* |
||||
* The given version number is assumed to be a SemVer version number. Additionally, if the version |
||||
* has a prerelease component, it is assumed to have the format "<build type>.<build version", |
||||
* where the build version is a positive integer. |
||||
* |
||||
* @param {string} currentVersion - The current version. |
||||
* @param {string[]} platforms - A list of browsers to generate versions for. |
||||
* @returns {Object} An object with the browser as the key and the browser-specific version object |
||||
* as the value. For example, the version `9.6.0-beta.1` would return the object |
||||
* `{ firefox: { version: '9.6.0.beta1' }, chrome: { version: '9.6.0.1', version_name: 'beta' } }`. |
||||
*/ |
||||
function getNextBetaVersionMap(currentVersion, betaVersion, platforms) { |
||||
const [major, minor] = currentVersion.split('.'); |
||||
function getBrowserVersionMap(platforms) { |
||||
const major = semver.major(version); |
||||
const minor = semver.minor(version); |
||||
const patch = semver.patch(version); |
||||
const prerelease = semver.prerelease(version); |
||||
|
||||
let buildType; |
||||
let buildVersion; |
||||
if (prerelease) { |
||||
if (prerelease.length !== 2) { |
||||
throw new Error(`Invalid prerelease version: '${prerelease.join('.')}'`); |
||||
} |
||||
[buildType, buildVersion] = prerelease; |
||||
if (!String(buildVersion).match(/^\d+$/u)) { |
||||
throw new Error(`Invalid prerelease build version: '${buildVersion}'`); |
||||
} else if (buildType !== BuildTypes.beta) { |
||||
throw new Error(`Invalid prerelease build type: ${buildType}`); |
||||
} |
||||
} |
||||
|
||||
return platforms.reduce((platformMap, platform) => { |
||||
platformMap[platform] = [ |
||||
// Keeps the current major
|
||||
major, |
||||
// Bump the minor version
|
||||
Number(minor) + 1, |
||||
// This isn't typically used
|
||||
0, |
||||
// The beta number
|
||||
`${platform === 'firefox' ? 'beta' : ''}${betaVersion}`, |
||||
].join('.'); |
||||
const versionParts = [major, minor, patch]; |
||||
const browserSpecificVersion = {}; |
||||
if (prerelease) { |
||||
if (platform === 'firefox') { |
||||
versionParts.push(`${buildType}${buildVersion}`); |
||||
} else { |
||||
versionParts.push(buildVersion); |
||||
browserSpecificVersion.version_name = buildType; |
||||
} |
||||
} |
||||
browserSpecificVersion.version = versionParts.join('.'); |
||||
platformMap[platform] = browserSpecificVersion; |
||||
return platformMap; |
||||
}, {}); |
||||
} |
||||
|
||||
const BuildTypes = { |
||||
beta: 'beta', |
||||
flask: 'flask', |
||||
main: 'main', |
||||
}; |
||||
|
||||
module.exports = { |
||||
BuildTypes, |
||||
getNextBetaVersionMap, |
||||
getBrowserVersionMap, |
||||
}; |
||||
|
Loading…
Reference in new issue