Skip to content

Commit ccf966d

Browse files
committed
first pass
1 parent a415a23 commit ccf966d

3 files changed

Lines changed: 99 additions & 16 deletions

File tree

build/build-bundle.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const path = require('path');
1616
const LighthouseRunner = require('../lighthouse-core/runner.js');
1717
const babel = require('babel-core');
1818
const browserify = require('browserify');
19+
const exorcist = require('exorcist');
20+
const sourcemapValidator = require('sourcemap-validator');
1921
const makeDir = require('make-dir');
2022
const pkg = require('../package.json');
2123

@@ -38,7 +40,7 @@ const isDevtools = file => path.basename(file).includes('devtools');
3840
/** @param {string} file */
3941
const isExtension = file => path.basename(file).includes('extension');
4042

41-
const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n`;
43+
const BANNER = `lighthouse, browserified. ${VERSION} (${COMMIT_HASH})`;
4244
const DEBUG = false; // true for sourcemaps
4345

4446
/**
@@ -50,7 +52,7 @@ const DEBUG = false; // true for sourcemaps
5052
* @return {Promise<void>}
5153
*/
5254
async function browserifyFile(entryPath, distPath) {
53-
let bundle = browserify(entryPath, {debug: DEBUG});
55+
let bundle = browserify(entryPath, {debug: true});
5456

5557
bundle
5658
// Transform the fs.readFile etc into inline strings.
@@ -107,7 +109,9 @@ async function browserifyFile(entryPath, distPath) {
107109
writeStream.on('finish', resolve);
108110
writeStream.on('error', reject);
109111

110-
bundleStream.pipe(writeStream);
112+
bundleStream
113+
.pipe(exorcist(`${distPath}.map`))
114+
.pipe(writeStream);
111115
});
112116
}
113117

@@ -120,16 +124,23 @@ function minifyScript(filePath) {
120124
compact: true, // Do not include superfluous whitespace characters and line terminators.
121125
retainLines: true, // Keep things on the same line (looks wonky but helps with stacktraces)
122126
comments: false, // Don't output comments
123-
shouldPrintComment: () => false, // Don't include @license or @preserve comments either
127+
/** @param {string} comment */
128+
shouldPrintComment: (comment) => comment.includes(BANNER), // Don't include @license or @preserve comments either
124129
plugins: [
130+
// ['add-header-comment', {
131+
// header: [BANNER],
132+
// }],
125133
'syntax-object-rest-spread',
126134
'syntax-async-generators',
127135
],
128-
// sourceMaps: 'both'
136+
inputSourceMap: JSON.parse(fs.readFileSync(`${filePath}.map`, 'utf-8')),
137+
sourceMaps: /** @type {'both'} */('both'),
129138
};
130139

131-
const minified = BANNER + babel.transformFileSync(filePath, opts).code;
132-
fs.writeFileSync(filePath, minified);
140+
const result = babel.transformFileSync(filePath, opts);
141+
// fs.writeFileSync(filePath, `// ${BANNER}\n\n\n\n\n` + result.code);
142+
fs.writeFileSync(filePath, result.code);
143+
fs.writeFileSync(`${filePath}.map`, JSON.stringify(result.map, null, 2));
133144
}
134145

