From 5bfbe11d2874c69fdbb0f30fd45e9adf609d5ce0 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 19 Jan 2021 23:21:27 -0500 Subject: [PATCH 1/4] let no-bad-char run first to catch unexpected characters --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f7b260b35e1..a2db5382754 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -166,12 +166,12 @@ jobs: echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.js echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.min.js echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plot-schema.json - - run: - name: Test certain bundles against function constructors - command: npm run no-new-func - run: name: Test plotly bundles againt unexpected characters command: npm run no-bad-char + - run: + name: Test certain bundles against function constructors + command: npm run no-new-func workflows: version: 2 From bb88cabfae183bdfe7c236def410502dea4a40b3 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 19 Jan 2021 23:23:05 -0500 Subject: [PATCH 2/4] apply regex on the whole not on every chunk --- tasks/compress_attributes.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tasks/compress_attributes.js b/tasks/compress_attributes.js index 0fe6f1158d7..42f489e0810 100644 --- a/tasks/compress_attributes.js +++ b/tasks/compress_attributes.js @@ -33,11 +33,12 @@ var regexStr = [ var regex = new RegExp(regexStr, 'g'); module.exports = function() { - return through(function(buf, enc, next) { - this.push( - buf.toString('utf-8') - .replace(regex, '') - ); + var allChunks = []; + return through(function(chunk, enc, next) { + allChunks.push(chunk); next(); + }, function(done) { + this.push(Buffer.concat(allChunks).toString().replace(regex, '')); + done(); }); }; From ed0195b44ce3d06ede6cdb940c467f5dd4f7e3d6 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 20 Jan 2021 16:47:01 -0500 Subject: [PATCH 3/4] refactor compress attrs --- tasks/compress_attributes.js | 37 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tasks/compress_attributes.js b/tasks/compress_attributes.js index 42f489e0810..139086e8900 100644 --- a/tasks/compress_attributes.js +++ b/tasks/compress_attributes.js @@ -8,29 +8,30 @@ var through = require('through2'); // one line string with or without trailing comma function makeStringRegex(attr) { - return attr + ': \'.*\'' + ',?'; + return makeRegex( + attr + ': \'.*\'' + ',?' + ); } // joined array of strings with or without trailing comma function makeJoinedArrayRegex(attr) { - return attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?'; + return makeRegex( + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?' + ); } // array with or without trailing comma function makeArrayRegex(attr) { - return attr + ': \\[[\\s\\S]*?\\]' + ',?'; + return makeRegex( + attr + ': \\[[\\s\\S]*?\\]' + ',?' + ); } -// ref: http://www.regexr.com/3cmac -var regexStr = [ - makeStringRegex('description'), - makeJoinedArrayRegex('description'), - makeArrayRegex('requiredOpts'), - makeArrayRegex('otherOpts'), - makeStringRegex('hrName') -].join('|'); - -var regex = new RegExp(regexStr, 'g'); +function makeRegex(regexStr) { + return ( + new RegExp(regexStr, 'g') + ); +} module.exports = function() { var allChunks = []; @@ -38,7 +39,15 @@ module.exports = function() { allChunks.push(chunk); next(); }, function(done) { - this.push(Buffer.concat(allChunks).toString().replace(regex, '')); + var str = Buffer.concat(allChunks).toString('utf-8'); + this.push( + str + .replace(makeStringRegex('description'), '') + .replace(makeJoinedArrayRegex('description'), '') + .replace(makeArrayRegex('requiredOpts'), '') + .replace(makeArrayRegex('otherOpts'), '') + .replace(makeStringRegex('hrName'), '') + ); done(); }); }; From f68214bf7aafac12e64fbec4f8e9b95f4e247fb6 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 20 Jan 2021 18:07:38 -0500 Subject: [PATCH 4/4] Revert "remove return Plotly" This reverts commit 1fc1c035b16672e4d314ac1b55fcbc3fce308714. --- lib/index-basic.js | 3 +-- lib/index-cartesian.js | 3 +-- lib/index-finance.js | 3 +-- lib/index-geo.js | 3 +-- lib/index-gl2d.js | 3 +-- lib/index-gl3d.js | 3 +-- lib/index-mapbox.js | 3 +-- lib/index-strict.js | 3 +-- lib/index.js | 3 +-- lib/register_extra.js | 2 ++ 10 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/index-basic.js b/lib/index-basic.js index e445f45122d..ca431c84c6d 100644 --- a/lib/index-basic.js +++ b/lib/index-basic.js @@ -15,5 +15,4 @@ Plotly.register([ require('./pie') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-cartesian.js b/lib/index-cartesian.js index 50a1fcd09b7..94167d90d52 100644 --- a/lib/index-cartesian.js +++ b/lib/index-cartesian.js @@ -24,5 +24,4 @@ Plotly.register([ require('./violin') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-finance.js b/lib/index-finance.js index f6491a52d05..2f9be8733b8 100644 --- a/lib/index-finance.js +++ b/lib/index-finance.js @@ -22,5 +22,4 @@ Plotly.register([ require('./indicator') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-geo.js b/lib/index-geo.js index 1a673119f57..0bb5fb2145f 100644 --- a/lib/index-geo.js +++ b/lib/index-geo.js @@ -15,5 +15,4 @@ Plotly.register([ require('./choropleth') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-gl2d.js b/lib/index-gl2d.js index 20b75b60868..ad78095ed80 100644 --- a/lib/index-gl2d.js +++ b/lib/index-gl2d.js @@ -17,5 +17,4 @@ Plotly.register([ require('./parcoords') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-gl3d.js b/lib/index-gl3d.js index de23519bc76..800995e5608 100644 --- a/lib/index-gl3d.js +++ b/lib/index-gl3d.js @@ -20,5 +20,4 @@ Plotly.register([ require('./streamtube') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-mapbox.js b/lib/index-mapbox.js index ef337768dbb..272387d9810 100644 --- a/lib/index-mapbox.js +++ b/lib/index-mapbox.js @@ -16,5 +16,4 @@ Plotly.register([ require('./densitymapbox') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index-strict.js b/lib/index-strict.js index 24b5f21295b..43948f1e68e 100644 --- a/lib/index-strict.js +++ b/lib/index-strict.js @@ -56,5 +56,4 @@ Plotly.register([ require('./barpolar') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/index.js b/lib/index.js index 4cf645eecbe..72930ceb362 100644 --- a/lib/index.js +++ b/lib/index.js @@ -71,5 +71,4 @@ Plotly.register([ require('./barpolar') ]); -require('./register_extra')(Plotly); -module.exports = Plotly; +module.exports = require('./register_extra')(Plotly); diff --git a/lib/register_extra.js b/lib/register_extra.js index 822125b419d..896edf5cb38 100644 --- a/lib/register_extra.js +++ b/lib/register_extra.js @@ -30,4 +30,6 @@ module.exports = function registerExtra(Plotly) { Plotly.register([ require('./calendars') ]); + + return Plotly; };