From 16f1d1fd1a3a5ffa291d67fc5992055ca36d6955 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 17 Jan 2023 15:20:47 -0500 Subject: [PATCH 1/7] set umdNamedDefine to false - fix AMD import in docs --- webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index 94d66e448ef..f88e5e5d24d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,7 +10,7 @@ module.exports = { library: { name: 'Plotly', type: 'umd', - umdNamedDefine: true + umdNamedDefine: false } }, module: { From f23051a6cb9e484d6a53a6b5d0ca8630754501b7 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 17 Jan 2023 15:42:17 -0500 Subject: [PATCH 2/7] set umdNamedDefine to false in dashboard & karma config --- devtools/test_dashboard/server.js | 2 +- test/jasmine/karma.conf.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/test_dashboard/server.js b/devtools/test_dashboard/server.js index ae8b6079dc0..8372bb713ef 100644 --- a/devtools/test_dashboard/server.js +++ b/devtools/test_dashboard/server.js @@ -38,7 +38,7 @@ devtoolsConfig.output = { library: { name: 'Tabs', type: 'umd', - umdNamedDefine: true + umdNamedDefine: false } }; diff --git a/test/jasmine/karma.conf.js b/test/jasmine/karma.conf.js index 3a621b7e927..c15da7a4200 100644 --- a/test/jasmine/karma.conf.js +++ b/test/jasmine/karma.conf.js @@ -301,7 +301,7 @@ func.defaultConfig = { library: { name: 'Plotly', type: 'umd', - umdNamedDefine: true + umdNamedDefine: false } } }) From 549954761bbcfd50aad994f388305ad4ebefe24c Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Wed, 18 Jan 2023 10:33:33 -0500 Subject: [PATCH 3/7] use centralized webpack config.output.library options --- devtools/test_dashboard/server.js | 6 +----- test/jasmine/karma.conf.js | 7 ++----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/devtools/test_dashboard/server.js b/devtools/test_dashboard/server.js index 8372bb713ef..829aa7e3f58 100644 --- a/devtools/test_dashboard/server.js +++ b/devtools/test_dashboard/server.js @@ -35,11 +35,7 @@ devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js'); devtoolsConfig.output = { path: config.output.path, filename: 'test_dashboard-bundle.js', - library: { - name: 'Tabs', - type: 'umd', - umdNamedDefine: false - } + library: config.output.library }; devtoolsConfig.target = config.target; diff --git a/test/jasmine/karma.conf.js b/test/jasmine/karma.conf.js index c15da7a4200..df2f4f49d55 100644 --- a/test/jasmine/karma.conf.js +++ b/test/jasmine/karma.conf.js @@ -5,6 +5,7 @@ var minimist = require('minimist'); var NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); var LoaderOptionsPlugin = require('webpack').LoaderOptionsPlugin; var constants = require('../../tasks/util/constants'); +var webpackConfig = require('../../webpack.config.js'); var isCI = Boolean(process.env.CI); @@ -298,11 +299,7 @@ func.defaultConfig = { new LoaderOptionsPlugin({ // test: /\.xxx$/, // may apply this only for some modules options: { - library: { - name: 'Plotly', - type: 'umd', - umdNamedDefine: false - } + library: webpackConfig.output.library } }) ] From e32ba76fe7db9f3c6374744a4a140384a1e32ace Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Wed, 18 Jan 2023 11:38:07 -0500 Subject: [PATCH 4/7] rename requirejs to amdefine test then add new requirejs test --- .circleci/config.yml | 3 +++ .eslintignore | 1 + package.json | 1 + tasks/test_amdefine.js | 28 ++++++++++++++++++++++++++++ tasks/test_requirejs.js | 18 ++++++++---------- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 tasks/test_amdefine.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a38ad3964d..dba2f83dbab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -400,6 +400,9 @@ jobs: - run: name: Test plot-schema.json diff - If failed, after (npm start) you could run (npm run schema && git add test/plot-schema.json && git commit -m "update plot-schema diff") command: diff --unified --color dist/plot-schema.json test/plot-schema.json + - run: + name: Test plotly.min.js import using amdefine + command: npm run test-amdefine - run: name: Test plotly.min.js import using requirejs command: npm run test-requirejs diff --git a/.eslintignore b/.eslintignore index e445d51e232..186f2f01a04 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,5 +3,6 @@ node_modules dist build +tasks/test_amdefine.js tasks/test_requirejs.js test/jasmine/assets/jquery-1.8.3.min.js diff --git a/package.json b/package.json index 877a384bad9..1645892ad63 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "test-export": "node test/image/export_test.js", "test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output", "test-bundle": "node tasks/test_bundle.js", + "test-amdefine": "node tasks/test_amdefine.js", "test-requirejs": "node tasks/test_requirejs.js", "test-plain-obj": "node tasks/test_plain_obj.js", "test": "npm run test-jasmine -- --nowatch && npm run test-bundle && npm run test-image && npm run test-export && npm run test-syntax && npm run lint", diff --git a/tasks/test_amdefine.js b/tasks/test_amdefine.js new file mode 100644 index 00000000000..0da4ee86a93 --- /dev/null +++ b/tasks/test_amdefine.js @@ -0,0 +1,28 @@ +var JSDOM = require('jsdom').JSDOM; +global.document = new JSDOM('').window.document; +global.window = document.defaultView; +global.window.document = global.document; +global.self = global.window; +global.Blob = global.window.Blob; +global.DOMParser = global.window.DOMParser; +global.getComputedStyle = global.window.getComputedStyle; +global.window.URL.createObjectURL = function() {}; + +// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html +if(typeof define !== 'function') { + var define = require('amdefine')(module); +} + +define(function(require) { + var plotly = require('../dist/plotly.min.js'); + + if(plotly) { + console.log(plotly); + } else { + throw 'Error: loading with amdefine'; + } + + // The value returned from the function is + // used as the module export visible to Node. + return function() {}; +}); diff --git a/tasks/test_requirejs.js b/tasks/test_requirejs.js index b743bc0b2da..4ec56da300e 100644 --- a/tasks/test_requirejs.js +++ b/tasks/test_requirejs.js @@ -8,21 +8,19 @@ global.DOMParser = global.window.DOMParser; global.getComputedStyle = global.window.getComputedStyle; global.window.URL.createObjectURL = function() {}; -// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html -if(typeof define !== 'function') { - var define = require('amdefine')(module); -} +var requirejs = require('requirejs'); -define(function(require) { - var plotly = require('../dist/plotly.min.js'); +requirejs.config({ + paths: { + 'plotly': '../dist/plotly.min' + } +}); +requirejs(['plotly'], +function(plotly) { if(plotly) { console.log(plotly); } else { throw 'Error: loading with requirejs'; } - - // The value returned from the function is - // used as the module export visible to Node. - return function() {}; }); From 40cecb67382611a13c888270f2b4f6b2574799d2 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Wed, 18 Jan 2023 15:32:30 -0500 Subject: [PATCH 5/7] draft log for PR 6440 --- draftlogs/6440_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/6440_fix.md diff --git a/draftlogs/6440_fix.md b/draftlogs/6440_fix.md new file mode 100644 index 00000000000..7c402f3284d --- /dev/null +++ b/draftlogs/6440_fix.md @@ -0,0 +1 @@ + - Fix library's imported name using `requirejs` AMD loader (regression introduced in 2.17.0) [[#6440](https://github.com/plotly/plotly.js/pull/6440)] From 4fd73a764e9efd08794ee18e19c402f8c58cb029 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> Date: Wed, 18 Jan 2023 16:35:08 -0500 Subject: [PATCH 6/7] Update devtools/test_dashboard/server.js Co-authored-by: Alex Johnson --- devtools/test_dashboard/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/test_dashboard/server.js b/devtools/test_dashboard/server.js index 829aa7e3f58..af24cb8d5b3 100644 --- a/devtools/test_dashboard/server.js +++ b/devtools/test_dashboard/server.js @@ -35,7 +35,7 @@ devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js'); devtoolsConfig.output = { path: config.output.path, filename: 'test_dashboard-bundle.js', - library: config.output.library + library: {...config.output.library, name: 'Tabs'} }; devtoolsConfig.target = config.target; From 9da2ce0428555d49a9c76a60904b478a018a568a Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Wed, 18 Jan 2023 16:40:31 -0500 Subject: [PATCH 7/7] fixup Tabs --- devtools/test_dashboard/server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/devtools/test_dashboard/server.js b/devtools/test_dashboard/server.js index af24cb8d5b3..e55dc473b50 100644 --- a/devtools/test_dashboard/server.js +++ b/devtools/test_dashboard/server.js @@ -35,7 +35,10 @@ devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js'); devtoolsConfig.output = { path: config.output.path, filename: 'test_dashboard-bundle.js', - library: {...config.output.library, name: 'Tabs'} + library: { + name: 'Tabs', + type: 'umd' + } }; devtoolsConfig.target = config.target;