Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
7 changes: 0 additions & 7 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
"deep-equal": "^2.2.3",
"ecstatic": "^4.1.4",
"esbuild": "^0.25.5",
"esbuild-plugin-browserify-adapter": "^0.1.4",
"esbuild-plugin-environment": "^0.4.0",
"esbuild-plugin-glsl": "^1.2.2",
"esbuild-plugin-inline-css": "^0.0.1",
Expand Down Expand Up @@ -182,4 +181,4 @@
"acorn": "^8.1.1"
}
}
}
}
44 changes: 24 additions & 20 deletions tasks/compress_attributes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var through = require('through2');
const fs = require('fs');

/**
* Browserify transform that strips meta attributes out
* ESBuild plugin that strips out meta attributes
* of the plotly.js bundles
*/

Expand Down Expand Up @@ -35,22 +35,26 @@ function makeRegex(regexStr) {
);
}

module.exports = function() {
var allChunks = [];
return through(function(chunk, enc, next) {
allChunks.push(chunk);
next();
}, function(done) {
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('role'), '')
.replace(makeStringRegex('hrName'), '')
);
done();
});
const allRegexes = [
makeStringRegex('description'),
makeJoinedArrayRegex('description'),
makeArrayRegex('requiredOpts'),
makeArrayRegex('otherOpts'),
makeStringRegex('role'),
makeStringRegex('hrName')
];

var esbuildPluginStripMeta = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var esbuildPluginStripMeta = {
const esbuildPluginStripMeta = {

name: 'strip-meta-attributes',
setup(build) {
const loader = 'js';
build.onLoad({ filter: /\.js$/ }, async file => ({
contents: await fs.promises.readFile(file.path, 'utf-8').then(c => {
allRegexes.forEach(r => { c = c.replace(r, ''); });
return c;
}), loader
}));
}
};

module.exports = esbuildPluginStripMeta;
9 changes: 4 additions & 5 deletions tasks/util/bundle_wrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import prependFile from 'prepend-file';
import { build } from 'esbuild';

import esbuildConfig from '../../esbuild-config.js';
import browserifyAdapter from 'esbuild-plugin-browserify-adapter';
import esbuildPluginStripMeta from '../../tasks/compress_attributes.js';

import transform from '../../tasks/compress_attributes.js';
import common from './common.js';

var basePlugins = esbuildConfig.plugins;
Expand All @@ -30,14 +29,14 @@ var basePlugins = esbuildConfig.plugins;
export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {
opts = opts || {};

var config = {...esbuildConfig};
var config = { ...esbuildConfig };

config.entryPoints = [pathToIndex];
config.outfile = pathToBundle;
config.minify = !!opts.minify;

if(!opts.noCompressAttributes) {
config.plugins = basePlugins.concat([browserifyAdapter(transform)]);
config.plugins = basePlugins.concat([esbuildPluginStripMeta]);
}

if(opts.noPlugins) config.plugins = [];
Expand All @@ -51,7 +50,7 @@ export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {

// Until https://github.com/evanw/esbuild/pull/513 is merged
// Thanks to https://github.com/prantlf and https://github.com/birkskyum
function addWrapper(path){
function addWrapper(path) {
prependFile.sync(
path,
[
Expand Down
Binary file modified test/image/baselines/gl2d_scatter-colorscale-colorbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion test/image/mocks/gl2d_scatter-colorscale-colorbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"marker": {
"size": 20
},
"text": ["orange"],
"textposition": "top center",
"type": "scattergl",
"mode": "markers"
"mode": "text+markers"
}
],
"layout": {
Expand Down