Skip to content

Commit 360213e

Browse files
authored
Merge pull request #6440 from plotly/false-umdNamedDefine
Fix library's imported name using `requirejs` AMD loader
2 parents 48ce92e + 9da2ce0 commit 360213e

File tree

9 files changed

+46
-18
lines changed

9 files changed

+46
-18
lines changed

.circleci/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ jobs:
400400
- run:
401401
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")
402402
command: diff --unified --color dist/plot-schema.json test/plot-schema.json
403+
- run:
404+
name: Test plotly.min.js import using amdefine
405+
command: npm run test-amdefine
403406
- run:
404407
name: Test plotly.min.js import using requirejs
405408
command: npm run test-requirejs

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ node_modules
33
dist
44
build
55

6+
tasks/test_amdefine.js
67
tasks/test_requirejs.js
78
test/jasmine/assets/jquery-1.8.3.min.js

devtools/test_dashboard/server.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ devtoolsConfig.output = {
3737
filename: 'test_dashboard-bundle.js',
3838
library: {
3939
name: 'Tabs',
40-
type: 'umd',
41-
umdNamedDefine: true
40+
type: 'umd'
4241
}
4342
};
4443

draftlogs/6440_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)]

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"test-export": "node test/image/export_test.js",
4949
"test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output",
5050
"test-bundle": "node tasks/test_bundle.js",
51+
"test-amdefine": "node tasks/test_amdefine.js",
5152
"test-requirejs": "node tasks/test_requirejs.js",
5253
"test-plain-obj": "node tasks/test_plain_obj.js",
5354
"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",

tasks/test_amdefine.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var JSDOM = require('jsdom').JSDOM;
2+
global.document = new JSDOM('<!DOCTYPE html><head></head><html><body></body></html>').window.document;
3+
global.window = document.defaultView;
4+
global.window.document = global.document;
5+
global.self = global.window;
6+
global.Blob = global.window.Blob;
7+
global.DOMParser = global.window.DOMParser;
8+
global.getComputedStyle = global.window.getComputedStyle;
9+
global.window.URL.createObjectURL = function() {};
10+
11+
// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html
12+
if(typeof define !== 'function') {
13+
var define = require('amdefine')(module);
14+
}
15+
16+
define(function(require) {
17+
var plotly = require('../dist/plotly.min.js');
18+
19+
if(plotly) {
20+
console.log(plotly);
21+
} else {
22+
throw 'Error: loading with amdefine';
23+
}
24+
25+
// The value returned from the function is
26+
// used as the module export visible to Node.
27+
return function() {};
28+
});

tasks/test_requirejs.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ global.DOMParser = global.window.DOMParser;
88
global.getComputedStyle = global.window.getComputedStyle;
99
global.window.URL.createObjectURL = function() {};
1010

11-
// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html
12-
if(typeof define !== 'function') {
13-
var define = require('amdefine')(module);
14-
}
11+
var requirejs = require('requirejs');
1512

16-
define(function(require) {
17-
var plotly = require('../dist/plotly.min.js');
13+
requirejs.config({
14+
paths: {
15+
'plotly': '../dist/plotly.min'
16+
}
17+
});
1818

19+
requirejs(['plotly'],
20+
function(plotly) {
1921
if(plotly) {
2022
console.log(plotly);
2123
} else {
2224
throw 'Error: loading with requirejs';
2325
}
24-
25-
// The value returned from the function is
26-
// used as the module export visible to Node.
27-
return function() {};
2826
});

test/jasmine/karma.conf.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var minimist = require('minimist');
55
var NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
66
var LoaderOptionsPlugin = require('webpack').LoaderOptionsPlugin;
77
var constants = require('../../tasks/util/constants');
8+
var webpackConfig = require('../../webpack.config.js');
89

910
var isCI = Boolean(process.env.CI);
1011

@@ -298,11 +299,7 @@ func.defaultConfig = {
298299
new LoaderOptionsPlugin({
299300
// test: /\.xxx$/, // may apply this only for some modules
300301
options: {
301-
library: {
302-
name: 'Plotly',
303-
type: 'umd',
304-
umdNamedDefine: true
305-
}
302+
library: webpackConfig.output.library
306303
}
307304
})
308305
]

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
library: {
1111
name: 'Plotly',
1212
type: 'umd',
13-
umdNamedDefine: true
13+
umdNamedDefine: false
1414
}
1515
},
1616
module: {

0 commit comments

Comments
 (0)