|
9 | 9 | * in the browser (as long as they have access to a debugger protocol Connection). |
10 | 10 | */ |
11 | 11 |
|
12 | | -import fs from 'fs'; |
13 | 12 | import path from 'path'; |
14 | 13 | import {execSync} from 'child_process'; |
15 | 14 | import {createRequire} from 'module'; |
@@ -159,6 +158,10 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) { |
159 | 158 | // Because of page-functions! |
160 | 159 | keepNames: true, |
161 | 160 | inject: ['./build/process-global.js'], |
| 161 | + alias: { |
| 162 | + 'debug': require.resolve('debug/src/browser.js'), |
| 163 | + 'lighthouse-logger': require.resolve('../lighthouse-logger/index.js'), |
| 164 | + }, |
162 | 165 | /** @type {esbuild.Plugin[]} */ |
163 | 166 | plugins: [ |
164 | 167 | plugins.replaceModules({ |
@@ -203,66 +206,7 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) { |
203 | 206 | 'import.meta': (id) => `{url: '${path.relative(LH_ROOT, id)}'}`, |
204 | 207 | }), |
205 | 208 | ]), |
206 | | - { |
207 | | - name: 'alias', |
208 | | - setup({onResolve}) { |
209 | | - onResolve({filter: /\.*/}, (args) => { |
210 | | - /** @type {Record<string, string>} */ |
211 | | - const entries = { |
212 | | - 'debug': require.resolve('debug/src/browser.js'), |
213 | | - 'lighthouse-logger': require.resolve('../lighthouse-logger/index.js'), |
214 | | - }; |
215 | | - if (args.path in entries) { |
216 | | - return {path: entries[args.path]}; |
217 | | - } |
218 | | - }); |
219 | | - }, |
220 | | - }, |
221 | | - { |
222 | | - name: 'postprocess', |
223 | | - setup({onEnd}) { |
224 | | - onEnd(async (result) => { |
225 | | - if (result.errors.length) { |
226 | | - return; |
227 | | - } |
228 | | - |
229 | | - const codeFile = result.outputFiles?.find(file => file.path.endsWith('.js')); |
230 | | - const mapFile = result.outputFiles?.find(file => file.path.endsWith('.js.map')); |
231 | | - if (!codeFile) { |
232 | | - throw new Error('missing output'); |
233 | | - } |
234 | | - |
235 | | - // Just make sure the above shimming worked. |
236 | | - let code = codeFile.text; |
237 | | - if (code.includes('inflate_fast')) { |
238 | | - throw new Error('Expected zlib inflate code to have been removed'); |
239 | | - } |
240 | | - |
241 | | - // Get rid of our extra license comments. |
242 | | - // All comments would have been moved to the end of the file, so removing some will not break |
243 | | - // source maps. |
244 | | - // https://stackoverflow.com/a/35923766 |
245 | | - const re = /\/\*\*\s*\n([^*]|(\*(?!\/)))*\*\/\n/g; |
246 | | - let hasSeenFirst = false; |
247 | | - code = code.replace(re, (match) => { |
248 | | - if (match.includes('@license') && match.match(/Lighthouse Authors|Google/)) { |
249 | | - if (hasSeenFirst) { |
250 | | - return ''; |
251 | | - } |
252 | | - |
253 | | - hasSeenFirst = true; |
254 | | - } |
255 | | - |
256 | | - return match; |
257 | | - }); |
258 | | - |
259 | | - await fs.promises.writeFile(codeFile.path, code); |
260 | | - if (mapFile) { |
261 | | - await fs.promises.writeFile(mapFile.path, mapFile.text); |
262 | | - } |
263 | | - }); |
264 | | - }, |
265 | | - }, |
| 209 | + plugins.postprocess({removeExtraLicenses: true}), |
266 | 210 | ], |
267 | 211 | }); |
268 | 212 | } |
|
0 commit comments