initial commit
This commit is contained in:
22
node_modules/watchify/.github/workflows/ci.yml
generated
vendored
Normal file
22
node_modules/watchify/.github/workflows/ci.yml
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Tests
|
||||
strategy:
|
||||
matrix:
|
||||
node: [8.x, 10.x, 12.x, 14.x, 15.x]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Node.js ${{matrix.node}}
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: ${{matrix.node}}
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: npm test
|
||||
run: npm test
|
||||
8
node_modules/watchify/CHANGELOG.md
generated
vendored
Normal file
8
node_modules/watchify/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# watchify Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 4.0.0
|
||||
* Update dependencies.
|
||||
|
||||
This release drops support for Node.js versions older than 8.10, following the upgrade to `chokidar` 3.x.
|
||||
18
node_modules/watchify/LICENSE
generated
vendored
Normal file
18
node_modules/watchify/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
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.
|
||||
16
node_modules/watchify/bin/args.js
generated
vendored
Normal file
16
node_modules/watchify/bin/args.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var fromArgs = require('browserify/bin/args');
|
||||
var watchify = require('../');
|
||||
var defined = require('defined');
|
||||
var xtend = require('xtend');
|
||||
|
||||
module.exports = function (args) {
|
||||
var b = fromArgs(args, watchify.args);
|
||||
|
||||
var opts = {};
|
||||
var ignoreWatch = defined(b.argv['ignore-watch'], b.argv.iw);
|
||||
if (ignoreWatch) {
|
||||
opts.ignoreWatch = ignoreWatch;
|
||||
}
|
||||
|
||||
return watchify(b, xtend(opts, b.argv));
|
||||
};
|
||||
69
node_modules/watchify/bin/cmd.js
generated
vendored
Executable file
69
node_modules/watchify/bin/cmd.js
generated
vendored
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var path = require('path');
|
||||
var outpipe = require('outpipe');
|
||||
var through = require('through2');
|
||||
|
||||
var fromArgs = require('./args.js');
|
||||
var w = fromArgs(process.argv.slice(2));
|
||||
|
||||
var outfile = w.argv.o || w.argv.outfile;
|
||||
var verbose = w.argv.v || w.argv.verbose;
|
||||
|
||||
if (w.argv.version) {
|
||||
console.error('watchify v' + require('../package.json').version +
|
||||
' (in ' + path.resolve(__dirname, '..') + ')'
|
||||
);
|
||||
console.error('browserify v' + require('browserify/package.json').version +
|
||||
' (in ' + path.dirname(require.resolve('browserify')) + ')'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!outfile) {
|
||||
console.error('You MUST specify an outfile with -o.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var bytes, time;
|
||||
w.on('bytes', function (b) { bytes = b });
|
||||
w.on('time', function (t) { time = t });
|
||||
|
||||
w.on('update', bundle);
|
||||
bundle();
|
||||
|
||||
function bundle () {
|
||||
var didError = false;
|
||||
var writer = through();
|
||||
var wb = w.bundle();
|
||||
|
||||
w.pipeline.get('pack').once('readable', function() {
|
||||
if (!didError) {
|
||||
wb.pipe(writer);
|
||||
}
|
||||
});
|
||||
|
||||
wb.on('error', function (err) {
|
||||
console.error(String(err));
|
||||
if (!didError) {
|
||||
didError = true;
|
||||
writer.end('console.error(' + JSON.stringify(String(err)) + ');');
|
||||
}
|
||||
});
|
||||
|
||||
writer.once('readable', function() {
|
||||
var outStream = outpipe(outfile);
|
||||
outStream.on('error', function (err) {
|
||||
console.error(err);
|
||||
});
|
||||
outStream.on('exit', function () {
|
||||
if (verbose && !didError) {
|
||||
console.error(bytes + ' bytes written to ' + outfile
|
||||
+ ' (' + (time / 1000).toFixed(2) + ' seconds) at '
|
||||
+ new Date().toLocaleTimeString()
|
||||
);
|
||||
}
|
||||
});
|
||||
writer.pipe(outStream);
|
||||
});
|
||||
}
|
||||
2
node_modules/watchify/example/files/main.js
generated
vendored
Normal file
2
node_modules/watchify/example/files/main.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var one = require('./one');
|
||||
console.log(one(5));
|
||||
3
node_modules/watchify/example/files/one.js
generated
vendored
Normal file
3
node_modules/watchify/example/files/one.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var two = require('./two');
|
||||
|
||||
module.exports = function (x) { return x * two(x + 5) };
|
||||
1
node_modules/watchify/example/files/two.js
generated
vendored
Normal file
1
node_modules/watchify/example/files/two.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function (n) { return n * 11 };
|
||||
165
node_modules/watchify/index.js
generated
vendored
Normal file
165
node_modules/watchify/index.js
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
var through = require('through2');
|
||||
var path = require('path');
|
||||
var chokidar = require('chokidar');
|
||||
var xtend = require('xtend');
|
||||
var anymatch = require('anymatch');
|
||||
|
||||
module.exports = watchify;
|
||||
module.exports.args = {
|
||||
cache: {}, packageCache: {}
|
||||
};
|
||||
|
||||
function watchify (b, opts) {
|
||||
if (!opts) opts = {};
|
||||
var cache = b._options.cache;
|
||||
var pkgcache = b._options.packageCache;
|
||||
var delay = typeof opts.delay === 'number' ? opts.delay : 100;
|
||||
var changingDeps = {};
|
||||
var pending = false;
|
||||
var updating = false;
|
||||
|
||||
var wopts = {persistent: true};
|
||||
if (opts.ignoreWatch) {
|
||||
var ignored = opts.ignoreWatch !== true
|
||||
? opts.ignoreWatch
|
||||
: '**/node_modules/**';
|
||||
}
|
||||
if (opts.poll || typeof opts.poll === 'number') {
|
||||
wopts.usePolling = true;
|
||||
wopts.interval = opts.poll !== true
|
||||
? opts.poll
|
||||
: undefined;
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
b.on('reset', collect);
|
||||
collect();
|
||||
}
|
||||
|
||||
function collect () {
|
||||
b.pipeline.get('deps').push(through.obj(function(row, enc, next) {
|
||||
var file = row.expose ? b._expose[row.id] : row.file;
|
||||
cache[file] = {
|
||||
source: row.source,
|
||||
deps: xtend(row.deps)
|
||||
};
|
||||
this.push(row);
|
||||
next();
|
||||
}));
|
||||
}
|
||||
|
||||
b.on('file', function (file) {
|
||||
watchFile(file);
|
||||
});
|
||||
|
||||
b.on('package', function (pkg) {
|
||||
var file = path.join(pkg.__dirname, 'package.json');
|
||||
watchFile(file);
|
||||
if (pkgcache) pkgcache[file] = pkg;
|
||||
});
|
||||
|
||||
b.on('reset', reset);
|
||||
reset();
|
||||
|
||||
function reset () {
|
||||
var time = null;
|
||||
var bytes = 0;
|
||||
b.pipeline.get('record').on('end', function () {
|
||||
time = Date.now();
|
||||
});
|
||||
|
||||
b.pipeline.get('wrap').push(through(write, end));
|
||||
function write (buf, enc, next) {
|
||||
bytes += buf.length;
|
||||
this.push(buf);
|
||||
next();
|
||||
}
|
||||
function end () {
|
||||
var delta = Date.now() - time;
|
||||
b.emit('time', delta);
|
||||
b.emit('bytes', bytes);
|
||||
b.emit('log', bytes + ' bytes written ('
|
||||
+ (delta / 1000).toFixed(2) + ' seconds)'
|
||||
);
|
||||
this.push(null);
|
||||
}
|
||||
}
|
||||
|
||||
var fwatchers = {};
|
||||
var fwatcherFiles = {};
|
||||
var ignoredFiles = {};
|
||||
|
||||
b.on('transform', function (tr, mfile) {
|
||||
tr.on('file', function (dep) {
|
||||
watchFile(mfile, dep);
|
||||
});
|
||||
});
|
||||
b.on('bundle', function (bundle) {
|
||||
updating = true;
|
||||
bundle.on('error', onend);
|
||||
bundle.on('end', onend);
|
||||
function onend () { updating = false }
|
||||
});
|
||||
|
||||
function watchFile (file, dep) {
|
||||
dep = dep || file;
|
||||
if (ignored) {
|
||||
if (!ignoredFiles.hasOwnProperty(file)) {
|
||||
ignoredFiles[file] = anymatch(ignored, file);
|
||||
}
|
||||
if (ignoredFiles[file]) return;
|
||||
}
|
||||
if (!fwatchers[file]) fwatchers[file] = [];
|
||||
if (!fwatcherFiles[file]) fwatcherFiles[file] = [];
|
||||
if (fwatcherFiles[file].indexOf(dep) >= 0) return;
|
||||
|
||||
var w = b._watcher(dep, wopts);
|
||||
w.setMaxListeners(0);
|
||||
w.on('error', b.emit.bind(b, 'error'));
|
||||
w.on('change', function () {
|
||||
invalidate(file);
|
||||
});
|
||||
fwatchers[file].push(w);
|
||||
fwatcherFiles[file].push(dep);
|
||||
}
|
||||
|
||||
function invalidate (id) {
|
||||
if (cache) delete cache[id];
|
||||
if (pkgcache) delete pkgcache[id];
|
||||
changingDeps[id] = true;
|
||||
|
||||
if (!updating && fwatchers[id]) {
|
||||
fwatchers[id].forEach(function (w) {
|
||||
w.close();
|
||||
});
|
||||
delete fwatchers[id];
|
||||
delete fwatcherFiles[id];
|
||||
}
|
||||
|
||||
// wait for the disk/editor to quiet down first:
|
||||
if (pending) clearTimeout(pending);
|
||||
pending = setTimeout(notify, delay);
|
||||
}
|
||||
|
||||
function notify () {
|
||||
if (updating) {
|
||||
pending = setTimeout(notify, delay);
|
||||
} else {
|
||||
pending = false;
|
||||
b.emit('update', Object.keys(changingDeps));
|
||||
changingDeps = {};
|
||||
}
|
||||
}
|
||||
|
||||
b.close = function () {
|
||||
Object.keys(fwatchers).forEach(function (id) {
|
||||
fwatchers[id].forEach(function (w) { w.close() });
|
||||
});
|
||||
};
|
||||
|
||||
b._watcher = function (file, opts) {
|
||||
return chokidar.watch(file, opts);
|
||||
};
|
||||
|
||||
return b;
|
||||
}
|
||||
9
node_modules/watchify/node_modules/through2/LICENSE.md
generated
vendored
Normal file
9
node_modules/watchify/node_modules/through2/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
**Copyright (c) Rod Vagg (the "Original Author") and additional 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.
|
||||
140
node_modules/watchify/node_modules/through2/README.md
generated
vendored
Normal file
140
node_modules/watchify/node_modules/through2/README.md
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
# through2
|
||||
|
||||

|
||||
|
||||
[](https://nodei.co/npm/through2/)
|
||||
|
||||
**A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise**
|
||||
|
||||
Inspired by [Dominic Tarr](https://github.com/dominictarr)'s [through](https://github.com/dominictarr/through) in that it's so much easier to make a stream out of a function than it is to set up the prototype chain properly: `through(function (chunk) { ... })`.
|
||||
|
||||
```js
|
||||
fs.createReadStream('ex.txt')
|
||||
.pipe(through2(function (chunk, enc, callback) {
|
||||
for (let i = 0; i < chunk.length; i++)
|
||||
if (chunk[i] == 97)
|
||||
chunk[i] = 122 // swap 'a' for 'z'
|
||||
|
||||
this.push(chunk)
|
||||
|
||||
callback()
|
||||
}))
|
||||
.pipe(fs.createWriteStream('out.txt'))
|
||||
.on('finish', () => doSomethingSpecial())
|
||||
```
|
||||
|
||||
Or object streams:
|
||||
|
||||
```js
|
||||
const all = []
|
||||
|
||||
fs.createReadStream('data.csv')
|
||||
.pipe(csv2())
|
||||
.pipe(through2.obj(function (chunk, enc, callback) {
|
||||
const data = {
|
||||
name : chunk[0]
|
||||
, address : chunk[3]
|
||||
, phone : chunk[10]
|
||||
}
|
||||
this.push(data)
|
||||
|
||||
callback()
|
||||
}))
|
||||
.on('data', (data) => {
|
||||
all.push(data)
|
||||
})
|
||||
.on('end', () => {
|
||||
doSomethingSpecial(all)
|
||||
})
|
||||
```
|
||||
|
||||
Note that `through2.obj(fn)` is a convenience wrapper around `through2({ objectMode: true }, fn)`.
|
||||
|
||||
## Do you need this?
|
||||
|
||||
Since Node.js introduced [Simplified Stream Construction](https://nodejs.org/api/stream.html#stream_simplified_construction), many uses of **through2** have become redundant. Consider whether you really need to use **through2** or just want to use the `'readable-stream'` package, or the core `'stream'` package (which is derived from `'readable-stream'`):
|
||||
|
||||
```js
|
||||
const { Transform } = require('readable-stream')
|
||||
|
||||
const transformer = new Transform({
|
||||
transform(chunk, enc, callback) {
|
||||
// ...
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
<b><code>through2([ options, ] [ transformFunction ] [, flushFunction ])</code></b>
|
||||
|
||||
Consult the **[stream.Transform](https://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform)** documentation for the exact rules of the `transformFunction` (i.e. `this._transform`) and the optional `flushFunction` (i.e. `this._flush`).
|
||||
|
||||
### options
|
||||
|
||||
The options argument is optional and is passed straight through to `stream.Transform`. So you can use `objectMode:true` if you are processing non-binary streams (or just use `through2.obj()`).
|
||||
|
||||
The `options` argument is first, unlike standard convention, because if I'm passing in an anonymous function then I'd prefer for the options argument to not get lost at the end of the call:
|
||||
|
||||
```js
|
||||
fs.createReadStream('/tmp/important.dat')
|
||||
.pipe(through2({ objectMode: true, allowHalfOpen: false },
|
||||
(chunk, enc, cb) => {
|
||||
cb(null, 'wut?') // note we can use the second argument on the callback
|
||||
// to provide data as an alternative to this.push('wut?')
|
||||
}
|
||||
))
|
||||
.pipe(fs.createWriteStream('/tmp/wut.txt'))
|
||||
```
|
||||
|
||||
### transformFunction
|
||||
|
||||
The `transformFunction` must have the following signature: `function (chunk, encoding, callback) {}`. A minimal implementation should call the `callback` function to indicate that the transformation is done, even if that transformation means discarding the chunk.
|
||||
|
||||
To queue a new chunk, call `this.push(chunk)`—this can be called as many times as required before the `callback()` if you have multiple pieces to send on.
|
||||
|
||||
Alternatively, you may use `callback(err, chunk)` as shorthand for emitting a single chunk or an error.
|
||||
|
||||
If you **do not provide a `transformFunction`** then you will get a simple pass-through stream.
|
||||
|
||||
### flushFunction
|
||||
|
||||
The optional `flushFunction` is provided as the last argument (2nd or 3rd, depending on whether you've supplied options) is called just prior to the stream ending. Can be used to finish up any processing that may be in progress.
|
||||
|
||||
```js
|
||||
fs.createReadStream('/tmp/important.dat')
|
||||
.pipe(through2(
|
||||
(chunk, enc, cb) => cb(null, chunk), // transform is a noop
|
||||
function (cb) { // flush function
|
||||
this.push('tacking on an extra buffer to the end');
|
||||
cb();
|
||||
}
|
||||
))
|
||||
.pipe(fs.createWriteStream('/tmp/wut.txt'));
|
||||
```
|
||||
|
||||
<b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
|
||||
|
||||
Instead of returning a `stream.Transform` instance, `through2.ctor()` returns a **constructor** for a custom Transform. This is useful when you want to use the same transform logic in multiple instances.
|
||||
|
||||
```js
|
||||
const FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
|
||||
if (record.temp != null && record.unit == "F") {
|
||||
record.temp = ( ( record.temp - 32 ) * 5 ) / 9
|
||||
record.unit = "C"
|
||||
}
|
||||
this.push(record)
|
||||
callback()
|
||||
})
|
||||
|
||||
// Create instances of FToC like so:
|
||||
const converter = new FToC()
|
||||
// Or:
|
||||
const converter = FToC()
|
||||
// Or specify/override options when you instantiate, if you prefer:
|
||||
const converter = FToC({objectMode: true})
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
**through2** is Copyright © Rod Vagg and additional contributors and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
|
||||
38
node_modules/watchify/node_modules/through2/package.json
generated
vendored
Normal file
38
node_modules/watchify/node_modules/through2/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "through2",
|
||||
"version": "4.0.2",
|
||||
"description": "A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise",
|
||||
"main": "through2.js",
|
||||
"scripts": {
|
||||
"test:node": "hundreds mocha test/test.js",
|
||||
"test:browser": "node -e 'process.exit(process.version.startsWith(\"v8.\") ? 0 : 1)' || polendina --cleanup --runner=mocha test/test.js",
|
||||
"test": "npm run lint && npm run test:node && npm run test:browser",
|
||||
"lint": "standard",
|
||||
"coverage": "c8 --reporter=text --reporter=html mocha test/test.js && npx st -d coverage -p 8888"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rvagg/through2.git"
|
||||
},
|
||||
"keywords": [
|
||||
"stream",
|
||||
"streams2",
|
||||
"through",
|
||||
"transform"
|
||||
],
|
||||
"author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"readable-stream": "3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bl": "^4.0.2",
|
||||
"buffer": "^5.6.0",
|
||||
"chai": "^4.2.0",
|
||||
"hundreds": "~0.0.7",
|
||||
"mocha": "^7.2.0",
|
||||
"polendina": "^1.0.0",
|
||||
"standard": "^14.3.4",
|
||||
"stream-spigot": "^3.0.6"
|
||||
}
|
||||
}
|
||||
83
node_modules/watchify/node_modules/through2/through2.js
generated
vendored
Normal file
83
node_modules/watchify/node_modules/through2/through2.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
const { Transform } = require('readable-stream')
|
||||
|
||||
function inherits (fn, sup) {
|
||||
fn.super_ = sup
|
||||
fn.prototype = Object.create(sup.prototype, {
|
||||
constructor: { value: fn, enumerable: false, writable: true, configurable: true }
|
||||
})
|
||||
}
|
||||
|
||||
// create a new export function, used by both the main export and
|
||||
// the .ctor export, contains common logic for dealing with arguments
|
||||
function through2 (construct) {
|
||||
return (options, transform, flush) => {
|
||||
if (typeof options === 'function') {
|
||||
flush = transform
|
||||
transform = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
if (typeof transform !== 'function') {
|
||||
// noop
|
||||
transform = (chunk, enc, cb) => cb(null, chunk)
|
||||
}
|
||||
|
||||
if (typeof flush !== 'function') {
|
||||
flush = null
|
||||
}
|
||||
|
||||
return construct(options, transform, flush)
|
||||
}
|
||||
}
|
||||
|
||||
// main export, just make me a transform stream!
|
||||
const make = through2((options, transform, flush) => {
|
||||
const t2 = new Transform(options)
|
||||
|
||||
t2._transform = transform
|
||||
|
||||
if (flush) {
|
||||
t2._flush = flush
|
||||
}
|
||||
|
||||
return t2
|
||||
})
|
||||
|
||||
// make me a reusable prototype that I can `new`, or implicitly `new`
|
||||
// with a constructor call
|
||||
const ctor = through2((options, transform, flush) => {
|
||||
function Through2 (override) {
|
||||
if (!(this instanceof Through2)) {
|
||||
return new Through2(override)
|
||||
}
|
||||
|
||||
this.options = Object.assign({}, options, override)
|
||||
|
||||
Transform.call(this, this.options)
|
||||
|
||||
this._transform = transform
|
||||
if (flush) {
|
||||
this._flush = flush
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Through2, Transform)
|
||||
|
||||
return Through2
|
||||
})
|
||||
|
||||
const obj = through2(function (options, transform, flush) {
|
||||
const t2 = new Transform(Object.assign({ objectMode: true, highWaterMark: 16 }, options))
|
||||
|
||||
t2._transform = transform
|
||||
|
||||
if (flush) {
|
||||
t2._flush = flush
|
||||
}
|
||||
|
||||
return t2
|
||||
})
|
||||
|
||||
module.exports = make
|
||||
module.exports.ctor = ctor
|
||||
module.exports.obj = obj
|
||||
49
node_modules/watchify/package.json
generated
vendored
Normal file
49
node_modules/watchify/package.json
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "watchify",
|
||||
"version": "4.0.0",
|
||||
"description": "watch mode for browserify builds",
|
||||
"main": "index.js",
|
||||
"bin": "bin/cmd.js",
|
||||
"engines": {
|
||||
"node": ">= 8.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"anymatch": "^3.1.0",
|
||||
"browserify": "^17.0.0",
|
||||
"chokidar": "^3.4.0",
|
||||
"defined": "^1.0.0",
|
||||
"outpipe": "^1.1.0",
|
||||
"through2": "^4.0.2",
|
||||
"xtend": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"brfs": "^2.0.1",
|
||||
"mkdirp": "^0.5.5",
|
||||
"split": "^1.0.0",
|
||||
"tape": "^5.1.1",
|
||||
"uglify-js": "^2.5.0",
|
||||
"win-spawn": "^2.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/browserify/watchify.git"
|
||||
},
|
||||
"homepage": "https://github.com/browserify/watchify",
|
||||
"keywords": [
|
||||
"browserify",
|
||||
"browserify-tool",
|
||||
"watch",
|
||||
"bundle",
|
||||
"build",
|
||||
"browser"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
270
node_modules/watchify/readme.markdown
generated
vendored
Normal file
270
node_modules/watchify/readme.markdown
generated
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
# watchify
|
||||
|
||||
watch mode for [browserify](https://github.com/substack/node-browserify) builds
|
||||
|
||||
[](http://travis-ci.org/browserify/watchify)
|
||||
|
||||
Update any source file and your browserify bundle will be recompiled on the
|
||||
spot.
|
||||
|
||||
# example
|
||||
|
||||
```
|
||||
$ watchify main.js -o static/bundle.js
|
||||
```
|
||||
|
||||
Now as you update files, `static/bundle.js` will be automatically
|
||||
incrementally rebuilt on the fly.
|
||||
|
||||
The `-o` option can be a file or a shell command (not available on Windows)
|
||||
that receives piped input:
|
||||
|
||||
``` sh
|
||||
watchify main.js -o 'exorcist static/bundle.js.map > static/bundle.js' -d
|
||||
```
|
||||
|
||||
``` sh
|
||||
watchify main.js -o 'uglifyjs -cm > static/bundle.min.js'
|
||||
```
|
||||
|
||||
You can use `-v` to get more verbose output to show when a file was written and how long the bundling took (in seconds):
|
||||
|
||||
```
|
||||
$ watchify browser.js -d -o static/bundle.js -v
|
||||
610598 bytes written to static/bundle.js (0.23 seconds) at 8:31:25 PM
|
||||
610606 bytes written to static/bundle.js (0.10 seconds) at 8:45:59 PM
|
||||
610597 bytes written to static/bundle.js (0.14 seconds) at 8:46:02 PM
|
||||
610606 bytes written to static/bundle.js (0.08 seconds) at 8:50:13 PM
|
||||
610597 bytes written to static/bundle.js (0.08 seconds) at 8:58:16 PM
|
||||
610597 bytes written to static/bundle.js (0.19 seconds) at 9:10:45 PM
|
||||
```
|
||||
|
||||
# usage
|
||||
|
||||
Use `watchify` with all the same options as `browserify` except that `-o` (or
|
||||
`--outfile`) is mandatory. Additionally, there are also:
|
||||
|
||||
```
|
||||
Standard Options:
|
||||
|
||||
--outfile=FILE, -o FILE
|
||||
|
||||
This option is required. Write the browserify bundle to this file. If
|
||||
the file contains the operators `|` or `>`, it will be treated as a
|
||||
shell command, and the output will be piped to it.
|
||||
|
||||
--verbose, -v [default: false]
|
||||
|
||||
Show when a file was written and how long the bundling took (in
|
||||
seconds).
|
||||
|
||||
--version
|
||||
|
||||
Show the watchify and browserify versions with their module paths.
|
||||
```
|
||||
|
||||
```
|
||||
Advanced Options:
|
||||
|
||||
--delay [default: 100]
|
||||
|
||||
Amount of time in milliseconds to wait before emitting an "update"
|
||||
event after a change.
|
||||
|
||||
--ignore-watch=GLOB, --iw GLOB [default: false]
|
||||
|
||||
Ignore monitoring files for changes that match the pattern. Omitting
|
||||
the pattern will default to "**/node_modules/**".
|
||||
|
||||
--poll=INTERVAL [default: false]
|
||||
|
||||
Use polling to monitor for changes. Omitting the interval will default
|
||||
to 100ms. This option is useful if you're watching an NFS volume.
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var watchify = require('watchify');
|
||||
```
|
||||
|
||||
## watchify(b, opts)
|
||||
|
||||
watchify is a browserify [plugin](https://github.com/browserify/browserify#bpluginplugin-opts), so it can be applied like any other plugin.
|
||||
However, when creating the browserify instance `b`, **you MUST set the `cache`
|
||||
and `packageCache` properties**:
|
||||
|
||||
``` js
|
||||
var b = browserify({ cache: {}, packageCache: {} });
|
||||
b.plugin(watchify);
|
||||
```
|
||||
|
||||
```js
|
||||
var b = browserify({
|
||||
cache: {},
|
||||
packageCache: {},
|
||||
plugin: [watchify]
|
||||
});
|
||||
```
|
||||
|
||||
**By default, watchify doesn't display any output, see [events](https://github.com/browserify/watchify#events) for more info.**
|
||||
|
||||
`b` continues to behave like a browserify instance except that it caches file
|
||||
contents and emits an `'update'` event when a file changes. You should call
|
||||
`b.bundle()` after the `'update'` event fires to generate a new bundle.
|
||||
Calling `b.bundle()` extra times past the first time will be much faster due
|
||||
to caching.
|
||||
|
||||
**Important:** Watchify will not emit `'update'` events until you've called
|
||||
`b.bundle()` once and completely drained the stream it returns.
|
||||
|
||||
```js
|
||||
var fs = require('fs');
|
||||
var browserify = require('browserify');
|
||||
var watchify = require('watchify');
|
||||
|
||||
var b = browserify({
|
||||
entries: ['path/to/entry.js'],
|
||||
cache: {},
|
||||
packageCache: {},
|
||||
plugin: [watchify]
|
||||
});
|
||||
|
||||
b.on('update', bundle);
|
||||
bundle();
|
||||
|
||||
function bundle() {
|
||||
b.bundle()
|
||||
.on('error', console.error)
|
||||
.pipe(fs.createWriteStream('output.js'))
|
||||
;
|
||||
}
|
||||
```
|
||||
|
||||
### options
|
||||
|
||||
You can to pass an additional options object as a second parameter of
|
||||
watchify. Its properties are:
|
||||
|
||||
`opts.delay` is the amount of time in milliseconds to wait before emitting
|
||||
an "update" event after a change. Defaults to `100`.
|
||||
|
||||
`opts.ignoreWatch` ignores monitoring files for changes. If set to `true`,
|
||||
then `**/node_modules/**` will be ignored. For other possible values see
|
||||
Chokidar's [documentation](https://github.com/paulmillr/chokidar#path-filtering) on "ignored".
|
||||
|
||||
`opts.poll` enables polling to monitor for changes. If set to `true`, then
|
||||
a polling interval of 100ms is used. If set to a number, then that amount of
|
||||
milliseconds will be the polling interval. For more info see Chokidar's
|
||||
[documentation](https://github.com/paulmillr/chokidar#performance) on
|
||||
"usePolling" and "interval".
|
||||
**This option is useful if you're watching an NFS volume.**
|
||||
|
||||
```js
|
||||
var b = browserify({ cache: {}, packageCache: {} });
|
||||
// watchify defaults:
|
||||
b.plugin(watchify, {
|
||||
delay: 100,
|
||||
ignoreWatch: ['**/node_modules/**'],
|
||||
poll: false
|
||||
});
|
||||
```
|
||||
|
||||
## b.close()
|
||||
|
||||
Close all the open watch handles.
|
||||
|
||||
# events
|
||||
|
||||
## b.on('update', function (ids) {})
|
||||
|
||||
When the bundle changes, emit the array of bundle `ids` that changed.
|
||||
|
||||
## b.on('bytes', function (bytes) {})
|
||||
|
||||
When a bundle is generated, this event fires with the number of bytes.
|
||||
|
||||
## b.on('time', function (time) {})
|
||||
|
||||
When a bundle is generated, this event fires with the time it took to create the
|
||||
bundle in milliseconds.
|
||||
|
||||
## b.on('log', function (msg) {})
|
||||
|
||||
This event fires after a bundle was created with messages of the form:
|
||||
|
||||
```
|
||||
X bytes written (Y seconds)
|
||||
```
|
||||
|
||||
with the number of bytes in the bundle X and the time in seconds Y.
|
||||
|
||||
# working with browserify transforms
|
||||
|
||||
If your custom transform for browserify adds new files to the bundle in a non-standard way without requiring.
|
||||
You can inform Watchify about these files by emiting a 'file' event.
|
||||
|
||||
```
|
||||
module.exports = function(file) {
|
||||
return through(
|
||||
function(buf, enc, next) {
|
||||
/*
|
||||
manipulating file content
|
||||
*/
|
||||
|
||||
this.emit("file", absolutePathToFileThatHasToBeWatched);
|
||||
|
||||
next();
|
||||
}
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
$ npm install -g watchify
|
||||
```
|
||||
|
||||
to get the watchify command and:
|
||||
|
||||
```
|
||||
$ npm install watchify
|
||||
```
|
||||
|
||||
to get just the library.
|
||||
|
||||
# troubleshooting
|
||||
|
||||
## rebuilds on OS X never trigger
|
||||
|
||||
It may be related to a bug in `fsevents` (see [#250](https://github.com/browserify/watchify/issues/205#issuecomment-98672850)
|
||||
and [stackoverflow](http://stackoverflow.com/questions/26708205/webpack-watch-isnt-compiling-changed-files/28610124#28610124)).
|
||||
Try the `--poll` flag
|
||||
and/or renaming the project's directory - that might help.
|
||||
|
||||
## watchify swallows errors
|
||||
|
||||
To ensure errors are reported you have to add a event listener to your bundle stream. For more information see ([browserify/browserify#1487 (comment)](https://github.com/browserify/browserify/issues/1487#issuecomment-173357516) and [stackoverflow](https://stackoverflow.com/a/22389498/1423220))
|
||||
|
||||
**Example:**
|
||||
```
|
||||
var b = browserify();
|
||||
b.bundle()
|
||||
.on('error', console.error)
|
||||
...
|
||||
;
|
||||
```
|
||||
|
||||
# see also
|
||||
|
||||
- [budo](https://www.npmjs.com/package/budo) – a simple development server built on watchify
|
||||
- [errorify](https://www.npmjs.com/package/errorify) – a plugin to add error handling to watchify development
|
||||
- [watchify-request](https://www.npmjs.com/package/watchify-request) – wraps a `watchify` instance to avoid stale bundles in HTTP requests
|
||||
- [watchify-middleware](https://www.npmjs.com/package/watchify-middleware) – similar to `watchify-request`, but includes some higher-level features
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
44
node_modules/watchify/test/api.js
generated
vendored
Normal file
44
node_modules/watchify/test/api.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var file = path.join(tmpdir, 'main.js');
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(file, 'console.log(555)');
|
||||
|
||||
test('api', function (t) {
|
||||
t.plan(5);
|
||||
var w = watchify(browserify(file, watchify.args));
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '333\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '555\n');
|
||||
setTimeout(function () {
|
||||
fs.writeFile(file, 'console.log(333)', function (err) {
|
||||
t.ifError(err);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
53
node_modules/watchify/test/api_brfs.js
generated
vendored
Normal file
53
node_modules/watchify/test/api_brfs.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
lines: path.join(tmpdir, 'lines.txt')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, [
|
||||
'var fs = require("fs");',
|
||||
'var src = fs.readFileSync(__dirname + "/lines.txt", "utf8");',
|
||||
'console.log(src.toUpperCase());'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.lines, 'beep\nboop');
|
||||
|
||||
test('api with brfs', function (t) {
|
||||
t.plan(5);
|
||||
var w = watchify(browserify(files.main, watchify.args));
|
||||
w.transform('brfs');
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'ROBO-BOOGIE\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'BEEP\nBOOP\n');
|
||||
setTimeout(function () {
|
||||
fs.writeFile(files.lines, 'rObO-bOOgie', function (err) {
|
||||
t.ifError(err);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
60
node_modules/watchify/test/api_ignore_watch.js
generated
vendored
Normal file
60
node_modules/watchify/test/api_ignore_watch.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
robot: path.join(tmpdir, 'node_modules', 'robot', 'index.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.dirname(files.robot));
|
||||
fs.writeFileSync(files.main, [
|
||||
'var beep = require("./beep");',
|
||||
'var boop = require("./boop");',
|
||||
'var robot = require("robot");',
|
||||
'console.log(beep + " " + boop + " " + robot);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = "beep";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "boop";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "robot";');
|
||||
|
||||
test('api ignore watch', function (t) {
|
||||
t.plan(4);
|
||||
var w = watchify(browserify(files.main, watchify.args), {
|
||||
ignoreWatch: '**/be*.js'
|
||||
});
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'beep BOOP ROBOT\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'beep boop robot\n');
|
||||
setTimeout(function () {
|
||||
fs.writeFileSync(files.beep, 'module.exports = "BEEP";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "BOOP";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "ROBOT";');
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
60
node_modules/watchify/test/api_ignore_watch_default.js
generated
vendored
Normal file
60
node_modules/watchify/test/api_ignore_watch_default.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
robot: path.join(tmpdir, 'node_modules', 'robot', 'index.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.dirname(files.robot));
|
||||
fs.writeFileSync(files.main, [
|
||||
'var beep = require("./beep");',
|
||||
'var boop = require("./boop");',
|
||||
'var robot = require("robot");',
|
||||
'console.log(beep + " " + boop + " " + robot);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = "beep";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "boop";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "robot";');
|
||||
|
||||
test('api ignore watch default', function (t) {
|
||||
t.plan(4);
|
||||
var w = watchify(browserify(files.main, watchify.args), {
|
||||
ignoreWatch: true
|
||||
});
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'BEEP BOOP robot\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'beep boop robot\n');
|
||||
setTimeout(function () {
|
||||
fs.writeFileSync(files.beep, 'module.exports = "BEEP";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "BOOP";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "ROBOT";');
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
60
node_modules/watchify/test/api_ignore_watch_multiple.js
generated
vendored
Normal file
60
node_modules/watchify/test/api_ignore_watch_multiple.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
robot: path.join(tmpdir, 'node_modules', 'robot', 'index.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.dirname(files.robot));
|
||||
fs.writeFileSync(files.main, [
|
||||
'var beep = require("./beep");',
|
||||
'var boop = require("./boop");',
|
||||
'var robot = require("robot");',
|
||||
'console.log(beep + " " + boop + " " + robot);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = "beep";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "boop";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "robot";');
|
||||
|
||||
test('api ignore watch multiple paths', function (t) {
|
||||
t.plan(4);
|
||||
var w = watchify(browserify(files.main, watchify.args), {
|
||||
ignoreWatch: ['**/be*.js', '**/robot/*.js']
|
||||
});
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'beep BOOP robot\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'beep boop robot\n');
|
||||
setTimeout(function () {
|
||||
fs.writeFileSync(files.beep, 'module.exports = "BEEP";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "BOOP";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "ROBOT";');
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
44
node_modules/watchify/test/api_implicit_cache.js
generated
vendored
Normal file
44
node_modules/watchify/test/api_implicit_cache.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var file = path.join(tmpdir, 'main.js');
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(file, 'console.log(555)');
|
||||
|
||||
test('api implicit cache', function (t) {
|
||||
t.plan(5);
|
||||
var w = watchify(browserify(file));
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '333\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '555\n');
|
||||
setTimeout(function () {
|
||||
fs.writeFile(file, 'console.log(333)', function (err) {
|
||||
t.ifError(err);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
52
node_modules/watchify/test/bin.js
generated
vendored
Normal file
52
node_modules/watchify/test/bin.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, 'console.log(555)');
|
||||
|
||||
test('bin', function (t) {
|
||||
t.plan(5);
|
||||
var ps = spawn(cmd, [ files.main, '-o', files.bundle, '-v' ]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, '555\n');
|
||||
fs.writeFile(files.main, 'console.log(333)', t.ifError);
|
||||
})
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, '333\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
62
node_modules/watchify/test/bin_brfs.js
generated
vendored
Normal file
62
node_modules/watchify/test/bin_brfs.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
lines: path.join(tmpdir, 'lines.txt'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, [
|
||||
'var fs = require("fs");',
|
||||
'var src = fs.readFileSync(__dirname + "/lines.txt", "utf8");',
|
||||
'console.log(src.toUpperCase());'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.lines, 'beep\nboop');
|
||||
|
||||
test('bin brfs', function (t) {
|
||||
t.plan(5);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'-t', require.resolve('brfs'), '-v',
|
||||
'-o', files.bundle
|
||||
]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'BEEP\nBOOP\n');
|
||||
fs.writeFile(files.lines, 'robo-bOOgie', t.ifError);
|
||||
})
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'ROBO-BOOGIE\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
71
node_modules/watchify/test/bin_ignore_watch.js
generated
vendored
Normal file
71
node_modules/watchify/test/bin_ignore_watch.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
robot: path.join(tmpdir, 'node_modules', 'robot', 'index.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.dirname(files.robot));
|
||||
fs.writeFileSync(files.main, [
|
||||
'var beep = require("./beep");',
|
||||
'var boop = require("./boop");',
|
||||
'var robot = require("robot");',
|
||||
'console.log(beep + " " + boop + " " + robot);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = "beep";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "boop";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "robot";');
|
||||
|
||||
test('api ignore watch', function (t) {
|
||||
t.plan(4);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'--ignore-watch', '**/be*.js',
|
||||
'-o', files.bundle,
|
||||
'-v'
|
||||
]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'beep boop robot\n');
|
||||
fs.writeFileSync(files.beep, 'module.exports = "BEEP";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "BOOP";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "ROBOT";');
|
||||
});
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'beep BOOP ROBOT\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
71
node_modules/watchify/test/bin_ignore_watch_default.js
generated
vendored
Normal file
71
node_modules/watchify/test/bin_ignore_watch_default.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
robot: path.join(tmpdir, 'node_modules', 'robot', 'index.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.dirname(files.robot));
|
||||
fs.writeFileSync(files.main, [
|
||||
'var beep = require("./beep");',
|
||||
'var boop = require("./boop");',
|
||||
'var robot = require("robot");',
|
||||
'console.log(beep + " " + boop + " " + robot);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = "beep";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "boop";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "robot";');
|
||||
|
||||
test('api ignore watch', function (t) {
|
||||
t.plan(4);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'--ignore-watch',
|
||||
'-o', files.bundle,
|
||||
'-v'
|
||||
]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'beep boop robot\n');
|
||||
fs.writeFileSync(files.beep, 'module.exports = "BEEP";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "BOOP";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "ROBOT";');
|
||||
});
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'BEEP BOOP robot\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
72
node_modules/watchify/test/bin_ignore_watch_multiple.js
generated
vendored
Normal file
72
node_modules/watchify/test/bin_ignore_watch_multiple.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
robot: path.join(tmpdir, 'node_modules', 'robot', 'index.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.dirname(files.robot));
|
||||
fs.writeFileSync(files.main, [
|
||||
'var beep = require("./beep");',
|
||||
'var boop = require("./boop");',
|
||||
'var robot = require("robot");',
|
||||
'console.log(beep + " " + boop + " " + robot);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = "beep";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "boop";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "robot";');
|
||||
|
||||
test('api ignore watch multiple paths', function (t) {
|
||||
t.plan(4);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'--ignore-watch', '**/be*.js',
|
||||
'--ignore-watch', '**/robot/*.js',
|
||||
'-o', files.bundle,
|
||||
'-v'
|
||||
]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'beep boop robot\n');
|
||||
fs.writeFileSync(files.beep, 'module.exports = "BEEP";');
|
||||
fs.writeFileSync(files.boop, 'module.exports = "BOOP";');
|
||||
fs.writeFileSync(files.robot, 'module.exports = "ROBOT";');
|
||||
});
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, 'beep BOOP robot\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
56
node_modules/watchify/test/bin_pipe.js
generated
vendored
Normal file
56
node_modules/watchify/test/bin_pipe.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, 'console.log(num * 2)');
|
||||
|
||||
test('bin with pipe', function (t) {
|
||||
t.plan(5);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'-o', 'uglifyjs - --enclose 11:num > ' + files.bundle,
|
||||
'-v'
|
||||
]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, '22\n');
|
||||
fs.writeFile(files.main, 'console.log(num * 3)', t.ifError);
|
||||
});
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, '33\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
56
node_modules/watchify/test/bin_plugins_pipelining_multiple_errors.js
generated
vendored
Normal file
56
node_modules/watchify/test/bin_plugins_pipelining_multiple_errors.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
plugin: path.join(tmpdir, 'plugin.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.plugin, [
|
||||
'module.exports = function(b, opts) {',
|
||||
' b.on("file", function (file, id) {',
|
||||
' b.pipeline.emit("error", "bad boop");',
|
||||
' b.pipeline.emit("error", "bad boop");',
|
||||
' });',
|
||||
'};',
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.main, 'boop\nbeep');
|
||||
|
||||
test('bin plugins pipelining multiple errors', function (t) {
|
||||
t.plan(4);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'-p', files.plugin, '-v',
|
||||
'-o', files.bundle
|
||||
]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
t.equal(line, 'bad boop');
|
||||
}
|
||||
if (lineNum === 2) {
|
||||
t.equal(line, 'bad boop');
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(files.main, 'beep\nboop');
|
||||
}, 1000);
|
||||
}
|
||||
if (lineNum === 3) {
|
||||
t.equal(line, 'bad boop');
|
||||
}
|
||||
if (lineNum === 4) {
|
||||
t.equal(line, 'bad boop');
|
||||
ps.kill();
|
||||
}
|
||||
});
|
||||
});
|
||||
52
node_modules/watchify/test/bin_standalone.js
generated
vendored
Normal file
52
node_modules/watchify/test/bin_standalone.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, 'console.log(555)');
|
||||
|
||||
test('bin with standalone', function (t) {
|
||||
t.plan(5);
|
||||
var ps = spawn(cmd, [ files.main, '-o', files.bundle, '-v', '-s', 'XXX' ]);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
lineNum ++;
|
||||
if (lineNum === 1) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, '555\n');
|
||||
fs.writeFile(files.main, 'console.log(333)', t.ifError);
|
||||
})
|
||||
}
|
||||
else if (lineNum === 2) {
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, '333\n');
|
||||
ps.kill();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
56
node_modules/watchify/test/errors.js
generated
vendored
Normal file
56
node_modules/watchify/test/errors.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var file = path.join(tmpdir, 'main.js');
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(file, 'console.log(555)');
|
||||
|
||||
test('errors', function (t) {
|
||||
t.plan(5);
|
||||
var w = watchify(browserify(file, watchify.args));
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '555\n');
|
||||
breakTheBuild();
|
||||
});
|
||||
function breakTheBuild() {
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(file, 'console.log(');
|
||||
}, 1000);
|
||||
w.once('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ok(err instanceof Error, 'should be error');
|
||||
fixTheBuild();
|
||||
});
|
||||
});
|
||||
}
|
||||
function fixTheBuild() {
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(file, 'console.log(333)');
|
||||
}, 1000);
|
||||
w.once('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '333\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
83
node_modules/watchify/test/errors_transform.js
generated
vendored
Normal file
83
node_modules/watchify/test/errors_transform.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var through = require('through2');
|
||||
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var main = path.join(tmpdir, 'main.js');
|
||||
var file = path.join(tmpdir, 'dep.jsnum');
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(main, 'require("./dep.jsnum")');
|
||||
fs.writeFileSync(file, 'console.log(555)');
|
||||
|
||||
function someTransform(file) {
|
||||
if (!/\.jsnum$/.test(file)) {
|
||||
return through();
|
||||
}
|
||||
function write (chunk, enc, next) {
|
||||
if (/\d/.test(chunk)) {
|
||||
this.push(chunk);
|
||||
} else {
|
||||
this.emit('error', new Error('No number in this chunk'));
|
||||
}
|
||||
next();
|
||||
}
|
||||
return through(write);
|
||||
}
|
||||
|
||||
test('errors in transform', function (t) {
|
||||
t.plan(6);
|
||||
var b = browserify(main, watchify.args);
|
||||
b.transform(someTransform);
|
||||
var w = watchify(b);
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '555\n');
|
||||
breakTheBuild();
|
||||
});
|
||||
function breakTheBuild() {
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(file, 'console.log()');
|
||||
}, 1000);
|
||||
w.once('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ok(err instanceof Error, 'should be error');
|
||||
t.ok(/^No number in this chunk/.test(err.message));
|
||||
fixTheBuild();
|
||||
});
|
||||
});
|
||||
}
|
||||
function fixTheBuild() {
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(file, 'console.log(333)');
|
||||
}, 1000);
|
||||
var safety = setTimeout(function() {
|
||||
t.fail("gave up waiting");
|
||||
w.close();
|
||||
t.end();
|
||||
}, 5000);
|
||||
w.once('update', function () {
|
||||
clearTimeout(safety);
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), '333\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
72
node_modules/watchify/test/expose.js
generated
vendored
Normal file
72
node_modules/watchify/test/expose.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
var test = require('tape');
|
||||
var watchify = require('../');
|
||||
var browserify = require('browserify');
|
||||
var vm = require('vm');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
|
||||
var os = require('os');
|
||||
var tmpbase = fs.realpathSync((os.tmpdir || os.tmpDir)());
|
||||
var tmpdir = path.join(tmpbase, 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
beep: path.join(tmpdir, 'beep.js'),
|
||||
boop: path.join(tmpdir, 'boop.js'),
|
||||
abc: path.join(tmpdir, 'lib', 'abc.js'),
|
||||
xyz: path.join(tmpdir, 'lib', 'xyz.js')
|
||||
};
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
mkdirp.sync(path.join(tmpdir, 'lib'));
|
||||
|
||||
fs.writeFileSync(files.main, [
|
||||
'var abc = require("abc");',
|
||||
'var xyz = require("xyz");',
|
||||
'var beep = require("./beep");',
|
||||
'console.log(abc + " " + xyz + " " + beep);'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.beep, 'module.exports = require("./boop");');
|
||||
fs.writeFileSync(files.boop, 'module.exports = require("xyz");');
|
||||
fs.writeFileSync(files.abc, 'module.exports = "abc";');
|
||||
fs.writeFileSync(files.xyz, 'module.exports = "xyz";');
|
||||
|
||||
test('properly caches exposed files', function (t) {
|
||||
t.plan(4);
|
||||
var cache = {};
|
||||
var w = watchify(browserify({
|
||||
entries: [files.main],
|
||||
basedir: tmpdir,
|
||||
cache: cache,
|
||||
packageCache: {}
|
||||
}));
|
||||
|
||||
w.require('./lib/abc', {expose: 'abc'});
|
||||
w.require('./lib/xyz', {expose: 'xyz'});
|
||||
w.on('update', function () {
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'ABC XYZ XYZ\n');
|
||||
w.close();
|
||||
});
|
||||
});
|
||||
w.bundle(function (err, src) {
|
||||
t.ifError(err);
|
||||
t.equal(run(src), 'abc xyz xyz\n');
|
||||
setTimeout(function () {
|
||||
// If we're incorrectly caching exposed files,
|
||||
// then "files.abc" would be re-read from disk.
|
||||
cache[files.abc].source = 'module.exports = "ABC";';
|
||||
fs.writeFileSync(files.xyz, 'module.exports = "XYZ";');
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
function run (src) {
|
||||
var output = '';
|
||||
function log (msg) { output += msg + '\n' }
|
||||
vm.runInNewContext(src, { console: { log: log } });
|
||||
return output;
|
||||
}
|
||||
101
node_modules/watchify/test/many.js
generated
vendored
Normal file
101
node_modules/watchify/test/many.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
robot: path.join(tmpdir, 'robot.js'),
|
||||
lines: path.join(tmpdir, 'lines.txt'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
var edits = [
|
||||
{ file: 'lines', source: 'robo-boogie' },
|
||||
{ file: 'lines', source: 'dinosaurus rex' },
|
||||
{
|
||||
file: 'robot',
|
||||
source: 'module.exports = function (n) { return n * 111 }',
|
||||
next: true
|
||||
},
|
||||
{ file: 'main', source: [
|
||||
'var fs = require("fs");',
|
||||
'var robot = require("./robot.js");',
|
||||
'var src = fs.readFileSync(__dirname + "/lines.txt", "utf8");',
|
||||
'console.log(src.toUpperCase() + " " + robot(src.length));'
|
||||
].join('\n') },
|
||||
{ file: 'lines', source: 't-rex' },
|
||||
{
|
||||
file: 'robot',
|
||||
source: 'module.exports = function (n) { return n * 100 }',
|
||||
}
|
||||
];
|
||||
|
||||
var expected = [
|
||||
'BEEP\nBOOP\n',
|
||||
'ROBO-BOOGIE\n',
|
||||
'DINOSAURUS REX\n',
|
||||
'DINOSAURUS REX 1554\n',
|
||||
'T-REX 555\n',
|
||||
'T-REX 500\n'
|
||||
];
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, [
|
||||
'var fs = require("fs");',
|
||||
'var src = fs.readFileSync(__dirname + "/lines.txt", "utf8");',
|
||||
'console.log(src.toUpperCase());'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.lines, 'beep\nboop');
|
||||
|
||||
test('many edits', function (t) {
|
||||
t.plan(expected.length * 2 + edits.length);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'-t', require.resolve('brfs'), '-v',
|
||||
'-o', files.bundle
|
||||
]);
|
||||
ps.stdout.pipe(process.stdout);
|
||||
ps.stderr.pipe(process.stdout);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
if (line.length === 0) return;
|
||||
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, expected.shift());
|
||||
|
||||
(function next () {
|
||||
if (edits.length === 0) return;
|
||||
var edit = edits.shift();
|
||||
setTimeout(function () {
|
||||
fs.writeFile(files[edit.file], edit.source, function (err) {
|
||||
t.ifError(err);
|
||||
if (edit.next) next();
|
||||
});
|
||||
}, 25);
|
||||
})();
|
||||
})
|
||||
});
|
||||
|
||||
t.on('end', function () {
|
||||
ps.kill();
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
99
node_modules/watchify/test/many_immediate.js
generated
vendored
Normal file
99
node_modules/watchify/test/many_immediate.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
var test = require('tape');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var mkdirp = require('mkdirp');
|
||||
var spawn = require('win-spawn');
|
||||
var split = require('split');
|
||||
|
||||
var cmd = path.resolve(__dirname, '../bin/cmd.js');
|
||||
var os = require('os');
|
||||
var tmpdir = path.join((os.tmpdir || os.tmpDir)(), 'watchify-' + Math.random());
|
||||
|
||||
var files = {
|
||||
main: path.join(tmpdir, 'main.js'),
|
||||
robot: path.join(tmpdir, 'robot.js'),
|
||||
lines: path.join(tmpdir, 'lines.txt'),
|
||||
bundle: path.join(tmpdir, 'bundle.js')
|
||||
};
|
||||
|
||||
var edits = [
|
||||
{ file: 'lines', source: 'robo-boogie' },
|
||||
{ file: 'lines', source: 'dinosaurus rex' },
|
||||
{
|
||||
file: 'robot',
|
||||
source: 'module.exports = function (n) { return n * 111 }',
|
||||
next: true
|
||||
},
|
||||
{ file: 'main', source: [
|
||||
'var fs = require("fs");',
|
||||
'var robot = require("./robot.js");',
|
||||
'var src = fs.readFileSync(__dirname + "/lines.txt", "utf8");',
|
||||
'console.log(src.toUpperCase() + " " + robot(src.length));'
|
||||
].join('\n') },
|
||||
{ file: 'lines', source: 't-rex' },
|
||||
{
|
||||
file: 'robot',
|
||||
source: 'module.exports = function (n) { return n * 100 }',
|
||||
}
|
||||
];
|
||||
|
||||
var expected = [
|
||||
'BEEP\nBOOP\n',
|
||||
'ROBO-BOOGIE\n',
|
||||
'DINOSAURUS REX\n',
|
||||
'DINOSAURUS REX 1554\n',
|
||||
'T-REX 555\n',
|
||||
'T-REX 500\n'
|
||||
];
|
||||
|
||||
mkdirp.sync(tmpdir);
|
||||
fs.writeFileSync(files.main, [
|
||||
'var fs = require("fs");',
|
||||
'var src = fs.readFileSync(__dirname + "/lines.txt", "utf8");',
|
||||
'console.log(src.toUpperCase());'
|
||||
].join('\n'));
|
||||
fs.writeFileSync(files.lines, 'beep\nboop');
|
||||
|
||||
test('many immediate', function (t) {
|
||||
t.plan(expected.length * 2 + edits.length);
|
||||
var ps = spawn(cmd, [
|
||||
files.main,
|
||||
'-t', require.resolve('brfs'), '-v',
|
||||
'-o', files.bundle
|
||||
]);
|
||||
ps.stdout.pipe(process.stdout);
|
||||
ps.stderr.pipe(process.stdout);
|
||||
var lineNum = 0;
|
||||
ps.stderr.pipe(split()).on('data', function (line) {
|
||||
if (line.length === 0) return;
|
||||
|
||||
run(files.bundle, function (err, output) {
|
||||
t.ifError(err);
|
||||
t.equal(output, expected.shift());
|
||||
|
||||
(function next () {
|
||||
if (edits.length === 0) return;
|
||||
var edit = edits.shift();
|
||||
fs.writeFile(files[edit.file], edit.source, function (err) {
|
||||
t.ifError(err);
|
||||
if (edit.next) next();
|
||||
});
|
||||
})();
|
||||
})
|
||||
});
|
||||
|
||||
t.on('end', function () {
|
||||
ps.kill();
|
||||
});
|
||||
});
|
||||
|
||||
function run (file, cb) {
|
||||
var ps = spawn(process.execPath, [ file ]);
|
||||
var data = [];
|
||||
ps.stdout.on('data', function (buf) { data.push(buf) });
|
||||
ps.stdout.on('end', function () {
|
||||
cb(null, Buffer.concat(data).toString('utf8'));
|
||||
});
|
||||
ps.on('error', cb);
|
||||
return ps;
|
||||
}
|
||||
10
node_modules/watchify/test/zzz.js
generated
vendored
Normal file
10
node_modules/watchify/test/zzz.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var test = require('tape');
|
||||
|
||||
test('__END__', function (t) {
|
||||
t.on('end', function () {
|
||||
setTimeout(function () {
|
||||
process.exit(0);
|
||||
}, 100)
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user