1
0
Fork 0

Build - refactor background process to use html (#10769)

* build - declare background as html

* build - fill in empty file when a missing file is expected

* lint - fix

* Update development/build/manifest.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* Update development/build/manifest.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
kumavis 2021-03-31 11:12:28 +08:00 committed by GitHub
parent 2dadf4374a
commit 952adbce44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 32 deletions

View File

@ -26,7 +26,7 @@ module.exports = {
'test-*/**',
'docs/**',
'coverage/',
'app/scripts/chromereload.js',
'development/chromereload.js',
'app/vendor/**',
'test/e2e/send-eth-with-private-key-test/**',
'nyc_output/**',

15
app/background.html Normal file
View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
<script src="./initSentry.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown.js" type="text/javascript" charset="utf-8"></script>
<script src="./runLockdown.js" type="text/javascript" charset="utf-8"></script>
<script src="./bg-libs.js" type="text/javascript" charset="utf-8"></script>
<script src="./background.js" type="text/javascript" charset="utf-8"></script>
<script src="./chromereload.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

View File

@ -1,14 +1,7 @@
{
"author": "https://metamask.io",
"background": {
"scripts": [
"globalthis.js",
"initSentry.js",
"lockdown.js",
"runLockdown.js",
"bg-libs.js",
"background.js"
],
"page": "background.html",
"persistent": true
},
"browser_action": {

View File

@ -8,10 +8,6 @@ const { createTask, composeSeries } = require('./task');
module.exports = createManifestTasks;
const scriptsToExcludeFromBackgroundDevBuild = {
'bg-libs.js': true,
};
function createManifestTasks({ browserPlatforms }) {
// merge base manifest with per-platform manifests
const prepPlatforms = async () => {
@ -35,29 +31,13 @@ function createManifestTasks({ browserPlatforms }) {
);
};
// dev: remove bg-libs, add chromereload, add perms
// dev: add perms
const envDev = createTaskForModifyManifestForEnvironment((manifest) => {
const scripts = manifest.background.scripts.filter(
(scriptName) => !scriptsToExcludeFromBackgroundDevBuild[scriptName],
);
scripts.push('chromereload.js');
manifest.background = {
...manifest.background,
scripts,
};
manifest.permissions = [...manifest.permissions, 'webRequestBlocking'];
});
// testDev: remove bg-libs, add perms
// testDev: add perms
const envTestDev = createTaskForModifyManifestForEnvironment((manifest) => {
const scripts = manifest.background.scripts.filter(
(scriptName) => !scriptsToExcludeFromBackgroundDevBuild[scriptName],
);
scripts.push('chromereload.js');
manifest.background = {
...manifest.background,
scripts,
};
manifest.permissions = [
...manifest.permissions,
'webRequestBlocking',

View File

@ -80,13 +80,34 @@ const copyTargetsDev = [
pattern: '/chromereload.js',
dest: ``,
},
// empty files to suppress missing file errors
{
src: './development/',
pattern: '/empty.js',
dest: `bg-libs.js`,
},
{
src: './development/',
pattern: '/empty.js',
dest: `ui-libs.js`,
},
];
const copyTargetsProd = [
...copyTargets,
// empty files to suppress missing file errors
{
src: './development/',
pattern: '/empty.js',
dest: `chromereload.js`,
},
];
function createStaticAssetTasks({ livereload, browserPlatforms }) {
const prod = createTask(
'static:prod',
composeSeries(
...copyTargets.map((target) => {
...copyTargetsProd.map((target) => {
return async function copyStaticAssets() {
await performCopy(target);
};

1
development/empty.js Normal file
View File

@ -0,0 +1 @@
// this file intentionally left blank : )