|
|
|
const semver = require('semver');
|
|
|
|
const { version } = require('../../package.json');
|
|
|
|
|
|
|
|
const BuildTypes = {
|
|
|
|
beta: 'beta',
|
|
|
|
flask: 'flask',
|
|
|
|
main: 'main',
|
|
|
|
};
|
|
|
|
|
Rationalize build system arguments (#12047)
This rationalizes how arguments are passed to and parsed by the build system. To accomplish this, everything that isn't an environment variable from `.metamaskrc` or our CI environment is now passed as an argument on the command line.
Of such arguments, the `entryTask` is still expected as a positional argument in the first position (i.e. `process.argv[2]`), but everything else must be passed as a named argument. We use `minimist` to parse the arguments, and set defaults to preserve existing behavior.
Arguments are parsed in a new function, `parseArgv`, in `development/build/index.js`. They are assigned to environment variables where convenient, and otherwise returned from `parseArgv` to be passed to other functions invoked in the same file.
This change is motivated by our previous inconsistent handling of arguments to the build system, which will grow increasingly problematic as the build system grows in complexity. (Which it will very shortly, as we introduce Flask builds.)
Miscellaneous changes:
- Adds a build system readme at `development/build/README.md`
- Removes the `beta` package script. Now, we can instead call: `yarn dist --build-type beta`
- Fixes the casing of some log messages and reorders some parameters in the build system
3 years ago
|
|
|
/**
|
|
|
|
* 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' } }`.
|
Rationalize build system arguments (#12047)
This rationalizes how arguments are passed to and parsed by the build system. To accomplish this, everything that isn't an environment variable from `.metamaskrc` or our CI environment is now passed as an argument on the command line.
Of such arguments, the `entryTask` is still expected as a positional argument in the first position (i.e. `process.argv[2]`), but everything else must be passed as a named argument. We use `minimist` to parse the arguments, and set defaults to preserve existing behavior.
Arguments are parsed in a new function, `parseArgv`, in `development/build/index.js`. They are assigned to environment variables where convenient, and otherwise returned from `parseArgv` to be passed to other functions invoked in the same file.
This change is motivated by our previous inconsistent handling of arguments to the build system, which will grow increasingly problematic as the build system grows in complexity. (Which it will very shortly, as we introduce Flask builds.)
Miscellaneous changes:
- Adds a build system readme at `development/build/README.md`
- Removes the `beta` package script. Now, we can instead call: `yarn dist --build-type beta`
- Fixes the casing of some log messages and reorders some parameters in the build system
3 years ago
|
|
|
*/
|
|
|
|
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) => {
|
|
|
|
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 = {
|
Add build-time code exclusion using code fencing (#12060)
This PR adds build-time code exclusion by means of code fencing. For details, please see the README in `./development/build/transforms`. Note that linting of transformed files as a form of validation is added in a follow-up, #12075.
Hopefully exhaustive tests are added to ensure that the transform works according to its specification. Since these tests are Node-only, they required their own Jest config. The recommended way to work with multiple Jest configs is using the `projects` field in the Jest config, however [that feature breaks coverage collection](https://github.com/facebook/jest/issues/9628). That being the case, I had to set up two separate Jest configs. In order to get both test suites to run in parallel, Jest is now invoked via a script, `./test/run-jest.sh`.
By way of example, this build system feature allows us to add fences like this:
```javascript
this.store.updateStructure({
...,
GasFeeController: this.gasFeeController,
TokenListController: this.tokenListController,
///: BEGIN:ONLY_INCLUDE_IN(beta)
PluginController: this.pluginController,
///: END:ONLY_INCLUDE_IN
});
```
Which at build time are transformed to the following if the build type is not `beta`:
```javascript
this.store.updateStructure({
...,
GasFeeController: this.gasFeeController,
TokenListController: this.tokenListController,
});
```
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
3 years ago
|
|
|
BuildTypes,
|
|
|
|
getBrowserVersionMap,
|
|
|
|
};
|