Skip to content

Commit 5f1f244

Browse files
committed
fix processing of JSON files in build pipeline
1 parent e2abf6e commit 5f1f244

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
"deep-equal": "^2.2.3",
134134
"ecstatic": "^4.1.4",
135135
"esbuild": "^0.25.5",
136-
"esbuild-plugin-browserify-adapter": "^0.1.4",
137136
"esbuild-plugin-environment": "^0.4.0",
138137
"esbuild-plugin-glsl": "^1.2.2",
139138
"esbuild-plugin-inline-css": "^0.0.1",
@@ -182,4 +181,4 @@
182181
"acorn": "^8.1.1"
183182
}
184183
}
185-
}
184+
}

tasks/compress_attributes.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var through = require('through2');
1+
const fs = require('fs');
22

33
/**
4-
* Browserify transform that strips meta attributes out
4+
* ESBuild plugin that strips out meta attributes
55
* of the plotly.js bundles
66
*/
77

@@ -35,22 +35,26 @@ function makeRegex(regexStr) {
3535
);
3636
}
3737

38-
module.exports = function() {
39-
var allChunks = [];
40-
return through(function(chunk, enc, next) {
41-
allChunks.push(chunk);
42-
next();
43-
}, function(done) {
44-
var str = Buffer.concat(allChunks).toString('utf-8');
45-
this.push(
46-
str
47-
.replace(makeStringRegex('description'), '')
48-
.replace(makeJoinedArrayRegex('description'), '')
49-
.replace(makeArrayRegex('requiredOpts'), '')
50-
.replace(makeArrayRegex('otherOpts'), '')
51-
.replace(makeStringRegex('role'), '')
52-
.replace(makeStringRegex('hrName'), '')
53-
);
54-
done();
55-
});
38+
const allRegexes = [
39+
makeStringRegex('description'),
40+
makeJoinedArrayRegex('description'),
41+
makeArrayRegex('requiredOpts'),
42+
makeArrayRegex('otherOpts'),
43+
makeStringRegex('role'),
44+
makeStringRegex('hrName')
45+
];
46+
47+
var esbuildPluginStripMeta = {
48+
name: 'strip-meta-attributes',
49+
setup(build) {
50+
const loader = 'js';
51+
build.onLoad({ filter: /\.js$/ }, async file => ({
52+
contents: await fs.promises.readFile(file.path, 'utf-8').then(c => {
53+
allRegexes.forEach(r => { c = c.replace(r, ''); });
54+
return c;
55+
}), loader
56+
}));
57+
}
5658
};
59+
60+
module.exports = esbuildPluginStripMeta;

tasks/util/bundle_wrapper.mjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import prependFile from 'prepend-file';
55
import { build } from 'esbuild';
66

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

10-
import transform from '../../tasks/compress_attributes.js';
1110
import common from './common.js';
1211

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

33-
var config = {...esbuildConfig};
32+
var config = { ...esbuildConfig };
3433

3534
config.entryPoints = [pathToIndex];
3635
config.outfile = pathToBundle;
3736
config.minify = !!opts.minify;
3837

3938
if(!opts.noCompressAttributes) {
40-
config.plugins = basePlugins.concat([browserifyAdapter(transform)]);
39+
config.plugins = basePlugins.concat([esbuildPluginStripMeta]);
4140
}
4241

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

5251
// Until https://github.com/evanw/esbuild/pull/513 is merged
5352
// Thanks to https://github.com/prantlf and https://github.com/birkskyum
54-
function addWrapper(path){
53+
function addWrapper(path) {
5554
prependFile.sync(
5655
path,
5756
[

0 commit comments

Comments
 (0)