-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
107 lines (91 loc) · 3.14 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
'use strict';
const VersionChecker = require('ember-cli-version-checker');
const SilentError = require('silent-error');
function inertPlugin() {
return {
name: 'holy-futuristic-template-namespacing-batman:noop',
visitor: {},
};
}
inertPlugin.cacheKey = () => 'ember-holy-futuristic-template-namespacing-batman:noop';
module.exports = {
name: 'ember-holy-futuristic-template-namespacing-batman',
init() {
this._super.init.apply(this, arguments);
let checker = new VersionChecker(this.project);
// Only check ember-resolver version if the app is using it (handles case where app uses ember-strict-resolver)
const emberResolverDep = checker.for('ember-resolver');
if (emberResolverDep.exists()) {
emberResolverDep.assertAbove('4.5.0', 'To use ember-holy-futuristic-template-namespacing-batman you must have ember-resolver@4.5.0');
}
},
_shouldBeInert() {
if (this.parent === this.project) {
// If we're a top-level addon, we're never inert
return false;
}
const addon = this.project && this.project.addons.find(a => Boolean(a.app));
const options = addon && addon.app.options['ember-holy-futuristic-template-namespacing-batman'] || {};
return Boolean(options.excludeNestedAddonTransforms);
},
setupPreprocessorRegistry(type, registry) {
const addon = this;
const dollarPluginObj = {
name: 'holy-futuristic-template-namespacing-batman',
get plugin() {
if (addon._shouldBeInert()) {
return inertPlugin;
}
return require('./lib/namespacing-transform');
},
baseDir: function() {
return __dirname;
},
cacheKey: function() {
return addon._shouldBeInert() ? 'noop' : 'transform';
},
parallelBabel: {
requireFile: __filename,
get buildUsing() {
return addon._shouldBeInert() ? '_buildInertPlugin' : '_buildDollarPlugin';
},
},
};
registry.add("htmlbars-ast-plugin", dollarPluginObj);
},
_buildDollarPlugin() {
// Used only when parallelizing the build
return {
name: 'holy-futuristic-template-namespacing-batman',
plugin: require('./lib/namespacing-transform'),
baseDir: function() {
return __dirname;
},
};
},
_buildInertPlugin() {
// Used when parallelized and doing nothing
return {
name: 'holy-futuristic-template-namespacing-batman',
plugin: inertPlugin,
baseDir: function () {
return __dirname;
},
};
},
included() {
this._super.included.apply(this, arguments);
if (this._shouldBeInert()) {
// This addon is included as a transitive dep _and_ excludeNestedAddonTransforms is set
// Check if there is a top-level copy of this addon and error if not
const topLevelAddon = this.project.addons.find(a => a.name === this.name);
if (!topLevelAddon) {
throw new SilentError(
"You must have ember-holy-futuristic-template-namespacing-batman installed in the root App if you enable the 'excludeNestedAddonTransforms' option."
);
}
} else {
this.import('vendor/service-inject-4.js');
}
},
};