mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Refactor build script to include build target (#15447)
The "scripts" portion of the build script has been refactored to pass the "build target" throughout the file. The "build target" is the target environment for the build, reflected by the command used to start the build (e.g. "dev", "prod", "test", or "testDev"). Beforehand we derived the variables `devMode` and `testing` from this build target, and passed these throughout the script. However, there is a future change [1] that requires adding a new build target that acts like "prod" in some ways but not others. It was easier to refactor to pass through `buildTarget` directly than it was to add a _third_ boolean flag to indirectly represent the target. The existence of the "testDev" target made it convenient to still have the `testing` and `devMode` flag, so helper functions were added to derive those values from the build target. I anticipate that these will only be needed temporarily though. We will probably be able to get rid of the `testDev` target and the related complexities when we start adding more flags (like `--watch`[2] and `--minify`[3]) to the build script directly. [1]: https://github.com/MetaMask/metamask-extension/issues/15003 [2]: https://github.com/MetaMask/metamask-extension/issues/12767 [3]: https://github.com/MetaMask/metamask-extension/issues/12768
This commit is contained in:
parent
cad7ea04b1
commit
fa336b5137
@ -1,3 +1,10 @@
|
|||||||
|
const BUILD_TARGETS = {
|
||||||
|
DEVELOPMENT: 'dev',
|
||||||
|
PRODUCTION: 'prod',
|
||||||
|
E2E_TEST: 'test',
|
||||||
|
E2E_TEST_DEV: 'testDev',
|
||||||
|
};
|
||||||
|
|
||||||
const TASKS = {
|
const TASKS = {
|
||||||
CLEAN: 'clean',
|
CLEAN: 'clean',
|
||||||
DEV: 'dev',
|
DEV: 'dev',
|
||||||
@ -45,4 +52,4 @@ const TASKS = {
|
|||||||
ZIP: 'zip',
|
ZIP: 'zip',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { TASKS };
|
module.exports = { BUILD_TARGETS, TASKS };
|
||||||
|
@ -49,6 +49,7 @@ const metamaskrc = require('rc')('metamask', {
|
|||||||
|
|
||||||
const { streamFlatMap } = require('../stream-flat-map');
|
const { streamFlatMap } = require('../stream-flat-map');
|
||||||
const { BuildType } = require('../lib/build-type');
|
const { BuildType } = require('../lib/build-type');
|
||||||
|
const { BUILD_TARGETS } = require('./constants');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
createTask,
|
createTask,
|
||||||
@ -73,6 +74,32 @@ const ENVIRONMENT = {
|
|||||||
TESTING: 'testing',
|
TESTING: 'testing',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the current build is a development build or not.
|
||||||
|
*
|
||||||
|
* @param {BUILD_TARGETS} buildTarget - The current build target.
|
||||||
|
* @returns Whether the current build is a development build.
|
||||||
|
*/
|
||||||
|
function isDevBuild(buildTarget) {
|
||||||
|
return (
|
||||||
|
buildTarget === BUILD_TARGETS.DEVELOPMENT ||
|
||||||
|
buildTarget === BUILD_TARGETS.E2E_TEST_DEV
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the current build is an e2e test build or not.
|
||||||
|
*
|
||||||
|
* @param {BUILD_TARGETS} buildTarget - The current build target.
|
||||||
|
* @returns Whether the current build is an e2e test build.
|
||||||
|
*/
|
||||||
|
function isTestBuild(buildTarget) {
|
||||||
|
return (
|
||||||
|
buildTarget === BUILD_TARGETS.E2E_TEST ||
|
||||||
|
buildTarget === BUILD_TARGETS.E2E_TEST_DEV
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a value from the configuration, and confirm that it is set.
|
* Get a value from the configuration, and confirm that it is set.
|
||||||
*
|
*
|
||||||
@ -94,7 +121,7 @@ function getConfigValue(key) {
|
|||||||
* @param {object} options - The Infura project ID options.
|
* @param {object} options - The Infura project ID options.
|
||||||
* @param {BuildType} options.buildType - The current build type.
|
* @param {BuildType} options.buildType - The current build type.
|
||||||
* @param {ENVIRONMENT[keyof ENVIRONMENT]} options.environment - The build environment.
|
* @param {ENVIRONMENT[keyof ENVIRONMENT]} options.environment - The build environment.
|
||||||
* @param {boolean} options.testing - Whether the current build is a test build or not.
|
* @param {boolean} options.testing - Whether this is a test build or not.
|
||||||
* @returns {string} The Infura project ID.
|
* @returns {string} The Infura project ID.
|
||||||
*/
|
*/
|
||||||
function getInfuraProjectId({ buildType, environment, testing }) {
|
function getInfuraProjectId({ buildType, environment, testing }) {
|
||||||
@ -223,21 +250,24 @@ function createScriptTasks({
|
|||||||
const core = {
|
const core = {
|
||||||
// dev tasks (live reload)
|
// dev tasks (live reload)
|
||||||
dev: createTasksForScriptBundles({
|
dev: createTasksForScriptBundles({
|
||||||
|
buildTarget: BUILD_TARGETS.DEVELOPMENT,
|
||||||
taskPrefix: 'scripts:core:dev',
|
taskPrefix: 'scripts:core:dev',
|
||||||
devMode: true,
|
|
||||||
}),
|
}),
|
||||||
testDev: createTasksForScriptBundles({
|
// production
|
||||||
taskPrefix: 'scripts:core:test-live',
|
prod: createTasksForScriptBundles({
|
||||||
devMode: true,
|
buildTarget: BUILD_TARGETS.PRODUCTION,
|
||||||
testing: true,
|
taskPrefix: 'scripts:core:prod',
|
||||||
}),
|
}),
|
||||||
// built for CI tests
|
// built for CI tests
|
||||||
test: createTasksForScriptBundles({
|
test: createTasksForScriptBundles({
|
||||||
|
buildTarget: BUILD_TARGETS.E2E_TEST,
|
||||||
taskPrefix: 'scripts:core:test',
|
taskPrefix: 'scripts:core:test',
|
||||||
testing: true,
|
|
||||||
}),
|
}),
|
||||||
// production
|
// built for CI test debugging
|
||||||
prod: createTasksForScriptBundles({ taskPrefix: 'scripts:core:prod' }),
|
testDev: createTasksForScriptBundles({
|
||||||
|
buildTarget: BUILD_TARGETS.E2E_TEST_DEV,
|
||||||
|
taskPrefix: 'scripts:core:test-live',
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
// high level tasks
|
// high level tasks
|
||||||
@ -251,26 +281,20 @@ function createScriptTasks({
|
|||||||
* parallel for a single type of build (e.g. dev, testing, production).
|
* parallel for a single type of build (e.g. dev, testing, production).
|
||||||
*
|
*
|
||||||
* @param {object} options - The build options.
|
* @param {object} options - The build options.
|
||||||
|
* @param {BUILD_TARGETS} options.buildTarget - The build target that these
|
||||||
|
* JavaScript modules are intended for.
|
||||||
* @param {string} options.taskPrefix - The prefix to use for the name of
|
* @param {string} options.taskPrefix - The prefix to use for the name of
|
||||||
* each defined task.
|
* each defined task.
|
||||||
* @param {boolean} [options.devMode] - Whether the build is being used for
|
|
||||||
* development.
|
|
||||||
* @param {boolean} [options.testing] - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
*/
|
*/
|
||||||
function createTasksForScriptBundles({
|
function createTasksForScriptBundles({ buildTarget, taskPrefix }) {
|
||||||
taskPrefix,
|
|
||||||
devMode = false,
|
|
||||||
testing = false,
|
|
||||||
}) {
|
|
||||||
const standardEntryPoints = ['background', 'ui', 'content-script'];
|
const standardEntryPoints = ['background', 'ui', 'content-script'];
|
||||||
const standardSubtask = createTask(
|
const standardSubtask = createTask(
|
||||||
`${taskPrefix}:standardEntryPoints`,
|
`${taskPrefix}:standardEntryPoints`,
|
||||||
createFactoredBuild({
|
createFactoredBuild({
|
||||||
applyLavaMoat,
|
applyLavaMoat,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
entryFiles: standardEntryPoints.map((label) => {
|
entryFiles: standardEntryPoints.map((label) => {
|
||||||
if (label === 'content-script') {
|
if (label === 'content-script') {
|
||||||
return './app/vendor/trezor/content-script.js';
|
return './app/vendor/trezor/content-script.js';
|
||||||
@ -280,7 +304,6 @@ function createScriptTasks({
|
|||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -289,24 +312,24 @@ function createScriptTasks({
|
|||||||
// because inpage bundle result is included inside contentscript
|
// because inpage bundle result is included inside contentscript
|
||||||
const contentscriptSubtask = createTask(
|
const contentscriptSubtask = createTask(
|
||||||
`${taskPrefix}:contentscript`,
|
`${taskPrefix}:contentscript`,
|
||||||
createContentscriptBundle({ devMode, testing }),
|
createContentscriptBundle({ buildTarget }),
|
||||||
);
|
);
|
||||||
|
|
||||||
// this can run whenever
|
// this can run whenever
|
||||||
const disableConsoleSubtask = createTask(
|
const disableConsoleSubtask = createTask(
|
||||||
`${taskPrefix}:disable-console`,
|
`${taskPrefix}:disable-console`,
|
||||||
createDisableConsoleBundle({ devMode, testing }),
|
createDisableConsoleBundle({ buildTarget }),
|
||||||
);
|
);
|
||||||
|
|
||||||
// this can run whenever
|
// this can run whenever
|
||||||
const installSentrySubtask = createTask(
|
const installSentrySubtask = createTask(
|
||||||
`${taskPrefix}:sentry`,
|
`${taskPrefix}:sentry`,
|
||||||
createSentryBundle({ devMode, testing }),
|
createSentryBundle({ buildTarget }),
|
||||||
);
|
);
|
||||||
|
|
||||||
// task for initiating browser livereload
|
// task for initiating browser livereload
|
||||||
const initiateLiveReload = async () => {
|
const initiateLiveReload = async () => {
|
||||||
if (devMode) {
|
if (isDevBuild(buildTarget)) {
|
||||||
// trigger live reload when the bundles are updated
|
// trigger live reload when the bundles are updated
|
||||||
// this is not ideal, but overcomes the limitations:
|
// this is not ideal, but overcomes the limitations:
|
||||||
// - run from the main process (not child process tasks)
|
// - run from the main process (not child process tasks)
|
||||||
@ -343,23 +366,19 @@ function createScriptTasks({
|
|||||||
* Create a bundle for the "disable-console" module.
|
* Create a bundle for the "disable-console" module.
|
||||||
*
|
*
|
||||||
* @param {object} options - The build options.
|
* @param {object} options - The build options.
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* development.
|
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @returns {Function} A function that creates the bundle.
|
* @returns {Function} A function that creates the bundle.
|
||||||
*/
|
*/
|
||||||
function createDisableConsoleBundle({ devMode, testing }) {
|
function createDisableConsoleBundle({ buildTarget }) {
|
||||||
const label = 'disable-console';
|
const label = 'disable-console';
|
||||||
return createNormalBundle({
|
return createNormalBundle({
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
destFilepath: `${label}.js`,
|
destFilepath: `${label}.js`,
|
||||||
devMode,
|
|
||||||
entryFilepath: `./app/scripts/${label}.js`,
|
entryFilepath: `./app/scripts/${label}.js`,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
label,
|
label,
|
||||||
testing,
|
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
version,
|
version,
|
||||||
@ -370,23 +389,19 @@ function createScriptTasks({
|
|||||||
* Create a bundle for the "sentry-install" module.
|
* Create a bundle for the "sentry-install" module.
|
||||||
*
|
*
|
||||||
* @param {object} options - The build options.
|
* @param {object} options - The build options.
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* development.
|
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @returns {Function} A function that creates the bundle.
|
* @returns {Function} A function that creates the bundle.
|
||||||
*/
|
*/
|
||||||
function createSentryBundle({ devMode, testing }) {
|
function createSentryBundle({ buildTarget }) {
|
||||||
const label = 'sentry-install';
|
const label = 'sentry-install';
|
||||||
return createNormalBundle({
|
return createNormalBundle({
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
destFilepath: `${label}.js`,
|
destFilepath: `${label}.js`,
|
||||||
devMode,
|
|
||||||
entryFilepath: `./app/scripts/${label}.js`,
|
entryFilepath: `./app/scripts/${label}.js`,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
label,
|
label,
|
||||||
testing,
|
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
version,
|
version,
|
||||||
@ -399,40 +414,35 @@ function createScriptTasks({
|
|||||||
* module.
|
* module.
|
||||||
*
|
*
|
||||||
* @param {object} options - The build options.
|
* @param {object} options - The build options.
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* development.
|
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @returns {Function} A function that creates the bundles.
|
* @returns {Function} A function that creates the bundles.
|
||||||
*/
|
*/
|
||||||
function createContentscriptBundle({ devMode, testing }) {
|
function createContentscriptBundle({ buildTarget }) {
|
||||||
const inpage = 'inpage';
|
const inpage = 'inpage';
|
||||||
const contentscript = 'contentscript';
|
const contentscript = 'contentscript';
|
||||||
return composeSeries(
|
return composeSeries(
|
||||||
createNormalBundle({
|
createNormalBundle({
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
destFilepath: `${inpage}.js`,
|
destFilepath: `${inpage}.js`,
|
||||||
devMode,
|
|
||||||
entryFilepath: `./app/scripts/${inpage}.js`,
|
entryFilepath: `./app/scripts/${inpage}.js`,
|
||||||
label: inpage,
|
label: inpage,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}),
|
}),
|
||||||
createNormalBundle({
|
createNormalBundle({
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
destFilepath: `${contentscript}.js`,
|
destFilepath: `${contentscript}.js`,
|
||||||
devMode,
|
|
||||||
entryFilepath: `./app/scripts/${contentscript}.js`,
|
entryFilepath: `./app/scripts/${contentscript}.js`,
|
||||||
label: contentscript,
|
label: contentscript,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -451,10 +461,9 @@ function createScriptTasks({
|
|||||||
* LavaMoat at runtime or not.
|
* LavaMoat at runtime or not.
|
||||||
* @param {string[]} options.browserPlatforms - A list of browser platforms to
|
* @param {string[]} options.browserPlatforms - A list of browser platforms to
|
||||||
* build bundles for.
|
* build bundles for.
|
||||||
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
||||||
* "flask", etc.).
|
* "flask", etc.).
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
|
||||||
* development.
|
|
||||||
* @param {string[] | null} options.ignoredFiles - A list of files to exclude
|
* @param {string[] | null} options.ignoredFiles - A list of files to exclude
|
||||||
* from the current build.
|
* from the current build.
|
||||||
* @param {string[]} options.jsBundles - A list of JavaScript bundles to be
|
* @param {string[]} options.jsBundles - A list of JavaScript bundles to be
|
||||||
@ -464,21 +473,18 @@ function createScriptTasks({
|
|||||||
* LavaMoat policy itself.
|
* LavaMoat policy itself.
|
||||||
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
|
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
|
||||||
* fences should be linted after fences have been removed.
|
* fences should be linted after fences have been removed.
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @param {string} options.version - The current version of the extension.
|
* @param {string} options.version - The current version of the extension.
|
||||||
* @returns {Function} A function that creates the set of bundles.
|
* @returns {Function} A function that creates the set of bundles.
|
||||||
*/
|
*/
|
||||||
async function createManifestV3AppInitializationBundle({
|
async function createManifestV3AppInitializationBundle({
|
||||||
applyLavaMoat,
|
applyLavaMoat,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
jsBundles,
|
jsBundles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}) {
|
}) {
|
||||||
const label = 'app-init';
|
const label = 'app-init';
|
||||||
@ -502,14 +508,13 @@ async function createManifestV3AppInitializationBundle({
|
|||||||
|
|
||||||
await createNormalBundle({
|
await createNormalBundle({
|
||||||
browserPlatforms: mv3BrowserPlatforms,
|
browserPlatforms: mv3BrowserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
destFilepath: 'app-init.js',
|
destFilepath: 'app-init.js',
|
||||||
devMode,
|
|
||||||
entryFilepath: './app/scripts/app-init.js',
|
entryFilepath: './app/scripts/app-init.js',
|
||||||
extraEnvironmentVariables,
|
extraEnvironmentVariables,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
label,
|
label,
|
||||||
testing,
|
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
version,
|
version,
|
||||||
@ -517,7 +522,7 @@ async function createManifestV3AppInitializationBundle({
|
|||||||
|
|
||||||
// Code below is used to set statsMode to true when testing in MV3
|
// Code below is used to set statsMode to true when testing in MV3
|
||||||
// This is used to capture module initialisation stats using lavamoat.
|
// This is used to capture module initialisation stats using lavamoat.
|
||||||
if (testing) {
|
if (isTestBuild(buildTarget)) {
|
||||||
const content = readFileSync('./dist/chrome/runtime-lavamoat.js', 'utf8');
|
const content = readFileSync('./dist/chrome/runtime-lavamoat.js', 'utf8');
|
||||||
const fileOutput = content.replace('statsMode = false', 'statsMode = true');
|
const fileOutput = content.replace('statsMode = false', 'statsMode = true');
|
||||||
writeFileSync('./dist/chrome/runtime-lavamoat.js', fileOutput);
|
writeFileSync('./dist/chrome/runtime-lavamoat.js', fileOutput);
|
||||||
@ -541,10 +546,9 @@ async function createManifestV3AppInitializationBundle({
|
|||||||
* LavaMoat at runtime or not.
|
* LavaMoat at runtime or not.
|
||||||
* @param {string[]} options.browserPlatforms - A list of browser platforms to
|
* @param {string[]} options.browserPlatforms - A list of browser platforms to
|
||||||
* build bundles for.
|
* build bundles for.
|
||||||
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
||||||
* "flask", etc.).
|
* "flask", etc.).
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
|
||||||
* development.
|
|
||||||
* @param {string[]} options.entryFiles - A list of entry point file paths,
|
* @param {string[]} options.entryFiles - A list of entry point file paths,
|
||||||
* relative to the repository root directory.
|
* relative to the repository root directory.
|
||||||
* @param {string[] | null} options.ignoredFiles - A list of files to exclude
|
* @param {string[] | null} options.ignoredFiles - A list of files to exclude
|
||||||
@ -554,21 +558,18 @@ async function createManifestV3AppInitializationBundle({
|
|||||||
* LavaMoat policy itself.
|
* LavaMoat policy itself.
|
||||||
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
|
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
|
||||||
* fences should be linted after fences have been removed.
|
* fences should be linted after fences have been removed.
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @param {string} options.version - The current version of the extension.
|
* @param {string} options.version - The current version of the extension.
|
||||||
* @returns {Function} A function that creates the set of bundles.
|
* @returns {Function} A function that creates the set of bundles.
|
||||||
*/
|
*/
|
||||||
function createFactoredBuild({
|
function createFactoredBuild({
|
||||||
applyLavaMoat,
|
applyLavaMoat,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
entryFiles,
|
entryFiles,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}) {
|
}) {
|
||||||
return async function () {
|
return async function () {
|
||||||
@ -578,25 +579,23 @@ function createFactoredBuild({
|
|||||||
const { bundlerOpts, events } = buildConfiguration;
|
const { bundlerOpts, events } = buildConfiguration;
|
||||||
|
|
||||||
// devMode options
|
// devMode options
|
||||||
const reloadOnChange = Boolean(devMode);
|
const reloadOnChange = isDevBuild(buildTarget);
|
||||||
const minify = Boolean(devMode) === false;
|
const minify = !isDevBuild(buildTarget);
|
||||||
|
|
||||||
const envVars = getEnvironmentVariables({
|
const envVars = getEnvironmentVariables({
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
});
|
});
|
||||||
setupBundlerDefaults(buildConfiguration, {
|
setupBundlerDefaults(buildConfiguration, {
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
envVars,
|
envVars,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
minify,
|
minify,
|
||||||
reloadOnChange,
|
reloadOnChange,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// set bundle entries
|
// set bundle entries
|
||||||
@ -725,13 +724,12 @@ function createFactoredBuild({
|
|||||||
await createManifestV3AppInitializationBundle({
|
await createManifestV3AppInitializationBundle({
|
||||||
applyLavaMoat,
|
applyLavaMoat,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
jsBundles,
|
jsBundles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -766,12 +764,11 @@ function createFactoredBuild({
|
|||||||
* @param {object} options - Build options.
|
* @param {object} options - Build options.
|
||||||
* @param {string[]} options.browserPlatforms - A list of browser platforms to
|
* @param {string[]} options.browserPlatforms - A list of browser platforms to
|
||||||
* build the bundle for.
|
* build the bundle for.
|
||||||
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
||||||
* "flask", etc.).
|
* "flask", etc.).
|
||||||
* @param {string} options.destFilepath - The file path the bundle should be
|
* @param {string} options.destFilepath - The file path the bundle should be
|
||||||
* written to.
|
* written to.
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
|
||||||
* development.
|
|
||||||
* @param {string[]} options.entryFilepath - The entry point file path,
|
* @param {string[]} options.entryFilepath - The entry point file path,
|
||||||
* relative to the repository root directory.
|
* relative to the repository root directory.
|
||||||
* @param {Record<string, unknown>} options.extraEnvironmentVariables - Extra
|
* @param {Record<string, unknown>} options.extraEnvironmentVariables - Extra
|
||||||
@ -785,23 +782,20 @@ function createFactoredBuild({
|
|||||||
* LavaMoat policy itself.
|
* LavaMoat policy itself.
|
||||||
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
|
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
|
||||||
* fences should be linted after fences have been removed.
|
* fences should be linted after fences have been removed.
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @param {string} options.version - The current version of the extension.
|
* @param {string} options.version - The current version of the extension.
|
||||||
* @returns {Function} A function that creates the bundle.
|
* @returns {Function} A function that creates the bundle.
|
||||||
*/
|
*/
|
||||||
function createNormalBundle({
|
function createNormalBundle({
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
destFilepath,
|
destFilepath,
|
||||||
devMode,
|
|
||||||
entryFilepath,
|
entryFilepath,
|
||||||
extraEnvironmentVariables,
|
extraEnvironmentVariables,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
label,
|
label,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}) {
|
}) {
|
||||||
return async function () {
|
return async function () {
|
||||||
@ -811,28 +805,26 @@ function createNormalBundle({
|
|||||||
const { bundlerOpts, events } = buildConfiguration;
|
const { bundlerOpts, events } = buildConfiguration;
|
||||||
|
|
||||||
// devMode options
|
// devMode options
|
||||||
|
const devMode = isDevBuild(buildTarget);
|
||||||
const reloadOnChange = Boolean(devMode);
|
const reloadOnChange = Boolean(devMode);
|
||||||
const minify = Boolean(devMode) === false;
|
const minify = Boolean(devMode) === false;
|
||||||
|
|
||||||
const envVars = {
|
const envVars = {
|
||||||
...getEnvironmentVariables({
|
...getEnvironmentVariables({
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
testing,
|
|
||||||
version,
|
version,
|
||||||
}),
|
}),
|
||||||
...extraEnvironmentVariables,
|
...extraEnvironmentVariables,
|
||||||
};
|
};
|
||||||
setupBundlerDefaults(buildConfiguration, {
|
setupBundlerDefaults(buildConfiguration, {
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
envVars,
|
envVars,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
minify,
|
minify,
|
||||||
reloadOnChange,
|
reloadOnChange,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// set bundle entries
|
// set bundle entries
|
||||||
@ -874,15 +866,14 @@ function createBuildConfiguration() {
|
|||||||
function setupBundlerDefaults(
|
function setupBundlerDefaults(
|
||||||
buildConfiguration,
|
buildConfiguration,
|
||||||
{
|
{
|
||||||
|
buildTarget,
|
||||||
buildType,
|
buildType,
|
||||||
devMode,
|
|
||||||
envVars,
|
envVars,
|
||||||
ignoredFiles,
|
ignoredFiles,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
minify,
|
minify,
|
||||||
reloadOnChange,
|
reloadOnChange,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
testing,
|
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { bundlerOpts } = buildConfiguration;
|
const { bundlerOpts } = buildConfiguration;
|
||||||
@ -905,13 +896,13 @@ function setupBundlerDefaults(
|
|||||||
// Look for TypeScript files when walking the dependency tree
|
// Look for TypeScript files when walking the dependency tree
|
||||||
extensions,
|
extensions,
|
||||||
// Use entryFilepath for moduleIds, easier to determine origin file
|
// Use entryFilepath for moduleIds, easier to determine origin file
|
||||||
fullPaths: devMode || testing,
|
fullPaths: isDevBuild(buildTarget) || isTestBuild(buildTarget),
|
||||||
// For sourcemaps
|
// For sourcemaps
|
||||||
debug: true,
|
debug: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ensure react-devtools are not included in non-dev builds
|
// Ensure react-devtools is only included in dev builds
|
||||||
if (!devMode || testing) {
|
if (buildTarget !== BUILD_TARGETS.DEVELOPMENT) {
|
||||||
bundlerOpts.manualIgnore.push('react-devtools');
|
bundlerOpts.manualIgnore.push('react-devtools');
|
||||||
bundlerOpts.manualIgnore.push('remote-redux-devtools');
|
bundlerOpts.manualIgnore.push('remote-redux-devtools');
|
||||||
}
|
}
|
||||||
@ -937,7 +928,7 @@ function setupBundlerDefaults(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup source maps
|
// Setup source maps
|
||||||
setupSourcemaps(buildConfiguration, { devMode });
|
setupSourcemaps(buildConfiguration, { buildTarget });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -991,7 +982,7 @@ function setupMinification(buildConfiguration) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupSourcemaps(buildConfiguration, { devMode }) {
|
function setupSourcemaps(buildConfiguration, { buildTarget }) {
|
||||||
const { events } = buildConfiguration;
|
const { events } = buildConfiguration;
|
||||||
events.on('configurePipeline', ({ pipeline }) => {
|
events.on('configurePipeline', ({ pipeline }) => {
|
||||||
pipeline.get('sourcemaps:init').push(sourcemaps.init({ loadMaps: true }));
|
pipeline.get('sourcemaps:init').push(sourcemaps.init({ loadMaps: true }));
|
||||||
@ -1000,7 +991,7 @@ function setupSourcemaps(buildConfiguration, { devMode }) {
|
|||||||
// Use inline source maps for development due to Chrome DevTools bug
|
// Use inline source maps for development due to Chrome DevTools bug
|
||||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=931675
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=931675
|
||||||
.push(
|
.push(
|
||||||
devMode
|
isDevBuild(buildTarget)
|
||||||
? sourcemaps.write()
|
? sourcemaps.write()
|
||||||
: sourcemaps.write('../sourcemaps', { addComment: false }),
|
: sourcemaps.write('../sourcemaps', { addComment: false }),
|
||||||
);
|
);
|
||||||
@ -1071,49 +1062,53 @@ async function createBundle(buildConfiguration, { reloadOnChange }) {
|
|||||||
* Get environment variables to inject in the current build.
|
* Get environment variables to inject in the current build.
|
||||||
*
|
*
|
||||||
* @param {object} options - Build options.
|
* @param {object} options - Build options.
|
||||||
|
* @param {BUILD_TARGETS} options.buildTarget - The current build target.
|
||||||
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
* @param {BuildType} options.buildType - The current build type (e.g. "main",
|
||||||
* "flask", etc.).
|
* "flask", etc.).
|
||||||
* @param {boolean} options.devMode - Whether the build is being used for
|
|
||||||
* development.
|
|
||||||
* @param {boolean} options.testing - Whether the build is intended for
|
|
||||||
* running end-to-end (e2e) tests.
|
|
||||||
* @param {string} options.version - The current version of the extension.
|
* @param {string} options.version - The current version of the extension.
|
||||||
* @returns {object} A map of environment variables to inject.
|
* @returns {object} A map of environment variables to inject.
|
||||||
*/
|
*/
|
||||||
function getEnvironmentVariables({ buildType, devMode, testing, version }) {
|
function getEnvironmentVariables({ buildTarget, buildType, version }) {
|
||||||
const environment = getEnvironment({ devMode, testing });
|
const environment = getEnvironment({ buildTarget });
|
||||||
if (environment === ENVIRONMENT.PRODUCTION && !process.env.SENTRY_DSN) {
|
if (environment === ENVIRONMENT.PRODUCTION && !process.env.SENTRY_DSN) {
|
||||||
throw new Error('Missing SENTRY_DSN environment variable');
|
throw new Error('Missing SENTRY_DSN environment variable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const devMode = isDevBuild(buildTarget);
|
||||||
|
const testing = isTestBuild(buildTarget);
|
||||||
return {
|
return {
|
||||||
|
COLLECTIBLES_V1: metamaskrc.COLLECTIBLES_V1 === '1',
|
||||||
|
CONF: devMode ? metamaskrc : {},
|
||||||
|
IN_TEST: testing,
|
||||||
|
INFURA_PROJECT_ID: getInfuraProjectId({
|
||||||
|
buildType,
|
||||||
|
environment,
|
||||||
|
testing,
|
||||||
|
}),
|
||||||
METAMASK_DEBUG: devMode,
|
METAMASK_DEBUG: devMode,
|
||||||
METAMASK_ENVIRONMENT: environment,
|
METAMASK_ENVIRONMENT: environment,
|
||||||
METAMASK_VERSION: version,
|
METAMASK_VERSION: version,
|
||||||
METAMASK_BUILD_TYPE: buildType,
|
METAMASK_BUILD_TYPE: buildType,
|
||||||
NODE_ENV: devMode ? ENVIRONMENT.DEVELOPMENT : ENVIRONMENT.PRODUCTION,
|
NODE_ENV: devMode ? ENVIRONMENT.DEVELOPMENT : ENVIRONMENT.PRODUCTION,
|
||||||
IN_TEST: testing,
|
ONBOARDING_V2: metamaskrc.ONBOARDING_V2 === '1',
|
||||||
PHISHING_WARNING_PAGE_URL: getPhishingWarningPageUrl({ testing }),
|
PHISHING_WARNING_PAGE_URL: getPhishingWarningPageUrl({ testing }),
|
||||||
PUBNUB_SUB_KEY: process.env.PUBNUB_SUB_KEY || '',
|
|
||||||
PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '',
|
PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '',
|
||||||
CONF: devMode ? metamaskrc : {},
|
PUBNUB_SUB_KEY: process.env.PUBNUB_SUB_KEY || '',
|
||||||
SENTRY_DSN: process.env.SENTRY_DSN,
|
|
||||||
SENTRY_DSN_DEV: metamaskrc.SENTRY_DSN_DEV,
|
|
||||||
INFURA_PROJECT_ID: getInfuraProjectId({ buildType, environment, testing }),
|
|
||||||
SEGMENT_HOST: metamaskrc.SEGMENT_HOST,
|
SEGMENT_HOST: metamaskrc.SEGMENT_HOST,
|
||||||
SEGMENT_WRITE_KEY: getSegmentWriteKey({ buildType, environment }),
|
SEGMENT_WRITE_KEY: getSegmentWriteKey({ buildType, environment }),
|
||||||
|
SENTRY_DSN: process.env.SENTRY_DSN,
|
||||||
|
SENTRY_DSN_DEV: metamaskrc.SENTRY_DSN_DEV,
|
||||||
SIWE_V1: metamaskrc.SIWE_V1 === '1',
|
SIWE_V1: metamaskrc.SIWE_V1 === '1',
|
||||||
SWAPS_USE_DEV_APIS: process.env.SWAPS_USE_DEV_APIS === '1',
|
SWAPS_USE_DEV_APIS: process.env.SWAPS_USE_DEV_APIS === '1',
|
||||||
ONBOARDING_V2: metamaskrc.ONBOARDING_V2 === '1',
|
|
||||||
COLLECTIBLES_V1: metamaskrc.COLLECTIBLES_V1 === '1',
|
|
||||||
TOKEN_DETECTION_V2: metamaskrc.TOKEN_DETECTION_V2 === '1',
|
TOKEN_DETECTION_V2: metamaskrc.TOKEN_DETECTION_V2 === '1',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnvironment({ devMode, testing }) {
|
function getEnvironment({ buildTarget }) {
|
||||||
// get environment slug
|
// get environment slug
|
||||||
if (devMode) {
|
if (isDevBuild(buildTarget)) {
|
||||||
return ENVIRONMENT.DEVELOPMENT;
|
return ENVIRONMENT.DEVELOPMENT;
|
||||||
} else if (testing) {
|
} else if (isTestBuild(buildTarget)) {
|
||||||
return ENVIRONMENT.TESTING;
|
return ENVIRONMENT.TESTING;
|
||||||
} else if (process.env.CIRCLE_BRANCH === 'master') {
|
} else if (process.env.CIRCLE_BRANCH === 'master') {
|
||||||
return ENVIRONMENT.PRODUCTION;
|
return ENVIRONMENT.PRODUCTION;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user