Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --strict option to custom bundle #6557

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
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
9 changes: 6 additions & 3 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 @@ -35,8 +37,9 @@ module.exports = function partialBundle(tasks, opts) {
var newCode = partialIndex.replace(
new RegExp(
WHITESPACE_BEFORE +
'require\\(\'\\./' + t + '\'\\),',
'g'), ''
'require\\(\'\\./' + t + '\'\\),' + '|' +
'require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),',
'g'), ''
archmoj marked this conversation as resolved.
Show resolved Hide resolved
);

// test removal
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