From 48ef8262bd57db8615a71fb5bdced3a5afaa2f9d Mon Sep 17 00:00:00 2001 From: Spencer Wilson Date: Mon, 20 Aug 2018 10:42:58 -0700 Subject: [PATCH 1/6] fix(build): Restore build-browser-umd task --- package.json | 5 +++-- packages/optimizely-sdk/package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3cbfb4773..847b1eb14 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "1.0.0", "name": "optimizely-sdk-packages", "scripts": { - "postinstall": "lerna bootstrap", + "postinstall": "lerna bootstrap && lerna run build", + "build": "lerna run build", "clean": "lerna run clean", - "publish": "lerna publish", + "publish": "npm run build && lerna publish", "test": "lerna run test --stream", "test-xbrowser": "lerna run test-xbrowser --stream" }, diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index b99793de9..50dcea799 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -7,10 +7,11 @@ "scripts": { "test": "mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js --recursive", "test-xbrowser": "karma start karma.bs.conf.js --single-run", + "build-browser-umd": "webpack -p lib/index.browser.js dist/optimizely.browser.umd.min.js --output-library-target=umd --output-library=optimizelyClient ", "lint": "eslint lib/**", "cover": "istanbul cover _mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js", "coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls", - "prepublishOnly": "npm test && npm run test-xbrowser" + "prepublishOnly": "npm test && npm run test-xbrowser && npm run build-browser-umd" }, "repository": { "type": "git", From 1ef07387520488046d79a825e5595d05f14c3641 Mon Sep 17 00:00:00 2001 From: Spencer Wilson Date: Mon, 20 Aug 2018 11:11:19 -0700 Subject: [PATCH 2/6] Add back docs to readme --- packages/optimizely-sdk/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/optimizely-sdk/README.md b/packages/optimizely-sdk/README.md index eacb3b89c..7cb032350 100644 --- a/packages/optimizely-sdk/README.md +++ b/packages/optimizely-sdk/README.md @@ -32,6 +32,14 @@ npm install --save @optimizely/optimizely-sdk ### Usage See the Optimizely X Full Stack [developer documentation](http://developers.optimizely.com/server/reference/index.html) to learn how to set up your first JavaScript project and use the SDK. +The package's entry point is a CommonJS module, which can be used directly in environments which support it (e.g., Node.js, or loaded in a browser via Browserify or RequireJS). Additionally, you can include a standalone bundle of the SDK in your web page by fetching it from [unpkg](https://unpkg.com/): + +```html + +``` + +When evaluated, that bundle assigns the SDK's exports to `window.optimizelySdk`. If you wish to use the asset locally (for example, if unpkg is down), you can find it in your local copy of the package at dist/optimizely.browser.umd.min.js, or [here in GitHub](./dist/optimizely.browser.umd.min.js). + Regarding `EventDispatcher`s: In Node.js and browser environments, the default `EventDispatcher` is powered by the [`http/s`](https://nodejs.org/api/http.html) modules and by [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Browser_compatibility), respectively. In all other environments, you must supply your own `EventDispatcher`. ### Migrating from 1.x.x From 61f912a039a9955eaa4d11d7b8b14f1286aee6c1 Mon Sep 17 00:00:00 2001 From: Spencer Wilson Date: Mon, 20 Aug 2018 11:11:43 -0700 Subject: [PATCH 3/6] Make bullet points shallow (appease Typora) --- packages/optimizely-sdk/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/optimizely-sdk/README.md b/packages/optimizely-sdk/README.md index 7cb032350..a1b3a56fa 100644 --- a/packages/optimizely-sdk/README.md +++ b/packages/optimizely-sdk/README.md @@ -15,13 +15,13 @@ This directory contains the source code for the JavaScript SDK, which is usable ### Prerequisites Ensure the SDK supports all of the platforms you're targeting. In particular, the SDK targets any ES5-compliant JavaScript environment. We officially support: - - Node.js >= 4.0.0. By extension, environments like AWS Lambda, Google Cloud Functions, and Auth0 Webtasks are supported as well. Older Node.js releases likely work too (try `npm test` to validate for yourself), but are not formally supported. - - [Web browsers](https://caniuse.com/#feat=es5) +- Node.js >= 4.0.0. By extension, environments like AWS Lambda, Google Cloud Functions, and Auth0 Webtasks are supported as well. Older Node.js releases likely work too (try `npm test` to validate for yourself), but are not formally supported. +- [Web browsers](https://caniuse.com/#feat=es5) Other environments likely are compatible, too, but note that we don't officially support them: - - Progressive Web Apps, WebViews, and hybrid mobile apps like those built with React Native and Apache Cordova. - - [Cloudflare Workers](https://developers.cloudflare.com/workers/) and [Fly](https://fly.io/), both of which are powered by recent releases of V8. - - Anywhere else you can think of that might embed a JavaScript engine. The sky is the limit; experiment everywhere! 🚀 +- Progressive Web Apps, WebViews, and hybrid mobile apps like those built with React Native and Apache Cordova. +- [Cloudflare Workers](https://developers.cloudflare.com/workers/) and [Fly](https://fly.io/), both of which are powered by recent releases of V8. +- Anywhere else you can think of that might embed a JavaScript engine. The sky is the limit; experiment everywhere! 🚀 Once you've validated that the SDK supports the platforms you're targeting, fetch the package from [NPM](https://www.npmjs.com/package/@optimizely/optimizely-sdk). Using `npm`: From 5e7c423e56a0445456d10701aeab14f46dc79186 Mon Sep 17 00:00:00 2001 From: Spencer Wilson Date: Mon, 20 Aug 2018 11:12:02 -0700 Subject: [PATCH 4/6] Rename --output-library optimizelyClient -> optimizelySdk --- packages/optimizely-sdk/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index 50dcea799..532e2794d 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -7,7 +7,7 @@ "scripts": { "test": "mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js --recursive", "test-xbrowser": "karma start karma.bs.conf.js --single-run", - "build-browser-umd": "webpack -p lib/index.browser.js dist/optimizely.browser.umd.min.js --output-library-target=umd --output-library=optimizelyClient ", + "build-browser-umd": "webpack -p lib/index.browser.js dist/optimizely.browser.umd.min.js --output-library-target=umd --output-library=optimizelySdk", "lint": "eslint lib/**", "cover": "istanbul cover _mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js", "coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls", From d440082ed2386e7cd0f8b0a0a29583bec620e370 Mon Sep 17 00:00:00 2001 From: Spencer Wilson Date: Mon, 20 Aug 2018 14:56:13 -0700 Subject: [PATCH 5/6] Properly alias/deprecate the change --- packages/optimizely-sdk/CHANGELOG.MD | 11 ++++++++ packages/optimizely-sdk/package.json | 2 +- .../scripts/build_browser_umd.sh | 28 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 packages/optimizely-sdk/scripts/build_browser_umd.sh diff --git a/packages/optimizely-sdk/CHANGELOG.MD b/packages/optimizely-sdk/CHANGELOG.MD index 19149da7b..944f40281 100644 --- a/packages/optimizely-sdk/CHANGELOG.MD +++ b/packages/optimizely-sdk/CHANGELOG.MD @@ -1,3 +1,14 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Deprecated +* The UMD build of the SDK now assigns the SDK namespace object to `window.optimizelySdk` rather than to `window.optimizelyClient`. The old name still works, but on its first access a deprecation warning is logged to the console. The alias will be removed in the 3.0.0 release. + ## 2.1.1 June 19, 2018 diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index 532e2794d..1558a7ed7 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -7,7 +7,7 @@ "scripts": { "test": "mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js --recursive", "test-xbrowser": "karma start karma.bs.conf.js --single-run", - "build-browser-umd": "webpack -p lib/index.browser.js dist/optimizely.browser.umd.min.js --output-library-target=umd --output-library=optimizelySdk", + "build-browser-umd": "./scripts/build_browser_umd.sh", "lint": "eslint lib/**", "cover": "istanbul cover _mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js", "coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls", diff --git a/packages/optimizely-sdk/scripts/build_browser_umd.sh b/packages/optimizely-sdk/scripts/build_browser_umd.sh new file mode 100755 index 000000000..eff13d263 --- /dev/null +++ b/packages/optimizely-sdk/scripts/build_browser_umd.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash -e + +BUNDLE_NAME="optimizelySdk" + +npx webpack -p lib/index.browser.js dist/optimizely.browser.umd.min.js \ + --output-library-target=umd \ + --output-library="$BUNDLE_NAME" + +# Append some backwards-compatibility code to the bundle +cat - >> dist/optimizely.browser.umd.min.js < Date: Mon, 20 Aug 2018 14:59:26 -0700 Subject: [PATCH 6/6] s/functionality/alias/ --- packages/optimizely-sdk/scripts/build_browser_umd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizely-sdk/scripts/build_browser_umd.sh b/packages/optimizely-sdk/scripts/build_browser_umd.sh index eff13d263..79daafc6c 100755 --- a/packages/optimizely-sdk/scripts/build_browser_umd.sh +++ b/packages/optimizely-sdk/scripts/build_browser_umd.sh @@ -15,7 +15,7 @@ window._optimizelyClientWarningGiven = false; Object.defineProperty(window, 'optimizelyClient', { get: function () { if (!window._optimizelyClientWarningGiven) { - console.warn('Accessing the SDK via window.optimizelyClient is deprecated; please use window.optimizelySdk instead. This functionality will be dropped in 3.0.0.'); + console.warn('Accessing the SDK via window.optimizelyClient is deprecated; please use window.optimizelySdk instead. This alias will be dropped in 3.0.0.'); window._optimizelyClientWarningGiven = true; }