Add es6-promise polyfill to build step so users don't have to.

This commit is contained in:
Tankred Hase 2014-10-02 10:55:27 +02:00
parent 4cd664a919
commit 39e1e145e4
7 changed files with 9 additions and 23 deletions

View File

@ -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/'],

View File

@ -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

View File

@ -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": {

View File

@ -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
/**

View File

@ -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;

View File

@ -9,9 +9,6 @@
<body>
<div id="mocha"></div>
<!-- polyfills -->
<script src="lib/promise-1.0.0.js"></script>
<!-- libs -->
<script src="../dist/openpgp.js"></script>
<script src="lib/chai.js"></script>

View File

@ -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');