Skip to content

Commit

Permalink
attempt to get browserify@14 working by explicitly using buffer@4
Browse files Browse the repository at this point in the history
see browserify/browserify#1678 for more details
  • Loading branch information
boneskull committed Sep 29, 2017
1 parent 228dc47 commit 38b1cb0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 38 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -21,6 +21,7 @@ mocha.js BUILDTMP/mocha.js: $(SRC) browser-entry.js
@printf "==> [Browser :: build]\n"
mkdir -p ${@D}
$(BROWSERIFY) ./browser-entry \
--require buffer/:buffer \
--plugin ./scripts/dedefine \
--ignore 'fs' \
--ignore 'glob' \
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Expand Up @@ -49,6 +49,7 @@ module.exports = function (config) {
.ignore('fs')
.ignore('path')
.ignore('supports-color')
.require(path.join(__dirname, 'node_modules', 'buffer'), {expose: 'buffer'})
.on('bundled', function (err, content) {
if (!err && bundleDirpath) {
// write bundle to directory for debugging
Expand Down
26 changes: 2 additions & 24 deletions lib/utils.js
Expand Up @@ -209,17 +209,6 @@ var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (ob

exports.isArray = isArray;

/**
* Buffer.prototype.toJSON polyfill.
*
* @type {Function}
*/
if (typeof Buffer !== 'undefined' && Buffer.prototype) {
Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
return Array.prototype.slice.call(this, 0);
};
}

/**
* Ignored files.
*
Expand Down Expand Up @@ -411,7 +400,7 @@ var type = exports.type = function type (value) {
return 'undefined';
} else if (value === null) {
return 'null';
} else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
} else if (Buffer.isBuffer(value)) {
return 'buffer';
}
return Object.prototype.toString.call(value)
Expand Down Expand Up @@ -439,7 +428,7 @@ exports.stringify = function (value) {

if (!~indexOf(['object', 'array', 'function'], typeHint)) {
if (typeHint === 'buffer') {
var json = value.toJSON();
var json = Buffer.prototype.toJSON.call(value);
// Based on the toJSON result
return jsonStringify(json.data && json.type ? json.data : json, 2)
.replace(/,(\n|$)/g, '$1');
Expand Down Expand Up @@ -549,17 +538,6 @@ function jsonStringify (object, spaces, depth) {
(str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
}

/**
* Test if a value is a buffer.
*
* @api private
* @param {*} value The value to test.
* @return {boolean} True if `value` is a buffer, otherwise false
*/
exports.isBuffer = function (value) {
return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
};

/**
* Return a new Thing that has the keys in sorted order. Recursive.
*
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -321,7 +321,8 @@
"devDependencies": {
"@coderbyheart/karma-sauce-launcher": "git://github.com/coderbyheart/karma-sauce-launcher#5259942cd6d40090eaa13ceeef5b0b8738c7710f",
"assert": "^1.4.1",
"browserify": "^13.0.0",
"browserify": "^14.4.0",
"buffer": "^4.9.1",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.15",
"cross-spawn": "^5.1.0",
Expand Down Expand Up @@ -367,7 +368,8 @@
"fs": false,
"glob": false,
"path": false,
"supports-color": false
"supports-color": false,
"buffer": "buffer"
},
"homepage": "https://mochajs.org",
"logo": "https://cldup.com/S9uQ-cOLYz.svg"
Expand Down
12 changes: 0 additions & 12 deletions test/unit/utils.spec.js
Expand Up @@ -495,18 +495,6 @@ describe('lib/utils', function () {
});
});

describe('isBuffer()', function () {
var isBuffer = utils.isBuffer;
it('should test if object is a Buffer', function () {
expect(isBuffer(Buffer.from([0x01])))
.to
.equal(true);
expect(isBuffer({}))
.to
.equal(false);
});
});

describe('map()', function () {
var map = utils.map;
it('should behave same as Array.prototype.map', function () {
Expand Down

0 comments on commit 38b1cb0

Please sign in to comment.