(/** @type {JSEntry} */entry, platform, debug, watch, log, test)
| 73 | const rollupCache = {}; |
| 74 | |
| 75 | async function bundleJS(/** @type {JSEntry} */entry, platform, debug, watch, log, test) { |
| 76 | const {src, dest} = entry; |
| 77 | |
| 78 | let replace = {}; |
| 79 | switch (platform) { |
| 80 | case PLATFORM.FIREFOX_MV2: |
| 81 | case PLATFORM.THUNDERBIRD: |
| 82 | if (entry.src === 'src/ui/popup/index.tsx') { |
| 83 | break; |
| 84 | } |
| 85 | replace = { |
| 86 | 'chrome.fontSettings.getFontList': `chrome['font' + 'Settings']['get' + 'Font' + 'List']`, |
| 87 | 'chrome.fontSettings': `chrome['font' + 'Settings']`, |
| 88 | }; |
| 89 | break; |
| 90 | case PLATFORM.CHROMIUM_MV3: |
| 91 | replace = { |
| 92 | 'chrome.browserAction.setIcon': 'chrome.action.setIcon', |
| 93 | 'chrome.browserAction.setBadgeBackgroundColor': 'chrome.action.setBadgeBackgroundColor', |
| 94 | 'chrome.browserAction.setBadgeText': 'chrome.action.setBadgeText', |
| 95 | }; |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | // See comment below |
| 100 | // TODO(anton): remove this once Firefox supports tab.eval() via WebDriver BiDi |
| 101 | const mustRemoveEval = !test && (platform === PLATFORM.FIREFOX_MV2) && (entry.src === 'src/inject/index.ts'); |
| 102 | |
| 103 | const cacheId = `${entry.src}-${platform}-${debug}-${watch}-${log}-${test}`; |
| 104 | const outDir = getDestDir({debug, platform}); |
| 105 | |
| 106 | const bundle = await rollup.rollup({ |
| 107 | input: absolutePath(src), |
| 108 | preserveSymlinks: true, |
| 109 | onwarn: (error) => { |
| 110 | // TODO(anton): remove this once Firefox supports tab.eval() via WebDriver BiDi |
| 111 | if (error.code === 'EVAL' && !mustRemoveEval) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | throw error; |
| 116 | }, |
| 117 | plugins: [ |
| 118 | // Firefox WebDriver implementation does not currently support tab.eval() functions fully, |
| 119 | // so we have to manually polyfill it via regular eval(). |
| 120 | // This plugin is necessary to avoid (benign) warnings in the console during builds, it just replaces |
| 121 | // literally one occurrence of eval() in our code even before TypeScript even encounters it. |
| 122 | // With this plugin, warning appears only on Firefox test builds. |
| 123 | // TODO(anton): remove this once Firefox supports tab.eval() via WebDriver BiDi |
| 124 | // @ts-expect-error This expression is not callable |
| 125 | rollupPluginReplace({ |
| 126 | preventAssignment: true, |
| 127 | 'eval(': 'void(', |
| 128 | }), |
| 129 | // @ts-expect-error This expression is not callable |
| 130 | rollupPluginNodeResolve(), |
| 131 | // @ts-expect-error This expression is not callable |
| 132 | rollupPluginTypescript({ |
no test coverage detected