2020-02-20 22:27:33 +03:00
|
|
|
/**
|
2023-09-16 02:49:41 +03:00
|
|
|
* @license
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2020-02-20 22:27:33 +03:00
|
|
|
*/
|
|
|
|
|
2023-07-15 01:32:02 +03:00
|
|
|
import esbuild from 'esbuild';
|
2022-05-07 01:24:53 +03:00
|
|
|
|
2023-07-15 01:32:02 +03:00
|
|
|
import * as plugins from './esbuild-plugins.js';
|
2023-09-06 01:04:35 +03:00
|
|
|
import {LH_ROOT} from '../shared/root.js';
|
2023-07-15 01:32:02 +03:00
|
|
|
import {nodeModulesPolyfillPlugin} from '../third-party/esbuild-plugins-polyfills/esbuild-polyfills.js';
|
2020-02-20 22:27:33 +03:00
|
|
|
|
2021-07-01 00:23:30 +03:00
|
|
|
const distDir = `${LH_ROOT}/dist`;
|
2020-02-20 22:27:33 +03:00
|
|
|
const bundleOutFile = `${distDir}/smokehouse-bundle.js`;
|
2022-07-29 23:55:41 +03:00
|
|
|
const smokehouseLibFilename = './cli/test/smokehouse/frontends/lib.js';
|
|
|
|
const smokehouseCliFilename = `${LH_ROOT}/cli/test/smokehouse/lighthouse-runners/cli.js`;
|
2020-02-20 22:27:33 +03:00
|
|
|
|
2022-06-10 20:23:08 +03:00
|
|
|
async function main() {
|
2023-07-15 01:32:02 +03:00
|
|
|
await esbuild.build({
|
|
|
|
entryPoints: [smokehouseLibFilename],
|
|
|
|
outfile: bundleOutFile,
|
|
|
|
format: 'cjs',
|
|
|
|
bundle: true,
|
2021-09-15 02:15:36 +03:00
|
|
|
plugins: [
|
2023-07-15 01:32:02 +03:00
|
|
|
plugins.replaceModules({
|
2021-10-12 23:33:25 +03:00
|
|
|
[smokehouseCliFilename]:
|
|
|
|
'export function runLighthouse() { throw new Error("not supported"); }',
|
2022-07-14 02:14:27 +03:00
|
|
|
'module': `
|
|
|
|
export const createRequire = () => {
|
|
|
|
return {
|
|
|
|
resolve() {
|
|
|
|
throw new Error('createRequire.resolve is not supported in bundled Lighthouse');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
`,
|
2023-07-15 01:32:02 +03:00
|
|
|
// Our node modules polyfill plugin does not support assert/strict.
|
|
|
|
'assert/strict': `
|
|
|
|
import assert from 'assert';
|
|
|
|
export default assert;
|
|
|
|
`,
|
2021-10-12 23:33:25 +03:00
|
|
|
}),
|
2023-07-15 01:32:02 +03:00
|
|
|
plugins.bulkLoader([
|
|
|
|
plugins.partialLoaders.inlineFs({verbose: Boolean(process.env.DEBUG)}),
|
|
|
|
plugins.partialLoaders.rmGetModuleDirectory,
|
|
|
|
]),
|
|
|
|
nodeModulesPolyfillPlugin(),
|
|
|
|
plugins.ignoreBuiltins(),
|
2021-09-15 02:15:36 +03:00
|
|
|
],
|
2020-02-20 22:27:33 +03:00
|
|
|
});
|
2021-09-15 02:15:36 +03:00
|
|
|
}
|
|
|
|
|
2022-06-10 20:23:08 +03:00
|
|
|
await main();
|