MinsoftK

9

Showing 1000 changed files with 0 additions and 4904 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

1 -sauce_connect: true
2 -loopback: airtap.local
3 -browsers:
4 - - name: chrome
5 - version: latest
6 - - name: firefox
7 - version: latest
8 - - name: safari
9 - version: 9..latest
10 - - name: iphone
11 - version: latest
12 - - name: ie
13 - version: 9..latest
14 - - name: microsoftedge
15 - version: 13..latest
1 -# These are supported funding model platforms
2 -
3 -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 -patreon: # Replace with a single Patreon username
5 -open_collective: # Replace with a single Open Collective username
6 -ko_fi: # Replace with a single Ko-fi username
7 -tidelift: npm/events
8 -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 -liberapay: # Replace with a single Liberapay username
10 -issuehunt: # Replace with a single IssueHunt username
11 -otechie: # Replace with a single Otechie username
12 -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1 -dist: xenial
2 -os: linux
3 -language: node_js
4 -node_js:
5 - - 'stable'
6 - - 'lts/*'
7 - - '0.12'
8 -script:
9 - - npm test
10 - - if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_NODE_VERSION}" = "stable" ]; then npm run test:browsers; fi
11 -addons:
12 - sauce_connect: true
13 - hosts:
14 - - airtap.local
15 -env:
16 - global:
17 - - secure: XcBiD8yReflut9q7leKsigDZ0mI3qTKH+QrNVY8DaqlomJOZw8aOrVuX9Jz12l86ZJ41nbxmKnRNkFzcVr9mbP9YaeTb3DpeOBWmvaoSfud9Wnc16VfXtc1FCcwDhSVcSiM3UtnrmFU5cH+Dw1LPh5PbfylYOS/nJxUvG0FFLqI=
18 - - secure: jNWtEbqhUdQ0xXDHvCYfUbKYeJCi6a7B4LsrcxYCyWWn4NIgncE5x2YbB+FSUUFVYfz0dsn5RKP1oHB99f0laUEo18HBNkrAS/rtyOdVzcpJjbQ6kgSILGjnJD/Ty1B57Rcz3iyev5Y7bLZ6Y1FbDnk/i9/l0faOGz8vTC3Vdkc=
1 -# 3.2.0
2 -
3 - - Add `events.once` from Node.js 11.13.0.
4 -
5 - To use this function, Promises must be supported in the environment. Use a polyfill like `es6-promise` if you support older browsers.
6 -
7 -# 3.1.0 (2020-01-08)
8 -
9 -`events` now matches the Node.js 11.12.0 API.
10 -
11 - - pass through return value in wrapped `emitter.once()` listeners
12 -
13 - Now, this works:
14 - ```js
15 - emitter.once('myevent', function () { return 1; });
16 - var listener = emitter.rawListeners('myevent')[0]
17 - assert(listener() === 1);
18 - ```
19 - Previously, `listener()` would return undefined regardless of the implementation.
20 -
21 - Ported from https://github.com/nodejs/node/commit/acc506c2d2771dab8d7bba6d3452bc5180dff7cf
22 -
23 - - Reduce code duplication in listener type check ([#67](https://github.com/Gozala/events/pull/67) by [@friederbluemle](https://github.com/friederbluemle)).
24 - - Improve `emitter.once()` performance in some engines
25 -
26 -# 3.0.0 (2018-05-25)
27 -
28 -**This version drops support for IE8.** `events` no longer includes polyfills
29 -for ES5 features. If you need to support older environments, use an ES5 shim
30 -like [es5-shim](https://npmjs.com/package/es5-shim). Both the shim and sham
31 -versions of es5-shim are necessary.
32 -
33 - - Update to events code from Node.js 10.x
34 - - (semver major) Adds `off()` method
35 - - Port more tests from Node.js
36 - - Switch browser tests to airtap, making things more reliable
37 -
38 -# 2.1.0 (2018-05-25)
39 -
40 - - add Emitter#rawListeners from Node.js v9.4
41 -
42 -# 2.0.0 (2018-02-02)
43 -
44 - - Update to events code from node.js 8.x
45 - - Adds `prependListener()` and `prependOnceListener()`
46 - - Adds `eventNames()` method
47 - - (semver major) Unwrap `once()` listeners in `listeners()`
48 - - copy tests from node.js
49 -
50 -Note that this version doubles the gzipped size, jumping from 1.1KB to 2.1KB,
51 -due to new methods and runtime performance improvements. Be aware of that when
52 -upgrading.
53 -
54 -# 1.1.1 (2016-06-22)
55 -
56 - - add more context to errors if they are not instanceof Error
57 -
58 -# 1.1.0 (2015-09-29)
59 -
60 - - add Emitter#listerCount (to match node v4 api)
61 -
62 -# 1.0.2 (2014-08-28)
63 -
64 - - remove un-reachable code
65 - - update devDeps
66 -
67 -## 1.0.1 / 2014-05-11
68 -
69 - - check for console.trace before using it
70 -
71 -## 1.0.0 / 2013-12-10
72 -
73 - - Update to latest events code from node.js 0.10
74 - - copy tests from node.js
75 -
76 -## 0.4.0 / 2011-07-03 ##
77 -
78 - - Switching to graphquire@0.8.0
79 -
80 -## 0.3.0 / 2011-07-03 ##
81 -
82 - - Switching to URL based module require.
83 -
84 -## 0.2.0 / 2011-06-10 ##
85 -
86 - - Simplified package structure.
87 - - Graphquire for dependency management.
88 -
89 -## 0.1.1 / 2011-05-16 ##
90 -
91 - - Unhandled errors are logged via console.error
92 -
93 -## 0.1.0 / 2011-04-22 ##
94 -
95 - - Initial release
1 -MIT
2 -
3 -Copyright Joyent, Inc. and other Node contributors.
4 -
5 -Permission is hereby granted, free of charge, to any person obtaining a
6 -copy of this software and associated documentation files (the
7 -"Software"), to deal in the Software without restriction, including
8 -without limitation the rights to use, copy, modify, merge, publish,
9 -distribute, sublicense, and/or sell copies of the Software, and to permit
10 -persons to whom the Software is furnished to do so, subject to the
11 -following conditions:
12 -
13 -The above copyright notice and this permission notice shall be included
14 -in all copies or substantial portions of the Software.
15 -
16 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19 -NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 -USE OR OTHER DEALINGS IN THE SOFTWARE.
1 -# events [![Build Status](https://travis-ci.org/Gozala/events.png?branch=master)](https://travis-ci.org/Gozala/events)
2 -
3 -> Node's event emitter for all engines.
4 -
5 -This implements the Node.js [`events`][node.js docs] module for environments that do not have it, like browsers.
6 -
7 -> `events` currently matches the **Node.js 11.13.0** API.
8 -
9 -Note that the `events` module uses ES5 features. If you need to support very old browsers like IE8, use a shim like [`es5-shim`](https://www.npmjs.com/package/es5-shim). You need both the shim and the sham versions of `es5-shim`.
10 -
11 -This module is maintained, but only by very few people. If you'd like to help, let us know in the [Maintainer Needed](https://github.com/Gozala/events/issues/43) issue!
12 -
13 -## Install
14 -
15 -You usually do not have to install `events` yourself! If your code runs in Node.js, `events` is built in. If your code runs in the browser, bundlers like [browserify](https://github.com/browserify/browserify) or [webpack](https://github.com/webpack/webpack) also include the `events` module.
16 -
17 -But if none of those apply, with npm do:
18 -
19 -```
20 -npm install events
21 -```
22 -
23 -## Usage
24 -
25 -```javascript
26 -var EventEmitter = require('events')
27 -
28 -var ee = new EventEmitter()
29 -ee.on('message', function (text) {
30 - console.log(text)
31 -})
32 -ee.emit('message', 'hello world')
33 -```
34 -
35 -## API
36 -
37 -See the [Node.js EventEmitter docs][node.js docs]. `events` currently matches the Node.js 11.13.0 API.
38 -
39 -## Contributing
40 -
41 -PRs are very welcome! The main way to contribute to `events` is by porting features, bugfixes and tests from Node.js. Ideally, code contributions to this module are copy-pasted from Node.js and transpiled to ES5, rather than reimplemented from scratch. Matching the Node.js code as closely as possible makes maintenance simpler when new changes land in Node.js.
42 -This module intends to provide exactly the same API as Node.js, so features that are not available in the core `events` module will not be accepted. Feature requests should instead be directed at [nodejs/node](https://github.com/nodejs/node) and will be added to this module once they are implemented in Node.js.
43 -
44 -If there is a difference in behaviour between Node.js's `events` module and this module, please open an issue!
45 -
46 -## License
47 -
48 -[MIT](./LICENSE)
49 -[node.js docs]: https://nodejs.org/dist/v11.13.0/docs/api/events.html
This diff is collapsed. Click to expand it.
1 -{
2 - "_from": "events@^3.0.0",
3 - "_id": "events@3.2.0",
4 - "_inBundle": false,
5 - "_integrity": "sha512-/46HWwbfCX2xTawVfkKLGxMifJYQBWMwY1mjywRtb4c9x8l5NP3KoJtnIOiL1hfdRkIuYhETxQlo62IF8tcnlg==",
6 - "_location": "/events",
7 - "_phantomChildren": {},
8 - "_requested": {
9 - "type": "range",
10 - "registry": true,
11 - "raw": "events@^3.0.0",
12 - "name": "events",
13 - "escapedName": "events",
14 - "rawSpec": "^3.0.0",
15 - "saveSpec": null,
16 - "fetchSpec": "^3.0.0"
17 - },
18 - "_requiredBy": [
19 - "/node-libs-browser"
20 - ],
21 - "_resolved": "https://registry.npmjs.org/events/-/events-3.2.0.tgz",
22 - "_shasum": "93b87c18f8efcd4202a461aec4dfc0556b639379",
23 - "_spec": "events@^3.0.0",
24 - "_where": "C:\\Users\\kkwan_000\\Desktop\\git\\2017110269\\minsung\\node_modules\\node-libs-browser",
25 - "author": {
26 - "name": "Irakli Gozalishvili",
27 - "email": "rfobic@gmail.com",
28 - "url": "http://jeditoolkit.com"
29 - },
30 - "bugs": {
31 - "url": "http://github.com/Gozala/events/issues/"
32 - },
33 - "bundleDependencies": false,
34 - "deprecated": false,
35 - "description": "Node's event emitter for all engines.",
36 - "devDependencies": {
37 - "airtap": "^1.0.0",
38 - "functions-have-names": "^1.2.1",
39 - "has-symbols": "^1.0.1",
40 - "isarray": "^2.0.5",
41 - "tape": "^5.0.0"
42 - },
43 - "engines": {
44 - "node": ">=0.8.x"
45 - },
46 - "homepage": "https://github.com/Gozala/events#readme",
47 - "keywords": [
48 - "events",
49 - "eventEmitter",
50 - "eventDispatcher",
51 - "listeners"
52 - ],
53 - "license": "MIT",
54 - "main": "./events.js",
55 - "name": "events",
56 - "repository": {
57 - "type": "git",
58 - "url": "git://github.com/Gozala/events.git",
59 - "web": "https://github.com/Gozala/events"
60 - },
61 - "scripts": {
62 - "test": "node tests/index.js",
63 - "test:browsers": "airtap -- tests/index.js"
64 - },
65 - "version": "3.2.0"
66 -}
1 -# Security Policy
2 -
3 -## Supported Versions
4 -Only the latest major version is supported at any given time.
5 -
6 -## Reporting a Vulnerability
7 -
8 -To report a security vulnerability, please use the
9 -[Tidelift security contact](https://tidelift.com/security).
10 -Tidelift will coordinate the fix and disclosure.
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var assert = require('assert');
24 -var EventEmitter = require('../');
25 -
26 -{
27 - var ee = new EventEmitter();
28 - var events_new_listener_emitted = [];
29 - var listeners_new_listener_emitted = [];
30 -
31 - // Sanity check
32 - assert.strictEqual(ee.addListener, ee.on);
33 -
34 - ee.on('newListener', function(event, listener) {
35 - // Don't track newListener listeners.
36 - if (event === 'newListener')
37 - return;
38 -
39 - events_new_listener_emitted.push(event);
40 - listeners_new_listener_emitted.push(listener);
41 - });
42 -
43 - var hello = common.mustCall(function(a, b) {
44 - assert.strictEqual('a', a);
45 - assert.strictEqual('b', b);
46 - });
47 -
48 - ee.once('newListener', function(name, listener) {
49 - assert.strictEqual(name, 'hello');
50 - assert.strictEqual(listener, hello);
51 -
52 - var listeners = this.listeners('hello');
53 - assert.ok(Array.isArray(listeners));
54 - assert.strictEqual(listeners.length, 0);
55 - });
56 -
57 - ee.on('hello', hello);
58 - ee.once('foo', assert.fail);
59 -
60 - assert.ok(Array.isArray(events_new_listener_emitted));
61 - assert.strictEqual(events_new_listener_emitted.length, 2);
62 - assert.strictEqual(events_new_listener_emitted[0], 'hello');
63 - assert.strictEqual(events_new_listener_emitted[1], 'foo');
64 -
65 - assert.ok(Array.isArray(listeners_new_listener_emitted));
66 - assert.strictEqual(listeners_new_listener_emitted.length, 2);
67 - assert.strictEqual(listeners_new_listener_emitted[0], hello);
68 - assert.strictEqual(listeners_new_listener_emitted[1], assert.fail);
69 -
70 - ee.emit('hello', 'a', 'b');
71 -}
72 -
73 -// just make sure that this doesn't throw:
74 -{
75 - var f = new EventEmitter();
76 -
77 - f.setMaxListeners(0);
78 -}
79 -
80 -{
81 - var listen1 = function() {};
82 - var listen2 = function() {};
83 - var ee = new EventEmitter();
84 -
85 - ee.once('newListener', function() {
86 - var listeners = ee.listeners('hello');
87 - assert.ok(Array.isArray(listeners));
88 - assert.strictEqual(listeners.length, 0);
89 - ee.once('newListener', function() {
90 - var listeners = ee.listeners('hello');
91 - assert.ok(Array.isArray(listeners));
92 - assert.strictEqual(listeners.length, 0);
93 - });
94 - ee.on('hello', listen2);
95 - });
96 - ee.on('hello', listen1);
97 - // The order of listeners on an event is not always the order in which the
98 - // listeners were added.
99 - var listeners = ee.listeners('hello');
100 - assert.ok(Array.isArray(listeners));
101 - assert.strictEqual(listeners.length, 2);
102 - assert.strictEqual(listeners[0], listen2);
103 - assert.strictEqual(listeners[1], listen1);
104 -}
105 -
106 -// Verify that the listener must be a function
107 -assert.throws(function() {
108 - var ee = new EventEmitter();
109 -
110 - ee.on('foo', null);
111 -}, /^TypeError: The "listener" argument must be of type Function. Received type object$/);
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -
26 -// Redirect warning output to tape.
27 -var consoleWarn = console.warn;
28 -console.warn = common.test.comment;
29 -
30 -common.test.on('end', function () {
31 - console.warn = consoleWarn;
32 -});
33 -
34 -// default
35 -{
36 - var e = new events.EventEmitter();
37 -
38 - for (var i = 0; i < 10; i++) {
39 - e.on('default', common.mustNotCall());
40 - }
41 - assert.ok(!e._events['default'].hasOwnProperty('warned'));
42 - e.on('default', common.mustNotCall());
43 - assert.ok(e._events['default'].warned);
44 -
45 - // specific
46 - e.setMaxListeners(5);
47 - for (var i = 0; i < 5; i++) {
48 - e.on('specific', common.mustNotCall());
49 - }
50 - assert.ok(!e._events['specific'].hasOwnProperty('warned'));
51 - e.on('specific', common.mustNotCall());
52 - assert.ok(e._events['specific'].warned);
53 -
54 - // only one
55 - e.setMaxListeners(1);
56 - e.on('only one', common.mustNotCall());
57 - assert.ok(!e._events['only one'].hasOwnProperty('warned'));
58 - e.on('only one', common.mustNotCall());
59 - assert.ok(e._events['only one'].hasOwnProperty('warned'));
60 -
61 - // unlimited
62 - e.setMaxListeners(0);
63 - for (var i = 0; i < 1000; i++) {
64 - e.on('unlimited', common.mustNotCall());
65 - }
66 - assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
67 -}
68 -
69 -// process-wide
70 -{
71 - events.EventEmitter.defaultMaxListeners = 42;
72 - var e = new events.EventEmitter();
73 -
74 - for (var i = 0; i < 42; ++i) {
75 - e.on('fortytwo', common.mustNotCall());
76 - }
77 - assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
78 - e.on('fortytwo', common.mustNotCall());
79 - assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
80 - delete e._events['fortytwo'].warned;
81 -
82 - events.EventEmitter.defaultMaxListeners = 44;
83 - e.on('fortytwo', common.mustNotCall());
84 - assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
85 - e.on('fortytwo', common.mustNotCall());
86 - assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
87 -}
88 -
89 -// but _maxListeners still has precedence over defaultMaxListeners
90 -{
91 - events.EventEmitter.defaultMaxListeners = 42;
92 - var e = new events.EventEmitter();
93 - e.setMaxListeners(1);
94 - e.on('uno', common.mustNotCall());
95 - assert.ok(!e._events['uno'].hasOwnProperty('warned'));
96 - e.on('uno', common.mustNotCall());
97 - assert.ok(e._events['uno'].hasOwnProperty('warned'));
98 -
99 - // chainable
100 - assert.strictEqual(e, e.setMaxListeners(1));
101 -}
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var test = require('tape');
23 -var assert = require('assert');
24 -
25 -var noop = function() {};
26 -
27 -var mustCallChecks = [];
28 -
29 -function runCallChecks(exitCode) {
30 - if (exitCode !== 0) return;
31 -
32 - var failed = filter(mustCallChecks, function(context) {
33 - if ('minimum' in context) {
34 - context.messageSegment = 'at least ' + context.minimum;
35 - return context.actual < context.minimum;
36 - } else {
37 - context.messageSegment = 'exactly ' + context.exact;
38 - return context.actual !== context.exact;
39 - }
40 - });
41 -
42 - for (var i = 0; i < failed.length; i++) {
43 - var context = failed[i];
44 - console.log('Mismatched %s function calls. Expected %s, actual %d.',
45 - context.name,
46 - context.messageSegment,
47 - context.actual);
48 - // IE8 has no .stack
49 - if (context.stack) console.log(context.stack.split('\n').slice(2).join('\n'));
50 - }
51 -
52 - assert.strictEqual(failed.length, 0);
53 -}
54 -
55 -exports.mustCall = function(fn, exact) {
56 - return _mustCallInner(fn, exact, 'exact');
57 -};
58 -
59 -function _mustCallInner(fn, criteria, field) {
60 - if (typeof criteria == 'undefined') criteria = 1;
61 -
62 - if (typeof fn === 'number') {
63 - criteria = fn;
64 - fn = noop;
65 - } else if (fn === undefined) {
66 - fn = noop;
67 - }
68 -
69 - if (typeof criteria !== 'number')
70 - throw new TypeError('Invalid ' + field + ' value: ' + criteria);
71 -
72 - var context = {
73 - actual: 0,
74 - stack: (new Error()).stack,
75 - name: fn.name || '<anonymous>'
76 - };
77 -
78 - context[field] = criteria;
79 -
80 - // add the exit listener only once to avoid listener leak warnings
81 - if (mustCallChecks.length === 0) test.onFinish(function() { runCallChecks(0); });
82 -
83 - mustCallChecks.push(context);
84 -
85 - return function() {
86 - context.actual++;
87 - return fn.apply(this, arguments);
88 - };
89 -}
90 -
91 -exports.mustNotCall = function(msg) {
92 - return function mustNotCall() {
93 - assert.fail(msg || 'function should not have been called');
94 - };
95 -};
96 -
97 -function filter(arr, fn) {
98 - if (arr.filter) return arr.filter(fn);
99 - var filtered = [];
100 - for (var i = 0; i < arr.length; i++) {
101 - if (fn(arr[i], i, arr)) filtered.push(arr[i]);
102 - }
103 - return filtered
104 -}
1 -'use strict';
2 -var assert = require('assert');
3 -var EventEmitter = require('../');
4 -
5 -var EE = new EventEmitter();
6 -
7 -assert.throws(function () {
8 - EE.emit('error', 'Accepts a string');
9 -}, 'Error: Unhandled error. (Accepts a string)');
10 -
11 -assert.throws(function () {
12 - EE.emit('error', { message: 'Error!' });
13 -}, 'Unhandled error. ([object Object])');
1 -'use strict';
2 -
3 -var EventEmitter = require('../');
4 -var assert = require('assert');
5 -
6 -var EE = new EventEmitter();
7 -var m = function() {};
8 -EE.on('foo', function() {});
9 -assert.equal(1, EE.eventNames().length);
10 -assert.equal('foo', EE.eventNames()[0]);
11 -EE.on('bar', m);
12 -assert.equal(2, EE.eventNames().length);
13 -assert.equal('foo', EE.eventNames()[0]);
14 -assert.equal('bar', EE.eventNames()[1]);
15 -EE.removeListener('bar', m);
16 -assert.equal(1, EE.eventNames().length);
17 -assert.equal('foo', EE.eventNames()[0]);
18 -
19 -if (typeof Symbol !== 'undefined') {
20 - var s = Symbol('s');
21 - EE.on(s, m);
22 - assert.equal(2, EE.eventNames().length);
23 - assert.equal('foo', EE.eventNames()[0]);
24 - assert.equal(s, EE.eventNames()[1]);
25 - EE.removeListener(s, m);
26 - assert.equal(1, EE.eventNames().length);
27 - assert.equal('foo', EE.eventNames()[0]);
28 -}
1 -'use strict';
2 -
3 -var common = require('./common');
4 -var EventEmitter = require('../').EventEmitter;
5 -var once = require('../').once;
6 -var assert = require('assert');
7 -
8 -function onceAnEvent() {
9 - var ee = new EventEmitter();
10 -
11 - process.nextTick(function () {
12 - ee.emit('myevent', 42);
13 - });
14 -
15 - return once(ee, 'myevent').then(function (args) {
16 - var value = args[0]
17 - assert.strictEqual(value, 42);
18 - assert.strictEqual(ee.listenerCount('error'), 0);
19 - assert.strictEqual(ee.listenerCount('myevent'), 0);
20 - });
21 -}
22 -
23 -function onceAnEventWithTwoArgs() {
24 - var ee = new EventEmitter();
25 -
26 - process.nextTick(function () {
27 - ee.emit('myevent', 42, 24);
28 - });
29 -
30 - return once(ee, 'myevent').then(function (value) {
31 - assert.strictEqual(value.length, 2);
32 - assert.strictEqual(value[0], 42);
33 - assert.strictEqual(value[1], 24);
34 - });
35 -}
36 -
37 -function catchesErrors() {
38 - var ee = new EventEmitter();
39 -
40 - var expected = new Error('kaboom');
41 - var err;
42 - process.nextTick(function () {
43 - ee.emit('error', expected);
44 - });
45 -
46 - return once(ee, 'myevent').then(function () {
47 - throw new Error('should reject')
48 - }, function (err) {
49 - assert.strictEqual(err, expected);
50 - assert.strictEqual(ee.listenerCount('error'), 0);
51 - assert.strictEqual(ee.listenerCount('myevent'), 0);
52 - });
53 -}
54 -
55 -function stopListeningAfterCatchingError() {
56 - var ee = new EventEmitter();
57 -
58 - var expected = new Error('kaboom');
59 - var err;
60 - process.nextTick(function () {
61 - ee.emit('error', expected);
62 - ee.emit('myevent', 42, 24);
63 - });
64 -
65 - // process.on('multipleResolves', common.mustNotCall());
66 -
67 - return once(ee, 'myevent').then(common.mustNotCall, function (err) {
68 - // process.removeAllListeners('multipleResolves');
69 - assert.strictEqual(err, expected);
70 - assert.strictEqual(ee.listenerCount('error'), 0);
71 - assert.strictEqual(ee.listenerCount('myevent'), 0);
72 - });
73 -}
74 -
75 -function onceError() {
76 - var ee = new EventEmitter();
77 -
78 - var expected = new Error('kaboom');
79 - process.nextTick(function () {
80 - ee.emit('error', expected);
81 - });
82 -
83 - return once(ee, 'error').then(function (args) {
84 - var err = args[0]
85 - assert.strictEqual(err, expected);
86 - assert.strictEqual(ee.listenerCount('error'), 0);
87 - assert.strictEqual(ee.listenerCount('myevent'), 0);
88 - });
89 -}
90 -
91 -Promise.all([
92 - onceAnEvent(),
93 - onceAnEventWithTwoArgs(),
94 - catchesErrors(),
95 - stopListeningAfterCatchingError(),
96 - onceError()
97 -]).catch(function (err) {
98 - console.error(err.stack)
99 - process.exit(1)
100 -});
1 -var test = require('tape');
2 -var functionsHaveNames = require('functions-have-names');
3 -var hasSymbols = require('has-symbols');
4 -
5 -require('./legacy-compat');
6 -var common = require('./common');
7 -
8 -// we do this to easily wrap each file in a mocha test
9 -// and also have browserify be able to statically analyze this file
10 -var orig_require = require;
11 -var require = function(file) {
12 - test(file, function(t) {
13 - // Store the tape object so tests can access it.
14 - t.on('end', function () { delete common.test; });
15 - common.test = t;
16 -
17 - try { orig_require(file); } catch (err) { t.fail(err); }
18 - t.end();
19 - });
20 -};
21 -
22 -require('./add-listeners.js');
23 -require('./check-listener-leaks.js');
24 -require('./errors.js');
25 -require('./events-list.js');
26 -if (typeof Promise === 'function') {
27 - require('./events-once.js');
28 -} else {
29 - // Promise support is not available.
30 - test('./events-once.js', { skip: true }, function () {});
31 -}
32 -require('./listener-count.js');
33 -require('./listeners-side-effects.js');
34 -require('./listeners.js');
35 -require('./max-listeners.js');
36 -if (functionsHaveNames()) {
37 - require('./method-names.js');
38 -} else {
39 - // Function.name is not supported in IE
40 - test('./method-names.js', { skip: true }, function () {});
41 -}
42 -require('./modify-in-emit.js');
43 -require('./num-args.js');
44 -require('./once.js');
45 -require('./prepend.js');
46 -require('./set-max-listeners-side-effects.js');
47 -require('./special-event-names.js');
48 -require('./subclass.js');
49 -if (hasSymbols()) {
50 - require('./symbols.js');
51 -} else {
52 - // Symbol is not available.
53 - test('./symbols.js', { skip: true }, function () {});
54 -}
55 -require('./remove-all-listeners.js');
56 -require('./remove-listeners.js');
1 -// sigh... life is hard
2 -if (!global.console) {
3 - console = {}
4 -}
5 -
6 -var fns = ['log', 'error', 'trace'];
7 -for (var i=0 ; i<fns.length ; ++i) {
8 - var fn = fns[i];
9 - if (!console[fn]) {
10 - console[fn] = function() {};
11 - }
12 -}
13 -
14 -if (!Array.isArray) {
15 - Array.isArray = require('isarray');
16 -}
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -require('./common');
23 -var assert = require('assert');
24 -var EventEmitter = require('../');
25 -
26 -var emitter = new EventEmitter();
27 -emitter.on('foo', function() {});
28 -emitter.on('foo', function() {});
29 -emitter.on('baz', function() {});
30 -// Allow any type
31 -emitter.on(123, function() {});
32 -
33 -assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2);
34 -assert.strictEqual(emitter.listenerCount('foo'), 2);
35 -assert.strictEqual(emitter.listenerCount('bar'), 0);
36 -assert.strictEqual(emitter.listenerCount('baz'), 1);
37 -assert.strictEqual(emitter.listenerCount(123), 1);
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -require('./common');
23 -var assert = require('assert');
24 -
25 -var EventEmitter = require('../').EventEmitter;
26 -
27 -var e = new EventEmitter();
28 -var fl; // foo listeners
29 -
30 -fl = e.listeners('foo');
31 -assert.ok(Array.isArray(fl));
32 -assert.strictEqual(fl.length, 0);
33 -if (Object.create) assert.ok(!(e._events instanceof Object));
34 -assert.strictEqual(Object.keys(e._events).length, 0);
35 -
36 -e.on('foo', assert.fail);
37 -fl = e.listeners('foo');
38 -assert.strictEqual(e._events.foo, assert.fail);
39 -assert.ok(Array.isArray(fl));
40 -assert.strictEqual(fl.length, 1);
41 -assert.strictEqual(fl[0], assert.fail);
42 -
43 -e.listeners('bar');
44 -
45 -e.on('foo', assert.ok);
46 -fl = e.listeners('foo');
47 -
48 -assert.ok(Array.isArray(e._events.foo));
49 -assert.strictEqual(e._events.foo.length, 2);
50 -assert.strictEqual(e._events.foo[0], assert.fail);
51 -assert.strictEqual(e._events.foo[1], assert.ok);
52 -
53 -assert.ok(Array.isArray(fl));
54 -assert.strictEqual(fl.length, 2);
55 -assert.strictEqual(fl[0], assert.fail);
56 -assert.strictEqual(fl[1], assert.ok);
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -var util = require('util');
26 -
27 -function listener() {}
28 -function listener2() {}
29 -function listener3() {
30 - return 0;
31 -}
32 -function listener4() {
33 - return 1;
34 -}
35 -
36 -function TestStream() {}
37 -util.inherits(TestStream, events.EventEmitter);
38 -
39 -{
40 - var ee = new events.EventEmitter();
41 - ee.on('foo', listener);
42 - var fooListeners = ee.listeners('foo');
43 -
44 - var listeners = ee.listeners('foo');
45 - assert.ok(Array.isArray(listeners));
46 - assert.strictEqual(listeners.length, 1);
47 - assert.strictEqual(listeners[0], listener);
48 -
49 - ee.removeAllListeners('foo');
50 - listeners = ee.listeners('foo');
51 - assert.ok(Array.isArray(listeners));
52 - assert.strictEqual(listeners.length, 0);
53 -
54 - assert.ok(Array.isArray(fooListeners));
55 - assert.strictEqual(fooListeners.length, 1);
56 - assert.strictEqual(fooListeners[0], listener);
57 -}
58 -
59 -{
60 - var ee = new events.EventEmitter();
61 - ee.on('foo', listener);
62 -
63 - var eeListenersCopy = ee.listeners('foo');
64 - assert.ok(Array.isArray(eeListenersCopy));
65 - assert.strictEqual(eeListenersCopy.length, 1);
66 - assert.strictEqual(eeListenersCopy[0], listener);
67 -
68 - var listeners = ee.listeners('foo');
69 - assert.ok(Array.isArray(listeners));
70 - assert.strictEqual(listeners.length, 1);
71 - assert.strictEqual(listeners[0], listener);
72 -
73 - eeListenersCopy.push(listener2);
74 - listeners = ee.listeners('foo');
75 -
76 - assert.ok(Array.isArray(listeners));
77 - assert.strictEqual(listeners.length, 1);
78 - assert.strictEqual(listeners[0], listener);
79 -
80 - assert.strictEqual(eeListenersCopy.length, 2);
81 - assert.strictEqual(eeListenersCopy[0], listener);
82 - assert.strictEqual(eeListenersCopy[1], listener2);
83 -}
84 -
85 -{
86 - var ee = new events.EventEmitter();
87 - ee.on('foo', listener);
88 - var eeListenersCopy = ee.listeners('foo');
89 - ee.on('foo', listener2);
90 -
91 - var listeners = ee.listeners('foo');
92 - assert.ok(Array.isArray(listeners));
93 - assert.strictEqual(listeners.length, 2);
94 - assert.strictEqual(listeners[0], listener);
95 - assert.strictEqual(listeners[1], listener2);
96 -
97 - assert.ok(Array.isArray(eeListenersCopy));
98 - assert.strictEqual(eeListenersCopy.length, 1);
99 - assert.strictEqual(eeListenersCopy[0], listener);
100 -}
101 -
102 -{
103 - var ee = new events.EventEmitter();
104 - ee.once('foo', listener);
105 - var listeners = ee.listeners('foo');
106 - assert.ok(Array.isArray(listeners));
107 - assert.strictEqual(listeners.length, 1);
108 - assert.strictEqual(listeners[0], listener);
109 -}
110 -
111 -{
112 - var ee = new events.EventEmitter();
113 - ee.on('foo', listener);
114 - ee.once('foo', listener2);
115 -
116 - var listeners = ee.listeners('foo');
117 - assert.ok(Array.isArray(listeners));
118 - assert.strictEqual(listeners.length, 2);
119 - assert.strictEqual(listeners[0], listener);
120 - assert.strictEqual(listeners[1], listener2);
121 -}
122 -
123 -{
124 - var ee = new events.EventEmitter();
125 - ee._events = undefined;
126 - var listeners = ee.listeners('foo');
127 - assert.ok(Array.isArray(listeners));
128 - assert.strictEqual(listeners.length, 0);
129 -}
130 -
131 -{
132 - var s = new TestStream();
133 - var listeners = s.listeners('foo');
134 - assert.ok(Array.isArray(listeners));
135 - assert.strictEqual(listeners.length, 0);
136 -}
137 -
138 -
139 -{
140 - var ee = new events.EventEmitter();
141 - ee.on('foo', listener);
142 - var wrappedListener = ee.rawListeners('foo');
143 - assert.strictEqual(wrappedListener.length, 1);
144 - assert.strictEqual(wrappedListener[0], listener);
145 - assert.notStrictEqual(wrappedListener, ee.rawListeners('foo'));
146 - ee.once('foo', listener);
147 - var wrappedListeners = ee.rawListeners('foo');
148 - assert.strictEqual(wrappedListeners.length, 2);
149 - assert.strictEqual(wrappedListeners[0], listener);
150 - assert.notStrictEqual(wrappedListeners[1], listener);
151 - assert.strictEqual(wrappedListeners[1].listener, listener);
152 - assert.notStrictEqual(wrappedListeners, ee.rawListeners('foo'));
153 - ee.emit('foo');
154 - assert.strictEqual(wrappedListeners.length, 2);
155 - assert.strictEqual(wrappedListeners[1].listener, listener);
156 -}
157 -
158 -{
159 - var ee = new events.EventEmitter();
160 - ee.once('foo', listener3);
161 - ee.on('foo', listener4);
162 - var rawListeners = ee.rawListeners('foo');
163 - assert.strictEqual(rawListeners.length, 2);
164 - assert.strictEqual(rawListeners[0](), 0);
165 - var rawListener = ee.rawListeners('foo');
166 - assert.strictEqual(rawListener.length, 1);
167 - assert.strictEqual(rawListener[0](), 1);
168 -}
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -var e = new events.EventEmitter();
26 -
27 -var hasDefineProperty = !!Object.defineProperty;
28 -try { Object.defineProperty({}, 'x', { value: 0 }); } catch (err) { hasDefineProperty = false }
29 -
30 -e.on('maxListeners', common.mustCall());
31 -
32 -// Should not corrupt the 'maxListeners' queue.
33 -e.setMaxListeners(42);
34 -
35 -var throwsObjs = [NaN, -1, 'and even this'];
36 -var maxError = /^RangeError: The value of "n" is out of range\. It must be a non-negative number\./;
37 -var defError = /^RangeError: The value of "defaultMaxListeners" is out of range\. It must be a non-negative number\./;
38 -
39 -for (var i = 0; i < throwsObjs.length; i++) {
40 - var obj = throwsObjs[i];
41 - assert.throws(function() { e.setMaxListeners(obj); }, maxError);
42 - if (hasDefineProperty) {
43 - assert.throws(function() { events.defaultMaxListeners = obj; }, defError);
44 - }
45 -}
46 -
47 -e.emit('maxListeners');
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -'use strict';
23 -require('./common');
24 -var assert = require('assert');
25 -var events = require('../');
26 -
27 -var E = events.EventEmitter.prototype;
28 -assert.strictEqual(E.constructor.name, 'EventEmitter');
29 -assert.strictEqual(E.on, E.addListener); // Same method.
30 -assert.strictEqual(E.off, E.removeListener); // Same method.
31 -Object.getOwnPropertyNames(E).forEach(function(name) {
32 - if (name === 'constructor' || name === 'on' || name === 'off') return;
33 - if (typeof E[name] !== 'function') return;
34 - assert.strictEqual(E[name].name, name);
35 -});
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -
26 -var callbacks_called = [];
27 -
28 -var e = new events.EventEmitter();
29 -
30 -function callback1() {
31 - callbacks_called.push('callback1');
32 - e.on('foo', callback2);
33 - e.on('foo', callback3);
34 - e.removeListener('foo', callback1);
35 -}
36 -
37 -function callback2() {
38 - callbacks_called.push('callback2');
39 - e.removeListener('foo', callback2);
40 -}
41 -
42 -function callback3() {
43 - callbacks_called.push('callback3');
44 - e.removeListener('foo', callback3);
45 -}
46 -
47 -e.on('foo', callback1);
48 -assert.strictEqual(e.listeners('foo').length, 1);
49 -
50 -e.emit('foo');
51 -assert.strictEqual(e.listeners('foo').length, 2);
52 -assert.ok(Array.isArray(callbacks_called));
53 -assert.strictEqual(callbacks_called.length, 1);
54 -assert.strictEqual(callbacks_called[0], 'callback1');
55 -
56 -e.emit('foo');
57 -assert.strictEqual(e.listeners('foo').length, 0);
58 -assert.ok(Array.isArray(callbacks_called));
59 -assert.strictEqual(callbacks_called.length, 3);
60 -assert.strictEqual(callbacks_called[0], 'callback1');
61 -assert.strictEqual(callbacks_called[1], 'callback2');
62 -assert.strictEqual(callbacks_called[2], 'callback3');
63 -
64 -e.emit('foo');
65 -assert.strictEqual(e.listeners('foo').length, 0);
66 -assert.ok(Array.isArray(callbacks_called));
67 -assert.strictEqual(callbacks_called.length, 3);
68 -assert.strictEqual(callbacks_called[0], 'callback1');
69 -assert.strictEqual(callbacks_called[1], 'callback2');
70 -assert.strictEqual(callbacks_called[2], 'callback3');
71 -
72 -e.on('foo', callback1);
73 -e.on('foo', callback2);
74 -assert.strictEqual(e.listeners('foo').length, 2);
75 -e.removeAllListeners('foo');
76 -assert.strictEqual(e.listeners('foo').length, 0);
77 -
78 -// Verify that removing callbacks while in emit allows emits to propagate to
79 -// all listeners
80 -callbacks_called = [];
81 -
82 -e.on('foo', callback2);
83 -e.on('foo', callback3);
84 -assert.strictEqual(2, e.listeners('foo').length);
85 -e.emit('foo');
86 -assert.ok(Array.isArray(callbacks_called));
87 -assert.strictEqual(callbacks_called.length, 2);
88 -assert.strictEqual(callbacks_called[0], 'callback2');
89 -assert.strictEqual(callbacks_called[1], 'callback3');
90 -assert.strictEqual(0, e.listeners('foo').length);
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -
26 -var e = new events.EventEmitter();
27 -var num_args_emitted = [];
28 -
29 -e.on('numArgs', function() {
30 - var numArgs = arguments.length;
31 - num_args_emitted.push(numArgs);
32 -});
33 -
34 -e.on('foo', function() {
35 - num_args_emitted.push(arguments.length);
36 -});
37 -
38 -e.on('foo', function() {
39 - num_args_emitted.push(arguments.length);
40 -});
41 -
42 -e.emit('numArgs');
43 -e.emit('numArgs', null);
44 -e.emit('numArgs', null, null);
45 -e.emit('numArgs', null, null, null);
46 -e.emit('numArgs', null, null, null, null);
47 -e.emit('numArgs', null, null, null, null, null);
48 -
49 -e.emit('foo', null, null, null, null);
50 -
51 -assert.ok(Array.isArray(num_args_emitted));
52 -assert.strictEqual(num_args_emitted.length, 8);
53 -assert.strictEqual(num_args_emitted[0], 0);
54 -assert.strictEqual(num_args_emitted[1], 1);
55 -assert.strictEqual(num_args_emitted[2], 2);
56 -assert.strictEqual(num_args_emitted[3], 3);
57 -assert.strictEqual(num_args_emitted[4], 4);
58 -assert.strictEqual(num_args_emitted[5], 5);
59 -assert.strictEqual(num_args_emitted[6], 4);
60 -assert.strictEqual(num_args_emitted[6], 4);
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var assert = require('assert');
24 -var EventEmitter = require('../');
25 -
26 -var e = new EventEmitter();
27 -
28 -e.once('hello', common.mustCall());
29 -
30 -e.emit('hello', 'a', 'b');
31 -e.emit('hello', 'a', 'b');
32 -e.emit('hello', 'a', 'b');
33 -e.emit('hello', 'a', 'b');
34 -
35 -function remove() {
36 - assert.fail('once->foo should not be emitted');
37 -}
38 -
39 -e.once('foo', remove);
40 -e.removeListener('foo', remove);
41 -e.emit('foo');
42 -
43 -e.once('e', common.mustCall(function() {
44 - e.emit('e');
45 -}));
46 -
47 -e.once('e', common.mustCall());
48 -
49 -e.emit('e');
50 -
51 -// Verify that the listener must be a function
52 -assert.throws(function() {
53 - var ee = new EventEmitter();
54 -
55 - ee.once('foo', null);
56 -}, /^TypeError: The "listener" argument must be of type Function. Received type object$/);
57 -
58 -{
59 - // once() has different code paths based on the number of arguments being
60 - // emitted. Verify that all of the cases are covered.
61 - var maxArgs = 4;
62 -
63 - for (var i = 0; i <= maxArgs; ++i) {
64 - var ee = new EventEmitter();
65 - var args = ['foo'];
66 -
67 - for (var j = 0; j < i; ++j)
68 - args.push(j);
69 -
70 - ee.once('foo', common.mustCall(function() {
71 - var params = Array.prototype.slice.call(arguments);
72 - var restArgs = args.slice(1);
73 - assert.ok(Array.isArray(params));
74 - assert.strictEqual(params.length, restArgs.length);
75 - for (var index = 0; index < params.length; index++) {
76 - var param = params[index];
77 - assert.strictEqual(param, restArgs[index]);
78 - }
79 - }));
80 -
81 - EventEmitter.prototype.emit.apply(ee, args);
82 - }
83 -}
1 -'use strict';
2 -
3 -var common = require('./common');
4 -var EventEmitter = require('../');
5 -var assert = require('assert');
6 -
7 -var myEE = new EventEmitter();
8 -var m = 0;
9 -// This one comes last.
10 -myEE.on('foo', common.mustCall(function () {
11 - assert.strictEqual(m, 2);
12 -}));
13 -
14 -// This one comes second.
15 -myEE.prependListener('foo', common.mustCall(function () {
16 - assert.strictEqual(m++, 1);
17 -}));
18 -
19 -// This one comes first.
20 -myEE.prependOnceListener('foo',
21 - common.mustCall(function () {
22 - assert.strictEqual(m++, 0);
23 - }));
24 -
25 -myEE.emit('foo');
26 -
27 -// Verify that the listener must be a function
28 -assert.throws(function () {
29 - var ee = new EventEmitter();
30 - ee.prependOnceListener('foo', null);
31 -}, 'TypeError: The "listener" argument must be of type Function. Received type object');
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -var test = require('tape');
26 -
27 -function expect(expected) {
28 - var actual = [];
29 - test.onFinish(function() {
30 - var sortedActual = actual.sort();
31 - var sortedExpected = expected.sort();
32 - assert.strictEqual(sortedActual.length, sortedExpected.length);
33 - for (var index = 0; index < sortedActual.length; index++) {
34 - var value = sortedActual[index];
35 - assert.strictEqual(value, sortedExpected[index]);
36 - }
37 - });
38 - function listener(name) {
39 - actual.push(name);
40 - }
41 - return common.mustCall(listener, expected.length);
42 -}
43 -
44 -{
45 - var ee = new events.EventEmitter();
46 - var noop = common.mustNotCall();
47 - ee.on('foo', noop);
48 - ee.on('bar', noop);
49 - ee.on('baz', noop);
50 - ee.on('baz', noop);
51 - var fooListeners = ee.listeners('foo');
52 - var barListeners = ee.listeners('bar');
53 - var bazListeners = ee.listeners('baz');
54 - ee.on('removeListener', expect(['bar', 'baz', 'baz']));
55 - ee.removeAllListeners('bar');
56 - ee.removeAllListeners('baz');
57 -
58 - var listeners = ee.listeners('foo');
59 - assert.ok(Array.isArray(listeners));
60 - assert.strictEqual(listeners.length, 1);
61 - assert.strictEqual(listeners[0], noop);
62 -
63 - listeners = ee.listeners('bar');
64 - assert.ok(Array.isArray(listeners));
65 - assert.strictEqual(listeners.length, 0);
66 - listeners = ee.listeners('baz');
67 - assert.ok(Array.isArray(listeners));
68 - assert.strictEqual(listeners.length, 0);
69 - // After calling removeAllListeners(),
70 - // the old listeners array should stay unchanged.
71 - assert.strictEqual(fooListeners.length, 1);
72 - assert.strictEqual(fooListeners[0], noop);
73 - assert.strictEqual(barListeners.length, 1);
74 - assert.strictEqual(barListeners[0], noop);
75 - assert.strictEqual(bazListeners.length, 2);
76 - assert.strictEqual(bazListeners[0], noop);
77 - assert.strictEqual(bazListeners[1], noop);
78 - // After calling removeAllListeners(),
79 - // new listeners arrays is different from the old.
80 - assert.notStrictEqual(ee.listeners('bar'), barListeners);
81 - assert.notStrictEqual(ee.listeners('baz'), bazListeners);
82 -}
83 -
84 -{
85 - var ee = new events.EventEmitter();
86 - ee.on('foo', common.mustNotCall());
87 - ee.on('bar', common.mustNotCall());
88 - // Expect LIFO order
89 - ee.on('removeListener', expect(['foo', 'bar', 'removeListener']));
90 - ee.on('removeListener', expect(['foo', 'bar']));
91 - ee.removeAllListeners();
92 -
93 - var listeners = ee.listeners('foo');
94 - assert.ok(Array.isArray(listeners));
95 - assert.strictEqual(listeners.length, 0);
96 - listeners = ee.listeners('bar');
97 - assert.ok(Array.isArray(listeners));
98 - assert.strictEqual(listeners.length, 0);
99 -}
100 -
101 -{
102 - var ee = new events.EventEmitter();
103 - ee.on('removeListener', common.mustNotCall());
104 - // Check for regression where removeAllListeners() throws when
105 - // there exists a 'removeListener' listener, but there exists
106 - // no listeners for the provided event type.
107 - assert.doesNotThrow(function () { ee.removeAllListeners(ee, 'foo') });
108 -}
109 -
110 -{
111 - var ee = new events.EventEmitter();
112 - var expectLength = 2;
113 - ee.on('removeListener', function() {
114 - assert.strictEqual(expectLength--, this.listeners('baz').length);
115 - });
116 - ee.on('baz', common.mustNotCall());
117 - ee.on('baz', common.mustNotCall());
118 - ee.on('baz', common.mustNotCall());
119 - assert.strictEqual(ee.listeners('baz').length, expectLength + 1);
120 - ee.removeAllListeners('baz');
121 - assert.strictEqual(ee.listeners('baz').length, 0);
122 -}
123 -
124 -{
125 - var ee = new events.EventEmitter();
126 - assert.strictEqual(ee, ee.removeAllListeners());
127 -}
128 -
129 -{
130 - var ee = new events.EventEmitter();
131 - ee._events = undefined;
132 - assert.strictEqual(ee, ee.removeAllListeners());
133 -}
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var assert = require('assert');
24 -var EventEmitter = require('../');
25 -
26 -var listener1 = function listener1() {};
27 -var listener2 = function listener2() {};
28 -
29 -{
30 - var ee = new EventEmitter();
31 - ee.on('hello', listener1);
32 - ee.on('removeListener', common.mustCall(function(name, cb) {
33 - assert.strictEqual(name, 'hello');
34 - assert.strictEqual(cb, listener1);
35 - }));
36 - ee.removeListener('hello', listener1);
37 - var listeners = ee.listeners('hello');
38 - assert.ok(Array.isArray(listeners));
39 - assert.strictEqual(listeners.length, 0);
40 -}
41 -
42 -{
43 - var ee = new EventEmitter();
44 - ee.on('hello', listener1);
45 - ee.on('removeListener', common.mustNotCall());
46 - ee.removeListener('hello', listener2);
47 -
48 - var listeners = ee.listeners('hello');
49 - assert.ok(Array.isArray(listeners));
50 - assert.strictEqual(listeners.length, 1);
51 - assert.strictEqual(listeners[0], listener1);
52 -}
53 -
54 -{
55 - var ee = new EventEmitter();
56 - ee.on('hello', listener1);
57 - ee.on('hello', listener2);
58 -
59 - var listeners;
60 - ee.once('removeListener', common.mustCall(function(name, cb) {
61 - assert.strictEqual(name, 'hello');
62 - assert.strictEqual(cb, listener1);
63 - listeners = ee.listeners('hello');
64 - assert.ok(Array.isArray(listeners));
65 - assert.strictEqual(listeners.length, 1);
66 - assert.strictEqual(listeners[0], listener2);
67 - }));
68 - ee.removeListener('hello', listener1);
69 - listeners = ee.listeners('hello');
70 - assert.ok(Array.isArray(listeners));
71 - assert.strictEqual(listeners.length, 1);
72 - assert.strictEqual(listeners[0], listener2);
73 - ee.once('removeListener', common.mustCall(function(name, cb) {
74 - assert.strictEqual(name, 'hello');
75 - assert.strictEqual(cb, listener2);
76 - listeners = ee.listeners('hello');
77 - assert.ok(Array.isArray(listeners));
78 - assert.strictEqual(listeners.length, 0);
79 - }));
80 - ee.removeListener('hello', listener2);
81 - listeners = ee.listeners('hello');
82 - assert.ok(Array.isArray(listeners));
83 - assert.strictEqual(listeners.length, 0);
84 -}
85 -
86 -{
87 - var ee = new EventEmitter();
88 -
89 - function remove1() {
90 - assert.fail('remove1 should not have been called');
91 - }
92 -
93 - function remove2() {
94 - assert.fail('remove2 should not have been called');
95 - }
96 -
97 - ee.on('removeListener', common.mustCall(function(name, cb) {
98 - if (cb !== remove1) return;
99 - this.removeListener('quux', remove2);
100 - this.emit('quux');
101 - }, 2));
102 - ee.on('quux', remove1);
103 - ee.on('quux', remove2);
104 - ee.removeListener('quux', remove1);
105 -}
106 -
107 -{
108 - var ee = new EventEmitter();
109 - ee.on('hello', listener1);
110 - ee.on('hello', listener2);
111 -
112 - var listeners;
113 - ee.once('removeListener', common.mustCall(function(name, cb) {
114 - assert.strictEqual(name, 'hello');
115 - assert.strictEqual(cb, listener1);
116 - listeners = ee.listeners('hello');
117 - assert.ok(Array.isArray(listeners));
118 - assert.strictEqual(listeners.length, 1);
119 - assert.strictEqual(listeners[0], listener2);
120 - ee.once('removeListener', common.mustCall(function(name, cb) {
121 - assert.strictEqual(name, 'hello');
122 - assert.strictEqual(cb, listener2);
123 - listeners = ee.listeners('hello');
124 - assert.ok(Array.isArray(listeners));
125 - assert.strictEqual(listeners.length, 0);
126 - }));
127 - ee.removeListener('hello', listener2);
128 - listeners = ee.listeners('hello');
129 - assert.ok(Array.isArray(listeners));
130 - assert.strictEqual(listeners.length, 0);
131 - }));
132 - ee.removeListener('hello', listener1);
133 - listeners = ee.listeners('hello');
134 - assert.ok(Array.isArray(listeners));
135 - assert.strictEqual(listeners.length, 0);
136 -}
137 -
138 -{
139 - var ee = new EventEmitter();
140 - var listener3 = common.mustCall(function() {
141 - ee.removeListener('hello', listener4);
142 - }, 2);
143 - var listener4 = common.mustCall();
144 -
145 - ee.on('hello', listener3);
146 - ee.on('hello', listener4);
147 -
148 - // listener4 will still be called although it is removed by listener 3.
149 - ee.emit('hello');
150 - // This is so because the interal listener array at time of emit
151 - // was [listener3,listener4]
152 -
153 - // Interal listener array [listener3]
154 - ee.emit('hello');
155 -}
156 -
157 -{
158 - var ee = new EventEmitter();
159 -
160 - ee.once('hello', listener1);
161 - ee.on('removeListener', common.mustCall(function(eventName, listener) {
162 - assert.strictEqual(eventName, 'hello');
163 - assert.strictEqual(listener, listener1);
164 - }));
165 - ee.emit('hello');
166 -}
167 -
168 -{
169 - var ee = new EventEmitter();
170 -
171 - assert.strictEqual(ee, ee.removeListener('foo', function() {}));
172 -}
173 -
174 -// Verify that the removed listener must be a function
175 -assert.throws(function() {
176 - var ee = new EventEmitter();
177 -
178 - ee.removeListener('foo', null);
179 -}, /^TypeError: The "listener" argument must be of type Function\. Received type object$/);
180 -
181 -{
182 - var ee = new EventEmitter();
183 - var listener = function() {};
184 - ee._events = undefined;
185 - var e = ee.removeListener('foo', listener);
186 - assert.strictEqual(e, ee);
187 -}
188 -
189 -{
190 - var ee = new EventEmitter();
191 -
192 - ee.on('foo', listener1);
193 - ee.on('foo', listener2);
194 - var listeners = ee.listeners('foo');
195 - assert.ok(Array.isArray(listeners));
196 - assert.strictEqual(listeners.length, 2);
197 - assert.strictEqual(listeners[0], listener1);
198 - assert.strictEqual(listeners[1], listener2);
199 -
200 - ee.removeListener('foo', listener1);
201 - assert.strictEqual(ee._events.foo, listener2);
202 -
203 - ee.on('foo', listener1);
204 - listeners = ee.listeners('foo');
205 - assert.ok(Array.isArray(listeners));
206 - assert.strictEqual(listeners.length, 2);
207 - assert.strictEqual(listeners[0], listener2);
208 - assert.strictEqual(listeners[1], listener1);
209 -
210 - ee.removeListener('foo', listener1);
211 - assert.strictEqual(ee._events.foo, listener2);
212 -}
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -require('./common');
23 -var assert = require('assert');
24 -var events = require('../');
25 -
26 -var e = new events.EventEmitter();
27 -
28 -if (Object.create) assert.ok(!(e._events instanceof Object));
29 -assert.strictEqual(Object.keys(e._events).length, 0);
30 -e.setMaxListeners(5);
31 -assert.strictEqual(Object.keys(e._events).length, 0);
1 -'use strict';
2 -
3 -var common = require('./common');
4 -var EventEmitter = require('../');
5 -var assert = require('assert');
6 -
7 -var ee = new EventEmitter();
8 -var handler = function() {};
9 -
10 -assert.strictEqual(ee.eventNames().length, 0);
11 -
12 -assert.strictEqual(ee._events.hasOwnProperty, undefined);
13 -assert.strictEqual(ee._events.toString, undefined);
14 -
15 -ee.on('__defineGetter__', handler);
16 -ee.on('toString', handler);
17 -ee.on('__proto__', handler);
18 -
19 -assert.strictEqual(ee.eventNames()[0], '__defineGetter__');
20 -assert.strictEqual(ee.eventNames()[1], 'toString');
21 -
22 -assert.strictEqual(ee.listeners('__defineGetter__').length, 1);
23 -assert.strictEqual(ee.listeners('__defineGetter__')[0], handler);
24 -assert.strictEqual(ee.listeners('toString').length, 1);
25 -assert.strictEqual(ee.listeners('toString')[0], handler);
26 -
27 -// Only run __proto__ tests if that property can actually be set
28 -if ({ __proto__: 'ok' }.__proto__ === 'ok') {
29 - assert.strictEqual(ee.eventNames().length, 3);
30 - assert.strictEqual(ee.eventNames()[2], '__proto__');
31 - assert.strictEqual(ee.listeners('__proto__').length, 1);
32 - assert.strictEqual(ee.listeners('__proto__')[0], handler);
33 -
34 - ee.on('__proto__', common.mustCall(function(val) {
35 - assert.strictEqual(val, 1);
36 - }));
37 - ee.emit('__proto__', 1);
38 -
39 - process.on('__proto__', common.mustCall(function(val) {
40 - assert.strictEqual(val, 1);
41 - }));
42 - process.emit('__proto__', 1);
43 -} else {
44 - console.log('# skipped __proto__')
45 -}
1 -// Copyright Joyent, Inc. and other Node contributors.
2 -//
3 -// Permission is hereby granted, free of charge, to any person obtaining a
4 -// copy of this software and associated documentation files (the
5 -// "Software"), to deal in the Software without restriction, including
6 -// without limitation the rights to use, copy, modify, merge, publish,
7 -// distribute, sublicense, and/or sell copies of the Software, and to permit
8 -// persons to whom the Software is furnished to do so, subject to the
9 -// following conditions:
10 -//
11 -// The above copyright notice and this permission notice shall be included
12 -// in all copies or substantial portions of the Software.
13 -//
14 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 -// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 -
22 -var common = require('./common');
23 -var test = require('tape');
24 -var assert = require('assert');
25 -var EventEmitter = require('../').EventEmitter;
26 -var util = require('util');
27 -
28 -util.inherits(MyEE, EventEmitter);
29 -
30 -function MyEE(cb) {
31 - this.once(1, cb);
32 - this.emit(1);
33 - this.removeAllListeners();
34 - EventEmitter.call(this);
35 -}
36 -
37 -var myee = new MyEE(common.mustCall());
38 -
39 -
40 -util.inherits(ErrorEE, EventEmitter);
41 -function ErrorEE() {
42 - this.emit('error', new Error('blerg'));
43 -}
44 -
45 -assert.throws(function() {
46 - new ErrorEE();
47 -}, /blerg/);
48 -
49 -test.onFinish(function() {
50 - assert.ok(!(myee._events instanceof Object));
51 - assert.strictEqual(Object.keys(myee._events).length, 0);
52 -});
53 -
54 -
55 -function MyEE2() {
56 - EventEmitter.call(this);
57 -}
58 -
59 -MyEE2.prototype = new EventEmitter();
60 -
61 -var ee1 = new MyEE2();
62 -var ee2 = new MyEE2();
63 -
64 -ee1.on('x', function() {});
65 -
66 -assert.strictEqual(ee2.listenerCount('x'), 0);
1 -'use strict';
2 -
3 -var common = require('./common');
4 -var EventEmitter = require('../');
5 -var assert = require('assert');
6 -
7 -var ee = new EventEmitter();
8 -var foo = Symbol('foo');
9 -var listener = common.mustCall();
10 -
11 -ee.on(foo, listener);
12 -assert.strictEqual(ee.listeners(foo).length, 1);
13 -assert.strictEqual(ee.listeners(foo)[0], listener);
14 -
15 -ee.emit(foo);
16 -
17 -ee.removeAllListeners();
18 -assert.strictEqual(ee.listeners(foo).length, 0);
19 -
20 -ee.on(foo, listener);
21 -assert.strictEqual(ee.listeners(foo).length, 1);
22 -assert.strictEqual(ee.listeners(foo)[0], listener);
23 -
24 -ee.removeListener(foo, listener);
25 -assert.strictEqual(ee.listeners(foo).length, 0);
1 -# http://editorconfig.org
2 -root = true
3 -
4 -[*]
5 -# Use hard or soft tabs
6 -indent_style = space
7 -
8 -# Size of a single indent
9 -indent_size = tab
10 -
11 -# Number of columns representing a tab character
12 -tab_width = 2
13 -
14 -# Use line-feed as EOL indicator
15 -end_of_line = lf
16 -
17 -# Use UTF-8 character encoding for all files
18 -charset = utf-8
19 -
20 -# Remove any whitespace characters preceding newline characters
21 -trim_trailing_whitespace = true
22 -
23 -# Ensure file ends with a newline when saving
24 -insert_final_newline = true
25 -
26 -[*.md]
27 -trim_trailing_whitespace = false
1 -language: node_js
2 -
3 -node_js:
4 - - '0.12'
5 - - '4'
6 - - '6'
7 - - '8'
8 - - '10'
1 -# Contributing to EventSource
2 -
3 -If you add or fix something, add tests.
4 -
5 -## Release process
6 -
7 -Update `HISTORY.md`, Then:
8 -
9 - npm outdated --depth 0 # See if you can upgrade something
10 - npm run polyfill
11 - git commit ...
12 - npm version [major|minor|patch]
13 - npm publish
1 -# [1.0.7](https://github.com/EventSource/eventsource/compare/v1.0.6...v1.0.7)
2 -
3 -* Add dispatchEvent to EventSource ([#101](https://github.com/EventSource/eventsource/pull/101) Ali Afroozeh)
4 -* Added `checkServerIdentity` option ([#104](https://github.com/EventSource/eventsource/pull/104) cintolas)
5 -* Surface request error message ([#107](https://github.com/EventSource/eventsource/pull/107) RasPhilCo)
6 -
7 -# [1.0.6](https://github.com/EventSource/eventsource/compare/v1.0.5...v1.0.6)
8 -
9 -* Fix issue where a unicode sequence split in two chunks would lead to invalid messages ([#108](https://github.com/EventSource/eventsource/pull/108) Espen Hovlandsdal)
10 -* Change example to use `eventsource/ssestream` (Aslak Hellesøy)
11 -
12 -# [1.0.5](https://github.com/EventSource/eventsource/compare/v1.0.4...v1.0.5)
13 -
14 -* Check for `window` existing before polyfilling. ([#80](https://github.com/EventSource/eventsource/pull/80) Neftaly Hernandez)
15 -
16 -# [1.0.4](https://github.com/EventSource/eventsource/compare/v1.0.2...v1.0.4)
17 -
18 -* Pass withCredentials on to the XHR. ([#79](https://github.com/EventSource/eventsource/pull/79) Ken Mayer)
19 -
20 -# [1.0.2](https://github.com/EventSource/eventsource/compare/v1.0.1...v1.0.2)
21 -
22 -* Fix proxy not working when proxy and target URL uses different protocols. ([#76](https://github.com/EventSource/eventsource/pull/76) Espen Hovlandsdal)
23 -* Make `close()` a prototype method instead of an instance method. ([#77](https://github.com/EventSource/eventsource/pull/77) Espen Hovlandsdal)
24 -
25 -# [1.0.1](https://github.com/EventSource/eventsource/compare/v1.0.0...v1.0.1)
26 -
27 -* Reconnect if server responds with HTTP 500, 502, 503 or 504. ([#74](https://github.com/EventSource/eventsource/pull/74) Vykintas Narmontas)
28 -
29 -# [1.0.0](https://github.com/EventSource/eventsource/compare/v0.2.3...v1.0.0)
30 -
31 -* Add missing `removeEventListener`-method. ([#51](https://github.com/EventSource/eventsource/pull/51) Yucheng Tu / Espen Hovlandsdal)
32 -* Fix EventSource reconnecting on non-200 responses. ([af84476](https://github.com/EventSource/eventsource/commit/af84476b519a01e61b8c80727261df52ae40022c) Espen Hovlandsdal)
33 -* Add ability to customize https options. ([#53](https://github.com/EventSource/eventsource/pull/53) Rafael Alfaro)
34 -* Add readyState constants to EventSource instances. ([#66](https://github.com/EventSource/eventsource/pull/66) Espen Hovlandsdal)
35 -
36 -# [0.2.3](https://github.com/EventSource/eventsource/compare/v0.2.2...v0.2.3)
37 -
38 -* Fix `onConnectionClosed` firing multiple times resulting in multiple connections. ([#61](https://github.com/EventSource/eventsource/pull/61) Phil Strong / Duncan Wong)
39 -* Remove unneeded isPlainObject check for headers. ([#64](https://github.com/EventSource/eventsource/pull/64) David Mark)
40 -
41 -# [0.2.2](https://github.com/EventSource/eventsource/compare/v0.2.1...v0.2.2)
42 -
43 -* Don't include test files in npm package. ([#56](https://github.com/EventSource/eventsource/pull/56) eanplatter)
44 -
45 -# [0.2.1](https://github.com/EventSource/eventsource/compare/v0.2.0...v0.2.1)
46 -
47 -* Fix `close()` for polyfill. ([#52](https://github.com/EventSource/eventsource/pull/52) brian-medendorp)
48 -* Add http/https proxy function. ([#46](https://github.com/EventSource/eventsource/pull/46) Eric Lu)
49 -* Fix reconnect for polyfill. Only disable reconnect when server status is 204. (Aslak Hellesøy).
50 -* Drop support for Node 0.10.x and older (Aslak Hellesøy).
51 -
52 -# [0.2.0](https://github.com/EventSource/eventsource/compare/v0.1.6...v0.2.0)
53 -
54 -* Renamed repository to `eventsource` (since it's not just Node, but also browser polyfill). (Aslak Hellesøy).
55 -* Compatibility with webpack/browserify. ([#44](https://github.com/EventSource/eventsource/pull/44) Adriano Raiano).
56 -
57 -# [0.1.6](https://github.com/EventSource/eventsource/compare/v0.1.5...v0.1.6)
58 -
59 -* Ignore headers without a value. ([#41](https://github.com/EventSource/eventsource/issues/41), [#43](https://github.com/EventSource/eventsource/pull/43) Adriano Raiano)
60 -
61 -# [0.1.5](https://github.com/EventSource/eventsource/compare/v0.1.4...v0.1.5)
62 -
63 -* Refactor tests to support Node.js 0.12.0 and Io.js 1.1.0. (Aslak Hellesøy)
64 -
65 -# [0.1.4](https://github.com/EventSource/eventsource/compare/v0.1.3...master)
66 -
67 -* Bugfix: Added missing origin property. ([#39](https://github.com/EventSource/eventsource/pull/39), [#38](https://github.com/EventSource/eventsource/issues/38) Arnout Kazemier)
68 -* Expose `status` property on `error` events. ([#40](https://github.com/EventSource/eventsource/pull/40) Adriano Raiano)
69 -
70 -# [0.1.3](https://github.com/EventSource/eventsource/compare/v0.1.2...v0.1.3)
71 -
72 -* Bugfix: Made message properties enumerable. ([#37](https://github.com/EventSource/eventsource/pull/37) Golo Roden)
73 -
74 -# [0.1.2](https://github.com/EventSource/eventsource/compare/v0.1.1...v0.1.2)
75 -
76 -* Bugfix: Blank lines not read. ([#35](https://github.com/EventSource/eventsource/issues/35), [#36](https://github.com/EventSource/eventsource/pull/36) Lesterpig)
77 -
78 -# [0.1.1](https://github.com/EventSource/eventsource/compare/v0.1.0...v0.1.1)
79 -
80 -* Bugfix: Fix message type. ([#33](https://github.com/EventSource/eventsource/pull/33) Romain Gauthier)
81 -
82 -# [0.1.0](https://github.com/EventSource/eventsource/compare/v0.0.10...v0.1.0)
83 -
84 -* Bugfix: High CPU usage by replacing Jison with port of WebKit's parser. ([#25](https://github.com/EventSource/eventsource/issues/25), [#32](https://github.com/EventSource/eventsource/pull/32), [#18](https://github.com/EventSource/eventsource/issues/18) qqueue)
85 -* Reformatted all code to 2 spaces.
86 -
87 -# [0.0.10](https://github.com/EventSource/eventsource/compare/v0.0.9...v0.0.10)
88 -
89 -* Provide `Event` argument on `open` and `error` event ([#30](https://github.com/EventSource/eventsource/issues/30), [#31](https://github.com/EventSource/eventsource/pull/31) Donghwan Kim)
90 -* Expose `lastEventId` on messages. ([#28](https://github.com/EventSource/eventsource/pull/28) mbieser)
91 -
92 -# [0.0.9](https://github.com/EventSource/eventsource/compare/v0.0.8...v0.0.9)
93 -
94 -* Bugfix: old "last-event-id" used on reconnect ([#27](https://github.com/EventSource/eventsource/pull/27) Aslak Hellesøy)
95 -
96 -# [0.0.8](https://github.com/EventSource/eventsource/compare/v0.0.7...v0.0.8)
97 -
98 -* Bugfix: EventSource still reconnected when closed ([#24](https://github.com/EventSource/eventsource/pull/24) FrozenCow)
99 -* Allow unauthorized HTTPS connections by setting `rejectUnauthorized` to false. (Aslak Hellesøy)
100 -
101 -# [0.0.7](https://github.com/EventSource/eventsource/compare/v0.0.6...v0.0.7)
102 -
103 -* Explicitly raise an error when server returns http 403 and don't continue ([#20](https://github.com/EventSource/eventsource/pull/20) Scott Moak)
104 -* Added ability to send custom http headers to server ([#21](https://github.com/EventSource/eventsource/pull/21), [#9](https://github.com/EventSource/eventsource/issues/9) Scott Moak)
105 -* Fix Unicode support to cope with Javascript Unicode size limitations ([#23](https://github.com/EventSource/eventsource/pull/23), [#22](https://github.com/EventSource/eventsource/issues/22) Devon Adkisson)
106 -* Graceful handling of parse errors ([#19](https://github.com/EventSource/eventsource/issues/19) Aslak Hellesøy)
107 -* Switched from testing with Nodeunit to Mocha (Aslak Hellesøy)
108 -
109 -# [0.0.6](https://github.com/EventSource/eventsource/compare/v0.0.5...v0.0.6)
110 -
111 -* Add Accept: text/event-stream header ([#17](https://github.com/EventSource/eventsource/pull/17) William Wicks)
112 -
113 -# [0.0.5](https://github.com/EventSource/eventsource/compare/v0.0.4...v0.0.5)
114 -
115 -* Add no-cache and https support ([#10](https://github.com/EventSource/eventsource/pull/10) Einar Otto Stangvik)
116 -* Ensure that Last-Event-ID is sent to the server for reconnects, as defined in the spec ([#8](https://github.com/EventSource/eventsource/pull/8) Einar Otto Stangvik)
117 -* Verify that CR and CRLF are accepted alongside LF ([#7](https://github.com/EventSource/eventsource/pull/7) Einar Otto Stangvik)
118 -* Emit 'open' event ([#4](https://github.com/EventSource/eventsource/issues/4) Einar Otto Stangvik)
119 -
120 -# [0.0.4](https://github.com/EventSource/eventsource/compare/v0.0.3...v0.0.4)
121 -
122 -* Automatic reconnect every second if the server is down. Reconnect interval can be set with `reconnectInterval` (not in W3C spec). (Aslak Hellesøy)
123 -
124 -# [0.0.3](https://github.com/EventSource/eventsource/compare/v0.0.2...v0.0.3)
125 -
126 -* Jison based eventstream parser ([#2](https://github.com/EventSource/eventsource/pull/2) Einar Otto Stangvik)
127 -
128 -# [0.0.2](https://github.com/EventSource/eventsource/compare/v0.0.1...v0.0.2)
129 -
130 -* Use native EventListener (Aslak Hellesøy)
131 -
132 -# 0.0.1
133 -
134 -* First release
1 -The MIT License
2 -
3 -Copyright (c) EventSource GitHub organisation
4 -
5 -Permission is hereby granted, free of charge, to any person obtaining
6 -a copy of this software and associated documentation files (the
7 -"Software"), to deal in the Software without restriction, including
8 -without limitation the rights to use, copy, modify, merge, publish,
9 -distribute, sublicense, and/or sell copies of the Software, and to
10 -permit persons to whom the Software is furnished to do so, subject to
11 -the following conditions:
12 -
13 -The above copyright notice and this permission notice shall be
14 -included in all copies or substantial portions of the Software.
15 -
16 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 -# EventSource [![npm version](http://img.shields.io/npm/v/eventsource.svg?style=flat-square)](http://browsenpm.org/package/eventsource)[![Build Status](http://img.shields.io/travis/EventSource/eventsource/master.svg?style=flat-square)](https://travis-ci.org/EventSource/eventsource)[![NPM Downloads](https://img.shields.io/npm/dm/eventsource.svg?style=flat-square)](http://npm-stat.com/charts.html?package=eventsource&from=2015-09-01)[![Dependencies](https://img.shields.io/david/EventSource/eventsource.svg?style=flat-square)](https://david-dm.org/EventSource/eventsource)
2 -
3 -This library is a pure JavaScript implementation of the [EventSource](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) client. The API aims to be W3C compatible.
4 -
5 -You can use it with Node.js or as a browser polyfill for
6 -[browsers that don't have native `EventSource` support](http://caniuse.com/#feat=eventsource).
7 -
8 -## Install
9 -
10 - npm install eventsource
11 -
12 -## Example
13 -
14 - npm install
15 - node ./example/sse-server.js
16 - node ./example/sse-client.js # Node.js client
17 - open http://localhost:8080 # Browser client - both native and polyfill
18 - curl http://localhost:8080/sse # Enjoy the simplicity of SSE
19 -
20 -## Browser Polyfill
21 -
22 -Just add `example/eventsource-polyfill.js` file to your web page:
23 -
24 -```html
25 -<script src=/eventsource-polyfill.js></script>
26 -```
27 -
28 -Now you will have two global constructors:
29 -
30 -```javascript
31 -window.EventSourcePolyfill
32 -window.EventSource // Unchanged if browser has defined it. Otherwise, same as window.EventSourcePolyfill
33 -```
34 -
35 -If you're using [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/)
36 -you can of course build your own. (The `example/eventsource-polyfill.js` is built with webpack).
37 -
38 -## Extensions to the W3C API
39 -
40 -### Setting HTTP request headers
41 -
42 -You can define custom HTTP headers for the initial HTTP request. This can be useful for e.g. sending cookies
43 -or to specify an initial `Last-Event-ID` value.
44 -
45 -HTTP headers are defined by assigning a `headers` attribute to the optional `eventSourceInitDict` argument:
46 -
47 -```javascript
48 -var eventSourceInitDict = {headers: {'Cookie': 'test=test'}};
49 -var es = new EventSource(url, eventSourceInitDict);
50 -```
51 -
52 -### Allow unauthorized HTTPS requests
53 -
54 -By default, https requests that cannot be authorized will cause the connection to fail and an exception
55 -to be emitted. You can override this behaviour, along with other https options:
56 -
57 -```javascript
58 -var eventSourceInitDict = {https: {rejectUnauthorized: false}};
59 -var es = new EventSource(url, eventSourceInitDict);
60 -```
61 -
62 -Note that for Node.js < v0.10.x this option has no effect - unauthorized HTTPS requests are *always* allowed.
63 -
64 -### HTTP status code on error events
65 -
66 -Unauthorized and redirect error status codes (for example 401, 403, 301, 307) are available in the `status` property in the error event.
67 -
68 -```javascript
69 -es.onerror = function (err) {
70 - if (err) {
71 - if (err.status === 401 || err.status === 403) {
72 - console.log('not authorized');
73 - }
74 - }
75 -};
76 -```
77 -
78 -### HTTP/HTTPS proxy
79 -
80 -You can define a `proxy` option for the HTTP request to be used. This is typically useful if you are behind a corporate firewall.
81 -
82 -```javascript
83 -var es = new EventSource(url, {proxy: 'http://your.proxy.com'});
84 -```
85 -
86 -
87 -## License
88 -
89 -MIT-licensed. See LICENSE
This diff could not be displayed because it is too large.
1 -<!DOCTYPE html>
2 -<html>
3 -<head>
4 -<style>
5 -.col {
6 - float:left;
7 - width:50%;
8 - left:50%;
9 -}
10 -</style>
11 -</head>
12 -
13 -<body>
14 -<div class=col>
15 - <h2>EventSource</h2>
16 - <ul id=es-messages>
17 - </ul>
18 -</div>
19 -
20 -<div class=col>
21 - <h2>EventSourcePolyfill</h2>
22 - <ul id=es-polyfill-messages>
23 - </ul>
24 -</div>
25 -
26 -<script src=/eventsource-polyfill.js></script>
27 -
28 -<script>
29 -function subscribe(es, ul) {
30 - es.addEventListener('server-time', function (e) {
31 - var li = document.createElement("LI");
32 - li.appendChild(document.createTextNode(e.data));
33 - ul.appendChild(li);
34 - });
35 -}
36 -
37 -subscribe(new EventSource('/sse'), document.getElementById('es-messages'));
38 -subscribe(new EventSourcePolyfill('/sse'), document.getElementById('es-polyfill-messages'));
39 -</script>
40 -</body>
1 -var EventSource = require('..')
2 -var es = new EventSource('http://localhost:8080/sse')
3 -es.addEventListener('server-time', function (e) {
4 - console.log(e.data)
5 -})
1 -const express = require('express')
2 -const serveStatic = require('serve-static')
3 -const SseStream = require('ssestream')
4 -
5 -const app = express()
6 -app.use(serveStatic(__dirname))
7 -app.get('/sse', (req, res) => {
8 - console.log('new connection')
9 -
10 - const sseStream = new SseStream(req)
11 - sseStream.pipe(res)
12 - const pusher = setInterval(() => {
13 - sseStream.write({
14 - event: 'server-time',
15 - data: new Date().toTimeString()
16 - })
17 - }, 1000)
18 -
19 - res.on('close', () => {
20 - console.log('lost connection')
21 - clearInterval(pusher)
22 - sseStream.unpipe(res)
23 - })
24 -})
25 -
26 -app.listen(8080, (err) => {
27 - if (err) throw err
28 - console.log('server ready on http://localhost:8080')
29 -})
1 -var EventSource = require('./eventsource')
2 -
3 -if (typeof window === 'object') {
4 - window.EventSourcePolyfill = EventSource
5 - if (!window.EventSource) window.EventSource = EventSource
6 - module.exports = window.EventSource
7 -} else {
8 - module.exports = EventSource
9 -}
This diff is collapsed. Click to expand it.
1 -{
2 - "_from": "eventsource@^1.0.7",
3 - "_id": "eventsource@1.0.7",
4 - "_inBundle": false,
5 - "_integrity": "sha512-4Ln17+vVT0k8aWq+t/bF5arcS3EpT9gYtW66EPacdj/mAFevznsnyoHLPy2BA8gbIQeIHoPsvwmfBftfcG//BQ==",
6 - "_location": "/eventsource",
7 - "_phantomChildren": {},
8 - "_requested": {
9 - "type": "range",
10 - "registry": true,
11 - "raw": "eventsource@^1.0.7",
12 - "name": "eventsource",
13 - "escapedName": "eventsource",
14 - "rawSpec": "^1.0.7",
15 - "saveSpec": null,
16 - "fetchSpec": "^1.0.7"
17 - },
18 - "_requiredBy": [
19 - "/sockjs-client"
20 - ],
21 - "_resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.0.7.tgz",
22 - "_shasum": "8fbc72c93fcd34088090bc0a4e64f4b5cee6d8d0",
23 - "_spec": "eventsource@^1.0.7",
24 - "_where": "C:\\Users\\kkwan_000\\Desktop\\git\\2017110269\\minsung\\node_modules\\sockjs-client",
25 - "author": {
26 - "name": "Aslak Hellesøy",
27 - "email": "aslak.hellesoy@gmail.com"
28 - },
29 - "bugs": {
30 - "url": "http://github.com/EventSource/eventsource/issues"
31 - },
32 - "bundleDependencies": false,
33 - "dependencies": {
34 - "original": "^1.0.0"
35 - },
36 - "deprecated": false,
37 - "description": "W3C compliant EventSource client for Node.js and browser (polyfill)",
38 - "devDependencies": {
39 - "buffer-from": "^1.1.1",
40 - "express": "^4.15.3",
41 - "mocha": "^3.5.3",
42 - "nyc": "^11.2.1",
43 - "serve-static": "^1.12.3",
44 - "ssestream": "^1.0.0",
45 - "standard": "^10.0.2",
46 - "webpack": "^3.5.6"
47 - },
48 - "directories": {
49 - "lib": "./lib"
50 - },
51 - "engines": {
52 - "node": ">=0.12.0"
53 - },
54 - "homepage": "http://github.com/EventSource/eventsource",
55 - "keywords": [
56 - "eventsource",
57 - "http",
58 - "streaming",
59 - "sse",
60 - "polyfill"
61 - ],
62 - "license": "MIT",
63 - "licenses": [
64 - {
65 - "type": "MIT",
66 - "url": "http://github.com/EventSource/eventsource/raw/master/LICENSE"
67 - }
68 - ],
69 - "main": "./lib/eventsource",
70 - "name": "eventsource",
71 - "repository": {
72 - "type": "git",
73 - "url": "git://github.com/EventSource/eventsource.git"
74 - },
75 - "scripts": {
76 - "coverage": "nyc --reporter=html --reporter=text _mocha --reporter spec",
77 - "polyfill": "webpack lib/eventsource-polyfill.js example/eventsource-polyfill.js",
78 - "postpublish": "git push && git push --tags",
79 - "test": "mocha --reporter spec && standard"
80 - },
81 - "standard": {
82 - "ignore": [
83 - "example/eventsource-polyfill.js"
84 - ]
85 - },
86 - "version": "1.0.7"
87 -}
This diff could not be displayed because it is too large.
1 -The MIT License (MIT)
2 -
3 -Copyright (c) 2017 crypto-browserify contributors
4 -
5 -Permission is hereby granted, free of charge, to any person obtaining a copy
6 -of this software and associated documentation files (the "Software"), to deal
7 -in the Software without restriction, including without limitation the rights
8 -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 -copies of the Software, and to permit persons to whom the Software is
10 -furnished to do so, subject to the following conditions:
11 -
12 -The above copyright notice and this permission notice shall be included in all
13 -copies or substantial portions of the Software.
14 -
15 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 -SOFTWARE.
1 -# EVP\_BytesToKey
2 -[![NPM Package](https://img.shields.io/npm/v/evp_bytestokey.svg?style=flat-square)](https://www.npmjs.org/package/evp_bytestokey)
3 -[![Build Status](https://img.shields.io/travis/crypto-browserify/EVP_BytesToKey.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/EVP_BytesToKey)
4 -[![Dependency status](https://img.shields.io/david/crypto-browserify/EVP_BytesToKey.svg?style=flat-square)](https://david-dm.org/crypto-browserify/EVP_BytesToKey#info=dependencies)
5 -
6 -[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
7 -
8 -The insecure [key derivation algorithm from OpenSSL.][1]
9 -
10 -**WARNING: DO NOT USE, except for compatibility reasons.**
11 -
12 -MD5 is insecure.
13 -
14 -Use at least `scrypt` or `pbkdf2-hmac-sha256` instead.
15 -
16 -
17 -## API
18 -`EVP_BytesToKey(password, salt, keyLen, ivLen)`
19 -
20 -* `password` - `Buffer`, password used to derive the key data.
21 -* `salt` - 8 byte `Buffer` or `null`, salt is used as a salt in the derivation.
22 -* `keyBits` - `number`, key length in **bits**.
23 -* `ivLen` - `number`, iv length in bytes.
24 -
25 -*Returns*: `{ key: Buffer, iv: Buffer }`
26 -
27 -
28 -## Examples
29 -MD5 with `aes-256-cbc`:
30 -
31 -```js
32 -const crypto = require('crypto')
33 -const EVP_BytesToKey = require('evp_bytestokey')
34 -
35 -const result = EVP_BytesToKey(
36 - 'my-secret-password',
37 - null,
38 - 32,
39 - 16
40 -)
41 -// =>
42 -// { key: <Buffer e3 4f 96 f3 86 24 82 7c c2 5d ff 23 18 6f 77 72 54 45 7f 49 d4 be 4b dd 4f 6e 1b cc 92 a4 27 33>,
43 -// iv: <Buffer 85 71 9a bf ae f4 1e 74 dd 46 b6 13 79 56 f5 5b> }
44 -
45 -const cipher = crypto.createCipheriv('aes-256-cbc', result.key, result.iv)
46 -```
47 -
48 -## LICENSE [MIT](LICENSE)
49 -
50 -[1]: https://wiki.openssl.org/index.php/Manual:EVP_BytesToKey(3)
51 -[2]: https://nodejs.org/api/crypto.html#crypto_class_hash
1 -var Buffer = require('safe-buffer').Buffer
2 -var MD5 = require('md5.js')
3 -
4 -/* eslint-disable camelcase */
5 -function EVP_BytesToKey (password, salt, keyBits, ivLen) {
6 - if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary')
7 - if (salt) {
8 - if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary')
9 - if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length')
10 - }
11 -
12 - var keyLen = keyBits / 8
13 - var key = Buffer.alloc(keyLen)
14 - var iv = Buffer.alloc(ivLen || 0)
15 - var tmp = Buffer.alloc(0)
16 -
17 - while (keyLen > 0 || ivLen > 0) {
18 - var hash = new MD5()
19 - hash.update(tmp)
20 - hash.update(password)
21 - if (salt) hash.update(salt)
22 - tmp = hash.digest()
23 -
24 - var used = 0
25 -
26 - if (keyLen > 0) {
27 - var keyStart = key.length - keyLen
28 - used = Math.min(keyLen, tmp.length)
29 - tmp.copy(key, keyStart, 0, used)
30 - keyLen -= used
31 - }
32 -
33 - if (used < tmp.length && ivLen > 0) {
34 - var ivStart = iv.length - ivLen
35 - var length = Math.min(ivLen, tmp.length - used)
36 - tmp.copy(iv, ivStart, used, used + length)
37 - ivLen -= length
38 - }
39 - }
40 -
41 - tmp.fill(0)
42 - return { key: key, iv: iv }
43 -}
44 -
45 -module.exports = EVP_BytesToKey
1 -{
2 - "_from": "evp_bytestokey@^1.0.0",
3 - "_id": "evp_bytestokey@1.0.3",
4 - "_inBundle": false,
5 - "_integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==",
6 - "_location": "/evp_bytestokey",
7 - "_phantomChildren": {},
8 - "_requested": {
9 - "type": "range",
10 - "registry": true,
11 - "raw": "evp_bytestokey@^1.0.0",
12 - "name": "evp_bytestokey",
13 - "escapedName": "evp_bytestokey",
14 - "rawSpec": "^1.0.0",
15 - "saveSpec": null,
16 - "fetchSpec": "^1.0.0"
17 - },
18 - "_requiredBy": [
19 - "/browserify-aes",
20 - "/browserify-cipher",
21 - "/parse-asn1"
22 - ],
23 - "_resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz",
24 - "_shasum": "7fcbdb198dc71959432efe13842684e0525acb02",
25 - "_spec": "evp_bytestokey@^1.0.0",
26 - "_where": "C:\\Users\\kkwan_000\\Desktop\\git\\2017110269\\minsung\\node_modules\\browserify-cipher",
27 - "author": {
28 - "name": "Calvin Metcalf",
29 - "email": "calvin.metcalf@gmail.com"
30 - },
31 - "bugs": {
32 - "url": "https://github.com/crypto-browserify/EVP_BytesToKey/issues"
33 - },
34 - "bundleDependencies": false,
35 - "contributors": [
36 - {
37 - "name": "Kirill Fomichev",
38 - "email": "fanatid@ya.ru"
39 - }
40 - ],
41 - "dependencies": {
42 - "md5.js": "^1.3.4",
43 - "safe-buffer": "^5.1.1"
44 - },
45 - "deprecated": false,
46 - "description": "The insecure key derivation algorithm from OpenSSL",
47 - "devDependencies": {
48 - "bindings": "^1.2.1",
49 - "nan": "^2.4.0",
50 - "nyc": "^8.1.0",
51 - "standard": "^8.0.0",
52 - "tape": "^4.6.0"
53 - },
54 - "files": [
55 - "index.js"
56 - ],
57 - "gypfile": false,
58 - "homepage": "https://github.com/crypto-browserify/EVP_BytesToKey",
59 - "keywords": [
60 - "crypto",
61 - "openssl"
62 - ],
63 - "license": "MIT",
64 - "main": "index.js",
65 - "name": "evp_bytestokey",
66 - "repository": {
67 - "type": "git",
68 - "url": "git+https://github.com/crypto-browserify/EVP_BytesToKey.git"
69 - },
70 - "scripts": {
71 - "coverage": "nyc tape test/*.js",
72 - "lint": "standard",
73 - "test": "npm run lint && npm run unit",
74 - "test:prepare": "node-gyp rebuild",
75 - "unit": "tape test/*.js"
76 - },
77 - "version": "1.0.3"
78 -}
1 -{
2 - // --------------------------------------------------------------------
3 - // JSHint Configuration, Strict Edition
4 - // --------------------------------------------------------------------
5 - //
6 - // This is a options template for [JSHint][1], using [JSHint example][2]
7 - // and [Ory Band's example][3] as basis and setting config values to
8 - // be most strict:
9 - //
10 - // * set all enforcing options to true
11 - // * set all relaxing options to false
12 - // * set all environment options to false, except the browser value
13 - // * set all JSLint legacy options to false
14 - //
15 - // [1]: http://www.jshint.com/
16 - // [2]: https://github.com/jshint/node-jshint/blob/master/example/config.json
17 - // [3]: https://github.com/oryband/dotfiles/blob/master/jshintrc
18 - //
19 - // @author http://michael.haschke.biz/
20 - // @license http://unlicense.org/
21 -
22 - // == Enforcing Options ===============================================
23 - //
24 - // These options tell JSHint to be more strict towards your code. Use
25 - // them if you want to allow only a safe subset of JavaScript, very
26 - // useful when your codebase is shared with a big number of developers
27 - // with different skill levels.
28 -
29 - "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
30 - "curly" : true, // Require {} for every new block or scope.
31 - "eqeqeq" : true, // Require triple equals i.e. `===`.
32 - "forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
33 - "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
34 - "latedef" : true, // Prohibit variable use before definition.
35 - "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
36 - "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
37 - "noempty" : true, // Prohibit use of empty blocks.
38 - "nonew" : true, // Prohibit use of constructors for side-effects.
39 - "plusplus" : true, // Prohibit use of `++` & `--`.
40 - "regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
41 - "undef" : true, // Require all non-global variables be declared before they are used.
42 - "strict" : false, // Require `use strict` pragma in every file.
43 - "trailing" : true, // Prohibit trailing whitespaces.
44 -
45 - // == Relaxing Options ================================================
46 - //
47 - // These options allow you to suppress certain types of warnings. Use
48 - // them only if you are absolutely positive that you know what you are
49 - // doing.
50 -
51 - "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
52 - "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
53 - "debug" : false, // Allow debugger statements e.g. browser breakpoints.
54 - "eqnull" : false, // Tolerate use of `== null`.
55 - "es5" : false, // Allow EcmaScript 5 syntax.
56 - "esnext" : false, // Allow ES.next specific features such as `const` and `let`.
57 - "evil" : false, // Tolerate use of `eval`.
58 - "expr" : false, // Tolerate `ExpressionStatement` as Programs.
59 - "funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
60 - "globalstrict" : false, // Allow global "use strict" (also enables 'strict').
61 - "iterator" : false, // Allow usage of __iterator__ property.
62 - "lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
63 - "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
64 - "laxcomma" : false, // Suppress warnings about comma-first coding style.
65 - "loopfunc" : false, // Allow functions to be defined within loops.
66 - "multistr" : false, // Tolerate multi-line strings.
67 - "onecase" : false, // Tolerate switches with just one case.
68 - "proto" : false, // Tolerate __proto__ property. This property is deprecated.
69 - "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
70 - "scripturl" : false, // Tolerate script-targeted URLs.
71 - "smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
72 - "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
73 - "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
74 - "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
75 - "validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
76 -
77 - // == Environments ====================================================
78 - //
79 - // These options pre-define global variables that are exposed by
80 - // popular JavaScript libraries and runtime environments—such as
81 - // browser or node.js.
82 -
83 - "browser" : false, // Standard browser globals e.g. `window`, `document`.
84 - "couch" : false, // Enable globals exposed by CouchDB.
85 - "devel" : false, // Allow development statements e.g. `console.log();`.
86 - "dojo" : false, // Enable globals exposed by Dojo Toolkit.
87 - "jquery" : false, // Enable globals exposed by jQuery JavaScript library.
88 - "mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
89 - "node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment.
90 - "nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
91 - "prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
92 - "rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
93 - "wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.
94 -
95 - // == JSLint Legacy ===================================================
96 - //
97 - // These options are legacy from JSLint. Aside from bug fixes they will
98 - // not be improved in any way and might be removed at any point.
99 -
100 - "nomen" : false, // Prohibit use of initial or trailing underbars in names.
101 - "onevar" : false, // Allow only one `var` statement per function.
102 - "passfail" : false, // Stop on first error.
103 - "white" : false, // Check against strict whitespace and indentation rules.
104 -
105 - // == Undocumented Options ============================================
106 - //
107 - // While I've found these options in [example1][2] and [example2][3]
108 - // they are not described in the [JSHint Options documentation][4].
109 - //
110 - // [4]: http://www.jshint.com/options/
111 -
112 - "maxerr" : 100, // Maximum errors before stopping.
113 - "predef" : [ // Extra globals.
114 - //"exampleVar",
115 - //"anotherCoolGlobal",
116 - //"iLoveDouglas"
117 - ],
118 - "indent" : 2, // Specify indentation spacing
119 - "maxlen" : 100 // The maximum number of characters in a line.
120 -}
...\ No newline at end of file ...\ No newline at end of file
1 -language: node_js
2 -node_js:
3 -- 'node'
4 -after_success:
5 -- npm run jsdoc
6 -- cat artifacts/coverage/lcov.info | node_modules/coveralls/bin/coveralls.js
7 -notifications:
8 - slack:
9 - secure: k4kpAZcA1Mu7LHs58m4JkMbGtpWPI8BPYqmqKVfHBE21daaqRYgpHOiLyWiFhv83xkiOWWfDAS2svvS2h2jDmaRzieVBlonQlhGgDEu123Mobvi8nUxeu6bNxoFSRwKXVx8uTCGKmzwqWz870Y6d7+TUQnMhhdl0GRB2tqAhY0A=
10 -deploy:
11 -- provider: s3
12 - access_key_id:
13 - secure: IQXPBnuNyREtmNN+W9bONLok5lFO9+JzQ3n5nK/uRHTuYDgS4ZbKJwaJ1dRNS6Zb8qAgVyIq8FBVa4olbvH6sfxGwVluwY0ujskvgA5hOMEpyjJ5zQx5+boWDTz9wNdMUe4ImygJjcpTjn33wMu9arFLMyIQdKysrlfU1HlRWB0=
14 - secret_access_key:
15 - secure: lIFQHzB5Sfzi0BmYM/b8PzEtdwOUQjtTPBGdTjX09b7OFVsb3M4FROaAsaTMrbZ+L6TyLD9fDBJMPHW7xZTnrZG1zcKIjZITT25Ec/2YQ9CCdAdbr+NobKrjaJ6dIcF2NKcUaRQQvRE9E8uC/KVveWGEC7ITtv0yssuADNSdcOU=
16 - bucket: tsertkov-artifacts
17 - local-dir: artifacts
18 - upload-dir: exec-sh/master
19 - acl: public_read
20 - skip_cleanup: true
21 - region: eu-central-1
22 - endpoint: s3.eu-central-1.amazonaws.com
23 - on:
24 - branch: master
25 -- provider: s3
26 - access_key_id:
27 - secure: IQXPBnuNyREtmNN+W9bONLok5lFO9+JzQ3n5nK/uRHTuYDgS4ZbKJwaJ1dRNS6Zb8qAgVyIq8FBVa4olbvH6sfxGwVluwY0ujskvgA5hOMEpyjJ5zQx5+boWDTz9wNdMUe4ImygJjcpTjn33wMu9arFLMyIQdKysrlfU1HlRWB0=
28 - secret_access_key:
29 - secure: lIFQHzB5Sfzi0BmYM/b8PzEtdwOUQjtTPBGdTjX09b7OFVsb3M4FROaAsaTMrbZ+L6TyLD9fDBJMPHW7xZTnrZG1zcKIjZITT25Ec/2YQ9CCdAdbr+NobKrjaJ6dIcF2NKcUaRQQvRE9E8uC/KVveWGEC7ITtv0yssuADNSdcOU=
30 - bucket: tsertkov-artifacts
31 - local-dir: artifacts
32 - upload-dir: exec-sh/develop
33 - acl: public_read
34 - skip_cleanup: true
35 - region: eu-central-1
36 - endpoint: s3.eu-central-1.amazonaws.com
37 - on:
38 - branch: develop
1 -The MIT License (MIT)
2 -
3 -Copyright (c) 2014 Aleksandr Tsertkov <tsertkov@gmail.com>
4 -
5 -Permission is hereby granted, free of charge, to any person obtaining a copy
6 -of this software and associated documentation files (the "Software"), to deal
7 -in the Software without restriction, including without limitation the rights
8 -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 -copies of the Software, and to permit persons to whom the Software is
10 -furnished to do so, subject to the following conditions:
11 -
12 -The above copyright notice and this permission notice shall be included in
13 -all copies or substantial portions of the Software.
14 -
15 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 -THE SOFTWARE.
1 -# exec-sh
2 -
3 -[![NPM](https://nodei.co/npm/exec-sh.png)](https://nodei.co/npm/exec-sh/)
4 -
5 -[![NPM Downloads](https://img.shields.io/npm/dm/exec-sh.svg)](https://www.npmjs.com/package/exec-sh)
6 -[![Build Status](https://travis-ci.org/tsertkov/exec-sh.svg?branch=master)](https://travis-ci.org/tsertkov/exec-sh)
7 -[![Coverage Status](https://img.shields.io/coveralls/tsertkov/exec-sh.svg)](https://coveralls.io/r/tsertkov/exec-sh?branch=master)
8 -[![David Status](https://david-dm.org/tsertkov/exec-sh.png)](https://david-dm.org/tsertkov/exec-sh)
9 -
10 -> Execute shell command forwarding all stdio streams.
11 -
12 -## Features
13 -
14 -exec-sh is a wrapper for [`child_process.spawn`](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) with some improvements:
15 -
16 -- Cross platform command execution:
17 - - Windows: `cmd /C COMMAND`
18 - - others: `sh -c COMMAND`
19 -- Fowrards all stdio streams to current terminal (by default):
20 - - `execSh("bash")`
21 - - `execsh("echo -n Say: && read i && echo Said:$i")`
22 -- stdout and stderr are passed to callback when available
23 - - `execSh("pwd", console.log)`
24 -
25 -## Showcase
26 -```javascript
27 -// JavaScript
28 -
29 -execSh("echo hello exec-sh && bash", { cwd: "/home" }, function(err){
30 - if (err) {
31 - console.log("Exit code: ", err.code);
32 - }
33 -});
34 -```
35 -
36 -```sh
37 -# Terminal output: interactive bash session
38 -
39 -hello exec-sh
40 -bash-3.2$ pwd
41 -/home
42 -bash-3.2$ exit 99
43 -exit
44 -Exit code: 99
45 -```
46 -
47 -## Usage
48 -
49 -```javascript
50 -var execSh = require("../");
51 -
52 -// run interactive bash shell
53 -execSh("echo lorem && bash", { cwd: "/home" }, function(err){
54 - if (err) {
55 - console.log("Exit code: ", err.code);
56 - return;
57 - }
58 -
59 - // collect streams output
60 - var child = execSh(["bash -c id", "echo lorem >&2"], true,
61 - function(err, stdout, stderr){
62 - console.log("error: ", err);
63 - console.log("stdout: ", stdout);
64 - console.log("stderr: ", stderr);
65 - });
66 -});
67 -```
68 -
69 -## Promise Interface
70 -
71 -```javascript
72 -var execShPromise = require("exec-sh").promise;
73 -
74 -// run interactive bash shell
75 -const run = async () => {
76 - let out;
77 -
78 - try {
79 - out = await execShPromise('pwd', true);
80 - } catch (e) {
81 - console.log('Error: ', e);
82 - console.log('Stderr: ', e.stderr);
83 - console.log('Stdout: ', e.stdout);
84 -
85 - return e;
86 - }
87 -
88 - console.log('out: ', out.stdout, out.stderr);
89 -}
90 -
91 -run();
92 -```
93 -
94 -## Public API
95 -
96 -### `execSh(command, [options], [callback])`
97 -
98 -Execute shell command forwarding all stdio.
99 -
100 -**Parameters:**
101 -
102 -- `command {String|Array}` - The command to run, or array of commands
103 -- `[options] {Object|TRUE}` - Options object passed directly to [`child_process.spawn`](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options), when `TRUE` then `{ stdio: null }` used
104 -- `[callback] {Function}` - `callback(err, stdout, stderr)`
105 - - `err {Error|NULL}` - Error object. Has `code` property containing last command exit code when available
106 - - `stdout {String|NULL}` - aggregated stdout or `NULL` if not available
107 - - `stderr {String|NULL}` - aggregated stderr or `NULL` if not available
108 -
109 -**Return Values:**
110 -
111 -Returns [ChildProcess](http://nodejs.org/api/child_process.html#child_process_class_childprocess) object.
112 -
113 -## Private API
114 -Complete API Documentation including private and public methods is generated from source code by JSDoc tool and is [available here](https://s3.eu-central-1.amazonaws.com/tsertkov-artifacts/exec-sh/master/jsdoc/index.html).
115 -
116 -## Code Coverage
117 -Code coverage report for all files is [available here](https://s3.eu-central-1.amazonaws.com/tsertkov-artifacts/exec-sh/master/coverage/index.html).
118 -
119 -## Scripts
120 -
121 -- `npm test` - run tests
122 -- `npm run jsdoc` - build jsdoc
123 -- `npm run dev` - run tests continuously
124 -
125 -## License
126 -
127 -The MIT License (MIT)
1 -var execSh = require('../')
2 -
3 -// run interactive bash shell
4 -execSh('echo ola && bash', { cwd: '/home' }, function (err) {
5 - if (err) {
6 - console.log('Exit code: ', err.code)
7 - return
8 - }
9 -
10 - // collect streams output
11 - execSh(['bash -c id', 'echo olaola >&2'], true,
12 - function (err, stdout, stderr) {
13 - console.log('error: ', err)
14 - console.log('stdout: ', stdout)
15 - console.log('stderr: ', stderr)
16 - })
17 -})
1 -var cp = require('child_process')
2 -
3 -var defSpawnOptions = { stdio: 'inherit' }
4 -
5 -/**
6 - * @summary Get shell program meta for current platform
7 - * @private
8 - * @returns {Object}
9 - */
10 -function getShell () {
11 - if (process.platform === 'win32') {
12 - return { cmd: 'cmd', arg: '/C' }
13 - } else {
14 - return { cmd: 'sh', arg: '-c' }
15 - }
16 -}
17 -
18 -/**
19 - * Callback is called with the output when the process terminates. Output is
20 - * available when true is passed as options argument or stdio: null set
21 - * within given options.
22 - *
23 - * @summary Execute shell command forwarding all stdio
24 - * @param {String|Array} command
25 - * @param {Object|TRUE} [options] spawn() options or TRUE to set stdio: null
26 - * @param {Function} [callback]
27 - * @returns {ChildProcess}
28 - */
29 -function execSh (command, options, callback) {
30 - if (Array.isArray(command)) {
31 - command = command.join(';')
32 - }
33 -
34 - if (options === true) {
35 - options = { stdio: null }
36 - }
37 -
38 - if (typeof options === 'function') {
39 - callback = options
40 - options = defSpawnOptions
41 - } else {
42 - options = options || {}
43 - options = Object.assign({}, defSpawnOptions, options)
44 - callback = callback || function () {}
45 - }
46 -
47 - var child
48 - var stdout = ''
49 - var stderr = ''
50 - var shell = getShell()
51 -
52 - try {
53 - child = cp.spawn(shell.cmd, [shell.arg, command], options)
54 - } catch (e) {
55 - callback(e, stdout, stderr)
56 - return
57 - }
58 -
59 - if (child.stdout) {
60 - child.stdout.on('data', function (data) {
61 - stdout += data
62 - })
63 - }
64 -
65 - if (child.stderr) {
66 - child.stderr.on('data', function (data) {
67 - stderr += data
68 - })
69 - }
70 -
71 - child.on('close', function (code) {
72 - if (code) {
73 - var e = new Error('Shell command exit with non zero code: ' + code)
74 - e.code = code
75 - callback(e, stdout, stderr)
76 - } else {
77 - callback(null, stdout, stderr)
78 - }
79 - })
80 -
81 - return child
82 -}
83 -
84 -execSh.promise = function (command, options) {
85 - return new Promise(function (resolve, reject) {
86 - execSh(command, options, function (err, stdout, stderr) {
87 - if (err) {
88 - err.stdout = stdout
89 - err.stderr = stderr
90 - return reject(err)
91 - }
92 -
93 - resolve({
94 - stderr: stderr,
95 - stdout: stdout
96 - })
97 - })
98 - })
99 -}
100 -
101 -module.exports = execSh
1 -{
2 - "_from": "exec-sh@^0.3.2",
3 - "_id": "exec-sh@0.3.4",
4 - "_inBundle": false,
5 - "_integrity": "sha512-sEFIkc61v75sWeOe72qyrqg2Qg0OuLESziUDk/O/z2qgS15y2gWVFrI6f2Qn/qw/0/NCfCEsmNA4zOjkwEZT1A==",
6 - "_location": "/exec-sh",
7 - "_phantomChildren": {},
8 - "_requested": {
9 - "type": "range",
10 - "registry": true,
11 - "raw": "exec-sh@^0.3.2",
12 - "name": "exec-sh",
13 - "escapedName": "exec-sh",
14 - "rawSpec": "^0.3.2",
15 - "saveSpec": null,
16 - "fetchSpec": "^0.3.2"
17 - },
18 - "_requiredBy": [
19 - "/@cnakazawa/watch",
20 - "/sane"
21 - ],
22 - "_resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.4.tgz",
23 - "_shasum": "3a018ceb526cc6f6df2bb504b2bfe8e3a4934ec5",
24 - "_spec": "exec-sh@^0.3.2",
25 - "_where": "C:\\Users\\kkwan_000\\Desktop\\git\\2017110269\\minsung\\node_modules\\sane",
26 - "author": {
27 - "name": "Aleksandr Tsertkov",
28 - "email": "tsertkov@gmail.com"
29 - },
30 - "bugs": {
31 - "url": "https://github.com/tsertkov/exec-sh/issues"
32 - },
33 - "bundleDependencies": false,
34 - "dependencies": {},
35 - "deprecated": false,
36 - "description": "Execute shell command forwarding all stdio.",
37 - "devDependencies": {
38 - "coveralls": "^3.0.7",
39 - "jsdoc": "^3.6.3",
40 - "jshint": "^2.10.3",
41 - "mocha": "^6.2.2",
42 - "nyc": "^14.1.1",
43 - "sinon": "^7.5.0",
44 - "standard": "^14.3.1"
45 - },
46 - "homepage": "https://github.com/tsertkov/exec-sh#readme",
47 - "keywords": [
48 - "exec",
49 - "spawn",
50 - "terminal",
51 - "console",
52 - "shell",
53 - "command",
54 - "child_process"
55 - ],
56 - "license": "MIT",
57 - "main": "lib/exec-sh.js",
58 - "name": "exec-sh",
59 - "repository": {
60 - "type": "git",
61 - "url": "git+ssh://git@github.com/tsertkov/exec-sh.git"
62 - },
63 - "scripts": {
64 - "cover-test": "nyc --reporter=html --report-dir=artifacts/coverage mocha",
65 - "dev": "mocha --reporter spec --watch",
66 - "jsdoc": "jsdoc --private --destination artifacts/jsdoc lib/",
67 - "lint": "standard --verbose **/*.js",
68 - "test": "npm run lint && npm run cover-test"
69 - },
70 - "version": "0.3.4"
71 -}
1 -/* global describe, it, beforeEach, afterEach */
2 -var execSh = require('..')
3 -var assert = require('assert')
4 -var sinon = require('sinon')
5 -var cp = require('child_process')
6 -
7 -describe('exec-sh', function () {
8 - describe('module.exports', function () {
9 - it('should export a single function', function () {
10 - assert.strictEqual(typeof execSh, 'function')
11 - })
12 -
13 - it('should export promise interface', function () {
14 - assert.strictEqual(typeof execSh.promise, 'function')
15 - })
16 - })
17 -
18 - describe('#execSh() arguments', function () {
19 - var spawn, exitCode, stream
20 -
21 - stream = {
22 - on: function (e, c) {
23 - if (e === 'data') {
24 - // execute callback two times to check if stream
25 - // aggregation works correctly
26 - c('1')
27 - c('2')
28 - }
29 - }
30 - }
31 -
32 - beforeEach(function () {
33 - exitCode = 0
34 - spawn = sinon.stub(cp, 'spawn')
35 - spawn.returns({
36 - spawn_return: true,
37 - on: function (e, c) {
38 - if (e === 'close') {
39 - c(exitCode)
40 - }
41 - },
42 - stdout: stream,
43 - stderr: stream
44 - })
45 - })
46 -
47 - afterEach(function () {
48 - cp.spawn.restore()
49 - })
50 -
51 - it('should pass command to spawn function', function () {
52 - execSh('command')
53 - sinon.assert.calledOnce(spawn)
54 - assert.strictEqual('command', spawn.getCall(0).args[1][1])
55 - })
56 -
57 - it('should accept array of commands to run', function () {
58 - execSh(['command1', 'command2'])
59 - sinon.assert.calledOnce(spawn)
60 - assert.strictEqual('command1;command2', spawn.getCall(0).args[1][1])
61 - })
62 -
63 - it('should accept true as options argument', function () {
64 - execSh('command', true)
65 - sinon.assert.calledOnce(spawn)
66 - assert.strictEqual(spawn.getCall(0).args[2].stdio, null)
67 - })
68 -
69 - it('should merge defaults with options', function () {
70 - var options = { key: 'value' }
71 - var expectedOptions = {
72 - key: 'value',
73 - stdio: 'inherit'
74 - }
75 - execSh('command', options)
76 - assert.deepStrictEqual(spawn.getCall(0).args[2], expectedOptions)
77 - })
78 -
79 - it('should allow overriding default options', function () {
80 - var options = { foo: 'bar', stdio: null }
81 - var expectedOptions = {
82 - foo: 'bar',
83 - stdio: null
84 - }
85 - execSh('command', options)
86 - assert.deepStrictEqual(spawn.getCall(0).args[2], expectedOptions)
87 - })
88 -
89 - it('should allow passing nested environment options', function () {
90 - var options = {
91 - env: {
92 - key1: 'value 1',
93 - key2: 'value 2'
94 - }
95 - }
96 - var expectedOptions = {
97 - env: {
98 - key1: 'value 1',
99 - key2: 'value 2'
100 - },
101 - stdio: 'inherit'
102 - }
103 - execSh('command', options)
104 - assert.deepStrictEqual(spawn.getCall(0).args[2], expectedOptions)
105 - })
106 -
107 - it("should accept optional 'callback' parameter", function () {
108 - var callback = sinon.spy()
109 - execSh('command', callback)
110 - execSh('command', { key: 'value' }, callback)
111 - sinon.assert.callCount(callback, 2)
112 - })
113 -
114 - it("should use 'cmd /C' command prefix on windows", function () {
115 - var platform = process.platform
116 - Object.defineProperty(process, 'platform', { value: 'win32' })
117 - execSh('command')
118 - Object.defineProperty(process, 'platform', { value: platform })
119 -
120 - sinon.assert.calledOnce(spawn)
121 - assert.strictEqual(spawn.getCall(0).args[0], 'cmd')
122 - })
123 -
124 - it("should use 'sh -c' command prefix on *nix", function () {
125 - var platform = process.platform
126 - process.platform = 'linux'
127 - execSh('command')
128 - process.platform = platform
129 -
130 - sinon.assert.calledOnce(spawn)
131 - assert.strictEqual(spawn.getCall(0).args[1][0], '-c')
132 - assert.strictEqual(spawn.getCall(0).args[0], 'sh')
133 - })
134 -
135 - it('should return spawn() result', function () {
136 - assert(execSh('command').spawn_return)
137 - })
138 -
139 - it('should aggregate stdoout and stderr', function (done) {
140 - execSh('command', function (_err, stdout, stderr) {
141 - assert.strictEqual(stdout, '12')
142 - assert.strictEqual(stderr, '12')
143 - done()
144 - })
145 - })
146 -
147 - it('should catch exceptions thrown by spawn', function (done) {
148 - spawn.throws()
149 - execSh('command', function (err, stdout, stderr) {
150 - assert(err instanceof Error)
151 - done()
152 - })
153 - })
154 -
155 - it('should return empty stdout and stderr when spawn throws', function (done) {
156 - spawn.throws()
157 - stream = null
158 - execSh('command', function (_err, stdout, stderr) {
159 - assert.strictEqual(stderr, '')
160 - assert.strictEqual(stdout, '')
161 - done()
162 - })
163 - })
164 -
165 - it('should run callback with error when shell exit with non-zero code', function (done) {
166 - exitCode = 1
167 - execSh('command', function (err) {
168 - assert(err instanceof Error)
169 - assert.strictEqual(exitCode, err.code)
170 - done()
171 - })
172 - })
173 -
174 - it('promise interface: should return promise', function () {
175 - assert(execSh.promise('command') instanceof Promise)
176 - })
177 -
178 - it('promise interface: should resolve with stderr and stdout', function (done) {
179 - execSh.promise('command').then(function (data) {
180 - assert.ok('stdout' in data)
181 - assert.ok('stderr' in data)
182 - done()
183 - })
184 - })
185 -
186 - it('promise interface: should reject promise when exceptions thrown by spawn', function (done) {
187 - spawn.throws()
188 - execSh.promise('command').catch(function (err) {
189 - assert(err instanceof Error)
190 - done()
191 - })
192 - })
193 - })
194 -})
1 -'use strict';
2 -const path = require('path');
3 -const childProcess = require('child_process');
4 -const crossSpawn = require('cross-spawn');
5 -const stripEof = require('strip-eof');
6 -const npmRunPath = require('npm-run-path');
7 -const isStream = require('is-stream');
8 -const _getStream = require('get-stream');
9 -const pFinally = require('p-finally');
10 -const onExit = require('signal-exit');
11 -const errname = require('./lib/errname');
12 -const stdio = require('./lib/stdio');
13 -
14 -const TEN_MEGABYTES = 1000 * 1000 * 10;
15 -
16 -function handleArgs(cmd, args, opts) {
17 - let parsed;
18 -
19 - opts = Object.assign({
20 - extendEnv: true,
21 - env: {}
22 - }, opts);
23 -
24 - if (opts.extendEnv) {
25 - opts.env = Object.assign({}, process.env, opts.env);
26 - }
27 -
28 - if (opts.__winShell === true) {
29 - delete opts.__winShell;
30 - parsed = {
31 - command: cmd,
32 - args,
33 - options: opts,
34 - file: cmd,
35 - original: {
36 - cmd,
37 - args
38 - }
39 - };
40 - } else {
41 - parsed = crossSpawn._parse(cmd, args, opts);
42 - }
43 -
44 - opts = Object.assign({
45 - maxBuffer: TEN_MEGABYTES,
46 - buffer: true,
47 - stripEof: true,
48 - preferLocal: true,
49 - localDir: parsed.options.cwd || process.cwd(),
50 - encoding: 'utf8',
51 - reject: true,
52 - cleanup: true
53 - }, parsed.options);
54 -
55 - opts.stdio = stdio(opts);
56 -
57 - if (opts.preferLocal) {
58 - opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
59 - }
60 -
61 - if (opts.detached) {
62 - // #115
63 - opts.cleanup = false;
64 - }
65 -
66 - if (process.platform === 'win32' && path.basename(parsed.command) === 'cmd.exe') {
67 - // #116
68 - parsed.args.unshift('/q');
69 - }
70 -
71 - return {
72 - cmd: parsed.command,
73 - args: parsed.args,
74 - opts,
75 - parsed
76 - };
77 -}
78 -
79 -function handleInput(spawned, input) {
80 - if (input === null || input === undefined) {
81 - return;
82 - }
83 -
84 - if (isStream(input)) {
85 - input.pipe(spawned.stdin);
86 - } else {
87 - spawned.stdin.end(input);
88 - }
89 -}
90 -
91 -function handleOutput(opts, val) {
92 - if (val && opts.stripEof) {
93 - val = stripEof(val);
94 - }
95 -
96 - return val;
97 -}
98 -
99 -function handleShell(fn, cmd, opts) {
100 - let file = '/bin/sh';
101 - let args = ['-c', cmd];
102 -
103 - opts = Object.assign({}, opts);
104 -
105 - if (process.platform === 'win32') {
106 - opts.__winShell = true;
107 - file = process.env.comspec || 'cmd.exe';
108 - args = ['/s', '/c', `"${cmd}"`];
109 - opts.windowsVerbatimArguments = true;
110 - }
111 -
112 - if (opts.shell) {
113 - file = opts.shell;
114 - delete opts.shell;
115 - }
116 -
117 - return fn(file, args, opts);
118 -}
119 -
120 -function getStream(process, stream, {encoding, buffer, maxBuffer}) {
121 - if (!process[stream]) {
122 - return null;
123 - }
124 -
125 - let ret;
126 -
127 - if (!buffer) {
128 - // TODO: Use `ret = util.promisify(stream.finished)(process[stream]);` when targeting Node.js 10
129 - ret = new Promise((resolve, reject) => {
130 - process[stream]
131 - .once('end', resolve)
132 - .once('error', reject);
133 - });
134 - } else if (encoding) {
135 - ret = _getStream(process[stream], {
136 - encoding,
137 - maxBuffer
138 - });
139 - } else {
140 - ret = _getStream.buffer(process[stream], {maxBuffer});
141 - }
142 -
143 - return ret.catch(err => {
144 - err.stream = stream;
145 - err.message = `${stream} ${err.message}`;
146 - throw err;
147 - });
148 -}
149 -
150 -function makeError(result, options) {
151 - const {stdout, stderr} = result;
152 -
153 - let err = result.error;
154 - const {code, signal} = result;
155 -
156 - const {parsed, joinedCmd} = options;
157 - const timedOut = options.timedOut || false;
158 -
159 - if (!err) {
160 - let output = '';
161 -
162 - if (Array.isArray(parsed.opts.stdio)) {
163 - if (parsed.opts.stdio[2] !== 'inherit') {
164 - output += output.length > 0 ? stderr : `\n${stderr}`;
165 - }
166 -
167 - if (parsed.opts.stdio[1] !== 'inherit') {
168 - output += `\n${stdout}`;
169 - }
170 - } else if (parsed.opts.stdio !== 'inherit') {
171 - output = `\n${stderr}${stdout}`;
172 - }
173 -
174 - err = new Error(`Command failed: ${joinedCmd}${output}`);
175 - err.code = code < 0 ? errname(code) : code;
176 - }
177 -
178 - err.stdout = stdout;
179 - err.stderr = stderr;
180 - err.failed = true;
181 - err.signal = signal || null;
182 - err.cmd = joinedCmd;
183 - err.timedOut = timedOut;
184 -
185 - return err;
186 -}
187 -
188 -function joinCmd(cmd, args) {
189 - let joinedCmd = cmd;
190 -
191 - if (Array.isArray(args) && args.length > 0) {
192 - joinedCmd += ' ' + args.join(' ');
193 - }
194 -
195 - return joinedCmd;
196 -}
197 -
198 -module.exports = (cmd, args, opts) => {
199 - const parsed = handleArgs(cmd, args, opts);
200 - const {encoding, buffer, maxBuffer} = parsed.opts;
201 - const joinedCmd = joinCmd(cmd, args);
202 -
203 - let spawned;
204 - try {
205 - spawned = childProcess.spawn(parsed.cmd, parsed.args, parsed.opts);
206 - } catch (err) {
207 - return Promise.reject(err);
208 - }
209 -
210 - let removeExitHandler;
211 - if (parsed.opts.cleanup) {
212 - removeExitHandler = onExit(() => {
213 - spawned.kill();
214 - });
215 - }
216 -
217 - let timeoutId = null;
218 - let timedOut = false;
219 -
220 - const cleanup = () => {
221 - if (timeoutId) {
222 - clearTimeout(timeoutId);
223 - timeoutId = null;
224 - }
225 -
226 - if (removeExitHandler) {
227 - removeExitHandler();
228 - }
229 - };
230 -
231 - if (parsed.opts.timeout > 0) {
232 - timeoutId = setTimeout(() => {
233 - timeoutId = null;
234 - timedOut = true;
235 - spawned.kill(parsed.opts.killSignal);
236 - }, parsed.opts.timeout);
237 - }
238 -
239 - const processDone = new Promise(resolve => {
240 - spawned.on('exit', (code, signal) => {
241 - cleanup();
242 - resolve({code, signal});
243 - });
244 -
245 - spawned.on('error', err => {
246 - cleanup();
247 - resolve({error: err});
248 - });
249 -
250 - if (spawned.stdin) {
251 - spawned.stdin.on('error', err => {
252 - cleanup();
253 - resolve({error: err});
254 - });
255 - }
256 - });
257 -
258 - function destroy() {
259 - if (spawned.stdout) {
260 - spawned.stdout.destroy();
261 - }
262 -
263 - if (spawned.stderr) {
264 - spawned.stderr.destroy();
265 - }
266 - }
267 -
268 - const handlePromise = () => pFinally(Promise.all([
269 - processDone,
270 - getStream(spawned, 'stdout', {encoding, buffer, maxBuffer}),
271 - getStream(spawned, 'stderr', {encoding, buffer, maxBuffer})
272 - ]).then(arr => {
273 - const result = arr[0];
274 - result.stdout = arr[1];
275 - result.stderr = arr[2];
276 -
277 - if (result.error || result.code !== 0 || result.signal !== null) {
278 - const err = makeError(result, {
279 - joinedCmd,
280 - parsed,
281 - timedOut
282 - });
283 -
284 - // TODO: missing some timeout logic for killed
285 - // https://github.com/nodejs/node/blob/master/lib/child_process.js#L203
286 - // err.killed = spawned.killed || killed;
287 - err.killed = err.killed || spawned.killed;
288 -
289 - if (!parsed.opts.reject) {
290 - return err;
291 - }
292 -
293 - throw err;
294 - }
295 -
296 - return {
297 - stdout: handleOutput(parsed.opts, result.stdout),
298 - stderr: handleOutput(parsed.opts, result.stderr),
299 - code: 0,
300 - failed: false,
301 - killed: false,
302 - signal: null,
303 - cmd: joinedCmd,
304 - timedOut: false
305 - };
306 - }), destroy);
307 -
308 - crossSpawn._enoent.hookChildProcess(spawned, parsed.parsed);
309 -
310 - handleInput(spawned, parsed.opts.input);
311 -
312 - spawned.then = (onfulfilled, onrejected) => handlePromise().then(onfulfilled, onrejected);
313 - spawned.catch = onrejected => handlePromise().catch(onrejected);
314 -
315 - return spawned;
316 -};
317 -
318 -// TODO: set `stderr: 'ignore'` when that option is implemented
319 -module.exports.stdout = (...args) => module.exports(...args).then(x => x.stdout);
320 -
321 -// TODO: set `stdout: 'ignore'` when that option is implemented
322 -module.exports.stderr = (...args) => module.exports(...args).then(x => x.stderr);
323 -
324 -module.exports.shell = (cmd, opts) => handleShell(module.exports, cmd, opts);
325 -
326 -module.exports.sync = (cmd, args, opts) => {
327 - const parsed = handleArgs(cmd, args, opts);
328 - const joinedCmd = joinCmd(cmd, args);
329 -
330 - if (isStream(parsed.opts.input)) {
331 - throw new TypeError('The `input` option cannot be a stream in sync mode');
332 - }
333 -
334 - const result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts);
335 - result.code = result.status;
336 -
337 - if (result.error || result.status !== 0 || result.signal !== null) {
338 - const err = makeError(result, {
339 - joinedCmd,
340 - parsed
341 - });
342 -
343 - if (!parsed.opts.reject) {
344 - return err;
345 - }
346 -
347 - throw err;
348 - }
349 -
350 - return {
351 - stdout: handleOutput(parsed.opts, result.stdout),
352 - stderr: handleOutput(parsed.opts, result.stderr),
353 - code: 0,
354 - failed: false,
355 - signal: null,
356 - cmd: joinedCmd,
357 - timedOut: false
358 - };
359 -};
360 -
361 -module.exports.shellSync = (cmd, opts) => handleShell(module.exports.sync, cmd, opts);
1 -'use strict';
2 -// Older verions of Node.js might not have `util.getSystemErrorName()`.
3 -// In that case, fall back to a deprecated internal.
4 -const util = require('util');
5 -
6 -let uv;
7 -
8 -if (typeof util.getSystemErrorName === 'function') {
9 - module.exports = util.getSystemErrorName;
10 -} else {
11 - try {
12 - uv = process.binding('uv');
13 -
14 - if (typeof uv.errname !== 'function') {
15 - throw new TypeError('uv.errname is not a function');
16 - }
17 - } catch (err) {
18 - console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', err);
19 - uv = null;
20 - }
21 -
22 - module.exports = code => errname(uv, code);
23 -}
24 -
25 -// Used for testing the fallback behavior
26 -module.exports.__test__ = errname;
27 -
28 -function errname(uv, code) {
29 - if (uv) {
30 - return uv.errname(code);
31 - }
32 -
33 - if (!(code < 0)) {
34 - throw new Error('err >= 0');
35 - }
36 -
37 - return `Unknown system error ${code}`;
38 -}
39 -
1 -'use strict';
2 -const alias = ['stdin', 'stdout', 'stderr'];
3 -
4 -const hasAlias = opts => alias.some(x => Boolean(opts[x]));
5 -
6 -module.exports = opts => {
7 - if (!opts) {
8 - return null;
9 - }
10 -
11 - if (opts.stdio && hasAlias(opts)) {
12 - throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${alias.map(x => `\`${x}\``).join(', ')}`);
13 - }
14 -
15 - if (typeof opts.stdio === 'string') {
16 - return opts.stdio;
17 - }
18 -
19 - const stdio = opts.stdio || [];
20 -
21 - if (!Array.isArray(stdio)) {
22 - throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
23 - }
24 -
25 - const result = [];
26 - const len = Math.max(stdio.length, alias.length);
27 -
28 - for (let i = 0; i < len; i++) {
29 - let value = null;
30 -
31 - if (stdio[i] !== undefined) {
32 - value = stdio[i];
33 - } else if (opts[alias[i]] !== undefined) {
34 - value = opts[alias[i]];
35 - }
36 -
37 - result[i] = value;
38 - }
39 -
40 - return result;
41 -};
1 -MIT License
2 -
3 -Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
4 -
5 -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:
6 -
7 -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 -
9 -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.
1 -{
2 - "_from": "execa@^1.0.0",
3 - "_id": "execa@1.0.0",
4 - "_inBundle": false,
5 - "_integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==",
6 - "_location": "/execa",
7 - "_phantomChildren": {},
8 - "_requested": {
9 - "type": "range",
10 - "registry": true,
11 - "raw": "execa@^1.0.0",
12 - "name": "execa",
13 - "escapedName": "execa",
14 - "rawSpec": "^1.0.0",
15 - "saveSpec": null,
16 - "fetchSpec": "^1.0.0"
17 - },
18 - "_requiredBy": [
19 - "/default-gateway",
20 - "/sane"
21 - ],
22 - "_resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz",
23 - "_shasum": "c6236a5bb4df6d6f15e88e7f017798216749ddd8",
24 - "_spec": "execa@^1.0.0",
25 - "_where": "C:\\Users\\kkwan_000\\Desktop\\git\\2017110269\\minsung\\node_modules\\sane",
26 - "author": {
27 - "name": "Sindre Sorhus",
28 - "email": "sindresorhus@gmail.com",
29 - "url": "sindresorhus.com"
30 - },
31 - "bugs": {
32 - "url": "https://github.com/sindresorhus/execa/issues"
33 - },
34 - "bundleDependencies": false,
35 - "dependencies": {
36 - "cross-spawn": "^6.0.0",
37 - "get-stream": "^4.0.0",
38 - "is-stream": "^1.1.0",
39 - "npm-run-path": "^2.0.0",
40 - "p-finally": "^1.0.0",
41 - "signal-exit": "^3.0.0",
42 - "strip-eof": "^1.0.0"
43 - },
44 - "deprecated": false,
45 - "description": "A better `child_process`",
46 - "devDependencies": {
47 - "ava": "*",
48 - "cat-names": "^1.0.2",
49 - "coveralls": "^3.0.1",
50 - "delay": "^3.0.0",
51 - "is-running": "^2.0.0",
52 - "nyc": "^13.0.1",
53 - "tempfile": "^2.0.0",
54 - "xo": "*"
55 - },
56 - "engines": {
57 - "node": ">=6"
58 - },
59 - "files": [
60 - "index.js",
61 - "lib"
62 - ],
63 - "homepage": "https://github.com/sindresorhus/execa#readme",
64 - "keywords": [
65 - "exec",
66 - "child",
67 - "process",
68 - "execute",
69 - "fork",
70 - "execfile",
71 - "spawn",
72 - "file",
73 - "shell",
74 - "bin",
75 - "binary",
76 - "binaries",
77 - "npm",
78 - "path",
79 - "local"
80 - ],
81 - "license": "MIT",
82 - "name": "execa",
83 - "nyc": {
84 - "reporter": [
85 - "text",
86 - "lcov"
87 - ],
88 - "exclude": [
89 - "**/fixtures/**",
90 - "**/test.js",
91 - "**/test/**"
92 - ]
93 - },
94 - "repository": {
95 - "type": "git",
96 - "url": "git+https://github.com/sindresorhus/execa.git"
97 - },
98 - "scripts": {
99 - "test": "xo && nyc ava"
100 - },
101 - "version": "1.0.0"
102 -}
1 -# execa [![Build Status: Linux](https://travis-ci.org/sindresorhus/execa.svg?branch=master)](https://travis-ci.org/sindresorhus/execa) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/x5ajamxtjtt93cqv/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/execa/branch/master) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/execa/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/execa?branch=master)
2 -
3 -> A better [`child_process`](https://nodejs.org/api/child_process.html)
4 -
5 -
6 -## Why
7 -
8 -- Promise interface.
9 -- [Strips EOF](https://github.com/sindresorhus/strip-eof) from the output so you don't have to `stdout.trim()`.
10 -- Supports [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries cross-platform.
11 -- [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why)
12 -- Higher max buffer. 10 MB instead of 200 KB.
13 -- [Executes locally installed binaries by name.](#preferlocal)
14 -- [Cleans up spawned processes when the parent process dies.](#cleanup)
15 -
16 -
17 -## Install
18 -
19 -```
20 -$ npm install execa
21 -```
22 -
23 -<a href="https://www.patreon.com/sindresorhus">
24 - <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
25 -</a>
26 -
27 -
28 -## Usage
29 -
30 -```js
31 -const execa = require('execa');
32 -
33 -(async () => {
34 - const {stdout} = await execa('echo', ['unicorns']);
35 - console.log(stdout);
36 - //=> 'unicorns'
37 -})();
38 -```
39 -
40 -Additional examples:
41 -
42 -```js
43 -const execa = require('execa');
44 -
45 -(async () => {
46 - // Pipe the child process stdout to the current stdout
47 - execa('echo', ['unicorns']).stdout.pipe(process.stdout);
48 -
49 -
50 - // Run a shell command
51 - const {stdout} = await execa.shell('echo unicorns');
52 - //=> 'unicorns'
53 -
54 -
55 - // Catching an error
56 - try {
57 - await execa.shell('exit 3');
58 - } catch (error) {
59 - console.log(error);
60 - /*
61 - {
62 - message: 'Command failed: /bin/sh -c exit 3'
63 - killed: false,
64 - code: 3,
65 - signal: null,
66 - cmd: '/bin/sh -c exit 3',
67 - stdout: '',
68 - stderr: '',
69 - timedOut: false
70 - }
71 - */
72 - }
73 -})();
74 -
75 -// Catching an error with a sync method
76 -try {
77 - execa.shellSync('exit 3');
78 -} catch (error) {
79 - console.log(error);
80 - /*
81 - {
82 - message: 'Command failed: /bin/sh -c exit 3'
83 - code: 3,
84 - signal: null,
85 - cmd: '/bin/sh -c exit 3',
86 - stdout: '',
87 - stderr: '',
88 - timedOut: false
89 - }
90 - */
91 -}
92 -```
93 -
94 -
95 -## API
96 -
97 -### execa(file, [arguments], [options])
98 -
99 -Execute a file.
100 -
101 -Think of this as a mix of `child_process.execFile` and `child_process.spawn`.
102 -
103 -Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties.
104 -
105 -### execa.stdout(file, [arguments], [options])
106 -
107 -Same as `execa()`, but returns only `stdout`.
108 -
109 -### execa.stderr(file, [arguments], [options])
110 -
111 -Same as `execa()`, but returns only `stderr`.
112 -
113 -### execa.shell(command, [options])
114 -
115 -Execute a command through the system shell. Prefer `execa()` whenever possible, as it's both faster and safer.
116 -
117 -Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess).
118 -
119 -The `child_process` instance is enhanced to also be promise for a result object with `stdout` and `stderr` properties.
120 -
121 -### execa.sync(file, [arguments], [options])
122 -
123 -Execute a file synchronously.
124 -
125 -Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).
126 -
127 -This method throws an `Error` if the command fails.
128 -
129 -### execa.shellSync(file, [options])
130 -
131 -Execute a command synchronously through the system shell.
132 -
133 -Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).
134 -
135 -### options
136 -
137 -Type: `Object`
138 -
139 -#### cwd
140 -
141 -Type: `string`<br>
142 -Default: `process.cwd()`
143 -
144 -Current working directory of the child process.
145 -
146 -#### env
147 -
148 -Type: `Object`<br>
149 -Default: `process.env`
150 -
151 -Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.
152 -
153 -#### extendEnv
154 -
155 -Type: `boolean`<br>
156 -Default: `true`
157 -
158 -Set to `false` if you don't want to extend the environment variables when providing the `env` property.
159 -
160 -#### argv0
161 -
162 -Type: `string`
163 -
164 -Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified.
165 -
166 -#### stdio
167 -
168 -Type: `string[]` `string`<br>
169 -Default: `pipe`
170 -
171 -Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.
172 -
173 -#### detached
174 -
175 -Type: `boolean`
176 -
177 -Prepare child to run independently of its parent process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).
178 -
179 -#### uid
180 -
181 -Type: `number`
182 -
183 -Sets the user identity of the process.
184 -
185 -#### gid
186 -
187 -Type: `number`
188 -
189 -Sets the group identity of the process.
190 -
191 -#### shell
192 -
193 -Type: `boolean` `string`<br>
194 -Default: `false`
195 -
196 -If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.
197 -
198 -#### stripEof
199 -
200 -Type: `boolean`<br>
201 -Default: `true`
202 -
203 -[Strip EOF](https://github.com/sindresorhus/strip-eof) (last newline) from the output.
204 -
205 -#### preferLocal
206 -
207 -Type: `boolean`<br>
208 -Default: `true`
209 -
210 -Prefer locally installed binaries when looking for a binary to execute.<br>
211 -If you `$ npm install foo`, you can then `execa('foo')`.
212 -
213 -#### localDir
214 -
215 -Type: `string`<br>
216 -Default: `process.cwd()`
217 -
218 -Preferred path to find locally installed binaries in (use with `preferLocal`).
219 -
220 -#### input
221 -
222 -Type: `string` `Buffer` `stream.Readable`
223 -
224 -Write some input to the `stdin` of your binary.<br>
225 -Streams are not allowed when using the synchronous methods.
226 -
227 -#### reject
228 -
229 -Type: `boolean`<br>
230 -Default: `true`
231 -
232 -Setting this to `false` resolves the promise with the error instead of rejecting it.
233 -
234 -#### cleanup
235 -
236 -Type: `boolean`<br>
237 -Default: `true`
238 -
239 -Keep track of the spawned process and `kill` it when the parent process exits.
240 -
241 -#### encoding
242 -
243 -Type: `string`<br>
244 -Default: `utf8`
245 -
246 -Specify the character encoding used to decode the `stdout` and `stderr` output.
247 -
248 -#### timeout
249 -
250 -Type: `number`<br>
251 -Default: `0`
252 -
253 -If timeout is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than timeout milliseconds.
254 -
255 -#### buffer
256 -
257 -Type: `boolean`<br>
258 -Default: `true`
259 -
260 -Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.
261 -
262 -#### maxBuffer
263 -
264 -Type: `number`<br>
265 -Default: `10000000` (10MB)
266 -
267 -Largest amount of data in bytes allowed on `stdout` or `stderr`.
268 -
269 -#### killSignal
270 -
271 -Type: `string` `number`<br>
272 -Default: `SIGTERM`
273 -
274 -Signal value to be used when the spawned process will be killed.
275 -
276 -#### stdin
277 -
278 -Type: `string` `number` `Stream` `undefined` `null`<br>
279 -Default: `pipe`
280 -
281 -Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
282 -
283 -#### stdout
284 -
285 -Type: `string` `number` `Stream` `undefined` `null`<br>
286 -Default: `pipe`
287 -
288 -Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
289 -
290 -#### stderr
291 -
292 -Type: `string` `number` `Stream` `undefined` `null`<br>
293 -Default: `pipe`
294 -
295 -Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
296 -
297 -#### windowsVerbatimArguments
298 -
299 -Type: `boolean`<br>
300 -Default: `false`
301 -
302 -If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`.
303 -
304 -
305 -## Tips
306 -
307 -### Save and pipe output from a child process
308 -
309 -Let's say you want to show the output of a child process in real-time while also saving it to a variable.
310 -
311 -```js
312 -const execa = require('execa');
313 -const getStream = require('get-stream');
314 -
315 -const stream = execa('echo', ['foo']).stdout;
316 -
317 -stream.pipe(process.stdout);
318 -
319 -getStream(stream).then(value => {
320 - console.log('child output:', value);
321 -});
322 -```
323 -
324 -
325 -## License
326 -
327 -MIT © [Sindre Sorhus](https://sindresorhus.com)
1 -{
2 - "curly": true,
3 - "eqeqeq": true,
4 - "immed": true,
5 - "latedef": "nofunc",
6 - "newcap": true,
7 - "noarg": true,
8 - "sub": true,
9 - "undef": true,
10 - "unused": true,
11 - "boss": true,
12 - "eqnull": true,
13 - "node": true
14 -}
1 -language: node_js
2 -node_js:
3 - - 0.8
4 - - '0.10'
5 -before_script:
6 - - npm install -g grunt-cli
1 -'use strict';
2 -
3 -module.exports = function(grunt) {
4 -
5 - // Project configuration.
6 - grunt.initConfig({
7 - nodeunit: {
8 - files: ['test/**/*_test.js'],
9 - },
10 - jshint: {
11 - options: {
12 - jshintrc: '.jshintrc'
13 - },
14 - gruntfile: {
15 - src: 'Gruntfile.js'
16 - },
17 - lib: {
18 - src: ['lib/**/*.js']
19 - },
20 - test: {
21 - src: ['test/**/*.js']
22 - },
23 - },
24 - watch: {
25 - gruntfile: {
26 - files: '<%= jshint.gruntfile.src %>',
27 - tasks: ['jshint:gruntfile']
28 - },
29 - lib: {
30 - files: '<%= jshint.lib.src %>',
31 - tasks: ['jshint:lib', 'nodeunit']
32 - },
33 - test: {
34 - files: '<%= jshint.test.src %>',
35 - tasks: ['jshint:test', 'nodeunit']
36 - },
37 - },
38 - });
39 -
40 - // These plugins provide necessary tasks.
41 - grunt.loadNpmTasks('grunt-contrib-nodeunit');
42 - grunt.loadNpmTasks('grunt-contrib-jshint');
43 - grunt.loadNpmTasks('grunt-contrib-watch');
44 -
45 - // Default task.
46 - grunt.registerTask('default', ['jshint', 'nodeunit']);
47 -
48 -};
1 -Copyright (c) 2013 "Cowboy" Ben Alman
2 -
3 -Permission is hereby granted, free of charge, to any person
4 -obtaining a copy of this software and associated documentation
5 -files (the "Software"), to deal in the Software without
6 -restriction, including without limitation the rights to use,
7 -copy, modify, merge, publish, distribute, sublicense, and/or sell
8 -copies of the Software, and to permit persons to whom the
9 -Software is furnished to do so, subject to the following
10 -conditions:
11 -
12 -The above copyright notice and this permission notice shall be
13 -included in all copies or substantial portions of the Software.
14 -
15 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 -OTHER DEALINGS IN THE SOFTWARE.
1 -# exit [![Build Status](https://secure.travis-ci.org/cowboy/node-exit.png?branch=master)](http://travis-ci.org/cowboy/node-exit)
2 -
3 -A replacement for process.exit that ensures stdio are fully drained before exiting.
4 -
5 -To make a long story short, if `process.exit` is called on Windows, script output is often truncated when pipe-redirecting `stdout` or `stderr`. This module attempts to work around this issue by waiting until those streams have been completely drained before actually calling `process.exit`.
6 -
7 -See [Node.js issue #3584](https://github.com/joyent/node/issues/3584) for further reference.
8 -
9 -Tested in OS X 10.8, Windows 7 on Node.js 0.8.25 and 0.10.18.
10 -
11 -Based on some code by [@vladikoff](https://github.com/vladikoff).
12 -
13 -## Getting Started
14 -Install the module with: `npm install exit`
15 -
16 -```javascript
17 -var exit = require('exit');
18 -
19 -// These lines should appear in the output, EVEN ON WINDOWS.
20 -console.log("omg");
21 -console.error("yay");
22 -
23 -// process.exit(5);
24 -exit(5);
25 -
26 -// These lines shouldn't appear in the output.
27 -console.log("wtf");
28 -console.error("bro");
29 -```
30 -
31 -## Don't believe me? Try it for yourself.
32 -
33 -In Windows, clone the repo and cd to the `test\fixtures` directory. The only difference between [log.js](test/fixtures/log.js) and [log-broken.js](test/fixtures/log-broken.js) is that the former uses `exit` while the latter calls `process.exit` directly.
34 -
35 -This test was done using cmd.exe, but you can see the same results using `| grep "std"` in either PowerShell or git-bash.
36 -
37 -```
38 -C:\node-exit\test\fixtures>node log.js 0 10 stdout stderr 2>&1 | find "std"
39 -stdout 0
40 -stderr 0
41 -stdout 1
42 -stderr 1
43 -stdout 2
44 -stderr 2
45 -stdout 3
46 -stderr 3
47 -stdout 4
48 -stderr 4
49 -stdout 5
50 -stderr 5
51 -stdout 6
52 -stderr 6
53 -stdout 7
54 -stderr 7
55 -stdout 8
56 -stderr 8
57 -stdout 9
58 -stderr 9
59 -
60 -C:\node-exit\test\fixtures>node log-broken.js 0 10 stdout stderr 2>&1 | find "std"
61 -
62 -C:\node-exit\test\fixtures>
63 -```
64 -
65 -## Contributing
66 -In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
67 -
68 -## Release History
69 -2013-11-26 - v0.1.2 - Fixed a bug with hanging processes.
70 -2013-09-26 - v0.1.1 - Fixed some bugs. It seems to actually work now!
71 -2013-09-20 - v0.1.0 - Initial release.
72 -
73 -## License
74 -Copyright (c) 2013 "Cowboy" Ben Alman
75 -Licensed under the MIT license.
1 -/*
2 - * exit
3 - * https://github.com/cowboy/node-exit
4 - *
5 - * Copyright (c) 2013 "Cowboy" Ben Alman
6 - * Licensed under the MIT license.
7 - */
8 -
9 -'use strict';
10 -
11 -module.exports = function exit(exitCode, streams) {
12 - if (!streams) { streams = [process.stdout, process.stderr]; }
13 - var drainCount = 0;
14 - // Actually exit if all streams are drained.
15 - function tryToExit() {
16 - if (drainCount === streams.length) {
17 - process.exit(exitCode);
18 - }
19 - }
20 - streams.forEach(function(stream) {
21 - // Count drained streams now, but monitor non-drained streams.
22 - if (stream.bufferSize === 0) {
23 - drainCount++;
24 - } else {
25 - stream.write('', 'utf-8', function() {
26 - drainCount++;
27 - tryToExit();
28 - });
29 - }
30 - // Prevent further writing.
31 - stream.write = function() {};
32 - });
33 - // If all streams were already drained, exit now.
34 - tryToExit();
35 - // In Windows, when run as a Node.js child process, a script utilizing
36 - // this library might just exit with a 0 exit code, regardless. This code,
37 - // despite the fact that it looks a bit crazy, appears to fix that.
38 - process.on('exit', function() {
39 - process.exit(exitCode);
40 - });
41 -};
1 -{
2 - "_from": "exit@^0.1.2",
3 - "_id": "exit@0.1.2",
4 - "_inBundle": false,
5 - "_integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=",
6 - "_location": "/exit",
7 - "_phantomChildren": {},
8 - "_requested": {
9 - "type": "range",
10 - "registry": true,
11 - "raw": "exit@^0.1.2",
12 - "name": "exit",
13 - "escapedName": "exit",
14 - "rawSpec": "^0.1.2",
15 - "saveSpec": null,
16 - "fetchSpec": "^0.1.2"
17 - },
18 - "_requiredBy": [
19 - "/@jest/core",
20 - "/@jest/reporters",
21 - "/jest-runner",
22 - "/jest-runtime",
23 - "/jest/jest-cli"
24 - ],
25 - "_resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz",
26 - "_shasum": "0632638f8d877cc82107d30a0fff1a17cba1cd0c",
27 - "_spec": "exit@^0.1.2",
28 - "_where": "C:\\Users\\kkwan_000\\Desktop\\git\\2017110269\\minsung\\node_modules\\@jest\\core",
29 - "author": {
30 - "name": "\"Cowboy\" Ben Alman",
31 - "url": "http://benalman.com/"
32 - },
33 - "bugs": {
34 - "url": "https://github.com/cowboy/node-exit/issues"
35 - },
36 - "bundleDependencies": false,
37 - "deprecated": false,
38 - "description": "A replacement for process.exit that ensures stdio are fully drained before exiting.",
39 - "devDependencies": {
40 - "grunt": "~0.4.1",
41 - "grunt-contrib-jshint": "~0.6.4",
42 - "grunt-contrib-nodeunit": "~0.2.0",
43 - "grunt-contrib-watch": "~0.5.3",
44 - "which": "~1.0.5"
45 - },
46 - "engines": {
47 - "node": ">= 0.8.0"
48 - },
49 - "homepage": "https://github.com/cowboy/node-exit",
50 - "keywords": [
51 - "exit",
52 - "process",
53 - "stdio",
54 - "stdout",
55 - "stderr",
56 - "drain",
57 - "flush",
58 - "3584"
59 - ],
60 - "licenses": [
61 - {
62 - "type": "MIT",
63 - "url": "https://github.com/cowboy/node-exit/blob/master/LICENSE-MIT"
64 - }
65 - ],
66 - "main": "lib/exit",
67 - "name": "exit",
68 - "repository": {
69 - "type": "git",
70 - "url": "git://github.com/cowboy/node-exit.git"
71 - },
72 - "scripts": {
73 - "test": "grunt nodeunit"
74 - },
75 - "version": "0.1.2"
76 -}
1 -'use strict';
2 -
3 -/*
4 - ======== A Handy Little Nodeunit Reference ========
5 - https://github.com/caolan/nodeunit
6 -
7 - Test methods:
8 - test.expect(numAssertions)
9 - test.done()
10 - Test assertions:
11 - test.ok(value, [message])
12 - test.equal(actual, expected, [message])
13 - test.notEqual(actual, expected, [message])
14 - test.deepEqual(actual, expected, [message])
15 - test.notDeepEqual(actual, expected, [message])
16 - test.strictEqual(actual, expected, [message])
17 - test.notStrictEqual(actual, expected, [message])
18 - test.throws(block, [error], [message])
19 - test.doesNotThrow(block, [error], [message])
20 - test.ifError(value)
21 -*/
22 -
23 -var fs = require('fs');
24 -var exec = require('child_process').exec;
25 -
26 -var _which = require('which').sync;
27 -function which(command) {
28 - try {
29 - _which(command);
30 - return command;
31 - } catch (err) {
32 - return false;
33 - }
34 -}
35 -
36 -// Look for grep first (any OS). If not found (but on Windows) look for find,
37 -// which is Windows' horribly crippled grep alternative.
38 -var grep = which('grep') || process.platform === 'win32' && which('find');
39 -
40 -exports['exit'] = {
41 - setUp: function(done) {
42 - this.origCwd = process.cwd();
43 - process.chdir('test/fixtures');
44 - done();
45 - },
46 - tearDown: function(done) {
47 - process.chdir(this.origCwd);
48 - done();
49 - },
50 - 'grep': function(test) {
51 - test.expect(1);
52 - // Many unit tests depend on this.
53 - test.ok(grep, 'A suitable "grep" or "find" program was not found in the PATH.');
54 - test.done();
55 - },
56 - // The rest of the tests are built dynamically, to keep things sane.
57 -};
58 -
59 -// A few helper functions.
60 -function normalizeLineEndings(s) {
61 - return s.replace(/\r?\n/g, '\n');
62 -}
63 -
64 -// Capture command output, normalizing captured stdout to unix file endings.
65 -function run(command, callback) {
66 - exec(command, function(error, stdout) {
67 - callback(error ? error.code : 0, normalizeLineEndings(stdout));
68 - });
69 -}
70 -
71 -// Read a fixture file, normalizing file contents to unix file endings.
72 -function fixture(filename) {
73 - return normalizeLineEndings(String(fs.readFileSync(filename)));
74 -}
75 -
76 -function buildTests() {
77 - // Build individual unit tests for command output.
78 - var counts = [10, 100, 1000];
79 - var outputs = [' stdout stderr', ' stdout', ' stderr'];
80 - var pipes = ['', ' | ' + grep + ' "std"'];
81 - counts.forEach(function(count) {
82 - outputs.forEach(function(output) {
83 - pipes.forEach(function(pipe) {
84 - var command = 'node log.js 0 ' + count + output + ' 2>&1' + pipe;
85 - exports['exit']['output (' + command + ')'] = function(test) {
86 - test.expect(2);
87 - run(command, function(code, actual) {
88 - var expected = fixture(count + output.replace(/ /g, '-') + '.txt');
89 - // Sometimes, the actual file lines are out of order on Windows.
90 - // But since the point of this lib is to drain the buffer and not
91 - // guarantee output order, we only test the length.
92 - test.equal(actual.length, expected.length, 'should be the same length.');
93 - // The "fail" lines in log.js should NOT be output!
94 - test.ok(actual.indexOf('fail') === -1, 'should not output after exit is called.');
95 - test.done();
96 - });
97 - };
98 - });
99 - });
100 - });
101 -
102 - // Build individual unit tests for exit codes.
103 - var codes = [0, 1, 123];
104 - codes.forEach(function(code) {
105 - var command = 'node log.js ' + code + ' 10 stdout stderr';
106 - exports['exit']['exit code (' + command + ')'] = function(test) {
107 - test.expect(1);
108 - run(command, function(actual) {
109 - // The specified exit code should be passed through.
110 - test.equal(actual, code, 'should exit with ' + code + ' error code.');
111 - test.done();
112 - });
113 - };
114 - });
115 -}
116 -
117 -// Don't bother building tests if grep wasn't found, otherwise everything will
118 -// fail and the error will get lost.
119 -if (grep) {
120 - buildTests();
121 -}
1 -stderr 0
2 -stderr 1
3 -stderr 2
4 -stderr 3
5 -stderr 4
6 -stderr 5
7 -stderr 6
8 -stderr 7
9 -stderr 8
10 -stderr 9
1 -stdout 0
2 -stderr 0
3 -stdout 1
4 -stdout 2
5 -stderr 1
6 -stdout 3
7 -stderr 2
8 -stderr 3
9 -stdout 4
10 -stderr 4
11 -stdout 5
12 -stderr 5
13 -stdout 6
14 -stderr 6
15 -stdout 7
16 -stderr 7
17 -stdout 8
18 -stderr 8
19 -stdout 9
20 -stderr 9
1 -stdout 0
2 -stdout 1
3 -stdout 2
4 -stdout 3
5 -stdout 4
6 -stdout 5
7 -stdout 6
8 -stdout 7
9 -stdout 8
10 -stdout 9
1 -stderr 0
2 -stderr 1
3 -stderr 2
4 -stderr 3
5 -stderr 4
6 -stderr 5
7 -stderr 6
8 -stderr 7
9 -stderr 8
10 -stderr 9
11 -stderr 10
12 -stderr 11
13 -stderr 12
14 -stderr 13
15 -stderr 14
16 -stderr 15
17 -stderr 16
18 -stderr 17
19 -stderr 18
20 -stderr 19
21 -stderr 20
22 -stderr 21
23 -stderr 22
24 -stderr 23
25 -stderr 24
26 -stderr 25
27 -stderr 26
28 -stderr 27
29 -stderr 28
30 -stderr 29
31 -stderr 30
32 -stderr 31
33 -stderr 32
34 -stderr 33
35 -stderr 34
36 -stderr 35
37 -stderr 36
38 -stderr 37
39 -stderr 38
40 -stderr 39
41 -stderr 40
42 -stderr 41
43 -stderr 42
44 -stderr 43
45 -stderr 44
46 -stderr 45
47 -stderr 46
48 -stderr 47
49 -stderr 48
50 -stderr 49
51 -stderr 50
52 -stderr 51
53 -stderr 52
54 -stderr 53
55 -stderr 54
56 -stderr 55
57 -stderr 56
58 -stderr 57
59 -stderr 58
60 -stderr 59
61 -stderr 60
62 -stderr 61
63 -stderr 62
64 -stderr 63
65 -stderr 64
66 -stderr 65
67 -stderr 66
68 -stderr 67
69 -stderr 68
70 -stderr 69
71 -stderr 70
72 -stderr 71
73 -stderr 72
74 -stderr 73
75 -stderr 74
76 -stderr 75
77 -stderr 76
78 -stderr 77
79 -stderr 78
80 -stderr 79
81 -stderr 80
82 -stderr 81
83 -stderr 82
84 -stderr 83
85 -stderr 84
86 -stderr 85
87 -stderr 86
88 -stderr 87
89 -stderr 88
90 -stderr 89
91 -stderr 90
92 -stderr 91
93 -stderr 92
94 -stderr 93
95 -stderr 94
96 -stderr 95
97 -stderr 96
98 -stderr 97
99 -stderr 98
100 -stderr 99
1 -stdout 0
2 -stderr 0
3 -stdout 1
4 -stderr 1
5 -stdout 2
6 -stderr 2
7 -stdout 3
8 -stderr 3
9 -stdout 4
10 -stderr 4
11 -stdout 5
12 -stderr 5
13 -stdout 6
14 -stderr 6
15 -stdout 7
16 -stderr 7
17 -stdout 8
18 -stderr 8
19 -stdout 9
20 -stderr 9
21 -stdout 10
22 -stderr 10
23 -stdout 11
24 -stderr 11
25 -stdout 12
26 -stderr 12
27 -stdout 13
28 -stderr 13
29 -stdout 14
30 -stderr 14
31 -stdout 15
32 -stderr 15
33 -stdout 16
34 -stderr 16
35 -stdout 17
36 -stderr 17
37 -stdout 18
38 -stderr 18
39 -stdout 19
40 -stderr 19
41 -stdout 20
42 -stderr 20
43 -stdout 21
44 -stderr 21
45 -stdout 22
46 -stderr 22
47 -stdout 23
48 -stderr 23
49 -stdout 24
50 -stderr 24
51 -stdout 25
52 -stderr 25
53 -stdout 26
54 -stderr 26
55 -stdout 27
56 -stderr 27
57 -stdout 28
58 -stderr 28
59 -stdout 29
60 -stderr 29
61 -stdout 30
62 -stderr 30
63 -stdout 31
64 -stderr 31
65 -stdout 32
66 -stderr 32
67 -stdout 33
68 -stderr 33
69 -stdout 34
70 -stderr 34
71 -stdout 35
72 -stderr 35
73 -stdout 36
74 -stderr 36
75 -stdout 37
76 -stderr 37
77 -stdout 38
78 -stderr 38
79 -stdout 39
80 -stderr 39
81 -stdout 40
82 -stderr 40
83 -stdout 41
84 -stderr 41
85 -stdout 42
86 -stderr 42
87 -stdout 43
88 -stderr 43
89 -stdout 44
90 -stderr 44
91 -stdout 45
92 -stderr 45
93 -stdout 46
94 -stderr 46
95 -stdout 47
96 -stderr 47
97 -stdout 48
98 -stderr 48
99 -stdout 49
100 -stderr 49
101 -stdout 50
102 -stderr 50
103 -stdout 51
104 -stderr 51
105 -stdout 52
106 -stderr 52
107 -stdout 53
108 -stderr 53
109 -stdout 54
110 -stderr 54
111 -stdout 55
112 -stderr 55
113 -stdout 56
114 -stderr 56
115 -stdout 57
116 -stderr 57
117 -stdout 58
118 -stderr 58
119 -stdout 59
120 -stderr 59
121 -stdout 60
122 -stderr 60
123 -stdout 61
124 -stderr 61
125 -stdout 62
126 -stderr 62
127 -stdout 63
128 -stderr 63
129 -stdout 64
130 -stderr 64
131 -stdout 65
132 -stderr 65
133 -stdout 66
134 -stderr 66
135 -stdout 67
136 -stderr 67
137 -stdout 68
138 -stderr 68
139 -stdout 69
140 -stderr 69
141 -stdout 70
142 -stderr 70
143 -stdout 71
144 -stderr 71
145 -stdout 72
146 -stderr 72
147 -stdout 73
148 -stderr 73
149 -stdout 74
150 -stderr 74
151 -stdout 75
152 -stderr 75
153 -stdout 76
154 -stderr 76
155 -stdout 77
156 -stderr 77
157 -stdout 78
158 -stderr 78
159 -stdout 79
160 -stderr 79
161 -stdout 80
162 -stderr 80
163 -stdout 81
164 -stderr 81
165 -stdout 82
166 -stderr 82
167 -stdout 83
168 -stderr 83
169 -stdout 84
170 -stderr 84
171 -stdout 85
172 -stderr 85
173 -stdout 86
174 -stderr 86
175 -stdout 87
176 -stderr 87
177 -stdout 88
178 -stderr 88
179 -stdout 89
180 -stderr 89
181 -stdout 90
182 -stderr 90
183 -stdout 91
184 -stderr 91
185 -stdout 92
186 -stderr 92
187 -stdout 93
188 -stderr 93
189 -stdout 94
190 -stderr 94
191 -stdout 95
192 -stderr 95
193 -stdout 96
194 -stderr 96
195 -stdout 97
196 -stderr 97
197 -stdout 98
198 -stderr 98
199 -stdout 99
200 -stderr 99
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.