ignores
This commit is contained in:
parent
5f64fb79b8
commit
96f006aa22
1
0Ao5u1U6KYND7dFVkcnJRNUtHWUNKamxoRGg4ZzNiT3c.json
Normal file
1
0Ao5u1U6KYND7dFVkcnJRNUtHWUNKamxoRGg4ZzNiT3c.json
Normal file
@ -0,0 +1 @@
|
||||
[{"contributerstwitter":"jllord","name":"Sweet Bar Bakery","address":"2355 Broadway","city":"Oakland","state":"Ca","long":"-122.266011839473","lat":"37.8129222733119","country":"USA","wifipassword":"cupcakes","outlets":"yes","couch":"no","largetable":"yes","brewing":"","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":1},{"contributerstwitter":"jllord","name":"Awaken Cafe","address":"1429 Broadway","city":"Oakland","state":"Ca","long":"-122.271131495076","lat":"37.8046753170488","country":"USA","wifipassword":"iced coffee","outlets":"yes","couch":"yes","largetable":"yes","brewing":"Four Barrel","outdoorseating":"","hexcolor":"#B9FCFC","rowNumber":2},{"contributerstwitter":"jllord","name":"Panther Coffee","address":"2390 NW 2nd Ave","city":"Miami","state":"Fl","long":"-80.1991536666667","lat":"25.8000021666667","country":"USA","wifipassword":"espresso","outlets":"yes","couch":"no","largetable":"yes","brewing":"In-house","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":3},{"contributerstwitter":"jllord","name":"Haddon Hill Cafe","address":"504 Wesley Ave","city":"Oakland","state":"Ca","long":"-122.2488474","lat":"37.8049159","country":"USA","wifipassword":"haddon10","outlets":"yes","couch":"no","largetable":"yes","brewing":"Sight Glass","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":4},{"contributerstwitter":"jllord","name":"SubRosa Coffee","address":"419 40th Street","city":"Oakland","state":"Ca","long":"-122.2604838","lat":"37.8283586","country":"USA","wifipassword":"-","outlets":"yes","couch":"no","largetable":"no","brewing":"Four Barrel","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":5}]
|
1
node_modules/.bin/beefy
generated
vendored
1
node_modules/.bin/beefy
generated
vendored
@ -1 +0,0 @@
|
||||
../beefy/bin/beefy
|
1
node_modules/.bin/browserify
generated
vendored
1
node_modules/.bin/browserify
generated
vendored
@ -1 +0,0 @@
|
||||
../browserify/bin/cmd.js
|
1
node_modules/.bin/browservefy
generated
vendored
1
node_modules/.bin/browservefy
generated
vendored
@ -1 +0,0 @@
|
||||
../browservefy/bin/browservefy
|
1
node_modules/.bin/ecstatic
generated
vendored
1
node_modules/.bin/ecstatic
generated
vendored
@ -1 +0,0 @@
|
||||
../ecstatic/lib/ecstatic.js
|
1
node_modules/.bin/http-server
generated
vendored
1
node_modules/.bin/http-server
generated
vendored
@ -1 +0,0 @@
|
||||
../http-server/bin/http-server
|
1
node_modules/.bin/marked
generated
vendored
1
node_modules/.bin/marked
generated
vendored
@ -1 +0,0 @@
|
||||
../marked/bin/marked
|
1
node_modules/beefy/.npmignore
generated
vendored
1
node_modules/beefy/.npmignore
generated
vendored
@ -1 +0,0 @@
|
||||
node_modules
|
60
node_modules/beefy/README.md
generated
vendored
60
node_modules/beefy/README.md
generated
vendored
@ -1,60 +0,0 @@
|
||||
# beefy
|
||||
|
||||
a local development server designed to work with browserify.
|
||||
|
||||
it:
|
||||
|
||||
* can live relaod your browser when your code changes (if you want)
|
||||
* works with whatever version of browserify; globally installed or
|
||||
locally installed to `node_modules/browserify`.
|
||||
* will spit compile errors out into the browser so you don't have that
|
||||
1-2 seconds of cognitive dissonance and profound ennui that follows
|
||||
refreshing the page only to get a blank screen.
|
||||
* will spit out a default `index.html` for missing routes so you don't
|
||||
need to even muck about with HTML to get started
|
||||
* serves up static files with grace and aplomb (and also appropriate
|
||||
mimetypes)
|
||||
* makes it easy to sanity check your [testling ci tape test suite](http://npm.im/tape/).
|
||||
* loves you, unconditionally
|
||||
|
||||
## how do I get it?
|
||||
|
||||
`npm install -g beefy`; and if you want to always have a browserify available
|
||||
for beefy to use, `npm install -g browserify`.
|
||||
|
||||
## usage
|
||||
|
||||
```javascript
|
||||
$ cd directory/you/want/served
|
||||
$ beefy path/to/thing/you/want/browserified.js PORT -- [browserify args]
|
||||
```
|
||||
|
||||
#### `path/to/file.js`
|
||||
|
||||
the path to the file you want browserified. can be just a normal node module.
|
||||
you can also alias it: `path/to/file.js:bundle.js` if you want -- so all requests
|
||||
to `bundle.js` will browserify `path/to/file.js`. this is helpful for when you're
|
||||
writing `gh-pages`-style sites that already have an index.html, and expect the
|
||||
bundle to be pregenerated and available at a certain path.
|
||||
|
||||
#### `--browserify command`
|
||||
|
||||
use `command` instead of `browserify` or `./node_modules/.bin/browserify`.
|
||||
|
||||
in theory, you could even get this working with `r.js`, but that would probably
|
||||
be scary and bats would fly out of it. but it's there if you need it!
|
||||
|
||||
#### `--live`
|
||||
|
||||
enable live reloading. this'll start up a sideband server and an `fs` watch on
|
||||
the current working directory -- if you save a file, your browser will refresh.
|
||||
|
||||
## the fake index
|
||||
|
||||
by default, if you get a URL that doesn't exist (with an `Accept` header that has `html` in it someplace), you'll get the "fake index." this page is setup so that
|
||||
it automatically includes both the live reload script (if it's enabled) **and** the
|
||||
path you want browserified.
|
||||
|
||||
## license
|
||||
|
||||
MIT
|
2
node_modules/beefy/bin/beefy
generated
vendored
2
node_modules/beefy/bin/beefy
generated
vendored
@ -1,2 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
require('../index')
|
11
node_modules/beefy/fake_index.html
generated
vendored
11
node_modules/beefy/fake_index.html
generated
vendored
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Browservefy</title>
|
||||
</head>
|
||||
<body>
|
||||
{{ EXTRA }}
|
||||
<script src="{{ PATH }}" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
38
node_modules/beefy/help.js
generated
vendored
38
node_modules/beefy/help.js
generated
vendored
@ -1,38 +0,0 @@
|
||||
module.exports = help
|
||||
|
||||
function help() {
|
||||
/*
|
||||
beefy path/to/entry.js[:as.js] [PORT] -- [arguments to forward to browserify command]
|
||||
|
||||
Spins up a development server on ``http://localhost:PORT`` for working with static
|
||||
files and browserifiable JavaScript modules.
|
||||
|
||||
If there's a path it doesn't recognize, it will serve up an empty HTML file with
|
||||
your javascript entry point included as a script tag. Otherwise you can provide
|
||||
your own ``index.html``.
|
||||
|
||||
All arguments after ``--`` are forwarded to the ``browserify-command``.
|
||||
|
||||
When the browser requests your entry point, it will run ``browserify-command`` with
|
||||
the forwarded arguments on the file and pipe the results into the response.
|
||||
|
||||
If no PORT is defined, it defaults to 9966.
|
||||
|
||||
If you specify your file in the form ``realfile.js:as-file.js``, any request to
|
||||
``as-file.js`` will browserify ``realfile.js`` and return it as the output.
|
||||
|
||||
arguments:
|
||||
|
||||
--browserify command The command to run to compile your entry point.
|
||||
If not provided, defaults to ``./node_modules/.bin/browserify``,
|
||||
and falls back to ``which browserify`` if that's not
|
||||
available.
|
||||
|
||||
--live Enable live reloading. Reloads the page every time
|
||||
your JavaScript changes.
|
||||
*/
|
||||
|
||||
var str = help+''
|
||||
|
||||
process.stdout.write(str.slice(str.indexOf('/*')+3, str.indexOf('*/')))
|
||||
}
|
216
node_modules/beefy/index.js
generated
vendored
216
node_modules/beefy/index.js
generated
vendored
@ -1,216 +0,0 @@
|
||||
var http = require('http')
|
||||
, spawn = require('child_process').spawn
|
||||
, url = require('url')
|
||||
, path = require('path')
|
||||
, fs = require('fs')
|
||||
|
||||
var filed = require('filed')
|
||||
, LiveReloadServer = require('live-reload')
|
||||
, response_stream = require('response-stream')
|
||||
, optimist = require('optimist').argv
|
||||
, colors = require('colors')
|
||||
, through = require('through')
|
||||
|
||||
var help = require('./help')
|
||||
, fake_index_html = fs.readFileSync(path.join(__dirname, 'fake_index.html'), 'utf8')
|
||||
|
||||
var argv = process.argv.slice(/node/.test(process.argv[0]) ? 2 : 1)
|
||||
, CWD = process.cwd()
|
||||
, browserify_path = which_browserify()
|
||||
, browserify_args = null
|
||||
, ENTRY_POINT_TARGET
|
||||
, ENTRY_POINT_URL
|
||||
, LIVE_PORT
|
||||
, PORT
|
||||
|
||||
if(!get_args()) {
|
||||
return process.exit(1)
|
||||
}
|
||||
|
||||
info('using '+browserify_path.replace(CWD, '.'))
|
||||
|
||||
var RESPONSE_MAP = [
|
||||
'grey'
|
||||
, 'grey'
|
||||
, 'green'
|
||||
, 'magenta'
|
||||
, 'yellow'
|
||||
, 'red'
|
||||
]
|
||||
|
||||
http.createServer(function(req, resp) {
|
||||
var parsed = url.parse(req.url, true)
|
||||
, pathname = parsed.pathname.slice(1) || 'index.html'
|
||||
, filepath = path.resolve(path.join(CWD, pathname))
|
||||
, logged_pathname = '/'+pathname
|
||||
, logged_color = null
|
||||
, query = parsed.query || {}
|
||||
, start = Date.now()
|
||||
, bytesize = 0
|
||||
, stream
|
||||
, args
|
||||
, bfy
|
||||
|
||||
if(pathname === ENTRY_POINT_URL || 'browserify' in query) {
|
||||
args = [
|
||||
pathname === ENTRY_POINT_URL ? ENTRY_POINT_TARGET : filepath
|
||||
].concat(browserify_args)
|
||||
|
||||
logged_pathname = logged_pathname + ' -> ' + [browserify_path]
|
||||
.concat(args)
|
||||
.map(function(xxx) { return xxx.replace(CWD, '.') })
|
||||
.join(' ').magenta
|
||||
|
||||
bfy = spawn(browserify_path, args)
|
||||
stream = response_stream(bfy.stdout)
|
||||
|
||||
logged_color = 'underline'
|
||||
stream.setHeader('content-type', 'text/javascript')
|
||||
|
||||
bfy.stderr.pipe(process.stdout)
|
||||
var error = []
|
||||
bfy.stderr.on('data', [].push.bind(error))
|
||||
bfy.stderr.on('end', function() {
|
||||
if(error.length) {
|
||||
bfyerror(error.join(''))
|
||||
}
|
||||
})
|
||||
} else if(fs.existsSync(filepath)) {
|
||||
stream = fs.createReadStream(filepath)
|
||||
} else if(/html/.test(req.headers.accept || '')) {
|
||||
logged_pathname = logged_pathname.blue + ' ' + '(generated)'.grey
|
||||
stream = response_stream(fake_index(query))
|
||||
stream.setHeader('content-type', 'text/html')
|
||||
} else {
|
||||
stream = response_stream(through())
|
||||
stream.writeHead(404, {'content-type': 'text/plain'})
|
||||
process.nextTick(function() {
|
||||
stream.end('not found')
|
||||
})
|
||||
}
|
||||
|
||||
stream.pipe(resp)
|
||||
stream.on('end', log)
|
||||
stream.on('data', function(data) {
|
||||
bytesize += data.length
|
||||
})
|
||||
|
||||
function log() {
|
||||
var code = resp.statusCode + ''
|
||||
|
||||
console.log(
|
||||
code[RESPONSE_MAP[code.charAt(0)]] + ' '
|
||||
+ pad(Date.now() - start + 'ms', 6) + ' '
|
||||
+ pad(sized(bytesize), 9).grey + ' '
|
||||
+ logged_pathname
|
||||
)
|
||||
}
|
||||
|
||||
function bfyerror(data) {
|
||||
resp.end('('+function(error) {
|
||||
var pre = document.createElement('pre')
|
||||
pre.textContent = error
|
||||
document.body.children.length ?
|
||||
document.body.insertBefore(pre, document.body.children[0]) :
|
||||
document.body.appendChild(pre)
|
||||
}+'('+JSON.stringify(data+'')+'))')
|
||||
}
|
||||
}).listen(PORT)
|
||||
|
||||
if(optimist.live) {
|
||||
LIVE_PORT = optimist.live === true ? 9967 : optimist.live
|
||||
|
||||
LiveReloadServer({
|
||||
port: LIVE_PORT
|
||||
})
|
||||
}
|
||||
|
||||
function fake_index(query) {
|
||||
var stream = through()
|
||||
, index_path
|
||||
, live_text
|
||||
, html
|
||||
|
||||
index_path = query.p || ENTRY_POINT_URL.replace(CWD, '')
|
||||
|
||||
if(query.p) {
|
||||
index_path += '?browserify'
|
||||
}
|
||||
|
||||
live_text = '<script src="http://localhost:' + LIVE_PORT + '"></script>'
|
||||
html = fake_index_html
|
||||
.replace('{{ PATH }}', index_path)
|
||||
.replace('{{ EXTRA }}', LIVE_PORT ? live_text : '')
|
||||
|
||||
process.nextTick(function() {
|
||||
stream.end(html)
|
||||
})
|
||||
|
||||
return stream
|
||||
}
|
||||
|
||||
function get_args() {
|
||||
if(!argv.length || optimist.h || optimist.help) {
|
||||
return help()
|
||||
}
|
||||
|
||||
for(var i = 0, len = argv.length; i < len; ++i) {
|
||||
if(argv[i] === '--') {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
browserify_args = argv.splice(i+1, argv.length - i)
|
||||
|
||||
argv[0] = argv[0].split(':')
|
||||
ENTRY_POINT_TARGET = argv[0][0]
|
||||
ENTRY_POINT_URL = argv[0][~~(1 % argv[0].length)]
|
||||
ENTRY_POINT_TARGET = path.resolve(
|
||||
path.join(CWD, ENTRY_POINT_TARGET)
|
||||
)
|
||||
ENTRY_POINT_URL = ENTRY_POINT_URL.replace(/^\.\//g, '')
|
||||
|
||||
|
||||
PORT = +argv[1] || 9966
|
||||
info('listening on '+PORT)
|
||||
return true
|
||||
}
|
||||
|
||||
function which_browserify() {
|
||||
if(optimist.browserify) {
|
||||
return optimist.browserify
|
||||
}
|
||||
|
||||
var local = path.join(CWD, 'node_modules/.bin/browserify')
|
||||
if(fs.existsSync(local)) {
|
||||
return local
|
||||
}
|
||||
return 'browserify'
|
||||
}
|
||||
|
||||
function info(what) {
|
||||
console.log(what.grey)
|
||||
}
|
||||
|
||||
function sized(bytesize) {
|
||||
var powers = ['B', 'KB', 'MB', 'GB']
|
||||
, curr
|
||||
, next
|
||||
|
||||
for(var i = 0, len = powers.length; i < len; ++i) {
|
||||
curr = Math.pow(1024, i)
|
||||
next = Math.pow(1024, i + 1)
|
||||
|
||||
if(bytesize < next) {
|
||||
return (bytesize / curr).toFixed(2).replace(/\.?0+$/g, '') + powers[i]
|
||||
}
|
||||
}
|
||||
return (bytesize / curr) + 'gib'
|
||||
}
|
||||
|
||||
function pad(s, n, w) {
|
||||
while(s.length < n) {
|
||||
s = (w || ' ') + s
|
||||
}
|
||||
return s
|
||||
}
|
1
node_modules/beefy/node_modules/.bin/live-reload
generated
vendored
1
node_modules/beefy/node_modules/.bin/live-reload
generated
vendored
@ -1 +0,0 @@
|
||||
../live-reload/bin/reload.js
|
22
node_modules/beefy/node_modules/colors/MIT-LICENSE.txt
generated
vendored
22
node_modules/beefy/node_modules/colors/MIT-LICENSE.txt
generated
vendored
@ -1,22 +0,0 @@
|
||||
Copyright (c) 2010
|
||||
|
||||
Marak Squires
|
||||
Alexis Sellier (cloudhead)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
77
node_modules/beefy/node_modules/colors/ReadMe.md
generated
vendored
77
node_modules/beefy/node_modules/colors/ReadMe.md
generated
vendored
@ -1,77 +0,0 @@
|
||||
# colors.js - get color and style in your node.js console ( and browser ) like what
|
||||
|
||||
<img src="http://i.imgur.com/goJdO.png" border = "0"/>
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
npm install colors
|
||||
|
||||
## colors and styles!
|
||||
|
||||
- bold
|
||||
- italic
|
||||
- underline
|
||||
- inverse
|
||||
- yellow
|
||||
- cyan
|
||||
- white
|
||||
- magenta
|
||||
- green
|
||||
- red
|
||||
- grey
|
||||
- blue
|
||||
- rainbow
|
||||
- zebra
|
||||
- random
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
var colors = require('./colors');
|
||||
|
||||
console.log('hello'.green); // outputs green text
|
||||
console.log('i like cake and pies'.underline.red) // outputs red underlined text
|
||||
console.log('inverse the color'.inverse); // inverses the color
|
||||
console.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
|
||||
```
|
||||
|
||||
# Creating Custom themes
|
||||
|
||||
```js
|
||||
|
||||
var require('colors');
|
||||
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log("this is a warning".warn);
|
||||
```
|
||||
|
||||
|
||||
### Contributors
|
||||
|
||||
Marak (Marak Squires)
|
||||
Alexis Sellier (cloudhead)
|
||||
mmalecki (Maciej Małecki)
|
||||
nicoreed (Nico Reed)
|
||||
morganrallen (Morgan Allen)
|
||||
JustinCampbell (Justin Campbell)
|
||||
ded (Dustin Diaz)
|
||||
|
||||
|
||||
#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)
|
269
node_modules/beefy/node_modules/colors/colors.js
generated
vendored
269
node_modules/beefy/node_modules/colors/colors.js
generated
vendored
@ -1,269 +0,0 @@
|
||||
/*
|
||||
colors.js
|
||||
|
||||
Copyright (c) 2010
|
||||
|
||||
Marak Squires
|
||||
Alexis Sellier (cloudhead)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
var isHeadless = false;
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
isHeadless = true;
|
||||
}
|
||||
|
||||
if (!isHeadless) {
|
||||
var exports = {};
|
||||
var module = {};
|
||||
var colors = exports;
|
||||
exports.mode = "browser";
|
||||
} else {
|
||||
exports.mode = "console";
|
||||
}
|
||||
|
||||
//
|
||||
// Prototypes the string object to have additional method calls that add terminal colors
|
||||
//
|
||||
var addProperty = function (color, func) {
|
||||
var allowOverride = ['bold'];
|
||||
exports[color] = function(str) {
|
||||
return func.apply(str);
|
||||
};
|
||||
String.prototype.__defineGetter__(color, func);
|
||||
}
|
||||
|
||||
//
|
||||
// Iterate through all default styles and colors
|
||||
//
|
||||
|
||||
var x = ['bold', 'underline', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
||||
x.forEach(function (style) {
|
||||
|
||||
// __defineGetter__ at the least works in more browsers
|
||||
// http://robertnyman.com/javascript/javascript-getters-setters.html
|
||||
// Object.defineProperty only works in Chrome
|
||||
addProperty(style, function () {
|
||||
return stylize(this, style);
|
||||
});
|
||||
});
|
||||
|
||||
function sequencer(map) {
|
||||
return function () {
|
||||
if (!isHeadless) {
|
||||
return this.replace(/( )/, '$1');
|
||||
}
|
||||
var exploded = this.split("");
|
||||
var i = 0;
|
||||
exploded = exploded.map(map);
|
||||
return exploded.join("");
|
||||
}
|
||||
}
|
||||
|
||||
var rainbowMap = (function () {
|
||||
var rainbowColors = ['red','yellow','green','blue','magenta']; //RoY G BiV
|
||||
return function (letter, i, exploded) {
|
||||
if (letter == " ") {
|
||||
return letter;
|
||||
} else {
|
||||
return stylize(letter, rainbowColors[i++ % rainbowColors.length]);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
exports.addSequencer = function (name, map) {
|
||||
addProperty(name, sequencer(map));
|
||||
}
|
||||
|
||||
exports.addSequencer('rainbow', rainbowMap);
|
||||
exports.addSequencer('zebra', function (letter, i, exploded) {
|
||||
return i % 2 === 0 ? letter : letter.inverse;
|
||||
});
|
||||
|
||||
exports.setTheme = function (theme) {
|
||||
Object.keys(theme).forEach(function(prop){
|
||||
addProperty(prop, function(){
|
||||
return exports[theme[prop]](this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function stylize(str, style) {
|
||||
|
||||
if (exports.mode == 'console') {
|
||||
var styles = {
|
||||
//styles
|
||||
'bold' : ['\033[1m', '\033[22m'],
|
||||
'italic' : ['\033[3m', '\033[23m'],
|
||||
'underline' : ['\033[4m', '\033[24m'],
|
||||
'inverse' : ['\033[7m', '\033[27m'],
|
||||
//grayscale
|
||||
'white' : ['\033[37m', '\033[39m'],
|
||||
'grey' : ['\033[90m', '\033[39m'],
|
||||
'black' : ['\033[30m', '\033[39m'],
|
||||
//colors
|
||||
'blue' : ['\033[34m', '\033[39m'],
|
||||
'cyan' : ['\033[36m', '\033[39m'],
|
||||
'green' : ['\033[32m', '\033[39m'],
|
||||
'magenta' : ['\033[35m', '\033[39m'],
|
||||
'red' : ['\033[31m', '\033[39m'],
|
||||
'yellow' : ['\033[33m', '\033[39m']
|
||||
};
|
||||
} else if (exports.mode == 'browser') {
|
||||
var styles = {
|
||||
//styles
|
||||
'bold' : ['<b>', '</b>'],
|
||||
'italic' : ['<i>', '</i>'],
|
||||
'underline' : ['<u>', '</u>'],
|
||||
'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
|
||||
//grayscale
|
||||
'white' : ['<span style="color:white;">', '</span>'],
|
||||
'grey' : ['<span style="color:grey;">', '</span>'],
|
||||
'black' : ['<span style="color:black;">', '</span>'],
|
||||
//colors
|
||||
'blue' : ['<span style="color:blue;">', '</span>'],
|
||||
'cyan' : ['<span style="color:cyan;">', '</span>'],
|
||||
'green' : ['<span style="color:green;">', '</span>'],
|
||||
'magenta' : ['<span style="color:magenta;">', '</span>'],
|
||||
'red' : ['<span style="color:red;">', '</span>'],
|
||||
'yellow' : ['<span style="color:yellow;">', '</span>']
|
||||
};
|
||||
} else if (exports.mode == 'none') {
|
||||
return str;
|
||||
} else {
|
||||
console.log('unsupported mode, try "browser", "console" or "none"');
|
||||
}
|
||||
return styles[style][0] + str + styles[style][1];
|
||||
};
|
||||
|
||||
// don't summon zalgo
|
||||
addProperty('zalgo', function () {
|
||||
return zalgo(this);
|
||||
});
|
||||
|
||||
// please no
|
||||
function zalgo(text, options) {
|
||||
var soul = {
|
||||
"up" : [
|
||||
'̍','̎','̄','̅',
|
||||
'̿','̑','̆','̐',
|
||||
'͒','͗','͑','̇',
|
||||
'̈','̊','͂','̓',
|
||||
'̈','͊','͋','͌',
|
||||
'̃','̂','̌','͐',
|
||||
'̀','́','̋','̏',
|
||||
'̒','̓','̔','̽',
|
||||
'̉','ͣ','ͤ','ͥ',
|
||||
'ͦ','ͧ','ͨ','ͩ',
|
||||
'ͪ','ͫ','ͬ','ͭ',
|
||||
'ͮ','ͯ','̾','͛',
|
||||
'͆','̚'
|
||||
],
|
||||
"down" : [
|
||||
'̖','̗','̘','̙',
|
||||
'̜','̝','̞','̟',
|
||||
'̠','̤','̥','̦',
|
||||
'̩','̪','̫','̬',
|
||||
'̭','̮','̯','̰',
|
||||
'̱','̲','̳','̹',
|
||||
'̺','̻','̼','ͅ',
|
||||
'͇','͈','͉','͍',
|
||||
'͎','͓','͔','͕',
|
||||
'͖','͙','͚','̣'
|
||||
],
|
||||
"mid" : [
|
||||
'̕','̛','̀','́',
|
||||
'͘','̡','̢','̧',
|
||||
'̨','̴','̵','̶',
|
||||
'͜','͝','͞',
|
||||
'͟','͠','͢','̸',
|
||||
'̷','͡',' ҉'
|
||||
]
|
||||
},
|
||||
all = [].concat(soul.up, soul.down, soul.mid),
|
||||
zalgo = {};
|
||||
|
||||
function randomNumber(range) {
|
||||
r = Math.floor(Math.random()*range);
|
||||
return r;
|
||||
};
|
||||
|
||||
function is_char(character) {
|
||||
var bool = false;
|
||||
all.filter(function(i){
|
||||
bool = (i == character);
|
||||
});
|
||||
return bool;
|
||||
}
|
||||
|
||||
function heComes(text, options){
|
||||
result = '';
|
||||
options = options || {};
|
||||
options["up"] = options["up"] || true;
|
||||
options["mid"] = options["mid"] || true;
|
||||
options["down"] = options["down"] || true;
|
||||
options["size"] = options["size"] || "maxi";
|
||||
var counts;
|
||||
text = text.split('');
|
||||
for(var l in text){
|
||||
if(is_char(l)) { continue; }
|
||||
result = result + text[l];
|
||||
|
||||
counts = {"up" : 0, "down" : 0, "mid" : 0};
|
||||
|
||||
switch(options.size) {
|
||||
case 'mini':
|
||||
counts.up = randomNumber(8);
|
||||
counts.min= randomNumber(2);
|
||||
counts.down = randomNumber(8);
|
||||
break;
|
||||
case 'maxi':
|
||||
counts.up = randomNumber(16) + 3;
|
||||
counts.min = randomNumber(4) + 1;
|
||||
counts.down = randomNumber(64) + 3;
|
||||
break;
|
||||
default:
|
||||
counts.up = randomNumber(8) + 1;
|
||||
counts.mid = randomNumber(6) / 2;
|
||||
counts.down= randomNumber(8) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
var arr = ["up", "mid", "down"];
|
||||
for(var d in arr){
|
||||
var index = arr[d];
|
||||
for (var i = 0 ; i <= counts[index]; i++)
|
||||
{
|
||||
if(options[index]) {
|
||||
result = result + soul[index][randomNumber(soul[index].length)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return heComes(text);
|
||||
}
|
||||
|
||||
addProperty('stripColors', function() {
|
||||
return ("" + this).replace(/\u001b\[\d+m/g,'');
|
||||
});
|
74
node_modules/beefy/node_modules/colors/example.html
generated
vendored
74
node_modules/beefy/node_modules/colors/example.html
generated
vendored
@ -1,74 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>Colors Example</title>
|
||||
<script src="colors.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
var test = colors.red("hopefully colorless output");
|
||||
|
||||
document.write('Rainbows are fun!'.rainbow + '<br/>');
|
||||
document.write('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
|
||||
document.write('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
||||
//document.write('zalgo time!'.zalgo);
|
||||
document.write(test.stripColors);
|
||||
document.write("a".grey + " b".black);
|
||||
|
||||
document.write("Zebras are so fun!".zebra);
|
||||
|
||||
document.write(colors.rainbow('Rainbows are fun!'));
|
||||
document.write(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
||||
document.write(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
||||
//document.write(colors.zalgo('zalgo time!'));
|
||||
document.write(colors.stripColors(test));
|
||||
document.write(colors.grey("a") + colors.black(" b"));
|
||||
|
||||
colors.addSequencer("america", function(letter, i, exploded) {
|
||||
if(letter === " ") return letter;
|
||||
switch(i%3) {
|
||||
case 0: return letter.red;
|
||||
case 1: return letter.white;
|
||||
case 2: return letter.blue;
|
||||
}
|
||||
});
|
||||
|
||||
colors.addSequencer("random", (function() {
|
||||
var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
||||
|
||||
return function(letter, i, exploded) {
|
||||
return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
|
||||
};
|
||||
})());
|
||||
|
||||
document.write("AMERICA! F--K YEAH!".america);
|
||||
document.write("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
|
||||
|
||||
//
|
||||
// Custom themes
|
||||
//
|
||||
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
document.write("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
document.write("this is a warning".warn);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
65
node_modules/beefy/node_modules/colors/example.js
generated
vendored
65
node_modules/beefy/node_modules/colors/example.js
generated
vendored
@ -1,65 +0,0 @@
|
||||
var colors = require('./colors');
|
||||
|
||||
//colors.mode = "browser";
|
||||
|
||||
var test = colors.red("hopefully colorless output");
|
||||
console.log('Rainbows are fun!'.rainbow);
|
||||
console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
|
||||
console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
||||
//console.log('zalgo time!'.zalgo);
|
||||
console.log(test.stripColors);
|
||||
console.log("a".grey + " b".black);
|
||||
|
||||
console.log("Zebras are so fun!".zebra);
|
||||
|
||||
console.log(colors.rainbow('Rainbows are fun!'));
|
||||
console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
||||
console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
||||
//console.log(colors.zalgo('zalgo time!'));
|
||||
console.log(colors.stripColors(test));
|
||||
console.log(colors.grey("a") + colors.black(" b"));
|
||||
|
||||
colors.addSequencer("america", function(letter, i, exploded) {
|
||||
if(letter === " ") return letter;
|
||||
switch(i%3) {
|
||||
case 0: return letter.red;
|
||||
case 1: return letter.white;
|
||||
case 2: return letter.blue;
|
||||
}
|
||||
});
|
||||
|
||||
colors.addSequencer("random", (function() {
|
||||
var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
||||
|
||||
return function(letter, i, exploded) {
|
||||
return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
|
||||
};
|
||||
})());
|
||||
|
||||
console.log("AMERICA! F--K YEAH!".america);
|
||||
console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
|
||||
|
||||
//
|
||||
// Custom themes
|
||||
//
|
||||
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log("this is a warning".warn);
|
||||
|
||||
|
19
node_modules/beefy/node_modules/colors/package.json
generated
vendored
19
node_modules/beefy/node_modules/colors/package.json
generated
vendored
@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "colors",
|
||||
"description": "get colors in your node.js console like what",
|
||||
"version": "0.6.0-1",
|
||||
"author": {
|
||||
"name": "Marak Squires"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/Marak/colors.js.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.1.90"
|
||||
},
|
||||
"main": "colors",
|
||||
"readme": "# colors.js - get color and style in your node.js console ( and browser ) like what\n\n<img src=\"http://i.imgur.com/goJdO.png\" border = \"0\"/>\n\n\n## Installation\n\n npm install colors\n\n## colors and styles!\n\n- bold\n- italic\n- underline\n- inverse\n- yellow\n- cyan\n- white\n- magenta\n- green\n- red\n- grey\n- blue\n- rainbow\n- zebra\n- random\n\n## Usage\n\n``` js\nvar colors = require('./colors');\n\nconsole.log('hello'.green); // outputs green text\nconsole.log('i like cake and pies'.underline.red) // outputs red underlined text\nconsole.log('inverse the color'.inverse); // inverses the color\nconsole.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)\n```\n\n# Creating Custom themes\n\n```js\n\nvar require('colors');\n\ncolors.setTheme({\n silly: 'rainbow',\n input: 'grey',\n verbose: 'cyan',\n prompt: 'grey',\n info: 'green',\n data: 'grey',\n help: 'cyan',\n warn: 'yellow',\n debug: 'blue',\n error: 'red'\n});\n\n// outputs red text\nconsole.log(\"this is an error\".error);\n\n// outputs yellow text\nconsole.log(\"this is a warning\".warn);\n```\n\n\n### Contributors \n\nMarak (Marak Squires)\nAlexis Sellier (cloudhead)\nmmalecki (Maciej Małecki)\nnicoreed (Nico Reed)\nmorganrallen (Morgan Allen)\nJustinCampbell (Justin Campbell)\nded (Dustin Diaz)\n\n\n#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)\n",
|
||||
"_id": "colors@0.6.0-1",
|
||||
"_from": "colors@~0.6.0-1"
|
||||
}
|
65
node_modules/beefy/node_modules/colors/test.js
generated
vendored
65
node_modules/beefy/node_modules/colors/test.js
generated
vendored
@ -1,65 +0,0 @@
|
||||
var assert = require('assert'),
|
||||
colors = require('./colors');
|
||||
|
||||
//
|
||||
// This is a pretty nice example on how tests shouldn't be written. However,
|
||||
// it's more about API stability than about really testing it (although it's
|
||||
// a pretty complete test suite).
|
||||
//
|
||||
|
||||
var s = 'string';
|
||||
|
||||
function a(s, code) {
|
||||
return '\033[' + code.toString() + 'm' + s + '\033[39m';
|
||||
}
|
||||
|
||||
function aE(s, color, code) {
|
||||
assert.equal(s[color], a(s, code));
|
||||
assert.equal(colors[color](s), a(s, code));
|
||||
assert.equal(s[color], colors[color](s));
|
||||
assert.equal(s[color].stripColors, s);
|
||||
assert.equal(s[color].stripColors, colors.stripColors(s));
|
||||
}
|
||||
|
||||
function h(s, color) {
|
||||
return '<span style="color:' + color + ';">' + s + '</span>';
|
||||
// that's pretty dumb approach to testing it
|
||||
}
|
||||
|
||||
var stylesColors = ['white', 'grey', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
|
||||
var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
|
||||
|
||||
colors.mode = 'console';
|
||||
assert.equal(s.bold, '\033[1m' + s + '\033[22m');
|
||||
assert.equal(s.italic, '\033[3m' + s + '\033[23m');
|
||||
assert.equal(s.underline, '\033[4m' + s + '\033[24m');
|
||||
assert.equal(s.inverse, '\033[7m' + s + '\033[27m');
|
||||
assert.ok(s.rainbow);
|
||||
aE(s, 'white', 37);
|
||||
aE(s, 'grey', 90);
|
||||
aE(s, 'black', 30);
|
||||
aE(s, 'blue', 34);
|
||||
aE(s, 'cyan', 36);
|
||||
aE(s, 'green', 32);
|
||||
aE(s, 'magenta', 35);
|
||||
aE(s, 'red', 31);
|
||||
aE(s, 'yellow', 33);
|
||||
assert.equal(s, 'string');
|
||||
|
||||
colors.mode = 'browser';
|
||||
assert.equal(s.bold, '<b>' + s + '</b>');
|
||||
assert.equal(s.italic, '<i>' + s + '</i>');
|
||||
assert.equal(s.underline, '<u>' + s + '</u>');
|
||||
assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
|
||||
assert.ok(s.rainbow);
|
||||
stylesColors.forEach(function (color) {
|
||||
assert.equal(s[color], h(s, color));
|
||||
assert.equal(colors[color](s), h(s, color));
|
||||
});
|
||||
|
||||
colors.mode = 'none';
|
||||
stylesAll.forEach(function (style) {
|
||||
assert.equal(s[style], s);
|
||||
assert.equal(colors[style](s), s);
|
||||
});
|
||||
|
76
node_modules/beefy/node_modules/filed/README.md
generated
vendored
76
node_modules/beefy/node_modules/filed/README.md
generated
vendored
@ -1,76 +0,0 @@
|
||||
# filed -- Simplified file library.
|
||||
|
||||
## Install
|
||||
|
||||
<pre>
|
||||
npm install filed
|
||||
</pre>
|
||||
|
||||
## Super simple to use
|
||||
|
||||
Filed does a lazy stat call so you can actually open a file and begin writing to it and if the file isn't there it will just be created.
|
||||
|
||||
```javascript
|
||||
var filed = require('filed');
|
||||
var f = filed('/newfile')
|
||||
f.write('test')
|
||||
f.end()
|
||||
```
|
||||
|
||||
## Streaming
|
||||
|
||||
The returned file object is a stream so you can do standard stream stuff to it. Based on *what* you do the object it will be a read stream, a write stream.
|
||||
|
||||
So if you send data to it, it'll be a write stream.
|
||||
|
||||
```javascript
|
||||
fs.createReadStream.pipe(filed('/newfile'))
|
||||
```
|
||||
|
||||
If you pipe it to a destination it'll be a read stream.
|
||||
|
||||
```javascript
|
||||
filed('/myfile').pipe(fs.createWriteStream('/out'))
|
||||
```
|
||||
|
||||
And of course you can pipe a filed object from itself to itself and it'll figure it out.
|
||||
|
||||
```javascript
|
||||
filed('/myfile').pipe(filed('/newfile'))
|
||||
```
|
||||
|
||||
Those familiar with [request](http://github.com/mikeal/request) will be familiar seeing object capability detection when doing HTTP. filed does this as well.
|
||||
|
||||
```javascript
|
||||
http.createServer(function (req, resp) {
|
||||
filed('/data.json').pipe(resp)
|
||||
})
|
||||
```
|
||||
|
||||
Not only does the JSON file get streamed to the HTTP Response it will include an Etag, Last-Modified, Content-Length, and a Content-Type header based on the filed extension.
|
||||
|
||||
```javascript
|
||||
http.createServer(function (req, resp) {
|
||||
req.pipe(filed('/newfile')).pipe(resp)
|
||||
})
|
||||
```
|
||||
|
||||
When accepting a PUT request data will be streamed to the file and a 201 status will be sent on the HTTP Response when the upload is finished.
|
||||
|
||||
During a GET request a 404 Response will be sent if the file does not exist.
|
||||
|
||||
```javascript
|
||||
http.createServer(function (req, resp) {
|
||||
req.pipe(filed('/data.json')).pipe(resp)
|
||||
})
|
||||
```
|
||||
|
||||
The Etag and Last-Modified headers filed creates are based solely on the stat() call so if you pipe a request to an existing file the cache control headers will be taken into account; a 304 response will be sent if the cache control headers match a new stat() call. This can be very helpful in avoiding unnecessary disc reads.
|
||||
|
||||
```javascript
|
||||
http.createServer(function (req, resp) {
|
||||
req.pipe(filed('/directory')).pipe(resp)
|
||||
})
|
||||
```
|
||||
|
||||
Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists.
|
202
node_modules/beefy/node_modules/filed/main.js
generated
vendored
202
node_modules/beefy/node_modules/filed/main.js
generated
vendored
@ -1,202 +0,0 @@
|
||||
var fs = require('fs')
|
||||
, util = require('util')
|
||||
, crypto = require('crypto')
|
||||
, stream = require('stream')
|
||||
, path = require('path')
|
||||
, mimetypes = require('./mimetypes')
|
||||
, rfc822 = require('./rfc822')
|
||||
;
|
||||
|
||||
function File (options) {
|
||||
stream.Stream.call(this)
|
||||
|
||||
this.writable = true
|
||||
this.readable = true
|
||||
this.buffers = []
|
||||
|
||||
var self = this
|
||||
|
||||
if (typeof options === 'string') options = {path:options}
|
||||
if (!options.index) options.index = 'index.html'
|
||||
self.writable = (typeof options.writable === "undefined") ? true : options.writable
|
||||
self.readable = (typeof options.readable === "undefined") ? true : options.readable
|
||||
|
||||
self.path = options.path
|
||||
self.index = options.index
|
||||
|
||||
self.on('pipe', function (src) {
|
||||
this.src = src
|
||||
})
|
||||
|
||||
this.buffering = true
|
||||
|
||||
this.mimetype = options.mimetype || mimetypes.lookup(this.path.slice(this.path.lastIndexOf('.')+1))
|
||||
|
||||
var stopBuffering = function () {
|
||||
self.buffering = false
|
||||
while (self.buffers.length) {
|
||||
self.emit('data', self.buffers.shift())
|
||||
}
|
||||
if (self.ended) self.emit('end')
|
||||
}
|
||||
|
||||
fs.stat(options.path, function (err, stats) {
|
||||
|
||||
var finish = function (err, stats) {
|
||||
self.stat = stats
|
||||
if (err && err.code === 'ENOENT' && !self.dest && !self.src) self.src = self.path
|
||||
if (err && !self.dest && !self.src) return self.emit('error', err)
|
||||
if (err && self.dest && !self.dest.writeHead) return self.emit('error', err)
|
||||
|
||||
// See if writes are disabled
|
||||
if (self.src && self.src.method &&
|
||||
!self.writable && self.dest.writeHead &&
|
||||
(self.src.method === 'PUT' || self.src.method === 'POST')) {
|
||||
self.dest.writeHead(405, {'content-type':'text/plain'})
|
||||
self.dest.end(self.src.method+' Not Allowed')
|
||||
return
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
self.etag = crypto.createHash('md5').update(stats.ino+'/'+stats.mtime+'/'+stats.size).digest("hex")
|
||||
self.lastmodified = rfc822.getRFC822Date(stats.mtime)
|
||||
}
|
||||
|
||||
process.nextTick(function () {
|
||||
stopBuffering()
|
||||
})
|
||||
|
||||
// 404 and 500
|
||||
if ( err && self.dest && self.dest.writeHead && // We have an error object and dest is an HTTP response
|
||||
( // Either we have a source and it's a GET/HEAD or we don't have a src
|
||||
(self.src && (self.src.method == 'GET' || self.src.method === 'HEAD')) || (!self.src)
|
||||
)
|
||||
) {
|
||||
if (err.code === 'ENOENT') {
|
||||
self.dest.statusCode = 404
|
||||
self.dest.end('Not Found')
|
||||
} else {
|
||||
self.dest.statusCode = 500
|
||||
self.dest.end(err.message)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Source is an HTTP Server Request
|
||||
if (self.src && (self.src.method === 'GET' || self.src.method === 'HEAD') && self.dest) {
|
||||
if (self.dest.setHeader) {
|
||||
self.dest.setHeader('content-type', self.mimetype)
|
||||
self.dest.setHeader('etag', self.etag)
|
||||
self.dest.setHeader('last-modified', self.lastmodified)
|
||||
}
|
||||
|
||||
if (self.dest.writeHead) {
|
||||
if (self.src && self.src.headers) {
|
||||
if (self.src.headers['if-none-match'] === self.etag ||
|
||||
// Lazy last-modifed matching but it's faster than parsing Datetime
|
||||
self.src.headers['if-modified-since'] === self.lastmodified) {
|
||||
self.dest.statusCode = 304
|
||||
self.dest.end()
|
||||
return
|
||||
}
|
||||
}
|
||||
// We're going to return the whole file
|
||||
self.dest.statusCode = 200
|
||||
self.dest.setHeader('content-length', stats.size)
|
||||
} else {
|
||||
// Destination is not an HTTP response, GET and HEAD method are not allowed
|
||||
return
|
||||
}
|
||||
|
||||
if (self.src.method !== 'HEAD') {
|
||||
fs.createReadStream(self.path).pipe(self.dest)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (self.src && (self.src.method === 'PUT' || self.src.method === 'POST')) {
|
||||
if (!err) {
|
||||
// TODO handle overwrite case
|
||||
return
|
||||
}
|
||||
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))
|
||||
if (self.dest && self.dest.writeHead) {
|
||||
self.on('end', function () {
|
||||
self.dest.statusCode = 201
|
||||
self.dest.setHeader('content-length', 0)
|
||||
self.dest.end()
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Desination is an HTTP response, we already handled 404 and 500
|
||||
if (self.dest && self.dest.writeHead) {
|
||||
self.dest.statusCode = 200
|
||||
self.dest.setHeader('content-type', self.mimetype)
|
||||
self.dest.setHeader('etag', self.etag)
|
||||
self.dest.setHeader('last-modified', self.lastmodified)
|
||||
self.dest.setHeader('content-length', stats.size)
|
||||
fs.createReadStream(self.path).pipe(self.dest)
|
||||
return
|
||||
}
|
||||
|
||||
// Destination is not an HTTP request
|
||||
|
||||
if (self.src && !self.dest) {
|
||||
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))
|
||||
} else if (self.dest && !self.src) {
|
||||
fs.createReadStream(self.path).pipe(self.dest)
|
||||
}
|
||||
}
|
||||
|
||||
if (!err && stats.isDirectory()) {
|
||||
self.path = path.join(self.path, self.index)
|
||||
self.mimetype = mimetypes.lookup(self.path.slice(self.path.lastIndexOf('.')+1))
|
||||
fs.stat(self.path, finish)
|
||||
return
|
||||
} else {
|
||||
finish(err, stats)
|
||||
}
|
||||
|
||||
if (!self.src && !self.dest) {
|
||||
if (self.buffers.length > 0) {
|
||||
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))
|
||||
} else if (self.listeners('data').length > 0) {
|
||||
fs.createReadStream(self.path).pipe(self.dest)
|
||||
} else {
|
||||
fs.createReadStream(self.path).pipe(self)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
util.inherits(File, stream.Stream)
|
||||
File.prototype.pipe = function (dest, options) {
|
||||
this.dest = dest
|
||||
this.destOptions = options
|
||||
dest.emit('pipe', this)
|
||||
// stream.Stream.prototype.pipe.call(this, dest, options)
|
||||
}
|
||||
File.prototype.write = function (chunk, encoding) {
|
||||
if (encoding) chunk = chunk.toString(encoding)
|
||||
if (this.buffering) {
|
||||
this.buffers.push(chunk)
|
||||
} else {
|
||||
this.emit('data', chunk)
|
||||
}
|
||||
}
|
||||
File.prototype.end = function (chunk) {
|
||||
if (chunk) this.write(chunk)
|
||||
if (this.buffering) {
|
||||
this.ended = true
|
||||
} else {
|
||||
this.emit('end')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function (options) {
|
||||
return new File(options)
|
||||
}
|
||||
module.exports.File = File
|
147
node_modules/beefy/node_modules/filed/mimetypes.js
generated
vendored
147
node_modules/beefy/node_modules/filed/mimetypes.js
generated
vendored
@ -1,147 +0,0 @@
|
||||
// from http://github.com/felixge/node-paperboy
|
||||
exports.types = {
|
||||
"aiff":"audio/x-aiff",
|
||||
"arj":"application/x-arj-compressed",
|
||||
"asf":"video/x-ms-asf",
|
||||
"asx":"video/x-ms-asx",
|
||||
"au":"audio/ulaw",
|
||||
"avi":"video/x-msvideo",
|
||||
"bcpio":"application/x-bcpio",
|
||||
"ccad":"application/clariscad",
|
||||
"cod":"application/vnd.rim.cod",
|
||||
"com":"application/x-msdos-program",
|
||||
"cpio":"application/x-cpio",
|
||||
"cpt":"application/mac-compactpro",
|
||||
"csh":"application/x-csh",
|
||||
"css":"text/css",
|
||||
"deb":"application/x-debian-package",
|
||||
"dl":"video/dl",
|
||||
"doc":"application/msword",
|
||||
"drw":"application/drafting",
|
||||
"dvi":"application/x-dvi",
|
||||
"dwg":"application/acad",
|
||||
"dxf":"application/dxf",
|
||||
"dxr":"application/x-director",
|
||||
"etx":"text/x-setext",
|
||||
"ez":"application/andrew-inset",
|
||||
"fli":"video/x-fli",
|
||||
"flv":"video/x-flv",
|
||||
"gif":"image/gif",
|
||||
"gl":"video/gl",
|
||||
"gtar":"application/x-gtar",
|
||||
"gz":"application/x-gzip",
|
||||
"hdf":"application/x-hdf",
|
||||
"hqx":"application/mac-binhex40",
|
||||
"html":"text/html",
|
||||
"ice":"x-conference/x-cooltalk",
|
||||
"ico":"image/x-icon",
|
||||
"ief":"image/ief",
|
||||
"igs":"model/iges",
|
||||
"ips":"application/x-ipscript",
|
||||
"ipx":"application/x-ipix",
|
||||
"jad":"text/vnd.sun.j2me.app-descriptor",
|
||||
"jar":"application/java-archive",
|
||||
"jpeg":"image/jpeg",
|
||||
"jpg":"image/jpeg",
|
||||
"js":"text/javascript",
|
||||
"json":"application/json",
|
||||
"latex":"application/x-latex",
|
||||
"lsp":"application/x-lisp",
|
||||
"lzh":"application/octet-stream",
|
||||
"m":"text/plain",
|
||||
"m3u":"audio/x-mpegurl",
|
||||
"man":"application/x-troff-man",
|
||||
"me":"application/x-troff-me",
|
||||
"midi":"audio/midi",
|
||||
"mif":"application/x-mif",
|
||||
"mime":"www/mime",
|
||||
"movie":"video/x-sgi-movie",
|
||||
"mustache":"text/plain",
|
||||
"mp4":"video/mp4",
|
||||
"mpg":"video/mpeg",
|
||||
"mpga":"audio/mpeg",
|
||||
"ms":"application/x-troff-ms",
|
||||
"nc":"application/x-netcdf",
|
||||
"oda":"application/oda",
|
||||
"ogm":"application/ogg",
|
||||
"pbm":"image/x-portable-bitmap",
|
||||
"pdf":"application/pdf",
|
||||
"pgm":"image/x-portable-graymap",
|
||||
"pgn":"application/x-chess-pgn",
|
||||
"pgp":"application/pgp",
|
||||
"pm":"application/x-perl",
|
||||
"png":"image/png",
|
||||
"pnm":"image/x-portable-anymap",
|
||||
"ppm":"image/x-portable-pixmap",
|
||||
"ppz":"application/vnd.ms-powerpoint",
|
||||
"pre":"application/x-freelance",
|
||||
"prt":"application/pro_eng",
|
||||
"ps":"application/postscript",
|
||||
"qt":"video/quicktime",
|
||||
"ra":"audio/x-realaudio",
|
||||
"rar":"application/x-rar-compressed",
|
||||
"ras":"image/x-cmu-raster",
|
||||
"rgb":"image/x-rgb",
|
||||
"rm":"audio/x-pn-realaudio",
|
||||
"rpm":"audio/x-pn-realaudio-plugin",
|
||||
"rtf":"text/rtf",
|
||||
"rtx":"text/richtext",
|
||||
"scm":"application/x-lotusscreencam",
|
||||
"set":"application/set",
|
||||
"sgml":"text/sgml",
|
||||
"sh":"application/x-sh",
|
||||
"shar":"application/x-shar",
|
||||
"silo":"model/mesh",
|
||||
"sit":"application/x-stuffit",
|
||||
"skt":"application/x-koan",
|
||||
"smil":"application/smil",
|
||||
"snd":"audio/basic",
|
||||
"sol":"application/solids",
|
||||
"spl":"application/x-futuresplash",
|
||||
"src":"application/x-wais-source",
|
||||
"stl":"application/SLA",
|
||||
"stp":"application/STEP",
|
||||
"sv4cpio":"application/x-sv4cpio",
|
||||
"sv4crc":"application/x-sv4crc",
|
||||
"svg":"image/svg+xml",
|
||||
"swf":"application/x-shockwave-flash",
|
||||
"tar":"application/x-tar",
|
||||
"tcl":"application/x-tcl",
|
||||
"tex":"application/x-tex",
|
||||
"texinfo":"application/x-texinfo",
|
||||
"tgz":"application/x-tar-gz",
|
||||
"tiff":"image/tiff",
|
||||
"tr":"application/x-troff",
|
||||
"tsi":"audio/TSP-audio",
|
||||
"tsp":"application/dsptype",
|
||||
"tsv":"text/tab-separated-values",
|
||||
"txt":"text/plain",
|
||||
"unv":"application/i-deas",
|
||||
"ustar":"application/x-ustar",
|
||||
"vcd":"application/x-cdlink",
|
||||
"vda":"application/vda",
|
||||
"vivo":"video/vnd.vivo",
|
||||
"vrm":"x-world/x-vrml",
|
||||
"wav":"audio/x-wav",
|
||||
"wax":"audio/x-ms-wax",
|
||||
"wma":"audio/x-ms-wma",
|
||||
"wmv":"video/x-ms-wmv",
|
||||
"wmx":"video/x-ms-wmx",
|
||||
"wrl":"model/vrml",
|
||||
"wvx":"video/x-ms-wvx",
|
||||
"xbm":"image/x-xbitmap",
|
||||
"xlw":"application/vnd.ms-excel",
|
||||
"xml":"text/xml",
|
||||
"xpm":"image/x-xpixmap",
|
||||
"xwd":"image/x-xwindowdump",
|
||||
"xyz":"chemical/x-pdb",
|
||||
"zip":"application/zip",
|
||||
};
|
||||
|
||||
exports.lookup = function(ext, defaultType) {
|
||||
defaultType = defaultType || 'application/octet-stream';
|
||||
|
||||
return (ext in exports.types)
|
||||
? exports.types[ext]
|
||||
: defaultType;
|
||||
};
|
23
node_modules/beefy/node_modules/filed/package.json
generated
vendored
23
node_modules/beefy/node_modules/filed/package.json
generated
vendored
@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "filed",
|
||||
"description": "Simplified file library.",
|
||||
"version": "0.0.7",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mikeal/filed.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Mikeal Rogers",
|
||||
"email": "mikeal.rogers@gmail.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js"
|
||||
},
|
||||
"main": "./main",
|
||||
"readme": "# filed -- Simplified file library.\n\n## Install\n\n<pre>\n npm install filed\n</pre>\n\n## Super simple to use\n\nFiled does a lazy stat call so you can actually open a file and begin writing to it and if the file isn't there it will just be created.\n\n```javascript\nvar filed = require('filed');\nvar f = filed('/newfile')\nf.write('test')\nf.end()\n```\n\n## Streaming\n\nThe returned file object is a stream so you can do standard stream stuff to it. Based on *what* you do the object it will be a read stream, a write stream.\n\nSo if you send data to it, it'll be a write stream.\n\n```javascript\nfs.createReadStream.pipe(filed('/newfile'))\n```\n\nIf you pipe it to a destination it'll be a read stream.\n\n```javascript\nfiled('/myfile').pipe(fs.createWriteStream('/out'))\n```\n\nAnd of course you can pipe a filed object from itself to itself and it'll figure it out.\n\n```javascript\nfiled('/myfile').pipe(filed('/newfile'))\n```\n\nThose familiar with [request](http://github.com/mikeal/request) will be familiar seeing object capability detection when doing HTTP. filed does this as well.\n\n```javascript\nhttp.createServer(function (req, resp) {\n filed('/data.json').pipe(resp)\n})\n```\n\nNot only does the JSON file get streamed to the HTTP Response it will include an Etag, Last-Modified, Content-Length, and a Content-Type header based on the filed extension.\n\n```javascript\nhttp.createServer(function (req, resp) {\n req.pipe(filed('/newfile')).pipe(resp)\n})\n```\n\nWhen accepting a PUT request data will be streamed to the file and a 201 status will be sent on the HTTP Response when the upload is finished.\n\nDuring a GET request a 404 Response will be sent if the file does not exist.\n\n```javascript\nhttp.createServer(function (req, resp) {\n req.pipe(filed('/data.json')).pipe(resp)\n})\n```\n\nThe Etag and Last-Modified headers filed creates are based solely on the stat() call so if you pipe a request to an existing file the cache control headers will be taken into account; a 304 response will be sent if the cache control headers match a new stat() call. This can be very helpful in avoiding unnecessary disc reads.\n\n```javascript\nhttp.createServer(function (req, resp) {\n req.pipe(filed('/directory')).pipe(resp)\n})\n```\n\nJust to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists.\n",
|
||||
"_id": "filed@0.0.7",
|
||||
"_from": "filed@0.0.7"
|
||||
}
|
47
node_modules/beefy/node_modules/filed/rfc822.js
generated
vendored
47
node_modules/beefy/node_modules/filed/rfc822.js
generated
vendored
@ -1,47 +0,0 @@
|
||||
// Support for rfc822, worst standard EVAR!
|
||||
|
||||
// require('./date')
|
||||
|
||||
function getRFC822Date(oDate)
|
||||
{
|
||||
var aMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
|
||||
|
||||
var aDays = new Array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
|
||||
var dtm = new String();
|
||||
|
||||
dtm = aDays[oDate.getDay()] + ", ";
|
||||
dtm += padWithZero(oDate.getDate()) + " ";
|
||||
dtm += aMonths[oDate.getMonth()] + " ";
|
||||
dtm += oDate.getFullYear() + " ";
|
||||
dtm += padWithZero(oDate.getHours()) + ":";
|
||||
dtm += padWithZero(oDate.getMinutes()) + ":";
|
||||
dtm += padWithZero(oDate.getSeconds()) + " " ;
|
||||
dtm += getTZOString(oDate.getTimezoneOffset());
|
||||
return dtm;
|
||||
}
|
||||
//Pads numbers with a preceding 0 if the number is less than 10.
|
||||
function padWithZero(val)
|
||||
{
|
||||
if (parseInt(val) < 10)
|
||||
{
|
||||
return "0" + val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/* accepts the client's time zone offset from GMT in minutes as a parameter.
|
||||
returns the timezone offset in the format [+|-}DDDD */
|
||||
function getTZOString(timezoneOffset)
|
||||
{
|
||||
var hours = Math.floor(timezoneOffset/60);
|
||||
var modMin = Math.abs(timezoneOffset%60);
|
||||
var s = new String();
|
||||
s += (hours > 0) ? "-" : "+";
|
||||
var absHours = Math.abs(hours)
|
||||
s += (absHours < 10) ? "0" + absHours :absHours;
|
||||
s += ((modMin == 0) ? "00" : modMin);
|
||||
return(s);
|
||||
}
|
||||
|
||||
exports.getRFC822Date = getRFC822Date;
|
1
node_modules/beefy/node_modules/filed/test/index.html
generated
vendored
1
node_modules/beefy/node_modules/filed/test/index.html
generated
vendored
@ -1 +0,0 @@
|
||||
test
|
20
node_modules/beefy/node_modules/filed/test/server.js
generated
vendored
20
node_modules/beefy/node_modules/filed/test/server.js
generated
vendored
@ -1,20 +0,0 @@
|
||||
var http = require('http')
|
||||
|
||||
function createServer () {
|
||||
var s = http.createServer(function (req, resp) {
|
||||
resp.___end = resp.end
|
||||
resp.end = function (chunk) {
|
||||
s.completed[req.url] = true
|
||||
resp.___end(chunk)
|
||||
if (Object.keys(s._events).filter(function(n){return n[0] === '/'}).length === Object.keys(s.completed).length) {
|
||||
setTimeout(function () {
|
||||
s.close()
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
s.emit(req.url, req, resp)
|
||||
})
|
||||
s.completed = {}
|
||||
return s;
|
||||
}
|
||||
module.exports = createServer;
|
209
node_modules/beefy/node_modules/filed/test/test.js
generated
vendored
209
node_modules/beefy/node_modules/filed/test/test.js
generated
vendored
@ -1,209 +0,0 @@
|
||||
var filed = require('../main')
|
||||
, server = require('./server')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, assert = require('assert')
|
||||
, request = require('request')
|
||||
, test1buffer = ''
|
||||
, testfile = path.join(__dirname, 'test.js')
|
||||
, writefile = path.join(__dirname, 'testdump-')
|
||||
, cleanup = []
|
||||
, validations = []
|
||||
, port = 9090
|
||||
, i = 0
|
||||
, url = 'http://localhost:'+port
|
||||
;
|
||||
|
||||
while (i < 50) {
|
||||
try {fs.unlinkSync(writefile+i)}
|
||||
catch (e) {}
|
||||
i += 1
|
||||
}
|
||||
|
||||
function FileValidator (path) {
|
||||
this.path = path
|
||||
this.buffers = []
|
||||
this.len = 0
|
||||
this.writable = true
|
||||
}
|
||||
FileValidator.prototype.write = function (chunk) {
|
||||
this.buffers.push(chunk)
|
||||
this.len += chunk.length
|
||||
}
|
||||
FileValidator.prototype.end = function () {
|
||||
var body = new Buffer(this.len)
|
||||
var i = 0
|
||||
this.buffers.forEach(function (chunk) {
|
||||
chunk.copy(body, i, 0, chunk.length)
|
||||
i += chunk.length
|
||||
})
|
||||
var f = fs.readFileSync(this.path)
|
||||
assert.equal(body.length, f.length)
|
||||
assert.deepEqual(body, f)
|
||||
}
|
||||
FileValidator.prototype.on = function () {}
|
||||
FileValidator.prototype.removeListener = function () {}
|
||||
FileValidator.prototype.emit = function () {}
|
||||
|
||||
function equalSync (f1, f2) {
|
||||
f1 = fs.readFileSync(f1)
|
||||
f2 = fs.readFileSync(f2)
|
||||
assert.equal(f1.length, f2.length)
|
||||
assert.deepEqual(f1, f2)
|
||||
}
|
||||
|
||||
// Test reading
|
||||
filed(testfile).pipe(new FileValidator(testfile))
|
||||
|
||||
// Test writing
|
||||
|
||||
function testwrites () {
|
||||
var x = filed(writefile+1)
|
||||
, y = fs.createReadStream(testfile)
|
||||
;
|
||||
y.pipe(x)
|
||||
x.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+1, testfile)
|
||||
console.log("Passed writing files")
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
testwrites()
|
||||
|
||||
function testhttp () {
|
||||
// Test HTTP use cases
|
||||
var s = server()
|
||||
s.on('/test-req', function (req, resp) {
|
||||
// Take a request and write it, do not send filed to the response
|
||||
req.pipe(filed(writefile+2))
|
||||
req.on('end', function () {
|
||||
resp.writeHead(201)
|
||||
resp.end()
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+2, testfile)
|
||||
console.log("Passed PUT file with pipe req only")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-req-resp', function (req, resp) {
|
||||
// Take a request and write it and pipe filed to the response
|
||||
var x = filed(writefile+3)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
req.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+3, testfile)
|
||||
console.log("Passed PUT file with pipe req and resp")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-resp', function (req, resp) {
|
||||
// Send a file to an HTTP response
|
||||
filed(testfile).pipe(resp)
|
||||
})
|
||||
|
||||
var fullpipe = function (req, resp) {
|
||||
var x = filed(testfile)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
}
|
||||
|
||||
s.on('/test-etags-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-etags-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-lastmodified-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-lastmodified-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-index', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-index-full', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-not-found', function (req, resp) {
|
||||
var x = filed(__dirname + "/there-is-no-such-file-here.no-extension")
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.listen(port, function () {
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req'))
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req-resp', function (e, resp) {
|
||||
assert.equal(resp.statusCode, 201)
|
||||
assert.equal(resp.headers['content-length'], '0')
|
||||
}))
|
||||
|
||||
var x = request.get(url+'/test-resp', function (e, resp) {
|
||||
if (e) throw e
|
||||
assert.equal(resp.statusCode, 200)
|
||||
assert.equal(resp.headers['content-type'], 'text/javascript')
|
||||
console.log("Passed GET file without piping request")
|
||||
})
|
||||
x.pipe(new FileValidator(testfile))
|
||||
|
||||
request.get(url+'/test-etags-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-etags-with', headers:{'if-none-match':resp.headers.etag}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with etag")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-lastmodified-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-lastmodified-with', headers:{'if-modified-since':resp.headers['last-modified']}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with if-modified-since")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-index', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index")
|
||||
})
|
||||
|
||||
request.get(url+'/test-index-full', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index, full pipe")
|
||||
})
|
||||
|
||||
request.get(url+'/test-not-found', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 404) throw new Error('Status code is not 404 it is '+resp.statusCode)
|
||||
console.log("Passed Not Found produces 404")
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
testhttp()
|
||||
|
||||
process.on('exit', function () {console.log('All tests passed.')})
|
209
node_modules/beefy/node_modules/filed/test/testdump-1
generated
vendored
209
node_modules/beefy/node_modules/filed/test/testdump-1
generated
vendored
@ -1,209 +0,0 @@
|
||||
var filed = require('../main')
|
||||
, server = require('./server')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, assert = require('assert')
|
||||
, request = require('request')
|
||||
, test1buffer = ''
|
||||
, testfile = path.join(__dirname, 'test.js')
|
||||
, writefile = path.join(__dirname, 'testdump-')
|
||||
, cleanup = []
|
||||
, validations = []
|
||||
, port = 9090
|
||||
, i = 0
|
||||
, url = 'http://localhost:'+port
|
||||
;
|
||||
|
||||
while (i < 50) {
|
||||
try {fs.unlinkSync(writefile+i)}
|
||||
catch (e) {}
|
||||
i += 1
|
||||
}
|
||||
|
||||
function FileValidator (path) {
|
||||
this.path = path
|
||||
this.buffers = []
|
||||
this.len = 0
|
||||
this.writable = true
|
||||
}
|
||||
FileValidator.prototype.write = function (chunk) {
|
||||
this.buffers.push(chunk)
|
||||
this.len += chunk.length
|
||||
}
|
||||
FileValidator.prototype.end = function () {
|
||||
var body = new Buffer(this.len)
|
||||
var i = 0
|
||||
this.buffers.forEach(function (chunk) {
|
||||
chunk.copy(body, i, 0, chunk.length)
|
||||
i += chunk.length
|
||||
})
|
||||
var f = fs.readFileSync(this.path)
|
||||
assert.equal(body.length, f.length)
|
||||
assert.deepEqual(body, f)
|
||||
}
|
||||
FileValidator.prototype.on = function () {}
|
||||
FileValidator.prototype.removeListener = function () {}
|
||||
FileValidator.prototype.emit = function () {}
|
||||
|
||||
function equalSync (f1, f2) {
|
||||
f1 = fs.readFileSync(f1)
|
||||
f2 = fs.readFileSync(f2)
|
||||
assert.equal(f1.length, f2.length)
|
||||
assert.deepEqual(f1, f2)
|
||||
}
|
||||
|
||||
// Test reading
|
||||
filed(testfile).pipe(new FileValidator(testfile))
|
||||
|
||||
// Test writing
|
||||
|
||||
function testwrites () {
|
||||
var x = filed(writefile+1)
|
||||
, y = fs.createReadStream(testfile)
|
||||
;
|
||||
y.pipe(x)
|
||||
x.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+1, testfile)
|
||||
console.log("Passed writing files")
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
testwrites()
|
||||
|
||||
function testhttp () {
|
||||
// Test HTTP use cases
|
||||
var s = server()
|
||||
s.on('/test-req', function (req, resp) {
|
||||
// Take a request and write it, do not send filed to the response
|
||||
req.pipe(filed(writefile+2))
|
||||
req.on('end', function () {
|
||||
resp.writeHead(201)
|
||||
resp.end()
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+2, testfile)
|
||||
console.log("Passed PUT file with pipe req only")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-req-resp', function (req, resp) {
|
||||
// Take a request and write it and pipe filed to the response
|
||||
var x = filed(writefile+3)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
req.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+3, testfile)
|
||||
console.log("Passed PUT file with pipe req and resp")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-resp', function (req, resp) {
|
||||
// Send a file to an HTTP response
|
||||
filed(testfile).pipe(resp)
|
||||
})
|
||||
|
||||
var fullpipe = function (req, resp) {
|
||||
var x = filed(testfile)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
}
|
||||
|
||||
s.on('/test-etags-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-etags-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-lastmodified-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-lastmodified-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-index', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-index-full', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-not-found', function (req, resp) {
|
||||
var x = filed(__dirname + "/there-is-no-such-file-here.no-extension")
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.listen(port, function () {
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req'))
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req-resp', function (e, resp) {
|
||||
assert.equal(resp.statusCode, 201)
|
||||
assert.equal(resp.headers['content-length'], '0')
|
||||
}))
|
||||
|
||||
var x = request.get(url+'/test-resp', function (e, resp) {
|
||||
if (e) throw e
|
||||
assert.equal(resp.statusCode, 200)
|
||||
assert.equal(resp.headers['content-type'], 'text/javascript')
|
||||
console.log("Passed GET file without piping request")
|
||||
})
|
||||
x.pipe(new FileValidator(testfile))
|
||||
|
||||
request.get(url+'/test-etags-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-etags-with', headers:{'if-none-match':resp.headers.etag}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with etag")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-lastmodified-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-lastmodified-with', headers:{'if-modified-since':resp.headers['last-modified']}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with if-modified-since")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-index', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index")
|
||||
})
|
||||
|
||||
request.get(url+'/test-index-full', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index, full pipe")
|
||||
})
|
||||
|
||||
request.get(url+'/test-not-found', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 404) throw new Error('Status code is not 404 it is '+resp.statusCode)
|
||||
console.log("Passed Not Found produces 404")
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
testhttp()
|
||||
|
||||
process.on('exit', function () {console.log('All tests passed.')})
|
209
node_modules/beefy/node_modules/filed/test/testdump-2
generated
vendored
209
node_modules/beefy/node_modules/filed/test/testdump-2
generated
vendored
@ -1,209 +0,0 @@
|
||||
var filed = require('../main')
|
||||
, server = require('./server')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, assert = require('assert')
|
||||
, request = require('request')
|
||||
, test1buffer = ''
|
||||
, testfile = path.join(__dirname, 'test.js')
|
||||
, writefile = path.join(__dirname, 'testdump-')
|
||||
, cleanup = []
|
||||
, validations = []
|
||||
, port = 9090
|
||||
, i = 0
|
||||
, url = 'http://localhost:'+port
|
||||
;
|
||||
|
||||
while (i < 50) {
|
||||
try {fs.unlinkSync(writefile+i)}
|
||||
catch (e) {}
|
||||
i += 1
|
||||
}
|
||||
|
||||
function FileValidator (path) {
|
||||
this.path = path
|
||||
this.buffers = []
|
||||
this.len = 0
|
||||
this.writable = true
|
||||
}
|
||||
FileValidator.prototype.write = function (chunk) {
|
||||
this.buffers.push(chunk)
|
||||
this.len += chunk.length
|
||||
}
|
||||
FileValidator.prototype.end = function () {
|
||||
var body = new Buffer(this.len)
|
||||
var i = 0
|
||||
this.buffers.forEach(function (chunk) {
|
||||
chunk.copy(body, i, 0, chunk.length)
|
||||
i += chunk.length
|
||||
})
|
||||
var f = fs.readFileSync(this.path)
|
||||
assert.equal(body.length, f.length)
|
||||
assert.deepEqual(body, f)
|
||||
}
|
||||
FileValidator.prototype.on = function () {}
|
||||
FileValidator.prototype.removeListener = function () {}
|
||||
FileValidator.prototype.emit = function () {}
|
||||
|
||||
function equalSync (f1, f2) {
|
||||
f1 = fs.readFileSync(f1)
|
||||
f2 = fs.readFileSync(f2)
|
||||
assert.equal(f1.length, f2.length)
|
||||
assert.deepEqual(f1, f2)
|
||||
}
|
||||
|
||||
// Test reading
|
||||
filed(testfile).pipe(new FileValidator(testfile))
|
||||
|
||||
// Test writing
|
||||
|
||||
function testwrites () {
|
||||
var x = filed(writefile+1)
|
||||
, y = fs.createReadStream(testfile)
|
||||
;
|
||||
y.pipe(x)
|
||||
x.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+1, testfile)
|
||||
console.log("Passed writing files")
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
testwrites()
|
||||
|
||||
function testhttp () {
|
||||
// Test HTTP use cases
|
||||
var s = server()
|
||||
s.on('/test-req', function (req, resp) {
|
||||
// Take a request and write it, do not send filed to the response
|
||||
req.pipe(filed(writefile+2))
|
||||
req.on('end', function () {
|
||||
resp.writeHead(201)
|
||||
resp.end()
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+2, testfile)
|
||||
console.log("Passed PUT file with pipe req only")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-req-resp', function (req, resp) {
|
||||
// Take a request and write it and pipe filed to the response
|
||||
var x = filed(writefile+3)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
req.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+3, testfile)
|
||||
console.log("Passed PUT file with pipe req and resp")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-resp', function (req, resp) {
|
||||
// Send a file to an HTTP response
|
||||
filed(testfile).pipe(resp)
|
||||
})
|
||||
|
||||
var fullpipe = function (req, resp) {
|
||||
var x = filed(testfile)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
}
|
||||
|
||||
s.on('/test-etags-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-etags-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-lastmodified-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-lastmodified-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-index', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-index-full', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-not-found', function (req, resp) {
|
||||
var x = filed(__dirname + "/there-is-no-such-file-here.no-extension")
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.listen(port, function () {
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req'))
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req-resp', function (e, resp) {
|
||||
assert.equal(resp.statusCode, 201)
|
||||
assert.equal(resp.headers['content-length'], '0')
|
||||
}))
|
||||
|
||||
var x = request.get(url+'/test-resp', function (e, resp) {
|
||||
if (e) throw e
|
||||
assert.equal(resp.statusCode, 200)
|
||||
assert.equal(resp.headers['content-type'], 'text/javascript')
|
||||
console.log("Passed GET file without piping request")
|
||||
})
|
||||
x.pipe(new FileValidator(testfile))
|
||||
|
||||
request.get(url+'/test-etags-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-etags-with', headers:{'if-none-match':resp.headers.etag}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with etag")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-lastmodified-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-lastmodified-with', headers:{'if-modified-since':resp.headers['last-modified']}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with if-modified-since")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-index', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index")
|
||||
})
|
||||
|
||||
request.get(url+'/test-index-full', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index, full pipe")
|
||||
})
|
||||
|
||||
request.get(url+'/test-not-found', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 404) throw new Error('Status code is not 404 it is '+resp.statusCode)
|
||||
console.log("Passed Not Found produces 404")
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
testhttp()
|
||||
|
||||
process.on('exit', function () {console.log('All tests passed.')})
|
209
node_modules/beefy/node_modules/filed/test/testdump-3
generated
vendored
209
node_modules/beefy/node_modules/filed/test/testdump-3
generated
vendored
@ -1,209 +0,0 @@
|
||||
var filed = require('../main')
|
||||
, server = require('./server')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, assert = require('assert')
|
||||
, request = require('request')
|
||||
, test1buffer = ''
|
||||
, testfile = path.join(__dirname, 'test.js')
|
||||
, writefile = path.join(__dirname, 'testdump-')
|
||||
, cleanup = []
|
||||
, validations = []
|
||||
, port = 9090
|
||||
, i = 0
|
||||
, url = 'http://localhost:'+port
|
||||
;
|
||||
|
||||
while (i < 50) {
|
||||
try {fs.unlinkSync(writefile+i)}
|
||||
catch (e) {}
|
||||
i += 1
|
||||
}
|
||||
|
||||
function FileValidator (path) {
|
||||
this.path = path
|
||||
this.buffers = []
|
||||
this.len = 0
|
||||
this.writable = true
|
||||
}
|
||||
FileValidator.prototype.write = function (chunk) {
|
||||
this.buffers.push(chunk)
|
||||
this.len += chunk.length
|
||||
}
|
||||
FileValidator.prototype.end = function () {
|
||||
var body = new Buffer(this.len)
|
||||
var i = 0
|
||||
this.buffers.forEach(function (chunk) {
|
||||
chunk.copy(body, i, 0, chunk.length)
|
||||
i += chunk.length
|
||||
})
|
||||
var f = fs.readFileSync(this.path)
|
||||
assert.equal(body.length, f.length)
|
||||
assert.deepEqual(body, f)
|
||||
}
|
||||
FileValidator.prototype.on = function () {}
|
||||
FileValidator.prototype.removeListener = function () {}
|
||||
FileValidator.prototype.emit = function () {}
|
||||
|
||||
function equalSync (f1, f2) {
|
||||
f1 = fs.readFileSync(f1)
|
||||
f2 = fs.readFileSync(f2)
|
||||
assert.equal(f1.length, f2.length)
|
||||
assert.deepEqual(f1, f2)
|
||||
}
|
||||
|
||||
// Test reading
|
||||
filed(testfile).pipe(new FileValidator(testfile))
|
||||
|
||||
// Test writing
|
||||
|
||||
function testwrites () {
|
||||
var x = filed(writefile+1)
|
||||
, y = fs.createReadStream(testfile)
|
||||
;
|
||||
y.pipe(x)
|
||||
x.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+1, testfile)
|
||||
console.log("Passed writing files")
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
testwrites()
|
||||
|
||||
function testhttp () {
|
||||
// Test HTTP use cases
|
||||
var s = server()
|
||||
s.on('/test-req', function (req, resp) {
|
||||
// Take a request and write it, do not send filed to the response
|
||||
req.pipe(filed(writefile+2))
|
||||
req.on('end', function () {
|
||||
resp.writeHead(201)
|
||||
resp.end()
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+2, testfile)
|
||||
console.log("Passed PUT file with pipe req only")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-req-resp', function (req, resp) {
|
||||
// Take a request and write it and pipe filed to the response
|
||||
var x = filed(writefile+3)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
req.on('end', function () {
|
||||
setTimeout(function () {
|
||||
equalSync(writefile+3, testfile)
|
||||
console.log("Passed PUT file with pipe req and resp")
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
s.on('/test-resp', function (req, resp) {
|
||||
// Send a file to an HTTP response
|
||||
filed(testfile).pipe(resp)
|
||||
})
|
||||
|
||||
var fullpipe = function (req, resp) {
|
||||
var x = filed(testfile)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
}
|
||||
|
||||
s.on('/test-etags-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-etags-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-lastmodified-wo', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
s.on('/test-lastmodified-with', function (req, resp) {
|
||||
fullpipe(req, resp)
|
||||
})
|
||||
|
||||
s.on('/test-index', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-index-full', function (req, resp) {
|
||||
var x = filed(__dirname)
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.on('/test-not-found', function (req, resp) {
|
||||
var x = filed(__dirname + "/there-is-no-such-file-here.no-extension")
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
s.listen(port, function () {
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req'))
|
||||
|
||||
fs.createReadStream(testfile).pipe(request.put(url+'/test-req-resp', function (e, resp) {
|
||||
assert.equal(resp.statusCode, 201)
|
||||
assert.equal(resp.headers['content-length'], '0')
|
||||
}))
|
||||
|
||||
var x = request.get(url+'/test-resp', function (e, resp) {
|
||||
if (e) throw e
|
||||
assert.equal(resp.statusCode, 200)
|
||||
assert.equal(resp.headers['content-type'], 'text/javascript')
|
||||
console.log("Passed GET file without piping request")
|
||||
})
|
||||
x.pipe(new FileValidator(testfile))
|
||||
|
||||
request.get(url+'/test-etags-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-etags-with', headers:{'if-none-match':resp.headers.etag}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with etag")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-lastmodified-wo', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
request.get({url:url+'/test-lastmodified-with', headers:{'if-modified-since':resp.headers['last-modified']}}, function (e, resp) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode)
|
||||
console.log("Passed GET with if-modified-since")
|
||||
})
|
||||
})
|
||||
|
||||
request.get(url+'/test-index', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index")
|
||||
})
|
||||
|
||||
request.get(url+'/test-index-full', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode)
|
||||
assert.equal(resp.headers['content-type'], 'text/html')
|
||||
assert.equal(body, fs.readFileSync(path.join(__dirname, 'index.html')).toString())
|
||||
console.log("Passed GET of directory index, full pipe")
|
||||
})
|
||||
|
||||
request.get(url+'/test-not-found', function (e, resp, body) {
|
||||
if (e) throw e
|
||||
if (resp.statusCode !== 404) throw new Error('Status code is not 404 it is '+resp.statusCode)
|
||||
console.log("Passed Not Found produces 404")
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
testhttp()
|
||||
|
||||
process.on('exit', function () {console.log('All tests passed.')})
|
3
node_modules/beefy/node_modules/live-reload/.npmignore
generated
vendored
3
node_modules/beefy/node_modules/live-reload/.npmignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.err
|
19
node_modules/beefy/node_modules/live-reload/LICENCE
generated
vendored
19
node_modules/beefy/node_modules/live-reload/LICENCE
generated
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2012 Raynos.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
34
node_modules/beefy/node_modules/live-reload/README.md
generated
vendored
34
node_modules/beefy/node_modules/live-reload/README.md
generated
vendored
@ -1,34 +0,0 @@
|
||||
# live-reload
|
||||
|
||||
A live reload server & client
|
||||
|
||||
## Docs
|
||||
|
||||
```
|
||||
Usage:
|
||||
|
||||
live-reload [uri] --port=somePort --delay=someDelay
|
||||
|
||||
Runs a live-reload server on the port. It listens on all files
|
||||
in the uri and sends reload commands to any browsers
|
||||
connected to it if the files change.
|
||||
|
||||
If a delay is set then it will send the command once the
|
||||
file has changed and the delay has elapsed. This is
|
||||
useful if your changing many files at once and only
|
||||
want to reload say 1s after all files have been written
|
||||
to disk.
|
||||
|
||||
To connect a browser to a live-reload server simply add
|
||||
<script src="localhost:somePort"></script> to your page
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
`npm install live-reload`
|
||||
|
||||
## Contributors
|
||||
|
||||
- Raynos
|
||||
|
||||
## MIT Licenced
|
17
node_modules/beefy/node_modules/live-reload/bin/reload.js
generated
vendored
17
node_modules/beefy/node_modules/live-reload/bin/reload.js
generated
vendored
@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require("optimist").argv
|
||||
, path = require("path")
|
||||
, filed = require("filed")
|
||||
|
||||
, Reload = require("..")
|
||||
|
||||
, uri = argv.uri = argv._[0]
|
||||
, help = argv.help || argv.h
|
||||
|
||||
if (help) {
|
||||
filed(path.join(__dirname, "usage.txt")).pipe(process.stdout)
|
||||
} else {
|
||||
Reload(argv)
|
||||
}
|
||||
|
16
node_modules/beefy/node_modules/live-reload/bin/usage.txt
generated
vendored
16
node_modules/beefy/node_modules/live-reload/bin/usage.txt
generated
vendored
@ -1,16 +0,0 @@
|
||||
Usage:
|
||||
|
||||
live-reload [uri] --port=somePort --delay=someDelay
|
||||
|
||||
Runs a live-reload server on the port. It listens on all files
|
||||
in the uri and sends reload commands to any browsers
|
||||
connected to it if the files change.
|
||||
|
||||
If a delay is set then it will send the command once the
|
||||
file has changed and the delay has elapsed. This is
|
||||
useful if your changing many files at once and only
|
||||
want to reload say 1s after all files have been written
|
||||
to disk.
|
||||
|
||||
To connect a browser to a live-reload server simply add
|
||||
<script src="localhost:somePort"></script> to your page
|
19
node_modules/beefy/node_modules/live-reload/browser.js
generated
vendored
19
node_modules/beefy/node_modules/live-reload/browser.js
generated
vendored
@ -1,19 +0,0 @@
|
||||
var reconnect = require("reconnect/shoe")
|
||||
|
||||
module.exports = LiveReloadClient
|
||||
|
||||
function LiveReloadClient(uri) {
|
||||
if (typeof uri === "number") {
|
||||
uri = "http://localhost:" + uri
|
||||
}
|
||||
|
||||
reconnect(function (stream) {
|
||||
stream.on("data", ondata)
|
||||
}).connect(uri + "/shoe")
|
||||
}
|
||||
|
||||
function ondata(data) {
|
||||
if (data === "reload") {
|
||||
document.location.reload()
|
||||
}
|
||||
}
|
72
node_modules/beefy/node_modules/live-reload/index.js
generated
vendored
72
node_modules/beefy/node_modules/live-reload/index.js
generated
vendored
@ -1,72 +0,0 @@
|
||||
var http = require("http")
|
||||
, shoe = require("shoe")
|
||||
, path = require("path")
|
||||
, watchr = require("watchr")
|
||||
, bundle = require("browserify-server")
|
||||
, openStreams = []
|
||||
|
||||
module.exports = LiveReloadServer
|
||||
|
||||
function LiveReloadServer(options) {
|
||||
var server = http.createServer(serveText)
|
||||
, sock = shoe(handleStream)
|
||||
, uri = options.uri || process.cwd()
|
||||
, filterIgnored = options.ignore || noop
|
||||
, delay = options.delay || 1000
|
||||
, port = options.port || 9090
|
||||
, timer
|
||||
, source = bundle(path.join(__dirname, "reload.js"), {
|
||||
body: "require('./browser.js')(" + port + ")"
|
||||
})
|
||||
|
||||
watchr.watch({
|
||||
path: uri
|
||||
, listener: reload
|
||||
, ignoreHiddenFiles: true
|
||||
, ignorePatterns: true
|
||||
})
|
||||
|
||||
sock.install(server, "/shoe")
|
||||
|
||||
server.listen(port)
|
||||
|
||||
console.log("live reload server listening on port", port
|
||||
, "reloading on files", uri)
|
||||
|
||||
|
||||
function serveText(req, res) {
|
||||
res.setHeader("content-type", "application/javascript")
|
||||
res.end(source)
|
||||
}
|
||||
|
||||
function handleStream(stream) {
|
||||
openStreams.push(stream)
|
||||
|
||||
stream.on("end", remove)
|
||||
|
||||
function remove() {
|
||||
var index = openStreams.indexOf(stream)
|
||||
if (index !== -1) {
|
||||
openStreams.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reload(fileName) {
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
|
||||
timer = setTimeout(function () {
|
||||
if (!filterIgnored(fileName)) {
|
||||
openStreams.forEach(sendMessage)
|
||||
}
|
||||
}, delay)
|
||||
}
|
||||
|
||||
function sendMessage(stream) {
|
||||
stream && stream.write("reload")
|
||||
}
|
||||
}
|
||||
|
||||
function noop() {}
|
1
node_modules/beefy/node_modules/live-reload/node_modules/.bin/browserify-server
generated
vendored
1
node_modules/beefy/node_modules/live-reload/node_modules/.bin/browserify-server
generated
vendored
@ -1 +0,0 @@
|
||||
../browserify-server/bin/browserify-server.js
|
1
node_modules/beefy/node_modules/live-reload/node_modules/.bin/watchr
generated
vendored
1
node_modules/beefy/node_modules/live-reload/node_modules/.bin/watchr
generated
vendored
@ -1 +0,0 @@
|
||||
../watchr/bin/watchr
|
@ -1,3 +0,0 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.err
|
19
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/LICENCE
generated
vendored
19
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/LICENCE
generated
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2012 Raynos.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
2
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/Makefile
generated
vendored
2
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/Makefile
generated
vendored
@ -1,2 +0,0 @@
|
||||
build:
|
||||
browserify lib/client.js -o lib/bundle.js
|
30
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/README.md
generated
vendored
30
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/README.md
generated
vendored
@ -1,30 +0,0 @@
|
||||
# browserify-server
|
||||
|
||||
Browserify bundling + static server in one!
|
||||
|
||||
## Docs
|
||||
|
||||
```
|
||||
Usage:
|
||||
|
||||
browserify-server bundle [file] -o [out]
|
||||
|
||||
bundle the file and write the bundle to out
|
||||
|
||||
browserify-server server [folder] --port PORT
|
||||
|
||||
Run a static http server serving the folder
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
`npm install browserify-server`
|
||||
|
||||
## Contributors
|
||||
|
||||
- Raynos
|
||||
|
||||
## MIT Licenced
|
||||
|
||||
[1]: https://secure.travis-ci.org/Raynos/browserify-server.png
|
||||
[2]: http://travis-ci.org/Raynos/browserify-server
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require("optimist").argv
|
||||
, path = require("path")
|
||||
, fs = require("fs")
|
||||
, filed = require("filed")
|
||||
|
||||
, Bundle = require("..")
|
||||
, Server = require("../server")
|
||||
|
||||
, help = argv.help || argv.h
|
||||
, index = argv.index || argv.i
|
||||
, bundle = argv.bundle || argv.b
|
||||
, server = argv.server || argv.s
|
||||
, output = argv.output || argv.o
|
||||
, port = argv.port || argv.p
|
||||
|
||||
if (help) {
|
||||
filed(path.join(__dirname, "usage.txt")).pipe(process.stdout)
|
||||
} else if (index) {
|
||||
filed(path.join(__dirname, "index.html")).pipe(process.stdout)
|
||||
} else if (bundle) {
|
||||
var data = Bundle(bundle, output)
|
||||
fs.writeFileSync(output, data, "utf-8")
|
||||
console.log("bundled", bundle, "to", output
|
||||
, "with env", process.env.NODE_ENV)
|
||||
} else if (server) {
|
||||
Server(server, port)
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Your title </title>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script src="bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,9 +0,0 @@
|
||||
Usage:
|
||||
|
||||
browserify-server bundle [file] -o [out]
|
||||
|
||||
bundle the file and write the bundle to out
|
||||
|
||||
browserify-server server [folder] --port PORT
|
||||
|
||||
Run a static http server serving the folder
|
36
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/index.js
generated
vendored
36
node_modules/beefy/node_modules/live-reload/node_modules/browserify-server/index.js
generated
vendored
@ -1,36 +0,0 @@
|
||||
var path = require("path")
|
||||
, fs = require("fs")
|
||||
, browserify = require("browserify")
|
||||
|
||||
module.exports = bundle
|
||||
|
||||
function bundle(input, options) {
|
||||
var bundle = createBundle(input, options)
|
||||
|
||||
try {
|
||||
return bundle.bundle()
|
||||
} catch (err) {
|
||||
console.error("[BROWSERIFY-SERVER]", err)
|
||||
}
|
||||
}
|
||||
|
||||
function createBundle(input, options) {
|
||||
var bundle = browserify({
|
||||
debug: true
|
||||
})
|
||||
|
||||
bundle.register(".html", handleHtml)
|
||||
bundle.register(".svg", handleHtml)
|
||||
|
||||
bundle.addEntry(path.join(__dirname, "other.js"), {
|
||||
body: "process.env.NODE_ENV = '" +
|
||||
process.env.NODE_ENV + "'\n"
|
||||
})
|
||||
bundle.addEntry(input, options)
|
||||
|
||||
return bundle
|
||||
}
|
||||
|
||||
function handleHtml(file, fileName) {
|
||||
return "module.exports = '" + file.replace(/\n/g, "\\n") + "'"
|
||||
}
|
@ -1 +0,0 @@
|
||||
../browserify/bin/cmd.js
|
@ -1,4 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
@ -1,63 +0,0 @@
|
||||
Some pieces from builtins/ taken from node core under this license:
|
||||
|
||||
----
|
||||
|
||||
Copyright Joyent, Inc. and other Node contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
----
|
||||
|
||||
buffer_ieee754.js has this license in it:
|
||||
|
||||
----
|
||||
|
||||
Copyright (c) 2008, Fair Oaks Labs, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Modifications to writeIEEE754 to support negative zeroes made by Brian White
|
||||
|
||||
----
|
@ -1,172 +0,0 @@
|
||||
browserify
|
||||
==========
|
||||
|
||||
Make node-style require() work in the browser with a server-side build step,
|
||||
as if by magic!
|
||||
|
||||
[![build status](https://secure.travis-ci.org/substack/node-browserify.png)](http://travis-ci.org/substack/node-browserify)
|
||||
|
||||
![browserify!](http://substack.net/images/browserify/browserify.png)
|
||||
|
||||
example
|
||||
=======
|
||||
|
||||
Just write an `entry.js` to start with some `require()`s in it:
|
||||
|
||||
````javascript
|
||||
// use relative requires
|
||||
var foo = require('./foo');
|
||||
var bar = require('../lib/bar');
|
||||
|
||||
// or use modules installed by npm into node_modules/
|
||||
var gamma = require('gamma');
|
||||
|
||||
var elem = document.getElementById('result');
|
||||
var x = foo(100) + bar('baz');
|
||||
elem.textContent = gamma(x);
|
||||
````
|
||||
|
||||
Now just use the `browserify` command to build a bundle starting at `entry.js`:
|
||||
|
||||
```
|
||||
$ browserify entry.js -o bundle.js
|
||||
```
|
||||
|
||||
All of the modules that `entry.js` needs are included in the final bundle from a
|
||||
recursive walk using [detective](https://github.com/substack/node-detective).
|
||||
|
||||
To use the bundle, just toss a `<script src="bundle.js"></script>` into your
|
||||
html!
|
||||
|
||||
usage
|
||||
=====
|
||||
|
||||
````
|
||||
Usage: browserify [entry files] {OPTIONS}
|
||||
|
||||
Options:
|
||||
--outfile, -o Write the browserify bundle to this file.
|
||||
If unspecified, browserify prints to stdout.
|
||||
--require, -r A module name or file to bundle.require()
|
||||
Optionally use a colon separator to set the target.
|
||||
--entry, -e An entry point of your app
|
||||
--exports Export these core objects, comma-separated list
|
||||
with any of: require, process. If unspecified, the
|
||||
export behavior will be inferred.
|
||||
|
||||
--ignore, -i Ignore a file
|
||||
--alias, -a Register an alias with a colon separator: "to:from"
|
||||
Example: --alias 'jquery:jquery-browserify'
|
||||
--cache, -c Turn on caching at $HOME/.config/browserling/cache.json or use
|
||||
a file for caching.
|
||||
[default: true]
|
||||
--debug, -d Switch on debugging mode with //@ sourceURL=...s. [boolean]
|
||||
--plugin, -p Use a plugin.
|
||||
Example: --plugin aliasify
|
||||
--prelude Include the code that defines require() in this bundle.
|
||||
[boolean] [default: true]
|
||||
--watch, -w Watch for changes. The script will stay open and write updates
|
||||
to the output every time any of the bundled files change.
|
||||
This option only works in tandem with -o.
|
||||
--verbose, -v Write out how many bytes were written in -o mode. This is
|
||||
especially useful with --watch.
|
||||
--help, -h Show this message
|
||||
|
||||
````
|
||||
|
||||
compatibility
|
||||
=============
|
||||
|
||||
Many [npm](http://npmjs.org) modules that don't do IO will just work after being
|
||||
browserified. Others take more work.
|
||||
|
||||
[coffee script](http://coffeescript.org/) should pretty much just work.
|
||||
Just do `browserify entry.coffee` or `require('./foo.coffee')`.
|
||||
|
||||
Many node built-in modules have been wrapped to work in the browser.
|
||||
All you need to do is `require()` them like in node.
|
||||
|
||||
* events
|
||||
* path
|
||||
* [vm](https://github.com/substack/vm-browserify)
|
||||
* [http](https://github.com/substack/http-browserify)
|
||||
* [crypto](https://github.com/dominictarr/crypto-browserify)
|
||||
* assert
|
||||
* url
|
||||
* buffer
|
||||
* buffer_ieee754
|
||||
* util
|
||||
* querystring
|
||||
* stream
|
||||
|
||||
process
|
||||
-------
|
||||
|
||||
Browserify makes available a faux `process` object to modules with these
|
||||
attributes:
|
||||
|
||||
* nextTick(fn) - uses [the postMessage trick](http://dbaron.org/log/20100309-faster-timeouts)
|
||||
for a faster `setTimeout(fn, 0)` if it can
|
||||
* title - set to 'browser' for browser code, 'node' in regular node code
|
||||
* browser - `true`, good for testing if you're in a browser or in node
|
||||
|
||||
By default the process object is only available inside of files wrapped by
|
||||
browserify. To expose it, use `--exports=process`
|
||||
|
||||
__dirname
|
||||
---------
|
||||
|
||||
The faux directory name, scrubbed of true directory information so as not to
|
||||
expose your filesystem organization.
|
||||
|
||||
__filename
|
||||
----------
|
||||
|
||||
The faux file path, scrubbed of true path information so as not to expose your
|
||||
filesystem organization.
|
||||
|
||||
package.json
|
||||
============
|
||||
|
||||
In order to resolve main files for projects, the package.json "main" field is
|
||||
read.
|
||||
|
||||
If a package.json has a "browserify" field, you can override the standard "main"
|
||||
behavior with something special just for browsers.
|
||||
|
||||
See [dnode's
|
||||
package.json](https://github.com/substack/dnode/blob/9e24b97cf2ce931fbf6d7beb3731086b46bca887/package.json#L40)
|
||||
for an example of using the "browserify" field.
|
||||
|
||||
more
|
||||
====
|
||||
|
||||
* [browserify recipes](https://github.com/substack/node-browserify/blob/master/doc/recipes.markdown#recipes)
|
||||
* [browserify api reference](https://github.com/substack/node-browserify/blob/master/doc/methods.markdown#methods)
|
||||
* [browserify cdn](http://browserify.nodejitsu.com/)
|
||||
|
||||
install
|
||||
=======
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install -g browserify
|
||||
```
|
||||
|
||||
test
|
||||
====
|
||||
|
||||
To run the node tests with tap, do:
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
To run the [testling](http://testling.com) tests,
|
||||
create a [browserling](http://browserling.com) account then:
|
||||
|
||||
```
|
||||
cd testling
|
||||
./test.sh
|
||||
```
|
@ -1,161 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var browserify = require('../');
|
||||
var fs = require('fs');
|
||||
var resolve = require('resolve');
|
||||
|
||||
var argv = require('optimist')
|
||||
.usage('Usage: browserify [entry files] {OPTIONS}')
|
||||
.wrap(80)
|
||||
.option('outfile', {
|
||||
alias : 'o',
|
||||
desc : 'Write the browserify bundle to this file.\n'
|
||||
+ 'If unspecified, browserify prints to stdout.'
|
||||
,
|
||||
})
|
||||
.option('require', {
|
||||
alias : 'r',
|
||||
desc : 'A module name or file to bundle.require()\n'
|
||||
+ 'Optionally use a colon separator to set the target.'
|
||||
,
|
||||
})
|
||||
.option('entry', {
|
||||
alias : 'e',
|
||||
desc : 'An entry point of your app'
|
||||
})
|
||||
.option('exports', {
|
||||
desc : 'Export these core objects, comma-separated list\n'
|
||||
+ 'with any of: require, process. If unspecified, the\n'
|
||||
+ 'export behavior will be inferred.\n'
|
||||
})
|
||||
.option('ignore', {
|
||||
alias : 'i',
|
||||
desc : 'Ignore a file'
|
||||
})
|
||||
.option('alias', {
|
||||
alias : 'a',
|
||||
desc : 'Register an alias with a colon separator: "to:from"\n'
|
||||
+ "Example: --alias 'jquery:jquery-browserify'"
|
||||
,
|
||||
})
|
||||
.option('cache', {
|
||||
alias : 'c',
|
||||
desc : 'Turn on caching at $HOME/.config/browserling/cache.json '
|
||||
+ 'or use a file for caching.\n',
|
||||
default : true,
|
||||
})
|
||||
.option('debug', {
|
||||
alias : 'd',
|
||||
desc : 'Switch on debugging mode with //@ sourceURL=...s.',
|
||||
type : 'boolean'
|
||||
})
|
||||
.option('plugin', {
|
||||
alias : 'p',
|
||||
desc : 'Use a plugin.\n'
|
||||
+ 'Example: --plugin aliasify'
|
||||
,
|
||||
})
|
||||
.option('prelude', {
|
||||
default : true,
|
||||
type : 'boolean',
|
||||
desc : 'Include the code that defines require() in this bundle.'
|
||||
})
|
||||
.option('watch', {
|
||||
alias : 'w',
|
||||
desc : 'Watch for changes. The script will stay open and write updates '
|
||||
+ 'to the output every time any of the bundled files change.\n'
|
||||
+ 'This option only works in tandem with -o.'
|
||||
,
|
||||
})
|
||||
.option('verbose', {
|
||||
alias : 'v',
|
||||
desc : 'Write out how many bytes were written in -o mode. '
|
||||
+ 'This is especially useful with --watch.'
|
||||
,
|
||||
})
|
||||
.option('help', {
|
||||
alias : 'h',
|
||||
desc : 'Show this message'
|
||||
})
|
||||
.check(function (argv) {
|
||||
if (argv.help) throw ''
|
||||
if (process.argv.length <= 2) throw 'Specify a parameter.'
|
||||
})
|
||||
.argv
|
||||
;
|
||||
|
||||
var bundle = browserify({
|
||||
watch : argv.watch,
|
||||
cache : argv.cache,
|
||||
debug : argv.debug,
|
||||
exports : argv.exports && argv.exports.split(','),
|
||||
});
|
||||
|
||||
bundle.on('syntaxError', function (err) {
|
||||
console.error(err);
|
||||
if (!argv.watch) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
if (argv.noprelude || argv.prelude === false) {
|
||||
bundle.files = [];
|
||||
bundle.prepends = [];
|
||||
}
|
||||
if (argv.ignore) bundle.ignore(argv.ignore);
|
||||
|
||||
([].concat(argv.plugin || [])).forEach(function (plugin) {
|
||||
var resolved = resolve.sync(plugin, { basedir : process.cwd() });
|
||||
bundle.use(require(resolved));
|
||||
});
|
||||
|
||||
([].concat(argv.alias || [])).forEach(function (alias) {
|
||||
if (!alias.match(/:/)) {
|
||||
console.error('aliases require a colon separator');
|
||||
process.exit();
|
||||
}
|
||||
bundle.alias.apply(bundle, alias.split(':'));
|
||||
});
|
||||
|
||||
([].concat(argv.require || [])).forEach(function (req) {
|
||||
if (req.match(/:/)) {
|
||||
var s = req.split(':');
|
||||
bundle.require(s[0], { target : s[1] });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^[.\/]/.test(req)) {
|
||||
try {
|
||||
var res = resolve.sync(req, { basedir : process.cwd() });
|
||||
}
|
||||
catch (e) {
|
||||
return bundle.require(req);
|
||||
}
|
||||
return bundle.require(res, { target : req });
|
||||
}
|
||||
bundle.require(req);
|
||||
});
|
||||
|
||||
(argv._.concat(argv.entry || [])).forEach(function (entry) {
|
||||
bundle.addEntry(entry);
|
||||
});
|
||||
|
||||
if (argv.outfile) {
|
||||
function write () {
|
||||
var src = bundle.bundle();
|
||||
if (!bundle.ok) return;
|
||||
|
||||
fs.writeFile(argv.outfile, src, function () {
|
||||
if (argv.verbose) {
|
||||
console.log(Buffer(src).length + ' bytes written');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
write();
|
||||
if (argv.watch) bundle.on('bundle', write)
|
||||
}
|
||||
else {
|
||||
var src = bundle.bundle();
|
||||
if (bundle.ok) console.log(src);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
var process = module.exports = {};
|
||||
|
||||
process.nextTick = (function () {
|
||||
var canSetImmediate = typeof window !== 'undefined'
|
||||
&& window.setImmediate;
|
||||
var canPost = typeof window !== 'undefined'
|
||||
&& window.postMessage && window.addEventListener
|
||||
;
|
||||
|
||||
if (canSetImmediate) {
|
||||
return function (f) { return window.setImmediate(f) };
|
||||
}
|
||||
|
||||
if (canPost) {
|
||||
var queue = [];
|
||||
window.addEventListener('message', function (ev) {
|
||||
if (ev.source === window && ev.data === 'browserify-tick') {
|
||||
ev.stopPropagation();
|
||||
if (queue.length > 0) {
|
||||
var fn = queue.shift();
|
||||
fn();
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
|
||||
return function nextTick(fn) {
|
||||
queue.push(fn);
|
||||
window.postMessage('browserify-tick', '*');
|
||||
};
|
||||
}
|
||||
|
||||
return function nextTick(fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
})();
|
||||
|
||||
process.title = 'browser';
|
||||
process.browser = true;
|
||||
process.env = {};
|
||||
process.argv = [];
|
||||
|
||||
process.binding = function (name) {
|
||||
if (name === 'evals') return (require)('vm')
|
||||
else throw new Error('No such module. (Possibly not yet loaded)')
|
||||
};
|
||||
|
||||
(function () {
|
||||
var cwd = '/';
|
||||
var path;
|
||||
process.cwd = function () { return cwd };
|
||||
process.chdir = function (dir) {
|
||||
if (!path) path = require('path');
|
||||
cwd = path.resolve(dir, cwd);
|
||||
};
|
||||
})();
|
@ -1,314 +0,0 @@
|
||||
// UTILITY
|
||||
var util = require('util');
|
||||
var Buffer = require("buffer").Buffer;
|
||||
var pSlice = Array.prototype.slice;
|
||||
|
||||
function objectKeys(object) {
|
||||
if (Object.keys) return Object.keys(object);
|
||||
var result = [];
|
||||
for (var name in object) {
|
||||
if (Object.prototype.hasOwnProperty.call(object, name)) {
|
||||
result.push(name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 1. The assert module provides functions that throw
|
||||
// AssertionError's when particular conditions are not met. The
|
||||
// assert module must conform to the following interface.
|
||||
|
||||
var assert = module.exports = ok;
|
||||
|
||||
// 2. The AssertionError is defined in assert.
|
||||
// new assert.AssertionError({ message: message,
|
||||
// actual: actual,
|
||||
// expected: expected })
|
||||
|
||||
assert.AssertionError = function AssertionError(options) {
|
||||
this.name = 'AssertionError';
|
||||
this.message = options.message;
|
||||
this.actual = options.actual;
|
||||
this.expected = options.expected;
|
||||
this.operator = options.operator;
|
||||
var stackStartFunction = options.stackStartFunction || fail;
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, stackStartFunction);
|
||||
}
|
||||
};
|
||||
util.inherits(assert.AssertionError, Error);
|
||||
|
||||
function replacer(key, value) {
|
||||
if (value === undefined) {
|
||||
return '' + value;
|
||||
}
|
||||
if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
|
||||
return value.toString();
|
||||
}
|
||||
if (typeof value === 'function' || value instanceof RegExp) {
|
||||
return value.toString();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function truncate(s, n) {
|
||||
if (typeof s == 'string') {
|
||||
return s.length < n ? s : s.slice(0, n);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
assert.AssertionError.prototype.toString = function() {
|
||||
if (this.message) {
|
||||
return [this.name + ':', this.message].join(' ');
|
||||
} else {
|
||||
return [
|
||||
this.name + ':',
|
||||
truncate(JSON.stringify(this.actual, replacer), 128),
|
||||
this.operator,
|
||||
truncate(JSON.stringify(this.expected, replacer), 128)
|
||||
].join(' ');
|
||||
}
|
||||
};
|
||||
|
||||
// assert.AssertionError instanceof Error
|
||||
|
||||
assert.AssertionError.__proto__ = Error.prototype;
|
||||
|
||||
// At present only the three keys mentioned above are used and
|
||||
// understood by the spec. Implementations or sub modules can pass
|
||||
// other keys to the AssertionError's constructor - they will be
|
||||
// ignored.
|
||||
|
||||
// 3. All of the following functions must throw an AssertionError
|
||||
// when a corresponding condition is not met, with a message that
|
||||
// may be undefined if not provided. All assertion methods provide
|
||||
// both the actual and expected values to the assertion error for
|
||||
// display purposes.
|
||||
|
||||
function fail(actual, expected, message, operator, stackStartFunction) {
|
||||
throw new assert.AssertionError({
|
||||
message: message,
|
||||
actual: actual,
|
||||
expected: expected,
|
||||
operator: operator,
|
||||
stackStartFunction: stackStartFunction
|
||||
});
|
||||
}
|
||||
|
||||
// EXTENSION! allows for well behaved errors defined elsewhere.
|
||||
assert.fail = fail;
|
||||
|
||||
// 4. Pure assertion tests whether a value is truthy, as determined
|
||||
// by !!guard.
|
||||
// assert.ok(guard, message_opt);
|
||||
// This statement is equivalent to assert.equal(true, guard,
|
||||
// message_opt);. To test strictly for the value true, use
|
||||
// assert.strictEqual(true, guard, message_opt);.
|
||||
|
||||
function ok(value, message) {
|
||||
if (!!!value) fail(value, true, message, '==', assert.ok);
|
||||
}
|
||||
assert.ok = ok;
|
||||
|
||||
// 5. The equality assertion tests shallow, coercive equality with
|
||||
// ==.
|
||||
// assert.equal(actual, expected, message_opt);
|
||||
|
||||
assert.equal = function equal(actual, expected, message) {
|
||||
if (actual != expected) fail(actual, expected, message, '==', assert.equal);
|
||||
};
|
||||
|
||||
// 6. The non-equality assertion tests for whether two objects are not equal
|
||||
// with != assert.notEqual(actual, expected, message_opt);
|
||||
|
||||
assert.notEqual = function notEqual(actual, expected, message) {
|
||||
if (actual == expected) {
|
||||
fail(actual, expected, message, '!=', assert.notEqual);
|
||||
}
|
||||
};
|
||||
|
||||
// 7. The equivalence assertion tests a deep equality relation.
|
||||
// assert.deepEqual(actual, expected, message_opt);
|
||||
|
||||
assert.deepEqual = function deepEqual(actual, expected, message) {
|
||||
if (!_deepEqual(actual, expected)) {
|
||||
fail(actual, expected, message, 'deepEqual', assert.deepEqual);
|
||||
}
|
||||
};
|
||||
|
||||
function _deepEqual(actual, expected) {
|
||||
// 7.1. All identical values are equivalent, as determined by ===.
|
||||
if (actual === expected) {
|
||||
return true;
|
||||
|
||||
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
|
||||
if (actual.length != expected.length) return false;
|
||||
|
||||
for (var i = 0; i < actual.length; i++) {
|
||||
if (actual[i] !== expected[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
// 7.2. If the expected value is a Date object, the actual value is
|
||||
// equivalent if it is also a Date object that refers to the same time.
|
||||
} else if (actual instanceof Date && expected instanceof Date) {
|
||||
return actual.getTime() === expected.getTime();
|
||||
|
||||
// 7.3. Other pairs that do not both pass typeof value == 'object',
|
||||
// equivalence is determined by ==.
|
||||
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
||||
return actual == expected;
|
||||
|
||||
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
||||
// determined by having the same number of owned properties (as verified
|
||||
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
||||
// (although not necessarily the same order), equivalent values for every
|
||||
// corresponding key, and an identical 'prototype' property. Note: this
|
||||
// accounts for both named and indexed properties on Arrays.
|
||||
} else {
|
||||
return objEquiv(actual, expected);
|
||||
}
|
||||
}
|
||||
|
||||
function isUndefinedOrNull(value) {
|
||||
return value === null || value === undefined;
|
||||
}
|
||||
|
||||
function isArguments(object) {
|
||||
return Object.prototype.toString.call(object) == '[object Arguments]';
|
||||
}
|
||||
|
||||
function objEquiv(a, b) {
|
||||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
||||
return false;
|
||||
// an identical 'prototype' property.
|
||||
if (a.prototype !== b.prototype) return false;
|
||||
//~~~I've managed to break Object.keys through screwy arguments passing.
|
||||
// Converting to array solves the problem.
|
||||
if (isArguments(a)) {
|
||||
if (!isArguments(b)) {
|
||||
return false;
|
||||
}
|
||||
a = pSlice.call(a);
|
||||
b = pSlice.call(b);
|
||||
return _deepEqual(a, b);
|
||||
}
|
||||
try {
|
||||
var ka = objectKeys(a),
|
||||
kb = objectKeys(b),
|
||||
key, i;
|
||||
} catch (e) {//happens when one is a string literal and the other isn't
|
||||
return false;
|
||||
}
|
||||
// having the same number of owned properties (keys incorporates
|
||||
// hasOwnProperty)
|
||||
if (ka.length != kb.length)
|
||||
return false;
|
||||
//the same set of keys (although not necessarily the same order),
|
||||
ka.sort();
|
||||
kb.sort();
|
||||
//~~~cheap key test
|
||||
for (i = ka.length - 1; i >= 0; i--) {
|
||||
if (ka[i] != kb[i])
|
||||
return false;
|
||||
}
|
||||
//equivalent values for every corresponding key, and
|
||||
//~~~possibly expensive deep test
|
||||
for (i = ka.length - 1; i >= 0; i--) {
|
||||
key = ka[i];
|
||||
if (!_deepEqual(a[key], b[key])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 8. The non-equivalence assertion tests for any deep inequality.
|
||||
// assert.notDeepEqual(actual, expected, message_opt);
|
||||
|
||||
assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
||||
if (_deepEqual(actual, expected)) {
|
||||
fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
|
||||
}
|
||||
};
|
||||
|
||||
// 9. The strict equality assertion tests strict equality, as determined by ===.
|
||||
// assert.strictEqual(actual, expected, message_opt);
|
||||
|
||||
assert.strictEqual = function strictEqual(actual, expected, message) {
|
||||
if (actual !== expected) {
|
||||
fail(actual, expected, message, '===', assert.strictEqual);
|
||||
}
|
||||
};
|
||||
|
||||
// 10. The strict non-equality assertion tests for strict inequality, as
|
||||
// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
|
||||
|
||||
assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
||||
if (actual === expected) {
|
||||
fail(actual, expected, message, '!==', assert.notStrictEqual);
|
||||
}
|
||||
};
|
||||
|
||||
function expectedException(actual, expected) {
|
||||
if (!actual || !expected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expected instanceof RegExp) {
|
||||
return expected.test(actual);
|
||||
} else if (actual instanceof expected) {
|
||||
return true;
|
||||
} else if (expected.call({}, actual) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _throws(shouldThrow, block, expected, message) {
|
||||
var actual;
|
||||
|
||||
if (typeof expected === 'string') {
|
||||
message = expected;
|
||||
expected = null;
|
||||
}
|
||||
|
||||
try {
|
||||
block();
|
||||
} catch (e) {
|
||||
actual = e;
|
||||
}
|
||||
|
||||
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
|
||||
(message ? ' ' + message : '.');
|
||||
|
||||
if (shouldThrow && !actual) {
|
||||
fail('Missing expected exception' + message);
|
||||
}
|
||||
|
||||
if (!shouldThrow && expectedException(actual, expected)) {
|
||||
fail('Got unwanted exception' + message);
|
||||
}
|
||||
|
||||
if ((shouldThrow && actual && expected &&
|
||||
!expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
||||
throw actual;
|
||||
}
|
||||
}
|
||||
|
||||
// 11. Expected to throw an error:
|
||||
// assert.throws(block, Error_opt, message_opt);
|
||||
|
||||
assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
||||
_throws.apply(this, [true].concat(pSlice.call(arguments)));
|
||||
};
|
||||
|
||||
// EXTENSION! This is annoying to write outside this module.
|
||||
assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
|
||||
_throws.apply(this, [false].concat(pSlice.call(arguments)));
|
||||
};
|
||||
|
||||
assert.ifError = function(err) { if (err) {throw err;}};
|
@ -1,2 +0,0 @@
|
||||
exports.spawn = function () {};
|
||||
exports.exec = function () {};
|
@ -1,178 +0,0 @@
|
||||
if (!process.EventEmitter) process.EventEmitter = function () {};
|
||||
|
||||
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
||||
var isArray = typeof Array.isArray === 'function'
|
||||
? Array.isArray
|
||||
: function (xs) {
|
||||
return Object.prototype.toString.call(xs) === '[object Array]'
|
||||
}
|
||||
;
|
||||
function indexOf (xs, x) {
|
||||
if (xs.indexOf) return xs.indexOf(x);
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
if (x === xs[i]) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// By default EventEmitters will print a warning if more than
|
||||
// 10 listeners are added to it. This is a useful default which
|
||||
// helps finding memory leaks.
|
||||
//
|
||||
// Obviously not all Emitters should be limited to 10. This function allows
|
||||
// that to be increased. Set to zero for unlimited.
|
||||
var defaultMaxListeners = 10;
|
||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
if (!this._events) this._events = {};
|
||||
this._events.maxListeners = n;
|
||||
};
|
||||
|
||||
|
||||
EventEmitter.prototype.emit = function(type) {
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (type === 'error') {
|
||||
if (!this._events || !this._events.error ||
|
||||
(isArray(this._events.error) && !this._events.error.length))
|
||||
{
|
||||
if (arguments[1] instanceof Error) {
|
||||
throw arguments[1]; // Unhandled 'error' event
|
||||
} else {
|
||||
throw new Error("Uncaught, unspecified 'error' event.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._events) return false;
|
||||
var handler = this._events[type];
|
||||
if (!handler) return false;
|
||||
|
||||
if (typeof handler == 'function') {
|
||||
switch (arguments.length) {
|
||||
// fast cases
|
||||
case 1:
|
||||
handler.call(this);
|
||||
break;
|
||||
case 2:
|
||||
handler.call(this, arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
handler.call(this, arguments[1], arguments[2]);
|
||||
break;
|
||||
// slower
|
||||
default:
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
handler.apply(this, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (isArray(handler)) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
var listeners = handler.slice();
|
||||
for (var i = 0, l = listeners.length; i < l; i++) {
|
||||
listeners[i].apply(this, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// EventEmitter is defined in src/node_events.cc
|
||||
// EventEmitter.prototype.emit() is also defined there.
|
||||
EventEmitter.prototype.addListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('addListener only takes instances of Function');
|
||||
}
|
||||
|
||||
if (!this._events) this._events = {};
|
||||
|
||||
// To avoid recursion in the case that type == "newListeners"! Before
|
||||
// adding it to the listeners, first emit "newListeners".
|
||||
this.emit('newListener', type, listener);
|
||||
|
||||
if (!this._events[type]) {
|
||||
// Optimize the case of one listener. Don't need the extra array object.
|
||||
this._events[type] = listener;
|
||||
} else if (isArray(this._events[type])) {
|
||||
|
||||
// Check for listener leak
|
||||
if (!this._events[type].warned) {
|
||||
var m;
|
||||
if (this._events.maxListeners !== undefined) {
|
||||
m = this._events.maxListeners;
|
||||
} else {
|
||||
m = defaultMaxListeners;
|
||||
}
|
||||
|
||||
if (m && m > 0 && this._events[type].length > m) {
|
||||
this._events[type].warned = true;
|
||||
console.error('(node) warning: possible EventEmitter memory ' +
|
||||
'leak detected. %d listeners added. ' +
|
||||
'Use emitter.setMaxListeners() to increase limit.',
|
||||
this._events[type].length);
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
|
||||
// If we've already got an array, just append.
|
||||
this._events[type].push(listener);
|
||||
} else {
|
||||
// Adding the second element, need to change to array.
|
||||
this._events[type] = [this._events[type], listener];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||
|
||||
EventEmitter.prototype.once = function(type, listener) {
|
||||
var self = this;
|
||||
self.on(type, function g() {
|
||||
self.removeListener(type, g);
|
||||
listener.apply(this, arguments);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('removeListener only takes instances of Function');
|
||||
}
|
||||
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (!this._events || !this._events[type]) return this;
|
||||
|
||||
var list = this._events[type];
|
||||
|
||||
if (isArray(list)) {
|
||||
var i = indexOf(list, listener);
|
||||
if (i < 0) return this;
|
||||
list.splice(i, 1);
|
||||
if (list.length == 0)
|
||||
delete this._events[type];
|
||||
} else if (this._events[type] === listener) {
|
||||
delete this._events[type];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (type && this._events && this._events[type]) this._events[type] = null;
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listeners = function(type) {
|
||||
if (!this._events) this._events = {};
|
||||
if (!this._events[type]) this._events[type] = [];
|
||||
if (!isArray(this._events[type])) {
|
||||
this._events[type] = [this._events[type]];
|
||||
}
|
||||
return this._events[type];
|
||||
};
|
@ -1 +0,0 @@
|
||||
// nothing to see here... no file methods for the browser
|
@ -1 +0,0 @@
|
||||
module.exports = require('http');
|
@ -1 +0,0 @@
|
||||
// todo
|
@ -1,134 +0,0 @@
|
||||
function filter (xs, fn) {
|
||||
var res = [];
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
if (fn(xs[i], i, xs)) res.push(xs[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// resolves . and .. elements in a path array with directory names there
|
||||
// must be no slashes, empty elements, or device names (c:\) in the array
|
||||
// (so also no leading and trailing slashes - it does not distinguish
|
||||
// relative and absolute paths)
|
||||
function normalizeArray(parts, allowAboveRoot) {
|
||||
// if the path tries to go above the root, `up` ends up > 0
|
||||
var up = 0;
|
||||
for (var i = parts.length; i >= 0; i--) {
|
||||
var last = parts[i];
|
||||
if (last == '.') {
|
||||
parts.splice(i, 1);
|
||||
} else if (last === '..') {
|
||||
parts.splice(i, 1);
|
||||
up++;
|
||||
} else if (up) {
|
||||
parts.splice(i, 1);
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
// if the path is allowed to go above the root, restore leading ..s
|
||||
if (allowAboveRoot) {
|
||||
for (; up--; up) {
|
||||
parts.unshift('..');
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
// Regex to split a filename into [*, dir, basename, ext]
|
||||
// posix version
|
||||
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
|
||||
|
||||
// path.resolve([from ...], to)
|
||||
// posix version
|
||||
exports.resolve = function() {
|
||||
var resolvedPath = '',
|
||||
resolvedAbsolute = false;
|
||||
|
||||
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
|
||||
var path = (i >= 0)
|
||||
? arguments[i]
|
||||
: process.cwd();
|
||||
|
||||
// Skip empty and invalid entries
|
||||
if (typeof path !== 'string' || !path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
resolvedPath = path + '/' + resolvedPath;
|
||||
resolvedAbsolute = path.charAt(0) === '/';
|
||||
}
|
||||
|
||||
// At this point the path should be resolved to a full absolute path, but
|
||||
// handle relative paths to be safe (might happen when process.cwd() fails)
|
||||
|
||||
// Normalize the path
|
||||
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
||||
return !!p;
|
||||
}), !resolvedAbsolute).join('/');
|
||||
|
||||
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
||||
};
|
||||
|
||||
// path.normalize(path)
|
||||
// posix version
|
||||
exports.normalize = function(path) {
|
||||
var isAbsolute = path.charAt(0) === '/',
|
||||
trailingSlash = path.slice(-1) === '/';
|
||||
|
||||
// Normalize the path
|
||||
path = normalizeArray(filter(path.split('/'), function(p) {
|
||||
return !!p;
|
||||
}), !isAbsolute).join('/');
|
||||
|
||||
if (!path && !isAbsolute) {
|
||||
path = '.';
|
||||
}
|
||||
if (path && trailingSlash) {
|
||||
path += '/';
|
||||
}
|
||||
|
||||
return (isAbsolute ? '/' : '') + path;
|
||||
};
|
||||
|
||||
|
||||
// posix version
|
||||
exports.join = function() {
|
||||
var paths = Array.prototype.slice.call(arguments, 0);
|
||||
return exports.normalize(filter(paths, function(p, index) {
|
||||
return p && typeof p === 'string';
|
||||
}).join('/'));
|
||||
};
|
||||
|
||||
|
||||
exports.dirname = function(path) {
|
||||
var dir = splitPathRe.exec(path)[1] || '';
|
||||
var isWindows = false;
|
||||
if (!dir) {
|
||||
// No dirname
|
||||
return '.';
|
||||
} else if (dir.length === 1 ||
|
||||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
|
||||
// It is just a slash or a drive letter with a slash
|
||||
return dir;
|
||||
} else {
|
||||
// It is a full dirname, strip trailing slash
|
||||
return dir.substring(0, dir.length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.basename = function(path, ext) {
|
||||
var f = splitPathRe.exec(path)[2] || '';
|
||||
// TODO: make this comparison case-insensitive on windows?
|
||||
if (ext && f.substr(-1 * ext.length) === ext) {
|
||||
f = f.substr(0, f.length - ext.length);
|
||||
}
|
||||
return f;
|
||||
};
|
||||
|
||||
|
||||
exports.extname = function(path) {
|
||||
return splitPathRe.exec(path)[3] || '';
|
||||
};
|
@ -1,250 +0,0 @@
|
||||
var isArray = typeof Array.isArray === 'function'
|
||||
? Array.isArray
|
||||
: function (xs) {
|
||||
return Object.prototype.toString.call(xs) === '[object Array]'
|
||||
};
|
||||
|
||||
var objectKeys = Object.keys || function objectKeys(object) {
|
||||
if (object !== Object(object)) throw new TypeError('Invalid object');
|
||||
var keys = [];
|
||||
for (var key in object) if (object.hasOwnProperty(key)) keys[keys.length] = key;
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* querystring
|
||||
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Library version.
|
||||
*/
|
||||
|
||||
exports.version = '0.3.1';
|
||||
|
||||
/**
|
||||
* Object#toString() ref for stringify().
|
||||
*/
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Cache non-integer test regexp.
|
||||
*/
|
||||
|
||||
var notint = /[^0-9]/;
|
||||
|
||||
/**
|
||||
* Parse the given query `str`, returning an object.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.parse = function(str){
|
||||
if (null == str || '' == str) return {};
|
||||
|
||||
function promote(parent, key) {
|
||||
if (parent[key].length == 0) return parent[key] = {};
|
||||
var t = {};
|
||||
for (var i in parent[key]) t[i] = parent[key][i];
|
||||
parent[key] = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
return String(str)
|
||||
.split('&')
|
||||
.reduce(function(ret, pair){
|
||||
try{
|
||||
pair = decodeURIComponent(pair.replace(/\+/g, ' '));
|
||||
} catch(e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
var eql = pair.indexOf('=')
|
||||
, brace = lastBraceInKey(pair)
|
||||
, key = pair.substr(0, brace || eql)
|
||||
, val = pair.substr(brace || eql, pair.length)
|
||||
, val = val.substr(val.indexOf('=') + 1, val.length)
|
||||
, parent = ret;
|
||||
|
||||
// ?foo
|
||||
if ('' == key) key = pair, val = '';
|
||||
|
||||
// nested
|
||||
if (~key.indexOf(']')) {
|
||||
var parts = key.split('[')
|
||||
, len = parts.length
|
||||
, last = len - 1;
|
||||
|
||||
function parse(parts, parent, key) {
|
||||
var part = parts.shift();
|
||||
|
||||
// end
|
||||
if (!part) {
|
||||
if (isArray(parent[key])) {
|
||||
parent[key].push(val);
|
||||
} else if ('object' == typeof parent[key]) {
|
||||
parent[key] = val;
|
||||
} else if ('undefined' == typeof parent[key]) {
|
||||
parent[key] = val;
|
||||
} else {
|
||||
parent[key] = [parent[key], val];
|
||||
}
|
||||
// array
|
||||
} else {
|
||||
obj = parent[key] = parent[key] || [];
|
||||
if (']' == part) {
|
||||
if (isArray(obj)) {
|
||||
if ('' != val) obj.push(val);
|
||||
} else if ('object' == typeof obj) {
|
||||
obj[objectKeys(obj).length] = val;
|
||||
} else {
|
||||
obj = parent[key] = [parent[key], val];
|
||||
}
|
||||
// prop
|
||||
} else if (~part.indexOf(']')) {
|
||||
part = part.substr(0, part.length - 1);
|
||||
if(notint.test(part) && isArray(obj)) obj = promote(parent, key);
|
||||
parse(parts, obj, part);
|
||||
// key
|
||||
} else {
|
||||
if(notint.test(part) && isArray(obj)) obj = promote(parent, key);
|
||||
parse(parts, obj, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parse(parts, parent, 'base');
|
||||
// optimize
|
||||
} else {
|
||||
if (notint.test(key) && isArray(parent.base)) {
|
||||
var t = {};
|
||||
for(var k in parent.base) t[k] = parent.base[k];
|
||||
parent.base = t;
|
||||
}
|
||||
set(parent.base, key, val);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}, {base: {}}).base;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn the given `obj` into a query string
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var stringify = exports.stringify = function(obj, prefix) {
|
||||
if (isArray(obj)) {
|
||||
return stringifyArray(obj, prefix);
|
||||
} else if ('[object Object]' == toString.call(obj)) {
|
||||
return stringifyObject(obj, prefix);
|
||||
} else if ('string' == typeof obj) {
|
||||
return stringifyString(obj, prefix);
|
||||
} else {
|
||||
return prefix;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stringify the given `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyString(str, prefix) {
|
||||
if (!prefix) throw new TypeError('stringify expects an object');
|
||||
return prefix + '=' + encodeURIComponent(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the given `arr`.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyArray(arr, prefix) {
|
||||
var ret = [];
|
||||
if (!prefix) throw new TypeError('stringify expects an object');
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
ret.push(stringify(arr[i], prefix + '[]'));
|
||||
}
|
||||
return ret.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the given `obj`.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyObject(obj, prefix) {
|
||||
var ret = []
|
||||
, keys = objectKeys(obj)
|
||||
, key;
|
||||
for (var i = 0, len = keys.length; i < len; ++i) {
|
||||
key = keys[i];
|
||||
ret.push(stringify(obj[key], prefix
|
||||
? prefix + '[' + encodeURIComponent(key) + ']'
|
||||
: encodeURIComponent(key)));
|
||||
}
|
||||
return ret.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set `obj`'s `key` to `val` respecting
|
||||
* the weird and wonderful syntax of a qs,
|
||||
* where "foo=bar&foo=baz" becomes an array.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {String} key
|
||||
* @param {String} val
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function set(obj, key, val) {
|
||||
var v = obj[key];
|
||||
if (undefined === v) {
|
||||
obj[key] = val;
|
||||
} else if (isArray(v)) {
|
||||
v.push(val);
|
||||
} else {
|
||||
obj[key] = [v, val];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate last brace in `str` within the key.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function lastBraceInKey(str) {
|
||||
var len = str.length
|
||||
, brace
|
||||
, c;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
c = str[i];
|
||||
if (']' == c) brace = false;
|
||||
if ('[' == c) brace = true;
|
||||
if ('=' == c && !brace) return i;
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
var events = require('events');
|
||||
var util = require('util');
|
||||
|
||||
function Stream() {
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
util.inherits(Stream, events.EventEmitter);
|
||||
module.exports = Stream;
|
||||
// Backwards-compat with node 0.4.x
|
||||
Stream.Stream = Stream;
|
||||
|
||||
Stream.prototype.pipe = function(dest, options) {
|
||||
var source = this;
|
||||
|
||||
function ondata(chunk) {
|
||||
if (dest.writable) {
|
||||
if (false === dest.write(chunk) && source.pause) {
|
||||
source.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
source.on('data', ondata);
|
||||
|
||||
function ondrain() {
|
||||
if (source.readable && source.resume) {
|
||||
source.resume();
|
||||
}
|
||||
}
|
||||
|
||||
dest.on('drain', ondrain);
|
||||
|
||||
// If the 'end' option is not supplied, dest.end() will be called when
|
||||
// source gets the 'end' or 'close' events. Only dest.end() once, and
|
||||
// only when all sources have ended.
|
||||
if (!dest._isStdio && (!options || options.end !== false)) {
|
||||
dest._pipeCount = dest._pipeCount || 0;
|
||||
dest._pipeCount++;
|
||||
|
||||
source.on('end', onend);
|
||||
source.on('close', onclose);
|
||||
}
|
||||
|
||||
var didOnEnd = false;
|
||||
function onend() {
|
||||
if (didOnEnd) return;
|
||||
didOnEnd = true;
|
||||
|
||||
dest._pipeCount--;
|
||||
|
||||
// remove the listeners
|
||||
cleanup();
|
||||
|
||||
if (dest._pipeCount > 0) {
|
||||
// waiting for other incoming streams to end.
|
||||
return;
|
||||
}
|
||||
|
||||
dest.end();
|
||||
}
|
||||
|
||||
|
||||
function onclose() {
|
||||
if (didOnEnd) return;
|
||||
didOnEnd = true;
|
||||
|
||||
dest._pipeCount--;
|
||||
|
||||
// remove the listeners
|
||||
cleanup();
|
||||
|
||||
if (dest._pipeCount > 0) {
|
||||
// waiting for other incoming streams to end.
|
||||
return;
|
||||
}
|
||||
|
||||
dest.destroy();
|
||||
}
|
||||
|
||||
// don't leave dangling pipes when there are errors.
|
||||
function onerror(er) {
|
||||
cleanup();
|
||||
if (this.listeners('error').length === 0) {
|
||||
throw er; // Unhandled stream error in pipe.
|
||||
}
|
||||
}
|
||||
|
||||
source.on('error', onerror);
|
||||
dest.on('error', onerror);
|
||||
|
||||
// remove all the event listeners that were added.
|
||||
function cleanup() {
|
||||
source.removeListener('data', ondata);
|
||||
dest.removeListener('drain', ondrain);
|
||||
|
||||
source.removeListener('end', onend);
|
||||
source.removeListener('close', onclose);
|
||||
|
||||
source.removeListener('error', onerror);
|
||||
dest.removeListener('error', onerror);
|
||||
|
||||
source.removeListener('end', cleanup);
|
||||
source.removeListener('close', cleanup);
|
||||
|
||||
dest.removeListener('end', cleanup);
|
||||
dest.removeListener('close', cleanup);
|
||||
}
|
||||
|
||||
source.on('end', cleanup);
|
||||
source.on('close', cleanup);
|
||||
|
||||
dest.on('end', cleanup);
|
||||
dest.on('close', cleanup);
|
||||
|
||||
dest.emit('pipe', source);
|
||||
|
||||
// Allow for unix-like usage: A.pipe(B).pipe(C)
|
||||
return dest;
|
||||
};
|
@ -1,161 +0,0 @@
|
||||
var StringDecoder = exports.StringDecoder = function(encoding) {
|
||||
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
||||
switch (this.encoding) {
|
||||
case 'utf8':
|
||||
// CESU-8 represents each of Surrogate Pair by 3-bytes
|
||||
this.surrogateSize = 3;
|
||||
break;
|
||||
case 'ucs2':
|
||||
case 'utf16le':
|
||||
// UTF-16 represents each of Surrogate Pair by 2-bytes
|
||||
this.surrogateSize = 2;
|
||||
this.detectIncompleteChar = utf16DetectIncompleteChar;
|
||||
break;
|
||||
case 'base64':
|
||||
// Base-64 stores 3 bytes in 4 chars, and pads the remainder.
|
||||
this.surrogateSize = 3;
|
||||
this.detectIncompleteChar = base64DetectIncompleteChar;
|
||||
break;
|
||||
default:
|
||||
this.write = passThroughWrite;
|
||||
return;
|
||||
}
|
||||
|
||||
this.charBuffer = new Buffer(6);
|
||||
this.charReceived = 0;
|
||||
this.charLength = 0;
|
||||
};
|
||||
|
||||
|
||||
StringDecoder.prototype.write = function(buffer) {
|
||||
var charStr = '';
|
||||
var offset = 0;
|
||||
|
||||
// if our last write ended with an incomplete multibyte character
|
||||
while (this.charLength) {
|
||||
// determine how many remaining bytes this buffer has to offer for this char
|
||||
var i = (buffer.length >= this.charLength - this.charReceived) ?
|
||||
this.charLength - this.charReceived :
|
||||
buffer.length;
|
||||
|
||||
// add the new bytes to the char buffer
|
||||
buffer.copy(this.charBuffer, this.charReceived, offset, i);
|
||||
this.charReceived += (i - offset);
|
||||
offset = i;
|
||||
|
||||
if (this.charReceived < this.charLength) {
|
||||
// still not enough chars in this buffer? wait for more ...
|
||||
return '';
|
||||
}
|
||||
|
||||
// get the character that was split
|
||||
charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
||||
|
||||
// lead surrogate (D800-DBFF) is also the incomplete character
|
||||
var charCode = charStr.charCodeAt(charStr.length - 1);
|
||||
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
||||
this.charLength += this.surrogateSize;
|
||||
charStr = '';
|
||||
continue;
|
||||
}
|
||||
this.charReceived = this.charLength = 0;
|
||||
|
||||
// if there are no more bytes in this buffer, just emit our char
|
||||
if (i == buffer.length) return charStr;
|
||||
|
||||
// otherwise cut off the characters end from the beginning of this buffer
|
||||
buffer = buffer.slice(i, buffer.length);
|
||||
break;
|
||||
}
|
||||
|
||||
var lenIncomplete = this.detectIncompleteChar(buffer);
|
||||
|
||||
var end = buffer.length;
|
||||
if (this.charLength) {
|
||||
// buffer the incomplete character bytes we got
|
||||
buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
|
||||
this.charReceived = lenIncomplete;
|
||||
end -= lenIncomplete;
|
||||
}
|
||||
|
||||
charStr += buffer.toString(this.encoding, 0, end);
|
||||
|
||||
var end = charStr.length - 1;
|
||||
var charCode = charStr.charCodeAt(end);
|
||||
// lead surrogate (D800-DBFF) is also the incomplete character
|
||||
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
||||
var size = this.surrogateSize;
|
||||
this.charLength += size;
|
||||
this.charReceived += size;
|
||||
this.charBuffer.copy(this.charBuffer, size, 0, size);
|
||||
this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
|
||||
return charStr.substring(0, end);
|
||||
}
|
||||
|
||||
// or just emit the charStr
|
||||
return charStr;
|
||||
};
|
||||
|
||||
StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
||||
// determine how many bytes we have to check at the end of this buffer
|
||||
var i = (buffer.length >= 3) ? 3 : buffer.length;
|
||||
|
||||
// Figure out if one of the last i bytes of our buffer announces an
|
||||
// incomplete char.
|
||||
for (; i > 0; i--) {
|
||||
var c = buffer[buffer.length - i];
|
||||
|
||||
// See http://en.wikipedia.org/wiki/UTF-8#Description
|
||||
|
||||
// 110XXXXX
|
||||
if (i == 1 && c >> 5 == 0x06) {
|
||||
this.charLength = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// 1110XXXX
|
||||
if (i <= 2 && c >> 4 == 0x0E) {
|
||||
this.charLength = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
// 11110XXX
|
||||
if (i <= 3 && c >> 3 == 0x1E) {
|
||||
this.charLength = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
};
|
||||
|
||||
StringDecoder.prototype.end = function(buffer) {
|
||||
var res = '';
|
||||
if (buffer && buffer.length)
|
||||
res = this.write(buffer);
|
||||
|
||||
if (this.charReceived) {
|
||||
var cr = this.charReceived;
|
||||
var buf = this.charBuffer;
|
||||
var enc = this.encoding;
|
||||
res += buf.slice(0, cr).toString(enc);
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
function passThroughWrite(buffer) {
|
||||
return buffer.toString(this.encoding);
|
||||
}
|
||||
|
||||
function utf16DetectIncompleteChar(buffer) {
|
||||
var incomplete = this.charReceived = buffer.length % 2;
|
||||
this.charLength = incomplete ? 2 : 0;
|
||||
return incomplete;
|
||||
}
|
||||
|
||||
function base64DetectIncompleteChar(buffer) {
|
||||
var incomplete = this.charReceived = buffer.length % 3;
|
||||
this.charLength = incomplete ? 3 : 0;
|
||||
return incomplete;
|
||||
}
|
@ -1 +0,0 @@
|
||||
module.exports = require('util');
|
@ -1 +0,0 @@
|
||||
// todo
|
@ -1,2 +0,0 @@
|
||||
exports.isatty = function () {};
|
||||
exports.setRawMode = function () {};
|
@ -1,604 +0,0 @@
|
||||
var punycode = { encode : function (s) { return s } };
|
||||
|
||||
exports.parse = urlParse;
|
||||
exports.resolve = urlResolve;
|
||||
exports.resolveObject = urlResolveObject;
|
||||
exports.format = urlFormat;
|
||||
|
||||
function arrayIndexOf(array, subject) {
|
||||
for (var i = 0, j = array.length; i < j; i++) {
|
||||
if(array[i] == subject) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
var objectKeys = Object.keys || function objectKeys(object) {
|
||||
if (object !== Object(object)) throw new TypeError('Invalid object');
|
||||
var keys = [];
|
||||
for (var key in object) if (object.hasOwnProperty(key)) keys[keys.length] = key;
|
||||
return keys;
|
||||
}
|
||||
|
||||
// Reference: RFC 3986, RFC 1808, RFC 2396
|
||||
|
||||
// define these here so at least they only have to be
|
||||
// compiled once on the first module load.
|
||||
var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
||||
portPattern = /:[0-9]+$/,
|
||||
// RFC 2396: characters reserved for delimiting URLs.
|
||||
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
|
||||
// RFC 2396: characters not allowed for various reasons.
|
||||
unwise = ['{', '}', '|', '\\', '^', '~', '[', ']', '`'].concat(delims),
|
||||
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
|
||||
autoEscape = ['\''],
|
||||
// Characters that are never ever allowed in a hostname.
|
||||
// Note that any invalid chars are also handled, but these
|
||||
// are the ones that are *expected* to be seen, so we fast-path
|
||||
// them.
|
||||
nonHostChars = ['%', '/', '?', ';', '#']
|
||||
.concat(unwise).concat(autoEscape),
|
||||
nonAuthChars = ['/', '@', '?', '#'].concat(delims),
|
||||
hostnameMaxLen = 255,
|
||||
hostnamePartPattern = /^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,
|
||||
hostnamePartStart = /^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,
|
||||
// protocols that can allow "unsafe" and "unwise" chars.
|
||||
unsafeProtocol = {
|
||||
'javascript': true,
|
||||
'javascript:': true
|
||||
},
|
||||
// protocols that never have a hostname.
|
||||
hostlessProtocol = {
|
||||
'javascript': true,
|
||||
'javascript:': true
|
||||
},
|
||||
// protocols that always have a path component.
|
||||
pathedProtocol = {
|
||||
'http': true,
|
||||
'https': true,
|
||||
'ftp': true,
|
||||
'gopher': true,
|
||||
'file': true,
|
||||
'http:': true,
|
||||
'ftp:': true,
|
||||
'gopher:': true,
|
||||
'file:': true
|
||||
},
|
||||
// protocols that always contain a // bit.
|
||||
slashedProtocol = {
|
||||
'http': true,
|
||||
'https': true,
|
||||
'ftp': true,
|
||||
'gopher': true,
|
||||
'file': true,
|
||||
'http:': true,
|
||||
'https:': true,
|
||||
'ftp:': true,
|
||||
'gopher:': true,
|
||||
'file:': true
|
||||
},
|
||||
querystring = require('querystring');
|
||||
|
||||
function urlParse(url, parseQueryString, slashesDenoteHost) {
|
||||
if (url && typeof(url) === 'object' && url.href) return url;
|
||||
|
||||
if (typeof url !== 'string') {
|
||||
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
|
||||
}
|
||||
|
||||
var out = {},
|
||||
rest = url;
|
||||
|
||||
// cut off any delimiters.
|
||||
// This is to support parse stuff like "<http://foo.com>"
|
||||
for (var i = 0, l = rest.length; i < l; i++) {
|
||||
if (arrayIndexOf(delims, rest.charAt(i)) === -1) break;
|
||||
}
|
||||
if (i !== 0) rest = rest.substr(i);
|
||||
|
||||
|
||||
var proto = protocolPattern.exec(rest);
|
||||
if (proto) {
|
||||
proto = proto[0];
|
||||
var lowerProto = proto.toLowerCase();
|
||||
out.protocol = lowerProto;
|
||||
rest = rest.substr(proto.length);
|
||||
}
|
||||
|
||||
// figure out if it's got a host
|
||||
// user@server is *always* interpreted as a hostname, and url
|
||||
// resolution will treat //foo/bar as host=foo,path=bar because that's
|
||||
// how the browser resolves relative URLs.
|
||||
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
|
||||
var slashes = rest.substr(0, 2) === '//';
|
||||
if (slashes && !(proto && hostlessProtocol[proto])) {
|
||||
rest = rest.substr(2);
|
||||
out.slashes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hostlessProtocol[proto] &&
|
||||
(slashes || (proto && !slashedProtocol[proto]))) {
|
||||
// there's a hostname.
|
||||
// the first instance of /, ?, ;, or # ends the host.
|
||||
// don't enforce full RFC correctness, just be unstupid about it.
|
||||
|
||||
// If there is an @ in the hostname, then non-host chars *are* allowed
|
||||
// to the left of the first @ sign, unless some non-auth character
|
||||
// comes *before* the @-sign.
|
||||
// URLs are obnoxious.
|
||||
var atSign = arrayIndexOf(rest, '@');
|
||||
if (atSign !== -1) {
|
||||
// there *may be* an auth
|
||||
var hasAuth = true;
|
||||
for (var i = 0, l = nonAuthChars.length; i < l; i++) {
|
||||
var index = arrayIndexOf(rest, nonAuthChars[i]);
|
||||
if (index !== -1 && index < atSign) {
|
||||
// not a valid auth. Something like http://foo.com/bar@baz/
|
||||
hasAuth = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasAuth) {
|
||||
// pluck off the auth portion.
|
||||
out.auth = rest.substr(0, atSign);
|
||||
rest = rest.substr(atSign + 1);
|
||||
}
|
||||
}
|
||||
|
||||
var firstNonHost = -1;
|
||||
for (var i = 0, l = nonHostChars.length; i < l; i++) {
|
||||
var index = arrayIndexOf(rest, nonHostChars[i]);
|
||||
if (index !== -1 &&
|
||||
(firstNonHost < 0 || index < firstNonHost)) firstNonHost = index;
|
||||
}
|
||||
|
||||
if (firstNonHost !== -1) {
|
||||
out.host = rest.substr(0, firstNonHost);
|
||||
rest = rest.substr(firstNonHost);
|
||||
} else {
|
||||
out.host = rest;
|
||||
rest = '';
|
||||
}
|
||||
|
||||
// pull out port.
|
||||
var p = parseHost(out.host);
|
||||
var keys = objectKeys(p);
|
||||
for (var i = 0, l = keys.length; i < l; i++) {
|
||||
var key = keys[i];
|
||||
out[key] = p[key];
|
||||
}
|
||||
|
||||
// we've indicated that there is a hostname,
|
||||
// so even if it's empty, it has to be present.
|
||||
out.hostname = out.hostname || '';
|
||||
|
||||
// validate a little.
|
||||
if (out.hostname.length > hostnameMaxLen) {
|
||||
out.hostname = '';
|
||||
} else {
|
||||
var hostparts = out.hostname.split(/\./);
|
||||
for (var i = 0, l = hostparts.length; i < l; i++) {
|
||||
var part = hostparts[i];
|
||||
if (!part) continue;
|
||||
if (!part.match(hostnamePartPattern)) {
|
||||
var newpart = '';
|
||||
for (var j = 0, k = part.length; j < k; j++) {
|
||||
if (part.charCodeAt(j) > 127) {
|
||||
// we replace non-ASCII char with a temporary placeholder
|
||||
// we need this to make sure size of hostname is not
|
||||
// broken by replacing non-ASCII by nothing
|
||||
newpart += 'x';
|
||||
} else {
|
||||
newpart += part[j];
|
||||
}
|
||||
}
|
||||
// we test again with ASCII char only
|
||||
if (!newpart.match(hostnamePartPattern)) {
|
||||
var validParts = hostparts.slice(0, i);
|
||||
var notHost = hostparts.slice(i + 1);
|
||||
var bit = part.match(hostnamePartStart);
|
||||
if (bit) {
|
||||
validParts.push(bit[1]);
|
||||
notHost.unshift(bit[2]);
|
||||
}
|
||||
if (notHost.length) {
|
||||
rest = '/' + notHost.join('.') + rest;
|
||||
}
|
||||
out.hostname = validParts.join('.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hostnames are always lower case.
|
||||
out.hostname = out.hostname.toLowerCase();
|
||||
|
||||
// IDNA Support: Returns a puny coded representation of "domain".
|
||||
// It only converts the part of the domain name that
|
||||
// has non ASCII characters. I.e. it dosent matter if
|
||||
// you call it with a domain that already is in ASCII.
|
||||
var domainArray = out.hostname.split('.');
|
||||
var newOut = [];
|
||||
for (var i = 0; i < domainArray.length; ++i) {
|
||||
var s = domainArray[i];
|
||||
newOut.push(s.match(/[^A-Za-z0-9_-]/) ?
|
||||
'xn--' + punycode.encode(s) : s);
|
||||
}
|
||||
out.hostname = newOut.join('.');
|
||||
|
||||
out.host = (out.hostname || '') +
|
||||
((out.port) ? ':' + out.port : '');
|
||||
out.href += out.host;
|
||||
}
|
||||
|
||||
// now rest is set to the post-host stuff.
|
||||
// chop off any delim chars.
|
||||
if (!unsafeProtocol[lowerProto]) {
|
||||
|
||||
// First, make 100% sure that any "autoEscape" chars get
|
||||
// escaped, even if encodeURIComponent doesn't think they
|
||||
// need to be.
|
||||
for (var i = 0, l = autoEscape.length; i < l; i++) {
|
||||
var ae = autoEscape[i];
|
||||
var esc = encodeURIComponent(ae);
|
||||
if (esc === ae) {
|
||||
esc = escape(ae);
|
||||
}
|
||||
rest = rest.split(ae).join(esc);
|
||||
}
|
||||
|
||||
// Now make sure that delims never appear in a url.
|
||||
var chop = rest.length;
|
||||
for (var i = 0, l = delims.length; i < l; i++) {
|
||||
var c = arrayIndexOf(rest, delims[i]);
|
||||
if (c !== -1) {
|
||||
chop = Math.min(c, chop);
|
||||
}
|
||||
}
|
||||
rest = rest.substr(0, chop);
|
||||
}
|
||||
|
||||
|
||||
// chop off from the tail first.
|
||||
var hash = arrayIndexOf(rest, '#');
|
||||
if (hash !== -1) {
|
||||
// got a fragment string.
|
||||
out.hash = rest.substr(hash);
|
||||
rest = rest.slice(0, hash);
|
||||
}
|
||||
var qm = arrayIndexOf(rest, '?');
|
||||
if (qm !== -1) {
|
||||
out.search = rest.substr(qm);
|
||||
out.query = rest.substr(qm + 1);
|
||||
if (parseQueryString) {
|
||||
out.query = querystring.parse(out.query);
|
||||
}
|
||||
rest = rest.slice(0, qm);
|
||||
} else if (parseQueryString) {
|
||||
// no query string, but parseQueryString still requested
|
||||
out.search = '';
|
||||
out.query = {};
|
||||
}
|
||||
if (rest) out.pathname = rest;
|
||||
if (slashedProtocol[proto] &&
|
||||
out.hostname && !out.pathname) {
|
||||
out.pathname = '/';
|
||||
}
|
||||
|
||||
//to support http.request
|
||||
if (out.pathname || out.search) {
|
||||
out.path = (out.pathname ? out.pathname : '') +
|
||||
(out.search ? out.search : '');
|
||||
}
|
||||
|
||||
// finally, reconstruct the href based on what has been validated.
|
||||
out.href = urlFormat(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
// format a parsed object into a url string
|
||||
function urlFormat(obj) {
|
||||
// ensure it's an object, and not a string url.
|
||||
// If it's an obj, this is a no-op.
|
||||
// this way, you can call url_format() on strings
|
||||
// to clean up potentially wonky urls.
|
||||
if (typeof(obj) === 'string') obj = urlParse(obj);
|
||||
|
||||
var auth = obj.auth || '';
|
||||
if (auth) {
|
||||
auth = auth.split('@').join('%40');
|
||||
for (var i = 0, l = nonAuthChars.length; i < l; i++) {
|
||||
var nAC = nonAuthChars[i];
|
||||
auth = auth.split(nAC).join(encodeURIComponent(nAC));
|
||||
}
|
||||
auth += '@';
|
||||
}
|
||||
|
||||
var protocol = obj.protocol || '',
|
||||
host = (obj.host !== undefined) ? auth + obj.host :
|
||||
obj.hostname !== undefined ? (
|
||||
auth + obj.hostname +
|
||||
(obj.port ? ':' + obj.port : '')
|
||||
) :
|
||||
false,
|
||||
pathname = obj.pathname || '',
|
||||
query = obj.query &&
|
||||
((typeof obj.query === 'object' &&
|
||||
objectKeys(obj.query).length) ?
|
||||
querystring.stringify(obj.query) :
|
||||
'') || '',
|
||||
search = obj.search || (query && ('?' + query)) || '',
|
||||
hash = obj.hash || '';
|
||||
|
||||
if (protocol && protocol.substr(-1) !== ':') protocol += ':';
|
||||
|
||||
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
|
||||
// unless they had them to begin with.
|
||||
if (obj.slashes ||
|
||||
(!protocol || slashedProtocol[protocol]) && host !== false) {
|
||||
host = '//' + (host || '');
|
||||
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
|
||||
} else if (!host) {
|
||||
host = '';
|
||||
}
|
||||
|
||||
if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
|
||||
if (search && search.charAt(0) !== '?') search = '?' + search;
|
||||
|
||||
return protocol + host + pathname + search + hash;
|
||||
}
|
||||
|
||||
function urlResolve(source, relative) {
|
||||
return urlFormat(urlResolveObject(source, relative));
|
||||
}
|
||||
|
||||
function urlResolveObject(source, relative) {
|
||||
if (!source) return relative;
|
||||
|
||||
source = urlParse(urlFormat(source), false, true);
|
||||
relative = urlParse(urlFormat(relative), false, true);
|
||||
|
||||
// hash is always overridden, no matter what.
|
||||
source.hash = relative.hash;
|
||||
|
||||
if (relative.href === '') {
|
||||
source.href = urlFormat(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
// hrefs like //foo/bar always cut to the protocol.
|
||||
if (relative.slashes && !relative.protocol) {
|
||||
relative.protocol = source.protocol;
|
||||
//urlParse appends trailing / to urls like http://www.example.com
|
||||
if (slashedProtocol[relative.protocol] &&
|
||||
relative.hostname && !relative.pathname) {
|
||||
relative.path = relative.pathname = '/';
|
||||
}
|
||||
relative.href = urlFormat(relative);
|
||||
return relative;
|
||||
}
|
||||
|
||||
if (relative.protocol && relative.protocol !== source.protocol) {
|
||||
// if it's a known url protocol, then changing
|
||||
// the protocol does weird things
|
||||
// first, if it's not file:, then we MUST have a host,
|
||||
// and if there was a path
|
||||
// to begin with, then we MUST have a path.
|
||||
// if it is file:, then the host is dropped,
|
||||
// because that's known to be hostless.
|
||||
// anything else is assumed to be absolute.
|
||||
if (!slashedProtocol[relative.protocol]) {
|
||||
relative.href = urlFormat(relative);
|
||||
return relative;
|
||||
}
|
||||
source.protocol = relative.protocol;
|
||||
if (!relative.host && !hostlessProtocol[relative.protocol]) {
|
||||
var relPath = (relative.pathname || '').split('/');
|
||||
while (relPath.length && !(relative.host = relPath.shift()));
|
||||
if (!relative.host) relative.host = '';
|
||||
if (!relative.hostname) relative.hostname = '';
|
||||
if (relPath[0] !== '') relPath.unshift('');
|
||||
if (relPath.length < 2) relPath.unshift('');
|
||||
relative.pathname = relPath.join('/');
|
||||
}
|
||||
source.pathname = relative.pathname;
|
||||
source.search = relative.search;
|
||||
source.query = relative.query;
|
||||
source.host = relative.host || '';
|
||||
source.auth = relative.auth;
|
||||
source.hostname = relative.hostname || relative.host;
|
||||
source.port = relative.port;
|
||||
//to support http.request
|
||||
if (source.pathname !== undefined || source.search !== undefined) {
|
||||
source.path = (source.pathname ? source.pathname : '') +
|
||||
(source.search ? source.search : '');
|
||||
}
|
||||
source.slashes = source.slashes || relative.slashes;
|
||||
source.href = urlFormat(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
var isSourceAbs = (source.pathname && source.pathname.charAt(0) === '/'),
|
||||
isRelAbs = (
|
||||
relative.host !== undefined ||
|
||||
relative.pathname && relative.pathname.charAt(0) === '/'
|
||||
),
|
||||
mustEndAbs = (isRelAbs || isSourceAbs ||
|
||||
(source.host && relative.pathname)),
|
||||
removeAllDots = mustEndAbs,
|
||||
srcPath = source.pathname && source.pathname.split('/') || [],
|
||||
relPath = relative.pathname && relative.pathname.split('/') || [],
|
||||
psychotic = source.protocol &&
|
||||
!slashedProtocol[source.protocol];
|
||||
|
||||
// if the url is a non-slashed url, then relative
|
||||
// links like ../.. should be able
|
||||
// to crawl up to the hostname, as well. This is strange.
|
||||
// source.protocol has already been set by now.
|
||||
// Later on, put the first path part into the host field.
|
||||
if (psychotic) {
|
||||
|
||||
delete source.hostname;
|
||||
delete source.port;
|
||||
if (source.host) {
|
||||
if (srcPath[0] === '') srcPath[0] = source.host;
|
||||
else srcPath.unshift(source.host);
|
||||
}
|
||||
delete source.host;
|
||||
if (relative.protocol) {
|
||||
delete relative.hostname;
|
||||
delete relative.port;
|
||||
if (relative.host) {
|
||||
if (relPath[0] === '') relPath[0] = relative.host;
|
||||
else relPath.unshift(relative.host);
|
||||
}
|
||||
delete relative.host;
|
||||
}
|
||||
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
|
||||
}
|
||||
|
||||
if (isRelAbs) {
|
||||
// it's absolute.
|
||||
source.host = (relative.host || relative.host === '') ?
|
||||
relative.host : source.host;
|
||||
source.hostname = (relative.hostname || relative.hostname === '') ?
|
||||
relative.hostname : source.hostname;
|
||||
source.search = relative.search;
|
||||
source.query = relative.query;
|
||||
srcPath = relPath;
|
||||
// fall through to the dot-handling below.
|
||||
} else if (relPath.length) {
|
||||
// it's relative
|
||||
// throw away the existing file, and take the new path instead.
|
||||
if (!srcPath) srcPath = [];
|
||||
srcPath.pop();
|
||||
srcPath = srcPath.concat(relPath);
|
||||
source.search = relative.search;
|
||||
source.query = relative.query;
|
||||
} else if ('search' in relative) {
|
||||
// just pull out the search.
|
||||
// like href='?foo'.
|
||||
// Put this after the other two cases because it simplifies the booleans
|
||||
if (psychotic) {
|
||||
source.hostname = source.host = srcPath.shift();
|
||||
//occationaly the auth can get stuck only in host
|
||||
//this especialy happens in cases like
|
||||
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
||||
var authInHost = source.host && arrayIndexOf(source.host, '@') > 0 ?
|
||||
source.host.split('@') : false;
|
||||
if (authInHost) {
|
||||
source.auth = authInHost.shift();
|
||||
source.host = source.hostname = authInHost.shift();
|
||||
}
|
||||
}
|
||||
source.search = relative.search;
|
||||
source.query = relative.query;
|
||||
//to support http.request
|
||||
if (source.pathname !== undefined || source.search !== undefined) {
|
||||
source.path = (source.pathname ? source.pathname : '') +
|
||||
(source.search ? source.search : '');
|
||||
}
|
||||
source.href = urlFormat(source);
|
||||
return source;
|
||||
}
|
||||
if (!srcPath.length) {
|
||||
// no path at all. easy.
|
||||
// we've already handled the other stuff above.
|
||||
delete source.pathname;
|
||||
//to support http.request
|
||||
if (!source.search) {
|
||||
source.path = '/' + source.search;
|
||||
} else {
|
||||
delete source.path;
|
||||
}
|
||||
source.href = urlFormat(source);
|
||||
return source;
|
||||
}
|
||||
// if a url ENDs in . or .., then it must get a trailing slash.
|
||||
// however, if it ends in anything else non-slashy,
|
||||
// then it must NOT get a trailing slash.
|
||||
var last = srcPath.slice(-1)[0];
|
||||
var hasTrailingSlash = (
|
||||
(source.host || relative.host) && (last === '.' || last === '..') ||
|
||||
last === '');
|
||||
|
||||
// strip single dots, resolve double dots to parent dir
|
||||
// if the path tries to go above the root, `up` ends up > 0
|
||||
var up = 0;
|
||||
for (var i = srcPath.length; i >= 0; i--) {
|
||||
last = srcPath[i];
|
||||
if (last == '.') {
|
||||
srcPath.splice(i, 1);
|
||||
} else if (last === '..') {
|
||||
srcPath.splice(i, 1);
|
||||
up++;
|
||||
} else if (up) {
|
||||
srcPath.splice(i, 1);
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
// if the path is allowed to go above the root, restore leading ..s
|
||||
if (!mustEndAbs && !removeAllDots) {
|
||||
for (; up--; up) {
|
||||
srcPath.unshift('..');
|
||||
}
|
||||
}
|
||||
|
||||
if (mustEndAbs && srcPath[0] !== '' &&
|
||||
(!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
|
||||
srcPath.unshift('');
|
||||
}
|
||||
|
||||
if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
|
||||
srcPath.push('');
|
||||
}
|
||||
|
||||
var isAbsolute = srcPath[0] === '' ||
|
||||
(srcPath[0] && srcPath[0].charAt(0) === '/');
|
||||
|
||||
// put the host back
|
||||
if (psychotic) {
|
||||
source.hostname = source.host = isAbsolute ? '' :
|
||||
srcPath.length ? srcPath.shift() : '';
|
||||
//occationaly the auth can get stuck only in host
|
||||
//this especialy happens in cases like
|
||||
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
||||
var authInHost = source.host && arrayIndexOf(source.host, '@') > 0 ?
|
||||
source.host.split('@') : false;
|
||||
if (authInHost) {
|
||||
source.auth = authInHost.shift();
|
||||
source.host = source.hostname = authInHost.shift();
|
||||
}
|
||||
}
|
||||
|
||||
mustEndAbs = mustEndAbs || (source.host && srcPath.length);
|
||||
|
||||
if (mustEndAbs && !isAbsolute) {
|
||||
srcPath.unshift('');
|
||||
}
|
||||
|
||||
source.pathname = srcPath.join('/');
|
||||
//to support request.http
|
||||
if (source.pathname !== undefined || source.search !== undefined) {
|
||||
source.path = (source.pathname ? source.pathname : '') +
|
||||
(source.search ? source.search : '');
|
||||
}
|
||||
source.auth = relative.auth || source.auth;
|
||||
source.slashes = source.slashes || relative.slashes;
|
||||
source.href = urlFormat(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
function parseHost(host) {
|
||||
var out = {};
|
||||
var port = portPattern.exec(host);
|
||||
if (port) {
|
||||
port = port[0];
|
||||
out.port = port.substr(1);
|
||||
host = host.substr(0, host.length - port.length);
|
||||
}
|
||||
if (host) out.hostname = host;
|
||||
return out;
|
||||
}
|
@ -1,351 +0,0 @@
|
||||
var events = require('events');
|
||||
|
||||
exports.isArray = isArray;
|
||||
exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
|
||||
exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
|
||||
|
||||
|
||||
exports.print = function () {};
|
||||
exports.puts = function () {};
|
||||
exports.debug = function() {};
|
||||
|
||||
exports.inspect = function(obj, showHidden, depth, colors) {
|
||||
var seen = [];
|
||||
|
||||
var stylize = function(str, styleType) {
|
||||
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||
var styles =
|
||||
{ 'bold' : [1, 22],
|
||||
'italic' : [3, 23],
|
||||
'underline' : [4, 24],
|
||||
'inverse' : [7, 27],
|
||||
'white' : [37, 39],
|
||||
'grey' : [90, 39],
|
||||
'black' : [30, 39],
|
||||
'blue' : [34, 39],
|
||||
'cyan' : [36, 39],
|
||||
'green' : [32, 39],
|
||||
'magenta' : [35, 39],
|
||||
'red' : [31, 39],
|
||||
'yellow' : [33, 39] };
|
||||
|
||||
var style =
|
||||
{ 'special': 'cyan',
|
||||
'number': 'blue',
|
||||
'boolean': 'yellow',
|
||||
'undefined': 'grey',
|
||||
'null': 'bold',
|
||||
'string': 'green',
|
||||
'date': 'magenta',
|
||||
// "name": intentionally not styling
|
||||
'regexp': 'red' }[styleType];
|
||||
|
||||
if (style) {
|
||||
return '\033[' + styles[style][0] + 'm' + str +
|
||||
'\033[' + styles[style][1] + 'm';
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
};
|
||||
if (! colors) {
|
||||
stylize = function(str, styleType) { return str; };
|
||||
}
|
||||
|
||||
function format(value, recurseTimes) {
|
||||
// Provide a hook for user-specified inspect functions.
|
||||
// Check that value is an object with an inspect function on it
|
||||
if (value && typeof value.inspect === 'function' &&
|
||||
// Filter out the util module, it's inspect function is special
|
||||
value !== exports &&
|
||||
// Also filter out any prototype objects using the circular check.
|
||||
!(value.constructor && value.constructor.prototype === value)) {
|
||||
return value.inspect(recurseTimes);
|
||||
}
|
||||
|
||||
// Primitive types cannot have properties
|
||||
switch (typeof value) {
|
||||
case 'undefined':
|
||||
return stylize('undefined', 'undefined');
|
||||
|
||||
case 'string':
|
||||
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
||||
.replace(/'/g, "\\'")
|
||||
.replace(/\\"/g, '"') + '\'';
|
||||
return stylize(simple, 'string');
|
||||
|
||||
case 'number':
|
||||
return stylize('' + value, 'number');
|
||||
|
||||
case 'boolean':
|
||||
return stylize('' + value, 'boolean');
|
||||
}
|
||||
// For some reason typeof null is "object", so special case here.
|
||||
if (value === null) {
|
||||
return stylize('null', 'null');
|
||||
}
|
||||
|
||||
// Look up the keys of the object.
|
||||
var visible_keys = Object_keys(value);
|
||||
var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
|
||||
|
||||
// Functions without properties can be shortcutted.
|
||||
if (typeof value === 'function' && keys.length === 0) {
|
||||
if (isRegExp(value)) {
|
||||
return stylize('' + value, 'regexp');
|
||||
} else {
|
||||
var name = value.name ? ': ' + value.name : '';
|
||||
return stylize('[Function' + name + ']', 'special');
|
||||
}
|
||||
}
|
||||
|
||||
// Dates without properties can be shortcutted
|
||||
if (isDate(value) && keys.length === 0) {
|
||||
return stylize(value.toUTCString(), 'date');
|
||||
}
|
||||
|
||||
var base, type, braces;
|
||||
// Determine the object type
|
||||
if (isArray(value)) {
|
||||
type = 'Array';
|
||||
braces = ['[', ']'];
|
||||
} else {
|
||||
type = 'Object';
|
||||
braces = ['{', '}'];
|
||||
}
|
||||
|
||||
// Make functions say that they are functions
|
||||
if (typeof value === 'function') {
|
||||
var n = value.name ? ': ' + value.name : '';
|
||||
base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
|
||||
} else {
|
||||
base = '';
|
||||
}
|
||||
|
||||
// Make dates with properties first say the date
|
||||
if (isDate(value)) {
|
||||
base = ' ' + value.toUTCString();
|
||||
}
|
||||
|
||||
if (keys.length === 0) {
|
||||
return braces[0] + base + braces[1];
|
||||
}
|
||||
|
||||
if (recurseTimes < 0) {
|
||||
if (isRegExp(value)) {
|
||||
return stylize('' + value, 'regexp');
|
||||
} else {
|
||||
return stylize('[Object]', 'special');
|
||||
}
|
||||
}
|
||||
|
||||
seen.push(value);
|
||||
|
||||
var output = keys.map(function(key) {
|
||||
var name, str;
|
||||
if (value.__lookupGetter__) {
|
||||
if (value.__lookupGetter__(key)) {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = stylize('[Getter/Setter]', 'special');
|
||||
} else {
|
||||
str = stylize('[Getter]', 'special');
|
||||
}
|
||||
} else {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = stylize('[Setter]', 'special');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visible_keys.indexOf(key) < 0) {
|
||||
name = '[' + key + ']';
|
||||
}
|
||||
if (!str) {
|
||||
if (seen.indexOf(value[key]) < 0) {
|
||||
if (recurseTimes === null) {
|
||||
str = format(value[key]);
|
||||
} else {
|
||||
str = format(value[key], recurseTimes - 1);
|
||||
}
|
||||
if (str.indexOf('\n') > -1) {
|
||||
if (isArray(value)) {
|
||||
str = str.split('\n').map(function(line) {
|
||||
return ' ' + line;
|
||||
}).join('\n').substr(2);
|
||||
} else {
|
||||
str = '\n' + str.split('\n').map(function(line) {
|
||||
return ' ' + line;
|
||||
}).join('\n');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
str = stylize('[Circular]', 'special');
|
||||
}
|
||||
}
|
||||
if (typeof name === 'undefined') {
|
||||
if (type === 'Array' && key.match(/^\d+$/)) {
|
||||
return str;
|
||||
}
|
||||
name = JSON.stringify('' + key);
|
||||
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
||||
name = name.substr(1, name.length - 2);
|
||||
name = stylize(name, 'name');
|
||||
} else {
|
||||
name = name.replace(/'/g, "\\'")
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/(^"|"$)/g, "'");
|
||||
name = stylize(name, 'string');
|
||||
}
|
||||
}
|
||||
|
||||
return name + ': ' + str;
|
||||
});
|
||||
|
||||
seen.pop();
|
||||
|
||||
var numLinesEst = 0;
|
||||
var length = output.reduce(function(prev, cur) {
|
||||
numLinesEst++;
|
||||
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
||||
return prev + cur.length + 1;
|
||||
}, 0);
|
||||
|
||||
if (length > 50) {
|
||||
output = braces[0] +
|
||||
(base === '' ? '' : base + '\n ') +
|
||||
' ' +
|
||||
output.join(',\n ') +
|
||||
' ' +
|
||||
braces[1];
|
||||
|
||||
} else {
|
||||
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
return format(obj, (typeof depth === 'undefined' ? 2 : depth));
|
||||
};
|
||||
|
||||
|
||||
function isArray(ar) {
|
||||
return ar instanceof Array ||
|
||||
Array.isArray(ar) ||
|
||||
(ar && ar !== Object.prototype && isArray(ar.__proto__));
|
||||
}
|
||||
|
||||
|
||||
function isRegExp(re) {
|
||||
return re instanceof RegExp ||
|
||||
(typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]');
|
||||
}
|
||||
|
||||
|
||||
function isDate(d) {
|
||||
if (d instanceof Date) return true;
|
||||
if (typeof d !== 'object') return false;
|
||||
var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype);
|
||||
var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__);
|
||||
return JSON.stringify(proto) === JSON.stringify(properties);
|
||||
}
|
||||
|
||||
function pad(n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
||||
'Oct', 'Nov', 'Dec'];
|
||||
|
||||
// 26 Feb 16:19:34
|
||||
function timestamp() {
|
||||
var d = new Date();
|
||||
var time = [pad(d.getHours()),
|
||||
pad(d.getMinutes()),
|
||||
pad(d.getSeconds())].join(':');
|
||||
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
||||
}
|
||||
|
||||
exports.log = function (msg) {};
|
||||
|
||||
exports.pump = null;
|
||||
|
||||
var Object_keys = Object.keys || function (obj) {
|
||||
var res = [];
|
||||
for (var key in obj) res.push(key);
|
||||
return res;
|
||||
};
|
||||
|
||||
var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
|
||||
var res = [];
|
||||
for (var key in obj) {
|
||||
if (Object.hasOwnProperty.call(obj, key)) res.push(key);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
var Object_create = Object.create || function (prototype, properties) {
|
||||
// from es5-shim
|
||||
var object;
|
||||
if (prototype === null) {
|
||||
object = { '__proto__' : null };
|
||||
}
|
||||
else {
|
||||
if (typeof prototype !== 'object') {
|
||||
throw new TypeError(
|
||||
'typeof prototype[' + (typeof prototype) + '] != \'object\''
|
||||
);
|
||||
}
|
||||
var Type = function () {};
|
||||
Type.prototype = prototype;
|
||||
object = new Type();
|
||||
object.__proto__ = prototype;
|
||||
}
|
||||
if (typeof properties !== 'undefined' && Object.defineProperties) {
|
||||
Object.defineProperties(object, properties);
|
||||
}
|
||||
return object;
|
||||
};
|
||||
|
||||
exports.inherits = function(ctor, superCtor) {
|
||||
ctor.super_ = superCtor;
|
||||
ctor.prototype = Object_create(superCtor.prototype, {
|
||||
constructor: {
|
||||
value: ctor,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var formatRegExp = /%[sdj%]/g;
|
||||
exports.format = function(f) {
|
||||
if (typeof f !== 'string') {
|
||||
var objects = [];
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
objects.push(exports.inspect(arguments[i]));
|
||||
}
|
||||
return objects.join(' ');
|
||||
}
|
||||
|
||||
var i = 1;
|
||||
var args = arguments;
|
||||
var len = args.length;
|
||||
var str = String(f).replace(formatRegExp, function(x) {
|
||||
if (x === '%%') return '%';
|
||||
if (i >= len) return x;
|
||||
switch (x) {
|
||||
case '%s': return String(args[i++]);
|
||||
case '%d': return Number(args[i++]);
|
||||
case '%j': return JSON.stringify(args[i++]);
|
||||
default:
|
||||
return x;
|
||||
}
|
||||
});
|
||||
for(var x = args[i]; i < len; x = args[++i]){
|
||||
if (x === null || typeof x !== 'object') {
|
||||
str += ' ' + x;
|
||||
} else {
|
||||
str += ' ' + exports.inspect(x);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
@ -1,182 +0,0 @@
|
||||
methods
|
||||
=======
|
||||
|
||||
This section documents the browserify api.
|
||||
|
||||
````javascript
|
||||
var browserify = require('browserify');
|
||||
````
|
||||
|
||||
var b = browserify(opts={})
|
||||
---------------------------
|
||||
|
||||
Return a new bundle object.
|
||||
|
||||
`opts` may also contain these fields:
|
||||
|
||||
* watch - set watches on files, see below
|
||||
* cache - turn on caching for AST traversals, see below
|
||||
* debug - turn on source mapping for debugging with `//@ sourceURL=...`
|
||||
in browsers that support it
|
||||
* exports - an array of the core items to export to the namespace. Available
|
||||
items: 'require', 'process'
|
||||
|
||||
If `opts` is a string, it is interpreted as a file to call `.addEntry()` with.
|
||||
|
||||
### watch :: Boolean or Object
|
||||
|
||||
Set watches on files and automatically rebundle when a file changes.
|
||||
|
||||
This option defaults to false. If `opts.watch` is set to true, default watch
|
||||
arguments are assumed or you can pass in an object to pass along as the second
|
||||
parameter to `fs.watchFile()`.
|
||||
|
||||
### cache :: Boolean or String
|
||||
|
||||
If `cache` is a boolean, turn on caching at
|
||||
`$HOME/.config/browserify/cache.json`.
|
||||
|
||||
If `cache` is a string, turn on caching at the filename specified by `cache`.
|
||||
|
||||
### bundle events
|
||||
|
||||
`b` bundles will also emit events.
|
||||
|
||||
#### 'syntaxError', err
|
||||
|
||||
This event gets emitted when there is a syntax error somewhere in the build
|
||||
process. If you don't listen for this event, the error will be printed to
|
||||
stderr.
|
||||
|
||||
#### 'bundle'
|
||||
|
||||
In watch mode, this event is emitted when a new bundle has been generated.
|
||||
|
||||
b.bundle()
|
||||
----------
|
||||
|
||||
Return the bundled source as a string.
|
||||
|
||||
By default, `require` is not exported to the environment if there are entry
|
||||
files in the bundle but you can override that with `opts.exports`.
|
||||
|
||||
`process` is only exported to the environment when `opts.exports` contains the
|
||||
string `'process'`.
|
||||
|
||||
b.require(file)
|
||||
---------------
|
||||
|
||||
Require a file or files for inclusion in the bundle.
|
||||
|
||||
If `file` is an array, require each element in it.
|
||||
|
||||
If `file` is a non-array object, map an alias to a package name.
|
||||
For instance to be able to map `require('jquery')` to the jquery-browserify
|
||||
package, you can do:
|
||||
|
||||
````javascript
|
||||
b.require({ jquery : 'jquery-browserify' })
|
||||
````
|
||||
|
||||
and the same thing in middleware-form:
|
||||
|
||||
````javascript
|
||||
browserify({ require : { jquery : 'jquery-browserify' } })
|
||||
````
|
||||
|
||||
To mix alias objects with regular requires you could do:
|
||||
|
||||
````javascript
|
||||
browserify({ require : [ 'seq', { jquery : 'jquery-browserify' }, 'traverse' ])
|
||||
````
|
||||
|
||||
In practice you won't need to `b.require()` very many files since all the
|
||||
`require()`s are read from each file that you require and automatically
|
||||
included.
|
||||
|
||||
b.ignore(file)
|
||||
--------------
|
||||
|
||||
Omit a file or files from being included by the AST walk to hunt down
|
||||
`require()` statements.
|
||||
|
||||
b.addEntry(file)
|
||||
----------------
|
||||
|
||||
Append a file to the end of the bundle and execute it without having to
|
||||
`require()` it.
|
||||
|
||||
Specifying an entry point will let you `require()` other modules without having
|
||||
to load the entry point in a `<script>` tag yourself.
|
||||
|
||||
If entry is an Array, concatenate these files together and append to the end of
|
||||
the bundle.
|
||||
|
||||
b.filter(fn)
|
||||
------------
|
||||
|
||||
Transform the source using the filter function `fn(src)`. The return value of
|
||||
`fn` should be the new source.
|
||||
|
||||
b.register(ext, fn)
|
||||
-------------------
|
||||
|
||||
Register a handler to wrap extensions.
|
||||
|
||||
Wrap every file matching the extension `ext` with the function `fn`.
|
||||
|
||||
For every `file` included into the bundle `fn` gets called for matching file
|
||||
types as `fn.call(b, body, file)` for the bundle instance `b` and the file
|
||||
content string `body`. `fn` should return the new wrapped contents.
|
||||
|
||||
If `ext` is unspecified, execute the wrapper for every file.
|
||||
|
||||
If `ext` is 'post', execute the wrapper on the entire bundle.
|
||||
|
||||
If `ext` is 'pre', call the wrapper function with the bundle object before the
|
||||
source is generated.
|
||||
|
||||
If `ext` is 'path', execute the wrapper for every `file` before it is open,
|
||||
allowing the extension to change it. `fn` gets called as `fn.call(b, file)`
|
||||
for the bundle instance `b` and the file path `file`. `fn` should return the
|
||||
new path to the file.
|
||||
|
||||
If `ext` is an object, pull the extension from `ext.extension` and the wrapper
|
||||
function `fn` from `ext.wrapper`. This makes it easy to write plugins like
|
||||
[fileify](https://github.com/substack/node-fileify).
|
||||
|
||||
Coffee script support is just implemented internally as a `.register()`
|
||||
extension:
|
||||
|
||||
````javascript
|
||||
b.register('.coffee', function (body) {
|
||||
return coffee.compile(body);
|
||||
});
|
||||
````
|
||||
|
||||
b.use(fn)
|
||||
---------
|
||||
|
||||
Use a middleware plugin, `fn`. `fn` is called with the instance object `b`.
|
||||
|
||||
b.prepend(content)
|
||||
------------------
|
||||
|
||||
Prepend unwrapped content to the beginning of the bundle.
|
||||
|
||||
b.append(content)
|
||||
-----------------
|
||||
|
||||
Append unwrapped content to the end of the bundle.
|
||||
|
||||
b.alias(to, from)
|
||||
-----------------
|
||||
|
||||
Alias a package name from another package name.
|
||||
|
||||
b.modified
|
||||
----------
|
||||
|
||||
Contains a Date object with the time the bundle was last modified. This field is
|
||||
useful in conjunction with the `watch` field described in the `browserify()` to
|
||||
generate unique `<script>` `src` values to force script reloading.
|
@ -1,62 +0,0 @@
|
||||
recipes
|
||||
=======
|
||||
|
||||
Here are some recipe-style examples for getting started.
|
||||
|
||||
use an npm module in the browser
|
||||
================================
|
||||
|
||||
First install a module:
|
||||
|
||||
```
|
||||
npm install traverse
|
||||
```
|
||||
|
||||
Then write an `entry.js`:
|
||||
|
||||
````javascript
|
||||
var traverse = require('traverse');
|
||||
var obj = traverse({ a : 3, b : [ 4, 5 ] }).map(function (x) {
|
||||
if (typeof x === 'number') this.update(x * 100)
|
||||
});
|
||||
console.dir(obj);
|
||||
````
|
||||
|
||||
now bundle it!
|
||||
|
||||
```
|
||||
$ browserify entry.js -o bundle.js
|
||||
```
|
||||
|
||||
then put it in your html
|
||||
|
||||
``` html
|
||||
<script src="bundle.js"></script>
|
||||
```
|
||||
|
||||
and the entry.js will just run and `require('traverse')` will just work™.
|
||||
|
||||
convert a node module into a browser require-able standalone file
|
||||
-----------------------------------------------------------------
|
||||
|
||||
Install the `traverse` package into `./node_modules`:
|
||||
|
||||
```
|
||||
npm install traverse
|
||||
```
|
||||
|
||||
Bundle everything up with browserify:
|
||||
|
||||
```
|
||||
$ npm install -g browserify
|
||||
$ browserify -r traverse -o bundle.js
|
||||
```
|
||||
|
||||
Look at the files! There is a new one: `bundle.js`. Now go into HTML land:
|
||||
|
||||
``` html
|
||||
<script src="bundle.js"></script>
|
||||
<script>
|
||||
var traverse = require('traverse');
|
||||
</script>
|
||||
```
|
@ -1,219 +0,0 @@
|
||||
var require = function (file, cwd) {
|
||||
var resolved = require.resolve(file, cwd || '/');
|
||||
var mod = require.modules[resolved];
|
||||
if (!mod) throw new Error(
|
||||
'Failed to resolve module ' + file + ', tried ' + resolved
|
||||
);
|
||||
var res = mod._cached ? mod._cached : mod();
|
||||
return res;
|
||||
}
|
||||
|
||||
require.paths = [];
|
||||
require.modules = {};
|
||||
require.extensions = [".js",".coffee"];
|
||||
|
||||
require._core = {
|
||||
'assert': true,
|
||||
'events': true,
|
||||
'fs': true,
|
||||
'path': true,
|
||||
'vm': true
|
||||
};
|
||||
|
||||
require.resolve = (function () {
|
||||
return function (x, cwd) {
|
||||
if (!cwd) cwd = '/';
|
||||
|
||||
if (require._core[x]) return x;
|
||||
var path = require.modules.path();
|
||||
var y = cwd || '.';
|
||||
|
||||
if (x.match(/^(?:\.\.?\/|\/)/)) {
|
||||
var m = loadAsFileSync(path.resolve(y, x))
|
||||
|| loadAsDirectorySync(path.resolve(y, x));
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
var n = loadNodeModulesSync(x, y);
|
||||
if (n) return n;
|
||||
|
||||
throw new Error("Cannot find module '" + x + "'");
|
||||
|
||||
function loadAsFileSync (x) {
|
||||
if (require.modules[x]) {
|
||||
return x;
|
||||
}
|
||||
|
||||
for (var i = 0; i < require.extensions.length; i++) {
|
||||
var ext = require.extensions[i];
|
||||
if (require.modules[x + ext]) return x + ext;
|
||||
}
|
||||
}
|
||||
|
||||
function loadAsDirectorySync (x) {
|
||||
x = x.replace(/\/+$/, '');
|
||||
var pkgfile = x + '/package.json';
|
||||
if (require.modules[pkgfile]) {
|
||||
var pkg = require.modules[pkgfile]();
|
||||
var b = pkg.browserify;
|
||||
if (typeof b === 'object' && b.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, b.main));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (typeof b === 'string') {
|
||||
var m = loadAsFileSync(path.resolve(x, b));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (pkg.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, pkg.main));
|
||||
if (m) return m;
|
||||
}
|
||||
}
|
||||
|
||||
return loadAsFileSync(x + '/index');
|
||||
}
|
||||
|
||||
function loadNodeModulesSync (x, start) {
|
||||
var dirs = nodeModulesPathsSync(start);
|
||||
for (var i = 0; i < dirs.length; i++) {
|
||||
var dir = dirs[i];
|
||||
var m = loadAsFileSync(dir + '/' + x);
|
||||
if (m) return m;
|
||||
var n = loadAsDirectorySync(dir + '/' + x);
|
||||
if (n) return n;
|
||||
}
|
||||
|
||||
var m = loadAsFileSync(x);
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
function nodeModulesPathsSync (start) {
|
||||
var parts;
|
||||
if (start === '/') parts = [ '' ];
|
||||
else parts = path.normalize(start).split('/');
|
||||
|
||||
var dirs = [];
|
||||
for (var i = parts.length - 1; i >= 0; i--) {
|
||||
if (parts[i] === 'node_modules') continue;
|
||||
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
|
||||
dirs.push(dir);
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
require.alias = function (from, to) {
|
||||
var path = require.modules.path();
|
||||
var res = null;
|
||||
try {
|
||||
res = require.resolve(from + '/package.json', '/');
|
||||
}
|
||||
catch (err) {
|
||||
res = require.resolve(from, '/');
|
||||
}
|
||||
var basedir = path.dirname(res);
|
||||
|
||||
var keys = (Object.keys || function (obj) {
|
||||
var res = [];
|
||||
for (var key in obj) res.push(key)
|
||||
return res;
|
||||
})(require.modules);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
if (key.slice(0, basedir.length + 1) === basedir + '/') {
|
||||
var f = key.slice(basedir.length);
|
||||
require.modules[to + f] = require.modules[basedir + f];
|
||||
}
|
||||
else if (key === basedir) {
|
||||
require.modules[to] = require.modules[basedir];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require.define = function (filename, fn) {
|
||||
var dirname = require._core[filename]
|
||||
? ''
|
||||
: require.modules.path().dirname(filename)
|
||||
;
|
||||
|
||||
var require_ = function (file) {
|
||||
return require(file, dirname)
|
||||
};
|
||||
require_.resolve = function (name) {
|
||||
return require.resolve(name, dirname);
|
||||
};
|
||||
require_.modules = require.modules;
|
||||
require_.define = require.define;
|
||||
var module_ = { exports : {} };
|
||||
|
||||
require.modules[filename] = function () {
|
||||
require.modules[filename]._cached = module_.exports;
|
||||
fn.call(
|
||||
module_.exports,
|
||||
require_,
|
||||
module_,
|
||||
module_.exports,
|
||||
dirname,
|
||||
filename
|
||||
);
|
||||
require.modules[filename]._cached = module_.exports;
|
||||
return module_.exports;
|
||||
};
|
||||
};
|
||||
|
||||
if (typeof process === 'undefined') process = {};
|
||||
|
||||
if (!process.nextTick) process.nextTick = (function () {
|
||||
var queue = [];
|
||||
var canPost = typeof window !== 'undefined'
|
||||
&& window.postMessage && window.addEventListener
|
||||
;
|
||||
|
||||
if (canPost) {
|
||||
window.addEventListener('message', function (ev) {
|
||||
if (ev.source === window && ev.data === 'browserify-tick') {
|
||||
ev.stopPropagation();
|
||||
if (queue.length > 0) {
|
||||
var fn = queue.shift();
|
||||
fn();
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
return function (fn) {
|
||||
if (canPost) {
|
||||
queue.push(fn);
|
||||
window.postMessage('browserify-tick', '*');
|
||||
}
|
||||
else setTimeout(fn, 0);
|
||||
};
|
||||
})();
|
||||
|
||||
if (!process.title) process.title = 'browser';
|
||||
|
||||
if (!process.binding) process.binding = function (name) {
|
||||
if (name === 'evals') return require('vm')
|
||||
else throw new Error('No such module')
|
||||
};
|
||||
|
||||
if (!process.cwd) process.cwd = function () { return '.' };
|
||||
|
||||
require.define("path", Function(
|
||||
[ 'require', 'module', 'exports', '__dirname', '__filename' ],
|
||||
"function filter (xs, fn) {\n var res = [];\n for (var i = 0; i < xs.length; i++) {\n if (fn(xs[i], i, xs)) res.push(xs[i]);\n }\n return res;\n}\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\nfunction normalizeArray(parts, allowAboveRoot) {\n // if the path tries to go above the root, `up` ends up > 0\n var up = 0;\n for (var i = parts.length; i >= 0; i--) {\n var last = parts[i];\n if (last == '.') {\n parts.splice(i, 1);\n } else if (last === '..') {\n parts.splice(i, 1);\n up++;\n } else if (up) {\n parts.splice(i, 1);\n up--;\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..');\n }\n }\n\n return parts;\n}\n\n// Regex to split a filename into [*, dir, basename, ext]\n// posix version\nvar splitPathRe = /^(.+\\/(?!$)|\\/)?((?:.+?)?(\\.[^.]*)?)$/;\n\n// path.resolve([from ...], to)\n// posix version\nexports.resolve = function() {\nvar resolvedPath = '',\n resolvedAbsolute = false;\n\nfor (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {\n var path = (i >= 0)\n ? arguments[i]\n : process.cwd();\n\n // Skip empty and invalid entries\n if (typeof path !== 'string' || !path) {\n continue;\n }\n\n resolvedPath = path + '/' + resolvedPath;\n resolvedAbsolute = path.charAt(0) === '/';\n}\n\n// At this point the path should be resolved to a full absolute path, but\n// handle relative paths to be safe (might happen when process.cwd() fails)\n\n// Normalize the path\nresolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {\n return !!p;\n }), !resolvedAbsolute).join('/');\n\n return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';\n};\n\n// path.normalize(path)\n// posix version\nexports.normalize = function(path) {\nvar isAbsolute = path.charAt(0) === '/',\n trailingSlash = path.slice(-1) === '/';\n\n// Normalize the path\npath = normalizeArray(filter(path.split('/'), function(p) {\n return !!p;\n }), !isAbsolute).join('/');\n\n if (!path && !isAbsolute) {\n path = '.';\n }\n if (path && trailingSlash) {\n path += '/';\n }\n \n return (isAbsolute ? '/' : '') + path;\n};\n\n\n// posix version\nexports.join = function() {\n var paths = Array.prototype.slice.call(arguments, 0);\n return exports.normalize(filter(paths, function(p, index) {\n return p && typeof p === 'string';\n }).join('/'));\n};\n\n\nexports.dirname = function(path) {\n var dir = splitPathRe.exec(path)[1] || '';\n var isWindows = false;\n if (!dir) {\n // No dirname\n return '.';\n } else if (dir.length === 1 ||\n (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {\n // It is just a slash or a drive letter with a slash\n return dir;\n } else {\n // It is a full dirname, strip trailing slash\n return dir.substring(0, dir.length - 1);\n }\n};\n\n\nexports.basename = function(path, ext) {\n var f = splitPathRe.exec(path)[2] || '';\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.substr(-1 * ext.length) === ext) {\n f = f.substr(0, f.length - ext.length);\n }\n return f;\n};\n\n\nexports.extname = function(path) {\n return splitPathRe.exec(path)[3] || '';\n};\n\n//@ sourceURL=path"
|
||||
));
|
||||
|
||||
require.define("/thrower.js", Function(
|
||||
[ 'require', 'module', 'exports', '__dirname', '__filename' ],
|
||||
"module.exports = function () {\n throw 'beep';\n};\n\n//@ sourceURL=/thrower.js"
|
||||
));
|
||||
|
||||
require.define("/entry.js", Function(
|
||||
[ 'require', 'module', 'exports', '__dirname', '__filename' ],
|
||||
"var thrower = require('./thrower');\nthrower();\n\n//@ sourceURL=/entry.js"
|
||||
));
|
||||
require("/entry.js");
|
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
browserify js/entry.js -v -o browserify.js --debug
|
@ -1,7 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/browserify.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
@ -1,2 +0,0 @@
|
||||
var thrower = require('./thrower');
|
||||
thrower();
|
@ -1,3 +0,0 @@
|
||||
module.exports = function () {
|
||||
throw 'beep';
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var connect = require('connect');
|
||||
var server = connect.createServer();
|
||||
|
||||
server.use(connect.static(__dirname));
|
||||
server.listen(8080);
|
||||
console.log('Listening on :8080');
|
||||
console.log('Make sure to run ./build.sh to generate browserify.js');
|
@ -1,368 +0,0 @@
|
||||
var require = function (file, cwd) {
|
||||
var resolved = require.resolve(file, cwd || '/');
|
||||
var mod = require.modules[resolved];
|
||||
if (!mod) throw new Error(
|
||||
'Failed to resolve module ' + file + ', tried ' + resolved
|
||||
);
|
||||
var res = mod._cached ? mod._cached : mod();
|
||||
return res;
|
||||
}
|
||||
|
||||
require.paths = [];
|
||||
require.modules = {};
|
||||
require.extensions = [".js",".coffee"];
|
||||
|
||||
require._core = {
|
||||
'assert': true,
|
||||
'events': true,
|
||||
'fs': true,
|
||||
'path': true,
|
||||
'vm': true
|
||||
};
|
||||
|
||||
require.resolve = (function () {
|
||||
return function (x, cwd) {
|
||||
if (!cwd) cwd = '/';
|
||||
|
||||
if (require._core[x]) return x;
|
||||
var path = require.modules.path();
|
||||
cwd = path.resolve('/', cwd);
|
||||
var y = cwd || '/';
|
||||
|
||||
if (x.match(/^(?:\.\.?\/|\/)/)) {
|
||||
var m = loadAsFileSync(path.resolve(y, x))
|
||||
|| loadAsDirectorySync(path.resolve(y, x));
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
var n = loadNodeModulesSync(x, y);
|
||||
if (n) return n;
|
||||
|
||||
throw new Error("Cannot find module '" + x + "'");
|
||||
|
||||
function loadAsFileSync (x) {
|
||||
if (require.modules[x]) {
|
||||
return x;
|
||||
}
|
||||
|
||||
for (var i = 0; i < require.extensions.length; i++) {
|
||||
var ext = require.extensions[i];
|
||||
if (require.modules[x + ext]) return x + ext;
|
||||
}
|
||||
}
|
||||
|
||||
function loadAsDirectorySync (x) {
|
||||
x = x.replace(/\/+$/, '');
|
||||
var pkgfile = x + '/package.json';
|
||||
if (require.modules[pkgfile]) {
|
||||
var pkg = require.modules[pkgfile]();
|
||||
var b = pkg.browserify;
|
||||
if (typeof b === 'object' && b.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, b.main));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (typeof b === 'string') {
|
||||
var m = loadAsFileSync(path.resolve(x, b));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (pkg.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, pkg.main));
|
||||
if (m) return m;
|
||||
}
|
||||
}
|
||||
|
||||
return loadAsFileSync(x + '/index');
|
||||
}
|
||||
|
||||
function loadNodeModulesSync (x, start) {
|
||||
var dirs = nodeModulesPathsSync(start);
|
||||
for (var i = 0; i < dirs.length; i++) {
|
||||
var dir = dirs[i];
|
||||
var m = loadAsFileSync(dir + '/' + x);
|
||||
if (m) return m;
|
||||
var n = loadAsDirectorySync(dir + '/' + x);
|
||||
if (n) return n;
|
||||
}
|
||||
|
||||
var m = loadAsFileSync(x);
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
function nodeModulesPathsSync (start) {
|
||||
var parts;
|
||||
if (start === '/') parts = [ '' ];
|
||||
else parts = path.normalize(start).split('/');
|
||||
|
||||
var dirs = [];
|
||||
for (var i = parts.length - 1; i >= 0; i--) {
|
||||
if (parts[i] === 'node_modules') continue;
|
||||
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
|
||||
dirs.push(dir);
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
require.alias = function (from, to) {
|
||||
var path = require.modules.path();
|
||||
var res = null;
|
||||
try {
|
||||
res = require.resolve(from + '/package.json', '/');
|
||||
}
|
||||
catch (err) {
|
||||
res = require.resolve(from, '/');
|
||||
}
|
||||
var basedir = path.dirname(res);
|
||||
|
||||
var keys = (Object.keys || function (obj) {
|
||||
var res = [];
|
||||
for (var key in obj) res.push(key)
|
||||
return res;
|
||||
})(require.modules);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
if (key.slice(0, basedir.length + 1) === basedir + '/') {
|
||||
var f = key.slice(basedir.length);
|
||||
require.modules[to + f] = require.modules[basedir + f];
|
||||
}
|
||||
else if (key === basedir) {
|
||||
require.modules[to] = require.modules[basedir];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require.define = function (filename, fn) {
|
||||
var dirname = require._core[filename]
|
||||
? ''
|
||||
: require.modules.path().dirname(filename)
|
||||
;
|
||||
|
||||
var require_ = function (file) {
|
||||
return require(file, dirname)
|
||||
};
|
||||
require_.resolve = function (name) {
|
||||
return require.resolve(name, dirname);
|
||||
};
|
||||
require_.modules = require.modules;
|
||||
require_.define = require.define;
|
||||
var module_ = { exports : {} };
|
||||
|
||||
require.modules[filename] = function () {
|
||||
require.modules[filename]._cached = module_.exports;
|
||||
fn.call(
|
||||
module_.exports,
|
||||
require_,
|
||||
module_,
|
||||
module_.exports,
|
||||
dirname,
|
||||
filename
|
||||
);
|
||||
require.modules[filename]._cached = module_.exports;
|
||||
return module_.exports;
|
||||
};
|
||||
};
|
||||
|
||||
if (typeof process === 'undefined') process = {};
|
||||
|
||||
if (!process.nextTick) process.nextTick = (function () {
|
||||
var queue = [];
|
||||
var canPost = typeof window !== 'undefined'
|
||||
&& window.postMessage && window.addEventListener
|
||||
;
|
||||
|
||||
if (canPost) {
|
||||
window.addEventListener('message', function (ev) {
|
||||
if (ev.source === window && ev.data === 'browserify-tick') {
|
||||
ev.stopPropagation();
|
||||
if (queue.length > 0) {
|
||||
var fn = queue.shift();
|
||||
fn();
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
return function (fn) {
|
||||
if (canPost) {
|
||||
queue.push(fn);
|
||||
window.postMessage('browserify-tick', '*');
|
||||
}
|
||||
else setTimeout(fn, 0);
|
||||
};
|
||||
})();
|
||||
|
||||
if (!process.title) process.title = 'browser';
|
||||
|
||||
if (!process.binding) process.binding = function (name) {
|
||||
if (name === 'evals') return require('vm')
|
||||
else throw new Error('No such module')
|
||||
};
|
||||
|
||||
if (!process.cwd) process.cwd = function () { return '.' };
|
||||
|
||||
require.define("path", function (require, module, exports, __dirname, __filename) {
|
||||
function filter (xs, fn) {
|
||||
var res = [];
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
if (fn(xs[i], i, xs)) res.push(xs[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// resolves . and .. elements in a path array with directory names there
|
||||
// must be no slashes, empty elements, or device names (c:\) in the array
|
||||
// (so also no leading and trailing slashes - it does not distinguish
|
||||
// relative and absolute paths)
|
||||
function normalizeArray(parts, allowAboveRoot) {
|
||||
// if the path tries to go above the root, `up` ends up > 0
|
||||
var up = 0;
|
||||
for (var i = parts.length; i >= 0; i--) {
|
||||
var last = parts[i];
|
||||
if (last == '.') {
|
||||
parts.splice(i, 1);
|
||||
} else if (last === '..') {
|
||||
parts.splice(i, 1);
|
||||
up++;
|
||||
} else if (up) {
|
||||
parts.splice(i, 1);
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
// if the path is allowed to go above the root, restore leading ..s
|
||||
if (allowAboveRoot) {
|
||||
for (; up--; up) {
|
||||
parts.unshift('..');
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
// Regex to split a filename into [*, dir, basename, ext]
|
||||
// posix version
|
||||
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
|
||||
|
||||
// path.resolve([from ...], to)
|
||||
// posix version
|
||||
exports.resolve = function() {
|
||||
var resolvedPath = '',
|
||||
resolvedAbsolute = false;
|
||||
|
||||
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
|
||||
var path = (i >= 0)
|
||||
? arguments[i]
|
||||
: process.cwd();
|
||||
|
||||
// Skip empty and invalid entries
|
||||
if (typeof path !== 'string' || !path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
resolvedPath = path + '/' + resolvedPath;
|
||||
resolvedAbsolute = path.charAt(0) === '/';
|
||||
}
|
||||
|
||||
// At this point the path should be resolved to a full absolute path, but
|
||||
// handle relative paths to be safe (might happen when process.cwd() fails)
|
||||
|
||||
// Normalize the path
|
||||
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
||||
return !!p;
|
||||
}), !resolvedAbsolute).join('/');
|
||||
|
||||
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
||||
};
|
||||
|
||||
// path.normalize(path)
|
||||
// posix version
|
||||
exports.normalize = function(path) {
|
||||
var isAbsolute = path.charAt(0) === '/',
|
||||
trailingSlash = path.slice(-1) === '/';
|
||||
|
||||
// Normalize the path
|
||||
path = normalizeArray(filter(path.split('/'), function(p) {
|
||||
return !!p;
|
||||
}), !isAbsolute).join('/');
|
||||
|
||||
if (!path && !isAbsolute) {
|
||||
path = '.';
|
||||
}
|
||||
if (path && trailingSlash) {
|
||||
path += '/';
|
||||
}
|
||||
|
||||
return (isAbsolute ? '/' : '') + path;
|
||||
};
|
||||
|
||||
|
||||
// posix version
|
||||
exports.join = function() {
|
||||
var paths = Array.prototype.slice.call(arguments, 0);
|
||||
return exports.normalize(filter(paths, function(p, index) {
|
||||
return p && typeof p === 'string';
|
||||
}).join('/'));
|
||||
};
|
||||
|
||||
|
||||
exports.dirname = function(path) {
|
||||
var dir = splitPathRe.exec(path)[1] || '';
|
||||
var isWindows = false;
|
||||
if (!dir) {
|
||||
// No dirname
|
||||
return '.';
|
||||
} else if (dir.length === 1 ||
|
||||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
|
||||
// It is just a slash or a drive letter with a slash
|
||||
return dir;
|
||||
} else {
|
||||
// It is a full dirname, strip trailing slash
|
||||
return dir.substring(0, dir.length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.basename = function(path, ext) {
|
||||
var f = splitPathRe.exec(path)[2] || '';
|
||||
// TODO: make this comparison case-insensitive on windows?
|
||||
if (ext && f.substr(-1 * ext.length) === ext) {
|
||||
f = f.substr(0, f.length - ext.length);
|
||||
}
|
||||
return f;
|
||||
};
|
||||
|
||||
|
||||
exports.extname = function(path) {
|
||||
return splitPathRe.exec(path)[3] || '';
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("/foo.js", function (require, module, exports, __dirname, __filename) {
|
||||
var bar = require('./bar');
|
||||
|
||||
module.exports = function (x) {
|
||||
return x * bar.coeff(x) + (x * 3 - 2)
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("/bar.js", function (require, module, exports, __dirname, __filename) {
|
||||
exports.coeff = function (x) {
|
||||
return Math.log(x) / Math.log(2) + 1;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("/entry.js", function (require, module, exports, __dirname, __filename) {
|
||||
var foo = require('./foo');
|
||||
|
||||
window.onload = function () {
|
||||
document.getElementById('result').innerHTML = foo(100);
|
||||
};
|
||||
|
||||
});
|
||||
require("/entry.js");
|
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
browserify js/entry.js -v -o browserify.js
|
@ -1,9 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/browserify.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
foo =
|
||||
<span style='font-family: monospace' id="result"></span>
|
||||
</body>
|
||||
</html>
|
@ -1,3 +0,0 @@
|
||||
exports.coeff = function (x) {
|
||||
return Math.log(x) / Math.log(2) + 1;
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
var foo = require('./foo');
|
||||
|
||||
window.onload = function () {
|
||||
document.getElementById('result').innerHTML = foo(100);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
var bar = require('./bar');
|
||||
|
||||
module.exports = function (x) {
|
||||
return x * bar.coeff(x) + (x * 3 - 2)
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var connect = require('connect');
|
||||
var server = connect.createServer();
|
||||
|
||||
server.use(connect.static(__dirname));
|
||||
server.listen(8080);
|
||||
console.log('Listening on :8080');
|
||||
console.log('Make sure to run ./build.sh to generate browserify.js');
|
@ -1,5 +0,0 @@
|
||||
var browserify = require('../../');
|
||||
var b = browserify(__dirname + '/m.js');
|
||||
b.addEntry(__dirname + '/n.js');
|
||||
|
||||
b.bundle().pipe(process.stdout);
|
@ -1,3 +0,0 @@
|
||||
module.exports = function (n) {
|
||||
return n * 11;
|
||||
};
|
@ -1,3 +0,0 @@
|
||||
module.exports = function (n) {
|
||||
return 10 + n * require('./bar')(n);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
var foo = require('./foo');
|
||||
var bar = require('./bar');
|
||||
console.log(foo(10));
|
@ -1,3 +0,0 @@
|
||||
var bar = require('./bar.js');
|
||||
|
||||
console.log('bar(5)=' + bar(5));
|
@ -1,813 +0,0 @@
|
||||
var require = function (file, cwd) {
|
||||
var resolved = require.resolve(file, cwd || '/');
|
||||
var mod = require.modules[resolved];
|
||||
if (!mod) throw new Error(
|
||||
'Failed to resolve module ' + file + ', tried ' + resolved
|
||||
);
|
||||
var res = mod._cached ? mod._cached : mod();
|
||||
return res;
|
||||
}
|
||||
|
||||
require.paths = [];
|
||||
require.modules = {};
|
||||
require.extensions = [".js",".coffee"];
|
||||
|
||||
require._core = {
|
||||
'assert': true,
|
||||
'events': true,
|
||||
'fs': true,
|
||||
'path': true,
|
||||
'vm': true
|
||||
};
|
||||
|
||||
require.resolve = (function () {
|
||||
return function (x, cwd) {
|
||||
if (!cwd) cwd = '/';
|
||||
|
||||
if (require._core[x]) return x;
|
||||
var path = require.modules.path();
|
||||
cwd = path.resolve('/', cwd);
|
||||
var y = cwd || '/';
|
||||
|
||||
if (x.match(/^(?:\.\.?\/|\/)/)) {
|
||||
var m = loadAsFileSync(path.resolve(y, x))
|
||||
|| loadAsDirectorySync(path.resolve(y, x));
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
var n = loadNodeModulesSync(x, y);
|
||||
if (n) return n;
|
||||
|
||||
throw new Error("Cannot find module '" + x + "'");
|
||||
|
||||
function loadAsFileSync (x) {
|
||||
if (require.modules[x]) {
|
||||
return x;
|
||||
}
|
||||
|
||||
for (var i = 0; i < require.extensions.length; i++) {
|
||||
var ext = require.extensions[i];
|
||||
if (require.modules[x + ext]) return x + ext;
|
||||
}
|
||||
}
|
||||
|
||||
function loadAsDirectorySync (x) {
|
||||
x = x.replace(/\/+$/, '');
|
||||
var pkgfile = x + '/package.json';
|
||||
if (require.modules[pkgfile]) {
|
||||
var pkg = require.modules[pkgfile]();
|
||||
var b = pkg.browserify;
|
||||
if (typeof b === 'object' && b.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, b.main));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (typeof b === 'string') {
|
||||
var m = loadAsFileSync(path.resolve(x, b));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (pkg.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, pkg.main));
|
||||
if (m) return m;
|
||||
}
|
||||
}
|
||||
|
||||
return loadAsFileSync(x + '/index');
|
||||
}
|
||||
|
||||
function loadNodeModulesSync (x, start) {
|
||||
var dirs = nodeModulesPathsSync(start);
|
||||
for (var i = 0; i < dirs.length; i++) {
|
||||
var dir = dirs[i];
|
||||
var m = loadAsFileSync(dir + '/' + x);
|
||||
if (m) return m;
|
||||
var n = loadAsDirectorySync(dir + '/' + x);
|
||||
if (n) return n;
|
||||
}
|
||||
|
||||
var m = loadAsFileSync(x);
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
function nodeModulesPathsSync (start) {
|
||||
var parts;
|
||||
if (start === '/') parts = [ '' ];
|
||||
else parts = path.normalize(start).split('/');
|
||||
|
||||
var dirs = [];
|
||||
for (var i = parts.length - 1; i >= 0; i--) {
|
||||
if (parts[i] === 'node_modules') continue;
|
||||
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
|
||||
dirs.push(dir);
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
require.alias = function (from, to) {
|
||||
var path = require.modules.path();
|
||||
var res = null;
|
||||
try {
|
||||
res = require.resolve(from + '/package.json', '/');
|
||||
}
|
||||
catch (err) {
|
||||
res = require.resolve(from, '/');
|
||||
}
|
||||
var basedir = path.dirname(res);
|
||||
|
||||
var keys = (Object.keys || function (obj) {
|
||||
var res = [];
|
||||
for (var key in obj) res.push(key)
|
||||
return res;
|
||||
})(require.modules);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
if (key.slice(0, basedir.length + 1) === basedir + '/') {
|
||||
var f = key.slice(basedir.length);
|
||||
require.modules[to + f] = require.modules[basedir + f];
|
||||
}
|
||||
else if (key === basedir) {
|
||||
require.modules[to] = require.modules[basedir];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require.define = function (filename, fn) {
|
||||
var dirname = require._core[filename]
|
||||
? ''
|
||||
: require.modules.path().dirname(filename)
|
||||
;
|
||||
|
||||
var require_ = function (file) {
|
||||
return require(file, dirname)
|
||||
};
|
||||
require_.resolve = function (name) {
|
||||
return require.resolve(name, dirname);
|
||||
};
|
||||
require_.modules = require.modules;
|
||||
require_.define = require.define;
|
||||
var module_ = { exports : {} };
|
||||
|
||||
require.modules[filename] = function () {
|
||||
require.modules[filename]._cached = module_.exports;
|
||||
fn.call(
|
||||
module_.exports,
|
||||
require_,
|
||||
module_,
|
||||
module_.exports,
|
||||
dirname,
|
||||
filename
|
||||
);
|
||||
require.modules[filename]._cached = module_.exports;
|
||||
return module_.exports;
|
||||
};
|
||||
};
|
||||
|
||||
if (typeof process === 'undefined') process = {};
|
||||
|
||||
if (!process.nextTick) process.nextTick = (function () {
|
||||
var queue = [];
|
||||
var canPost = typeof window !== 'undefined'
|
||||
&& window.postMessage && window.addEventListener
|
||||
;
|
||||
|
||||
if (canPost) {
|
||||
window.addEventListener('message', function (ev) {
|
||||
if (ev.source === window && ev.data === 'browserify-tick') {
|
||||
ev.stopPropagation();
|
||||
if (queue.length > 0) {
|
||||
var fn = queue.shift();
|
||||
fn();
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
return function (fn) {
|
||||
if (canPost) {
|
||||
queue.push(fn);
|
||||
window.postMessage('browserify-tick', '*');
|
||||
}
|
||||
else setTimeout(fn, 0);
|
||||
};
|
||||
})();
|
||||
|
||||
if (!process.title) process.title = 'browser';
|
||||
|
||||
if (!process.binding) process.binding = function (name) {
|
||||
if (name === 'evals') return require('vm')
|
||||
else throw new Error('No such module')
|
||||
};
|
||||
|
||||
if (!process.cwd) process.cwd = function () { return '.' };
|
||||
|
||||
require.define("path", function (require, module, exports, __dirname, __filename) {
|
||||
function filter (xs, fn) {
|
||||
var res = [];
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
if (fn(xs[i], i, xs)) res.push(xs[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// resolves . and .. elements in a path array with directory names there
|
||||
// must be no slashes, empty elements, or device names (c:\) in the array
|
||||
// (so also no leading and trailing slashes - it does not distinguish
|
||||
// relative and absolute paths)
|
||||
function normalizeArray(parts, allowAboveRoot) {
|
||||
// if the path tries to go above the root, `up` ends up > 0
|
||||
var up = 0;
|
||||
for (var i = parts.length; i >= 0; i--) {
|
||||
var last = parts[i];
|
||||
if (last == '.') {
|
||||
parts.splice(i, 1);
|
||||
} else if (last === '..') {
|
||||
parts.splice(i, 1);
|
||||
up++;
|
||||
} else if (up) {
|
||||
parts.splice(i, 1);
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
// if the path is allowed to go above the root, restore leading ..s
|
||||
if (allowAboveRoot) {
|
||||
for (; up--; up) {
|
||||
parts.unshift('..');
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
// Regex to split a filename into [*, dir, basename, ext]
|
||||
// posix version
|
||||
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
|
||||
|
||||
// path.resolve([from ...], to)
|
||||
// posix version
|
||||
exports.resolve = function() {
|
||||
var resolvedPath = '',
|
||||
resolvedAbsolute = false;
|
||||
|
||||
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
|
||||
var path = (i >= 0)
|
||||
? arguments[i]
|
||||
: process.cwd();
|
||||
|
||||
// Skip empty and invalid entries
|
||||
if (typeof path !== 'string' || !path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
resolvedPath = path + '/' + resolvedPath;
|
||||
resolvedAbsolute = path.charAt(0) === '/';
|
||||
}
|
||||
|
||||
// At this point the path should be resolved to a full absolute path, but
|
||||
// handle relative paths to be safe (might happen when process.cwd() fails)
|
||||
|
||||
// Normalize the path
|
||||
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
||||
return !!p;
|
||||
}), !resolvedAbsolute).join('/');
|
||||
|
||||
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
||||
};
|
||||
|
||||
// path.normalize(path)
|
||||
// posix version
|
||||
exports.normalize = function(path) {
|
||||
var isAbsolute = path.charAt(0) === '/',
|
||||
trailingSlash = path.slice(-1) === '/';
|
||||
|
||||
// Normalize the path
|
||||
path = normalizeArray(filter(path.split('/'), function(p) {
|
||||
return !!p;
|
||||
}), !isAbsolute).join('/');
|
||||
|
||||
if (!path && !isAbsolute) {
|
||||
path = '.';
|
||||
}
|
||||
if (path && trailingSlash) {
|
||||
path += '/';
|
||||
}
|
||||
|
||||
return (isAbsolute ? '/' : '') + path;
|
||||
};
|
||||
|
||||
|
||||
// posix version
|
||||
exports.join = function() {
|
||||
var paths = Array.prototype.slice.call(arguments, 0);
|
||||
return exports.normalize(filter(paths, function(p, index) {
|
||||
return p && typeof p === 'string';
|
||||
}).join('/'));
|
||||
};
|
||||
|
||||
|
||||
exports.dirname = function(path) {
|
||||
var dir = splitPathRe.exec(path)[1] || '';
|
||||
var isWindows = false;
|
||||
if (!dir) {
|
||||
// No dirname
|
||||
return '.';
|
||||
} else if (dir.length === 1 ||
|
||||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
|
||||
// It is just a slash or a drive letter with a slash
|
||||
return dir;
|
||||
} else {
|
||||
// It is a full dirname, strip trailing slash
|
||||
return dir.substring(0, dir.length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.basename = function(path, ext) {
|
||||
var f = splitPathRe.exec(path)[2] || '';
|
||||
// TODO: make this comparison case-insensitive on windows?
|
||||
if (ext && f.substr(-1 * ext.length) === ext) {
|
||||
f = f.substr(0, f.length - ext.length);
|
||||
}
|
||||
return f;
|
||||
};
|
||||
|
||||
|
||||
exports.extname = function(path) {
|
||||
return splitPathRe.exec(path)[3] || '';
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("http", function (require, module, exports, __dirname, __filename) {
|
||||
module.exports = require("http-browserify")
|
||||
});
|
||||
|
||||
require.define("/node_modules/http-browserify/package.json", function (require, module, exports, __dirname, __filename) {
|
||||
module.exports = {"main":"index.js","browserify":"index.js"}
|
||||
});
|
||||
|
||||
require.define("/node_modules/http-browserify/index.js", function (require, module, exports, __dirname, __filename) {
|
||||
var http = module.exports;
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Request = require('./lib/request');
|
||||
|
||||
http.request = function (params, cb) {
|
||||
if (!params) params = {};
|
||||
if (!params.host) params.host = window.location.host.split(':')[0];
|
||||
if (!params.port) params.port = window.location.port;
|
||||
|
||||
var req = new Request(new xhrHttp, params);
|
||||
if (cb) req.on('response', cb);
|
||||
return req;
|
||||
};
|
||||
|
||||
http.get = function (params, cb) {
|
||||
params.method = 'GET';
|
||||
var req = http.request(params, cb);
|
||||
req.end();
|
||||
return req;
|
||||
};
|
||||
|
||||
var xhrHttp = (function () {
|
||||
if (typeof window === 'undefined') {
|
||||
throw new Error('no window object present');
|
||||
}
|
||||
else if (window.XMLHttpRequest) {
|
||||
return window.XMLHttpRequest;
|
||||
}
|
||||
else if (window.ActiveXObject) {
|
||||
var axs = [
|
||||
'Msxml2.XMLHTTP.6.0',
|
||||
'Msxml2.XMLHTTP.3.0',
|
||||
'Microsoft.XMLHTTP'
|
||||
];
|
||||
for (var i = 0; i < axs.length; i++) {
|
||||
try {
|
||||
var ax = new(window.ActiveXObject)(axs[i]);
|
||||
return function () {
|
||||
if (ax) {
|
||||
var ax_ = ax;
|
||||
ax = null;
|
||||
return ax_;
|
||||
}
|
||||
else {
|
||||
return new(window.ActiveXObject)(axs[i]);
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
throw new Error('ajax not supported in this browser')
|
||||
}
|
||||
else {
|
||||
throw new Error('ajax not supported in this browser');
|
||||
}
|
||||
})();
|
||||
|
||||
});
|
||||
|
||||
require.define("events", function (require, module, exports, __dirname, __filename) {
|
||||
if (!process.EventEmitter) process.EventEmitter = function () {};
|
||||
|
||||
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
||||
var isArray = typeof Array.isArray === 'function'
|
||||
? Array.isArray
|
||||
: function (xs) {
|
||||
return Object.toString.call(xs) === '[object Array]'
|
||||
}
|
||||
;
|
||||
|
||||
// By default EventEmitters will print a warning if more than
|
||||
// 10 listeners are added to it. This is a useful default which
|
||||
// helps finding memory leaks.
|
||||
//
|
||||
// Obviously not all Emitters should be limited to 10. This function allows
|
||||
// that to be increased. Set to zero for unlimited.
|
||||
var defaultMaxListeners = 10;
|
||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
if (!this._events) this._events = {};
|
||||
this._events.maxListeners = n;
|
||||
};
|
||||
|
||||
|
||||
EventEmitter.prototype.emit = function(type) {
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (type === 'error') {
|
||||
if (!this._events || !this._events.error ||
|
||||
(isArray(this._events.error) && !this._events.error.length))
|
||||
{
|
||||
if (arguments[1] instanceof Error) {
|
||||
throw arguments[1]; // Unhandled 'error' event
|
||||
} else {
|
||||
throw new Error("Uncaught, unspecified 'error' event.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._events) return false;
|
||||
var handler = this._events[type];
|
||||
if (!handler) return false;
|
||||
|
||||
if (typeof handler == 'function') {
|
||||
switch (arguments.length) {
|
||||
// fast cases
|
||||
case 1:
|
||||
handler.call(this);
|
||||
break;
|
||||
case 2:
|
||||
handler.call(this, arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
handler.call(this, arguments[1], arguments[2]);
|
||||
break;
|
||||
// slower
|
||||
default:
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
handler.apply(this, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (isArray(handler)) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
var listeners = handler.slice();
|
||||
for (var i = 0, l = listeners.length; i < l; i++) {
|
||||
listeners[i].apply(this, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// EventEmitter is defined in src/node_events.cc
|
||||
// EventEmitter.prototype.emit() is also defined there.
|
||||
EventEmitter.prototype.addListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('addListener only takes instances of Function');
|
||||
}
|
||||
|
||||
if (!this._events) this._events = {};
|
||||
|
||||
// To avoid recursion in the case that type == "newListeners"! Before
|
||||
// adding it to the listeners, first emit "newListeners".
|
||||
this.emit('newListener', type, listener);
|
||||
|
||||
if (!this._events[type]) {
|
||||
// Optimize the case of one listener. Don't need the extra array object.
|
||||
this._events[type] = listener;
|
||||
} else if (isArray(this._events[type])) {
|
||||
|
||||
// Check for listener leak
|
||||
if (!this._events[type].warned) {
|
||||
var m;
|
||||
if (this._events.maxListeners !== undefined) {
|
||||
m = this._events.maxListeners;
|
||||
} else {
|
||||
m = defaultMaxListeners;
|
||||
}
|
||||
|
||||
if (m && m > 0 && this._events[type].length > m) {
|
||||
this._events[type].warned = true;
|
||||
console.error('(node) warning: possible EventEmitter memory ' +
|
||||
'leak detected. %d listeners added. ' +
|
||||
'Use emitter.setMaxListeners() to increase limit.',
|
||||
this._events[type].length);
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
|
||||
// If we've already got an array, just append.
|
||||
this._events[type].push(listener);
|
||||
} else {
|
||||
// Adding the second element, need to change to array.
|
||||
this._events[type] = [this._events[type], listener];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||
|
||||
EventEmitter.prototype.once = function(type, listener) {
|
||||
var self = this;
|
||||
self.on(type, function g() {
|
||||
self.removeListener(type, g);
|
||||
listener.apply(this, arguments);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('removeListener only takes instances of Function');
|
||||
}
|
||||
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (!this._events || !this._events[type]) return this;
|
||||
|
||||
var list = this._events[type];
|
||||
|
||||
if (isArray(list)) {
|
||||
var i = list.indexOf(listener);
|
||||
if (i < 0) return this;
|
||||
list.splice(i, 1);
|
||||
if (list.length == 0)
|
||||
delete this._events[type];
|
||||
} else if (this._events[type] === listener) {
|
||||
delete this._events[type];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (type && this._events && this._events[type]) this._events[type] = null;
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listeners = function(type) {
|
||||
if (!this._events) this._events = {};
|
||||
if (!this._events[type]) this._events[type] = [];
|
||||
if (!isArray(this._events[type])) {
|
||||
this._events[type] = [this._events[type]];
|
||||
}
|
||||
return this._events[type];
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("/node_modules/http-browserify/lib/request.js", function (require, module, exports, __dirname, __filename) {
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Response = require('./response');
|
||||
|
||||
var Request = module.exports = function (xhr, params) {
|
||||
var self = this;
|
||||
self.xhr = xhr;
|
||||
self.body = '';
|
||||
|
||||
var uri = params.host + ':' + params.port + (params.path || '/');
|
||||
|
||||
xhr.open(
|
||||
params.method || 'GET',
|
||||
(params.scheme || 'http') + '://' + uri,
|
||||
true
|
||||
);
|
||||
|
||||
if (params.headers) {
|
||||
Object.keys(params.headers).forEach(function (key) {
|
||||
if (!self.isSafeRequestHeader(key)) return;
|
||||
var value = params.headers[key];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(function (v) {
|
||||
xhr.setRequestHeader(key, v);
|
||||
});
|
||||
}
|
||||
else xhr.setRequestHeader(key, value)
|
||||
});
|
||||
}
|
||||
|
||||
var res = new Response;
|
||||
res.on('ready', function () {
|
||||
self.emit('response', res);
|
||||
});
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
res.handle(xhr);
|
||||
};
|
||||
};
|
||||
|
||||
Request.prototype = new EventEmitter;
|
||||
|
||||
Request.prototype.setHeader = function (key, value) {
|
||||
if ((Array.isArray && Array.isArray(value))
|
||||
|| value instanceof Array) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
this.xhr.setRequestHeader(key, value[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.xhr.setRequestHeader(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
Request.prototype.write = function (s) {
|
||||
this.body += s;
|
||||
};
|
||||
|
||||
Request.prototype.end = function (s) {
|
||||
if (s !== undefined) this.write(s);
|
||||
this.xhr.send(this.body);
|
||||
};
|
||||
|
||||
// Taken from http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html
|
||||
Request.unsafeHeaders = [
|
||||
"accept-charset",
|
||||
"accept-encoding",
|
||||
"access-control-request-headers",
|
||||
"access-control-request-method",
|
||||
"connection",
|
||||
"content-length",
|
||||
"cookie",
|
||||
"cookie2",
|
||||
"content-transfer-encoding",
|
||||
"date",
|
||||
"expect",
|
||||
"host",
|
||||
"keep-alive",
|
||||
"origin",
|
||||
"referer",
|
||||
"te",
|
||||
"trailer",
|
||||
"transfer-encoding",
|
||||
"upgrade",
|
||||
"user-agent",
|
||||
"via"
|
||||
];
|
||||
|
||||
Request.prototype.isSafeRequestHeader = function (headerName) {
|
||||
if (!headerName) return false;
|
||||
return (Request.unsafeHeaders.indexOf(headerName.toLowerCase()) === -1)
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("/node_modules/http-browserify/lib/response.js", function (require, module, exports, __dirname, __filename) {
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var Response = module.exports = function (res) {
|
||||
this.offset = 0;
|
||||
};
|
||||
|
||||
Response.prototype = new EventEmitter;
|
||||
|
||||
var capable = {
|
||||
streaming : true,
|
||||
status2 : true
|
||||
};
|
||||
|
||||
function parseHeaders (res) {
|
||||
var lines = res.getAllResponseHeaders().split(/\r?\n/);
|
||||
var headers = {};
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i];
|
||||
if (line === '') continue;
|
||||
|
||||
var m = line.match(/^([^:]+):\s*(.*)/);
|
||||
if (m) {
|
||||
var key = m[1].toLowerCase(), value = m[2];
|
||||
|
||||
if (headers[key] !== undefined) {
|
||||
if ((Array.isArray && Array.isArray(headers[key]))
|
||||
|| headers[key] instanceof Array) {
|
||||
headers[key].push(value);
|
||||
}
|
||||
else {
|
||||
headers[key] = [ headers[key], value ];
|
||||
}
|
||||
}
|
||||
else {
|
||||
headers[key] = value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
headers[line] = true;
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
Response.prototype.getHeader = function (key) {
|
||||
return this.headers[key.toLowerCase()];
|
||||
};
|
||||
|
||||
Response.prototype.handle = function (res) {
|
||||
if (res.readyState === 2 && capable.status2) {
|
||||
try {
|
||||
this.statusCode = res.status;
|
||||
this.headers = parseHeaders(res);
|
||||
}
|
||||
catch (err) {
|
||||
capable.status2 = false;
|
||||
}
|
||||
|
||||
if (capable.status2) {
|
||||
this.emit('ready');
|
||||
}
|
||||
}
|
||||
else if (capable.streaming && res.readyState === 3) {
|
||||
try {
|
||||
if (!this.statusCode) {
|
||||
this.statusCode = res.status;
|
||||
this.headers = parseHeaders(res);
|
||||
this.emit('ready');
|
||||
}
|
||||
}
|
||||
catch (err) {}
|
||||
|
||||
try {
|
||||
this.write(res);
|
||||
}
|
||||
catch (err) {
|
||||
capable.streaming = false;
|
||||
}
|
||||
}
|
||||
else if (res.readyState === 4) {
|
||||
if (!this.statusCode) {
|
||||
this.statusCode = res.status;
|
||||
this.emit('ready');
|
||||
}
|
||||
this.write(res);
|
||||
|
||||
if (res.error) {
|
||||
this.emit('error', res.responseText);
|
||||
}
|
||||
else this.emit('end');
|
||||
}
|
||||
};
|
||||
|
||||
Response.prototype.write = function (res) {
|
||||
if (res.responseText.length > this.offset) {
|
||||
this.emit('data', res.responseText.slice(this.offset));
|
||||
this.offset = res.responseText.length;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
require.define("/entry.js", function (require, module, exports, __dirname, __filename) {
|
||||
var http = require('http');
|
||||
|
||||
$(function () {
|
||||
var opts = {
|
||||
host : window.location.hostname,
|
||||
port : window.location.port,
|
||||
path : '/count'
|
||||
};
|
||||
|
||||
http.get(opts, function (res) {
|
||||
res.on('data', function (buf) {
|
||||
$('<div>')
|
||||
.text(buf)
|
||||
.appendTo($('#count'))
|
||||
;
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
$('<div>')
|
||||
.text('__END__')
|
||||
.appendTo($('#count'))
|
||||
;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
require("/entry.js");
|
@ -1,25 +0,0 @@
|
||||
var http = require('http');
|
||||
|
||||
$(function () {
|
||||
var opts = {
|
||||
host : window.location.hostname,
|
||||
port : window.location.port,
|
||||
path : '/count'
|
||||
};
|
||||
|
||||
http.get(opts, function (res) {
|
||||
res.on('data', function (buf) {
|
||||
$('<div>')
|
||||
.text(buf)
|
||||
.appendTo($('#count'))
|
||||
;
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
$('<div>')
|
||||
.text('__END__')
|
||||
.appendTo($('#count'))
|
||||
;
|
||||
});
|
||||
});
|
||||
});
|
@ -1,9 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="/bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="count"></div>
|
||||
</body>
|
||||
</html>
|
@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
var http = require('http');
|
||||
var ecstatic = require('ecstatic')(__dirname);
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
if (req.url === '/count') {
|
||||
res.setHeader('content-type', 'multipart/octet-stream');
|
||||
|
||||
var n = 10;
|
||||
var iv = setInterval(function () {
|
||||
res.write(n + '\r\n');
|
||||
|
||||
if (--n === 0) {
|
||||
clearInterval(iv);
|
||||
res.end();
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
else ecstatic(req, res)
|
||||
});
|
||||
|
||||
server.listen(8001);
|
||||
console.log([
|
||||
'Listening on :8001',
|
||||
'',
|
||||
'To compile the build, do:',
|
||||
' browserify entry.js -o bundle.js'
|
||||
].join('\n'));
|
@ -1,202 +0,0 @@
|
||||
var path = require('path');
|
||||
var coffee = require('coffee-script');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var wrap = require('./lib/wrap');
|
||||
var watch = require('./lib/watch');
|
||||
|
||||
function idFromPath (path) {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
function isAbsolute (pathOrId) {
|
||||
return path.normalize(pathOrId) === path.normalize(path.resolve(pathOrId));
|
||||
}
|
||||
|
||||
function needsNodeModulesPrepended (id) {
|
||||
return !/^[.\/]/.test(id) && !isAbsolute(id);
|
||||
}
|
||||
|
||||
var exports = module.exports = function (entryFile, opts) {
|
||||
if (!opts) opts = {};
|
||||
|
||||
if (Array.isArray(entryFile)) {
|
||||
if (Array.isArray(opts.entry)) {
|
||||
opts.entry.unshift.apply(opts.entry, entryFile);
|
||||
}
|
||||
else if (opts.entry) {
|
||||
opts.entry = entryFile.concat(opts.entry);
|
||||
}
|
||||
else {
|
||||
opts.entry = entryFile;
|
||||
}
|
||||
}
|
||||
else if (typeof entryFile === 'object') {
|
||||
opts = entryFile;
|
||||
}
|
||||
else if (typeof entryFile === 'string') {
|
||||
if (Array.isArray(opts.entry)) {
|
||||
opts.entry.unshift(entryFile);
|
||||
}
|
||||
else if (opts.entry) {
|
||||
opts.entry = [ opts.entry, entryFile ];
|
||||
}
|
||||
else {
|
||||
opts.entry = entryFile;
|
||||
}
|
||||
}
|
||||
|
||||
var opts_ = {
|
||||
cache : opts.cache,
|
||||
debug : opts.debug,
|
||||
exports : opts.exports,
|
||||
};
|
||||
var w = wrap(opts_);
|
||||
w.register('.coffee', function (body, file) {
|
||||
try {
|
||||
var res = coffee.compile(body, { filename : file });
|
||||
}
|
||||
catch (err) {
|
||||
w.emit('syntaxError', err);
|
||||
}
|
||||
return res;
|
||||
});
|
||||
w.register('.json', function (body, file) {
|
||||
return 'module.exports = ' + body + ';\n';
|
||||
});
|
||||
|
||||
var listening = false;
|
||||
w._cache = null;
|
||||
|
||||
var self = function (req, res, next) {
|
||||
if (!listening && req.connection && req.connection.server) {
|
||||
req.connection.server.on('close', function () {
|
||||
self.end();
|
||||
});
|
||||
}
|
||||
listening = true;
|
||||
|
||||
if (req.url.split('?')[0] === (opts.mount || '/browserify.js')) {
|
||||
if (!w._cache) self.bundle();
|
||||
res.statusCode = 200;
|
||||
res.setHeader('last-modified', self.modified.toString());
|
||||
res.setHeader('content-type', 'text/javascript');
|
||||
res.end(w._cache);
|
||||
}
|
||||
else next()
|
||||
};
|
||||
|
||||
if (opts.watch) watch(w, opts.watch);
|
||||
|
||||
if (opts.filter) {
|
||||
w.register('post', function (body) {
|
||||
return opts.filter(body);
|
||||
});
|
||||
}
|
||||
|
||||
w.ignore(opts.ignore || []);
|
||||
|
||||
if (opts.require) {
|
||||
if (Array.isArray(opts.require)) {
|
||||
opts.require.forEach(function (r) {
|
||||
r = idFromPath(r);
|
||||
|
||||
var params = {};
|
||||
if (needsNodeModulesPrepended(r)) {
|
||||
params.target = '/node_modules/' + r + '/index.js';
|
||||
}
|
||||
w.require(r, params);
|
||||
});
|
||||
}
|
||||
else if (typeof opts.require === 'object') {
|
||||
Object.keys(opts.require).forEach(function (key) {
|
||||
opts.require[key] = idFromPath(opts.require[key]);
|
||||
|
||||
var params = {};
|
||||
if (needsNodeModulesPrepended(opts.require[key])) {
|
||||
params.target = '/node_modules/'
|
||||
+ opts.require[key] + '/index.js'
|
||||
;
|
||||
}
|
||||
w.require(opts.require[key], params);
|
||||
w.alias(key, opts.require[key]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
opts.require = idFromPath(opts.require);
|
||||
|
||||
var params = {};
|
||||
if (needsNodeModulesPrepended(opts.require)) {
|
||||
params.target = '/node_modules/'
|
||||
+ opts.require + '/index.js'
|
||||
;
|
||||
}
|
||||
w.require(opts.require, params);
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.entry) {
|
||||
if (Array.isArray(opts.entry)) {
|
||||
opts.entry.forEach(function (e) {
|
||||
w.addEntry(e);
|
||||
});
|
||||
}
|
||||
else {
|
||||
w.addEntry(opts.entry);
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(w).forEach(function (key) {
|
||||
Object.defineProperty(self, key, {
|
||||
set : function (value) { w[key] = value },
|
||||
get : function () { return w[key] }
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(Object.getPrototypeOf(w)).forEach(function (key) {
|
||||
self[key] = function () {
|
||||
var s = w[key].apply(self, arguments)
|
||||
if (s === self) { w._cache = null }
|
||||
return s;
|
||||
};
|
||||
});
|
||||
|
||||
Object.keys(EventEmitter.prototype).forEach(function (key) {
|
||||
if (typeof w[key] === 'function' && w[key].bind) {
|
||||
self[key] = w[key].bind(w);
|
||||
}
|
||||
else {
|
||||
self[key] = w[key];
|
||||
}
|
||||
});
|
||||
|
||||
var firstBundle = true;
|
||||
self.modified = new Date;
|
||||
|
||||
self.bundle = function () {
|
||||
if (w._cache) return w._cache;
|
||||
|
||||
var src = w.bundle.apply(w, arguments);
|
||||
self.ok = Object.keys(w.errors).length === 0;
|
||||
|
||||
if (!firstBundle) {
|
||||
self.modified = new Date;
|
||||
}
|
||||
firstBundle = false;
|
||||
|
||||
w._cache = src;
|
||||
return src;
|
||||
};
|
||||
|
||||
self.end = function () {
|
||||
Object.keys(w.watches || {}).forEach(function (file) {
|
||||
w.watches[file].close();
|
||||
});
|
||||
};
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
exports.bundle = function (opts) {
|
||||
return exports(opts).bundle();
|
||||
};
|
@ -1,75 +0,0 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var exists = fs.exists || path.exists;
|
||||
|
||||
module.exports = function (w, opts) {
|
||||
if (!w.watches) w.watches = [];
|
||||
w.register(reg.bind(null, w, opts));
|
||||
};
|
||||
|
||||
function reg (w, opts, body, file) {
|
||||
// if already being watched
|
||||
if (w.watches[file]) return body;
|
||||
|
||||
var type = w.files[file] ? 'files' : 'entries';
|
||||
|
||||
var watch = function () {
|
||||
if (w.files[file] && w.files[file].synthetic) return;
|
||||
|
||||
if (typeof opts === 'object') {
|
||||
w.watches[file] = fs.watch(file, opts, watcher);
|
||||
}
|
||||
else {
|
||||
w.watches[file] = fs.watch(file, watcher);
|
||||
}
|
||||
};
|
||||
var pending = null;
|
||||
var bundle = function () {
|
||||
if (pending) return;
|
||||
pending = setTimeout(function () {
|
||||
pending = null;
|
||||
// modified
|
||||
if (w[type][file]) {
|
||||
w.reload(file);
|
||||
}
|
||||
else if (type === 'entries') {
|
||||
w.addEntry(file);
|
||||
}
|
||||
else if (type === 'files') {
|
||||
w.require(file);
|
||||
}
|
||||
|
||||
w._cache = null;
|
||||
w.emit('bundle');
|
||||
}, 100);
|
||||
};
|
||||
|
||||
var watcher = function (event, filename) {
|
||||
exists(file, function (ex) {
|
||||
if (!ex) {
|
||||
// deleted
|
||||
if (w.files[file]) {
|
||||
delete w.files[file];
|
||||
}
|
||||
else if (w.entries[file] !== undefined) {
|
||||
w.appends.splice(w.entries[file], 1);
|
||||
}
|
||||
|
||||
w._cache = null;
|
||||
}
|
||||
else if (event === 'change') {
|
||||
bundle();
|
||||
}
|
||||
else if (event === 'rename') {
|
||||
w.watches[file].close();
|
||||
process.nextTick(watch);
|
||||
bundle();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
w.watches[file] = true;
|
||||
process.nextTick(watch);
|
||||
|
||||
return body;
|
||||
}
|
@ -1,580 +0,0 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var detective = require('detective');
|
||||
var deputy = require('deputy');
|
||||
var resolve = require('resolve');
|
||||
|
||||
var wrappers = require('./wrappers');
|
||||
var commondir = require('commondir');
|
||||
var nub = require('nub');
|
||||
var checkSyntax = require('syntax-error');
|
||||
|
||||
var existsSync = fs.existsSync || path.existsSync;
|
||||
var sep = path.sep || (process.platform === 'win32' ? '\\' : '/');
|
||||
|
||||
module.exports = function (opts) {
|
||||
return new Wrap(opts);
|
||||
};
|
||||
function idFromPath (path) {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
function Wrap (opts) {
|
||||
var home = process.env.HOME || process.env.USERPROFILE;
|
||||
if (opts.cache === undefined && home !== undefined) {
|
||||
opts.cache = true;
|
||||
}
|
||||
|
||||
if (opts.cache) {
|
||||
if (typeof opts.cache === 'boolean') {
|
||||
var file = home + '/.config/browserify/cache.json';
|
||||
this.detective = deputy(file);
|
||||
}
|
||||
else {
|
||||
this.detective = deputy(opts.cache);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.detective = detective;
|
||||
}
|
||||
|
||||
this.exports = opts.exports;
|
||||
|
||||
this.files = {};
|
||||
this.filters = [];
|
||||
this.pathFilters = [];
|
||||
this.postFilters = [];
|
||||
this.preFilters = [];
|
||||
this.aliases = {};
|
||||
this._checkedPackages = {};
|
||||
this.errors = {};
|
||||
|
||||
this.ignoring = {};
|
||||
this.extensions = [ '.js' ];
|
||||
|
||||
this.prepends = [ wrappers.prelude, wrappers.process ];
|
||||
this.appends = []
|
||||
this.entries = {};
|
||||
this.debug = opts.debug;
|
||||
|
||||
this.require('path');
|
||||
this.require('__browserify_process');
|
||||
}
|
||||
|
||||
function resolveMod(from, to){
|
||||
// not a real directory on the filesystem; just using the path
|
||||
// module to get rid of the filename.
|
||||
var targetDir = path.dirname(from);
|
||||
// not a real filename; just using the path module to deal with
|
||||
// relative paths.
|
||||
var reqFilename = path.resolve(targetDir, to);
|
||||
// get rid of drive letter on Windows; replace it with '/'
|
||||
var reqFilenameWithoutDriveLetter = /^[a-zA-Z]:\\/.test(reqFilename) ?
|
||||
'/' + reqFilename.substring(3) : reqFilename;
|
||||
|
||||
return reqFilenameWithoutDriveLetter;
|
||||
}
|
||||
|
||||
util.inherits(Wrap, EventEmitter);
|
||||
|
||||
Wrap.prototype.prepend = function (src) {
|
||||
this.prepends.unshift(src);
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.append = function (src) {
|
||||
this.appends.push(src);
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.ignore = function (files) {
|
||||
if (!files) files = [];
|
||||
if (!Array.isArray(files)) files = [ files ];
|
||||
|
||||
this.ignoring = files.reduce(function (acc,x) {
|
||||
acc[x] = true;
|
||||
return acc;
|
||||
}, this.ignoring);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.use = function (fn) {
|
||||
fn(this, this);
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.register = function (ext, fn) {
|
||||
if (typeof ext === 'object') {
|
||||
fn = ext.wrapper;
|
||||
ext = ext.extension;
|
||||
}
|
||||
|
||||
if (ext === 'post') {
|
||||
this.postFilters.push(fn);
|
||||
}
|
||||
else if (ext === 'pre') {
|
||||
this.preFilters.push(fn);
|
||||
}
|
||||
else if (ext === 'path') {
|
||||
this.pathFilters.push(fn);
|
||||
}
|
||||
else if (fn) {
|
||||
this.extensions.push(ext);
|
||||
this.filters.push(function (body, file) {
|
||||
if (file.slice(-ext.length) === ext) {
|
||||
return fn.call(this, body, file);
|
||||
}
|
||||
else return body;
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.filters.push(ext);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.reload = function (file) {
|
||||
var self = this;
|
||||
delete self.errors[file];
|
||||
|
||||
if (self.files[file]) {
|
||||
var f = self.files[file];
|
||||
f.body = undefined;
|
||||
delete self.files[file];
|
||||
|
||||
self.require(file, f);
|
||||
}
|
||||
else if (self.entries[file]) {
|
||||
var e = self.entries[file];
|
||||
e.body = undefined;
|
||||
delete self.entries[file];
|
||||
|
||||
self.addEntry(file, e);
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
Wrap.prototype.readFile = function (file) {
|
||||
var self = this;
|
||||
|
||||
self.pathFilters.forEach(function (fn) {
|
||||
file = fn.call(self, file);
|
||||
});
|
||||
|
||||
var body = fs.readFileSync(file, 'utf8').replace(/^#![^\n]*\n/, '');
|
||||
|
||||
self.filters.forEach(function (fn) {
|
||||
body = fn.call(self, body, file);
|
||||
});
|
||||
|
||||
var err = checkSyntax(body, file);
|
||||
if (err) {
|
||||
self.errors[file] = err;
|
||||
|
||||
process.nextTick(function () {
|
||||
self.emit('syntaxError', err);
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
delete self.errors[file];
|
||||
}
|
||||
|
||||
return body;
|
||||
};
|
||||
|
||||
Wrap.prototype.alias = function (to, from) {
|
||||
this.aliases[to] = from;
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.addEntry = function (file_, opts) {
|
||||
var self = this;
|
||||
if (!opts) opts = {};
|
||||
var file = path.resolve(opts.dirname || process.cwd(), file_);
|
||||
|
||||
var entry = this.entries[file] = {};
|
||||
// entry must be set before readFile for the watch
|
||||
var body = entry.body = opts.body || self.readFile(file);
|
||||
if (body === undefined) return self;
|
||||
|
||||
if (opts.target) entry.target = opts.target;
|
||||
|
||||
try {
|
||||
var required = self.detective.find(body);
|
||||
}
|
||||
catch (err) {
|
||||
process.nextTick(function () {
|
||||
err.message = 'Error while loading entry file '
|
||||
+ JSON.stringify(file)
|
||||
+ ': ' + err.message
|
||||
;
|
||||
self.emit('syntaxError', err);
|
||||
});
|
||||
return self;
|
||||
}
|
||||
|
||||
if (required.expressions.length) {
|
||||
console.error('Expressions in require() statements:');
|
||||
required.expressions.forEach(function (ex) {
|
||||
console.error(' require(' + ex + ')');
|
||||
});
|
||||
}
|
||||
|
||||
var dirname = path.dirname(file);
|
||||
|
||||
required.strings.forEach(function (req) {
|
||||
var params = {
|
||||
dirname : dirname,
|
||||
fromFile : file,
|
||||
};
|
||||
if (opts.target && /^[.\/]/.test(req)) {
|
||||
params.target = resolveMod(opts.target, req);
|
||||
}
|
||||
self.require(req, params);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.bundle = function () {
|
||||
var self = this;
|
||||
|
||||
for (var i = 0; i < self.prepends.length; i++) {
|
||||
var p = self.prepends[i];
|
||||
if (p === wrappers.prelude) {
|
||||
self.prepends[i] = p.replace(/\$extensions/, function () {
|
||||
return JSON.stringify(self.extensions);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.preFilters.forEach((function (fn) {
|
||||
fn.call(this, this);
|
||||
}).bind(this));
|
||||
|
||||
(function () {
|
||||
// hack to set -browserify module targets
|
||||
var nm = path.resolve(__dirname, '../node_modules');
|
||||
Object.keys(self.files).forEach(function (file) {
|
||||
if (file.substring(0, nm.length) !== nm) return;
|
||||
var relativeToNm = path.relative(nm, file);
|
||||
var topDir = relativeToNm.split(sep)[0];
|
||||
if (!/-browserify$/.test(topDir)) return;
|
||||
self.files[file].target = path.join('/', 'node_modules', relativeToNm);
|
||||
});
|
||||
})();
|
||||
|
||||
var basedir = (function () {
|
||||
var required = Object.keys(self.files)
|
||||
.filter(function (x) {
|
||||
return !self.files[x].target;
|
||||
})
|
||||
;
|
||||
var entries = Object.keys(self.entries)
|
||||
.filter(function (x) { return !self.entries[x].target })
|
||||
;
|
||||
var files = required.concat(entries)
|
||||
.map(function (x) { return path.dirname(x) })
|
||||
;
|
||||
if (files.length === 0) return '';
|
||||
|
||||
var dir = commondir(files) + '/';
|
||||
return path.normalize(dir.replace(/\/node_modules\/$/, '/'));
|
||||
})();
|
||||
|
||||
var removeLeading = function (s) {
|
||||
if (s.slice(0, basedir.length) === basedir) {
|
||||
return s.slice(basedir.length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
var src = []
|
||||
.concat(this.prepends)
|
||||
.concat(Object.keys(self.files).map(function (file) {
|
||||
var s = self.files[file];
|
||||
var target = s.target || removeLeading(file);
|
||||
|
||||
if (self.ignoring[target]) return '';
|
||||
|
||||
return self.wrap(idFromPath(target), s.body)
|
||||
}))
|
||||
.concat(Object.keys(self.aliases).map(function (to) {
|
||||
var from = self.aliases[to];
|
||||
if (!to.match(/^(\.\.?)?\//)) {
|
||||
to = '/node_modules/' + to;
|
||||
}
|
||||
|
||||
return wrappers.alias
|
||||
.replace(/\$from/, function () {
|
||||
return JSON.stringify(from);
|
||||
})
|
||||
.replace(/\$to/, function () {
|
||||
return JSON.stringify(to);
|
||||
})
|
||||
;
|
||||
}))
|
||||
.concat(Object.keys(self.entries).map(function (file) {
|
||||
var s = self.entries[file];
|
||||
var target = s.target || removeLeading(file);
|
||||
return self.wrapEntry(idFromPath(target), s.body);
|
||||
}))
|
||||
.concat(this.appends)
|
||||
.join('\n')
|
||||
;
|
||||
|
||||
if (!self.exports) {
|
||||
self.exports = Object.keys(self.entries).length ? [] : [ 'require' ];
|
||||
}
|
||||
if (self.exports === true) self.exports = [ 'require', 'process' ];
|
||||
if (!Array.isArray(self.exports)) self.exports = [ self.exports ];
|
||||
|
||||
if (self.exports.indexOf('process') >= 0
|
||||
&& self.exports.indexOf('require') >= 0) {
|
||||
src += 'var process = require("__browserify_process");\n'
|
||||
}
|
||||
else if (self.exports.indexOf('require') >= 0) {
|
||||
// nop
|
||||
}
|
||||
else if (self.exports.indexOf('process') >= 0) {
|
||||
src = 'var process = (function(){'
|
||||
+ src
|
||||
+ ';return require("__browserify_process")'
|
||||
+ '})();\n'
|
||||
;
|
||||
}
|
||||
else {
|
||||
src = '(function(){' + src + '})();\n'
|
||||
}
|
||||
|
||||
this.postFilters.forEach((function (fn) {
|
||||
src = fn.call(this, src);
|
||||
}).bind(this));
|
||||
|
||||
return src;
|
||||
};
|
||||
|
||||
Wrap.prototype.wrap = function (target, body) {
|
||||
var self = this;
|
||||
return (self.debug ? wrappers.body_debug : wrappers.body)
|
||||
.replace(/\$__filename/g, function () {
|
||||
return JSON.stringify(target);
|
||||
})
|
||||
.replace(/\$body/, function () {
|
||||
return self.debug
|
||||
? JSON.stringify(body + '\n//@ sourceURL=' + target)
|
||||
: body
|
||||
;
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
Wrap.prototype.wrapEntry = function (target, body) {
|
||||
var self = this;
|
||||
return (self.debug ? wrappers.entry_debug : wrappers.entry)
|
||||
.replace(/\$__filename/g, function () {
|
||||
return JSON.stringify(target)
|
||||
})
|
||||
.replace(/\$body/, function () {
|
||||
return self.debug
|
||||
? JSON.stringify(body + '\n//@ sourceURL=' + target)
|
||||
: body
|
||||
;
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
Wrap.prototype.include = function (file, target, body, root) {
|
||||
var synthetic = !file;
|
||||
if (!file) file = Math.floor(Math.random() * Math.pow(2,32)).toString(16);
|
||||
|
||||
this.files[file] = {
|
||||
body : body,
|
||||
target : target,
|
||||
synthetic : synthetic,
|
||||
root : root
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
||||
Wrap.prototype.require = function (mfile, opts) {
|
||||
var self = this;
|
||||
if (!opts) opts = {};
|
||||
if (!opts.dirname) opts.dirname = process.cwd();
|
||||
|
||||
if (typeof mfile === 'object') {
|
||||
throw new Error('require maps no longer supported');
|
||||
}
|
||||
|
||||
if (self.has(mfile)) return self;
|
||||
if (opts.target && self.has(opts.target)) return self;
|
||||
|
||||
if (self.ignoring[mfile]) return self;
|
||||
if (self.aliases[mfile]) return self;
|
||||
|
||||
function moduleError (msg) {
|
||||
return new Error(msg + ': ' + JSON.stringify(mfile)
|
||||
+ ' from directory ' + JSON.stringify(opts.dirname)
|
||||
+ (opts.fromFile ? ' while processing file ' + opts.fromFile : '')
|
||||
);
|
||||
}
|
||||
|
||||
var pkg = {};
|
||||
if (mfile === '__browserify_process' || resolve.isCore(mfile)) {
|
||||
opts.file = path.resolve(__dirname, '../builtins/' + mfile + '.js');
|
||||
opts.target = opts.target || mfile;
|
||||
|
||||
if (!existsSync(opts.file)) {
|
||||
try {
|
||||
require.resolve(mfile + '-browserify');
|
||||
opts.body = 'module.exports = require('
|
||||
+ JSON.stringify(mfile + '-browserify')
|
||||
+ ')';
|
||||
}
|
||||
catch (err) {
|
||||
throw moduleError('No wrapper for core module');
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (self.has(mfile)) {
|
||||
// package has already been included in some fashion, no need to resolve
|
||||
return self;
|
||||
}
|
||||
else if (opts.body) {
|
||||
opts.file = mfile;
|
||||
}
|
||||
else if (!opts.file) {
|
||||
try {
|
||||
var normPath
|
||||
= path.normalize(path.resolve(mfile)) === path.normalize(mfile)
|
||||
? path.normalize(mfile) : mfile
|
||||
;
|
||||
opts.file = self.resolver(normPath, opts.dirname);
|
||||
}
|
||||
catch (err) {
|
||||
throw moduleError('Cannot find module');
|
||||
}
|
||||
}
|
||||
|
||||
if (self.has(opts.file)) return self;
|
||||
|
||||
var dirname = path.dirname(opts.file);
|
||||
var pkgfile = path.join(dirname, 'package.json');
|
||||
|
||||
if (!mfile.match(/^(\.\.?)?\//)) {
|
||||
try {
|
||||
pkgfile = resolve.sync(path.join(mfile, 'package.json'), {
|
||||
basedir : dirname
|
||||
});
|
||||
}
|
||||
catch (err) {}
|
||||
}
|
||||
|
||||
if (pkgfile && !self._checkedPackages[pkgfile]) {
|
||||
self._checkedPackages[pkgfile] = true;
|
||||
if (existsSync(pkgfile)) {
|
||||
var pkgBody = fs.readFileSync(pkgfile, 'utf8');
|
||||
try {
|
||||
var npmpkg = JSON.parse(pkgBody);
|
||||
if (npmpkg.main !== undefined) {
|
||||
pkg.main = npmpkg.main;
|
||||
}
|
||||
if (npmpkg.browserify !== undefined) {
|
||||
pkg.browserify = npmpkg.browserify;
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
// ignore broken package.jsons just like node
|
||||
}
|
||||
|
||||
self.files[pkgfile] = {
|
||||
body : 'module.exports = ' + JSON.stringify(pkg),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var entry = self.files[opts.file] = {
|
||||
target : opts.target
|
||||
};
|
||||
// entry must be set before readFile for the watch
|
||||
var body = entry.body = opts.body || self.readFile(opts.file);
|
||||
if (body === undefined) {
|
||||
delete self.files[opts.file];
|
||||
return self;
|
||||
}
|
||||
|
||||
try {
|
||||
var required = self.detective.find(body);
|
||||
}
|
||||
catch (err) {
|
||||
process.nextTick(function () {
|
||||
self.emit('syntaxError', err);
|
||||
});
|
||||
return self;
|
||||
}
|
||||
|
||||
if (pkg.browserify && pkg.browserify.require) {
|
||||
required.strings = required.strings.concat(
|
||||
pkg.browserify.require
|
||||
);
|
||||
}
|
||||
|
||||
if (required.expressions.length) {
|
||||
console.error('Expressions in require() statements:');
|
||||
required.expressions.forEach(function (ex) {
|
||||
console.error(' require(' + ex + ')');
|
||||
});
|
||||
}
|
||||
|
||||
nub(required.strings).forEach(function (req) {
|
||||
var params = {
|
||||
dirname : dirname,
|
||||
fromFile : opts.file,
|
||||
};
|
||||
if (opts.target && /^[.\/]/.test(req)) {
|
||||
params.target = idFromPath(resolveMod(opts.target, req));
|
||||
}
|
||||
self.require(req, params);
|
||||
});
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
function isPrefixOf (x, y) {
|
||||
return y.slice(0, x.length) === x;
|
||||
}
|
||||
|
||||
Wrap.prototype.has = function (file) {
|
||||
var self = this;
|
||||
if (self.files[file]) return true;
|
||||
|
||||
var res = Object.keys(self.files).some(function (key) {
|
||||
return self.files[key].target === file;
|
||||
});
|
||||
return res;
|
||||
};
|
||||
|
||||
Wrap.prototype.resolver = function (file, basedir) {
|
||||
return resolve.sync(file, {
|
||||
basedir : basedir,
|
||||
extensions : this.extensions,
|
||||
packageFilter : function (pkg) {
|
||||
var b = pkg.browserify;
|
||||
if (b) {
|
||||
if (typeof b === 'string') {
|
||||
pkg.main = b;
|
||||
}
|
||||
else if (typeof b === 'object' && b.main) {
|
||||
pkg.main = b.main;
|
||||
}
|
||||
}
|
||||
return pkg
|
||||
}
|
||||
});
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = fs.readdirSync(__dirname + '/../wrappers')
|
||||
.filter(function (file) { return file.match(/\.js$/) })
|
||||
.reduce(function (acc, file) {
|
||||
var name = file.replace(/\.js$/, '');
|
||||
acc[name] = fs.readFileSync(__dirname + '/../wrappers/' + file, 'utf8');
|
||||
return acc;
|
||||
}, {})
|
||||
;
|
@ -1 +0,0 @@
|
||||
../coffee-script/bin/cake
|
@ -1 +0,0 @@
|
||||
../coffee-script/bin/coffee
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user