Skip to content

Commit d3008c1

Browse files
authored
use named export + misc cleanup
1 parent 153be24 commit d3008c1

File tree

7 files changed

+22
-142
lines changed

7 files changed

+22
-142
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
All notable changes to this package will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org).
55

6-
## [1.0.8] - 2019-01-29
7-
First release from this fork. Changes from the 1.0.7 release of the upstream code are as follows:
6+
## [1.0.0] - 2019-01-29
7+
First release from this fork. Changes from the previous release of the upstream code (1.0.7) are as follows:
88

99
### Added:
1010
- The optional `method` and `body` properties of the constructor options allow you to specify a different HTTP method from the default of `GET`, and to provide a request body if the specified method allows a body.
11+
12+
### Changed:
13+
- The EventSource constructor is now a named export, not a default export. This is necessary in order to avoid a problem that can happen when using Babel with ES6 code: the logic for converting CJS imports to ES6 imports does not work correctly if the default import has properties (`CONNECTING`, `OPEN`, `CLOSED`) but is also a function. Note that this is a breaking change if you were previously using the upstream code, but the only thing that needs to be changed is the import statement.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If you add or fix something, add tests.
44

55
## Release process
66

7-
Update `HISTORY.md`, Then:
7+
Update `CHANGELOG.md`, Then:
88

99
npm outdated --depth 0 # See if you can upgrade something
1010
npm run polyfill

HISTORY.md

Lines changed: 0 additions & 134 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# EventSource [![npm version](http://img.shields.io/npm/v/launchdarkly-eventsource.svg?style=flat-square)](http://browsenpm.org/package/launchdarkly-eventsource)[![Build Status](http://img.shields.io/travis/launchdarkly/js-eventsource/master.svg?style=flat-square)](https://travis-ci.org/launchdarkly/js-eventsource)[![NPM Downloads](https://img.shields.io/npm/dm/laumchdarkly-eventsource.svg?style=flat-square)](http://npm-stat.com/charts.html?package=launchdarkly-eventsource&from=2015-09-01)[![Dependencies](https://img.shields.io/david/launchdarkly/js-eventsource.svg?style=flat-square)](https://david-dm.org/launchdarkly/js-eventsource)
1+
# EventSource [![npm version](http://img.shields.io/npm/v/launchdarkly-eventsource.svg?style=flat-square)](http://browsenpm.org/package/launchdarkly-eventsource)[![Circle CI](https://circleci.com/gh/launchdarkly/js-eventsource/tree/master.svg?style=svg)](https://circleci.com/gh/launchdarkly/js-eventsource/tree/master)[![NPM Downloads](https://img.shields.io/npm/dm/laumchdarkly-eventsource.svg?style=flat-square)](http://npm-stat.com/charts.html?package=launchdarkly-eventsource&from=2015-09-01)[![Dependencies](https://img.shields.io/david/launchdarkly/js-eventsource.svg?style=flat-square)](https://david-dm.org/launchdarkly/js-eventsource)
22

33
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.
44

55
You can use it with Node.js or as a browser polyfill for
66
[browsers that don't have native `EventSource` support](http://caniuse.com/#feat=eventsource).
77

8-
This is a fork of the original [EventSource](https://github.com/EventSource/eventsource) project by Aslak Hellesøy, with minimal additions to support the requirements of the LaunchDarkly Node and Electron SDKs.
8+
This is a fork of the original [EventSource](https://github.com/EventSource/eventsource) project by Aslak Hellesøy, with additions to support the requirements of the LaunchDarkly Node and Electron SDKs. Note that as described in the [changelog](CHANGELOG.md), the API is _not_ backward-compatible with the original package, although it can be used with minimal changes.
99

1010
## Install
1111

@@ -51,6 +51,15 @@ var eventSourceInitDict = {headers: {'Cookie': 'test=test'}};
5151
var es = new EventSource(url, eventSourceInitDict);
5252
```
5353

54+
### Setting HTTP request method/body
55+
56+
By default, EventSource makes a `GET` request. You can specify a different HTTP verb and/or a request body:
57+
58+
```javascript
59+
var eventSourceInitDict = {method: 'POST', body: 'n=100'};
60+
var es = new EventSource(url, eventSourceInitDict);
61+
```
62+
5463
### Allow unauthorized HTTPS requests
5564

5665
By default, https requests that cannot be authorized will cause the connection to fail and an exception

lib/eventsource.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ function EventSource (url, eventSourceInitDict) {
303303
}
304304
}
305305

306-
module.exports = EventSource
306+
module.exports = {
307+
EventSource: EventSource
308+
}
307309

308310
util.inherits(EventSource, events.EventEmitter)
309311
EventSource.prototype.constructor = EventSource; // make stacktraces readable

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "launchdarkly-eventsource",
3-
"version": "1.0.8",
3+
"version": "1.0.0-rc.1",
44
"description": "Fork of eventsource package - W3C compliant EventSource client for Node.js and browser (polyfill)",
55
"keywords": [
66
"eventsource",

test/eventsource_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-new */
2-
var EventSource = require('../lib/eventsource')
2+
var EventSource = require('../lib/eventsource').EventSource
33
var bufferFrom = require('buffer-from')
44
var path = require('path')
55
var http = require('http')

0 commit comments

Comments
 (0)