-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
"version": "1.0.7", | ||
"description": "Builtins that were extracted from node-browser-resolve on which browserify depends", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test/node/* && browserify --transform ./test/browserify-transform.js test/browser/* | testling" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AndreasMadsen
Author
Collaborator
|
||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/alexgorbatchev/node-browser-builtins.git" | ||
|
@@ -22,5 +25,8 @@ | |
"buffer-browserify": "0.1.x", | ||
"zlib-browserify": "0.0.x", | ||
"constants-browserify": "0.0.x" | ||
}, | ||
"devDependencies": { | ||
"tape": "1.0.x" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
// This transformer changes the require calls so they don't point to the | ||
// browserify buildins (older version of this module). | ||
|
||
var path = require('path'); | ||
var util = require('util'); | ||
var stream = require('stream'); | ||
var buildins = require('../index.js'); | ||
|
||
function RequireRedirect() { | ||
if (!(this instanceof RequireRedirect)) return new RequireRedirect(); | ||
stream.Transform.call(this); | ||
this.buffers = []; | ||
} | ||
module.exports = RequireRedirect; | ||
util.inherits(RequireRedirect, stream.Transform); | ||
|
||
RequireRedirect.prototype._transform = function (chunk, encoding, done) { | ||
this.buffers.push(chunk); | ||
done(null); | ||
}; | ||
|
||
// NOTE: this is an incomplete require RegExp, but for internal use here | ||
// its fine. | ||
var REQUIRE_REGEX = /require\((?:"|')([^"']+)(?:"|')\)/g; | ||
|
||
var RELATIVE_DIR = path.resolve(__dirname, '..'); | ||
|
||
RequireRedirect.prototype._flush = function (done) { | ||
var file = Buffer.concat(this.buffers).toString(); | ||
|
||
file = file.replace(REQUIRE_REGEX, function (source, name) { | ||
if (buildins.hasOwnProperty(name)) { | ||
return "require('" + buildins[name] + "')"; | ||
} else { | ||
return source; | ||
} | ||
}); | ||
|
||
this.push(file); | ||
done(null); | ||
}; |
I can't seem to get
npm test
to work with this set up after install browserify and testling