From 3b465ceac44ec8558feb9b8b0a7c2e321cc41ba7 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Fri, 24 Mar 2023 12:03:18 +1300 Subject: [PATCH 1/6] Add --strict option to custom bundle command so that strict traces can be used in a custom bundle --- CUSTOM_BUNDLE.md | 5 +++++ tasks/custom_bundle.js | 4 +++- tasks/partial_bundle.js | 9 ++++++--- tasks/util/constants.js | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CUSTOM_BUNDLE.md b/CUSTOM_BUNDLE.md index 2de22668c40..5870352f3e1 100644 --- a/CUSTOM_BUNDLE.md +++ b/CUSTOM_BUNDLE.md @@ -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-.min.js` or `plotly-.js` if unminified. ```sh diff --git a/tasks/custom_bundle.js b/tasks/custom_bundle.js index bdb80642b0e..fe8fb90602f 100644 --- a/tasks/custom_bundle.js +++ b/tasks/custom_bundle.js @@ -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) { diff --git a/tasks/partial_bundle.js b/tasks/partial_bundle.js index 6eaafa9ce38..083ccce5a7c 100644 --- a/tasks/partial_bundle.js +++ b/tasks/partial_bundle.js @@ -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) { @@ -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); @@ -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'), '' ); // test removal diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 001b801e615..bf2f24470c9 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -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); @@ -191,6 +192,7 @@ module.exports = { allTransforms: allTransforms, allTraces: allTraces, mainIndex: mainIndex, + strictIndex: strictIndex, pathToPlotlyIndex: pathToPlotlyIndex, pathToPlotlyStrict: pathToPlotlyStrict, pathToPlotlyCore: path.join(pathToSrc, 'core.js'), From cf9edddda112fb6b01152b18b7ea236e232f2b04 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Fri, 14 Apr 2023 12:26:28 +1200 Subject: [PATCH 2/6] Choose regex expression to replace require line based on whether strict flag used --- tasks/partial_bundle.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tasks/partial_bundle.js b/tasks/partial_bundle.js index 083ccce5a7c..6adebe3a7ee 100644 --- a/tasks/partial_bundle.js +++ b/tasks/partial_bundle.js @@ -34,13 +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 + '\'\\),' + '|' + - 'require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),', - '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) { From 5fd35d0739391a2412302cde64ebcec83130e791 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Fri, 14 Apr 2023 12:37:15 +1200 Subject: [PATCH 3/6] Add changelog for PR #6557 --- draftlogs/6557_add.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/6557_add.md diff --git a/draftlogs/6557_add.md b/draftlogs/6557_add.md new file mode 100644 index 00000000000..ae9a5945d09 --- /dev/null +++ b/draftlogs/6557_add.md @@ -0,0 +1 @@ +- Add --strict option to custom bundle command so that strict traces can be used in a custom bundle. [[#6557](https://github.com/plotly/plotly.js/pull/6557)] \ No newline at end of file From f8ad34094cc81f4fe5696d9ded2c83e5bf814444 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Sat, 15 Apr 2023 09:54:15 +1200 Subject: [PATCH 4/6] Update draftlogs/6557_add.md Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- draftlogs/6557_add.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draftlogs/6557_add.md b/draftlogs/6557_add.md index ae9a5945d09..b4f4e71bd6e 100644 --- a/draftlogs/6557_add.md +++ b/draftlogs/6557_add.md @@ -1 +1 @@ -- Add --strict option to custom bundle command so that strict traces can be used in a custom bundle. [[#6557](https://github.com/plotly/plotly.js/pull/6557)] \ No newline at end of file + - Add strict option to custom bundle command [[#6557](https://github.com/plotly/plotly.js/pull/6557)], with thanks to @CallumNZ for the contribution! \ No newline at end of file From a1d8c9c28bda6460680a1b3c072527392b3f4911 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Sat, 15 Apr 2023 09:54:55 +1200 Subject: [PATCH 5/6] Update tasks/partial_bundle.js formatting Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- tasks/partial_bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/partial_bundle.js b/tasks/partial_bundle.js index 6adebe3a7ee..648dc4d3037 100644 --- a/tasks/partial_bundle.js +++ b/tasks/partial_bundle.js @@ -35,7 +35,7 @@ module.exports = function partialBundle(tasks, opts) { var WHITESPACE_BEFORE = '\\s*'; // remove require var regEx = WHITESPACE_BEFORE + 'require\\(\'\\./' + t + '\'\\),'; - if (strict) { + if(strict) { regEx += '|require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),' } var newCode = partialIndex.replace(new RegExp(regEx, 'g'), ''); From 174d387e9335fc45a2af6f0720085d4458c0cf74 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Sat, 15 Apr 2023 09:55:31 +1200 Subject: [PATCH 6/6] Update tasks/partial_bundle.js with missing semicolon. Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- tasks/partial_bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/partial_bundle.js b/tasks/partial_bundle.js index 648dc4d3037..1fed8e224f6 100644 --- a/tasks/partial_bundle.js +++ b/tasks/partial_bundle.js @@ -36,7 +36,7 @@ module.exports = function partialBundle(tasks, opts) { // remove require var regEx = WHITESPACE_BEFORE + 'require\\(\'\\./' + t + '\'\\),'; if(strict) { - regEx += '|require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),' + regEx += '|require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),'; } var newCode = partialIndex.replace(new RegExp(regEx, 'g'), '');