From 5b1325731e5ac21834321213baa0d4e879b24cfd Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Wed, 11 Apr 2018 15:07:20 -0400 Subject: [PATCH 1/6] Modernize development environment (#37) * Use Babel for transpilation * Use Rollup for bundling * Use ESlint for linting * Use prettier for formatting --- .babelrc | 45 + .eslintignore | 3 + .eslintrc | 22 - .eslintrc.yaml | 55 + .gitignore | 4 +- .prettierignore | 1 + .prettierrc | 5 + CHANGELOG.md | 144 +- CONTRIBUTING.md | 3 +- README.md | 337 +- index.html | 4 +- jest.config.js | 16 + karma.conf.js | 31 - package-lock.json | 11244 ++++++++++++++++++------ package.json | 83 +- rollup.config.js | 56 + scripts/build.js | 22 - src/EventEmitter.js | 31 +- src/EventProcessor.js | 55 +- src/EventSerializer.js | 109 +- src/GoalTracker.js | 102 +- src/Identity.js | 20 +- src/Requestor.js | 50 +- src/Stream.js | 28 +- src/__mocks__/Requestor.js | 4 + src/__tests__/.eslintrc.yaml | 7 + src/__tests__/EventProcessor-test.js | 75 +- src/__tests__/EventSerializer-test.js | 156 +- src/__tests__/LDClient-test.js | 682 +- src/__tests__/Requestor-test.js | 83 +- src/__tests__/Stream-test.js | 96 +- src/__tests__/mockEventSource.js | 22 - src/__tests__/store-test.js | 32 + src/__tests__/utils-test.js | 74 +- src/errors.js | 12 +- src/index.js | 352 +- src/jest.setup.js | 1 + src/messages.js | 67 +- src/store.js | 10 +- src/utils.js | 114 +- tests.webpack.js | 2 - webpack.config.js | 14 - 42 files changed, 10034 insertions(+), 4239 deletions(-) create mode 100644 .babelrc create mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 .eslintrc.yaml create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 jest.config.js delete mode 100644 karma.conf.js create mode 100644 rollup.config.js delete mode 100644 scripts/build.js create mode 100644 src/__mocks__/Requestor.js create mode 100644 src/__tests__/.eslintrc.yaml delete mode 100644 src/__tests__/mockEventSource.js create mode 100644 src/__tests__/store-test.js create mode 100644 src/jest.setup.js delete mode 100644 tests.webpack.js delete mode 100644 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..2a92546b --- /dev/null +++ b/.babelrc @@ -0,0 +1,45 @@ +{ + "env": { + "test": { + "presets": [ + [ + "env", + { + "targets": { + "browsers": ["last 2 versions"] + } + } + ], + "stage-1" + ] + }, + "development": { + "presets": [ + [ + "env", + { + "targets": { + "browsers": ["last 2 versions", "ie >= 11"] + }, + "modules": false + } + ], + "stage-1" + ] + }, + "production": { + "presets": [ + [ + "env", + { + "targets": { + "browsers": ["last 2 versions", "ie >= 10"] + }, + "modules": false + } + ], + "stage-1" + ] + } + } +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..06c3eac6 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ +coverage/ +dist/ diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 11dd50d8..00000000 --- a/.eslintrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - "env": { - "browser": true, - "node": true, - "es6": true, - "mocha": true - }, - "globals": { - - }, - "rules": { - "quotes": [2, "single"], - "indent": [2, 2], - "eol-last": 1, - "camelcase": 2, - "no-unused-vars": 1, - "no-underscore-dangle": 0, - "no-array-constructor": 2, - "no-cond-assign": 2, - "eqeqeq": 2 - } -} diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 00000000..2d50f0b6 --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,55 @@ +--- +parser: babel-eslint +extends: + - prettier +env: + es6: true + node: true + browser: true +plugins: + - babel + - prettier +globals: + VERSION: true +rules: + prettier/prettier: + - error + array-callback-return: error + curly: + - error + - all + no-implicit-coercion: + - 'off' + - boolean: false + number: true + string: true + allow: [] + no-eval: error + no-implied-eval: error + no-param-reassign: + - error + - props: true + no-return-assign: error + no-self-compare: error + radix: error + no-array-constructor: error + no-new-wrappers: error + no-cond-assign: error + no-use-before-define: + - error + - functions: false + eqeqeq: error + + # Deprecations are required to turn enforce this + camelcase: warn + + no-new-object: error + no-nested-ternary: error + no-unused-vars: error + no-var: error + prefer-const: error + prefer-arrow-callback: error + arrow-body-style: + - error + - as-needed + babel/semi: error \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5711ef2f..7f5f3fa9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .DS_Store **/junit.xml npm-debug.log +yarn-error.log node_modules dist -.idea \ No newline at end of file +.idea +.vscode/ \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..ec6d3cdd --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +package.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..e2f78207 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "es5", + "singleQuote": true, + "printWidth": 120 +} diff --git a/CHANGELOG.md b/CHANGELOG.md index b82ecc0a..ef952691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,133 +1,193 @@ # Change log -All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. This -project adheres to [Semantic Versioning](http://semver.org). +All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). ## [1.6.2] - 2018-04-05 + ### Fixed -- `LDClient.track` properly sets the user for custom events. +* `LDClient.track` properly sets the user for custom events. ## [1.6.1] - 2018-03-30 + ### Fixed -- The SDK now polls the URL for changes if (and only if) there are page view goals,to ensure it is accurately reporting page views. + +* The SDK now polls the URL for changes if (and only if) there are page view goals,to ensure it is accurately reporting page views. ## [1.6.0] - 2018-03-28 + ### Changed -- Added support for a future update to LaunchDarkly that will deliver individual feature flag changes over the streaming connection as they occur, rather than requiring the client to re-request all flags for each change. + +* Added support for a future update to LaunchDarkly that will deliver individual feature flag changes over the streaming connection as they occur, rather than requiring the client to re-request all flags for each change. ## [1.5.2] - 2018-03-28 + ### Added -- The new flush method on the client object tells the client to deliver any stored analytics events as soon as possible, rather than waiting for the regularly scheduled event-flushing interval. -### Fixed -- Fixed a bug that could prevent events from being generated for page view goals. + +* The new flush method on the client object tells the client to deliver any stored analytics events as soon as possible, rather than waiting for the regularly scheduled event-flushing interval. + ### Fixed +* Fixed a bug that could prevent events from being generated for page view goals. ## [1.5.1] - 2018-03-07 + ### Fixed -- Removed usage of the `const` keyword, to maintain IE10 compatibility. (Thanks, [turnerniles](https://github.com/launchdarkly/js-client/pull/68)!) + +* Removed usage of the `const` keyword, to maintain IE10 compatibility. (Thanks, [turnerniles](https://github.com/launchdarkly/js-client/pull/68)!) ## [1.5.0] - 2018-03-05 + ### Added -- The `options` object now supports a `samplingInterval` property. If greater than zero, this causes a fraction of analytics events to be sent to LaunchDarkly: one per that number of events (pseudo-randomly). For instance, setting it to 5 would cause 20% of events to be sent on average. + +* The `options` object now supports a `samplingInterval` property. If greater than zero, this causes a fraction of analytics events to be sent to LaunchDarkly: one per that number of events (pseudo-randomly). For instance, setting it to 5 would cause 20% of events to be sent on average. ## [1.4.0] - 2018-02-07 + ### Added -- The SDK now supports multiple environments. Calling `initialize` returns a new client each time. -### Fixed -- The `waitUntilReady` `Promise` will now resolve even after the `ready` event was emitted — thanks @rmanalan! + +* The SDK now supports multiple environments. Calling `initialize` returns a new client each time. + ### Fixed +* The `waitUntilReady` `Promise` will now resolve even after the `ready` event was emitted — thanks @rmanalan! ## [1.3.1] - 2018-01-23 + ### Fixed -- Methods that expose a `Promise` interface now properly return the resolution or rejection value to the caller. + +* Methods that expose a `Promise` interface now properly return the resolution or rejection value to the caller. ## [1.3.0] - 2018-01-22 + ### Added -- Support for [private user attributes](https://docs.launchdarkly.com/docs/private-user-attributes). -- New `sendEvents` option to control whether the SDK should send events back to LaunchDarkly or not. Defaults to `true`. -- It is now possible to wait for SDK readiness using `waitUntilReady` which returns a `Promise`. `identify` also returns a `Promise` (while still supporting the callback argument), which should make -it easier to integrate into code that relies heavily on `Promise`'s for asynchronous code. -### Changed -- The SDK now respects the user's [do-not-track setting](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack) + +* Support for [private user attributes](https://docs.launchdarkly.com/docs/private-user-attributes). +* New `sendEvents` option to control whether the SDK should send events back to LaunchDarkly or not. Defaults to `true`. +* It is now possible to wait for SDK readiness using `waitUntilReady` which returns a `Promise`. `identify` also returns a `Promise` (while still supporting the callback argument), which should make + it easier to integrate into code that relies heavily on `Promise`'s for asynchronous code. + ### Changed +* The SDK now respects the user's [do-not-track setting](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack) ## [1.2.0] - 2017-12-15 + ### Added -- Added `useReport` initialization option to use `REPORT` instead of `GET` when communicating with LaunchDarkly. -### Fixed -- Authentication errors will now be logged — the root cause for these errors is usually an invalid + +* Added `useReport` initialization option to use `REPORT` instead of `GET` when communicating with LaunchDarkly. + ### Fixed +* Authentication errors will now be logged — the root cause for these errors is usually an invalid client-side ID. ## [1.1.13] - 2017-12-12 + ### Changed -- Emit an `error` event — separately from the `ready` event — in case fetching initial data fails. This allows consumers to respond accordingly. + +* Emit an `error` event — separately from the `ready` event — in case fetching initial data fails. This allows consumers to respond accordingly. ## [1.1.12] - 2017-06-09 + ### Changed -- Improve error handling + +* Improve error handling ## [1.1.11] - 2017-05-16 + ### Added -- Add typescript definitions + +* Add typescript definitions ## [1.1.10] - 2017-05-04 + ### Added -- Add a warning when tracking unknown custom goal events + +* Add a warning when tracking unknown custom goal events ## [1.1.9] - 2017-04-07 + ### Fixed -- Changed default stream url + +* Changed default stream url ## [1.1.8] - 2017-02-02 + ### Fixed -- Cached `localStorage` copy is not overwritten anymore when connection to LD fails + +* Cached `localStorage` copy is not overwritten anymore when connection to LD + fails ## [1.1.7] - 2017-01-27 + ### Changed -- `onDone` argument to `identify` method is now optional + +* `onDone` argument to `identify` method is now optional ## [1.1.6] - 2017-01-16 + ### Changed -- Removed dependency on Sizzle and direct to polyfill for older browser support + +* Removed dependency on Sizzle and direct to polyfill for older browser support ## [1.1.5] - 2016-12-07 + ### Changed -- Fix bug in `Emitter.off()` + +* Fix bug in `Emitter.off()` ## [1.1.4] - 2016-10-26 + ### Changed -- Fix bug caused by accessing `undefined` flags + +* Fix bug caused by accessing `undefined` flags ## [1.1.3] - 2016-10-14 + ### Changed -- Fix bug caused by accessing `undefined` settings + +* Fix bug caused by accessing `undefined` settings ## [1.1.2] - 2016-09-21 + ### Changed -- Ensure callbacks only ever get called once + +* Ensure callbacks only ever get called once ## [1.1.1] - 2016-09-20 + ### Changed -- Fix flag setting request cancellation logic + +* Fix flag setting request cancellation logic ## [1.1.0] - 2016-09-14 + ### Added -- Add a new `allFlags` method that returns a map of all feature flag keys and their values for a user + +* Add a new `allFlags` method that returns a map of all feature flag keys and + their values for a user ## [1.0.8] - 2016-09-09 + ### Changed -- Added 'undefined' check on VERSION otherwise unbundled usage from npm fails + +* Added 'undefined' check on VERSION otherwise unbundled usage from npm fails ## [1.0.7] - 2016-09-06 + ### Changed -- Expose SDK version at `LDClient.version` + +* Expose SDK version at `LDClient.version` ## [1.0.6] - 2016-08-23 + ### Changed -- Added check for EventSource before trying to connect Stream. + +* Added check for EventSource before trying to connect Stream. ## [1.0.5] - 2016-08-22 + ### Changed -- Fixed an error that occurred on `hashchage`/`popstate` if the account had no goals. + +* Fixed an error that occurred on `hashchage`/`popstate` if the account had no + goals. ## [1.0.4] - 2016-08-12 + ### Changed -- Added window check for server side rendering compatibility before loading Sizzle. + +* Added window check for server side rendering compatibility before loading + Sizzle. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 898208eb..2d5ea986 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,3 @@ -Contributing to LaunchDarkly SDK for JavaScript -=============================================== +# Contributing to LaunchDarkly SDK for JavaScript We encourage pull-requests and other contributions from the community. We've also published an [SDK contributor's guide](http://docs.launchdarkly.com/docs/sdk-contributors-guide) that provides a detailed explanation of how our SDKs work. diff --git a/README.md b/README.md index 380338f4..94fd592c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,15 @@ # LaunchDarkly SDK for Client-Side JavaScript [![Circle CI](https://circleci.com/gh/launchdarkly/js-client/tree/master.svg?style=svg)](https://circleci.com/gh/launchdarkly/js-client/tree/master) + ## Introduction -This is the official LaunchDarkly client-side JavaScript SDK. This SDK does two things: +This is the official LaunchDarkly client-side JavaScript SDK. This SDK does two +things: * Makes feature flags available to your client-side (front-end) JavaScript code. -* Sends click, pageview, and custom events from your front-end for A/B tests and analytics. +* Sends click, pageview, and custom events from your front-end for A/B tests and + analytics. ## Browser Support @@ -14,27 +17,34 @@ The LaunchDarkly client-side JavaScript SDK supports the following browsers: * Chrome (any recent) * Firefox (any recent) -* Safari (any recent)* -* Internet Explorer (IE10+)* -* Edge (any recent)* -* Opera (any recent)* +* Safari (any recent)\* +* Internet Explorer (IE10+)\* +* Edge (any recent)\* +* Opera (any recent)\* -\* These browsers do not support streaming new flags to connected clients, even when `client.on('change')` is called. +\* These browsers do not support streaming new flags to connected clients, even +when `client.on('change')` is called. ### EventSource polyfill -If you need streaming support, and you wish to support browsers that do not support `EventSource` natively, you can install a polyfill, such -as [EventSource](https://github.com/Yaffle/EventSource). +If you need streaming support, and you wish to support browsers that do not +support `EventSource` natively, you can install a polyfill, such as +[EventSource](https://github.com/Yaffle/EventSource). -You can load the polyfill via a script tag in the `` before the script where you initialize `LDClient`: +You can load the polyfill via a script tag in the `` before the script +where you initialize `LDClient`: -If you use [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/), make sure to require the polyfill before `LDClient` is initialized. +If you use [webpack](https://webpack.github.io/) or +[browserify](http://browserify.org/), make sure to require the polyfill before +`LDClient` is initialized. ### Document.querySelectorAll() polyfill -If you need to run A/B tests on IE7 or IE8 you will need to install a polyfill for `document.querySelector()` such as [polyfill-queryselector](https://github.com/cobbdb/polyfill-queryselector). +If you need to run A/B tests on IE7 or IE8 you will need to install a polyfill +for `document.querySelector()` such as +[polyfill-queryselector](https://github.com/cobbdb/polyfill-queryselector). You can load the polyfll via a script tag in the ``: @@ -46,147 +56,227 @@ You can also install it with `npm install polyfill-queryselector` or `bower inst There are two ways to install the client-side SDK: -1. Via the `npm` package: - - npm install --save ldclient-js +1. Via the `npm` package: `npm install --save ldclient-js` -2. A minimized version of the script is also hosted on our CDN, and can be included via a `script` tag: +2. A minimized version of the script is also hosted on our CDN, and can be + included via a `script` tag: - + From a9f525737ec210bc18c4df430d3103d0b8560e0d Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Fri, 27 Apr 2018 14:52:33 -0400 Subject: [PATCH 6/6] Prepare 1.7.0 --- CHANGELOG.md | 12 +++++++++++- package.json | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef952691..1ff6d511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Change log -All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org). + +## [1.7.0] - 2018-04-27 +### Changed +- The build now uses Rollup, Babel and Jest. +### Fixed +- Fixed a bug that caused a syntax error when running in Internet Explorer 11. +- Fixed an IE 11 incompatibility in the example page index.html. +- Fixed a bug that caused the SDK to send events on beforeunload even if it should not send events. + ## [1.6.2] - 2018-04-05 diff --git a/package.json b/package.json index 6999941e..a5f54842 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ldclient-js", - "version": "1.6.2", + "version": "1.7.0", "description": "LaunchDarkly SDK for JavaScript", "author": "LaunchDarkly ", "license": "Apache-2.0",