Skip to content

Commit

Permalink
Don't use requirejs with minified Cesium.
Browse files Browse the repository at this point in the history
While the improvements in #7514 worked, they were a little more convoluted
than they had to be and also caused some weird edge cases where loading
Cesium in eval'd Node.js code didn't work.

This change avoids using requirejs entirely when loading minified Cesium
in Node and adds a smokescreen test to travis that fails in master. This
also avoids the odd global workaround I had to put in place previously.

I did have to modify the UMD headers for NoSleep.js and purify.js because
their preference is to look for Node.js first and not use AMD if it's
found, this was the root cause of the failures we were seeing in eval'd
code.  The smokescreen test I added will fail again if the problem were
reintroduced.

So overall, this make Cesium a little more node-friendly and just makes
things cleaner from our end.
  • Loading branch information
mramato committed Feb 12, 2019
1 parent f87fbad commit 55e9514
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ script:

- npm --silent run test -- --browsers FirefoxHeadless --failTaskOnError --webgl-stub --release --suppressPassed

# Various Node.js smoke-screen tests
- node -e "const Cesium = require('./');"
- NODE_ENV=development node index.js

- NODE_ENV=production node index.js

- npm --silent run cloc
4 changes: 2 additions & 2 deletions Source/ThirdParty/NoSleep.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*! NoSleep.js v0.7.0 - git.io/vfn01 - Rich Tibbett - MIT license */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
/* if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
else */ if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["NoSleep"] = factory();
Expand Down
2 changes: 1 addition & 1 deletion Source/ThirdParty/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ require([
], function(
Cesium) {
'use strict';
/*global self,global*/
/*global self,module*/
if (typeof window !== 'undefined') {
window.Cesium = Cesium;
} else if (typeof self !== 'undefined') {
self.Cesium = Cesium;
} else if (typeof global !== 'undefined') {
global.Cesium = Cesium;
} else if(typeof module !== 'undefined') {
module.exports = Cesium;
} else {
console.log('Unable to load Cesium.');
}
Expand Down
30 changes: 7 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,20 @@
'use strict';

var path = require('path');
var requirejs = require('requirejs');

//In explicit development mode, use un-optimized requirejs modules for improved error checking.
if (process.env.NODE_ENV === 'development') {
requirejs.config({
paths: {
'Cesium': path.join(__dirname, 'Source')
},
nodeRequire: require
});
module.exports = requirejs('Cesium/Cesium');
// If not explicitly in development mode, use the combined/minified/optimized version of Cesium
if (process.env.NODE_ENV !== 'development') {
module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium'));
return;
}

//In all other cases, use minified Cesium for performance.
// Otherwise, use un-optimized requirejs modules for improved error checking.
var requirejs = require('requirejs');
requirejs.config({
paths: {
'Cesium': path.join(__dirname, 'Build/Cesium/Cesium')
'Cesium': path.join(__dirname, 'Source')
},
nodeRequire: require
});

const hadCesiumProperty = global.hasOwnProperty('Cesium');
const oldCesium = global.Cesium;

requirejs('Cesium');
module.exports = global.Cesium;

if (hadCesiumProperty) {
global.Cesium = oldCesium;
} else {
delete global.Cesium;
}
module.exports = requirejs('Cesium/Cesium');

0 comments on commit 55e9514

Please sign in to comment.