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

core(unused-javascript): augment with source maps #10090

Merged
merged 54 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4a62a54
initial
connorjclark Dec 9, 2019
7886f5e
do not need _ yet
connorjclark Dec 9, 2019
65cc13c
test for unused bundle
connorjclark Dec 10, 2019
2ed3b7b
lint
connorjclark Dec 10, 2019
652059e
fix null mapping bug
connorjclark Dec 10, 2019
b48a400
fix counting
connorjclark Dec 11, 2019
7bdf8b4
fix smoke test
connorjclark Dec 11, 2019
b6a4a08
comment
connorjclark Dec 11, 2019
b840b10
comment
connorjclark Dec 11, 2019
c3fd09e
lint
connorjclark Dec 11, 2019
36c7bee
better bundle size filter
connorjclark Dec 11, 2019
c5cfac2
Squashed commit of the following:
connorjclark Dec 12, 2019
912f9f1
todo
connorjclark Dec 12, 2019
ea03907
update bundle.js
connorjclark Dec 12, 2019
a862683
count new lines
connorjclark Dec 12, 2019
4ff3804
dont double count
connorjclark Dec 13, 2019
fa429e0
fix test
connorjclark Dec 13, 2019
74b642d
fix test
connorjclark Dec 13, 2019
1c9d984
destructure
connorjclark Dec 13, 2019
0d440b2
lastColumnOfMapping
connorjclark Dec 13, 2019
60ac62f
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Dec 17, 2019
c27aa4a
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Jan 21, 2020
e2d1035
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Jan 30, 2020
e317115
fix
connorjclark Jan 31, 2020
d68a555
fix one test
connorjclark Jan 31, 2020
3d9c5f4
fix default config test
connorjclark Jan 31, 2020
1bd219d
fix
connorjclark Jan 31, 2020
4b8fe87
update
connorjclark Feb 3, 2020
39a4938
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Feb 3, 2020
d338faf
rm old code
connorjclark Feb 5, 2020
315aacb
destructure
connorjclark Feb 7, 2020
08bfc38
rm source-maps from default
connorjclark Feb 9, 2020
167dee1
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Feb 13, 2020
c404dce
wip
connorjclark Feb 18, 2020
1494110
core: audit.meta.optionalArtifacts
connorjclark Feb 18, 2020
b657659
up
connorjclark Feb 18, 2020
b1453a1
lint
connorjclark Feb 18, 2020
27a0b1e
Update lighthouse-core/test/config/config-test.js
connorjclark Feb 18, 2020
e3af45f
requestedArtifact
connorjclark Feb 18, 2020
44dcc19
fix
connorjclark Feb 18, 2020
fae6425
__internalOptionalArtifacts
connorjclark Feb 19, 2020
3672655
Update types/audit.d.ts
connorjclark Feb 20, 2020
82b2932
Merge remote-tracking branch 'origin/optional-artifacts' into unused-…
connorjclark Feb 20, 2020
19998bf
test
connorjclark Feb 20, 2020
bc46397
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Feb 20, 2020
f2ad7d2
update
connorjclark Feb 20, 2020
b6ca673
config
connorjclark Feb 20, 2020
5cbd43c
Merge remote-tracking branch 'origin/master' into unused-js-bundles
connorjclark Feb 20, 2020
2680116
updateg
connorjclark Feb 21, 2020
df5aac6
bundlesize
connorjclark Feb 21, 2020
b917684
const, revert config test
connorjclark Feb 22, 2020
8b356cf
lint
connorjclark Feb 22, 2020
01fa7f8
trim lcp
connorjclark Feb 22, 2020
44f7fd8
yay
connorjclark Feb 25, 2020
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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

