-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathforce-highlander-addon.js
58 lines (48 loc) · 1.85 KB
/
force-highlander-addon.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
'use strict';
const semver = require('semver');
const VersionChecker = require('ember-cli-version-checker');
const calculateCacheKeyForTree = require('calculate-cache-key-for-tree');
function findLatestVersion(addons) {
let latestVersion = addons[0];
addons.forEach((addon) => {
if (semver.gt(addon.pkg.version, latestVersion.pkg.version)) {
latestVersion = addon;
}
});
return latestVersion;
}
function forceHighlander(project) {
let checker = VersionChecker.forProject(project);
let testWaiterAddons = [
...checker.filterAddonsByName('ember-test-waiters'),
...checker.filterAddonsByName('@ember/test-waiters'),
];
let latestVersion = findLatestVersion(testWaiterAddons);
let noop = () => {};
return testWaiterAddons
.map((addon) => {
if (addon === latestVersion) {
return;
}
addon.cacheKeyForTree = (treeType) => {
// because this is overriding _both_ `@ember/test-waiters` and `ember-test-waiters`
// we need to append the addon's name here; the end result is that we get a different
// stable cache key, one for `@ember/test-waiters` and another for `ember-test-waiters`
// the reason for this is that Embroider doesn't currently take into account the addon's
// name when dealing with cache keys internally & as a result, it gets confused that
// (seemingly) two different addons have the same cache key. this will be fixed in Embroider,
// but in the short-term we're implementing this here to account for this issue
return `${calculateCacheKeyForTree(treeType, latestVersion)}-${addon.name}`;
};
addon.treeFor = (...args) => {
return latestVersion.treeFor(...args);
};
addon.included = noop;
return addon;
})
.filter(Boolean);
}
module.exports = {
findLatestVersion,
forceHighlander,
};