From 5c9cb0b7872d842bc5465894e1b2844ee352556c Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 27 Apr 2018 18:15:50 -0700 Subject: [PATCH 1/3] build - minify via gulp-uglify-es instead of uglifyify --- gulpfile.js | 20 ++++++++++---------- package.json | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4f0da9d60..e844a4cba 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -484,16 +484,6 @@ function generateBundler(opts, performBundle) { NODE_ENV: opts.devMode ? 'development' : 'production', })) - // Minification - if (opts.minifyBuild) { - bundler.transform('uglifyify', { - global: true, - mangle: { - reserved: [ 'MetamaskInpageProvider' ] - }, - }) - } - if (opts.watch) { bundler = watchify(bundler) // on any file update, re-runs the bundler @@ -567,6 +557,16 @@ function bundleTask(opts) { .pipe(sourcemaps.init({ loadMaps: true })) } + // Minification + if (opts.minifyBuild) { + buildStream = buildStream + .pipe(uglify({ + mangle: { + reserved: [ 'MetamaskInpageProvider' ] + }, + })) + } + // Finalize Source Maps (writes .map file) if (opts.buildSourceMaps) { buildStream = buildStream diff --git a/package.json b/package.json index 73892bc28..953d8d7ac 100644 --- a/package.json +++ b/package.json @@ -272,7 +272,6 @@ "stylelint-config-standard": "^18.2.0", "tape": "^4.5.1", "testem": "^2.0.0", - "uglifyify": "github:MetaMask/uglifyify#keep-flags", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0", "watchify": "^3.9.0" From f4fe3e81c16073c06aef489252f31cabef8b2214 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 27 Apr 2018 18:17:21 -0700 Subject: [PATCH 2/3] development - add sourcemap debug tool --- development/sourcemap-validator.js | 49 ++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 50 insertions(+) create mode 100644 development/sourcemap-validator.js diff --git a/development/sourcemap-validator.js b/development/sourcemap-validator.js new file mode 100644 index 000000000..edc97667a --- /dev/null +++ b/development/sourcemap-validator.js @@ -0,0 +1,49 @@ +const fs = require('fs') +const { SourceMapConsumer } = require('source-map') + +// +// Utility to help check if sourcemaps are working +// +// searches `dist/chrome/inpage.js` for "new Error" statements +// and prints their source lines using the sourcemaps. +// if not working it may error or print minified garbage +// + +start() + +async function start() { + const rawBuild = fs.readFileSync(__dirname + '/../dist/chrome/inpage.js', 'utf8') + const rawSourceMap = fs.readFileSync(__dirname + '/../dist/sourcemaps/inpage.js.map', 'utf8') + const consumer = await new SourceMapConsumer(rawSourceMap) + + console.log('hasContentsOfAllSources:', consumer.hasContentsOfAllSources(), '\n') + console.log('sources:') + consumer.sources.map((sourcePath) => console.log(sourcePath)) + + console.log('\nexamining "new Error" statements:\n') + const sourceLines = rawBuild.split('\n') + sourceLines.map(line => indicesOf('new Error', line)) + .forEach((errorIndices, lineIndex) => { + // if (errorIndex === null) return console.log('line does not contain "new Error"') + errorIndices.forEach((errorIndex) => { + const position = { line: lineIndex + 1, column: errorIndex } + const result = consumer.originalPositionFor(position) + if (!result.source) return console.warn(`!! missing source for position: ${position}`) + // filter out deps distributed minified without sourcemaps + if (result.source === 'node_modules/browserify/node_modules/browser-pack/_prelude.js') return // minified mess + if (result.source === 'node_modules/web3/dist/web3.min.js') return // minified mess + const sourceContent = consumer.sourceContentFor(result.source) + const sourceLines = sourceContent.split('\n') + const line = sourceLines[result.line-1] + console.log(`\n========================== ${result.source} ====================================\n`) + console.log(line) + console.log(`\n==============================================================================\n`) + }) + }) +} + +function indicesOf(substring, string) { + var a=[],i=-1; + while((i=string.indexOf(substring,i+1)) >= 0) a.push(i); + return a; +} diff --git a/package.json b/package.json index 953d8d7ac..39182fba0 100644 --- a/package.json +++ b/package.json @@ -269,6 +269,7 @@ "selenium-webdriver": "^3.5.0", "shell-parallel": "^1.0.3", "sinon": "^5.0.0", + "source-map": "^0.7.2", "stylelint-config-standard": "^18.2.0", "tape": "^4.5.1", "testem": "^2.0.0", From 1a60f42933739ae69f7ff0ac4ba56f4f4c9bfff5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 27 Apr 2018 18:17:31 -0700 Subject: [PATCH 3/3] deps - package-lock --- package-lock.json | 94 ++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5b5b82450..ae9bbb420 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3603,6 +3603,14 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-3.0.4.tgz", "integrity": "sha1-LcvSwofLwKVcxCMovQxzYVDVPj8=" + }, + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "requires": { + "amdefine": "1.0.1" + } } } }, @@ -4833,6 +4841,15 @@ "string_decoder": "0.10.31" } }, + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "dev": true, + "requires": { + "amdefine": "1.0.1" + } + }, "string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", @@ -10422,7 +10439,7 @@ "debug-fabulous": "1.0.0", "detect-newline": "2.1.0", "graceful-fs": "4.1.11", - "source-map": "0.4.4", + "source-map": "0.7.2", "strip-bom-string": "1.0.0", "through2": "2.0.3" }, @@ -11933,6 +11950,16 @@ "integrity": "sha1-Skxd2OT7Xps82mDIIt+tyu5m4K8=", "requires": { "source-map": "0.4.4" + }, + "dependencies": { + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "requires": { + "amdefine": "1.0.1" + } + } } }, "inquirer": { @@ -21856,6 +21883,16 @@ "requires": { "js-base64": "2.4.3", "source-map": "0.4.4" + }, + "dependencies": { + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "requires": { + "amdefine": "1.0.1" + } + } } }, "secp256k1": { @@ -22718,12 +22755,10 @@ "integrity": "sha512-I2UmuJSRr/T8jisiROLU3A3ltr+swpniSmNPI4Ml3ZCX6tVnDsuZzK7F2hl5jTqbZBWCEKlj5HRQiPExXLgE8A==" }, "source-map": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", - "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", - "requires": { - "amdefine": "1.0.1" - } + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.2.tgz", + "integrity": "sha512-NDJB/R2BS7YJG0tP9SbE4DKwKj1idLT5RJqfVYZ7dreFX7wulZT3xxVhbYKrQo9n0JkRptl51TrX/5VK3HodMA==", + "dev": true }, "source-map-resolve": { "version": "0.5.1", @@ -22920,7 +22955,7 @@ "requires": { "esprima": "1.0.4", "estraverse": "1.3.2", - "source-map": "0.4.4" + "source-map": "0.7.2" } }, "esprima": { @@ -24972,55 +25007,12 @@ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz", "integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g==" }, - "uglify-es": { - "version": "3.3.9", - "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz", - "integrity": "sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ==", - "dev": true, - "requires": { - "commander": "2.13.0", - "source-map": "0.6.1" - }, - "dependencies": { - "commander": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz", - "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==", - "dev": true - }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, "uglify-to-browserify": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", "optional": true }, - "uglifyify": { - "version": "github:MetaMask/uglifyify#8662585e39125a96a5379d71cb4a606829790f87", - "dev": true, - "requires": { - "convert-source-map": "1.1.3", - "extend": "1.3.0", - "minimatch": "3.0.4", - "through": "2.3.8", - "uglify-es": "3.3.9" - }, - "dependencies": { - "extend": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extend/-/extend-1.3.0.tgz", - "integrity": "sha1-0VFvsP9WJNLr+RI+odrFoZlABPg=", - "dev": true - } - } - }, "ultron": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz",