Skip to content

Commit

Permalink
Merge pull request #6557 from CallumNZ/custom-bundle-strict
Browse files Browse the repository at this point in the history
Add --strict option to custom bundle
  • Loading branch information
archmoj authored Apr 17, 2023
2 parents 3f8cfe7 + 174d387 commit 21d09a6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CUSTOM_BUNDLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Or use `transforms none` to exclude them all.
npm run custom-bundle -- --transforms none
```

Use the `strict` option to use strict trace types where possible.
```sh
npm run custom-bundle -- --traces scatter,scattergl --strict
```

Use the `out` option to change the bundle filename (default `custom`).
The new bundle will be created in the `dist/` directory and named `plotly-<out>.min.js` or `plotly-<out>.js` if unminified.
```sh
Expand Down
1 change: 1 addition & 0 deletions draftlogs/6557_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add strict option to custom bundle command [[#6557](https://github.com/plotly/plotly.js/pull/6557)], with thanks to @CallumNZ for the contribution!
4 changes: 3 additions & 1 deletion tasks/custom_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ if(process.argv.length > 2) {
var out = args.out ? args.out : 'custom';
var traces = inputArray(args.traces, allTraces);
var transforms = inputArray(args.transforms, allTransforms);
var strict = inputBoolean(args.strict, false);

var opts = {
traceList: createList(['scatter'], traces, allTraces, 'trace'),
transformList: createList([], transforms, allTransforms, 'transform'),

name: out,
index: path.join(constants.pathToLib, 'index-' + out + '.js')
index: path.join(constants.pathToLib, 'index-' + (strict ? 'strict-' : '') + out + '.js'),
strict: strict,
};

if(unminified) {
Expand Down
15 changes: 8 additions & 7 deletions tasks/partial_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var header = constants.licenseDist + '\n';
var allTransforms = constants.allTransforms;
var allTraces = constants.allTraces;
var mainIndex = constants.mainIndex;
var strictIndex = constants.strictIndex;

// Bundle the plotly.js partial bundles
module.exports = function partialBundle(tasks, opts) {
Expand All @@ -19,11 +20,12 @@ module.exports = function partialBundle(tasks, opts) {
var traceList = opts.traceList;
var transformList = opts.transformList;
var calendars = opts.calendars;
var strict = opts.strict;

// skip strict bundle which is no longer a partial bundle and has a special index file for regl traces
if(name !== 'strict') {
tasks.push(function(done) {
var partialIndex = mainIndex;
var partialIndex = (strict) ? strictIndex : mainIndex;

var all = ['calendars'].concat(allTransforms).concat(allTraces);
var includes = (calendars ? ['calendars'] : []).concat(transformList).concat(traceList);
Expand All @@ -32,12 +34,11 @@ module.exports = function partialBundle(tasks, opts) {
excludes.forEach(function(t) {
var WHITESPACE_BEFORE = '\\s*';
// remove require
var newCode = partialIndex.replace(
new RegExp(
WHITESPACE_BEFORE +
'require\\(\'\\./' + t + '\'\\),',
'g'), ''
);
var regEx = WHITESPACE_BEFORE + 'require\\(\'\\./' + t + '\'\\),';
if(strict) {
regEx += '|require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),';
}
var newCode = partialIndex.replace(new RegExp(regEx, 'g'), '');

// test removal
if(newCode === partialIndex) {
Expand Down
2 changes: 2 additions & 0 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function startsWithLowerCase(v) {
var pathToPlotlyIndex = path.join(pathToLib, 'index.js');
var pathToPlotlyStrict = path.join(pathToLib, 'index-strict.js');
var mainIndex = fs.readFileSync(pathToPlotlyIndex, 'utf-8');
var strictIndex = fs.readFileSync(pathToPlotlyStrict, 'utf-8');
var allTraces = fs.readdirSync(path.join(pathToSrc, 'traces'))
.filter(startsWithLowerCase);

Expand Down Expand Up @@ -191,6 +192,7 @@ module.exports = {
allTransforms: allTransforms,
allTraces: allTraces,
mainIndex: mainIndex,
strictIndex: strictIndex,
pathToPlotlyIndex: pathToPlotlyIndex,
pathToPlotlyStrict: pathToPlotlyStrict,
pathToPlotlyCore: path.join(pathToSrc, 'core.js'),
Expand Down

0 comments on commit 21d09a6

Please sign in to comment.