From 328af5fdd5442bc4fcb8fb3ac699a6bce0ec86c8 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 28 Nov 2017 18:01:10 -0500 Subject: [PATCH 1/5] Upgrade bundling to uglify-es Conflicts: package.json --- package.json | 4 +++- tasks/bundle.js | 2 ++ tasks/util/browserify_wrapper.js | 40 ++++++++++++++++---------------- tasks/util/constants.js | 21 +++++++++++++---- tasks/util/patch_minified.js | 22 ------------------ 5 files changed, 42 insertions(+), 47 deletions(-) delete mode 100644 tasks/util/patch_minified.js diff --git a/package.json b/package.json index 303f6c4993e..527c436dba1 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,8 @@ "3d-view": "^2.0.0", "@plotly/d3-sankey": "^0.5.0", "alpha-shape": "^1.0.0", + "bubleify": "^1.0.0", + "canvas-fit": "^1.5.0", "color-rgba": "^1.1.1", "convex-hull": "^1.0.3", "country-regex": "^1.1.0", @@ -86,6 +88,7 @@ "has-hover": "^1.0.1", "mapbox-gl": "^0.22.0", "matrix-camera-controller": "^2.1.3", + "minify-stream": "^1.1.0", "mouse-change": "^1.4.0", "mouse-event-offset": "^3.0.2", "mouse-wheel": "^1.0.2", @@ -140,7 +143,6 @@ "read-last-lines": "^1.1.0", "requirejs": "^2.3.1", "through2": "^2.0.3", - "uglify-js": "^2.8.12", "watchify": "^3.9.0", "xml2js": "^0.4.16" } diff --git a/tasks/bundle.js b/tasks/bundle.js index b1a175d4654..f3062c1d115 100644 --- a/tasks/bundle.js +++ b/tasks/bundle.js @@ -33,6 +33,7 @@ _bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, { pathToMinBundle: constants.pathToPlotlyDistMin }); + // Browserify the geo assets _bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, { standalone: 'PlotlyGeoAssets' @@ -53,3 +54,4 @@ constants.partialBundlePaths.forEach(function(pathObj) { pathToMinBundle: pathObj.distMin }); }); + diff --git a/tasks/util/browserify_wrapper.js b/tasks/util/browserify_wrapper.js index fa57092764e..3fd477a584f 100644 --- a/tasks/util/browserify_wrapper.js +++ b/tasks/util/browserify_wrapper.js @@ -2,11 +2,11 @@ var fs = require('fs'); var path = require('path'); var browserify = require('browserify'); -var UglifyJS = require('uglify-js'); +var bubleify = require('bubleify'); +var minify = require('minify-stream'); var constants = require('./constants'); var compressAttributes = require('./compress_attributes'); -var patchMinified = require('./patch_minified'); var strictD3 = require('./strict_d3'); /** Convenience browserify wrapper @@ -46,30 +46,30 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts) { } var b = browserify(pathToIndex, browserifyOpts); - var bundleWriteStream = fs.createWriteStream(pathToBundle); - bundleWriteStream.on('finish', function() { - logger(pathToBundle); - if(opts.then) { - opts.then(); - } - }); + b.transform(bubleify, constants.bubleifyOptions); - b.bundle(function(err, buf) { + var bundleStream = b.bundle(function(err, buf) { if(err) throw err; + }) - if(outputMinified) { - var minifiedCode = UglifyJS.minify(buf.toString(), constants.uglifyOptions).code; - minifiedCode = patchMinified(minifiedCode); - - fs.writeFile(pathToMinBundle, minifiedCode, function(err) { - if(err) throw err; - + if (outputMinified) { + bundleStream + .pipe(minify(constants.uglifyOptions)) + .pipe(fs.createWriteStream(pathToMinBundle)) + .on('finish', function() { logger(pathToMinBundle); }); - } - }) - .pipe(bundleWriteStream); + } + + bundleStream + .pipe(fs.createWriteStream(pathToBundle)) + .on('finish', function() { + logger(pathToBundle); + if(opts.then) { + opts.then(); + } + }); }; function logger(pathToOutput) { diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 1815c740616..3f65761597a 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -84,16 +84,29 @@ module.exports = { testContainerHome: '/var/www/streambed/image_server/plotly.js', uglifyOptions: { - fromString: true, mangle: true, compress: { - warnings: false, - screw_ie8: true + warnings: false }, output: { beautify: false, ascii_only: true - } + }, + sourceMap: false + }, + + bubleifyOptions: { + target: { + chrome: 48, + firefox: 44, + edge: 12 + }, + transforms: { + arrow: true, + defaultParameter: false, + dangerousForOf: true, + }, + sourceMap: false }, licenseDist: [ diff --git a/tasks/util/patch_minified.js b/tasks/util/patch_minified.js deleted file mode 100644 index e1388c71fa4..00000000000 --- a/tasks/util/patch_minified.js +++ /dev/null @@ -1,22 +0,0 @@ -var PATTERN = /require\("\+(\w)\((\w)\)\+"\)/; -var NEW_SUBSTR = 'require("+ $1($2) +")'; - -/* Uber hacky in-house fix to - * - * https://github.com/substack/webworkify/issues/29 - * - * so that plotly.min.js loads in Jupyter NBs, more info here: - * - * - https://github.com/plotly/plotly.py/pull/545 - * - https://github.com/plotly/plotly.js/pull/914 - * - https://github.com/plotly/plotly.js/pull/1094 - * - * For example, this routine replaces - * 'require("+o(s)+")' -> 'require("+ o(s) +")' - * - * But works for any 1-letter variable that uglify-js may output. - * - */ -module.exports = function patchMinified(minifiedCode) { - return minifiedCode.replace(PATTERN, NEW_SUBSTR); -}; From 41be06ff506856732bc336ec6ef074baa05b07e6 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 28 Nov 2017 18:07:33 -0500 Subject: [PATCH 2/5] Remove unused dep --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 527c436dba1..fa8620db081 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "@plotly/d3-sankey": "^0.5.0", "alpha-shape": "^1.0.0", "bubleify": "^1.0.0", - "canvas-fit": "^1.5.0", "color-rgba": "^1.1.1", "convex-hull": "^1.0.3", "country-regex": "^1.1.0", From a399671f69d5ebf3b87770c468d0cb701bc59a73 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 28 Nov 2017 18:25:10 -0500 Subject: [PATCH 3/5] Lintify --- tasks/bundle.js | 1 - tasks/util/browserify_wrapper.js | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tasks/bundle.js b/tasks/bundle.js index f3062c1d115..dd767f018ff 100644 --- a/tasks/bundle.js +++ b/tasks/bundle.js @@ -54,4 +54,3 @@ constants.partialBundlePaths.forEach(function(pathObj) { pathToMinBundle: pathObj.distMin }); }); - diff --git a/tasks/util/browserify_wrapper.js b/tasks/util/browserify_wrapper.js index 3fd477a584f..e4803d94e8c 100644 --- a/tasks/util/browserify_wrapper.js +++ b/tasks/util/browserify_wrapper.js @@ -49,11 +49,11 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts) { b.transform(bubleify, constants.bubleifyOptions); - var bundleStream = b.bundle(function(err, buf) { + var bundleStream = b.bundle(function(err) { if(err) throw err; - }) + }); - if (outputMinified) { + if(outputMinified) { bundleStream .pipe(minify(constants.uglifyOptions)) .pipe(fs.createWriteStream(pathToMinBundle)) From a053c2668734e740b2fd45e83acd530b241fff49 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 28 Nov 2017 18:54:41 -0500 Subject: [PATCH 4/5] Use cross-spawn for windows stats calc --- package.json | 1 + tasks/stats.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fa8620db081..842125b5353 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "brfs": "^1.4.3", "browserify": "^14.1.0", "browserify-transform-tools": "^1.7.0", + "cross-spawn": "^5.1.0", "deep-equal": "^1.0.1", "ecstatic": "^2.1.0", "eslint": "^3.17.1", diff --git a/tasks/stats.js b/tasks/stats.js index 6478db4a47a..63227f1f5b4 100644 --- a/tasks/stats.js +++ b/tasks/stats.js @@ -1,6 +1,6 @@ var path = require('path'); var fs = require('fs'); -var spawn = require('child_process').spawn; +var spawn = require('cross-spawn'); var falafel = require('falafel'); var gzipSize = require('gzip-size'); From 25fd2e4dde786b9524d371507e8438d1e893c322 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 29 Nov 2017 17:43:09 -0500 Subject: [PATCH 5/5] Remove bubleify --- package.json | 1 - tasks/util/browserify_wrapper.js | 3 --- tasks/util/constants.js | 14 -------------- 3 files changed, 18 deletions(-) diff --git a/package.json b/package.json index 842125b5353..1f15d00c564 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "3d-view": "^2.0.0", "@plotly/d3-sankey": "^0.5.0", "alpha-shape": "^1.0.0", - "bubleify": "^1.0.0", "color-rgba": "^1.1.1", "convex-hull": "^1.0.3", "country-regex": "^1.1.0", diff --git a/tasks/util/browserify_wrapper.js b/tasks/util/browserify_wrapper.js index e4803d94e8c..65a8de6c07b 100644 --- a/tasks/util/browserify_wrapper.js +++ b/tasks/util/browserify_wrapper.js @@ -2,7 +2,6 @@ var fs = require('fs'); var path = require('path'); var browserify = require('browserify'); -var bubleify = require('bubleify'); var minify = require('minify-stream'); var constants = require('./constants'); @@ -47,8 +46,6 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts) { var b = browserify(pathToIndex, browserifyOpts); - b.transform(bubleify, constants.bubleifyOptions); - var bundleStream = b.bundle(function(err) { if(err) throw err; }); diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 3f65761597a..46f0ba357d4 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -95,20 +95,6 @@ module.exports = { sourceMap: false }, - bubleifyOptions: { - target: { - chrome: 48, - firefox: 44, - edge: 12 - }, - transforms: { - arrow: true, - defaultParameter: false, - dangerousForOf: true, - }, - sourceMap: false - }, - licenseDist: [ '/**', '* plotly.js v' + pkg.version,