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

misc(build): create rollup-plugins.js helper module #13122

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 10 additions & 21 deletions build/build-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@
'use strict';

const rollup = require('rollup');
const {nodeResolve} = require('@rollup/plugin-node-resolve');
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'));

/**
* @type {import('@rollup/plugin-typescript').default}
*/
// @ts-expect-error types are wrong.
const typescript = require('@rollup/plugin-typescript');
const rollupPlugins = require('./rollup-plugins.js');

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

Expand All @@ -38,9 +27,9 @@ async function buildFlowReport() {
const bundle = await rollup.rollup({
input: 'flow-report/standalone-flow.tsx',
plugins: [
nodeResolve(),
commonjs(),
typescript({
rollupPlugins.nodeResolve(),
rollupPlugins.commonjs(),
rollupPlugins.typescript({
tsconfig: 'flow-report/tsconfig.json',
// Plugin struggles with custom outDir, so revert it from tsconfig value
// as well as any options that require an outDir is set.
Expand All @@ -49,7 +38,7 @@ async function buildFlowReport() {
emitDeclarationOnly: false,
declarationMap: false,
}),
terser(),
rollupPlugins.terser(),
],
});

Expand All @@ -63,7 +52,7 @@ async function buildPsiReport() {
const bundle = await rollup.rollup({
input: 'report/clients/psi.js',
plugins: [
commonjs(),
rollupPlugins.commonjs(),
],
});

Expand All @@ -77,7 +66,7 @@ async function buildEsModulesBundle() {
const bundle = await rollup.rollup({
input: 'report/clients/bundle.js',
plugins: [
commonjs(),
rollupPlugins.commonjs(),
],
});

Expand All @@ -91,7 +80,7 @@ async function buildUmdBundle() {
const bundle = await rollup.rollup({
input: 'report/clients/bundle.js',
plugins: [
commonjs(),
rollupPlugins.commonjs(),
],
});

Expand Down
23 changes: 4 additions & 19 deletions build/build-smokehouse-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,7 @@
'use strict';

const rollup = require('rollup');

/**
* Rollup plugins don't export types that work with commonjs.
* @template T
* @param {T} module
* @return {T['default']}
*/
function rollupPluginTypeCoerce(module) {
// @ts-expect-error
return module;
}

const nodeResolve = rollupPluginTypeCoerce(require('rollup-plugin-node-resolve'));
const commonjs = rollupPluginTypeCoerce(require('rollup-plugin-commonjs'));
// @ts-expect-error: no types
const shim = require('rollup-plugin-shim');
const rollupPlugins = require('./rollup-plugins.js');
const {LH_ROOT} = require('../root.js');

const distDir = `${LH_ROOT}/dist`;
Expand All @@ -35,9 +20,9 @@ async function build() {
input: smokehouseLibFilename,
context: 'globalThis',
plugins: [
nodeResolve(),
commonjs(),
shim({
rollupPlugins.nodeResolve(),
rollupPlugins.commonjs(),
rollupPlugins.shim({
[smokehouseCliFilename]: 'export default {}',
}),
],
Expand Down
12 changes: 4 additions & 8 deletions build/gh-pages-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
const fs = require('fs');
const path = require('path');
const rollup = require('rollup');
const commonjs =
// @ts-expect-error types are wrong.
/** @type {import('rollup-plugin-commonjs').default} */ (require('rollup-plugin-commonjs'));
const {terser: rollupTerser} = require('rollup-plugin-terser');
const {nodeResolve} = require('@rollup/plugin-node-resolve');
const rollupPlugins = require('./rollup-plugins.js');
const cpy = require('cpy');
const ghPages = require('gh-pages');
const glob = require('glob');
Expand Down Expand Up @@ -146,10 +142,10 @@ class GhPagesApp {
*/
async _rollupSource(input) {
const plugins = [
nodeResolve(),
commonjs(),
rollupPlugins.nodeResolve(),
rollupPlugins.commonjs(),
];
if (!process.env.DEBUG) plugins.push(rollupTerser());
if (!process.env.DEBUG) plugins.push(rollupPlugins.terser());
const bundle = await rollup.rollup({
input,
plugins,
Expand Down
32 changes: 32 additions & 0 deletions build/rollup-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @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';

/**
* Rollup plugins don't export types that work with commonjs.
* @template T
* @param {T} module
* @return {T['default']}
*/
function rollupPluginTypeCoerce(module) {
// @ts-expect-error
return module;
}

const commonjs = rollupPluginTypeCoerce(require('@rollup/plugin-commonjs'));
const {nodeResolve} = require('@rollup/plugin-node-resolve');
// @ts-expect-error: no published types.
const shim = require('rollup-plugin-shim');
const {terser} = require('rollup-plugin-terser');
const typescript = rollupPluginTypeCoerce(require('@rollup/plugin-typescript'));

module.exports = {
commonjs,
nodeResolve,
shim,
terser,
typescript,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
},
"devDependencies": {
"@build-tracker/cli": "^1.0.0-beta.15",
"@rollup/plugin-commonjs": "^20.0.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the package moved, we were using the old version. newer version necessary to fix a bug that appeared from building in the original pr

"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-typescript": "^8.2.5",
"@testing-library/preact": "^2.0.1",
Expand Down Expand Up @@ -163,7 +164,6 @@
"pretty-json-stringify": "^0.0.2",
"puppeteer": "^10.2.0",
"rollup": "^2.50.6",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-shim": "^1.0.0",
"rollup-plugin-terser": "^7.0.2",
Expand Down
52 changes: 38 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,19 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@rollup/plugin-commonjs@^20.0.0":
version "20.0.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-20.0.0.tgz#3246872dcbcb18a54aaa6277a8c7d7f1b155b745"
integrity sha512-5K0g5W2Ol8hAcTHqcTBHiA7M58tfmYi1o9KxeJuuRNpGaTa5iLjcyemBitCBcKXaHamOBBEH2dGom6v6Unmqjg==
dependencies:
"@rollup/pluginutils" "^3.1.0"
commondir "^1.0.1"
estree-walker "^2.0.1"
glob "^7.1.6"
is-reference "^1.2.1"
magic-string "^0.25.7"
resolve "^1.17.0"

"@rollup/plugin-node-resolve@^13.0.4":
version "13.0.4"
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.0.4.tgz#b10222f4145a019740acb7738402130d848660c0"
Expand Down Expand Up @@ -2944,6 +2957,11 @@ commander@~2.17.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=

compare-func@^1.3.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/compare-func/-/compare-func-1.3.2.tgz#99dd0ba457e1f9bc722b12c08ec33eeab31fa648"
Expand Down Expand Up @@ -4082,6 +4100,11 @@ estree-walker@^1.0.1:
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==

estree-walker@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==

esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
Expand Down Expand Up @@ -4685,6 +4708,18 @@ glob@^7.0.0, glob@^7.0.3, glob@^7.1.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, gl
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.1.6:
version "7.2.0"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023"
integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

global-dirs@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-2.0.1.tgz#acdf3bb6685bcd55cb35e8a052266569e9469201"
Expand Down Expand Up @@ -5410,7 +5445,7 @@ is-potential-custom-element-name@^1.0.1:
resolved "https://registry.yarnpkg.com/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz#171ed6f19e3ac554394edf78caa05784a45bebb5"
integrity sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==

is-reference@^1.1.2:
is-reference@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7"
integrity sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==
Expand Down Expand Up @@ -6559,7 +6594,7 @@ [email protected]:
dependencies:
sourcemap-codec "^1.4.1"

magic-string@^0.25.2:
magic-string@^0.25.7:
version "0.25.7"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051"
integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==
Expand Down Expand Up @@ -7938,7 +7973,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=

resolve@^1.1.4, resolve@^1.1.5, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.4.0:
resolve@^1.1.4, resolve@^1.1.5, resolve@^1.10.0, resolve@^1.11.1, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.4.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
Expand Down Expand Up @@ -7997,17 +8032,6 @@ robots-parser@^2.0.1:
resolved "https://registry.npmjs.org/robots-parser/-/robots-parser-2.1.0.tgz#d16b78ce34e861ab6afbbf0aac65974dbe01566e"
integrity sha512-k07MeDS1Tl1zjoYs5bHfUbgQ0MfaeTOepDcjZFxdYXd84p6IeLDQyUwlMk2AZ9c2yExA30I3ayWhmqz9tg0DzQ==

rollup-plugin-commonjs@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz#417af3b54503878e084d127adf4d1caf8beb86fb"
integrity sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q==
dependencies:
estree-walker "^0.6.1"
is-reference "^1.1.2"
magic-string "^0.25.2"
resolve "^1.11.0"
rollup-pluginutils "^2.8.1"

rollup-plugin-node-resolve@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523"
Expand Down