config.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*
  2. * Copyright 2010-2020 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * The code in this file is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU Affero General Public License
  9. * (GNU AGPL) as published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * The code in this file is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  15. * General Public License for more details.
  16. *
  17. * As additional permission under GNU AGPL version 3 section 7, you may
  18. * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
  19. * AGPL normally required by section 4, provided you include this license
  20. * notice and a URL through which recipients can access the Corresponding
  21. * Source.
  22. */
  23. /* global browser, navigator, URL, Blob */
  24. import { download } from "./download-util.js";
  25. import * as tabsData from "./tabs-data.js";
  26. const CURRENT_PROFILE_NAME = "-";
  27. const DEFAULT_PROFILE_NAME = "__Default_Settings__";
  28. const DISABLED_PROFILE_NAME = "__Disabled_Settings__";
  29. const REGEXP_RULE_PREFIX = "regexp:";
  30. const IS_NOT_SAFARI = !/Safari/.test(navigator.userAgent) || /Chrome/.test(navigator.userAgent) || /Vivaldi/.test(navigator.userAgent) || /OPR/.test(navigator.userAgent);
  31. const BACKGROUND_SAVE_SUPPORTED = !(/Mobile.*Firefox/.test(navigator.userAgent) || /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/Vivaldi/.test(navigator.userAgent) && !/OPR/.test(navigator.userAgent));
  32. const BADGE_COLOR_SUPPORTED = IS_NOT_SAFARI;
  33. const AUTO_SAVE_SUPPORTED = IS_NOT_SAFARI;
  34. const SELECTABLE_TABS_SUPPORTED = IS_NOT_SAFARI;
  35. const AUTO_OPEN_EDITOR_SUPPORTED = IS_NOT_SAFARI;
  36. const OPEN_SAVED_PAGE_SUPPORTED = IS_NOT_SAFARI;
  37. const INFOBAR_SUPPORTED = IS_NOT_SAFARI;
  38. const BOOKMARKS_API_SUPPORTED = IS_NOT_SAFARI;
  39. const IDENTITY_API_SUPPORTED = IS_NOT_SAFARI;
  40. const CLIPBOARD_API_SUPPORTED = IS_NOT_SAFARI;
  41. const NATIVE_API_API_SUPPORTED = IS_NOT_SAFARI;
  42. const WEB_BLOCKING_API_SUPPORTED = IS_NOT_SAFARI;
  43. const DEFAULT_CONFIG = {
  44. removeHiddenElements: true,
  45. removeUnusedStyles: true,
  46. removeUnusedFonts: true,
  47. removeFrames: false,
  48. compressHTML: true,
  49. compressCSS: false,
  50. loadDeferredImages: true,
  51. loadDeferredImagesMaxIdleTime: 1500,
  52. loadDeferredImagesBlockCookies: false,
  53. loadDeferredImagesBlockStorage: false,
  54. loadDeferredImagesKeepZoomLevel: false,
  55. loadDeferredImagesDispatchScrollEvent: false,
  56. loadDeferredImagesBeforeFrames: false,
  57. filenameTemplate: "{page-title} ({date-locale} {time-locale}).html",
  58. infobarTemplate: "",
  59. includeInfobar: false,
  60. confirmInfobarContent: false,
  61. autoClose: false,
  62. confirmFilename: false,
  63. filenameConflictAction: "uniquify",
  64. filenameMaxLength: 192,
  65. filenameMaxLengthUnit: "bytes",
  66. filenameReplacedCharacters: ["~", "+", "\\\\", "?", "%", "*", ":", "|", "\"", "<", ">", "\x00-\x1f", "\x7F"],
  67. filenameReplacementCharacter: "_",
  68. replaceEmojisInFilename: false,
  69. contextMenuEnabled: true,
  70. tabMenuEnabled: true,
  71. browserActionMenuEnabled: true,
  72. shadowEnabled: true,
  73. logsEnabled: true,
  74. progressBarEnabled: true,
  75. maxResourceSizeEnabled: false,
  76. maxResourceSize: 10,
  77. displayInfobar: true,
  78. displayStats: false,
  79. backgroundSave: BACKGROUND_SAVE_SUPPORTED,
  80. defaultEditorMode: "normal",
  81. applySystemTheme: true,
  82. autoSaveDelay: 1,
  83. autoSaveLoad: false,
  84. autoSaveUnload: false,
  85. autoSaveLoadOrUnload: true,
  86. autoSaveDiscard: false,
  87. autoSaveRemove: false,
  88. autoSaveRepeat: false,
  89. autoSaveRepeatDelay: 10,
  90. removeAlternativeFonts: true,
  91. removeAlternativeMedias: true,
  92. removeAlternativeImages: true,
  93. groupDuplicateImages: true,
  94. maxSizeDuplicateImages: 512 * 1024,
  95. saveRawPage: false,
  96. saveToClipboard: false,
  97. addProof: false,
  98. saveToGDrive: false,
  99. saveWithWebDAV: false,
  100. webDAVURL: "",
  101. webDAVUser: "",
  102. webDAVPassword: "",
  103. saveToGitHub: false,
  104. githubToken: "",
  105. githubUser: "",
  106. githubRepository: "SingleFile-Archives",
  107. githubBranch: "main",
  108. saveWithCompanion: false,
  109. forceWebAuthFlow: false,
  110. resolveFragmentIdentifierURLs: false,
  111. userScriptEnabled: false,
  112. openEditor: false,
  113. openSavedPage: false,
  114. autoOpenEditor: false,
  115. saveCreatedBookmarks: false,
  116. allowedBookmarkFolders: [],
  117. ignoredBookmarkFolders: [],
  118. replaceBookmarkURL: true,
  119. saveFavicon: true,
  120. includeBOM: false,
  121. warnUnsavedPage: true,
  122. autoSaveExternalSave: false,
  123. insertMetaNoIndex: false,
  124. insertMetaCSP: true,
  125. passReferrerOnError: false,
  126. insertSingleFileComment: true,
  127. removeSavedDate: false,
  128. blockMixedContent: false,
  129. saveOriginalURLs: false,
  130. acceptHeaders: {
  131. font: "application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8",
  132. image: "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
  133. stylesheet: "text/css,*/*;q=0.1",
  134. script: "*/*",
  135. document: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  136. video: "video/webm,video/ogg,video/*;q=0.9,application/ogg;q=0.7,audio/*;q=0.6,*/*;q=0.5",
  137. audio: "audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5"
  138. },
  139. moveStylesInHead: false,
  140. networkTimeout: 0,
  141. woleetKey: "",
  142. blockImages: false,
  143. blockStylesheets: false,
  144. blockFonts: false,
  145. blockScripts: true,
  146. blockVideos: true,
  147. blockAudios: true
  148. };
  149. const DEFAULT_RULES = [{
  150. "url": "file:",
  151. "profile": "__Default_Settings__",
  152. "autoSaveProfile": "__Disabled_Settings__"
  153. }];
  154. let configStorage;
  155. let pendingUpgradePromise = upgrade();
  156. export {
  157. DEFAULT_PROFILE_NAME,
  158. DISABLED_PROFILE_NAME,
  159. CURRENT_PROFILE_NAME,
  160. BACKGROUND_SAVE_SUPPORTED,
  161. BADGE_COLOR_SUPPORTED,
  162. AUTO_SAVE_SUPPORTED,
  163. SELECTABLE_TABS_SUPPORTED,
  164. OPEN_SAVED_PAGE_SUPPORTED,
  165. AUTO_OPEN_EDITOR_SUPPORTED,
  166. INFOBAR_SUPPORTED,
  167. BOOKMARKS_API_SUPPORTED,
  168. IDENTITY_API_SUPPORTED,
  169. CLIPBOARD_API_SUPPORTED,
  170. NATIVE_API_API_SUPPORTED,
  171. WEB_BLOCKING_API_SUPPORTED,
  172. getConfig as get,
  173. getRule,
  174. getOptions,
  175. getProfiles,
  176. onMessage,
  177. updateRule,
  178. addRule,
  179. getAuthInfo,
  180. setAuthInfo,
  181. removeAuthInfo
  182. };
  183. async function upgrade() {
  184. const { sync } = await browser.storage.local.get();
  185. if (sync) {
  186. configStorage = browser.storage.sync;
  187. } else {
  188. configStorage = browser.storage.local;
  189. }
  190. const config = await configStorage.get();
  191. if (!config.profiles) {
  192. const defaultConfig = config;
  193. delete defaultConfig.tabsData;
  194. applyUpgrade(defaultConfig);
  195. const newConfig = { profiles: {}, rules: DEFAULT_RULES };
  196. newConfig.profiles[DEFAULT_PROFILE_NAME] = defaultConfig;
  197. configStorage.remove(Object.keys(DEFAULT_CONFIG));
  198. await configStorage.set(newConfig);
  199. } else {
  200. if (!config.rules) {
  201. config.rules = DEFAULT_RULES;
  202. }
  203. Object.keys(config.profiles).forEach(profileName => applyUpgrade(config.profiles[profileName]));
  204. await configStorage.remove(["profiles", "rules"]);
  205. await configStorage.set({ profiles: config.profiles, rules: config.rules });
  206. }
  207. if (!config.maxParallelWorkers) {
  208. await configStorage.set({ maxParallelWorkers: navigator.hardwareConcurrency || 4 });
  209. }
  210. }
  211. function applyUpgrade(config) {
  212. upgradeOldConfig(config, "blockScripts", "removeScripts");
  213. upgradeOldConfig(config, "blockVideos", "removeVideoSrc");
  214. upgradeOldConfig(config, "blockAudios", "removeAudioSrc");
  215. Object.keys(DEFAULT_CONFIG).forEach(configKey => upgradeConfig(config, configKey));
  216. }
  217. function upgradeOldConfig(config, newKey, oldKey) { // eslint-disable-line no-unused-vars
  218. if (config[newKey] === undefined && config[oldKey] !== undefined) {
  219. config[newKey] = config[oldKey];
  220. delete config[oldKey];
  221. }
  222. }
  223. function upgradeConfig(config, key) {
  224. if (config[key] === undefined) {
  225. config[key] = DEFAULT_CONFIG[key];
  226. }
  227. }
  228. async function getRule(url, ignoreWildcard) {
  229. const config = await getConfig();
  230. const regExpRules = config.rules.filter(rule => testRegExpRule(rule));
  231. let rule = regExpRules.sort(sortRules).find(rule => url && url.match(new RegExp(rule.url.split(REGEXP_RULE_PREFIX)[1])));
  232. if (!rule) {
  233. const normalRules = config.rules.filter(rule => !testRegExpRule(rule));
  234. rule = normalRules.sort(sortRules).find(rule => (!ignoreWildcard && rule.url == "*") || (url && url.includes(rule.url)));
  235. }
  236. return rule;
  237. }
  238. async function getConfig() {
  239. await pendingUpgradePromise;
  240. return configStorage.get(["profiles", "rules", "maxParallelWorkers"]);
  241. }
  242. function sortRules(ruleLeft, ruleRight) {
  243. return ruleRight.url.length - ruleLeft.url.length;
  244. }
  245. function testRegExpRule(rule) {
  246. return rule.url.toLowerCase().startsWith(REGEXP_RULE_PREFIX);
  247. }
  248. async function onMessage(message) {
  249. if (message.method.endsWith(".deleteRules")) {
  250. await deleteRules(message.profileName);
  251. }
  252. if (message.method.endsWith(".deleteRule")) {
  253. await deleteRule(message.url);
  254. }
  255. if (message.method.endsWith(".addRule")) {
  256. await addRule(message.url, message.profileName, message.autoSaveProfileName);
  257. }
  258. if (message.method.endsWith(".createProfile")) {
  259. await createProfile(message.profileName, message.fromProfileName || DEFAULT_PROFILE_NAME);
  260. }
  261. if (message.method.endsWith(".renameProfile")) {
  262. await renameProfile(message.profileName, message.newProfileName);
  263. }
  264. if (message.method.endsWith(".deleteProfile")) {
  265. await deleteProfile(message.profileName);
  266. }
  267. if (message.method.endsWith(".resetProfiles")) {
  268. await resetProfiles();
  269. }
  270. if (message.method.endsWith(".resetProfile")) {
  271. await resetProfile(message.profileName);
  272. }
  273. if (message.method.endsWith(".importConfig")) {
  274. await importConfig(message.config);
  275. }
  276. if (message.method.endsWith(".updateProfile")) {
  277. await updateProfile(message.profileName, message.profile);
  278. }
  279. if (message.method.endsWith(".updateRule")) {
  280. await updateRule(message.url, message.newUrl, message.profileName, message.autoSaveProfileName);
  281. }
  282. if (message.method.endsWith(".getConstants")) {
  283. return {
  284. DISABLED_PROFILE_NAME,
  285. DEFAULT_PROFILE_NAME,
  286. CURRENT_PROFILE_NAME,
  287. BACKGROUND_SAVE_SUPPORTED,
  288. BADGE_COLOR_SUPPORTED,
  289. AUTO_SAVE_SUPPORTED,
  290. SELECTABLE_TABS_SUPPORTED,
  291. OPEN_SAVED_PAGE_SUPPORTED,
  292. AUTO_OPEN_EDITOR_SUPPORTED,
  293. INFOBAR_SUPPORTED,
  294. BOOKMARKS_API_SUPPORTED,
  295. IDENTITY_API_SUPPORTED,
  296. CLIPBOARD_API_SUPPORTED,
  297. NATIVE_API_API_SUPPORTED,
  298. WEB_BLOCKING_API_SUPPORTED
  299. };
  300. }
  301. if (message.method.endsWith(".getRules")) {
  302. return getRules();
  303. }
  304. if (message.method.endsWith(".getProfiles")) {
  305. return getProfiles();
  306. }
  307. if (message.method.endsWith(".exportConfig")) {
  308. return exportConfig();
  309. }
  310. if (message.method.endsWith(".enableSync")) {
  311. await browser.storage.local.set({ sync: true });
  312. const syncConfig = await browser.storage.sync.get();
  313. if (!syncConfig || !syncConfig.profiles) {
  314. const localConfig = await browser.storage.local.get();
  315. await browser.storage.sync.set({ profiles: localConfig.profiles, rules: localConfig.rules, maxParallelWorkers: localConfig.maxParallelWorkers });
  316. }
  317. configStorage = browser.storage.sync;
  318. return {};
  319. }
  320. if (message.method.endsWith(".disableSync")) {
  321. await browser.storage.local.set({ sync: false });
  322. const syncConfig = await browser.storage.sync.get();
  323. if (syncConfig && syncConfig.profiles) {
  324. await browser.storage.local.set({ profiles: syncConfig.profiles, rules: syncConfig.rules, maxParallelWorkers: syncConfig.maxParallelWorkers });
  325. }
  326. configStorage = browser.storage.local;
  327. }
  328. if (message.method.endsWith(".isSync")) {
  329. return { sync: (await browser.storage.local.get()).sync };
  330. }
  331. return {};
  332. }
  333. async function createProfile(profileName, fromProfileName) {
  334. const config = await getConfig();
  335. if (Object.keys(config.profiles).includes(profileName)) {
  336. throw new Error("Duplicate profile name");
  337. }
  338. config.profiles[profileName] = JSON.parse(JSON.stringify(config.profiles[fromProfileName]));
  339. await configStorage.set({ profiles: config.profiles });
  340. }
  341. async function getProfiles() {
  342. const config = await getConfig();
  343. return config.profiles;
  344. }
  345. async function getOptions(url, autoSave) {
  346. const [config, rule, allTabsData] = await Promise.all([getConfig(), getRule(url), tabsData.get()]);
  347. const tabProfileName = allTabsData.profileName || DEFAULT_PROFILE_NAME;
  348. let selectedProfileName;
  349. if (rule) {
  350. const profileName = rule[autoSave ? "autoSaveProfile" : "profile"];
  351. selectedProfileName = profileName == CURRENT_PROFILE_NAME ? tabProfileName : profileName;
  352. } else {
  353. selectedProfileName = tabProfileName;
  354. }
  355. return Object.assign({ profileName: selectedProfileName }, config.profiles[selectedProfileName]);
  356. }
  357. async function updateProfile(profileName, profile) {
  358. const config = await getConfig();
  359. if (!Object.keys(config.profiles).includes(profileName)) {
  360. throw new Error("Profile not found");
  361. }
  362. Object.keys(profile).forEach(key => config.profiles[profileName][key] = profile[key]);
  363. await configStorage.set({ profiles: config.profiles });
  364. }
  365. async function renameProfile(oldProfileName, profileName) {
  366. const [config, allTabsData] = await Promise.all([getConfig(), tabsData.get()]);
  367. if (!Object.keys(config.profiles).includes(oldProfileName)) {
  368. throw new Error("Profile not found");
  369. }
  370. if (Object.keys(config.profiles).includes(profileName)) {
  371. throw new Error("Duplicate profile name");
  372. }
  373. if (oldProfileName == DEFAULT_PROFILE_NAME) {
  374. throw new Error("Default settings cannot be renamed");
  375. }
  376. if (allTabsData.profileName == oldProfileName) {
  377. allTabsData.profileName = profileName;
  378. await tabsData.set(allTabsData);
  379. }
  380. config.profiles[profileName] = config.profiles[oldProfileName];
  381. config.rules.forEach(rule => {
  382. if (rule.profile == oldProfileName) {
  383. rule.profile = profileName;
  384. }
  385. if (rule.autoSaveProfile == oldProfileName) {
  386. rule.autoSaveProfile = profileName;
  387. }
  388. });
  389. delete config.profiles[oldProfileName];
  390. await configStorage.set({ profiles: config.profiles, rules: config.rules });
  391. }
  392. async function deleteProfile(profileName) {
  393. const [config, allTabsData] = await Promise.all([getConfig(), tabsData.get()]);
  394. if (!Object.keys(config.profiles).includes(profileName)) {
  395. throw new Error("Profile not found");
  396. }
  397. if (profileName == DEFAULT_PROFILE_NAME) {
  398. throw new Error("Default settings cannot be deleted");
  399. }
  400. if (allTabsData.profileName == profileName) {
  401. delete allTabsData.profileName;
  402. await tabsData.set(allTabsData);
  403. }
  404. config.rules.forEach(rule => {
  405. if (rule.profile == profileName) {
  406. rule.profile = DEFAULT_PROFILE_NAME;
  407. }
  408. if (rule.autoSaveProfile == profileName) {
  409. rule.autoSaveProfile = DEFAULT_PROFILE_NAME;
  410. }
  411. });
  412. delete config.profiles[profileName];
  413. await configStorage.set({ profiles: config.profiles, rules: config.rules });
  414. }
  415. async function getRules() {
  416. const config = await getConfig();
  417. return config.rules;
  418. }
  419. async function addRule(url, profile, autoSaveProfile) {
  420. if (!url) {
  421. throw new Error("URL is empty");
  422. }
  423. const config = await getConfig();
  424. if (config.rules.find(rule => rule.url == url)) {
  425. throw new Error("URL already exists");
  426. }
  427. config.rules.push({
  428. url,
  429. profile,
  430. autoSaveProfile
  431. });
  432. await configStorage.set({ rules: config.rules });
  433. }
  434. async function deleteRule(url) {
  435. if (!url) {
  436. throw new Error("URL is empty");
  437. }
  438. const config = await getConfig();
  439. config.rules = config.rules.filter(rule => rule.url != url);
  440. await configStorage.set({ rules: config.rules });
  441. }
  442. async function deleteRules(profileName) {
  443. const config = await getConfig();
  444. config.rules = config.rules = profileName ? config.rules.filter(rule => rule.autoSaveProfile != profileName && rule.profile != profileName) : [];
  445. await configStorage.set({ rules: config.rules });
  446. }
  447. async function updateRule(url, newURL, profile, autoSaveProfile) {
  448. if (!url || !newURL) {
  449. throw new Error("URL is empty");
  450. }
  451. const config = await getConfig();
  452. const urlConfig = config.rules.find(rule => rule.url == url);
  453. if (!urlConfig) {
  454. throw new Error("URL not found");
  455. }
  456. if (config.rules.find(rule => rule.url == newURL && rule.url != url)) {
  457. throw new Error("New URL already exists");
  458. }
  459. urlConfig.url = newURL;
  460. urlConfig.profile = profile;
  461. urlConfig.autoSaveProfile = autoSaveProfile;
  462. await configStorage.set({ rules: config.rules });
  463. }
  464. async function getAuthInfo() {
  465. return (await configStorage.get()).authInfo;
  466. }
  467. async function setAuthInfo(authInfo) {
  468. await configStorage.set({ authInfo });
  469. }
  470. async function removeAuthInfo() {
  471. let authInfo = getAuthInfo();
  472. if (authInfo.revokableAccessToken) {
  473. setAuthInfo({ revokableAccessToken: authInfo.revokableAccessToken });
  474. } else {
  475. await configStorage.remove(["authInfo"]);
  476. }
  477. }
  478. async function resetProfiles() {
  479. await pendingUpgradePromise;
  480. const allTabsData = await tabsData.get();
  481. delete allTabsData.profileName;
  482. await tabsData.set(allTabsData);
  483. await configStorage.remove(["profiles", "rules", "maxParallelWorkers"]);
  484. await browser.storage.local.set({ sync: false });
  485. configStorage = browser.storage.local;
  486. await upgrade();
  487. }
  488. async function resetProfile(profileName) {
  489. const config = await getConfig();
  490. if (!Object.keys(config.profiles).includes(profileName)) {
  491. throw new Error("Profile not found");
  492. }
  493. config.profiles[profileName] = DEFAULT_CONFIG;
  494. await configStorage.set({ profiles: config.profiles });
  495. }
  496. async function exportConfig() {
  497. const config = await getConfig();
  498. const textContent = JSON.stringify({ profiles: config.profiles, rules: config.rules, maxParallelWorkers: config.maxParallelWorkers }, null, 2);
  499. const filename = `singlefile-settings-${(new Date()).toISOString().replace(/:/g, "_")}.json`;
  500. if (IS_NOT_SAFARI) {
  501. const url = URL.createObjectURL(new Blob([textContent], { type: "text/json" }));
  502. try {
  503. await download({
  504. url,
  505. filename,
  506. saveAs: true
  507. }, "_");
  508. } finally {
  509. URL.revokeObjectURL(url);
  510. }
  511. return {};
  512. } else {
  513. return {
  514. filename,
  515. textContent
  516. };
  517. }
  518. }
  519. async function importConfig(config) {
  520. await configStorage.remove(["profiles", "rules", "maxParallelWorkers"]);
  521. await configStorage.set({ profiles: config.profiles, rules: config.rules, maxParallelWorkers: config.maxParallelWorkers });
  522. await upgrade();
  523. }