misc(build): fix smokehouse bundle (#13135)
This commit is contained in:
Родитель
2faf092f68
Коммит
961626d6d2
|
@ -6,6 +6,8 @@
|
|||
'use strict';
|
||||
|
||||
const browserify = require('browserify');
|
||||
const rollup = require('rollup');
|
||||
const rollupPlugins = require('./rollup-plugins.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const bundleBuilder = require('./build-bundle.js');
|
||||
|
@ -52,11 +54,31 @@ function buildReportGenerator() {
|
|||
});
|
||||
}
|
||||
|
||||
async function buildStaticServerBundle() {
|
||||
const bundle = await rollup.rollup({
|
||||
input: 'lighthouse-cli/test/fixtures/static-server.js',
|
||||
plugins: [
|
||||
rollupPlugins.shim({
|
||||
'es-main': 'export default function() { return false; }',
|
||||
}),
|
||||
rollupPlugins.commonjs(),
|
||||
rollupPlugins.nodeResolve(),
|
||||
],
|
||||
external: ['mime-types', 'glob'],
|
||||
});
|
||||
|
||||
await bundle.write({
|
||||
file: 'dist/lightrider/static-server.js',
|
||||
format: 'commonjs',
|
||||
});
|
||||
}
|
||||
|
||||
async function run() {
|
||||
await Promise.all([
|
||||
buildEntryPoint(),
|
||||
buildReportGenerator(),
|
||||
buildPsiReport(),
|
||||
buildStaticServerBundle(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,19 +12,25 @@ const {LH_ROOT} = require('../root.js');
|
|||
const distDir = `${LH_ROOT}/dist`;
|
||||
const bundleOutFile = `${distDir}/smokehouse-bundle.js`;
|
||||
const smokehouseLibFilename = './lighthouse-cli/test/smokehouse/frontends/lib.js';
|
||||
const smokehouseCliFilename =
|
||||
require.resolve('../lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js');
|
||||
const smokehouseCliFilename = `${LH_ROOT}/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js`;
|
||||
|
||||
async function build() {
|
||||
const bundle = await rollup.rollup({
|
||||
input: smokehouseLibFilename,
|
||||
context: 'globalThis',
|
||||
plugins: [
|
||||
rollupPlugins.nodeResolve(),
|
||||
rollupPlugins.commonjs(),
|
||||
rollupPlugins.shim({
|
||||
[smokehouseCliFilename]: 'export default {}',
|
||||
[smokehouseCliFilename]:
|
||||
'export function runLighthouse() { throw new Error("not supported"); }',
|
||||
}),
|
||||
// TODO(esmodules): brfs does not support es modules.
|
||||
rollupPlugins.brfs({
|
||||
global: true,
|
||||
parserOpts: {ecmaVersion: 12, sourceType: 'module'},
|
||||
}),
|
||||
rollupPlugins.commonjs(),
|
||||
rollupPlugins.nodePolyfills(),
|
||||
rollupPlugins.nodeResolve(),
|
||||
],
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// TODO: brfs doesn't work for ES modules, so this is a stopgap solution
|
||||
// for the present usecases that aren't in esm yet. Will be replaced
|
||||
// with a full-featured inlining plugin soon.
|
||||
|
||||
const path = require('path');
|
||||
const {Readable} = require('stream');
|
||||
// @ts-expect-error - no types.
|
||||
const brfs = require('@wardpeet/brfs');
|
||||
|
||||
const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];
|
||||
|
||||
const rollupBrfs = function rollUpBrfs(options = {}) {
|
||||
return {
|
||||
name: 'brfs',
|
||||
/**
|
||||
* @param {string} code
|
||||
* @param {string} id
|
||||
*/
|
||||
transform(code, id) {
|
||||
const ext = path.extname(id);
|
||||
if (!EXTENSIONS.includes(ext)) {
|
||||
return null;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
let output = '';
|
||||
const src = new Readable();
|
||||
src.push(code);
|
||||
src.push(null);
|
||||
const stream = src.pipe(brfs(id, options));
|
||||
stream.on('data', /** @param {Buffer} data */ function(data) {
|
||||
output += data.toString();
|
||||
});
|
||||
stream.on('end', function() {
|
||||
resolve({
|
||||
code: output,
|
||||
map: {mappings: ''},
|
||||
});
|
||||
});
|
||||
stream.on('error', /** @param {Error} error */ function(error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = rollupBrfs;
|
|
@ -16,6 +16,7 @@ function rollupPluginTypeCoerce(module) {
|
|||
return module;
|
||||
}
|
||||
|
||||
const brfs = require('./rollup-brfs.js');
|
||||
const commonjs = rollupPluginTypeCoerce(require('@rollup/plugin-commonjs'));
|
||||
const nodePolyfills = rollupPluginTypeCoerce(require('rollup-plugin-polyfill-node'));
|
||||
const {nodeResolve} = require('@rollup/plugin-node-resolve');
|
||||
|
@ -26,6 +27,7 @@ const {terser} = require('rollup-plugin-terser');
|
|||
const typescript = rollupPluginTypeCoerce(require('@rollup/plugin-typescript'));
|
||||
|
||||
module.exports = {
|
||||
brfs,
|
||||
commonjs,
|
||||
nodePolyfills,
|
||||
nodeResolve,
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
import fs from 'fs';
|
||||
import {LH_ROOT} from '../../../../../root.js';
|
||||
const fs = require('fs');
|
||||
|
||||
// TODO(esmodules): brfs does not support es modules, and this file needs to be bundlded,
|
||||
// so it is commonjs for now.
|
||||
const mapJson =
|
||||
fs.readFileSync(`${LH_ROOT}/lighthouse-cli/test/fixtures/source-map/script.js.map`, 'utf-8');
|
||||
fs.readFileSync(`${__dirname}/../../../fixtures/source-map/script.js.map`, 'utf-8');
|
||||
const map = JSON.parse(mapJson);
|
||||
|
||||
/**
|
||||
|
@ -41,4 +42,4 @@ const expectations = {
|
|||
},
|
||||
};
|
||||
|
||||
export {expectations};
|
||||
module.exports = {expectations};
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"type": "commonjs",
|
||||
"//": "Preserve commonjs in this directory. Temporary file until converted to type: module"
|
||||
}
|
|
@ -17,4 +17,4 @@ const config = {
|
|||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
module.exports = config;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
"build-extension-firefox": "node ./build/build-extension.js firefox",
|
||||
"build-devtools": "yarn reset-link && node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js",
|
||||
"build-smokehouse-bundle": "node ./build/build-smokehouse-bundle.js",
|
||||
"build-lr": "yarn reset-link && node ./build/build-lightrider-bundles.js && rollup lighthouse-cli/test/fixtures/static-server.js -o dist/lightrider/static-server.js -f commonjs -p commonjs -p node-resolve -e mime-types,glob",
|
||||
"build-lr": "yarn reset-link && node ./build/build-lightrider-bundles.js",
|
||||
"build-pack": "bash build/build-pack.sh",
|
||||
"build-report": "node build/build-report-components.js && yarn eslint --fix report/renderer/components.js && node build/build-report.js",
|
||||
"build-sample-reports": "yarn build-report && node build/build-sample-reports.js",
|
||||
|
|
Загрузка…
Ссылка в новой задаче