From 3a5538bd5030b15b682b2e6a1e774e43a754489f Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 6 Oct 2021 15:14:48 -0230 Subject: [PATCH] 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 `.`. 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. --- app/manifest/_beta_modifications.json | 3 +- development/build/README.md | 2 - development/build/etc.js | 24 +++------ development/build/index.js | 24 ++------- development/build/manifest.js | 28 +++++----- development/build/utils.js | 75 +++++++++++++++++++-------- lavamoat/node/policy.json | 10 +++- package.json | 1 + 8 files changed, 86 insertions(+), 81 deletions(-) diff --git a/app/manifest/_beta_modifications.json b/app/manifest/_beta_modifications.json index a505eb7f4..33a2da321 100644 --- a/app/manifest/_beta_modifications.json +++ b/app/manifest/_beta_modifications.json @@ -22,6 +22,5 @@ "512": "images/icon-512.png" }, "name": "__MSG_appName__ Beta", - "short_name": "__MSG_appName__ Beta", - "version": "" + "short_name": "__MSG_appName__ Beta" } diff --git a/development/build/README.md b/development/build/README.md index 6c671be27..0e29f78ec 100644 --- a/development/build/README.md +++ b/development/build/README.md @@ -40,8 +40,6 @@ Commands: e2e tests. Options: - --beta-version If the build type is "beta", the beta version number. - [number] [default: 0] --build-type The "type" of build to create. One of: "beta", "main" [string] [default: "main"] --lint-fence-files Whether files with code fences should be linted after diff --git a/development/build/etc.js b/development/build/etc.js index 8d2b75956..f68da192a 100644 --- a/development/build/etc.js +++ b/development/build/etc.js @@ -5,18 +5,12 @@ const del = require('del'); const pify = require('pify'); const pump = pify(require('pump')); const { version } = require('../../package.json'); - const { createTask, composeParallel } = require('./task'); const { BuildTypes } = require('./utils'); module.exports = createEtcTasks; -function createEtcTasks({ - betaVersionsMap, - browserPlatforms, - buildType, - livereload, -}) { +function createEtcTasks({ browserPlatforms, buildType, livereload }) { const clean = createTask('clean', async function clean() { await del(['./dist/*']); await Promise.all( @@ -34,23 +28,19 @@ function createEtcTasks({ const zip = createTask( 'zip', composeParallel( - ...browserPlatforms.map((platform) => - createZipTask( - platform, - buildType === BuildTypes.beta ? betaVersionsMap[platform] : undefined, - ), - ), + ...browserPlatforms.map((platform) => createZipTask(platform, buildType)), ), ); return { clean, reload, zip }; } -function createZipTask(platform, betaVersion) { +function createZipTask(platform, buildType) { return async () => { - const path = betaVersion - ? `metamask-BETA-${platform}-${betaVersion}` - : `metamask-${platform}-${version}`; + const path = + buildType === BuildTypes.main + ? `metamask-${platform}-${version}` + : `metamask-${buildType}-${platform}-${version}`; await pump( gulp.src(`dist/${platform}/**`), gulpZip(`${path}.zip`), diff --git a/development/build/index.js b/development/build/index.js index d3e2ecc8d..cbea6e799 100755 --- a/development/build/index.js +++ b/development/build/index.js @@ -5,7 +5,6 @@ // const livereload = require('gulp-livereload'); const minimist = require('minimist'); -const { version } = require('../../package.json'); const { createTask, composeSeries, @@ -17,7 +16,7 @@ const createScriptTasks = require('./scripts'); const createStyleTasks = require('./styles'); const createStaticAssetTasks = require('./static'); const createEtcTasks = require('./etc'); -const { BuildTypes, getNextBetaVersionMap } = require('./utils'); +const { BuildTypes, getBrowserVersionMap } = require('./utils'); // packages required dynamically via browserify configuration in dependencies require('loose-envify'); @@ -34,7 +33,6 @@ defineAndRunBuildTasks(); function defineAndRunBuildTasks() { const { - betaVersion, buildType, entryTask, isLavaMoat, @@ -45,14 +43,7 @@ function defineAndRunBuildTasks() { const browserPlatforms = ['firefox', 'chrome', 'brave', 'opera']; - let betaVersionsMap; - if (buildType === BuildTypes.beta) { - betaVersionsMap = getNextBetaVersionMap( - version, - betaVersion, - browserPlatforms, - ); - } + const browserVersionMap = getBrowserVersionMap(browserPlatforms); const staticTasks = createStaticAssetTasks({ livereload, @@ -63,7 +54,7 @@ function defineAndRunBuildTasks() { const manifestTasks = createManifestTasks({ browserPlatforms, - betaVersionsMap, + browserVersionMap, buildType, }); @@ -80,7 +71,6 @@ function defineAndRunBuildTasks() { const { clean, reload, zip } = createEtcTasks({ livereload, browserPlatforms, - betaVersionsMap, buildType, }); @@ -145,7 +135,6 @@ function defineAndRunBuildTasks() { function parseArgv() { const NamedArgs = { - BetaVersion: 'beta-version', BuildType: 'build-type', LintFenceFiles: 'lint-fence-files', OmitLockdown: 'omit-lockdown', @@ -160,7 +149,6 @@ function parseArgv() { ], string: [NamedArgs.BuildType], default: { - [NamedArgs.BetaVersion]: 0, [NamedArgs.BuildType]: BuildTypes.main, [NamedArgs.LintFenceFiles]: true, [NamedArgs.OmitLockdown]: false, @@ -179,11 +167,6 @@ function parseArgv() { throw new Error('MetaMask build: No entry task specified.'); } - const betaVersion = argv[NamedArgs.BetaVersion]; - if (!Number.isInteger(betaVersion) || betaVersion < 0) { - throw new Error(`MetaMask build: Invalid beta version: "${betaVersion}"`); - } - const buildType = argv[NamedArgs.BuildType]; if (!(buildType in BuildTypes)) { throw new Error(`MetaMask build: Invalid build type: "${buildType}"`); @@ -197,7 +180,6 @@ function parseArgv() { : !/dev/iu.test(entryTask); return { - betaVersion: String(betaVersion), buildType, entryTask, isLavaMoat: process.argv[0].includes('lavamoat'), diff --git a/development/build/manifest.js b/development/build/manifest.js index 6f8b9e8fe..e14c3d786 100644 --- a/development/build/manifest.js +++ b/development/build/manifest.js @@ -3,7 +3,6 @@ const path = require('path'); const { merge, cloneDeep } = require('lodash'); const baseManifest = require('../../app/manifest/_base.json'); -const { version } = require('../../package.json'); const betaManifestModifications = require('../../app/manifest/_beta_modifications.json'); const { createTask, composeSeries } = require('./task'); @@ -11,7 +10,11 @@ const { BuildTypes } = require('./utils'); module.exports = createManifestTasks; -function createManifestTasks({ betaVersionsMap, browserPlatforms, buildType }) { +function createManifestTasks({ + browserPlatforms, + browserVersionMap, + buildType, +}) { // merge base manifest with per-platform manifests const prepPlatforms = async () => { return Promise.all( @@ -29,9 +32,8 @@ function createManifestTasks({ betaVersionsMap, browserPlatforms, buildType }) { const result = merge( cloneDeep(baseManifest), platformModifications, - buildType === BuildTypes.beta - ? getBetaModifications(platform, betaVersionsMap) - : { version }, + browserVersionMap[platform], + getBuildModifications(buildType), ); const dir = path.join('.', 'dist', platform); await fs.mkdir(dir, { recursive: true }); @@ -110,16 +112,10 @@ async function writeJson(obj, file) { return fs.writeFile(file, JSON.stringify(obj, null, 2)); } -function getBetaModifications(platform, betaVersionsMap) { - if (!betaVersionsMap || typeof betaVersionsMap !== 'object') { - throw new Error('MetaMask build: Expected object beta versions map.'); +function getBuildModifications(buildType) { + const buildModifications = {}; + if (buildType === BuildTypes.beta) { + Object.assign(buildModifications, betaManifestModifications); } - - const betaVersion = betaVersionsMap[platform]; - - return { - ...betaManifestModifications, - version: betaVersion, - ...(platform === 'firefox' ? {} : { version_name: 'beta' }), - }; + return buildModifications; } diff --git a/development/build/utils.js b/development/build/utils.js index 0b8503d19..4413ab899 100644 --- a/development/build/utils.js +++ b/development/build/utils.js @@ -1,24 +1,5 @@ -/** - * @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' } - */ -function getNextBetaVersionMap(currentVersion, betaVersion, platforms) { - const [major, minor] = currentVersion.split('.'); - - 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('.'); - return platformMap; - }, {}); -} +const semver = require('semver'); +const { version } = require('../../package.json'); const BuildTypes = { beta: 'beta', @@ -26,7 +7,57 @@ const BuildTypes = { main: 'main', }; +/** + * 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 ". { + 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; + }, {}); +} + module.exports = { BuildTypes, - getNextBetaVersionMap, + getBrowserVersionMap, }; diff --git a/lavamoat/node/policy.json b/lavamoat/node/policy.json index b9080a2e6..8399643d6 100644 --- a/lavamoat/node/policy.json +++ b/lavamoat/node/policy.json @@ -2940,6 +2940,11 @@ "js-tokens": true } }, + "lru-cache": { + "packages": { + "yallist": true + } + }, "lru-queue": { "packages": { "es5-ext": true @@ -3815,6 +3820,9 @@ "globals": { "console": true, "process": true + }, + "packages": { + "lru-cache": true } }, "set-value": { @@ -4684,4 +4692,4 @@ } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 887b99329..6b0e1e337 100644 --- a/package.json +++ b/package.json @@ -316,6 +316,7 @@ "sass": "^1.32.4", "sass-loader": "^10.1.1", "selenium-webdriver": "4.0.0-alpha.7", + "semver": "^7.3.5", "serve-handler": "^6.1.2", "sinon": "^9.0.0", "source-map": "^0.7.2",