Skip to content

fix(build): Resume UMD bundle build, and restore docs #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/optimizely-sdk/CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 13 additions & 5 deletions packages/optimizely-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand All @@ -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
<script src="https://unpkg.com/@optimizely/optimizely-sdk/dist/optimizely.browser.umd.js"></script>
```

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
Expand Down
3 changes: 2 additions & 1 deletion packages/optimizely-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "./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",
"prepublishOnly": "npm test && npm run test-xbrowser"
"prepublishOnly": "npm test && npm run test-xbrowser && npm run build-browser-umd"
},
"repository": {
"type": "git",
Expand Down
28 changes: 28 additions & 0 deletions packages/optimizely-sdk/scripts/build_browser_umd.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF


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 alias will be dropped in 3.0.0.');
window._optimizelyClientWarningGiven = true;
}

return {
createInstance: window.optimizelySdk.createInstance
};
}
});
EOF