mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 07:16:36 +01:00
75a8aedc32
The version of a build is now derived from both the `version` field in `package.json` and the requested build type and version. The build type and version are added onto the manifest version as a suffix, according to the SemVer prerelease format. We already have support in the extension for versions of this format, but to apply a Flask or Beta version required manual updates to `package.json`. Now it can be done just with build arguments. A `get-version` module was created to make it easier to generate the version in the various places we do that during the build. It was created in the `development/lib` directory because it will be used by other non-build development scripts in a future PR. The `BuildType` constant was extracted to its own module as well, and moved to the `development/lib` directory. This was to make it clear that it's used by various different development scripts, not just the build.
57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
const semver = require('semver');
|
|
const { BuildType } = require('../lib/build-type');
|
|
|
|
/**
|
|
* 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[]} platforms - A list of browsers to generate versions for.
|
|
* @param {string} version - The current version.
|
|
* @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: '9.6.0-beta.1' } }`.
|
|
*/
|
|
function getBrowserVersionMap(platforms, version) {
|
|
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.beta, BuildType.flask].includes(buildType)) {
|
|
throw new Error(`Invalid prerelease build type: ${buildType}`);
|
|
}
|
|
}
|
|
|
|
return platforms.reduce((platformMap, platform) => {
|
|
const versionParts = [major, minor, patch];
|
|
const browserSpecificVersion = {};
|
|
if (prerelease) {
|
|
if (platform === 'firefox') {
|
|
versionParts[2] = `${versionParts[2]}${buildType}${buildVersion}`;
|
|
} else {
|
|
versionParts.push(buildVersion);
|
|
browserSpecificVersion.version_name = version;
|
|
}
|
|
}
|
|
browserSpecificVersion.version = versionParts.join('.');
|
|
platformMap[platform] = browserSpecificVersion;
|
|
return platformMap;
|
|
}, {});
|
|
}
|
|
|
|
module.exports = {
|
|
getBrowserVersionMap,
|
|
};
|