1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

MV3: Fix dynamic file list injection on service worker reload (#14795)

This commit is contained in:
Jyoti Puri 2022-06-15 20:27:51 +05:30 committed by GitHub
parent 25aa3ab4b4
commit d8e1961fd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -48,8 +48,3 @@ function importAllScripts() {
// Placing script import call here ensures that scripts are inported each time service worker is activated. // Placing script import call here ensures that scripts are inported each time service worker is activated.
importAllScripts(); importAllScripts();
/**
* An open issue is changes in this file break during hot reloading. Reason is dynamic injection of "FILE NAMES".
* Developers need to restart local server if they change this file.
*/

View File

@ -365,6 +365,15 @@ function createScriptTasks({
} }
} }
const postProcessServiceWorker = (mv3BrowserPlatforms, fileList) => {
mv3BrowserPlatforms.forEach((browser) => {
const appInitFile = `./dist/${browser}/app-init.js`;
const fileContent = readFileSync('./app/scripts/app-init.js', 'utf8');
const fileOutput = fileContent.replace('/** FILE NAMES */', fileList);
writeFileSync(appInitFile, fileOutput);
});
};
// Function generates app-init.js for browsers chrome, brave and opera. // Function generates app-init.js for browsers chrome, brave and opera.
// It dynamically injects list of files generated in the build. // It dynamically injects list of files generated in the build.
async function bundleMV3AppInitialiser({ async function bundleMV3AppInitialiser({
@ -400,12 +409,17 @@ async function bundleMV3AppInitialiser({
shouldLintFenceFiles, shouldLintFenceFiles,
})(); })();
mv3BrowserPlatforms.forEach((browser) => { postProcessServiceWorker(mv3BrowserPlatforms, fileList);
const appInitFile = `./dist/${browser}/app-init.js`;
const fileContent = readFileSync('./app/scripts/app-init.js', 'utf8'); let prevChromeFileContent;
const fileOutput = fileContent.replace('/** FILE NAMES */', fileList); watch('./dist/chrome/app-init.js', () => {
writeFileSync(appInitFile, fileOutput); const chromeFileContent = readFileSync('./dist/chrome/app-init.js', 'utf8');
if (chromeFileContent !== prevChromeFileContent) {
prevChromeFileContent = chromeFileContent;
postProcessServiceWorker(mv3BrowserPlatforms, fileList);
}
}); });
console.log(`Bundle end: service worker app-init.js`); console.log(`Bundle end: service worker app-init.js`);
} }