forked from mike-north/ember-lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (61 loc) · 1.7 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
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-env node */
'use strict';
let path = require('path');
let replace = require('broccoli-string-replace');
let mergeTrees = require('broccoli-merge-trees');
let Funnel = require('broccoli-funnel');
let BroccoliDebug = require('broccoli-debug');
module.exports = {
name: 'lodash',
init() {
this._super.init && this._super.init.apply(this, arguments);
this._debugTree = BroccoliDebug.buildDebugCallback('ember-lodash');
},
_shouldCompileJS() {
return true;
},
treeForAddon(tree) {
let lodashPath = path.dirname(require.resolve('lodash-es'));
let lodashTree = this._debugTree(lodashPath, 'input');
lodashTree = replace(lodashTree, {
files: ['*.js'],
pattern: {
match: /\.js/g,
replacement: ''
}
});
lodashTree = this._debugTree(lodashTree, 'post-extension-replace');
lodashTree = new Funnel(lodashTree, {
getDestinationPath(path) {
if (path === 'lodash.js') {
return 'index.js';
}
return path;
}
});
lodashTree = this._debugTree(lodashTree, 'post-index-move');
lodashTree = replace(lodashTree, {
files: ['_getNative.js'],
pattern: {
match: /undefined/g,
replacement: 'null'
}
});
lodashTree = replace(lodashTree, {
files: ['_defineProperty.js'],
pattern: {
match: /catch ?\(e\) ?{ ?}/g,
replacement: 'catch(e) { return null; }'
}
});
lodashTree = this._debugTree(lodashTree, 'post-replacement');
if (tree) {
tree = mergeTrees([lodashTree, tree], {
overwrite: true
});
} else {
tree = lodashTree;
}
return this._super.treeForAddon.call(this, tree);
}
};