From 39e1e145e40cd7bbbf89daf4f967b1181d4873f1 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 2 Oct 2014 10:55:27 +0200 Subject: [PATCH] Add es6-promise polyfill to build step so users don't have to. --- Gruntfile.js | 11 ++--------- README.md | 2 +- package.json | 2 +- src/openpgp.js | 5 +++++ src/worker/worker.js | 4 ---- test/unittests.html | 3 --- test/unittests.js | 5 ----- 7 files changed, 9 insertions(+), 23 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ef66d7e8..a6d76600 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -38,7 +38,7 @@ module.exports = function(grunt) { 'test/lib/unittests-bundle.js': [ './test/unittests.js' ] }, options: { - external: [ 'openpgp', 'crypto', 'node-localstorage', 'es6-promise'] + external: [ 'openpgp', 'crypto', 'node-localstorage'] } } }, @@ -116,15 +116,8 @@ module.exports = function(grunt) { expand: true, flatten: true, cwd: 'node_modules/', - src: ['mocha/mocha.css', 'mocha/mocha.js', 'chai/chai.js', 'es6-promise/dist/promise*.js'], + src: ['mocha/mocha.css', 'mocha/mocha.js', 'chai/chai.js'], dest: 'test/lib/' - }, - polyfill: { - expand: true, - flatten: true, - cwd: 'node_modules/', - src: ['es6-promise/dist/promise*.js'], - dest: 'dist/' } }, clean: ['dist/'], diff --git a/README.md b/README.md index 23b2849f..cf9df765 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The library can be loaded via AMD/require.js or accessed globally via `window.o OpenPGP.js only supports browsers that implement `window.crypto.getRandomValues`. Also, if the browsers support [native WebCrypto](http://www.w3.org/TR/WebCryptoAPI/) via the `window.crypto.subtle` api, this will be used. Though this can be deactivated by setting `config.useWebCrypto = false`. In this case the library will fall back to Web Worker operations if the `initWorker(workerPath)` is set. -OpenPGP.js uses ES6 promises which are available in [most modern browsers](http://caniuse.com/#feat=promises). If you need to support browsers that do not support Promises, fear not! There is a [polyfill](https://github.com/jakearchibald/es6-promise). +OpenPGP.js uses ES6 promises which are available in [most modern browsers](http://caniuse.com/#feat=promises). If you need to support browsers that do not support Promises, fear not! There is a [polyfill](https://github.com/jakearchibald/es6-promise), which is included in the build step. So no action required on the developer's part for promises! ### Examples diff --git a/package.json b/package.json index 95f59b26..feaf8b2e 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "devDependencies": { "browserify": "~2.35", "chai": "~1.8.1", - "es6-promise": "1.0.0", "grunt": "~0.4.2", "grunt-browserify": "~1.2.11", "grunt-cli": "~0.1.13", @@ -47,6 +46,7 @@ "phantomjs": "~1.9.2-5" }, "dependencies": { + "es6-promise": "^1.0.0", "node-localstorage": "~0.3.4" }, "repository": { diff --git a/src/openpgp.js b/src/openpgp.js index 5f18c46d..f37f3ad8 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -41,6 +41,11 @@ var armor = require('./encoding/armor.js'), util = require('./util'), AsyncProxy = require('./worker/async_proxy.js'); +if (typeof Promise === 'undefined') { + // load ES6 Promises polyfill + require('es6-promise').polyfill(); +} + var asyncProxy; // instance of the asyncproxy /** diff --git a/src/worker/worker.js b/src/worker/worker.js index 7f122b00..5959ec23 100644 --- a/src/worker/worker.js +++ b/src/worker/worker.js @@ -39,10 +39,6 @@ if (!Function.prototype.bind) { }; } -if (typeof Promise === 'undefined') { - // promises polyfill - importScripts('promise-1.0.0.js'); -} importScripts('openpgp.js'); var MIN_SIZE_RANDOM_BUFFER = 40000; diff --git a/test/unittests.html b/test/unittests.html index 4b5e3efd..3a0a787b 100644 --- a/test/unittests.html +++ b/test/unittests.html @@ -9,9 +9,6 @@
- - - diff --git a/test/unittests.js b/test/unittests.js index c2f48ac8..5705bf17 100644 --- a/test/unittests.js +++ b/test/unittests.js @@ -1,8 +1,3 @@ -if (typeof window === 'undefined') { - // load ES6 Promises polyfill under node.js - require('es6-promise').polyfill(); -} - describe('Unit Tests', function () { require('./general'); require('./crypto');