ember-cli 4.0.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/.github/workflows/ci.yml +4 -4
  2. package/CHANGELOG.md +42 -2
  3. package/blueprints/addon/additional-dev-dependencies.json +1 -1
  4. package/blueprints/addon/files/.github/workflows/ci.yml +0 -1
  5. package/blueprints/addon/files/.travis.yml +0 -1
  6. package/blueprints/addon/files/addon-config/ember-try.js +0 -13
  7. package/blueprints/app/files/config/environment.js +1 -1
  8. package/blueprints/app/files/package.json +6 -6
  9. package/docs/build/data.json +3 -3
  10. package/lib/models/host-info-cache.js +3 -5
  11. package/lib/models/per-bundle-addon-cache/index.js +2 -3
  12. package/lib/tasks/npm-task.js +1 -1
  13. package/lib/utilities/get-lang-arg.js +45 -45
  14. package/package.json +25 -25
  15. package/tests/helpers/mock-project.js +1 -1
  16. package/.github/ISSUE_TEMPLATE.md +0 -12
  17. package/.github/dependabot.yml +0 -15
  18. package/.github/workflows/coverage.yml +0 -31
  19. package/docs/analytics.md +0 -44
  20. package/docs/architecture.md +0 -316
  21. package/docs/assets/architecture/Ember-CLI architecture.png +0 -0
  22. package/docs/assets/architecture/Ember-CLI architecture.xml +0 -1
  23. package/docs/assets/architecture/README.md +0 -5
  24. package/docs/brocfile-transition.md +0 -46
  25. package/docs/build/api.js +0 -44
  26. package/docs/build/assets/css/external-small.png +0 -0
  27. package/docs/build/assets/css/logo.png +0 -0
  28. package/docs/build/assets/css/main.css +0 -555
  29. package/docs/build/assets/favicon.ico +0 -0
  30. package/docs/build/assets/img/spinner.gif +0 -0
  31. package/docs/build/assets/index.html +0 -10
  32. package/docs/build/assets/js/api-filter.js +0 -56
  33. package/docs/build/assets/js/api-list.js +0 -255
  34. package/docs/build/assets/js/api-search.js +0 -98
  35. package/docs/build/assets/js/apidocs.js +0 -376
  36. package/docs/build/assets/js/yui-prettify.js +0 -17
  37. package/docs/build/assets/vendor/prettify/CHANGES.html +0 -130
  38. package/docs/build/assets/vendor/prettify/COPYING +0 -202
  39. package/docs/build/assets/vendor/prettify/README.html +0 -203
  40. package/docs/build/assets/vendor/prettify/prettify-min.css +0 -1
  41. package/docs/build/assets/vendor/prettify/prettify-min.js +0 -1
  42. package/docs/build/classes/Addon.html +0 -4318
  43. package/docs/build/classes/AmdTransformAddon.html +0 -202
  44. package/docs/build/classes/Blueprint.html +0 -4796
  45. package/docs/build/classes/Builder.html +0 -611
  46. package/docs/build/classes/CLI.html +0 -810
  47. package/docs/build/classes/Command.html +0 -1655
  48. package/docs/build/classes/DefaultPackager.html +0 -202
  49. package/docs/build/classes/EmberAddon.html +0 -2207
  50. package/docs/build/classes/EmberApp.html +0 -2225
  51. package/docs/build/classes/HardwareInfo.html +0 -620
  52. package/docs/build/classes/HistorySupportAddon.html +0 -203
  53. package/docs/build/classes/Instrumentation.html +0 -695
  54. package/docs/build/classes/NodeModulesList.html +0 -460
  55. package/docs/build/classes/NpmTask.html +0 -333
  56. package/docs/build/classes/PackageInfo.html +0 -1390
  57. package/docs/build/classes/PackageInfoCache.html +0 -963
  58. package/docs/build/classes/PerBundleAddonCache {.html +0 -1010
  59. package/docs/build/classes/Project.html +0 -2083
  60. package/docs/build/classes/ServeFilesAddon.html +0 -260
  61. package/docs/build/classes/TestsServerAddon.html +0 -203
  62. package/docs/build/classes/WatcherAddon.html +0 -204
  63. package/docs/build/classes/WindowsSymlinkChecker.html +0 -1505
  64. package/docs/build/files/lib_broccoli_default-packager.js.html +0 -1426
  65. package/docs/build/files/lib_broccoli_ember-addon.js.html +0 -159
  66. package/docs/build/files/lib_broccoli_ember-app.js.html +0 -1913
  67. package/docs/build/files/lib_cli_cli.js.html +0 -417
  68. package/docs/build/files/lib_models_addon-info.js.html +0 -112
  69. package/docs/build/files/lib_models_addon.js.html +0 -1866
  70. package/docs/build/files/lib_models_blueprint.js.html +0 -1678
  71. package/docs/build/files/lib_models_builder.js.html +0 -417
  72. package/docs/build/files/lib_models_command.js.html +0 -804
  73. package/docs/build/files/lib_models_hardware-info.js.html +0 -479
  74. package/docs/build/files/lib_models_host-info-cache.js.html +0 -428
  75. package/docs/build/files/lib_models_installation-checker.js.html +0 -181
  76. package/docs/build/files/lib_models_instantiate-addons.js.html +0 -191
  77. package/docs/build/files/lib_models_instrumentation.js.html +0 -433
  78. package/docs/build/files/lib_models_package-info-cache_index.js.html +0 -793
  79. package/docs/build/files/lib_models_package-info-cache_node-modules-list.js.html +0 -208
  80. package/docs/build/files/lib_models_package-info-cache_package-info.js.html +0 -661
  81. package/docs/build/files/lib_models_per-bundle-addon-cache_addon-proxy.js.html +0 -252
  82. package/docs/build/files/lib_models_per-bundle-addon-cache_index.js.html +0 -485
  83. package/docs/build/files/lib_models_per-bundle-addon-cache_target-instance.js.html +0 -108
  84. package/docs/build/files/lib_models_project.js.html +0 -913
  85. package/docs/build/files/lib_models_task.js.html +0 -117
  86. package/docs/build/files/lib_tasks_build-watch.js.html +0 -157
  87. package/docs/build/files/lib_tasks_npm-task.js.html +0 -463
  88. package/docs/build/files/lib_tasks_serve.js.html +0 -207
  89. package/docs/build/files/lib_tasks_server_middleware_broccoli-serve-files_index.js.html +0 -127
  90. package/docs/build/files/lib_tasks_server_middleware_broccoli-watcher_index.js.html +0 -158
  91. package/docs/build/files/lib_tasks_server_middleware_history-support_index.js.html +0 -181
  92. package/docs/build/files/lib_tasks_server_middleware_tests-server_index.js.html +0 -171
  93. package/docs/build/files/lib_tasks_test-server.js.html +0 -167
  94. package/docs/build/files/lib_tasks_transforms_amd_index.js.html +0 -143
  95. package/docs/build/files/lib_utilities_ember-app-utils.js.html +0 -292
  96. package/docs/build/files/lib_utilities_insert-into-file.js.html +0 -219
  97. package/docs/build/files/lib_utilities_is-lazy-engine.js.html +0 -125
  98. package/docs/build/files/lib_utilities_is-yarn-project.js.html +0 -120
  99. package/docs/build/files/lib_utilities_valid-project-name.js.html +0 -142
  100. package/docs/build/files/lib_utilities_will-interrupt-process.js.html +0 -290
  101. package/docs/build/files/lib_utilities_windows-admin.js.html +0 -230
  102. package/docs/build/index.html +0 -125
  103. package/docs/build/modules/ember-cli.html +0 -152
  104. package/docs/build/modules/is-lazy-engine.html +0 -106
  105. package/docs/build-concurrency.md +0 -15
  106. package/docs/build-pipeline-debugging.md +0 -33
  107. package/docs/code-coverage.md +0 -14
  108. package/docs/error-propagation.md +0 -136
  109. package/docs/experiments.md +0 -53
  110. package/docs/node-support.md +0 -43
  111. package/docs/perf-guide.md +0 -250
  112. package/docs/project_version_preprocessor.js +0 -8
  113. package/docs/sourcemaps.md +0 -60
  114. package/docs/yuidoc.json +0 -13
@@ -1,1866 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>lib/models/addon.js - ember-cli</title>
6
- <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
7
- <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
8
- <script src="https://cdnjs.cloudflare.com/ajax/libs/yui/3.18.0/yui/yui-min.js"></script>
9
- </head>
10
- <body class="yui3-skin-sam">
11
-
12
- <div id="doc">
13
- <div class="yui3-g">
14
- <div id="sidebar" class="yui3-u">
15
- <div class="logo">
16
- <a href="../index.html">
17
- <img src="https://ember-cli.com/assets/images/ember-cli-logo-small-dark.png">
18
- </a>
19
- </div>
20
-
21
- <div id="modules" class="sidebox">
22
- <div class="hd">
23
- <h2 class="no-toc">Modules</h2>
24
- </div>
25
- <div class="bd">
26
- <ul>
27
- <li><a href="../modules/ember-cli.html">ember-cli</a>
28
- </li>
29
- <li><a href="../modules/is-lazy-engine.html">is-lazy-engine</a>
30
- </li>
31
- </ul>
32
- </div>
33
- </div>
34
-
35
- <div id="classes" class="sidebox">
36
- <div class="hd">
37
- <h2 class="no-toc">Classes</h2>
38
- </div>
39
- <div class="bd">
40
- <ul>
41
- <li><a href="../classes/Addon.html">Addon</a></li>
42
- <li><a href="../classes/AmdTransformAddon.html">AmdTransformAddon</a></li>
43
- <li><a href="../classes/Blueprint.html">Blueprint</a></li>
44
- <li><a href="../classes/Builder.html">Builder</a></li>
45
- <li><a href="../classes/CLI.html">CLI</a></li>
46
- <li><a href="../classes/Command.html">Command</a></li>
47
- <li><a href="../classes/DefaultPackager.html">DefaultPackager</a></li>
48
- <li><a href="../classes/EmberAddon.html">EmberAddon</a></li>
49
- <li><a href="../classes/EmberApp.html">EmberApp</a></li>
50
- <li><a href="../classes/HardwareInfo.html">HardwareInfo</a></li>
51
- <li><a href="../classes/HistorySupportAddon.html">HistorySupportAddon</a></li>
52
- <li><a href="../classes/Instrumentation.html">Instrumentation</a></li>
53
- <li><a href="../classes/NodeModulesList.html">NodeModulesList</a></li>
54
- <li><a href="../classes/NpmTask.html">NpmTask</a></li>
55
- <li><a href="../classes/PackageInfo.html">PackageInfo</a></li>
56
- <li><a href="../classes/PackageInfoCache.html">PackageInfoCache</a></li>
57
- <li><a href="../classes/PerBundleAddonCache {.html">PerBundleAddonCache {</a></li>
58
- <li><a href="../classes/Project.html">Project</a></li>
59
- <li><a href="../classes/ServeFilesAddon.html">ServeFilesAddon</a></li>
60
- <li><a href="../classes/TestsServerAddon.html">TestsServerAddon</a></li>
61
- <li><a href="../classes/WatcherAddon.html">WatcherAddon</a></li>
62
- <li><a href="../classes/WindowsSymlinkChecker.html">WindowsSymlinkChecker</a></li>
63
- </ul>
64
- </div>
65
- </div>
66
-
67
-
68
-
69
-
70
-
71
- <div class="version-info">
72
- Version: 4.0.0-release-b4cbb1029f
73
- </div>
74
-
75
- </div>
76
-
77
- <div id="main" class="yui3-u">
78
- <div class="content"><div class="title">
79
- <h1 class="file-name">lib/models/addon.js</h1>
80
- </div>
81
-
82
- <pre class="code prettyprint linenums">
83
- &#x27;use strict&#x27;;
84
-
85
- /**
86
- @module ember-cli
87
- */
88
-
89
- const fs = require(&#x27;fs&#x27;);
90
- const path = require(&#x27;path&#x27;);
91
- const SilentError = require(&#x27;silent-error&#x27;);
92
- const heimdallLogger = require(&#x27;heimdalljs-logger&#x27;);
93
- const logger = heimdallLogger(&#x27;ember-cli:addon&#x27;);
94
- const treeCacheLogger = heimdallLogger(&#x27;ember-cli:addon:tree-cache&#x27;);
95
- const cacheKeyLogger = heimdallLogger(&#x27;ember-cli:addon:cache-key-for-tree&#x27;);
96
- const PackageInfoCache = require(&#x27;../models/package-info-cache&#x27;);
97
-
98
- const p = require(&#x27;ember-cli-preprocess-registry/preprocessors&#x27;);
99
- const preprocessJs = p.preprocessJs;
100
- const preprocessCss = p.preprocessCss;
101
- const preprocessTemplates = p.preprocessTemplates;
102
-
103
- const instantiateAddons = require(&#x27;../models/instantiate-addons&#x27;);
104
-
105
- const CoreObject = require(&#x27;core-object&#x27;);
106
- const Project = require(&#x27;../models/project&#x27;);
107
-
108
- const mergeTrees = require(&#x27;../broccoli/merge-trees&#x27;);
109
- const Funnel = require(&#x27;broccoli-funnel&#x27;);
110
- const walkSync = require(&#x27;walk-sync&#x27;);
111
- const ensurePosixPath = require(&#x27;ensure-posix-path&#x27;);
112
- const defaultsDeep = require(&#x27;ember-cli-lodash-subset&#x27;).defaultsDeep;
113
- const findAddonByName = require(&#x27;../utilities/find-addon-by-name&#x27;);
114
- const heimdall = require(&#x27;heimdalljs&#x27;);
115
- const calculateCacheKeyForTree = require(&#x27;calculate-cache-key-for-tree&#x27;);
116
- const addonProcessTree = require(&#x27;../utilities/addon-process-tree&#x27;);
117
- const emberCLIBabelConfigKey = require(&#x27;../utilities/ember-cli-babel-config-key&#x27;);
118
- const semver = require(&#x27;semver&#x27;);
119
- const processModulesOnly = require(&#x27;../broccoli/babel-process-modules-only&#x27;);
120
- const registryHasPreprocessor = require(&#x27;../utilities/registry-has-preprocessor&#x27;);
121
-
122
- const BUILD_BABEL_OPTIONS_FOR_PREPROCESSORS = Symbol(&#x27;BUILD_BABEL_OPTIONS_FOR_PREPROCESSORS&#x27;);
123
-
124
- if (!heimdall.hasMonitor(&#x27;addon-tree-cache&#x27;)) {
125
- heimdall.registerMonitor(&#x27;addon-tree-cache&#x27;, function AddonTreeCacheSchema() {
126
- this.hits = 0;
127
- this.misses = 0;
128
- this.adds = 0;
129
- });
130
- }
131
-
132
- if (!heimdall.hasMonitor(&#x27;cache-key-for-tree&#x27;)) {
133
- heimdall.registerMonitor(&#x27;cache-key-for-tree&#x27;, function CacheKeyForTreeSchema() {
134
- this.modifiedMethods = 0;
135
- this.treeForMethodsOverride = 0;
136
- });
137
- }
138
-
139
- let DEFAULT_TREE_FOR_METHODS = {
140
- app: &#x27;treeForApp&#x27;,
141
- addon: &#x27;treeForAddon&#x27;,
142
- &#x27;addon-styles&#x27;: &#x27;treeForAddonStyles&#x27;,
143
- &#x27;addon-templates&#x27;: &#x27;treeForAddonTemplates&#x27;,
144
- &#x27;addon-test-support&#x27;: &#x27;treeForAddonTestSupport&#x27;,
145
- public: &#x27;treeForPublic&#x27;,
146
- styles: &#x27;treeForStyles&#x27;,
147
- templates: &#x27;treeForTemplates&#x27;,
148
- &#x27;test-support&#x27;: &#x27;treeForTestSupport&#x27;,
149
- vendor: &#x27;treeForVendor&#x27;,
150
- };
151
-
152
- let GLOBAL_TREE_FOR_METHOD_METHODS = [&#x27;treeFor&#x27;, &#x27;_treeFor&#x27;, &#x27;treeGenerator&#x27;];
153
- let DEFAULT_TREE_FOR_METHOD_METHODS = {
154
- app: [&#x27;treeForApp&#x27;],
155
- addon: [
156
- &#x27;treeForAddon&#x27;,
157
- &#x27;treeForAddonStyles&#x27;,
158
- &#x27;treeForAddonTemplates&#x27;,
159
- &#x27;compileAddon&#x27;,
160
- &#x27;processedAddonJsFiles&#x27;,
161
- &#x27;compileTemplates&#x27;,
162
- &#x27;_addonTemplateFiles&#x27;,
163
- &#x27;compileStyles&#x27;,
164
- &#x27;preprocessJs&#x27;,
165
- ],
166
- &#x27;addon-styles&#x27;: [&#x27;treeForAddonStyles&#x27;],
167
- &#x27;addon-templates&#x27;: [&#x27;treeForAddonTemplates&#x27;],
168
- &#x27;addon-test-support&#x27;: [&#x27;treeForAddonTestSupport&#x27;, &#x27;preprocessJs&#x27;],
169
- public: [&#x27;treeForPublic&#x27;],
170
- styles: [&#x27;treeForStyles&#x27;],
171
- templates: [&#x27;treeForTemplates&#x27;],
172
- &#x27;test-support&#x27;: [&#x27;treeForTestSupport&#x27;],
173
- vendor: [&#x27;treeForVendor&#x27;],
174
- };
175
-
176
- let ADDON_TREE_CACHE = {
177
- __cache: Object.create(null),
178
-
179
- getItem(key) {
180
- let addonTreeCacheStats = heimdall.statsFor(&#x27;addon-tree-cache&#x27;);
181
- let cachedValue = this.__cache[key];
182
-
183
- if (cachedValue) {
184
- addonTreeCacheStats.hits++;
185
- treeCacheLogger.info(&#x60;Cache Hit: ${key}&#x60;);
186
- return cachedValue;
187
- } else {
188
- addonTreeCacheStats.misses++;
189
- treeCacheLogger.info(&#x60;Cache Miss: ${key}&#x60;);
190
- return null;
191
- }
192
- },
193
-
194
- setItem(key, value) {
195
- let hasValue = !!value;
196
- heimdall.statsFor(&#x27;addon-tree-cache&#x27;).adds++;
197
- treeCacheLogger.info(&#x60;Cache Add: ${key} - ${hasValue}&#x60;);
198
- this.__cache[key] = value;
199
- },
200
-
201
- clear() {
202
- this.__cache = Object.create(null);
203
- },
204
- };
205
-
206
- function _resetTreeCache() {
207
- ADDON_TREE_CACHE.clear();
208
- }
209
-
210
- function warn(message) {
211
- if (this.ui) {
212
- this.ui.writeDeprecateLine(message);
213
- } else {
214
- const chalk = require(&#x27;chalk&#x27;);
215
- console.log(chalk.yellow(&#x60;DEPRECATION: ${message}&#x60;));
216
- }
217
- }
218
-
219
- /**
220
- Root class for an Addon. If your addon module exports an Object this
221
- will be extended from this base class. If you export a constructor (function),
222
- it will **not** extend from this class.
223
-
224
- Hooks:
225
-
226
- - {{#crossLink &quot;Addon/config:method&quot;}}{{/crossLink}}
227
- - {{#crossLink &quot;Addon/blueprintsPath:method&quot;}}{{/crossLink}}
228
- - {{#crossLink &quot;Addon/includedCommands:method&quot;}}{{/crossLink}}
229
- - {{#crossLink &quot;Addon/importTransforms:method&quot;}}{{/crossLink}}
230
- - {{#crossLink &quot;Addon/serverMiddleware:method&quot;}}{{/crossLink}}
231
- - {{#crossLink &quot;Addon/testemMiddleware:method&quot;}}{{/crossLink}}
232
- - {{#crossLink &quot;Addon/postBuild:method&quot;}}{{/crossLink}}
233
- - {{#crossLink &quot;Addon/preBuild:method&quot;}}{{/crossLink}}
234
- - {{#crossLink &quot;Addon/outputReady:method&quot;}}{{/crossLink}}
235
- - {{#crossLink &quot;Addon/buildError:method&quot;}}{{/crossLink}}
236
- - {{#crossLink &quot;Addon/included:method&quot;}}{{/crossLink}}
237
- - {{#crossLink &quot;Addon/shouldIncludeChildAddon:method&quot;}}{{/crossLink}}
238
- - {{#crossLink &quot;Addon/setupPreprocessorRegistry:method&quot;}}{{/crossLink}}
239
- - {{#crossLink &quot;Addon/preprocessTree:method&quot;}}{{/crossLink}}
240
- - {{#crossLink &quot;Addon/postprocessTree:method&quot;}}{{/crossLink}}
241
- - {{#crossLink &quot;Addon/lintTree:method&quot;}}{{/crossLink}}
242
- - {{#crossLink &quot;Addon/contentFor:method&quot;}}{{/crossLink}}
243
- - {{#crossLink &quot;Addon/treeFor:method&quot;}}{{/crossLink}}
244
-
245
- @class Addon
246
- @extends CoreObject
247
- @constructor
248
- @param {Project|Addon} parent The project or addon that directly depends on this addon
249
- @param {Project} project The current project (deprecated)
250
- */
251
- let addonProto = {
252
- /**
253
- The name of this addon.
254
-
255
- @public
256
- @final
257
- @type String
258
- @property name
259
- */
260
-
261
- /**
262
- The absolute path of the root directory where this addon is located.
263
-
264
- @public
265
- @final
266
- @type String
267
- @property root
268
- */
269
-
270
- /**
271
- The host app instance.
272
-
273
- **Note**: this property will only be present on addons that are a direct dependency
274
- of the application itself, not of other addons. It is also not available in &#x60;init()&#x60;,
275
- but will be set before &#x60;setupPreprocessorRegistry()&#x60; and &#x60;included()&#x60; are invoked.
276
-
277
- @public
278
- @final
279
- @type EmberApp
280
- @property app
281
- */
282
-
283
- /**
284
- The root {{#crossLink &quot;Project&quot;}}project{{/crossLink}} to which this addon belongs.
285
-
286
- @public
287
- @final
288
- @type Project
289
- @property project
290
- */
291
-
292
- /**
293
- This addon&#x27;s parent.
294
-
295
- If the addon is a direct dependency of an application, then &#x60;parent&#x60; will be the
296
- corresponding {{#crossLink &quot;Project&quot;}}project{{/crossLink}} instance. If it&#x27;s a
297
- dependency of another addon, then &#x60;parent&#x60; will be a reference to that addon.
298
-
299
- @public
300
- @final
301
- @type Project|Addon
302
- @property parent
303
- */
304
-
305
- /**
306
- The set of addons that this addon itself depends on.
307
-
308
- This array is populated from the addon&#x27;s listed &#x60;dependencies&#x60; and any items in
309
- &#x60;ember-addon.paths&#x60; in its &#x60;package.json&#x60;.
310
-
311
- @public
312
- @final
313
- @type Addon[]
314
- @property addons
315
- */
316
-
317
- /**
318
- A [&#x60;console-ui&#x60;](https://github.com/ember-cli/console-ui) object that can be used
319
- to log messages for the user and indicate progress on long-running operations.
320
-
321
- @public
322
- @final
323
- @type UI
324
- @property ui
325
- */
326
-
327
- /**
328
- The contents of the addon&#x27;s &#x60;package.json&#x60;.
329
-
330
- @public
331
- @final
332
- @type Object
333
- @property pkg
334
- */
335
-
336
- /**
337
- Initializes the addon. If you override this method make sure and call &#x60;this._super.init &amp;&amp; this._super.init.apply(this, arguments);&#x60; or your addon will not work.
338
-
339
- @public
340
- @method init
341
- @param {Project|Addon} parent The project or addon that directly depends on this addon
342
- @param {Project} project The current project (deprecated)
343
-
344
- @example
345
- &#x60;&#x60;&#x60;js
346
- init(parent, project) {
347
- this._super.init &amp;&amp; this._super.init.apply(this, arguments);
348
- this._someCustomSetup();
349
- }
350
- &#x60;&#x60;&#x60;
351
- */
352
- init(parent, project) {
353
- this._super();
354
- this.parent = parent;
355
- this.project = project;
356
- this.ui = project &amp;&amp; project.ui;
357
- this.addonPackages = Object.create(null);
358
- this.addons = [];
359
- this.registry = p.defaultRegistry(this);
360
-
361
- if (!this.root) {
362
- throw new Error(&#x27;Addon classes must be instantiated with the &#x60;root&#x60; property&#x27;);
363
- }
364
-
365
- if (!this.name) {
366
- throw new SilentError(&#x60;An addon must define a \&#x60;name\&#x60; property (found at ${this.root}).&#x60;);
367
- }
368
-
369
- this._nodeModulesPath = null;
370
-
371
- this.treePaths = {
372
- app: &#x27;app&#x27;,
373
- styles: &#x27;app/styles&#x27;,
374
- templates: &#x27;app/templates&#x27;,
375
- addon: &#x27;addon&#x27;,
376
- &#x27;addon-styles&#x27;: &#x27;addon/styles&#x27;,
377
- &#x27;addon-templates&#x27;: &#x27;addon/templates&#x27;,
378
- vendor: &#x27;vendor&#x27;,
379
- &#x27;test-support&#x27;: &#x27;test-support&#x27;,
380
- &#x27;addon-test-support&#x27;: &#x27;addon-test-support&#x27;,
381
- public: &#x27;public&#x27;,
382
- };
383
-
384
- this.treeForMethods = defaultsDeep({}, DEFAULT_TREE_FOR_METHODS);
385
-
386
- if (this.parent) {
387
- // The parent should already have a packageInfoCache.
388
- // Because it does, this package should already be in the cache.
389
- this.packageInfoCache = this.parent.packageInfoCache;
390
- }
391
-
392
- if (!this.packageInfoCache) {
393
- // this is most likely a &#x27;root&#x27; addon, so create a new PackageInfoCache
394
- // for it so we get the PackageInfo for it and its children.
395
- //
396
- // this may also be someone who failed to mock their addon correctly in testing.
397
- this.packageInfoCache = new PackageInfoCache(this.ui);
398
- }
399
-
400
- this._packageInfo = this.packageInfoCache.loadAddon(this);
401
-
402
- p.setupRegistry(this);
403
-
404
- this._initDefaultBabelOptions();
405
- },
406
-
407
- _initDefaultBabelOptions() {
408
- this.__originalOptions = this.options = defaultsDeep(this.options, {
409
- babel: this[BUILD_BABEL_OPTIONS_FOR_PREPROCESSORS](),
410
- });
411
-
412
- let defaultEmberCLIBabelOptions = {
413
- compileModules: true,
414
- };
415
- let emberCLIBabelConfigKey = this._emberCLIBabelConfigKey();
416
- this.__originalOptions[emberCLIBabelConfigKey] = this.options[emberCLIBabelConfigKey] = defaultsDeep(
417
- this.options[emberCLIBabelConfigKey],
418
- defaultEmberCLIBabelOptions
419
- );
420
- },
421
-
422
- /**
423
- * Find an addon of the current addon.
424
- *
425
- * Example: ember-data depends on ember-cli-babel and wishes to have
426
- * additional control over transpilation this method helps.
427
- *
428
- * &#x60;&#x60;&#x60;js
429
- * // ember-data/index.js
430
- * treeForAddon(tree) {
431
- * let babel = this.findOwnAddonByName(&#x27;ember-cli-babel&#x27;);
432
- *
433
- * return babel.transpileTree(tree, {
434
- * // customize the babel step (see: ember-cli-addons readme for more details);
435
- * });
436
- * }
437
- * &#x60;&#x60;&#x60;
438
- *
439
- * @public
440
- * @method findOwnAddonByName
441
- */
442
- findOwnAddonByName(name) {
443
- return this.addons.find((addon) =&gt; addon.name === name);
444
- },
445
-
446
- /**
447
- * Check if the current addon intends to be hinted. Typically this is for
448
- * hinting/linting libraries such as eslint or jshint
449
- *
450
- * @public
451
- * @method hintingEnabled
452
- */
453
- hintingEnabled() {
454
- let isProduction = process.env.EMBER_ENV === &#x27;production&#x27;;
455
- let testsEnabledDefault = process.env.EMBER_CLI_TEST_COMMAND === &#x27;true&#x27; || !isProduction;
456
- let explicitlyDisabled = this.app &amp;&amp; this.app.options &amp;&amp; this.app.options.hinting === false;
457
-
458
- return testsEnabledDefault &amp;&amp; !explicitlyDisabled;
459
- },
460
-
461
- /**
462
- Shorthand method for [broccoli-concat](https://github.com/ember-cli/broccoli-concat)
463
-
464
- @private
465
- @method concatFiles
466
- @param {tree} tree Tree of files
467
- @param {Object} options Options for broccoli-concat
468
- @return {tree} Modified tree
469
- */
470
- concatFiles(tree, options) {
471
- options.sourceMapConfig = this.app.options.sourcemaps;
472
- return require(&#x27;broccoli-concat&#x27;)(tree, options);
473
- },
474
-
475
- /**
476
- Allows to mark the addon as developing, triggering live-reload in the project the addon is linked to.
477
-
478
- #### Uses:
479
-
480
- - Working on projects with internal addons
481
-
482
- @public
483
- @method isDevelopingAddon
484
- @return {Boolean}
485
- */
486
- isDevelopingAddon() {
487
- if (process.env.EMBER_ADDON_ENV === &#x27;development&#x27; &amp;&amp; this.parent instanceof Project) {
488
- const parentName = this.parent.name();
489
- // If the name in package.json and index.js match, we&#x27;re definitely developing
490
- if (parentName === this.name) {
491
- return true;
492
- }
493
-
494
- // Addon names in index.js and package.json should be the same at all times whether they have scope or not.
495
- if (this.root === this.parent.root) {
496
- if (parentName !== this.name &amp;&amp; !process.env.EMBER_CLI_IGNORE_ADDON_NAME_MISMATCH) {
497
- let pathToDisplay = process.cwd() === this.root ? process.cwd() : path.relative(process.cwd(), this.root);
498
-
499
- throw new SilentError(
500
- &#x27;ember-cli: Your names in package.json and index.js should match. &#x27; +
501
- &#x60;The addon in ${pathToDisplay} currently have &#x27;${parentName}&#x27; in package.json and &#x27;${this.name}&#x27; in index.js. &#x60; +
502
- &#x27;Until ember-cli v3.9, this error can be disabled by setting env variable EMBER_CLI_IGNORE_ADDON_NAME_MISMATCH to &quot;true&quot;. &#x27; +
503
- &#x27;For more information about this workaround, see: https://github.com/ember-cli/ember-cli/pull/7950.&#x27;
504
- );
505
- }
506
-
507
- return true;
508
- }
509
- }
510
- return false;
511
- },
512
-
513
- /**
514
- * Discovers all child addons of this addon and an AddonInfo about
515
- * each addon in this.addonPackages (keyed on addon name).
516
- *
517
- * Child addons include those from &#x27;dependencies&#x27; (not devDependencies)
518
- * and in-repo addons
519
- *
520
- * Any packageInfos that we find that are marked as not valid are excluded.
521
- *
522
- * @private
523
- * @method discoverAddons
524
- */
525
- discoverAddons() {
526
- // prefer &#x60;packageRoot&#x60;, fallback to &#x60;root&#x60;; this is to maintain backwards compatibility for
527
- // consumers who create a new instance of the base addon model class directly and don&#x27;t set
528
- // &#x60;packageRoot&#x60;
529
- let pkgInfo = this.packageInfoCache.getEntry(this.packageRoot || this.root);
530
-
531
- if (pkgInfo) {
532
- let addonPackageList = pkgInfo.discoverAddonAddons();
533
- this.addonPackages = pkgInfo.generateAddonPackages(
534
- addonPackageList,
535
- (addonInfo) =&gt; this.shouldIncludeChildAddon &amp;&amp; !this.shouldIncludeChildAddon(addonInfo)
536
- );
537
-
538
- // in case any child addons are invalid, dump to the console about them.
539
- pkgInfo.dumpInvalidAddonPackages(addonPackageList);
540
- } else {
541
- // There are cases where an addon can be created in memory and not actually
542
- // have a root entry (or have one that is not actually pointing to a directory,
543
- // like &#x27;foo&#x27; in some of the tests. We don&#x27;t want to crash, but want to let
544
- // things continue even though they&#x27;re empty.
545
- this.addonPackages = Object.create(null);
546
- }
547
- },
548
-
549
- initializeAddons() {
550
- if (this._addonsInitialized) {
551
- return;
552
- }
553
- this._addonsInitialized = true;
554
-
555
- logger.info(&#x27;initializeAddons for: %s&#x27;, this.name);
556
-
557
- this.discoverAddons();
558
-
559
- this.addons = instantiateAddons(this, this.project, this.addonPackages);
560
- this.addons.forEach((addon) =&gt; logger.info(&#x27;addon: %s&#x27;, addon.name));
561
- },
562
-
563
- /**
564
- Invoke the specified method for each enabled addon.
565
-
566
- @private
567
- @method eachAddonInvoke
568
- @param {String} methodName the method to invoke on each addon
569
- @param {Array} args the arguments to pass to the invoked method
570
- */
571
- eachAddonInvoke(methodName, args) {
572
- this.initializeAddons();
573
-
574
- let invokeArguments = args || [];
575
-
576
- return this.addons.reduce((sum, addon) =&gt; {
577
- let method = addon[methodName];
578
- if (method) {
579
- let val = method.apply(addon, invokeArguments);
580
- if (val) {
581
- sum.push(val);
582
- }
583
- }
584
- return sum;
585
- }, []);
586
- },
587
-
588
- /**
589
- Invoke the specified method for each of the project&#x27;s addons.
590
-
591
- @private
592
- @method _eachProjectAddonInvoke
593
- @param {String} methodName the method to invoke on each addon
594
- @param {Array} args the arguments to pass to the invoked method
595
- */
596
- _eachProjectAddonInvoke(methodName, args) {
597
- this.initializeAddons();
598
-
599
- let invokeArguments = args || [];
600
-
601
- return this.project.addons.reduce((sum, addon) =&gt; {
602
- let method = addon[methodName];
603
- if (method) {
604
- let val = method.apply(addon, invokeArguments);
605
- if (val) {
606
- sum.push(val);
607
- }
608
- }
609
- return sum;
610
- }, []);
611
- },
612
-
613
- _addonPreprocessTree(type, tree) {
614
- return addonProcessTree(this, &#x27;preprocessTree&#x27;, type, tree);
615
- },
616
-
617
- _addonPostprocessTree(type, tree) {
618
- return addonProcessTree(this, &#x27;postprocessTree&#x27;, type, tree);
619
- },
620
-
621
- /**
622
- Generates a tree for the specified path
623
-
624
- @private
625
- @method treeGenerator
626
- @return {tree}
627
- */
628
- treeGenerator(dir) {
629
- let tree;
630
-
631
- if (!this.project) {
632
- this._warn(
633
- &#x60;Addon: \&#x60;${this.name}\&#x60; is missing addon.project, this may be the result of an addon forgetting to invoke \&#x60;super\&#x60; in its init.&#x60;
634
- );
635
- }
636
- // TODO: fix law of demeter &#x60;_watchmanInfo.canNestRoots&#x60; is obviously a poor idea
637
- if ((this.project &amp;&amp; this.project._watchmanInfo.canNestRoots) || this.isDevelopingAddon()) {
638
- const WatchedDir = require(&#x27;broccoli-source&#x27;).WatchedDir;
639
- tree = new WatchedDir(dir);
640
- } else {
641
- const UnwatchedDir = require(&#x27;broccoli-source&#x27;).UnwatchedDir;
642
- tree = new UnwatchedDir(dir);
643
- }
644
-
645
- return tree;
646
- },
647
-
648
- _treePathFor(treeName) {
649
- let treePath = this.treePaths[treeName];
650
- let absoluteTreePath = path.join(this.root, treePath);
651
- let normalizedAbsoluteTreePath = path.normalize(absoluteTreePath);
652
-
653
- return ensurePosixPath(normalizedAbsoluteTreePath);
654
- },
655
-
656
- /**
657
- * @private
658
- * @method _warn
659
- */
660
- _warn: warn,
661
-
662
- _emberCLIBabelConfigKey() {
663
- let emberCLIBabelInstance = findAddonByName(this.addons, &#x27;ember-cli-babel&#x27;);
664
-
665
- return emberCLIBabelConfigKey(emberCLIBabelInstance);
666
- },
667
-
668
- /**
669
- Returns a given type of tree (if present), merged with the
670
- application tree. For each of the trees available using this
671
- method, you can also use a direct method called &#x60;treeFor[Type]&#x60; (eg. &#x60;treeForApp&#x60;).
672
-
673
- Available tree names:
674
- - {{#crossLink &quot;Addon/treeForApp:method&quot;}}app{{/crossLink}}
675
- - {{#crossLink &quot;Addon/treeForStyles:method&quot;}}styles{{/crossLink}}
676
- - {{#crossLink &quot;Addon/treeForTemplates:method&quot;}}templates{{/crossLink}}
677
- - {{#crossLink &quot;Addon/treeForAddonTemplates:method&quot;}}addon-templates{{/crossLink}}
678
- - {{#crossLink &quot;Addon/treeForAddon:method&quot;}}addon{{/crossLink}}
679
- - {{#crossLink &quot;Addon/treeForVendor:method&quot;}}vendor{{/crossLink}}
680
- - {{#crossLink &quot;Addon/treeForTestSupport:method&quot;}}test-support{{/crossLink}}
681
- - {{#crossLink &quot;Addon/treeForAddonTestSupport:method&quot;}}addon-test-support{{/crossLink}}
682
- - {{#crossLink &quot;Addon/treeForPublic:method&quot;}}public{{/crossLink}}
683
-
684
- #### Uses:
685
-
686
- - manipulating trees at build time
687
-
688
- @public
689
- @method treeFor
690
- @param {String} name
691
- @return {Tree}
692
- */
693
- treeFor(treeType) {
694
- let node = heimdall.start({
695
- name: &#x60;treeFor(${this.name} - ${treeType})&#x60;,
696
- addonName: this.name,
697
- treeType,
698
- treeFor: true,
699
- });
700
-
701
- let cacheKeyForTreeType = this.cacheKeyForTree(treeType);
702
-
703
- let cachedTree = ADDON_TREE_CACHE.getItem(cacheKeyForTreeType);
704
- if (cachedTree) {
705
- node.stop();
706
- return cachedTree;
707
- }
708
-
709
- let trees = this.eachAddonInvoke(&#x27;treeFor&#x27;, [treeType]);
710
- let tree = this._treeFor(treeType);
711
-
712
- if (tree) {
713
- trees.push(tree);
714
- }
715
-
716
- if (this.isDevelopingAddon() &amp;&amp; this.hintingEnabled() &amp;&amp; treeType === &#x27;app&#x27;) {
717
- trees.push(this.jshintAddonTree());
718
- }
719
-
720
- let mergedTreesForType = mergeTrees(trees, {
721
- overwrite: true,
722
- annotation: &#x60;Addon#treeFor (${this.name} - ${treeType})&#x60;,
723
- });
724
-
725
- if (cacheKeyForTreeType) {
726
- ADDON_TREE_CACHE.setItem(cacheKeyForTreeType, mergedTreesForType);
727
- }
728
-
729
- node.stop();
730
-
731
- return mergedTreesForType;
732
- },
733
-
734
- /**
735
- @private
736
- @param {String} name
737
- @method _treeFor
738
- @return {tree}
739
- */
740
- _treeFor(name) {
741
- let treePath = path.resolve(this.root, this.treePaths[name]);
742
- let treeForMethod = this.treeForMethods[name];
743
- let tree;
744
-
745
- if (fs.existsSync(treePath)) {
746
- tree = this.treeGenerator(treePath);
747
- }
748
-
749
- if (this[treeForMethod]) {
750
- tree = this[treeForMethod](tree);
751
- }
752
-
753
- return tree;
754
- },
755
-
756
- /**
757
- Calculates a cacheKey for the given treeType. It is expected to return a
758
- cache key allowing multiple builds of the same tree to simply return the
759
- original tree (preventing duplicate work). If it returns null / undefined
760
- the tree in question will opt out of this caching system.
761
-
762
- This method is invoked prior to calling treeFor with the same tree name.
763
-
764
- You should override this method if you implement custom treeFor or treeFor*
765
- methods, which cause addons to opt-out of this caching.
766
-
767
- @public
768
- @method cacheKeyForTree
769
- @param {String} treeType
770
- @return {String} cacheKey
771
- */
772
- cacheKeyForTree(treeType) {
773
- let methodsToValidate = methodsForTreeType(treeType);
774
- let cacheKeyStats = heimdall.statsFor(&#x27;cache-key-for-tree&#x27;);
775
-
776
- // determine if treeFor* (or other methods for tree type) overrides for the given tree
777
- let modifiedMethods = methodsToValidate.filter((methodName) =&gt; this[methodName] !== addonProto[methodName]);
778
-
779
- if (modifiedMethods.length) {
780
- cacheKeyStats.modifiedMethods++;
781
- cacheKeyLogger.info(&#x60;Opting out due to: modified methods: ${modifiedMethods.join(&#x27;, &#x27;)}&#x60;);
782
- return null; // uncacheable
783
- }
784
-
785
- // determine if treeForMethods overrides for given tree
786
- if (this.treeForMethods[treeType] !== DEFAULT_TREE_FOR_METHODS[treeType]) {
787
- cacheKeyStats.treeForMethodsOverride++;
788
- cacheKeyLogger.info(&#x27;Opting out due to: treeForMethods override&#x27;);
789
- return null; // uncacheable
790
- }
791
-
792
- // compute cache key
793
- let cacheKey = calculateCacheKeyForTree(treeType, this);
794
-
795
- return cacheKey; // profit?
796
- },
797
-
798
- /**
799
- This method climbs up the hierarchy of addons
800
- up to the host application.
801
-
802
- This prevents previous addons (prior to &#x60;this.import&#x60;, ca 2.7.0)
803
- to break at importing assets when they are used nested in other addons.
804
-
805
- @private
806
- @method _findHost
807
- */
808
- _findHost() {
809
- let current = this;
810
- let app;
811
-
812
- // Keep iterating upward until we don&#x27;t have a grandparent.
813
- // Has to do this grandparent check because at some point we hit the project.
814
- do {
815
- app = current.app || app;
816
- } while (current.parent.parent &amp;&amp; (current = current.parent));
817
-
818
- return app;
819
- },
820
-
821
- /**
822
- This method is called when the addon is included in a build. You
823
- would typically use this hook to perform additional imports
824
-
825
- #### Uses:
826
-
827
- - including vendor files
828
- - setting configuration options
829
-
830
- *Note:* Any options set in the consuming application will override the addon.
831
-
832
- @public
833
- @method included
834
- @param {EmberApp|EmberAddon} parent The parent object which included this addon
835
-
836
- @example
837
- &#x60;&#x60;&#x60;js
838
- included(parent) {
839
- this._super.included.apply(this, arguments);
840
- this.import(somePath);
841
- }
842
- &#x60;&#x60;&#x60;
843
- */
844
- included(/* parent */) {
845
- if (!this._addonsInitialized) {
846
- // someone called &#x60;this._super.included&#x60; without &#x60;apply&#x60; (because of older
847
- // core-object issues that prevent a &quot;real&quot; super call from working properly)
848
- return;
849
- }
850
-
851
- this.eachAddonInvoke(&#x27;included&#x27;, [this]);
852
- },
853
-
854
- /**
855
- Imports an asset into this addon.
856
-
857
- @public
858
- @method import
859
- @param {Object|String} asset Either a path to the asset or an object with environment names and paths as key-value pairs.
860
- @param {Object} [options] Options object
861
- @param {String} [options.type] Either &#x27;vendor&#x27; or &#x27;test&#x27;, defaults to &#x27;vendor&#x27;
862
- @param {Boolean} [options.prepend] Whether or not this asset should be prepended, defaults to false
863
- @param {String} [options.destDir] Destination directory, defaults to the name of the directory the asset is in
864
- @since 2.7.0
865
- */
866
- import(asset, options) {
867
- options = options || {};
868
- options.resolveFrom = options.resolveFrom || this.root;
869
-
870
- let app = this._findHost();
871
- app.import(asset, options);
872
- },
873
-
874
- /**
875
- Returns the tree for all app files
876
-
877
- @public
878
- @method treeForApp
879
- @param {Tree} tree
880
- @return {Tree} App file tree
881
- */
882
- treeForApp(tree) {
883
- return tree;
884
- },
885
-
886
- /**
887
- Returns the tree for all template files
888
-
889
- @public
890
- @method treeForTemplates
891
- @param {Tree} tree
892
- @return {Tree} Template file tree
893
- */
894
- treeForTemplates(tree) {
895
- return tree;
896
- },
897
-
898
- /**
899
- Returns the tree for this addon&#x27;s templates
900
-
901
- @public
902
- @method treeForAddonTemplates
903
- @param {Tree} tree
904
- @return {Tree} Addon Template file tree
905
- */
906
- treeForAddonTemplates(tree) {
907
- return tree;
908
- },
909
-
910
- /**
911
- Returns a tree for this addon
912
-
913
- @public
914
- @method treeForAddon
915
- @param {Tree} tree
916
- @return {Tree} Addon file tree
917
-
918
- @example
919
- &#x60;&#x60;&#x60;js
920
- treeForAddon() {
921
- var tree = this._super.treeForAddon.apply(this, arguments);
922
- var checker = new VersionChecker(this);
923
- var isOldEmber = checker.for(&#x27;ember&#x27;, &#x27;bower&#x27;).lt(&#x27;1.13.0&#x27;);
924
-
925
- if (isOldEmber) {
926
- tree = new Funnel(tree, { exclude: [ /instance-initializers/ ] });
927
- }
928
-
929
- return tree;
930
- }
931
- &#x60;&#x60;&#x60;
932
- */
933
- treeForAddon(tree) {
934
- if (!tree) {
935
- return tree;
936
- }
937
-
938
- let addonTree = this.compileAddon(tree);
939
- let stylesTree = this.compileStyles(this._treeFor(&#x27;addon-styles&#x27;));
940
-
941
- return mergeTrees([addonTree, stylesTree], { annotation: &#x60;Addon#treeForAddon(${this.name})&#x60; });
942
- },
943
-
944
- /**
945
- Returns the tree for all style files
946
-
947
- @public
948
- @method treeForStyles
949
- @param {Tree} tree The tree to process, usually &#x60;app/styles/&#x60; in the addon.
950
- @return {Tree} The return tree has the same contents as the input tree, but is moved so that the &#x60;app/styles/&#x60; path is preserved.
951
- */
952
- treeForStyles(tree) {
953
- if (!tree) {
954
- return tree;
955
- }
956
-
957
- return new Funnel(tree, {
958
- destDir: &#x27;app/styles&#x27;,
959
- annotation: &#x60;Addon#treeForStyles (${this.name})&#x60;,
960
- });
961
- },
962
-
963
- /**
964
- Returns the tree for all vendor files
965
-
966
- @public
967
- @method treeForVendor
968
- @param {Tree} tree
969
- @return {Tree} Vendor file tree
970
- */
971
- treeForVendor(tree) {
972
- return tree;
973
- },
974
-
975
- /**
976
- Returns the tree for all test support files
977
-
978
- @public
979
- @method treeForTestSupport
980
- @param {Tree} tree
981
- @return {Tree} Test Support file tree
982
- */
983
- treeForTestSupport(tree) {
984
- return tree;
985
- },
986
-
987
- /**
988
- Returns the tree for all public files
989
-
990
- @public
991
- @method treeForPublic
992
- @param {Tree} tree
993
- @return {Tree} Public file tree
994
- */
995
- treeForPublic(tree) {
996
- if (!tree) {
997
- return tree;
998
- }
999
-
1000
- return new Funnel(tree, {
1001
- srcDir: &#x27;/&#x27;,
1002
- destDir: &#x60;/${this.moduleName()}&#x60;,
1003
- annotation: &#x60;Addon#treeForPublic (${this.name})&#x60;,
1004
- });
1005
- },
1006
-
1007
- /**
1008
- Returns the tree for all test files namespaced to a given addon.
1009
-
1010
- @public
1011
- @method treeForAddonTestSupport
1012
- @param {Tree} tree
1013
- @return {Tree}
1014
- */
1015
- treeForAddonTestSupport(tree) {
1016
- if (!tree) {
1017
- return tree;
1018
- }
1019
-
1020
- let namespacedTree = new Funnel(tree, {
1021
- srcDir: &#x27;/&#x27;,
1022
- destDir: &#x60;/${this.moduleName()}/test-support&#x60;,
1023
- annotation: &#x60;Addon#treeForTestSupport (${this.name})&#x60;,
1024
- });
1025
-
1026
- if (registryHasPreprocessor(this.registry, &#x27;js&#x27;)) {
1027
- return this.preprocessJs(namespacedTree, &#x27;/&#x27;, this.name, {
1028
- registry: this.registry,
1029
- treeType: &#x27;addon-test-support&#x27;,
1030
- });
1031
- } else {
1032
- this._warn(
1033
- &#x60;Addon test support files were detected in \&#x60;${this._treePathFor(&#x27;addon-test-support&#x27;)}\&#x60;, but no JavaScript &#x60; +
1034
- &#x60;preprocessors were found for \&#x60;${this.name}\&#x60;. Please make sure to add a preprocessor &#x60; +
1035
- &#x60;(most likely \&#x60;ember-cli-babel\&#x60;) to \&#x60;dependencies\&#x60; (NOT \&#x60;devDependencies\&#x60;) in &#x60; +
1036
- &#x60;\&#x60;${this.name}\&#x60;&#x27;s \&#x60;package.json\&#x60;.&#x60;
1037
- );
1038
-
1039
- return processModulesOnly(namespacedTree, &#x60;Babel Fallback - Addon#treeForAddonTestSupport (${this.name})&#x60;);
1040
- }
1041
- },
1042
-
1043
- /**
1044
- Runs the styles tree through preprocessors.
1045
-
1046
- @private
1047
- @method compileStyles
1048
- @param {Tree} addonStylesTree Styles file tree
1049
- @return {Tree} Compiled styles tree
1050
- */
1051
- compileStyles(addonStylesTree) {
1052
- if (addonStylesTree) {
1053
- let preprocessedStylesTree = this._addonPreprocessTree(&#x27;css&#x27;, addonStylesTree);
1054
-
1055
- let processedStylesTree = preprocessCss(preprocessedStylesTree, &#x27;/&#x27;, &#x27;/&#x27;, {
1056
- outputPaths: { addon: &#x60;${this.name}.css&#x60; },
1057
- registry: this.registry,
1058
- treeType: &#x27;addon-styles&#x27;,
1059
- });
1060
- processedStylesTree = new Funnel(processedStylesTree, {
1061
- destDir: &#x60;${this.name}/__COMPILED_STYLES__&#x60;,
1062
- });
1063
-
1064
- return this._addonPostprocessTree(&#x27;css&#x27;, processedStylesTree);
1065
- }
1066
- },
1067
-
1068
- /**
1069
- Looks in the addon/ and addon/templates trees to determine if template files
1070
- exist that need to be precompiled.
1071
-
1072
- This is executed once when building, but not on rebuilds.
1073
-
1074
- @private
1075
- @method shouldCompileTemplates
1076
- @return {Boolean} indicates if templates need to be compiled for this addon
1077
- */
1078
- shouldCompileTemplates() {
1079
- return this._fileSystemInfo().hasTemplates;
1080
- },
1081
-
1082
- /**
1083
- Looks in the addon/ and addon/templates trees to determine if template files
1084
- exist in the pods format that need to be precompiled.
1085
-
1086
- This is executed once when building, but not on rebuilds.
1087
-
1088
- @private
1089
- @method _shouldCompilePodTemplates
1090
- @return {Boolean} indicates if pod based templates need to be compiled for this addon
1091
- */
1092
- _shouldCompilePodTemplates() {
1093
- return this._fileSystemInfo().hasPodTemplates;
1094
- },
1095
-
1096
- _fileSystemInfo() {
1097
- if (this._cachedFileSystemInfo) {
1098
- return this._cachedFileSystemInfo;
1099
- }
1100
-
1101
- let jsExtensions = this.registry.extensionsForType(&#x27;js&#x27;);
1102
- let templateExtensions = this.registry.extensionsForType(&#x27;template&#x27;);
1103
- let addonTreePath = this._treePathFor(&#x27;addon&#x27;);
1104
- let addonTemplatesTreePath = this._treePathFor(&#x27;addon-templates&#x27;);
1105
- let addonTemplatesTreeInAddonTree = addonTemplatesTreePath.indexOf(addonTreePath) === 0;
1106
-
1107
- let files = this._getAddonTreeFiles();
1108
-
1109
- let addonTemplatesRelativeToAddonPath =
1110
- addonTemplatesTreeInAddonTree &amp;&amp; addonTemplatesTreePath.replace(&#x60;${addonTreePath}/&#x60;, &#x27;&#x27;);
1111
- let podTemplateMatcher = new RegExp(&#x60;template.(${templateExtensions.join(&#x27;|&#x27;)})$&#x60;);
1112
- let hasPodTemplates = files.some((file) =&gt; {
1113
- // short circuit if this is actually an &#x60;addon/templates&#x60; file
1114
- if (addonTemplatesTreeInAddonTree &amp;&amp; file.indexOf(addonTemplatesRelativeToAddonPath) === 0) {
1115
- return false;
1116
- }
1117
-
1118
- return podTemplateMatcher.test(file);
1119
- });
1120
-
1121
- let jsMatcher = new RegExp(&#x60;(${jsExtensions.join(&#x27;|&#x27;)})$&#x60;);
1122
- let hasJSFiles = files.some((file) =&gt; jsMatcher.test(file));
1123
-
1124
- if (!addonTemplatesTreeInAddonTree) {
1125
- files = files.concat(this._getAddonTemplatesTreeFiles());
1126
- }
1127
-
1128
- let extensionMatcher = new RegExp(&#x60;(${templateExtensions.join(&#x27;|&#x27;)})$&#x60;);
1129
- let hasTemplates = files.some((file) =&gt; extensionMatcher.test(file));
1130
-
1131
- this._cachedFileSystemInfo = {
1132
- hasJSFiles,
1133
- hasTemplates,
1134
- hasPodTemplates,
1135
- };
1136
-
1137
- return this._cachedFileSystemInfo;
1138
- },
1139
-
1140
- _getAddonTreeFiles() {
1141
- let addonTreePath = this._treePathFor(&#x27;addon&#x27;);
1142
-
1143
- if (fs.existsSync(addonTreePath)) {
1144
- return walkSync(addonTreePath);
1145
- }
1146
-
1147
- return [];
1148
- },
1149
-
1150
- _getAddonTemplatesTreeFiles() {
1151
- let addonTemplatesTreePath = this._treePathFor(&#x27;addon-templates&#x27;);
1152
-
1153
- if (fs.existsSync(addonTemplatesTreePath)) {
1154
- return walkSync(addonTemplatesTreePath);
1155
- }
1156
-
1157
- return [];
1158
- },
1159
-
1160
- _addonTemplateFiles(addonTree) {
1161
- if (this._cachedAddonTemplateFiles) {
1162
- return this._cachedAddonTemplateFiles;
1163
- }
1164
-
1165
- let trees = [];
1166
- let addonTemplates = this._treeFor(&#x27;addon-templates&#x27;);
1167
- let standardTemplates;
1168
-
1169
- if (addonTemplates) {
1170
- standardTemplates = new Funnel(addonTemplates, {
1171
- srcDir: &#x27;/&#x27;,
1172
- destDir: &#x60;${this.moduleName()}/templates&#x60;,
1173
- annotation: &#x60;Addon#_addonTemplateFiles (${this.name})&#x60;,
1174
- });
1175
-
1176
- trees.push(standardTemplates);
1177
- }
1178
-
1179
- if (this._shouldCompilePodTemplates()) {
1180
- let includePatterns = this.registry
1181
- .extensionsForType(&#x27;template&#x27;)
1182
- .map((extension) =&gt; &#x60;**/*/template.${extension}&#x60;);
1183
-
1184
- let podTemplates = new Funnel(addonTree, {
1185
- include: includePatterns,
1186
- destDir: &#x60;${this.moduleName()}/&#x60;,
1187
- annotation: &#x27;Funnel: Addon Pod Templates&#x27;,
1188
- });
1189
-
1190
- trees.push(podTemplates);
1191
- }
1192
-
1193
- this._cachedAddonTemplateFiles = mergeTrees(trees, {
1194
- annotation: &#x60;TreeMerge (${this.name} templates)&#x60;,
1195
- });
1196
-
1197
- return this._cachedAddonTemplateFiles;
1198
- },
1199
-
1200
- /**
1201
- Runs the templates tree through preprocessors.
1202
-
1203
- @private
1204
- @method compileTemplates
1205
- @param {Tree} tree Templates file tree
1206
- @return {Tree} Compiled templates tree
1207
- */
1208
- compileTemplates(addonTree) {
1209
- if (this.shouldCompileTemplates()) {
1210
- if (!registryHasPreprocessor(this.registry, &#x27;template&#x27;)) {
1211
- throw new SilentError(
1212
- &#x60;Addon templates were detected, but there are no template compilers registered for \&#x60;${this.name}\&#x60;. &#x60; +
1213
- &#x60;Please make sure your template precompiler (commonly \&#x60;ember-cli-htmlbars\&#x60;) is listed in \&#x60;dependencies\&#x60; &#x60; +
1214
- &#x60;(NOT \&#x60;devDependencies\&#x60;) in \&#x60;${this.name}\&#x60;&#x27;s \&#x60;package.json\&#x60;.&#x60;
1215
- );
1216
- }
1217
-
1218
- let preprocessedTemplateTree = this._addonPreprocessTree(&#x27;template&#x27;, addonTree);
1219
-
1220
- let processedTemplateTree = preprocessTemplates(preprocessedTemplateTree, {
1221
- annotation: &#x60;compileTemplates(${this.name})&#x60;,
1222
- registry: this.registry,
1223
- treeType: &#x27;addon-templates&#x27;,
1224
- });
1225
-
1226
- let postprocessedTemplateTree = this._addonPostprocessTree(&#x27;template&#x27;, processedTemplateTree);
1227
-
1228
- return postprocessedTemplateTree;
1229
- } else {
1230
- return addonTree;
1231
- }
1232
- },
1233
-
1234
- /**
1235
- Runs the addon tree through preprocessors.
1236
-
1237
- @private
1238
- @method compileAddon
1239
- @param {Tree} tree Addon file tree
1240
- @return {Tree} Compiled addon tree
1241
- */
1242
- compileAddon(tree) {
1243
- if (!this.options) {
1244
- this._warn(
1245
- &#x60;Ember CLI addons manage their own module transpilation during the \&#x60;treeForAddon\&#x60; processing. &#x60; +
1246
- &#x60;\&#x60;${this.name}\&#x60; (found at \&#x60;${this.root}\&#x60;) has removed \&#x60;this.options\&#x60; &#x60; +
1247
- &#x60;which conflicts with the addons ability to transpile its \&#x60;addon/\&#x60; files properly. &#x60; +
1248
- &#x60;Falling back to default babel configuration options.&#x60;
1249
- );
1250
-
1251
- this.options = {};
1252
- }
1253
-
1254
- if (!this.options.babel) {
1255
- this._warn(
1256
- &#x60;Ember CLI addons manage their own module transpilation during the \&#x60;treeForAddon\&#x60; processing. &#x60; +
1257
- &#x60;\&#x60;${this.name}\&#x60; (found at \&#x60;${this.root}\&#x60;) has overridden the \&#x60;this.options.babel\&#x60; &#x60; +
1258
- &#x60;options which conflicts with the addons ability to transpile its \&#x60;addon/\&#x60; files properly. &#x60; +
1259
- &#x60;Falling back to default babel configuration options.&#x60;
1260
- );
1261
-
1262
- this.options.babel = this.__originalOptions.babel;
1263
- }
1264
-
1265
- let emberCLIBabelConfigKey = this._emberCLIBabelConfigKey();
1266
- if (!this.options[emberCLIBabelConfigKey]) {
1267
- this._warn(
1268
- &#x60;Ember CLI addons manage their own module transpilation during the \&#x60;treeForAddon\&#x60; processing. &#x60; +
1269
- &#x60;\&#x60;${this.name}\&#x60; (found at \&#x60;${this.root}\&#x60;) has overridden the \&#x60;this.options.${emberCLIBabelConfigKey}\&#x60; &#x60; +
1270
- &#x60;options which conflicts with the addons ability to transpile its \&#x60;addon/\&#x60; files properly. &#x60; +
1271
- &#x60;Falling back to default babel configuration options.&#x60;
1272
- );
1273
-
1274
- this.options[emberCLIBabelConfigKey] = this.__originalOptions[emberCLIBabelConfigKey];
1275
- }
1276
-
1277
- let scopedInput = new Funnel(tree, {
1278
- destDir: this.moduleName(),
1279
- annotation: &#x60;Funnel: ${this.name}/addon&#x60;,
1280
- });
1281
-
1282
- let treeWithCompiledTemplates = this.compileTemplates(scopedInput);
1283
- let final = this.processedAddonJsFiles(treeWithCompiledTemplates);
1284
-
1285
- return final;
1286
- },
1287
-
1288
- /**
1289
- Returns a tree with JSHint output for all addon JS.
1290
-
1291
- @private
1292
- @method jshintAddonTree
1293
- @return {Tree} Tree with JShint output (tests)
1294
- */
1295
- jshintAddonTree() {
1296
- let trees = [];
1297
-
1298
- let addonPath = this._treePathFor(&#x27;addon&#x27;);
1299
- if (fs.existsSync(addonPath)) {
1300
- let addonJs = new Funnel(addonPath, {
1301
- exclude: [&#x27;templates/**/*&#x27;],
1302
- destDir: &#x27;addon&#x27;,
1303
- allowEmpty: true,
1304
- });
1305
- let lintAddonJsTrees = this._eachProjectAddonInvoke(&#x27;lintTree&#x27;, [&#x27;addon&#x27;, addonJs]);
1306
-
1307
- let addonTemplates = new Funnel(this._addonTemplateFiles(addonPath), {
1308
- srcDir: &#x60;${this.moduleName()}/templates&#x60;,
1309
- destDir: &#x27;addon/templates&#x27;,
1310
- allowEmpty: true,
1311
- });
1312
- let lintTemplateTrees = this._eachProjectAddonInvoke(&#x27;lintTree&#x27;, [&#x27;templates&#x27;, addonTemplates]);
1313
-
1314
- trees = trees.concat(lintAddonJsTrees, lintTemplateTrees);
1315
- }
1316
-
1317
- let addonTestSupportPath = this._treePathFor(&#x27;addon-test-support&#x27;);
1318
- if (fs.existsSync(addonTestSupportPath)) {
1319
- let addonTestSupportTree = new Funnel(addonTestSupportPath, { destDir: &#x27;addon-test-support&#x27; });
1320
- let lintAddonTestSupportJsTrees = this._eachProjectAddonInvoke(&#x27;lintTree&#x27;, [
1321
- &#x27;addon-test-support&#x27;,
1322
- addonTestSupportTree,
1323
- ]);
1324
- trees = trees.concat(lintAddonTestSupportJsTrees);
1325
- }
1326
-
1327
- let appPath = this._treePathFor(&#x27;app&#x27;);
1328
- if (fs.existsSync(appPath)) {
1329
- let appTree = new Funnel(appPath, { destDir: &#x27;app&#x27; });
1330
- let lintAppJsTrees = this._eachProjectAddonInvoke(&#x27;lintTree&#x27;, [&#x27;app&#x27;, appTree]);
1331
- trees = trees.concat(lintAppJsTrees);
1332
- }
1333
-
1334
- let testSupportPath = this._treePathFor(&#x27;test-support&#x27;);
1335
- if (fs.existsSync(testSupportPath)) {
1336
- let testSupportTree = new Funnel(testSupportPath, { destDir: &#x27;test-support&#x27; });
1337
- let lintTestSupportJsTrees = this._eachProjectAddonInvoke(&#x27;lintTree&#x27;, [&#x27;test-support&#x27;, testSupportTree]);
1338
- trees = trees.concat(lintTestSupportJsTrees);
1339
- }
1340
-
1341
- let lintTrees = trees.filter(Boolean);
1342
- let lintedAddon = mergeTrees(lintTrees, {
1343
- overwrite: true,
1344
- annotation: &#x27;TreeMerger (addon-lint)&#x27;,
1345
- });
1346
-
1347
- return new Funnel(lintedAddon, {
1348
- srcDir: &#x27;/&#x27;,
1349
- destDir: &#x60;${this.name}/tests/&#x60;,
1350
- annotation: &#x60;Funnel: Addon#jshintAddonTree(${this.name})&#x60;,
1351
- });
1352
- },
1353
-
1354
- /**
1355
- Returns a tree containing the addon&#x27;s js files
1356
-
1357
- @private
1358
- @deprecated
1359
- @method addonJsFiles
1360
- @return {Tree} The filtered addon js files
1361
- */
1362
- addonJsFiles(tree) {
1363
- this._warn(&#x60;Addon.prototype.addonJsFiles is deprecated&#x60;);
1364
-
1365
- return new Funnel(tree, {
1366
- destDir: this.moduleName(),
1367
- annotation: &#x27;Funnel: Addon JS&#x27;,
1368
- });
1369
- },
1370
-
1371
- /**
1372
- Preprocesses a javascript tree.
1373
-
1374
- @private
1375
- @method preprocessJs
1376
- @return {Tree} Preprocessed javascript
1377
- */
1378
- preprocessJs() {
1379
- return preprocessJs.apply(preprocessJs, arguments);
1380
- },
1381
-
1382
- /**
1383
- Returns a tree with all javascript for this addon.
1384
-
1385
- @private
1386
- @method processedAddonJsFiles
1387
- @param {Tree} the tree to preprocess
1388
- @return {Tree} Processed javascript file tree
1389
- */
1390
- processedAddonJsFiles(inputTree) {
1391
- let preprocessedAddonJS = this._addonPreprocessTree(&#x27;js&#x27;, inputTree);
1392
-
1393
- let processedAddonJS = this.preprocessJs(preprocessedAddonJS, &#x27;/&#x27;, this.name, {
1394
- annotation: &#x60;processedAddonJsFiles(${this.name})&#x60;,
1395
- registry: this.registry,
1396
- treeType: &#x27;addon&#x27;,
1397
- });
1398
-
1399
- let postprocessedAddonJs = this._addonPostprocessTree(&#x27;js&#x27;, processedAddonJS);
1400
-
1401
- if (!registryHasPreprocessor(this.registry, &#x27;js&#x27;)) {
1402
- this._warn(
1403
- &#x60;Addon files were detected in \&#x60;${this._treePathFor(&#x27;addon&#x27;)}\&#x60;, but no JavaScript &#x60; +
1404
- &#x60;preprocessors were found for \&#x60;${this.name}\&#x60;. Please make sure to add a preprocessor &#x60; +
1405
- &#x27;(most likely &#x60;ember-cli-babel&#x60;) to in &#x60;dependencies&#x60; (NOT &#x60;devDependencies&#x60;) in &#x27; +
1406
- &#x60;\&#x60;${this.name}\&#x60;&#x27;s \&#x60;package.json\&#x60;.&#x60;
1407
- );
1408
-
1409
- postprocessedAddonJs = processModulesOnly(
1410
- postprocessedAddonJs,
1411
- &#x60;Babel Fallback - Addon#processedAddonJsFiles(${this.name})&#x60;
1412
- );
1413
- }
1414
-
1415
- return postprocessedAddonJs;
1416
- },
1417
-
1418
- /**
1419
- Returns the module name for this addon.
1420
-
1421
- @public
1422
- @method moduleName
1423
- @return {String} module name
1424
- */
1425
- moduleName() {
1426
- if (!this.modulePrefix) {
1427
- this.modulePrefix = this.name.toLowerCase().replace(/\s/g, &#x27;-&#x27;);
1428
- }
1429
-
1430
- return this.modulePrefix;
1431
- },
1432
-
1433
- /**
1434
- Returns the path for addon blueprints.
1435
-
1436
- @public
1437
- @method blueprintsPath
1438
- @return {String} The path for blueprints
1439
-
1440
- @example
1441
- - [ember-cli-coffeescript](https://github.com/kimroen/ember-cli-coffeescript/blob/v1.13.2/index.js#L26)
1442
- */
1443
- blueprintsPath() {
1444
- let blueprintPath = path.join(this.root, &#x27;blueprints&#x27;);
1445
-
1446
- if (fs.existsSync(blueprintPath)) {
1447
- return blueprintPath;
1448
- }
1449
- },
1450
-
1451
- /**
1452
- Augments the application&#x27;s configuration settings.
1453
-
1454
- Object returned from this hook is merged with the application&#x27;s configuration object.
1455
-
1456
- Application&#x27;s configuration always take precedence.
1457
-
1458
- #### Uses:
1459
-
1460
- - Modifying configuration options (see list of defaults [here](https://github.com/ember-cli/ember-cli/blob/v2.4.3/lib/broccoli/ember-app.js#L163))
1461
- - For example
1462
- - &#x60;minifyJS&#x60;
1463
- - &#x60;storeConfigInMeta&#x60;
1464
- - et, al
1465
-
1466
- @public
1467
- @method config
1468
- @param {String} env Name of current environment (ie &quot;development&quot;)
1469
- @param {Object} baseConfig Initial application configuration
1470
- @return {Object} Configuration object to be merged with application configuration.
1471
-
1472
- @example
1473
- &#x60;&#x60;&#x60;js
1474
- config(environment, appConfig) {
1475
- return {
1476
- someAddonDefault: &quot;foo&quot;
1477
- };
1478
- }
1479
- &#x60;&#x60;&#x60;
1480
- */
1481
- config(env, baseConfig) {
1482
- let configPath = path.join(this.root, &#x27;config&#x27;, &#x27;environment.js&#x27;);
1483
-
1484
- if (fs.existsSync(configPath)) {
1485
- const configGenerator = require(configPath);
1486
-
1487
- return configGenerator(env, baseConfig);
1488
- }
1489
- },
1490
-
1491
- /**
1492
- @public
1493
- @method dependencies
1494
- @return {Object} The addon&#x27;s dependencies based on the addon&#x27;s package.json
1495
- */
1496
- dependencies() {
1497
- let pkg = this.pkg;
1498
- return pkg ? Object.assign({}, pkg.devDependencies, pkg.dependencies) : {};
1499
- },
1500
-
1501
- /**
1502
- @public
1503
- @method isEnabled
1504
- @return {Boolean} Whether or not this addon is enabled
1505
- */
1506
- isEnabled() {
1507
- return true;
1508
- },
1509
-
1510
- /**
1511
- Can be used to exclude addons from being added as a child addon.
1512
-
1513
- #### Uses:
1514
-
1515
- - Abstract away multiple addons while only including one into the built assets
1516
-
1517
- @public
1518
- @method shouldIncludeChildAddon
1519
- @param {Addon} childAddon
1520
- @return {Boolean} Whether or not a child addon is supposed to be included
1521
-
1522
- @example
1523
- &#x60;&#x60;&#x60;js
1524
- shouldIncludeChildAddon(childAddon) {
1525
- if(childAddon.name === &#x27;ember-cli-some-legacy-select-component&#x27;) {
1526
- return this.options.legacyMode;
1527
- } else if(childAddon.name === &#x27;ember-cli-awesome-new-select-component&#x27;) {
1528
- return !this.options.legacyMode;
1529
- } else {
1530
- return this._super.shouldIncludeChildAddon.apply(this, arguments);
1531
- }
1532
- }
1533
- &#x60;&#x60;&#x60;
1534
- */
1535
- shouldIncludeChildAddon() {
1536
- return true;
1537
- },
1538
- };
1539
-
1540
- // Methods without default implementation
1541
-
1542
- /**
1543
- Allows the specification of custom addon commands.
1544
- Expects you to return an object whose key is the name of the command and value is the command instance..
1545
-
1546
- This function is not implemented by default
1547
-
1548
- #### Uses:
1549
-
1550
- - Include custom commands into consuming application
1551
-
1552
- @public
1553
- @method includedCommands
1554
- @return {Object} An object with included commands
1555
-
1556
- @example
1557
- &#x60;&#x60;&#x60;js
1558
- includedCommands() {
1559
- return {
1560
- &#x27;do-foo&#x27;: require(&#x27;./lib/commands/foo&#x27;)
1561
- };
1562
- }
1563
- &#x60;&#x60;&#x60;
1564
- */
1565
-
1566
- /**
1567
- Allows addons to define a custom transform function that other addons and app can use when using &#x60;app.import&#x60;.
1568
-
1569
- This function is not implemented by default
1570
-
1571
- #### Uses:
1572
-
1573
- - An app or addons want to transform a dependency that is being imported using &#x60;app.import&#x60;.
1574
-
1575
- @public
1576
- @method importTransforms
1577
- @return {Object} An object with custom transforms
1578
-
1579
- @example
1580
- &#x60;&#x60;&#x60;js
1581
- importTransforms() {
1582
- return {
1583
- &#x27;my-custom-transform&#x27;: function(tree, options) {
1584
- // transform the incoming tree and return the updated tree
1585
- }
1586
- };
1587
- }
1588
- &#x60;&#x60;&#x60;
1589
-
1590
- Alternatively, if you want to process &#x60;options&#x60; before being passed into the custom transform function, use:
1591
-
1592
- @example
1593
- &#x60;&#x60;&#x60;js
1594
- importTransforms() {
1595
- return {
1596
- &#x27;my-custom-transform&#x27;: {
1597
- transform: function(tree, options) {
1598
- // transform the incoming tree and return the updated tree
1599
- },
1600
- processOptions: function(assetPath, entry, options) {
1601
- // process your options
1602
-
1603
- return options
1604
- }
1605
- };
1606
- }
1607
- &#x60;&#x60;&#x60;
1608
- */
1609
-
1610
- /**
1611
- Pre-process a tree
1612
-
1613
- #### Uses:
1614
-
1615
- - removing / adding files from the build.
1616
-
1617
- @public
1618
- @method preprocessTree
1619
- @param {String} type What kind of tree (eg. &#x27;js&#x27;, &#x27;css&#x27;, &#x27;template&#x27;)
1620
- @param {Tree} tree Tree to process
1621
- @return {Tree} Processed tree
1622
- */
1623
-
1624
- /**
1625
- Post-process a tree
1626
-
1627
- @public
1628
- @method postprocessTree
1629
- @param {String} type What kind of tree (eg. &#x27;js&#x27;, &#x27;css&#x27;, &#x27;template&#x27;)
1630
- @param {Tree} tree Tree to process
1631
- @return {Tree} Processed tree
1632
-
1633
- @example
1634
- - [broccoli-asset-rev](https://github.com/rickharrison/broccoli-asset-rev/blob/c82c3580855554a31f7d6600b866aecf69cdaa6d/index.js#L29)
1635
- */
1636
-
1637
- /**
1638
- This hook allows you to make changes to the express server run by ember-cli.
1639
-
1640
- It&#x27;s passed a &#x60;startOptions&#x60; object which contains:
1641
- - &#x60;app&#x60; Express server instance
1642
- - &#x60;options&#x60; A hash with:
1643
- - &#x60;project&#x60; Current {{#crossLink &quot;Project&quot;}}project{{/crossLink}}
1644
- - &#x60;watcher&#x60;
1645
- - &#x60;environment&#x60;
1646
-
1647
- This function is not implemented by default
1648
-
1649
- #### Uses:
1650
-
1651
- - Tacking on headers to each request
1652
- - Modifying the request object
1653
-
1654
- *Note:* that this should only be used in development, and if you need the same behavior in production you&#x27;ll
1655
- need to configure your server.
1656
-
1657
- @public
1658
- @method serverMiddleware
1659
- @param {Object} startOptions Express server start options
1660
-
1661
- @example
1662
- &#x60;&#x60;&#x60;js
1663
- serverMiddleware(startOptions) {
1664
- var app = startOptions.app;
1665
-
1666
- app.use(function(req, res, next) {
1667
- // Some middleware
1668
- });
1669
- }
1670
- &#x60;&#x60;&#x60;
1671
-
1672
- - [ember-cli-content-security-policy](https://github.com/rwjblue/ember-cli-content-security-policy/blob/v0.5.0/index.js#L84)
1673
- - [history-support-addon](https://github.com/ember-cli/ember-cli/blob/v2.4.3/lib/tasks/server/middleware/history-support/index.js#L25)
1674
- */
1675
-
1676
- /**
1677
- This hook allows you to make changes to the express server run by testem.
1678
-
1679
- This function is not implemented by default
1680
-
1681
- #### Uses:
1682
-
1683
- - Adding custom test-specific endpoints
1684
- - Manipulating HTTP requests in tests
1685
-
1686
- @public
1687
- @method testemMiddleware
1688
- @param {Object} app the express app instance
1689
- */
1690
-
1691
- /**
1692
- This hook is called before a build takes place.
1693
-
1694
- @public
1695
- @method preBuild
1696
- @param {Object} result Build object
1697
- */
1698
-
1699
- /**
1700
- This hook is called after a build is complete.
1701
-
1702
- It&#x27;s passed a &#x60;result&#x60; object which contains:
1703
- - &#x60;directory&#x60; Path to build output
1704
-
1705
- #### Uses:
1706
-
1707
- - Slow tree listing
1708
- - May be used to manipulate your project after build has happened
1709
-
1710
- @public
1711
- @method postBuild
1712
- @param {Object} result Build result object
1713
- */
1714
-
1715
- /**
1716
- This hook is called after the build has been processed and the build files have been copied to the output directory
1717
-
1718
- It&#x27;s passed a &#x60;result&#x60; object which contains:
1719
- - &#x60;directory&#x60; Path to build output
1720
-
1721
- @public
1722
- @method outputReady
1723
- @param {Object} result Build result object
1724
-
1725
- @example
1726
- - Opportunity to symlink or copy files elsewhere.
1727
- - [ember-cli-rails-addon](https://github.com/rondale-sc/ember-cli-rails-addon/blob/v0.7.0/index.js#L45)
1728
- - In this case we are using this in tandem with a rails middleware to remove a lock file.
1729
- This allows our ruby gem to block incoming requests until after the build happens reliably.
1730
- */
1731
-
1732
- /**
1733
- This hook is called when an error occurs during the preBuild, postBuild or outputReady hooks
1734
- for addons, or when the build fails
1735
-
1736
- #### Uses:
1737
-
1738
- - Custom error handling during build process
1739
-
1740
- @public
1741
- @method buildError
1742
- @param {Error} error The error that was caught during the processes listed above
1743
-
1744
- @example
1745
- - [ember-cli-rails-addon](https://github.com/rondale-sc/ember-cli-rails-addon/blob/v0.7.0/index.js#L11)
1746
- */
1747
-
1748
- /**
1749
- Used to add preprocessors to the preprocessor registry. This is often used by addons like [ember-cli-htmlbars](https://github.com/ember-cli/ember-cli-htmlbars)
1750
- and [ember-cli-coffeescript](https://github.com/kimroen/ember-cli-coffeescript) to add a &#x60;template&#x60; or &#x60;js&#x60; preprocessor to the registry.
1751
-
1752
- **Uses:**
1753
-
1754
- - Adding preprocessors to the registry.
1755
-
1756
- @public
1757
- @method setupPreprocessorRegistry
1758
- @param {String} type either &#x60;&quot;self&quot;&#x60; or &#x60;&quot;parent&quot;&#x60;
1759
- @param registry the registry to be set up
1760
-
1761
- @example
1762
- &#x60;&#x60;&#x60;js
1763
- setupPreprocessorRegistry(type, registry) {
1764
- // ensure that broccoli-ember-hbs-template-compiler is not processing hbs files
1765
- registry.remove(&#x27;template&#x27;, &#x27;broccoli-ember-hbs-template-compiler&#x27;);
1766
-
1767
- registry.add(&#x27;template&#x27;, {
1768
- name: &#x27;ember-cli-htmlbars&#x27;,
1769
- ext: &#x27;hbs&#x27;,
1770
- _addon: this,
1771
- toTree(tree) {
1772
- var htmlbarsOptions = this._addon.htmlbarsOptions();
1773
- return htmlbarsCompile(tree, htmlbarsOptions);
1774
- },
1775
-
1776
- precompile(string) {
1777
- var htmlbarsOptions = this._addon.htmlbarsOptions();
1778
- var templateCompiler = htmlbarsOptions.templateCompiler;
1779
- return utils.template(templateCompiler, string);
1780
- }
1781
- });
1782
-
1783
- if (type === &#x27;parent&#x27;) {
1784
- this.parentRegistry = registry;
1785
- }
1786
- }
1787
- &#x60;&#x60;&#x60;
1788
- */
1789
-
1790
- /**
1791
- Return value is merged into the **tests** tree. This lets you inject
1792
- linter output as test results.
1793
-
1794
- **Uses:**
1795
-
1796
- - JSHint
1797
- - any other form of automated test generation that turns code into tests
1798
-
1799
- @public
1800
- @method lintTree
1801
- @param {String} treeType &#x60;app&#x60;, &#x60;tests&#x60;, &#x60;templates&#x60;, or &#x60;addon&#x60;
1802
- @param {Tree} tree tree of files (JavaScript files for &#x60;app&#x60;, &#x60;tests&#x60;, and &#x60;addon&#x60; types)
1803
-
1804
- @example
1805
- - [ember-cli-qunit](https://github.com/ember-cli/ember-cli-qunit/blob/v1.4.1/index.js#L206)
1806
- - [ember-cli-mocha](https://github.com/ef4/ember-cli-mocha/blob/66803037fe203b24e96dea83a2bd91de48b842e1/index.js#L101)
1807
- */
1808
-
1809
- /**
1810
- Allow addons to implement contentFor method to add string output into the associated &#x60;{{content-for &#x27;foo&#x27;}}&#x60; section in &#x60;index.html&#x60;
1811
-
1812
- **Uses:**
1813
-
1814
- - For instance, to inject analytics code into &#x60;index.html&#x60;
1815
-
1816
- @public
1817
- @method contentFor
1818
- @param type
1819
- @param config
1820
- @param content
1821
-
1822
- @example
1823
- - [ember-cli-google-analytics](https://github.com/pgrippi/ember-cli-google-analytics/blob/v1.5.0/index.js#L79)
1824
- */
1825
-
1826
- function methodsForTreeType(treeType) {
1827
- let treeMethods = DEFAULT_TREE_FOR_METHOD_METHODS[treeType];
1828
-
1829
- return GLOBAL_TREE_FOR_METHOD_METHODS.concat(treeMethods);
1830
- }
1831
-
1832
- let Addon = CoreObject.extend(addonProto);
1833
-
1834
- Addon.prototype[BUILD_BABEL_OPTIONS_FOR_PREPROCESSORS] = function () {
1835
- let emberCLIBabelInstance = findAddonByName(this.addons, &#x27;ember-cli-babel&#x27;);
1836
- let version;
1837
- if (emberCLIBabelInstance) {
1838
- version = require(path.join(emberCLIBabelInstance.root, &#x27;package&#x27;)).version;
1839
- }
1840
-
1841
- if (version &amp;&amp; semver.satisfies(version, &#x27;^5&#x27;)) {
1842
- return {
1843
- modules: &#x27;amdStrict&#x27;,
1844
- moduleIds: true,
1845
- resolveModuleSource: require(&#x27;amd-name-resolver&#x27;).moduleResolve,
1846
- };
1847
- } else {
1848
- return {};
1849
- }
1850
- };
1851
-
1852
- module.exports = Addon;
1853
- module.exports._resetTreeCache = _resetTreeCache;
1854
- module.exports._treeCache = ADDON_TREE_CACHE;
1855
-
1856
- </pre>
1857
-
1858
- </div>
1859
- </div>
1860
- </div>
1861
- </div>
1862
- <script src="../assets/vendor/prettify/prettify-min.js"></script>
1863
- <script>prettyPrint();</script>
1864
- <script src="../assets/js/yui-prettify.js"></script>
1865
- </body>
1866
- </html>