From ac6af51a14d79c664bf518120175614b90754189 Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Fri, 14 Nov 2025 15:46:18 -0700 Subject: [PATCH 1/4] Linting/formatting --- tasks/preprocess.js | 61 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/tasks/preprocess.js b/tasks/preprocess.js index 302628090ec..85163e0ba1c 100644 --- a/tasks/preprocess.js +++ b/tasks/preprocess.js @@ -16,25 +16,32 @@ updateVersion(constants.pathToPlotlyVersion); // convert scss to css to js and static css file function makeBuildCSS() { - sass.render({ - file: constants.pathToSCSS, - outputStyle: 'compressed' - }, function(err, result) { - if(err) throw err; + sass.render( + { + file: constants.pathToSCSS, + outputStyle: 'compressed' + }, + function (err, result) { + if (err) throw err; - // To support application with strict CSP where styles cannot be inlined, - // build a static CSS file that can be included into such applications. - var staticCSS = String(result.css); - for(var k in mapBoxGLStyleRules) { - staticCSS = addAdditionalCSSRules(staticCSS, '.js-plotly-plot .plotly .mapboxgl-' + k, mapBoxGLStyleRules[k]); - } - fs.writeFile(constants.pathToCSSDist, staticCSS, function(err) { - if(err) throw err; - }); + // To support application with strict CSP where styles cannot be inlined, + // build a static CSS file that can be included into such applications. + var staticCSS = String(result.css); + for (var k in mapBoxGLStyleRules) { + staticCSS = addAdditionalCSSRules( + staticCSS, + '.js-plotly-plot .plotly .mapboxgl-' + k, + mapBoxGLStyleRules[k] + ); + } + fs.writeFile(constants.pathToCSSDist, staticCSS, function (err) { + if (err) throw err; + }); - // css to js to be inlined - pullCSS(String(result.css), constants.pathToCSSBuild); - }); + // css to js to be inlined + pullCSS(String(result.css), constants.pathToCSSBuild); + } + ); } function addAdditionalCSSRules(staticStyleString, selector, style) { @@ -44,7 +51,7 @@ function addAdditionalCSSRules(staticStyleString, selector, style) { function exposePartsInLib() { var obj = {}; - var insert = function(name, folder) { + var insert = function (name, folder) { obj[name] = folder + '/' + name; }; @@ -52,7 +59,7 @@ function exposePartsInLib() { insert('calendars', 'src/components'); - constants.allTraces.forEach(function(k) { + constants.allTraces.forEach(function (k) { insert(k, 'src/traces'); }); @@ -60,24 +67,14 @@ function exposePartsInLib() { } function writeLibFiles(obj) { - for(var name in obj) { + for (var name in obj) { common.writeFile( path.join(constants.pathToLib, name + '.js'), - [ - '\'use strict\';', - '', - 'module.exports = require(\'../' + obj[name] + '\');', - '' - ].join('\n') + ["'use strict';", '', "module.exports = require('../" + obj[name] + "');", ''].join('\n') ); } } function copyTopojsonFiles() { - fs.copy( - constants.pathToTopojsonSrc, - constants.pathToTopojsonDist, - { clobber: true }, - common.throwOnError - ); + fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist, { clobber: true }, common.throwOnError); } From 42492145dbb6a84566ddebca089814816106141f Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Fri, 14 Nov 2025 15:53:12 -0700 Subject: [PATCH 2/4] Log error message if malformed JSON file found --- devtools/dashboard_utilities.mjs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/devtools/dashboard_utilities.mjs b/devtools/dashboard_utilities.mjs index 8ff5c109e61..86419b64364 100644 --- a/devtools/dashboard_utilities.mjs +++ b/devtools/dashboard_utilities.mjs @@ -40,20 +40,24 @@ export function createMocksList(files) { const jsonFiles = files.filter((file) => file.name.substr(-5) === '.json'); const mocksList = jsonFiles.map((file) => { - const contents = JSON.parse(file.contents); + try { + const contents = JSON.parse(file.contents); - // get plot type keywords from mocks - const types = contents.data - .map((trace) => trace.type || 'scatter') - .reduce((acc, type, i, arr) => (arr.lastIndexOf(type) === i ? [...acc, type] : acc), []); + // get plot type keywords from mocks + const types = contents.data + .map((trace) => trace.type || 'scatter') + .reduce((acc, type, i, arr) => (arr.lastIndexOf(type) === i ? [...acc, type] : acc), []); - const filename = file.name.split(path.sep).pop(); + const filename = file.name.split(path.sep).pop(); - return { - name: filename.slice(0, -5), - file: filename, - keywords: types.join(', ') - }; + return { + name: filename.slice(0, -5), + file: filename, + keywords: types.join(', ') + }; + } catch { + console.log(`Couldn't parse ${file.name} as JSON. Excluding from mocks list.`); + } }); return mocksList; From 8c6f3cc02f80e44eb44fa596286356881b655f9f Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Mon, 17 Nov 2025 08:44:15 -0700 Subject: [PATCH 3/4] Revert "Linting/formatting" This reverts commit ac6af51a14d79c664bf518120175614b90754189. --- tasks/preprocess.js | 61 ++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/tasks/preprocess.js b/tasks/preprocess.js index 85163e0ba1c..302628090ec 100644 --- a/tasks/preprocess.js +++ b/tasks/preprocess.js @@ -16,32 +16,25 @@ updateVersion(constants.pathToPlotlyVersion); // convert scss to css to js and static css file function makeBuildCSS() { - sass.render( - { - file: constants.pathToSCSS, - outputStyle: 'compressed' - }, - function (err, result) { - if (err) throw err; + sass.render({ + file: constants.pathToSCSS, + outputStyle: 'compressed' + }, function(err, result) { + if(err) throw err; - // To support application with strict CSP where styles cannot be inlined, - // build a static CSS file that can be included into such applications. - var staticCSS = String(result.css); - for (var k in mapBoxGLStyleRules) { - staticCSS = addAdditionalCSSRules( - staticCSS, - '.js-plotly-plot .plotly .mapboxgl-' + k, - mapBoxGLStyleRules[k] - ); - } - fs.writeFile(constants.pathToCSSDist, staticCSS, function (err) { - if (err) throw err; - }); - - // css to js to be inlined - pullCSS(String(result.css), constants.pathToCSSBuild); + // To support application with strict CSP where styles cannot be inlined, + // build a static CSS file that can be included into such applications. + var staticCSS = String(result.css); + for(var k in mapBoxGLStyleRules) { + staticCSS = addAdditionalCSSRules(staticCSS, '.js-plotly-plot .plotly .mapboxgl-' + k, mapBoxGLStyleRules[k]); } - ); + fs.writeFile(constants.pathToCSSDist, staticCSS, function(err) { + if(err) throw err; + }); + + // css to js to be inlined + pullCSS(String(result.css), constants.pathToCSSBuild); + }); } function addAdditionalCSSRules(staticStyleString, selector, style) { @@ -51,7 +44,7 @@ function addAdditionalCSSRules(staticStyleString, selector, style) { function exposePartsInLib() { var obj = {}; - var insert = function (name, folder) { + var insert = function(name, folder) { obj[name] = folder + '/' + name; }; @@ -59,7 +52,7 @@ function exposePartsInLib() { insert('calendars', 'src/components'); - constants.allTraces.forEach(function (k) { + constants.allTraces.forEach(function(k) { insert(k, 'src/traces'); }); @@ -67,14 +60,24 @@ function exposePartsInLib() { } function writeLibFiles(obj) { - for (var name in obj) { + for(var name in obj) { common.writeFile( path.join(constants.pathToLib, name + '.js'), - ["'use strict';", '', "module.exports = require('../" + obj[name] + "');", ''].join('\n') + [ + '\'use strict\';', + '', + 'module.exports = require(\'../' + obj[name] + '\');', + '' + ].join('\n') ); } } function copyTopojsonFiles() { - fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist, { clobber: true }, common.throwOnError); + fs.copy( + constants.pathToTopojsonSrc, + constants.pathToTopojsonDist, + { clobber: true }, + common.throwOnError + ); } From a0f946920a8304932cd7b854aca348413cf881ec Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Mon, 17 Nov 2025 09:05:21 -0700 Subject: [PATCH 4/4] Add specific error handling --- devtools/dashboard_utilities.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/devtools/dashboard_utilities.mjs b/devtools/dashboard_utilities.mjs index 86419b64364..f64629a9e41 100644 --- a/devtools/dashboard_utilities.mjs +++ b/devtools/dashboard_utilities.mjs @@ -55,8 +55,12 @@ export function createMocksList(files) { file: filename, keywords: types.join(', ') }; - } catch { - console.log(`Couldn't parse ${file.name} as JSON. Excluding from mocks list.`); + } catch (error) { + if (error instanceof SyntaxError) { + console.log(`Couldn't parse ${file.name} as JSON. Excluding from mocks list.`); + } else { + throw error; + } } });