forked from adopted-ember-addons/ember-launch-darkly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (51 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
/* eslint-disable node/no-unpublished-require */
const path = require('path');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const browserslist = require('browserslist');
const EVENT_SOURCE_NON_SUPPORTED_BROWSERS = [
'Chrome < 6',
'Edge > 0',
'Firefox < 6.0',
'ie > 0',
'Safari < 5'
];
module.exports = {
name: require('./package').name,
isDevelopingAddon() {
return true;
},
included() {
this._super.included.apply(this, arguments);
if (this._shouldIncludePolyfill()) {
this.import('vendor/eventsource.js');
}
},
treeForVendor(vendorTree) {
let trees = vendorTree ? [vendorTree] : [];
if (this._shouldIncludePolyfill()) {
trees.push(this._eventSourceTree());
}
return new MergeTrees(trees);
},
_eventSourceTree() {
return new Funnel(
path.dirname(require.resolve('event-source-polyfill/src/eventsource.js')),
{
files: ['eventsource.js']
}
);
},
_shouldIncludePolyfill() {
if (this.project.targets && this.project.targets.browsers) {
let browsers = browserslist(this.project.targets.browsers);
let prohibitedBrowsers = browserslist(
EVENT_SOURCE_NON_SUPPORTED_BROWSERS
);
return prohibitedBrowsers.filter(version => browsers.includes(version))
.length;
}
return false;
}
};