Skip to content

Commit 592f9b1

Browse files
kevinoidstefanpenner
authored andcommitted
Provide separate auto-polyfill version of this module
This commit provides a mechanism for users to load a version of this module which automatically installs the polyfill, separately from the default non-automatic version, as outlined in #126 (comment) It uses require('es6-promise/auto') instead of require('es6-promise/polyfil') so that it does not directly conflict with the es-shim-api API Contract[1], in case support is later added. In addition to the Node/Browserify file, a UMD file which triggers automatic polyfill installation is also provided. Fixes: #140 Alternative-to: #126 1. https://github.com/es-shims/es-shim-api#api-contract Signed-off-by: Kevin Locke <[email protected]>
1 parent 7508b85 commit 592f9b1

12 files changed

+1199
-13
lines changed

Brocfile.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,24 @@ var header = stew.map(find('config/versionTemplate.txt'), function(content) {
5959
return content.replace(/VERSION_PLACEHOLDER_STRING/, version());
6060
});
6161

62+
var dist = es6Promise;
63+
6264
function concatAs(tree, outputFile) {
63-
return concat(merge([tree, header]), {
64-
headerFiles: ['config/versionTemplate.txt'],
65-
inputFiles: ['es6-promise.js'],
66-
outputFile: outputFile
67-
});
65+
return merge([
66+
concat(merge([tree, header]), {
67+
headerFiles: ['config/versionTemplate.txt'],
68+
inputFiles: ['es6-promise.js'],
69+
outputFile: outputFile
70+
}),
71+
72+
concat(merge([tree, header]), {
73+
headerFiles: ['config/versionTemplate.txt'],
74+
inputFiles: ['es6-promise.js'],
75+
outputFile: outputFile.replace('es6-promise', 'es6-promise.auto'),
76+
footer: 'ES6Promise.polyfill();',
77+
}),
78+
79+
]);
6880
}
6981

7082
function production(dist, header) {

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ For API details and how to use promises, see the <a href="http://www.html5rocks.
66

77
## Downloads
88

9-
* [es6-promise 27.86 KB (7.33 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.js)
10-
* [es6-promise-min 6.17 KB (2.4 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.min.js)
9+
* [es6-promise 27.86 KB (7.33 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/lib/es6-promise.js)
10+
* [es6-promise-auto 27.78 KB (7.3 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.auto.js) - Automatically provides/replaces `Promise` if missing or broken.
11+
* [es6-promise-min 6.17 KB (2.4 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/lib/es6-promise.min.js)
12+
* [es6-promise-auto-min 6.19 KB (2.4 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.auto.min.js) - Minified version of `es6-promise-auto` above.
1113

1214
## Node.js
1315

@@ -23,6 +25,12 @@ To use:
2325
var Promise = require('es6-promise').Promise;
2426
```
2527

28+
29+
```js
30+
require('es6-promise/auto');
31+
Promise;
32+
```
33+
2634
## Bower
2735

2836
To install:
@@ -60,6 +68,12 @@ To polyfill the global environment (either in Node or in the browser via CommonJ
6068
require('es6-promise').polyfill();
6169
```
6270

71+
Alternatively
72+
73+
```js
74+
require('es6-promise/auto');
75+
```
76+
6377
Notice that we don't assign the result of `polyfill()` to any variable. The `polyfill()` method will patch the global environment (in this case to the `Promise` name) when called.
6478

6579
## Building & Testing

auto.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file can be required in Browserify and Node.js for automatic polyfill
2+
// To use it: require('es6-promise/auto');
3+
'use strict';
4+
module.exports = require('.').polyfill();

0 commit comments

Comments
 (0)