Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

18
static/js/ketcher2/node_modules/watchify/LICENSE generated vendored Normal file
View 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
static/js/ketcher2/node_modules/watchify/bin/args.js generated vendored Normal file
View 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
static/js/ketcher2/node_modules/watchify/bin/cmd.js generated vendored Executable file
View 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);
});
}

View File

@ -0,0 +1,2 @@
var one = require('./one');
console.log(one(5));

View File

@ -0,0 +1,3 @@
var two = require('./two');
module.exports = function (x) { return x * two(x + 5) };

View File

@ -0,0 +1 @@
module.exports = function (n) { return n * 11 };

165
static/js/ketcher2/node_modules/watchify/index.js generated vendored Normal file
View 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;
}

76
static/js/ketcher2/node_modules/watchify/package.json generated vendored Normal file
View File

@ -0,0 +1,76 @@
{
"_from": "watchify@^3.3.1",
"_id": "watchify@3.9.0",
"_inBundle": false,
"_integrity": "sha1-8HX9LoqGrN6Eztum5cKgvt1SPZ4=",
"_location": "/watchify",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "watchify@^3.3.1",
"name": "watchify",
"escapedName": "watchify",
"rawSpec": "^3.3.1",
"saveSpec": null,
"fetchSpec": "^3.3.1"
},
"_requiredBy": [
"/watchify-middleware"
],
"_resolved": "https://registry.npmjs.org/watchify/-/watchify-3.9.0.tgz",
"_shasum": "f075fd2e8a86acde84cedba6e5c2a0bedd523d9e",
"_spec": "watchify@^3.3.1",
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/watchify-middleware",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"bin": {
"watchify": "bin/cmd.js"
},
"bugs": {
"url": "https://github.com/substack/watchify/issues"
},
"bundleDependencies": false,
"dependencies": {
"anymatch": "^1.3.0",
"browserify": "^14.0.0",
"chokidar": "^1.0.0",
"defined": "^1.0.0",
"outpipe": "^1.1.0",
"through2": "^2.0.0",
"xtend": "^4.0.0"
},
"deprecated": false,
"description": "watch mode for browserify builds",
"devDependencies": {
"brfs": "^1.0.1",
"mkdirp": "~0.5.1",
"split": "^1.0.0",
"tape": "^4.2.2",
"uglify-js": "^2.5.0",
"win-spawn": "^2.0.0"
},
"homepage": "https://github.com/substack/watchify",
"keywords": [
"browserify",
"browserify-tool",
"watch",
"bundle",
"build",
"browser"
],
"license": "MIT",
"main": "index.js",
"name": "watchify",
"repository": {
"type": "git",
"url": "git://github.com/substack/watchify.git"
},
"scripts": {
"test": "tape test/*.js"
},
"version": "3.9.0"
}

View File

@ -0,0 +1,233 @@
# watchify
watch mode for [browserify](https://github.com/substack/node-browserify) builds
[![build status](https://secure.travis-ci.org/substack/watchify.png)](http://travis-ci.org/substack/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/substack/node-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/substack/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
`w.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().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(bundle, {
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.
# 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/substack/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.
# 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
static/js/ketcher2/node_modules/watchify/test/api.js generated vendored Normal file
View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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
static/js/ketcher2/node_modules/watchify/test/bin.js generated vendored Normal file
View 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(4);
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)');
})
}
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;
}

View 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(4);
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');
})
}
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;
}

View 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;
}

View 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;
}

View 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;
}

View 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(4);
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)');
});
}
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;
}

View 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();
}
});
});

View 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(4);
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)');
})
}
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;
}

View 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;
}

View 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;
}

View 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
static/js/ketcher2/node_modules/watchify/test/many.js generated vendored Normal file
View 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;
}

View 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
static/js/ketcher2/node_modules/watchify/test/zzz.js generated vendored Normal file
View 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();
});