Skip to content

Commit

Permalink
Changes to build system.
Browse files Browse the repository at this point in the history
Disable amd when importing external sources so they populate the
namespace as expected.  Otherwise we lose access to them in request
based projects (like jupyter).

I'm pulling in UPNG now to support creation of animated pngs in py3Dmol.
  • Loading branch information
dkoes committed Jan 22, 2022
1 parent 6618f55 commit 7a4fa76
Show file tree
Hide file tree
Showing 9 changed files with 5,831 additions and 437 deletions.
8 changes: 8 additions & 0 deletions 3Dmol/3dmol.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,14 @@ $3Dmol.getPropertyRange = function (atomlist, prop) {

//hackish way to work with requirejs - doesn't actually work yet
//since we don't use the require optimizer to combine modules
if(typeof(_3dmol_saved_define) !== 'undefined') {
/** When pulling in external sources, disable amd to ensure they
* populate the global namespace as expected. Restore it so code
* using amd still works. */
/*global _3dmol_saved_define, _3dmol_saved_require, define:true, require:true */
define = _3dmol_saved_define;
require = _3dmol_saved_require;
}
if( typeof(define) === 'function' && define.amd) {
define('$3Dmol',[], function() { return $3Dmol; });
}
Expand Down
5 changes: 3 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ del = require('del');
jsdoc = require('gulp-jsdoc3');

coresrc = ['3Dmol/3dmol.js','3Dmol/WebGL/math.js','3Dmol/WebGL/shapes.js','3Dmol/WebGL/core.js','3Dmol/WebGL/**.js','3Dmol/**.js','!3Dmol/SurfaceWorker.js','3Dmol/SurfaceWorker.js'];
extsrc = ['js/mmtf.js','node_modules/pako/dist/pako.js','node_modules/netcdfjs/dist/netcdfjs.js','node_modules/upng-js/UPNG.js'];
extsrc = ['js/disable_amd.js','js/mmtf.js','node_modules/pako/dist/pako.js','node_modules/netcdfjs/dist/netcdfjs.js','node_modules/upng-js/UPNG.js'];
uisrc = ['3Dmol/ui/ui.js', '3Dmol/ui/state.js', '3Dmol/ui/icon.js', '3Dmol/ui/form.js', '3Dmol/ui/defaultValues.js'];
jqsrc = ['node_modules/jquery/dist/jquery.js'];

Expand Down Expand Up @@ -49,7 +49,8 @@ function check() {
'MMTF': false,
'TextDecoder': false,
'FileReader': false,
'define':false}}))
'define':false,
'require':false}}))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
}
Expand Down
8 changes: 8 additions & 0 deletions js/disable_amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

if(typeof define !== 'undefined') {
// UPNG checks the existence of require, not define, so need to do both
var _3dmol_saved_define = define;
var _3dmol_saved_require = require;
define = null;
require = null;
}
Loading

0 comments on commit 7a4fa76

Please sign in to comment.