**/node_modules/**
**/third_party/**
**/generated/**
**/source-maps/**
lighthouse-cli/test/fixtures/byte-efficiency/bundle.js

/dist/**

Expand Down
65 changes: 65 additions & 0 deletions build/build-cdt-lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @license Copyright 2019 Google Inc. 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 fs = require('fs');
const {execFileSync} = require('child_process');
const glob = require('glob');

const files = [
'node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js',
];
const outDir = 'lighthouse-core/lib/cdt/generated';

execFileSync('node_modules/.bin/tsc', [
'--allowJs',
'--outDir',
outDir,
...files,
]);

// eslint-disable-next-line no-console
console.log('making modifications ...');

for (const file of glob.sync(`${outDir}/**/*.js`)) {
const code = fs.readFileSync(file, 'utf-8');

let lines = code.match(/^.*(\r?\n|$)/mg) || [];
const cutoffIndex = lines.findIndex(line => line.includes('Legacy exported object'));
lines = lines.splice(0, cutoffIndex);

let deletionMode = false;

const modifiedLines = lines.map((line, i) => {
// Don't modify jsdoc comments.
if (/^\s*[/*]/.test(line)) {
return line;
}

let newLine = line;
if (file.endsWith('SourceMap.js')) {
if (line.includes('TextSourceMap.load =')) deletionMode = true;
if (line.includes('prototype.sourceContentProvider =')) deletionMode = true;
if (line.includes(`url += Common.UIString('? [sm]');`)) newLine = '';
newLine = line.replace(`Common.ParsedURL.completeURL(this._baseURL, href)`, `''`);
}
newLine = newLine.replace('exports["default"]', 'exports.default');
if (deletionMode) {
newLine = '';
if (line.startsWith(' };')) deletionMode = false;
}

if (newLine !== line) {
// eslint-disable-next-line no-console
console.log(`${file}:${i}: ${line.trim()}`);
}
return newLine;
});
modifiedLines.unshift(`const Common = require('../Common.js')\n`);
modifiedLines.unshift('// generated by build-cdt-lib.js\n');
modifiedLines.unshift('// @ts-nocheck\n');
fs.writeFileSync(file, modifiedLines.join(''));
}
157 changes: 157 additions & 0 deletions lighthouse-cli/test/fixtures/byte-efficiency/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

const a = __webpack_require__(1);
const b = __webpack_require__(2);
const c = __webpack_require__(3);

if (true) {
a();
b.half();
} else {}


/***/ }),
/* 1 */
/***/ (function(module, exports) {

module.exports = function() {
const kb2 = '................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................';
let i;
for (i = 0; i < 100; i++) {
i = i;
}
return i;
}


/***/ }),
/* 2 */
/***/ (function(module, exports) {

function half() {
const kb2 = '................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................';
let i;
for (i = 0; i < 100; i++) {
i = i;
}
return i;
}

function otherHalf() {
const kb2 = '................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................';
let i;
for (i = 0; i < 100; i++) {
i = i;
}
return i;
}


module.exports = {half, otherHalf};


/***/ }),
/* 3 */
/***/ (function(module, exports) {

module.exports = function() {
const kb2 = '................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................';
let i;
for (i = 0; i < 100; i++) {
i = i;
}
return i;
}


/***/ })
/******/ ]);
//# sourceMappingURL=bundle.js.map
14 changes: 14 additions & 0 deletions lighthouse-cli/test/fixtures/byte-efficiency/bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lighthouse-cli/test/fixtures/byte-efficiency/tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
}
</style>
<script src="script.js"></script>
<script src="bundle.js"></script>
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const expectations = [
wastedBytes: '6559 +/- 100',
wastedPercent: 100,
},
{
url: 'http://localhost:10200/byte-efficiency/bundle.js',
totalBytes: '13000 +/- 1000',
wastedBytes: '2500 +/- 100',
wastedPercent: '19 +/- 5',
},
],
},
},
Expand All @@ -60,9 +66,38 @@ const expectations = [
details: {
overallSavingsBytes: '>=25000',
overallSavingsMs: '>300',
items: {
length: 2,
},
items: [
{
url: 'http://localhost:10200/byte-efficiency/script.js',
totalBytes: '53000 +/- 1000',
wastedBytes: '22000 +/- 1000',
},
{
url: 'http://localhost:10200/byte-efficiency/tester.html',
totalBytes: '15000 +/- 1000',
wastedBytes: '6500 +/- 1000',
},
{
url: 'http://localhost:10200/byte-efficiency/bundle.js',
totalBytes: 13064,
wastedBytes: 5870,
sources: [
'webpack:///./c.js',
'webpack:///./b.js',
'webpack:///webpack/bootstrap',
],
sourceBytes: [
2223,
4432,
2740,
],
sourceWastedBytes: [
2204,
2198,
1234,
],
},
],
},
},
'offscreen-images': {
Expand Down Expand Up @@ -94,7 +129,7 @@ const expectations = [
overallSavingsMs: '>700',
overallSavingsBytes: '>50000',
items: {
length: 2,
length: 3,
},
},
},
Expand Down
Loading