From 5f9d7f255a59d36facbe991e15aa0d21bf504658 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Thu, 18 Oct 2018 18:40:33 -0700 Subject: [PATCH 1/4] extension: clean up client organization and building --- .appveyor.yml | 1 - .eslintignore | 2 - .github/CODEOWNERS | 2 +- .gitignore | 4 +- .npmignore | 2 +- .travis.yml | 3 +- .../build-extension.js | 57 ++++++------------ .../bundle-builder.js | 26 +++++--- build/changelog-generator/index.js | 4 ++ .../.eslintrc.js | 0 .../app/src => clients}/devtools-entry.js | 6 +- .../extension}/_locales/en/messages.json | 0 .../_locales/en/messages_canary.json | 0 .../app => clients/extension}/images/fail.svg | 0 .../extension}/images/lh_logo_bg.png | Bin .../extension}/images/lh_logo_bg_no-light.png | Bin .../extension}/images/lh_logo_canary_bg.png | Bin .../extension}/images/lh_logo_canary_icon.png | Bin .../extension}/images/lh_logo_icon.png | Bin .../extension}/images/lh_logo_icon_light.png | Bin .../app => clients/extension}/images/pass.svg | 0 .../extension}/images/verified.svg | 0 .../app => clients/extension}/manifest.json | 0 .../app => clients/extension}/popup.html | 0 .../extension/scripts}/extension-entry.js | 0 .../extension/scripts}/popup.js | 0 .../extension}/styles/lighthouse-loading.css | 0 .../extension}/styles/lighthouse.css | 0 .../app/src => clients}/lightrider-entry.js | 14 ++--- .../test/extension}/extension-test.js | 7 ++- .../test/extension}/popup-test.js | 4 +- .../test}/lightrider-entry-test.js | 4 +- docs/releasing.md | 10 ++- lighthouse-core/index.js | 2 +- lighthouse-core/scripts/roll-to-devtools.sh | 2 +- lighthouse-extension/.gitattributes | 1 - lighthouse-extension/.gitignore | 10 --- lighthouse-extension/README.md | 37 ------------ lighthouse-extension/package.json | 15 ----- lighthouse-extension/yarn.lock | 4 -- lighthouse-viewer/test/viewer-test-pptr.js | 2 +- package.json | 23 ++++--- tsconfig.json | 7 +-- yarn.lock | 35 ----------- 44 files changed, 88 insertions(+), 196 deletions(-) rename {lighthouse-extension => build}/build-extension.js (62%) rename {lighthouse-extension => build}/bundle-builder.js (88%) rename {lighthouse-extension => clients}/.eslintrc.js (100%) rename {lighthouse-extension/app/src => clients}/devtools-entry.js (89%) rename {lighthouse-extension/app => clients/extension}/_locales/en/messages.json (100%) rename {lighthouse-extension/app => clients/extension}/_locales/en/messages_canary.json (100%) rename {lighthouse-extension/app => clients/extension}/images/fail.svg (100%) rename {lighthouse-extension/app => clients/extension}/images/lh_logo_bg.png (100%) rename {lighthouse-extension/app => clients/extension}/images/lh_logo_bg_no-light.png (100%) rename {lighthouse-extension/app => clients/extension}/images/lh_logo_canary_bg.png (100%) rename {lighthouse-extension/app => clients/extension}/images/lh_logo_canary_icon.png (100%) rename {lighthouse-extension/app => clients/extension}/images/lh_logo_icon.png (100%) rename {lighthouse-extension/app => clients/extension}/images/lh_logo_icon_light.png (100%) rename {lighthouse-extension/app => clients/extension}/images/pass.svg (100%) rename {lighthouse-extension/app => clients/extension}/images/verified.svg (100%) rename {lighthouse-extension/app => clients/extension}/manifest.json (100%) rename {lighthouse-extension/app => clients/extension}/popup.html (100%) rename {lighthouse-extension/app/src => clients/extension/scripts}/extension-entry.js (100%) rename {lighthouse-extension/app/src => clients/extension/scripts}/popup.js (100%) rename {lighthouse-extension/app => clients/extension}/styles/lighthouse-loading.css (100%) rename {lighthouse-extension/app => clients/extension}/styles/lighthouse.css (100%) rename {lighthouse-extension/app/src => clients}/lightrider-entry.js (84%) rename {lighthouse-extension/test => clients/test/extension}/extension-test.js (95%) rename {lighthouse-extension/test => clients/test/extension}/popup-test.js (95%) rename {lighthouse-extension/test/app/src => clients/test}/lightrider-entry-test.js (94%) delete mode 100644 lighthouse-extension/.gitattributes delete mode 100644 lighthouse-extension/.gitignore delete mode 100644 lighthouse-extension/README.md delete mode 100644 lighthouse-extension/package.json delete mode 100644 lighthouse-extension/yarn.lock diff --git a/.appveyor.yml b/.appveyor.yml index 99c91450a385..710f0d95f95d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -48,6 +48,5 @@ test_script: cache: #- chrome-win32 -> appveyor.yml,package.json - node_modules -> appveyor.yml,package.json,yarn.lock - - lighthouse-extension\node_modules -> appveyor.yml,package.json,yarn.lock,lighthouse-extension\package.json,lighthouse-extension\yarn.lock - lighthouse-viewer\node_modules -> appveyor.yml,package.json,yarn.lock,lighthouse-viewer\package.json,lighthouse-viewer\yarn.lock - '%LOCALAPPDATA%\Yarn -> appveyor.yml,package.json,yarn.lock' diff --git a/.eslintignore b/.eslintignore index 229a0c723abf..5bd552cf0ed6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,9 +6,7 @@ **/third_party/** **/dist/** -lighthouse-extension/app/scripts -**/closure/*/* coverage/** !.eslintrc.js diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b36db743d01e..f31ed0bd0e82 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -12,7 +12,7 @@ lighthouse-core/report/ @paulirish lighthouse-core/config/ @patrickhulce @brendankenny lighthouse-core/lib/ @brendankenny @paulirish -lighthouse-extension/ @paulirish @patrickhulce +clients/ @paulirish @patrickhulce lighthouse-viewer/ @ebidel @brendankenny docs/ @paulirish diff --git a/.gitignore b/.gitignore index fd6d2d8c897b..3ef1f3662ec9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,7 @@ npm-debug.log .vscode .tmp -lighthouse-extension/dist -lighthouse-core/third_party/src -**/pages/scripts/lighthouse-report.js +dist coverage lcov.info .nyc_output diff --git a/.npmignore b/.npmignore index ae36ee757da4..a79f74359799 100644 --- a/.npmignore +++ b/.npmignore @@ -11,7 +11,7 @@ lighthouse-core/scripts/* lighthouse-core/test/ lighthouse-core/third_party/src/ lighthouse-viewer/ -lighthouse-extension/ +clients/ lighthouse-cli/results/ lighthouse-logger/ diff --git a/.travis.yml b/.travis.yml index 362465fae53e..1569dc308409 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ cache: directories: - node_modules - lantern-data - - lighthouse-extension/node_modules - lighthouse-viewer/node_modules - /home/travis/.rvm/gems/ install: @@ -38,7 +37,7 @@ script: - yarn unit:silentcoverage - yarn type-check - yarn smoke:silentcoverage - - yarn test-extension + - yarn test-clients - yarn test-viewer - yarn test-lantern - yarn i18n:checks diff --git a/lighthouse-extension/build-extension.js b/build/build-extension.js similarity index 62% rename from lighthouse-extension/build-extension.js rename to build/build-extension.js index 3349e754ac06..c87bf64a0896 100644 --- a/lighthouse-extension/build-extension.js +++ b/build/build-extension.js @@ -8,39 +8,23 @@ const fs = require('fs'); const archiver = require('archiver'); -const del = require('del'); const cpy = require('cpy'); const makeDir = require('make-dir'); const bundleBuilder = require('./bundle-builder.js'); -const distDir = 'dist'; -const manifestVersion = require(`./app/manifest.json`).version; - -// list of all consumers we build for (easier to understand which file is used for which) -const CONSUMERS = { - DEVTOOLS: { - src: 'devtools-entry.js', - dist: 'lighthouse-dt-bundle.js', - }, - EXTENSION: { - src: 'extension-entry.js', - dist: 'lighthouse-ext-bundle.js', - }, - LIGHTRIDER: { - src: 'lightrider-entry.js', - dist: 'lighthouse-lr-bundle.js', - }, -}; +const sourceDir = __dirname + '/../clients/extension'; +const sourceName = 'extension-entry.js'; +const distDir = __dirname + '/../dist/extension'; +const distName = 'lighthouse-ext-bundle.js'; +const manifestVersion = require(`${sourceDir}/manifest.json`).version; /** - * Browserify and minify scripts. + * Browserify and minify entry point. */ -function buildAll() { - return Object.values(CONSUMERS).map(consumer => { - const inFile = `app/src/${consumer.src}`; - const outFile = `dist/scripts/${consumer.dist}`; - return bundleBuilder.build(inFile, outFile); - }); +function buildEntryPoint() { + const inFile = `${sourceDir}/scripts/${sourceName}`; + const outFile = `${distDir}/scripts/${distName}`; + return bundleBuilder.build(inFile, outFile); } /** @@ -48,11 +32,12 @@ function buildAll() { * @return {Promise} */ async function copyPopup() { - let popupSrc = fs.readFileSync('app/src/popup.js', {encoding: 'utf8'}); + let popupSrc = fs.readFileSync(`${sourceDir}/scripts/popup.js`, {encoding: 'utf8'}); popupSrc = popupSrc.replace(/__COMMITHASH__/g, bundleBuilder.COMMIT_HASH); - await makeDir(`${distDir}/scripts`); - fs.writeFileSync(`${distDir}/scripts/popup.js`, popupSrc); + const popupDir = `${distDir}/scripts`; + await makeDir(popupDir); + fs.writeFileSync(`${popupDir}/popup.js`, popupSrc); } /** @@ -65,8 +50,8 @@ async function copyAssets() { 'images/**/*', 'manifest.json', '_locales/**', // currently non-functional - ], `../${distDir}`, { - cwd: 'app', + ], distDir, { + cwd: sourceDir, parents: true, }); } @@ -77,17 +62,15 @@ async function copyAssets() { * @return {Promise} */ async function packageExtension() { - await del([ - `${distDir}/scripts/${CONSUMERS.DEVTOOLS.dist}`, - `${distDir}/scripts/${CONSUMERS.LIGHTRIDER.dist}`, - ]); + const packagePath = `${distDir}/../extension-package`; + await makeDir(packagePath); return new Promise((resolve, reject) => { const archive = archiver('zip', { zlib: {level: 9}, }); - const outPath = `package/lighthouse-${manifestVersion}.zip`; + const outPath = `${packagePath}/lighthouse-${manifestVersion}.zip`; const writeStream = fs.createWriteStream(outPath); writeStream.on('finish', resolve); writeStream.on('error', reject); @@ -105,7 +88,7 @@ async function run() { } await Promise.all([ - ...buildAll(), + buildEntryPoint(), copyAssets(), copyPopup(), ]); diff --git a/lighthouse-extension/bundle-builder.js b/build/bundle-builder.js similarity index 88% rename from lighthouse-extension/bundle-builder.js rename to build/bundle-builder.js index d5c9ccb38949..eca18d1c2051 100644 --- a/lighthouse-extension/bundle-builder.js +++ b/build/bundle-builder.js @@ -25,12 +25,12 @@ const COMMIT_HASH = require('child_process') .toString().trim(); const audits = LighthouseRunner.getAuditList() - .map(f => '../lighthouse-core/audits/' + f.replace(/\.js$/, '')); + .map(f => './lighthouse-core/audits/' + f.replace(/\.js$/, '')); const gatherers = LighthouseRunner.getGathererList() - .map(f => '../lighthouse-core/gather/gatherers/' + f.replace(/\.js$/, '')); + .map(f => './lighthouse-core/gather/gatherers/' + f.replace(/\.js$/, '')); -const locales = fs.readdirSync('../lighthouse-core/lib/i18n/locales/') +const locales = fs.readdirSync(__dirname + '/../lighthouse-core/lib/i18n/locales/') .map(f => require.resolve(`../lighthouse-core/lib/i18n/locales/${f}`)); /** @param {string} file */ @@ -81,7 +81,7 @@ async function browserifyFile(entryPath, distPath) { } // Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded. - const corePath = '../lighthouse-core/'; + const corePath = './lighthouse-core/'; const driverPath = `${corePath}gather/`; audits.forEach(audit => { bundle = bundle.require(audit, {expose: audit.replace(corePath, '../')}); @@ -140,8 +140,16 @@ async function build(entryPath, distPath) { minifyScript(distPath); } -module.exports = { - /** The commit hash for the current HEAD. */ - COMMIT_HASH, - build, -}; +// @ts-ignore Test if called from the CLI or as a module. +if (require.main === module) { + // Take paths relative to cwd and build. + const [entryPath, distPath] = process.argv.slice(2) + .map(filePath => path.resolve(process.cwd(), filePath)); + build(entryPath, distPath); +} else { + module.exports = { + /** The commit hash for the current HEAD. */ + COMMIT_HASH, + build, + }; +} diff --git a/build/changelog-generator/index.js b/build/changelog-generator/index.js index ff8b8454e6e6..e26bfa0dafe0 100644 --- a/build/changelog-generator/index.js +++ b/build/changelog-generator/index.js @@ -10,6 +10,8 @@ const mainTemplate = readFileSync(resolve(__dirname, 'templates/template.hbs')). const headerPartial = readFileSync(resolve(__dirname, 'templates/header.hbs')).toString(); const commitPartial = readFileSync(resolve(__dirname, 'templates/commit.hbs')).toString(); +/** @typedef {{type: string, header: string, hash?: string, message?: string, PR?: string}} Commit */ + const pullRequestRegex = /\(#(\d+)\)$/; const parserOpts = { headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/, @@ -30,6 +32,7 @@ const writerOpts = { mainTemplate, headerPartial, commitPartial, + /** @param {Commit} commit */ transform: commit => { if (typeof commit.hash === 'string') { commit.hash = commit.hash.substring(0, 7); @@ -68,6 +71,7 @@ const writerOpts = { return commit; }, groupBy: 'type', + /** @param {{title: string}} a @param {{title: string}} b */ commitGroupsSort: (a, b) => { // put new audit on the top if (a.title === 'New Audits') { diff --git a/lighthouse-extension/.eslintrc.js b/clients/.eslintrc.js similarity index 100% rename from lighthouse-extension/.eslintrc.js rename to clients/.eslintrc.js diff --git a/lighthouse-extension/app/src/devtools-entry.js b/clients/devtools-entry.js similarity index 89% rename from lighthouse-extension/app/src/devtools-entry.js rename to clients/devtools-entry.js index ab7d83008b9d..cd542f7b3fce 100644 --- a/lighthouse-extension/app/src/devtools-entry.js +++ b/clients/devtools-entry.js @@ -5,11 +5,11 @@ */ 'use strict'; -const lighthouse = require('../../../lighthouse-core/index'); -const RawProtocol = require('../../../lighthouse-core/gather/connections/raw'); +const lighthouse = require('../lighthouse-core/index.js'); +const RawProtocol = require('../lighthouse-core/gather/connections/raw.js'); const log = require('lighthouse-logger'); -/** @typedef {import('../../../lighthouse-core/gather/connections/connection.js')} Connection */ +/** @typedef {import('../lighthouse-core/gather/connections/connection.js')} Connection */ /** * Return a version of the default config, filtered to only run the specified diff --git a/lighthouse-extension/app/_locales/en/messages.json b/clients/extension/_locales/en/messages.json similarity index 100% rename from lighthouse-extension/app/_locales/en/messages.json rename to clients/extension/_locales/en/messages.json diff --git a/lighthouse-extension/app/_locales/en/messages_canary.json b/clients/extension/_locales/en/messages_canary.json similarity index 100% rename from lighthouse-extension/app/_locales/en/messages_canary.json rename to clients/extension/_locales/en/messages_canary.json diff --git a/lighthouse-extension/app/images/fail.svg b/clients/extension/images/fail.svg similarity index 100% rename from lighthouse-extension/app/images/fail.svg rename to clients/extension/images/fail.svg diff --git a/lighthouse-extension/app/images/lh_logo_bg.png b/clients/extension/images/lh_logo_bg.png similarity index 100% rename from lighthouse-extension/app/images/lh_logo_bg.png rename to clients/extension/images/lh_logo_bg.png diff --git a/lighthouse-extension/app/images/lh_logo_bg_no-light.png b/clients/extension/images/lh_logo_bg_no-light.png similarity index 100% rename from lighthouse-extension/app/images/lh_logo_bg_no-light.png rename to clients/extension/images/lh_logo_bg_no-light.png diff --git a/lighthouse-extension/app/images/lh_logo_canary_bg.png b/clients/extension/images/lh_logo_canary_bg.png similarity index 100% rename from lighthouse-extension/app/images/lh_logo_canary_bg.png rename to clients/extension/images/lh_logo_canary_bg.png diff --git a/lighthouse-extension/app/images/lh_logo_canary_icon.png b/clients/extension/images/lh_logo_canary_icon.png similarity index 100% rename from lighthouse-extension/app/images/lh_logo_canary_icon.png rename to clients/extension/images/lh_logo_canary_icon.png diff --git a/lighthouse-extension/app/images/lh_logo_icon.png b/clients/extension/images/lh_logo_icon.png similarity index 100% rename from lighthouse-extension/app/images/lh_logo_icon.png rename to clients/extension/images/lh_logo_icon.png diff --git a/lighthouse-extension/app/images/lh_logo_icon_light.png b/clients/extension/images/lh_logo_icon_light.png similarity index 100% rename from lighthouse-extension/app/images/lh_logo_icon_light.png rename to clients/extension/images/lh_logo_icon_light.png diff --git a/lighthouse-extension/app/images/pass.svg b/clients/extension/images/pass.svg similarity index 100% rename from lighthouse-extension/app/images/pass.svg rename to clients/extension/images/pass.svg diff --git a/lighthouse-extension/app/images/verified.svg b/clients/extension/images/verified.svg similarity index 100% rename from lighthouse-extension/app/images/verified.svg rename to clients/extension/images/verified.svg diff --git a/lighthouse-extension/app/manifest.json b/clients/extension/manifest.json similarity index 100% rename from lighthouse-extension/app/manifest.json rename to clients/extension/manifest.json diff --git a/lighthouse-extension/app/popup.html b/clients/extension/popup.html similarity index 100% rename from lighthouse-extension/app/popup.html rename to clients/extension/popup.html diff --git a/lighthouse-extension/app/src/extension-entry.js b/clients/extension/scripts/extension-entry.js similarity index 100% rename from lighthouse-extension/app/src/extension-entry.js rename to clients/extension/scripts/extension-entry.js diff --git a/lighthouse-extension/app/src/popup.js b/clients/extension/scripts/popup.js similarity index 100% rename from lighthouse-extension/app/src/popup.js rename to clients/extension/scripts/popup.js diff --git a/lighthouse-extension/app/styles/lighthouse-loading.css b/clients/extension/styles/lighthouse-loading.css similarity index 100% rename from lighthouse-extension/app/styles/lighthouse-loading.css rename to clients/extension/styles/lighthouse-loading.css diff --git a/lighthouse-extension/app/styles/lighthouse.css b/clients/extension/styles/lighthouse.css similarity index 100% rename from lighthouse-extension/app/styles/lighthouse.css rename to clients/extension/styles/lighthouse.css diff --git a/lighthouse-extension/app/src/lightrider-entry.js b/clients/lightrider-entry.js similarity index 84% rename from lighthouse-extension/app/src/lightrider-entry.js rename to clients/lightrider-entry.js index eb0b53bcb57f..d46dd36d69a2 100644 --- a/lighthouse-extension/app/src/lightrider-entry.js +++ b/clients/lightrider-entry.js @@ -5,19 +5,19 @@ */ 'use strict'; -const lighthouse = require('../../../lighthouse-core/index'); +const lighthouse = require('../lighthouse-core/index.js'); -const assetSaver = require('../../../lighthouse-core/lib/asset-saver.js'); -const LHError = require('../../../lighthouse-core/lib/lh-error.js'); -const preprocessor = require('../../../lighthouse-core/lib/proto-preprocessor.js'); +const assetSaver = require('../lighthouse-core/lib/asset-saver.js'); +const LHError = require('../lighthouse-core/lib/lh-error.js'); +const preprocessor = require('../lighthouse-core/lib/proto-preprocessor.js'); /** @type {Record<'mobile'|'desktop', LH.Config.Json>} */ const LR_PRESETS = { - mobile: require('../../../lighthouse-core/config/lr-mobile-config'), - desktop: require('../../../lighthouse-core/config/lr-desktop-config'), + mobile: require('../lighthouse-core/config/lr-mobile-config.js'), + desktop: require('../lighthouse-core/config/lr-desktop-config.js'), }; -/** @typedef {import('../../../lighthouse-core/gather/connections/connection.js')} Connection */ +/** @typedef {import('../lighthouse-core/gather/connections/connection.js')} Connection */ /** * Run lighthouse for connection and provide similar results as in CLI. diff --git a/lighthouse-extension/test/extension-test.js b/clients/test/extension/extension-test.js similarity index 95% rename from lighthouse-extension/test/extension-test.js rename to clients/test/extension/extension-test.js index f25ef29e7f45..00bae127641d 100644 --- a/lighthouse-extension/test/extension-test.js +++ b/clients/test/extension/extension-test.js @@ -10,10 +10,11 @@ const path = require('path'); const assert = require('assert'); const fs = require('fs'); -const puppeteer = require('../../node_modules/puppeteer/index.js'); +const puppeteer = require('../../../node_modules/puppeteer/index.js'); -const lighthouseExtensionPath = path.resolve(__dirname, '../dist'); -const config = require(path.resolve(__dirname, '../../lighthouse-core/config/default-config.js')); +const lighthouseExtensionPath = path.resolve(__dirname, '../../../dist/extension'); +const config = require(path.resolve(__dirname, + '../../../lighthouse-core/config/default-config.js')); const getAuditsOfCategory = category => config.categories[category].auditRefs; diff --git a/lighthouse-extension/test/popup-test.js b/clients/test/extension/popup-test.js similarity index 95% rename from lighthouse-extension/test/popup-test.js rename to clients/test/extension/popup-test.js index 5196ed5ee883..0653792188f3 100644 --- a/lighthouse-extension/test/popup-test.js +++ b/clients/test/extension/popup-test.js @@ -9,9 +9,9 @@ const path = require('path'); const assert = require('assert'); -const puppeteer = require('../../node_modules/puppeteer/index.js'); +const puppeteer = require('../../../node_modules/puppeteer/index.js'); -const lighthouseExtensionPath = path.resolve(__dirname, '../dist'); +const lighthouseExtensionPath = path.resolve(__dirname, '../../../dist/extension'); const defaultCategoriesStub = [ { diff --git a/lighthouse-extension/test/app/src/lightrider-entry-test.js b/clients/test/lightrider-entry-test.js similarity index 94% rename from lighthouse-extension/test/app/src/lightrider-entry-test.js rename to clients/test/lightrider-entry-test.js index 15a617694acb..408c7dc944d2 100644 --- a/lighthouse-extension/test/app/src/lightrider-entry-test.js +++ b/clients/test/lightrider-entry-test.js @@ -6,8 +6,8 @@ 'use strict'; const assert = require('assert'); -const lhBackground = require('../../../app/src/lightrider-entry.js'); -const LHError = require('../../../../lighthouse-core/lib/lh-error.js'); +const lhBackground = require('../lightrider-entry.js'); +const LHError = require('../../lighthouse-core/lib/lh-error.js'); /* eslint-env mocha */ diff --git a/docs/releasing.md b/docs/releasing.md index a006692a93a0..044df741d8f2 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -38,7 +38,7 @@ yarn install-all # * Bump it * yarn version --no-git-tag-version -# manually bump extension v in extension/app/manifest.json +# manually bump extension v in clients/extension/manifest.json yarn update:sample-json # * Build it * @@ -94,9 +94,15 @@ echo "Rebuild extension and viewer to get the latest, tagged master commit" yarn build-all; # zip the extension files -cd lighthouse-extension; gulp package; cd .. +node build/build-extension.js package; cd dist/extension-package/ echo "Go here: https://chrome.google.com/webstore/developer/edit/blipmdconlkpinefehnmjammfjpmpbjk " echo "Upload the package zip to CWS dev dashboard" +# Be in lighthouse-extension-owners group +# Open +# Click _Edit_ on lighthouse +# _Upload Updated Package_ +# Select `lighthouse-4.X.X.zip` +# _Publish_ at the bottom echo "Verify the npm package won't include unncessary files" npm pack --dry-run diff --git a/lighthouse-core/index.js b/lighthouse-core/index.js index effe0545aff7..09bca84b0187 100644 --- a/lighthouse-core/index.js +++ b/lighthouse-core/index.js @@ -25,7 +25,7 @@ const LHError = require('./lib/lh-error.js'); * * lighthouse-cli \ * -- core/index.js ----> runner.js ----> [Gather / Audit] - * lighthouse-extension / + * clients / */ /** diff --git a/lighthouse-core/scripts/roll-to-devtools.sh b/lighthouse-core/scripts/roll-to-devtools.sh index e6c83f2c63e8..78e879f964c4 100755 --- a/lighthouse-core/scripts/roll-to-devtools.sh +++ b/lighthouse-core/scripts/roll-to-devtools.sh @@ -33,7 +33,7 @@ fi report_dir="lighthouse-core/report/html" fe_lh_dir="$frontend_dir/audits2/lighthouse" -lh_bg_js="lighthouse-extension/dist/scripts/lighthouse-dt-bundle.js" +lh_bg_js="dist/lighthouse-dt-bundle.js" lh_worker_dir="$frontend_dir/audits2_worker/lighthouse" # copy report files diff --git a/lighthouse-extension/.gitattributes b/lighthouse-extension/.gitattributes deleted file mode 100644 index 2125666142eb..000000000000 --- a/lighthouse-extension/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto \ No newline at end of file diff --git a/lighthouse-extension/.gitignore b/lighthouse-extension/.gitignore deleted file mode 100644 index 147daec22ef1..000000000000 --- a/lighthouse-extension/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -node_modules -temp -.tmp -dist -.sass-cache -app/bower_components -test/bower_components -package -app/scripts -app/pages/scripts/lighthouse-report.js diff --git a/lighthouse-extension/README.md b/lighthouse-extension/README.md deleted file mode 100644 index 9b9d912d4468..000000000000 --- a/lighthouse-extension/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# Lighthouse Extension - -## Install dogfood extension - -* - -(If the warning bar about the connected debugging agent bothers you, it can be disabled at `chrome://flags/#silent-debugger-extension-api`) - -## Dev - -* `npm i` -* `yarn watch` -* Load `/app` as Unpacked extension. -* Saved changes _should_ trigger a recompile followed by browsersync automatically refreshing the extension. -* Scripts in `./app/src/` are browserified into `./app/scripts`. - -## Manual Deploy to CWS - -* Be in lighthouse-extension-owners group -* `yarn build` -* Verify that the extension in `dist` works. -* Verify that `dist/manifest.json` bumps the version number vs what's on CWS. -* `gulp package` -* Open -* Click _Edit_ on lighthouse -* _Upload Updated Package_ -* Select `packages/lighthouse-1.X.X.zip` -* _Publish_ at the bottom - -## ~~Easier Deploy via API~~ - -(This appears to be broken, unfortunately…) - -* Install [web store api app](https://chrome.google.com/webstore/detail/web-store-api-sample-app/ndgidogppopohjpghapeojgoehfmflab) - * Add dist folder -* `yarn build` -* Use ID: `blipmdconlkpinefehnmjammfjpmpbjk` diff --git a/lighthouse-extension/package.json b/lighthouse-extension/package.json deleted file mode 100644 index 1630f150d101..000000000000 --- a/lighthouse-extension/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "lighthouse-extension", - "private": true, - "engines": { - "node": ">=8" - }, - "scripts": { - "build": "node ./build-extension.js", - "test": "mocha test/**/*-test.js", - "clean": "rimraf dist", - "package": "node ./build-extension.js package" - }, - "devDependencies": {}, - "dependencies": {} -} diff --git a/lighthouse-extension/yarn.lock b/lighthouse-extension/yarn.lock deleted file mode 100644 index fb57ccd13afb..000000000000 --- a/lighthouse-extension/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - diff --git a/lighthouse-viewer/test/viewer-test-pptr.js b/lighthouse-viewer/test/viewer-test-pptr.js index 1a42831bf935..e324d61d0310 100644 --- a/lighthouse-viewer/test/viewer-test-pptr.js +++ b/lighthouse-viewer/test/viewer-test-pptr.js @@ -20,7 +20,7 @@ const config = require(path.resolve(__dirname, '../../lighthouse-core/config/def const lighthouseCategories = Object.keys(config.categories); const getAuditsOfCategory = category => config.categories[category].auditRefs; -// TODO: should be combined in some way with lighthouse-extension/test/extension-test.js +// TODO: should be combined in some way with clients/test/extension/extension-test.js describe('Lighthouse Viewer', function() { // eslint-disable-next-line no-console console.log('\n✨ Be sure to have recently run this: yarn build-viewer'); diff --git a/package.json b/package.json index 2ddc15dd7fc5..07a3d4912fb5 100644 --- a/package.json +++ b/package.json @@ -12,22 +12,23 @@ }, "scripts": { "install-all": "npm-run-posix-or-windows install-all:task", - "install-all:task": "yarn & yarn install-extension & yarn install-viewer & wait", - "install-all:task:windows": "yarn && yarn install-extension && yarn install-viewer", - "install-extension": "cd ./lighthouse-extension && yarn install", + "install-all:task": "yarn & yarn install-viewer & wait", + "install-all:task:windows": "yarn && yarn install-viewer", "install-viewer": "cd ./lighthouse-viewer && yarn install", "build-all": "npm-run-posix-or-windows build-all:task", - "build-all:task": "yarn build-extension & yarn build-viewer & wait", - "build-all:task:windows": "yarn build-extension && yarn build-viewer", - "build-extension": "cd ./lighthouse-extension && yarn build", + "build-all:task": "yarn build-extension & yarn build-devtools & yarn build-lr & yarn build-viewer & wait", + "build-all:task:windows": "yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer", + "build-extension": "node ./build/build-extension.js", + "build-devtools": "node ./build/bundle-builder.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js", + "build-lr": "node ./build/bundle-builder.js clients/lightrider-entry.js dist/lighthouse-lr-bundle.js", "build-viewer": "cd ./lighthouse-viewer && yarn build", - "clean": "rimraf proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json || true", + "clean": "rimraf dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json || true", "lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .", "smoke": "node lighthouse-cli/test/smokehouse/run-smoke.js", "debug": "node --inspect-brk ./lighthouse-cli/index.js", "start": "node ./lighthouse-cli/index.js", "test": "yarn diff:sample-json && yarn lint --quiet && yarn unit && yarn type-check", - "test-extension": "cd lighthouse-extension && yarn test", + "test-clients": "mocha \"clients/test/**/*-test.js\"", "test-viewer": "cd lighthouse-viewer && yarn pptr-test", "test-lantern": "bash lighthouse-core/scripts/test-lantern.sh", "unit-core": "jest \"lighthouse-core/\"", @@ -75,7 +76,6 @@ "@types/configstore": "^2.1.1", "@types/cpy": "^5.1.0", "@types/css-font-loading-module": "^0.0.2", - "@types/del": "^3.0.1", "@types/esprima": "^4.0.2", "@types/inquirer": "^0.0.35", "@types/intl-messageformat": "^1.3.0", @@ -104,7 +104,6 @@ "cpy": "^7.0.1", "csv-validator": "^0.0.3", "cz-customizable": "^5.2.0", - "del": "^3.0.0", "devtools-protocol": "0.0.588129", "eslint": "^4.19.1", "eslint-config-google": "^0.9.1", @@ -172,7 +171,7 @@ }, "bundlesize": [ { - "path": "./lighthouse-extension/dist/scripts/lighthouse-ext-bundle.js", + "path": "./dist/lighthouse-ext-bundle.js", "threshold": "520 Kb" }, { @@ -189,7 +188,7 @@ "exclude": [ "**/third_party/**", "**/test/", - "lighthouse-extension/" + "clients/" ] }, "homepage": "https://github.com/GoogleChrome/lighthouse#readme", diff --git a/tsconfig.json b/tsconfig.json index dc1d9c37f865..88bcb7e99c61 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,14 +19,13 @@ "include": [ "lighthouse-cli/**/*.js", "lighthouse-core/**/*.js", - "lighthouse-extension/app/src/*.js", - "lighthouse-extension/*.js", + "clients/**/*.js", + "build/**/*.js", "./typings/*.d.ts", ], "exclude": [ "lighthouse-cli/test/**/*.js", "lighthouse-core/test/**/*.js", - "lighthouse-core/closure/**/*.js", - "lighthouse-core/third_party/src/**/*.js", + "clients/test/**/*.js", ] } diff --git a/yarn.lock b/yarn.lock index d983675d83de..d2e3fcb11791 100644 --- a/yarn.lock +++ b/yarn.lock @@ -126,13 +126,6 @@ resolved "https://registry.yarnpkg.com/@types/css-font-loading-module/-/css-font-loading-module-0.0.2.tgz#09f1f1772975777e37851b7b7a4389d97c210add" integrity sha512-zZTq/B1ZcJMepOfBIMEwOZ/g/jpSPUJoxP8zPtPizOKE/Q89SujK1BLYZBg+4LLW3IzJGOI67dbeePy8uPUs+g== -"@types/del@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@types/del/-/del-3.0.1.tgz#4712da8c119873cbbf533ad8dbf1baac5940ac5d" - integrity sha512-y6qRq6raBuu965clKgx6FHuiPu3oHdtmzMPXi8Uahsjdq1L6DL5fS/aY5/s71YwM7k6K1QIWvem5vNwlnNGIkQ== - dependencies: - "@types/glob" "*" - "@types/esprima@^4.0.2": version "4.0.2" resolved "https://registry.yarnpkg.com/@types/esprima/-/esprima-4.0.2.tgz#0303602d0644086d4802635d7abc9ac0eec57207" @@ -2517,18 +2510,6 @@ del@^2.0.2: pinkie-promise "^2.0.0" rimraf "^2.2.8" -del@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/del/-/del-3.0.0.tgz#53ecf699ffcbcb39637691ab13baf160819766e5" - integrity sha1-U+z2mf/LyzljdpGrE7rxYIGXZuU= - dependencies: - globby "^6.1.0" - is-path-cwd "^1.0.0" - is-path-in-cwd "^1.0.0" - p-map "^1.1.1" - pify "^3.0.0" - rimraf "^2.2.8" - delayed-stream@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" @@ -3748,17 +3729,6 @@ globby@^5.0.0: pify "^2.0.0" pinkie-promise "^2.0.0" -globby@^6.1.0: - version "6.1.0" - resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c" - integrity sha1-9abXDoOV4hyFj7BInWTfAkJNUGw= - dependencies: - array-union "^1.0.1" - glob "^7.0.3" - object-assign "^4.0.1" - pify "^2.0.0" - pinkie-promise "^2.0.0" - globby@^8.0.1: version "8.0.1" resolved "https://registry.yarnpkg.com/globby/-/globby-8.0.1.tgz#b5ad48b8aa80b35b814fc1281ecc851f1d2b5b50" @@ -6594,11 +6564,6 @@ p-locate@^2.0.0: dependencies: p-limit "^1.1.0" -p-map@^1.1.1: - version "1.2.0" - resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b" - integrity sha512-r6zKACMNhjPJMTl8KcFH4li//gkrXWfbD6feV8l6doRHlzljFWGJ2AP6iKaCJXyZmAUMOPtvbW7EXkbWO/pLEA== - package-json-versionify@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/package-json-versionify/-/package-json-versionify-1.0.4.tgz#5860587a944873a6b7e6d26e8e51ffb22315bf17" From 50b3b690c53d39f56996153b6aafd974e3c005d8 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Thu, 18 Oct 2018 22:59:12 -0700 Subject: [PATCH 2/4] cz --- .cz-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cz-config.js b/.cz-config.js index 61108b3bbd5e..db1d03a6acb9 100644 --- a/.cz-config.js +++ b/.cz-config.js @@ -18,7 +18,7 @@ module.exports = { {value: 'deps', name: 'deps: Dependency bumps only'}, {value: 'report', name: 'report: Report, UI, renderers'}, {value: 'cli', name: 'cli: CLI stuff'}, - {value: 'extension', name: 'extension: Chrome extension stuff'}, + {value: 'clients', name: 'clients: Extension, DevTools, or LR stuff'}, {value: 'misc', name: 'misc: Something else entirely'} ] }; From 52790927f2d2bfe08dd577250e6e091e0018814b Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Thu, 18 Oct 2018 23:18:13 -0700 Subject: [PATCH 3/4] actual bundlesize path --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07a3d4912fb5..81f2313428f1 100644 --- a/package.json +++ b/package.json @@ -171,7 +171,7 @@ }, "bundlesize": [ { - "path": "./dist/lighthouse-ext-bundle.js", + "path": "./dist/extension/scripts/lighthouse-ext-bundle.js", "threshold": "520 Kb" }, { From ac13d173907a9d0b5b9627b77055269e45e14ab7 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Fri, 19 Oct 2018 12:31:48 -0700 Subject: [PATCH 4/4] feedback --- build/{bundle-builder.js => build-bundle.js} | 13 ++++++++++--- build/build-extension.js | 8 +++++--- package.json | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) rename build/{bundle-builder.js => build-bundle.js} (97%) diff --git a/build/bundle-builder.js b/build/build-bundle.js similarity index 97% rename from build/bundle-builder.js rename to build/build-bundle.js index eca18d1c2051..2426210f48f3 100644 --- a/build/bundle-builder.js +++ b/build/build-bundle.js @@ -140,12 +140,19 @@ async function build(entryPath, distPath) { minifyScript(distPath); } -// @ts-ignore Test if called from the CLI or as a module. -if (require.main === module) { +/** + * @param {Array} argv + */ +async function cli(argv) { // Take paths relative to cwd and build. - const [entryPath, distPath] = process.argv.slice(2) + const [entryPath, distPath] = argv.slice(2) .map(filePath => path.resolve(process.cwd(), filePath)); build(entryPath, distPath); +} + +// @ts-ignore Test if called from the CLI or as a module. +if (require.main === module) { + cli(process.argv); } else { module.exports = { /** The commit hash for the current HEAD. */ diff --git a/build/build-extension.js b/build/build-extension.js index c87bf64a0896..cf7e9d1bdf0e 100644 --- a/build/build-extension.js +++ b/build/build-extension.js @@ -10,12 +10,14 @@ const fs = require('fs'); const archiver = require('archiver'); const cpy = require('cpy'); const makeDir = require('make-dir'); -const bundleBuilder = require('./bundle-builder.js'); +const bundleBuilder = require('./build-bundle.js'); -const sourceDir = __dirname + '/../clients/extension'; const sourceName = 'extension-entry.js'; -const distDir = __dirname + '/../dist/extension'; const distName = 'lighthouse-ext-bundle.js'; + +const sourceDir = __dirname + '/../clients/extension'; +const distDir = __dirname + '/../dist/extension'; + const manifestVersion = require(`${sourceDir}/manifest.json`).version; /** diff --git a/package.json b/package.json index 81f2313428f1..7d2901755518 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "build-all:task": "yarn build-extension & yarn build-devtools & yarn build-lr & yarn build-viewer & wait", "build-all:task:windows": "yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer", "build-extension": "node ./build/build-extension.js", - "build-devtools": "node ./build/bundle-builder.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js", - "build-lr": "node ./build/bundle-builder.js clients/lightrider-entry.js dist/lighthouse-lr-bundle.js", + "build-devtools": "node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js", + "build-lr": "node ./build/build-bundle.js clients/lightrider-entry.js dist/lighthouse-lr-bundle.js", "build-viewer": "cd ./lighthouse-viewer && yarn build", "clean": "rimraf dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json || true", "lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .",