Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: convert to ES modules #12702

Merged
merged 86 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
2b9cec9
first pass
connorjclark Jun 4, 2021
e89d095
rollup yum
connorjclark Jun 4, 2021
4e3800b
Merge remote-tracking branch 'origin/master' into esmodules
connorjclark Jun 21, 2021
9b5e303
copy and transform util.js to commonjs
connorjclark Jun 21, 2021
f32562d
tweak
connorjclark Jun 22, 2021
e6bb972
update for cdt
connorjclark Jun 22, 2021
937c710
import
connorjclark Jun 22, 2021
c745cbd
remove some changes
connorjclark Jun 23, 2021
aeea6a8
use render.js for standalone
connorjclark Jun 23, 2021
f34a012
tweak
connorjclark Jun 23, 2021
d24381f
fix tests. defer common entry point.
connorjclark Jun 24, 2021
5c66cfe
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jun 25, 2021
0107c03
report/clients
connorjclark Jun 25, 2021
cc3b98c
terser
connorjclark Jun 25, 2021
18eb5a4
tsignore
connorjclark Jun 25, 2021
0ac3a82
comments
connorjclark Jun 25, 2021
ad0974c
fix viewer
connorjclark Jun 25, 2021
593906b
fix devtools action
connorjclark Jun 25, 2021
3a38115
build: add build step for report
connorjclark Jun 25, 2021
53033c8
mkdir
connorjclark Jun 25, 2021
9b425a0
build that shiz
connorjclark Jun 25, 2021
19e11bb
rm
connorjclark Jun 25, 2021
844d5bf
ohhhh windows
connorjclark Jun 25, 2021
cafef7c
ugh
connorjclark Jun 25, 2021
9073d97
fix viewer
connorjclark Jun 25, 2021
f574fe2
fix collect strings
connorjclark Jun 25, 2021
a66a626
update psi.js
connorjclark Jun 29, 2021
f36cbab
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jun 29, 2021
008c3b0
rm autobuild
connorjclark Jun 29, 2021
aee255b
convert tests
connorjclark Jun 29, 2021
489e1a8
convert report tests
connorjclark Jun 29, 2021
cf5480a
remove global declaring stuff
connorjclark Jun 30, 2021
0ea11ab
fix treemap
connorjclark Jun 30, 2021
6579cce
--experimental-vm-modules
connorjclark Jun 30, 2021
214eb77
yarn jest
connorjclark Jun 30, 2021
91b6926
build report
connorjclark Jun 30, 2021
353c772
dist
connorjclark Jun 30, 2021
fd5128b
Merge remote-tracking branch 'origin/master' into build-report
connorjclark Jun 30, 2021
060eced
fix yarn jest
connorjclark Jun 30, 2021
e1627a8
Merge branch 'build-report' into report-esmodules
connorjclark Jun 30, 2021
bef23c1
yarn build-report
connorjclark Jun 30, 2021
bafdc7e
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jun 30, 2021
5805f34
lol
connorjclark Jun 30, 2021
1340b49
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jun 30, 2021
f1b4351
tweak
connorjclark Jun 30, 2021
7c9d522
only
connorjclark Jun 30, 2021
be94766
tweak roll script
connorjclark Jun 30, 2021
c419c30
tweak
connorjclark Jun 30, 2021
9ec4934
fix dt build
connorjclark Jun 30, 2021
329f09b
fix test
connorjclark Jun 30, 2021
a3bb85a
psi
connorjclark Jun 30, 2021
a8bb6f0
fix yarn test-clients
connorjclark Jul 1, 2021
d78111a
scripts(i18n): support es modules in collect-strings
connorjclark Jul 1, 2021
cd3e92a
more root
connorjclark Jul 2, 2021
258dcaf
fix script tests
connorjclark Jul 2, 2021
7329b3c
Merge branch 'esmodules-collect' into report-esmodules
connorjclark Jul 2, 2021
2e01344
ci
connorjclark Jul 2, 2021
8307eaf
just import
connorjclark Jul 2, 2021
1f386b7
rm
connorjclark Jul 2, 2021
9f50d9d
update
connorjclark Jul 2, 2021
642289b
revertests
connorjclark Jul 2, 2021
3e9f32e
more revert
connorjclark Jul 2, 2021
2a43904
Merge commit '2e013444f7eaf7d3b1249f5166a607274aa7c2c9' into report-e…
connorjclark Jul 2, 2021
a570796
update
connorjclark Jul 2, 2021
6a2bda5
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jul 8, 2021
a4488b4
fix async test
connorjclark Jul 8, 2021
fa1c6dd
yarn jest
connorjclark Jul 8, 2021
f9c508e
copy util again
connorjclark Jul 8, 2021
ebee371
fix for windows
connorjclark Jul 8, 2021
c6a6ef8
tmp no fail fast
connorjclark Jul 9, 2021
0f0fcee
tmp: debuging with runInBand
connorjclark Jul 9, 2021
a983e75
lets get that stacktrace
connorjclark Jul 9, 2021
7f5839e
node crash workaround
connorjclark Jul 9, 2021
3b8f9bb
comment
connorjclark Jul 9, 2021
b73d2c6
update
connorjclark Jul 13, 2021
292d3a8
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jul 13, 2021
46ca260
comment
connorjclark Jul 13, 2021
baf5e55
build: run build-report for vercel deployment
connorjclark Jul 13, 2021
d6d93b9
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jul 13, 2021
b406a6c
Merge branch 'fixnowbuildreport' into report-esmodules
connorjclark Jul 13, 2021
3679313
fix
connorjclark Jul 13, 2021
f9ff110
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jul 13, 2021
c7dfe92
fix standalone bundle
connorjclark Jul 14, 2021
860cb29
Merge remote-tracking branch 'origin/master' into report-esmodules
connorjclark Jul 14, 2021
547afdf
add comment for cdt
connorjclark Jul 15, 2021
88a86fe
fix un upstreamed psi fix
connorjclark Jul 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
- run: yarn test-legacy-javascript
- run: yarn i18n:checks
- run: yarn dogfood-lhci
- run: sh lighthouse-core/scripts/copy-util-commonjs.sh