135146
/**
@@ -142,6 +153,7 @@ async function build(entryPath, distPath) {
142153
await browserifyFile(entryPath, distPath);
143154
if (!DEBUG) {
144155
minifyScript(distPath);
156+
// sourcemapValidator(fs.readFileSync(distPath, 'utf-8'), fs.readFileSync(`${distPath}.map`, 'utf-8'));
145157
}
146158
}
147159

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"@types/cpy": "^5.1.0",
7777
"@types/css-font-loading-module": "^0.0.2",
7878
"@types/eslint": "^4.16.6",
79+
"@types/exorcist": "^0.4.5",
7980
"@types/gh-pages": "^2.0.0",
8081
"@types/google.analytics": "0.0.39",
8182
"@types/inquirer": "^0.0.35",
@@ -96,6 +97,7 @@
9697
"angular": "^1.7.4",
9798
"archiver": "^3.0.0",
9899
"babel-core": "^6.26.0",
100+
"babel-plugin-add-header-comment": "^1.0.3",
99101
"babel-plugin-syntax-async-generators": "^6.13.0",
100102
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
101103
"brfs": "^2.0.2",
@@ -112,6 +114,7 @@
112114
"eslint": "^4.19.1",
113115
"eslint-config-google": "^0.9.1",
114116
"eslint-plugin-local-rules": "0.1.0",
117+
"exorcist": "^1.0.1",
115118
"gh-pages": "^2.0.1",
116119
"glob": "^7.1.3",
117120
"idb-keyval": "2.2.0",
@@ -125,6 +128,7 @@
125128
"prettier": "^1.14.3",
126129
"pretty-json-stringify": "^0.0.2",
127130
"puppeteer": "^1.19.0",
131+
"sourcemap-validator": "^1.1.1",
128132
"terser": "^4.2.0",
129133
"typescript": "3.5.3",
130134
"zone.js": "^0.7.3"

yarn.lock

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@
447447
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86"
448448
integrity sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==
449449

450+
"@types/exorcist@^0.4.5":
451+
version "0.4.5"
452+
resolved "https://registry.yarnpkg.com/@types/exorcist/-/exorcist-0.4.5.tgz#613244b12490f5108f808589bc12b28450264eb8"
453+
integrity sha1-YTJEsSSQ9RCPgIWJvBKyhFAmTrg=
454+
dependencies:
455+
"@types/through" "*"
456+
450457
"@types/filesystem@*":
451458
version "0.0.28"
452459
resolved "https://registry.yarnpkg.com/@types/filesystem/-/filesystem-0.0.28.tgz#3fd7735830f2c7413cb5ac45780bc45904697b0e"
@@ -827,6 +834,11 @@ ajv@^5.2.3, ajv@^5.3.0:
827834
fast-json-stable-stringify "^2.0.0"
828835
json-schema-traverse "^0.3.0"
829836

837+
amdefine@>=0.0.4:
838+
version "1.0.1"
839+
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
840+
integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=
841+
830842
angular@^1.7.4:
831843
version "1.7.4"
832844
resolved "https://registry.yarnpkg.com/angular/-/angular-1.7.4.tgz#c1bf4884c2d470c06907737a1bf0835a9f646f31"
@@ -1194,6 +1206,11 @@ babel-messages@^6.23.0:
11941206
dependencies:
11951207
babel-runtime "^6.22.0"
11961208

1209+
babel-plugin-add-header-comment@^1.0.3:
1210+
version "1.0.3"
1211+
resolved "https://registry.yarnpkg.com/babel-plugin-add-header-comment/-/babel-plugin-add-header-comment-1.0.3.tgz#511c4901062640d5a480b4ac3edd6944195850ec"
1212+
integrity sha1-URxJAQYmQNWkgLSsPt1pRBlYUOw=
1213+
11971214
babel-plugin-istanbul@^5.1.0:
11981215
version "5.1.1"
11991216
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-5.1.1.tgz#7981590f1956d75d67630ba46f0c22493588c893"
@@ -2995,6 +3012,16 @@ exit@^0.1.2:
29953012
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
29963013
integrity sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=
29973014

3015+
exorcist@^1.0.1:
3016+
version "1.0.1"
3017+
resolved "https://registry.yarnpkg.com/exorcist/-/exorcist-1.0.1.tgz#79316e3c4885845490f7bb405c0e5b5db1167c52"
3018+
integrity sha1-eTFuPEiFhFSQ97tAXA5bXbEWfFI=
3019+
dependencies:
3020+
is-stream "~1.1.0"
3021+
minimist "0.0.5"
3022+
mkdirp "~0.5.1"
3023+
mold-source-map "~0.4.0"
3024+
29983025
expand-brackets@^2.1.4:
29993026
version "2.1.4"
30003027
resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622"
@@ -3968,7 +3995,7 @@ is-arrayish@^0.2.1:
39683995
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
39693996
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=
39703997

3971-
is-buffer@^1.0.2, is-buffer@^1.1.0, is-buffer@^1.1.5:
3998+
is-buffer@^1.1.0, is-buffer@^1.1.5:
39723999
version "1.1.6"
39734000
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
39744001
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
@@ -4186,7 +4213,7 @@ is-retry-allowed@^1.0.0:
41864213
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34"
41874214
integrity sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=
41884215

4189-
is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0:
4216+
is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0, is-stream@~1.1.0:
41904217
version "1.1.0"
41914218
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
41924219
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
@@ -4804,6 +4831,11 @@ jsesc@^2.5.1:
48044831
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
48054832
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==
48064833

4834+
jsesc@~0.3.x:
4835+
version "0.3.0"
4836+
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.3.0.tgz#1bf5ee63b4539fe2e26d0c1e99c240b97a457972"
4837+
integrity sha1-G/XuY7RTn+LibQwemcJAuXpFeXI=
4838+
48074839
json-parse-better-errors@^1.0.1:
48084840
version "1.0.2"
48094841
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
@@ -5057,6 +5089,11 @@ lodash.flattendeep@^4.4.0:
50575089
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
50585090
integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=
50595091

5092+
lodash.foreach@^4.5.0:
5093+
version "4.5.0"
5094+
resolved "https://registry.yarnpkg.com/lodash.foreach/-/lodash.foreach-4.5.0.tgz#1a6a35eace401280c7f06dddec35165ab27e3e53"
5095+
integrity sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM=
5096+
50605097
lodash.isequal@^4.5.0:
50615098
version "4.5.0"
50625099
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
@@ -5082,7 +5119,7 @@ lodash.sortby@^4.7.0:
50825119
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
50835120
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
50845121

5085-
lodash.template@^4.0.2:
5122+
lodash.template@^4.0.2, lodash.template@^4.5.0:
50865123
version "4.5.0"
50875124
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab"
50885125
integrity sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A==
@@ -5312,11 +5349,6 @@ miller-rabin@^4.0.0:
53125349
bn.js "^4.0.0"
53135350
brorand "^1.0.1"
53145351

5315-
mime-db@~1.24.0:
5316-
version "1.24.0"
5317-
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.24.0.tgz#e2d13f939f0016c6e4e9ad25a8652f126c467f0c"
5318-
integrity sha1-4tE/k58AFsbk6a0lqGUvEmxGfww=
5319-
53205352
mime-db@~1.37.0:
53215353
version "1.37.0"
53225354
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.37.0.tgz#0b6a0ce6fdbe9576e25f1f2d2fde8830dc0ad0d8"
@@ -5361,6 +5393,11 @@ minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
53615393
dependencies:
53625394
brace-expansion "^1.1.7"
53635395

5396+
minimist@0.0.5:
5397+
version "0.0.5"
5398+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.5.tgz#d7aa327bcecf518f9106ac6b8f003fa3bcea8566"
5399+
integrity sha1-16oye87PUY+RBqxrjwA/o7zqhWY=
5400+
53645401
minimist@0.0.8, minimist@~0.0.1:
53655402
version "0.0.8"
53665403
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
@@ -5379,7 +5416,7 @@ mixin-deep@^1.2.0:
53795416
for-in "^1.0.2"
53805417
is-extendable "^1.0.1"
53815418

5382-
mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1:
5419+
mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
53835420
version "0.5.1"
53845421
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
53855422
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
@@ -5412,6 +5449,14 @@ module-deps@^6.0.0:
54125449
through2 "^2.0.0"
54135450
xtend "^4.0.0"
54145451

5452+
mold-source-map@~0.4.0:
5453+
version "0.4.0"
5454+
resolved "https://registry.yarnpkg.com/mold-source-map/-/mold-source-map-0.4.0.tgz#cf67e0b31c47ab9badb5c9c25651862127bb8317"
5455+
integrity sha1-z2fgsxxHq5uttcnCVlGGISe7gxc=
5456+
dependencies:
5457+
convert-source-map "^1.1.0"
5458+
through "~2.2.7"
5459+
54155460
ms@2.0.0:
54165461
version "2.0.0"
54175462
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@@ -6876,6 +6921,23 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
68766921
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
68776922
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
68786923

6924+
source-map@~0.1.x:
6925+
version "0.1.43"
6926+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.1.43.tgz#c24bc146ca517c1471f5dacbe2571b2b7f9e3346"
6927+
integrity sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=
6928+
dependencies:
6929+
amdefine ">=0.0.4"
6930+
6931+
sourcemap-validator@^1.1.1:
6932+
version "1.1.1"
6933+
resolved "https://registry.yarnpkg.com/sourcemap-validator/-/sourcemap-validator-1.1.1.tgz#3d7d8a399ccab09c1fedc510d65436e25b1c386b"
6934+
integrity sha512-pq6y03Vs6HUaKo9bE0aLoksAcpeOo9HZd7I8pI6O480W/zxNZ9U32GfzgtPP0Pgc/K1JHna569nAbOk3X8/Qtw==
6935+
dependencies:
6936+
jsesc "~0.3.x"
6937+
lodash.foreach "^4.5.0"
6938+
lodash.template "^4.5.0"
6939+
source-map "~0.1.x"
6940+
68796941
spawn-sync@^1.0.15:
68806942
version "1.0.15"
68816943
resolved "https://registry.yarnpkg.com/spawn-sync/-/spawn-sync-1.0.15.tgz#b00799557eb7fb0c8376c29d44e8a1ea67e57476"
@@ -7331,6 +7393,11 @@ through@2, "through@>=2.2.7 <3", through@^2.3.6:
73317393
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
73327394
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
73337395

7396+
through@~2.2.7:
7397+
version "2.2.7"
7398+
resolved "https://registry.yarnpkg.com/through/-/through-2.2.7.tgz#6e8e21200191d4eb6a99f6f010df46aa1c6eb2bd"
7399+
integrity sha1-bo4hIAGR1OtqmfbwEN9Gqhxusr0=
7400+
73347401
timed-out@4.0.1, timed-out@^4.0.0:
73357402
version "4.0.1"
73367403
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"

0 commit comments

Comments
 (0)