2020-03-09 01:55:02 +01:00
|
|
|
//
|
|
|
|
// build task definitions
|
|
|
|
//
|
|
|
|
// run any task with "yarn build ${taskName}"
|
|
|
|
//
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
const path = require('path');
|
2021-02-04 19:15:23 +01:00
|
|
|
const livereload = require('gulp-livereload');
|
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
2021-09-09 21:44:57 +02:00
|
|
|
const minimist = require('minimist');
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
const { sync: globby } = require('globby');
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
createTask,
|
|
|
|
composeSeries,
|
|
|
|
composeParallel,
|
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
2021-09-09 21:44:57 +02:00
|
|
|
runTask,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = require('./task');
|
|
|
|
const createManifestTasks = require('./manifest');
|
|
|
|
const createScriptTasks = require('./scripts');
|
|
|
|
const createStyleTasks = require('./styles');
|
|
|
|
const createStaticAssetTasks = require('./static');
|
|
|
|
const createEtcTasks = require('./etc');
|
2021-10-25 18:57:30 +02:00
|
|
|
const { BuildType, getBrowserVersionMap } = require('./utils');
|
2020-03-09 01:55:02 +01:00
|
|
|
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
// Packages required dynamically via browserify configuration in dependencies
|
|
|
|
// Required for LavaMoat policy generation
|
2021-02-22 15:43:29 +01:00
|
|
|
require('loose-envify');
|
|
|
|
require('@babel/plugin-proposal-object-rest-spread');
|
|
|
|
require('@babel/plugin-transform-runtime');
|
|
|
|
require('@babel/plugin-proposal-class-properties');
|
|
|
|
require('@babel/plugin-proposal-optional-chaining');
|
|
|
|
require('@babel/plugin-proposal-nullish-coalescing-operator');
|
|
|
|
require('@babel/preset-env');
|
|
|
|
require('@babel/preset-react');
|
|
|
|
require('@babel/core');
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
// ESLint-related
|
|
|
|
require('@babel/eslint-parser');
|
|
|
|
require('@babel/eslint-plugin');
|
|
|
|
require('@metamask/eslint-config');
|
|
|
|
require('@metamask/eslint-config-nodejs');
|
|
|
|
require('eslint');
|
|
|
|
require('eslint-config-prettier');
|
|
|
|
require('eslint-import-resolver-node');
|
|
|
|
require('eslint-plugin-import');
|
|
|
|
require('eslint-plugin-node');
|
|
|
|
require('eslint-plugin-prettier');
|
|
|
|
require('eslint-plugin-react');
|
|
|
|
require('eslint-plugin-react-hooks');
|
2021-02-22 15:43:29 +01:00
|
|
|
|
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
2021-09-09 21:44:57 +02:00
|
|
|
defineAndRunBuildTasks();
|
2020-03-09 01:55:02 +01:00
|
|
|
|
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
2021-09-09 21:44:57 +02:00
|
|
|
function defineAndRunBuildTasks() {
|
|
|
|
const {
|
|
|
|
buildType,
|
|
|
|
entryTask,
|
|
|
|
isLavaMoat,
|
|
|
|
shouldIncludeLockdown,
|
2021-09-16 05:18:28 +02:00
|
|
|
shouldLintFenceFiles,
|
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
2021-09-09 21:44:57 +02:00
|
|
|
skipStats,
|
|
|
|
} = parseArgv();
|
|
|
|
|
|
|
|
const browserPlatforms = ['firefox', 'chrome', 'brave', 'opera'];
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2021-10-06 19:44:48 +02:00
|
|
|
const browserVersionMap = getBrowserVersionMap(browserPlatforms);
|
2021-09-08 22:08:23 +02:00
|
|
|
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
const ignoredFiles = getIgnoredFiles(buildType);
|
|
|
|
|
2021-08-31 01:49:39 +02:00
|
|
|
const staticTasks = createStaticAssetTasks({
|
|
|
|
livereload,
|
|
|
|
browserPlatforms,
|
|
|
|
shouldIncludeLockdown,
|
2021-09-28 18:13:26 +02:00
|
|
|
buildType,
|
2021-09-08 22:08:23 +02:00
|
|
|
});
|
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
2021-09-09 21:44:57 +02:00
|
|
|
|
2021-09-08 22:08:23 +02:00
|
|
|
const manifestTasks = createManifestTasks({
|
|
|
|
browserPlatforms,
|
2021-10-06 19:44:48 +02:00
|
|
|
browserVersionMap,
|
2021-09-28 18:13:26 +02:00
|
|
|
buildType,
|
2021-08-31 01:49:39 +02:00
|
|
|
});
|
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
2021-09-09 21:44:57 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const styleTasks = createStyleTasks({ livereload });
|
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
2021-09-09 21:44:57 +02:00
|
|
|
|
2021-09-08 22:08:23 +02:00
|
|
|
const scriptTasks = createScriptTasks({
|
|
|
|
browserPlatforms,
|
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
2021-09-09 21:44:57 +02:00
|
|
|
buildType,
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
ignoredFiles,
|
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
2021-09-09 21:44:57 +02:00
|
|
|
isLavaMoat,
|
|
|
|
livereload,
|
2021-09-16 05:18:28 +02:00
|
|
|
shouldLintFenceFiles,
|
2021-09-08 22:08:23 +02:00
|
|
|
});
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const { clean, reload, zip } = createEtcTasks({
|
|
|
|
livereload,
|
|
|
|
browserPlatforms,
|
2021-09-28 18:13:26 +02:00
|
|
|
buildType,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
// build for development (livereload)
|
2020-08-19 18:27:05 +02:00
|
|
|
createTask(
|
|
|
|
'dev',
|
2020-03-09 01:55:02 +01:00
|
|
|
composeSeries(
|
|
|
|
clean,
|
|
|
|
styleTasks.dev,
|
|
|
|
composeParallel(
|
|
|
|
scriptTasks.dev,
|
|
|
|
staticTasks.dev,
|
|
|
|
manifestTasks.dev,
|
2020-07-14 17:20:41 +02:00
|
|
|
reload,
|
|
|
|
),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
// build for test development (livereload)
|
2020-08-19 18:27:05 +02:00
|
|
|
createTask(
|
|
|
|
'testDev',
|
2020-03-09 01:55:02 +01:00
|
|
|
composeSeries(
|
|
|
|
clean,
|
|
|
|
styleTasks.dev,
|
|
|
|
composeParallel(
|
|
|
|
scriptTasks.testDev,
|
|
|
|
staticTasks.dev,
|
|
|
|
manifestTasks.testDev,
|
2020-07-14 17:20:41 +02:00
|
|
|
reload,
|
|
|
|
),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
// build for prod release
|
2020-08-19 18:27:05 +02:00
|
|
|
createTask(
|
|
|
|
'prod',
|
2020-03-09 01:55:02 +01:00
|
|
|
composeSeries(
|
|
|
|
clean,
|
|
|
|
styleTasks.prod,
|
2020-11-03 00:41:28 +01:00
|
|
|
composeParallel(scriptTasks.prod, staticTasks.prod, manifestTasks.prod),
|
2020-03-09 01:55:02 +01:00
|
|
|
zip,
|
2020-07-14 17:20:41 +02:00
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
// build for CI testing
|
2020-08-19 18:27:05 +02:00
|
|
|
createTask(
|
|
|
|
'test',
|
2020-03-09 01:55:02 +01:00
|
|
|
composeSeries(
|
|
|
|
clean,
|
|
|
|
styleTasks.prod,
|
2020-11-03 00:41:28 +01:00
|
|
|
composeParallel(scriptTasks.test, staticTasks.prod, manifestTasks.test),
|
2020-12-11 17:24:17 +01:00
|
|
|
zip,
|
2020-07-14 17:20:41 +02:00
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
// special build for minimal CI testing
|
2021-02-04 19:15:23 +01:00
|
|
|
createTask('styles', styleTasks.prod);
|
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
2021-09-09 21:44:57 +02:00
|
|
|
|
|
|
|
// Finally, start the build process by running the entry task.
|
|
|
|
runTask(entryTask, { skipStats });
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseArgv() {
|
|
|
|
const NamedArgs = {
|
|
|
|
BuildType: 'build-type',
|
2021-09-16 05:18:28 +02:00
|
|
|
LintFenceFiles: 'lint-fence-files',
|
2021-11-02 09:13:22 +01:00
|
|
|
Lockdown: 'lockdown',
|
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
2021-09-09 21:44:57 +02:00
|
|
|
SkipStats: 'skip-stats',
|
|
|
|
};
|
|
|
|
|
|
|
|
const argv = minimist(process.argv.slice(2), {
|
2021-09-16 05:18:28 +02:00
|
|
|
boolean: [
|
|
|
|
NamedArgs.LintFenceFiles,
|
2021-11-02 09:13:22 +01:00
|
|
|
NamedArgs.Lockdown,
|
2021-09-16 05:18:28 +02:00
|
|
|
NamedArgs.SkipStats,
|
|
|
|
],
|
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
2021-09-09 21:44:57 +02:00
|
|
|
string: [NamedArgs.BuildType],
|
|
|
|
default: {
|
2021-10-25 18:57:30 +02:00
|
|
|
[NamedArgs.BuildType]: BuildType.main,
|
2021-09-16 05:18:28 +02:00
|
|
|
[NamedArgs.LintFenceFiles]: true,
|
2021-11-02 09:13:22 +01:00
|
|
|
[NamedArgs.Lockdown]: true,
|
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
2021-09-09 21:44:57 +02:00
|
|
|
[NamedArgs.SkipStats]: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (argv._.length !== 1) {
|
|
|
|
throw new Error(
|
|
|
|
`Metamask build: Expected a single positional argument, but received "${argv._.length}" arguments.`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const entryTask = argv._[0];
|
|
|
|
if (!entryTask) {
|
|
|
|
throw new Error('MetaMask build: No entry task specified.');
|
|
|
|
}
|
|
|
|
|
|
|
|
const buildType = argv[NamedArgs.BuildType];
|
2021-10-25 18:57:30 +02:00
|
|
|
if (!(buildType in BuildType)) {
|
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
2021-09-09 21:44:57 +02:00
|
|
|
throw new Error(`MetaMask build: Invalid build type: "${buildType}"`);
|
|
|
|
}
|
|
|
|
|
2021-09-16 05:18:28 +02:00
|
|
|
// Manually default this to `false` for dev builds only.
|
|
|
|
const shouldLintFenceFiles = process.argv.includes(
|
|
|
|
`--${NamedArgs.LintFenceFiles}`,
|
|
|
|
)
|
|
|
|
? argv[NamedArgs.LintFenceFiles]
|
|
|
|
: !/dev/iu.test(entryTask);
|
|
|
|
|
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
2021-09-09 21:44:57 +02:00
|
|
|
return {
|
|
|
|
buildType,
|
|
|
|
entryTask,
|
|
|
|
isLavaMoat: process.argv[0].includes('lavamoat'),
|
2021-11-02 09:13:22 +01:00
|
|
|
shouldIncludeLockdown: argv[NamedArgs.Lockdown],
|
2021-09-16 05:18:28 +02:00
|
|
|
shouldLintFenceFiles,
|
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
2021-09-09 21:44:57 +02:00
|
|
|
skipStats: argv[NamedArgs.SkipStats],
|
|
|
|
};
|
2020-03-09 01:55:02 +01:00
|
|
|
}
|
Exclude files from builds by build type (#12521)
This PR enables the exclusion of JavaScript and JSON source by `buildType`, and enables the running of `eslint` under LavaMoat. 80-90% of the changes in this PR are `.patch` files and LavaMoat policy additions.
The file exclusion is designed to work in conjunction with our code fencing. If you forget to fence an import statement of an excluded file, the application will now error on boot. **This PR commits us to a particular naming convention for files intended only for certain builds.** Continue reading for details.
### Code Fencing and ESLint
When a file is modified by the code fencing transform, we run ESLint on it to ensure that we fail early for syntax-related issues. This PR adds the first code fences that will be actually be removed in production builds. As a consequence, this was also the first time we attempted to run ESLint under LavaMoat. Making that work required a lot of manual labor because of ESLint's use of dynamic imports, but the manual changes necessary were ultimately quite minor.
### File Exclusion
For all builds, any file in `app/`, `shared/` or `ui/` in a sub-directory matching `**/${otherBuildType}/**` (where `otherBuildType` is any build type except `main`) will be added to the list of excluded files, regardless of its file extension. For example, if we want to add one or more pages to the UI settings in Flask, we'd create the folder `ui/pages/settings/flask`, add any necessary files or sub-folders there, and fence the import statements for anything in that folder. If we wanted the same thing for Beta, we would name the directory `ui/pages/settings/beta`.
As it happens, we already organize some of our source files in this way, namely the logo JSON for Beta and Flask builds. See `ui/helpers/utils/build-types.js` to see how this works in practice.
Because the list of ignored filed is only passed to `browserify.exclude()`, any files not bundled by `browserify` will be ignored. For our purposes, this is mostly relevant for `.scss`. Since we don't have anything like code fencing for SCSS, we'll have to consider how to handle our styles separately.
2021-11-02 04:20:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the files to be ignored by the current build, if any.
|
|
|
|
*
|
|
|
|
* @param {string} buildType - The type of the current build.
|
|
|
|
* @returns {string[] | null} The array of files to be ignored by the current
|
|
|
|
* build, or `null` if no files are to be ignored.
|
|
|
|
*/
|
|
|
|
function getIgnoredFiles(currentBuildType) {
|
|
|
|
const excludedFiles = Object.values(BuildType)
|
|
|
|
// This filter removes "main" and the current build type. The files of any
|
|
|
|
// build types that remain in the array will be excluded. "main" is the
|
|
|
|
// default build type, and has no files that are excluded from other builds.
|
|
|
|
.filter(
|
|
|
|
(buildType) =>
|
|
|
|
buildType !== BuildType.main && buildType !== currentBuildType,
|
|
|
|
)
|
|
|
|
// Compute globs targeting files for exclusion for each excluded build
|
|
|
|
// type.
|
|
|
|
.reduce((excludedGlobs, excludedBuildType) => {
|
|
|
|
return excludedGlobs.concat([
|
|
|
|
`../../app/**/${excludedBuildType}/**`,
|
|
|
|
`../../shared/**/${excludedBuildType}/**`,
|
|
|
|
`../../ui/**/${excludedBuildType}/**`,
|
|
|
|
]);
|
|
|
|
}, [])
|
|
|
|
// This creates absolute paths of the form:
|
|
|
|
// PATH_TO_REPOSITORY_ROOT/app/**/${excludedBuildType}/**
|
|
|
|
.map((pathGlob) => path.resolve(__dirname, pathGlob));
|
|
|
|
|
|
|
|
return globby(excludedFiles);
|
|
|
|
}
|