forked from sir-dunxalot/ember-tooltips
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
114 lines (98 loc) · 3.05 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict';
const funnel = require('broccoli-funnel');
const stringReplace = require('broccoli-string-replace');
const MergedTrees = require('broccoli-merge-trees');
const UnwatchedDir = require('broccoli-source').UnwatchedDir;
const path = require('path');
module.exports = {
name: require('./package').name,
findModulePath(basedir, moduleName) {
try {
const resolve = require('resolve'); // eslint-disable-line node/no-extraneous-require
return path.dirname(resolve.sync(moduleName, { basedir: basedir }));
} catch (_) {
try {
return path.dirname(require.resolve(moduleName));
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
this.ui.writeLine(
`ember-tooltips: ${moduleName} not installed, be sure you have ${moduleName} installed via npm/yarn.`
);
return;
}
throw e;
}
}
},
included: function () {
this._super.included.apply(this, arguments);
this.import(`${this.treePaths.vendor}/ember-tooltips--popper.js`, {
using: [
{
transformation: 'amd',
as: 'popper.js',
},
],
});
this.import(`${this.treePaths.vendor}/ember-tooltips--tooltip.js`, {
using: [
{
transformation: 'amd',
as: 'tooltip.js',
},
],
});
},
removeSourcemapAnnotation(node) {
return stringReplace(node, {
files: ['popper.js', 'tooltip.js'],
annotation: 'Remove sourcemap annotation (popper.js & tooltip.js)',
patterns: [
{
match: /\/\/# sourceMappingURL=popper.js.map/g,
replacement: '',
},
{
match: /\/\/# sourceMappingURL=tooltip.js.map/g,
replacement: '',
},
],
});
},
treeForAddonTestSupport(tree) {
const writeFile = require('broccoli-file-creator');
const optionalFeatures = this.project.findAddonByName(
'@ember/optional-features'
);
const testType =
optionalFeatures &&
!optionalFeatures.isFeatureEnabled('jquery-integration')
? 'dom'
: 'jquery';
const reexportTree = writeFile(
'index.js',
`export * from '${this.moduleName()}/test-support/${testType}';`
);
const mergedTree = new MergedTrees([tree, reexportTree]);
return this._super(mergedTree);
},
treeForVendor(tree) {
let popperPath = this.findModulePath(this.project.root, 'popper.js');
let popperTree = funnel(new UnwatchedDir(popperPath), {
include: ['popper.js'],
});
let tooltipPath = this.findModulePath(this.project.root, 'tooltip.js');
let tooltipTree = funnel(new UnwatchedDir(tooltipPath), {
include: ['tooltip.js'],
});
const mergedTree = new MergedTrees([tree, popperTree, tooltipTree]);
return funnel(this.removeSourcemapAnnotation(mergedTree), {
getDestinationPath(relativePath) {
if (relativePath === 'popper.js' || relativePath === 'tooltip.js') {
return `ember-tooltips--${relativePath}`;
}
return relativePath;
},
});
},
};