Skip to content

Commit

Permalink
avoid define() calls in dependencies; closes #2424 (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Aug 8, 2016
1 parent 2f21eb0 commit bbc1682
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -13,6 +13,7 @@ all: mocha.js
mocha.js: $(SRC) browser-entry.js
@printf "==> [Browser :: build]\n"
$(BROWSERIFY) ./browser-entry \
--plugin ./scripts/dedefine \
--ignore 'fs' \
--ignore 'glob' \
--ignore 'path' \
Expand Down
4 changes: 2 additions & 2 deletions mocha.js
Expand Up @@ -9314,7 +9314,7 @@ function objectToString(o) {
/*global module */
if (typeof module !== 'undefined' && module.exports) {
module.exports = JsDiff;
} else if (typeof define === 'function' && define.amd) {
} else if (false) {
/*global define */
define([], function() { return JsDiff; });
} else if (typeof global.JsDiff === 'undefined') {
Expand Down Expand Up @@ -10076,7 +10076,7 @@ module.exports = Array.isArray || function (arr) {
;(function () {
// Detect the `define` function exposed by asynchronous module loaders. The
// strict `define` check is necessary for compatibility with `r.js`.
var isLoader = typeof define === "function" && define.amd;
var isLoader = false;

// A set of types used to distinguish objects from primitives.
var objectTypes = {
Expand Down
26 changes: 26 additions & 0 deletions scripts/dedefine.js
@@ -0,0 +1,26 @@
'use strict';

/**
* This is a transform stream we're using to strip AMD calls from
* dependencies in our Browserify bundle.
*/

var through = require('through2');
var defineRx = /typeof define === ['"]function['"] && define\.amd/g;

function createStream() {
return through.obj(function(chunk, enc, next) {
this.push(String(chunk)
.replace(defineRx, 'false'));
next();
});
}

module.exports = function(b) {
function wrap() {
b.pipeline.get('wrap').push(createStream());
}

b.on('reset', wrap);
wrap();
};

0 comments on commit bbc1682

Please sign in to comment.