Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit bd81ba5

Browse files
authored
avoid define() calls in dependencies; closes mochajs#2424 (mochajs#2425)
1 parent e404549 commit bd81ba5

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ all: mocha.js
1313
mocha.js: $(SRC) browser-entry.js
1414
@printf "==> [Browser :: build]\n"
1515
$(BROWSERIFY) ./browser-entry \
16+
--plugin ./scripts/dedefine \
1617
--ignore 'fs' \
1718
--ignore 'glob' \
1819
--ignore 'path' \

mocha.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9314,7 +9314,7 @@ function objectToString(o) {
93149314
/*global module */
93159315
if (typeof module !== 'undefined' && module.exports) {
93169316
module.exports = JsDiff;
9317-
} else if (typeof define === 'function' && define.amd) {
9317+
} else if (false) {
93189318
/*global define */
93199319
define([], function() { return JsDiff; });
93209320
} else if (typeof global.JsDiff === 'undefined') {
@@ -10076,7 +10076,7 @@ module.exports = Array.isArray || function (arr) {
1007610076
;(function () {
1007710077
// Detect the `define` function exposed by asynchronous module loaders. The
1007810078
// strict `define` check is necessary for compatibility with `r.js`.
10079-
var isLoader = typeof define === "function" && define.amd;
10079+
var isLoader = false;
1008010080

1008110081
// A set of types used to distinguish objects from primitives.
1008210082
var objectTypes = {

scripts/dedefine.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
/**
4+
* This is a transform stream we're using to strip AMD calls from
5+
* dependencies in our Browserify bundle.
6+
*/
7+
8+
var through = require('through2');
9+
var defineRx = /typeof define === ['"]function['"] && define\.amd/g;
10+
11+
function createStream() {
12+
return through.obj(function(chunk, enc, next) {
13+
this.push(String(chunk)
14+
.replace(defineRx, 'false'));
15+
next();
16+
});
17+
}
18+
19+
module.exports = function(b) {
20+
function wrap() {
21+
b.pipeline.get('wrap').push(createStream());
22+
}
23+
24+
b.on('reset', wrap);
25+
wrap();
26+
};

0 commit comments

Comments
 (0)