# Fail if any changes were written to any source files or generated untracked files (ex, from: build/build-cdt-lib.js).
- run: git add -A && git diff --cached --exit-code
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/devtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:

- run: yarn --frozen-lockfile
working-directory: ${{ github.workspace }}/lighthouse
- run: yarn build-report
working-directory: ${{ github.workspace }}/lighthouse
- run: yarn build-devtools
working-directory: ${{ github.workspace }}/lighthouse

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ last-run-results.html
*.artifacts.log
*.ctc.json

report/generated

!lighthouse-core/test/results/artifacts/*.trace.json
!lighthouse-core/test/results/artifacts/*.devtoolslog.json
!lighthouse-core/test/fixtures/artifacts/**/*.trace.json
Expand Down
67 changes: 67 additions & 0 deletions build/build-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @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';

const rollup = require('rollup');
const {terser} = require('rollup-plugin-terser');
// Only needed b/c getFilenamePrefix loads a commonjs module.
const commonjs =
// @ts-expect-error types are wrong.
/** @type {import('rollup-plugin-commonjs').default} */ (require('rollup-plugin-commonjs'));

async function buildStandaloneReport() {
const bundle = await rollup.rollup({
input: 'report/clients/standalone.js',
plugins: [
commonjs(),
terser(),
],
});

await bundle.write({
file: 'report/generated/standalone.js',
format: 'iife',
});
}

async function buildViewerReport() {
const bundle = await rollup.rollup({
input: 'report/clients/viewer.js',
plugins: [
commonjs(),
],
});

await bundle.write({
file: 'dist/viewer-report.js',
format: 'iife',
});
}

async function buildEsModulesBundle() {
const bundle = await rollup.rollup({
input: 'report/clients/bundle.js',
plugins: [
commonjs(),
],
});

await bundle.write({
file: 'dist/report.js',
format: 'esm',
});
}


if (require.main === module) {
buildStandaloneReport();
buildEsModulesBundle();
}

module.exports = {
buildStandaloneReport,
buildViewerReport,
};
5 changes: 4 additions & 1 deletion build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const fs = require('fs');
const browserify = require('browserify');
const GhPagesApp = require('./gh-pages-app.js');
const {minifyFileTransform} = require('./build-utils.js');
const {buildViewerReport} = require('./build-report.js');
const htmlReportAssets = require('../report/report-assets.js');

/**
Expand All @@ -30,6 +31,8 @@ async function run() {
});
});

await buildViewerReport();

const app = new GhPagesApp({
name: 'viewer',
appDir: `${__dirname}/../lighthouse-viewer/app`,
Expand All @@ -43,7 +46,7 @@ async function run() {
],
javascripts: [
await generatorJsPromise,
htmlReportAssets.REPORT_JAVASCRIPT,
fs.readFileSync(__dirname + '/../dist/viewer-report.js', 'utf8'),
fs.readFileSync(require.resolve('idb-keyval/dist/idb-keyval-min.js'), 'utf8'),
{path: 'src/*'},
],
Expand Down
2 changes: 1 addition & 1 deletion build/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Additionally, there are build processes for:
To build the devtools files and roll them into a local checkout of Chromium:

```sh
yarn build-devtools && yarn devtools
yarn devtools
```


Expand Down
1 change: 0 additions & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ echo "Complete the _Release publicity_ tasks documented above"

```sh
git checkout vx.x.x # Checkout the specific version.
yarn build-devtools
yarn devtools ~/src/devtools/devtools-frontend

cd ~/src/devtools/devtools-frontend
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const {isUnderTest} = require('../lib/lh-env.js');
const statistics = require('../lib/statistics.js');
const Util = require('../../report/renderer/util.js');
const Util = require('../util-commonjs.js');

const DEFAULT_PASS = 'defaultPass';

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/resource-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const URL = require('../lib/url-shim.js');
const NetworkRequest = require('../lib/network-request.js');
const MainResource = require('./main-resource.js');
const Budget = require('../config/budget.js');
const Util = require('../../report/renderer/util.js');
const Util = require('../util-commonjs.js');

/** @typedef {{count: number, resourceSize: number, transferSize: number}} ResourceEntry */

