Allow excluding lockdown at build time (#11937)

This adds an `--omit-lockdown` flag to our build script, which will cause SES `lockdown` to be omitted from the resulting bundle. Useful for development when we don't want the environment to be locked down.

Thanks to @kumavis for the suggestion.
feature/default_network_editable
Erik Marks 3 years ago committed by GitHub
parent 48c5c07ded
commit 290fcbf89e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      development/build/index.js
  2. 206
      development/build/static.js

@ -28,12 +28,17 @@ require('@babel/preset-react');
require('@babel/core'); require('@babel/core');
const browserPlatforms = ['firefox', 'chrome', 'brave', 'opera']; const browserPlatforms = ['firefox', 'chrome', 'brave', 'opera'];
const shouldIncludeLockdown = !process.argv.includes('--omit-lockdown');
defineAllTasks(); defineAllTasks();
detectAndRunEntryTask(); detectAndRunEntryTask();
function defineAllTasks() { function defineAllTasks() {
const staticTasks = createStaticAssetTasks({ livereload, browserPlatforms }); const staticTasks = createStaticAssetTasks({
livereload,
browserPlatforms,
shouldIncludeLockdown,
});
const manifestTasks = createManifestTasks({ browserPlatforms }); const manifestTasks = createManifestTasks({ browserPlatforms });
const styleTasks = createStyleTasks({ livereload }); const styleTasks = createStyleTasks({ livereload });
const scriptTasks = createScriptTasks({ livereload, browserPlatforms }); const scriptTasks = createScriptTasks({ livereload, browserPlatforms });

@ -7,103 +7,17 @@ const locales = require('../../app/_locales/index.json');
const { createTask, composeSeries } = require('./task'); const { createTask, composeSeries } = require('./task');
module.exports = createStaticAssetTasks; const EMPTY_JS_FILE = './development/empty.js';
const copyTargets = [ module.exports = function createStaticAssetTasks({
{ livereload,
src: `./app/_locales/`, browserPlatforms,
dest: `_locales`, shouldIncludeLockdown = true,
}, }) {
{ const [copyTargetsProd, copyTargetsDev] = getCopyTargets(
src: `./app/images/`, shouldIncludeLockdown,
dest: `images`, );
},
{
src: `./node_modules/@metamask/contract-metadata/images/`,
dest: `images/contract`,
},
{
src: `./app/fonts/`,
dest: `fonts`,
},
{
src: `./app/vendor/`,
dest: `vendor`,
},
{
src: `./node_modules/@fortawesome/fontawesome-free/webfonts/`,
dest: `fonts/fontawesome`,
},
{
src: `./ui/css/output/`,
pattern: `*.css`,
dest: ``,
},
{
src: `./app/loading.html`,
dest: `loading.html`,
},
{
src: `./node_modules/globalthis/dist/browser.js`,
dest: `globalthis.js`,
},
{
src: `./node_modules/ses/dist/lockdown.umd.min.js`,
dest: `lockdown-install.js`,
},
{
src: `./app/scripts/lockdown-run.js`,
dest: `lockdown-run.js`,
},
{
// eslint-disable-next-line node/no-extraneous-require
src: require.resolve('@lavamoat/lavapack/src/runtime-cjs.js'),
dest: `runtime-cjs.js`,
},
];
const languageTags = new Set();
for (const locale of locales) {
const { code } = locale;
const tag = code.split('_')[0];
languageTags.add(tag);
}
for (const tag of languageTags) {
copyTargets.push({
src: `./node_modules/@formatjs/intl-relativetimeformat/dist/locale-data/${tag}.json`,
dest: `intl/${tag}/relative-time-format-data.json`,
});
}
const copyTargetsDev = [
...copyTargets,
{
src: './development',
pattern: '/chromereload.js',
dest: ``,
},
// empty files to suppress missing file errors
{
src: './development/empty.js',
dest: `bg-libs.js`,
},
{
src: './development/empty.js',
dest: `ui-libs.js`,
},
];
const copyTargetsProd = [
...copyTargets,
// empty files to suppress missing file errors
{
src: './development/empty.js',
dest: `chromereload.js`,
},
];
function createStaticAssetTasks({ livereload, browserPlatforms }) {
const prod = createTask( const prod = createTask(
'static:prod', 'static:prod',
composeSeries( composeSeries(
@ -165,4 +79,106 @@ function createStaticAssetTasks({ livereload, browserPlatforms }) {
}), }),
); );
} }
};
function getCopyTargets(shouldIncludeLockdown) {
const allCopyTargets = [
{
src: `./app/_locales/`,
dest: `_locales`,
},
{
src: `./app/images/`,
dest: `images`,
},
{
src: `./node_modules/@metamask/contract-metadata/images/`,
dest: `images/contract`,
},
{
src: `./app/fonts/`,
dest: `fonts`,
},
{
src: `./app/vendor/`,
dest: `vendor`,
},
{
src: `./node_modules/@fortawesome/fontawesome-free/webfonts/`,
dest: `fonts/fontawesome`,
},
{
src: `./ui/css/output/`,
pattern: `*.css`,
dest: ``,
},
{
src: `./app/loading.html`,
dest: `loading.html`,
},
{
src: `./node_modules/globalthis/dist/browser.js`,
dest: `globalthis.js`,
},
{
src: shouldIncludeLockdown
? `./node_modules/ses/dist/lockdown.umd.min.js`
: EMPTY_JS_FILE,
dest: `lockdown-install.js`,
},
{
src: shouldIncludeLockdown
? `./app/scripts/lockdown-run.js`
: EMPTY_JS_FILE,
dest: `lockdown-run.js`,
},
{
// eslint-disable-next-line node/no-extraneous-require
src: require.resolve('@lavamoat/lavapack/src/runtime-cjs.js'),
dest: `runtime-cjs.js`,
},
];
const languageTags = new Set();
for (const locale of locales) {
const { code } = locale;
const tag = code.split('_')[0];
languageTags.add(tag);
}
for (const tag of languageTags) {
allCopyTargets.push({
src: `./node_modules/@formatjs/intl-relativetimeformat/dist/locale-data/${tag}.json`,
dest: `intl/${tag}/relative-time-format-data.json`,
});
}
const copyTargetsDev = [
...allCopyTargets,
{
src: './development',
pattern: '/chromereload.js',
dest: ``,
},
// empty files to suppress missing file errors
{
src: EMPTY_JS_FILE,
dest: `bg-libs.js`,
},
{
src: EMPTY_JS_FILE,
dest: `ui-libs.js`,
},
];
const copyTargetsProd = [
...allCopyTargets,
// empty files to suppress missing file errors
{
src: EMPTY_JS_FILE,
dest: `chromereload.js`,
},
];
return [copyTargetsProd, copyTargetsDev];
} }

Loading…
Cancel
Save