1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/development/build/static.js
Etienne Dusseault 9f6fa64d67
Add SES lockdown to extension webapp (#9729)
* Freezeglobals: remove Promise freezing, add lockdown

* background & UI: temp disable sentry

* add loose-envify, dedupe symbol-observable

* use loose envify

* add symbol-observable patch

* run freezeGlobals after sentry init

* use require instead of import

* add lockdown to contentscript

* add error code in message

* try increasing node env heap size to 2048

* change back circe CI option

* make freezeGlobals an exported function

* make freezeGlobals an exported function

* use freezeIntrinsics

* pass down env to child process

* fix unknown module

* fix tests

* change back to 2048

* fix import error

* attempt to fix memory error

* fix lint

* fix lint

* fix mem gain

* use lockdown in phishing detect

* fix lint

* move sentry init into freezeIntrinsics to run lockdown before other imports

* lint fix

* custom lockdown modules per context

* lint fix

* fix global test

* remove run in child process

* remove lavamoat-core, use ses, require lockdown directly

* revert childprocess

* patch package postinstall

* revert back child process

* add postinstall to ci

* revert node max space size to 1024

* put back loose-envify

* Disable sentry to see if e2e tetss pass

* use runLockdown, add as script in manifest

* remove global and require from runlockdown

* add more memory to tests

* upgrade resource class for prep-build & prep-build-test

* fix lint

* lint fix

* upgrade remote-redux-devtools

* skillfully re-add sentry

* lintfix

* fix lint

* put back beep

* remove envify, add loose-envify and patch-package in dev deps

* Replace patch with Yarn resolution (#9923)

Instead of patching `symbol-observable`, this ensures that all
versions of `symbol-observable` are resolved to the given range, even
if it contradicts the requested range.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-11-24 11:26:43 +08:00

145 lines
3.0 KiB
JavaScript

const path = require('path')
const fs = require('fs-extra')
const watch = require('gulp-watch')
const glob = require('fast-glob')
const locales = require('../../app/_locales/index.json')
const { createTask, composeSeries } = require('./task')
module.exports = createStaticAssetTasks
const copyTargets = [
{
src: `./app/_locales/`,
dest: `_locales`,
},
{
src: `./app/images/`,
dest: `images`,
},
{
src: `./node_modules/eth-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/app/css/output/`,
pattern: `*.css`,
dest: ``,
},
{
src: `./app/`,
pattern: `*.html`,
dest: ``,
},
{
src: `./node_modules/ses/dist/`,
pattern: `lockdown.cjs`,
dest: ``,
},
{
src: `./app/scripts/`,
pattern: `runLockdown.js`,
dest: ``,
},
]
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: './app/scripts/',
pattern: '/chromereload.js',
dest: ``,
},
]
function createStaticAssetTasks({ livereload, browserPlatforms }) {
const prod = createTask(
'static:prod',
composeSeries(
...copyTargets.map((target) => {
return async function copyStaticAssets() {
await performCopy(target)
}
}),
),
)
const dev = createTask(
'static:dev',
composeSeries(
...copyTargetsDev.map((target) => {
return async function copyStaticAssets() {
await setupLiveCopy(target)
}
}),
),
)
return { dev, prod }
async function setupLiveCopy(target) {
const pattern = target.pattern || '/**/*'
watch(target.src + pattern, (event) => {
livereload.changed(event.path)
performCopy(target)
})
await performCopy(target)
}
async function performCopy(target) {
await Promise.all(
browserPlatforms.map(async (platform) => {
if (target.pattern) {
await copyGlob(
target.src,
`${target.src}${target.pattern}`,
`./dist/${platform}/${target.dest}`,
)
} else {
await copyGlob(
target.src,
`${target.src}`,
`./dist/${platform}/${target.dest}`,
)
}
}),
)
}
async function copyGlob(baseDir, srcGlob, dest) {
const sources = await glob(srcGlob, { onlyFiles: false })
await Promise.all(
sources.map(async (src) => {
const relativePath = path.relative(baseDir, src)
await fs.copy(src, `${dest}${relativePath}`)
}),
)
}
}