Expand Down
5 changes: 1 addition & 4 deletions lighthouse-core/lib/file-namer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@ function getFilenamePrefix(lhr) {
return filenamePrefix.replace(/[/?<>\\:*|"]/g, '-');
}

// don't attempt to export in the browser.
if (typeof module !== 'undefined' && module.exports) {
module.exports = {getFilenamePrefix};
}
module.exports = {getFilenamePrefix};
2 changes: 1 addition & 1 deletion lighthouse-core/lib/url-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* URL shim so we keep our code DRY
*/

const Util = require('../../report/renderer/util.js');
const Util = require('../util-commonjs.js');

/** @typedef {import('./network-request.js')} NetworkRequest */

Expand Down
10 changes: 10 additions & 0 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ class Runner {
assetSaver.saveLhr(lhr, path);
}

// Build report if in local dev env so we don't have to run a watch command.
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
const forHtml = settings.output === 'html' ||
(Array.isArray(settings.output) && settings.output.includes('html'));
if (forHtml && !global.isDevtools && !global.isLightrider &&
fs.existsSync('dist') && fs.existsSync('.git')) {
// Prevent bundling.
const buildReportPath = '../build/build-report.js';
await require(buildReportPath).buildStandaloneReport();
}

// Create the HTML, JSON, and/or CSV string
const report = generateReport(lhr, settings.output);

Expand Down
18 changes: 18 additions & 0 deletions lighthouse-core/scripts/copy-util-commonjs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

##
# @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.
##

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LH_ROOT_DIR="$SCRIPT_DIR/../.."

OUT_FILE="$LH_ROOT_DIR"/lighthouse-core/util-commonjs.js

echo '// @ts-nocheck' > "$OUT_FILE"
echo '// Auto-generated by lighthouse-core/scripts/copy-util-commonjs.sh' >> "$OUT_FILE"
echo '// Temporary solution until all our code uses esmodules' >> "$OUT_FILE"
sed 's/export class Util/class Util/g' "$LH_ROOT_DIR"/report/renderer/util.js >> "$OUT_FILE"
echo 'module.exports = Util;' >> "$OUT_FILE"
2 changes: 1 addition & 1 deletion lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const path = require('path');
const assert = require('assert').strict;
const tsc = require('typescript');
const MessageParser = require('intl-messageformat-parser').default;
const Util = require('../../../report/renderer/util.js');
const Util = require('../../util-commonjs.js');
const {collectAndBakeCtcStrings} = require('./bake-ctc-to-lhl.js');
const {pruneObsoleteLhlMessages} = require('./prune-obsolete-lhl-messages.js');
const {countTranslatedMessages} = require('./count-translated.js');
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/scripts/open-devtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ if ! which gn ; then
export PYTHONPATH="${PYTHONPATH:-}:$BLINK_TOOLS_PATH/latest/third_party/typ"
fi

yarn build-devtools
yarn devtools "$DEVTOOLS_PATH"

cd "$DEVTOOLS_PATH"
Expand Down
11 changes: 11 additions & 0 deletions lighthouse-core/scripts/roll-to-devtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ mkdir -p "$fe_lh_dir"

lh_bg_js="dist/lighthouse-dt-bundle.js"

yarn build-report
yarn build-devtools

# copy lighthouse-dt-bundle (potentially stale)
cp -pPR "$lh_bg_js" "$fe_lh_dir/lighthouse-dt-bundle.js"
echo -e "$check (Potentially stale) lighthouse-dt-bundle copied."

# generate report.d.ts
npx tsc --allowJs --declaration --emitDeclarationOnly dist/report.js

# copy report code $fe_lh_dir
fe_lh_report_dir="$fe_lh_dir/report/"
cp dist/report.js dist/report.d.ts "$fe_lh_report_dir"
echo -e "$check Report code copied."

# copy report generator + cached resources into $fe_lh_dir
fe_lh_report_assets_dir="$fe_lh_dir/report-assets/"
rsync -avh dist/dt-report-resources/ "$fe_lh_report_assets_dir" --delete
Expand Down
Loading