ember-cli 4.0.0-beta.4 → 4.1.0

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 (118) hide show
  1. package/.github/workflows/ci.yml +4 -4
  2. package/CHANGELOG.md +28 -17
  3. package/bin/ember +0 -0
  4. package/blueprints/addon/additional-dev-dependencies.json +1 -1
  5. package/blueprints/addon/files/.github/workflows/ci.yml +5 -1
  6. package/blueprints/addon/files/.travis.yml +1 -1
  7. package/blueprints/addon/files/README.md +2 -2
  8. package/blueprints/addon/files/addon-config/ember-try.js +4 -4
  9. package/blueprints/app/files/.github/workflows/ci.yml +4 -0
  10. package/blueprints/app/files/package.json +8 -8
  11. package/blueprints/in-repo-addon/files/__root__/__name__/index.js +0 -0
  12. package/blueprints/in-repo-addon/index.js +0 -0
  13. package/blueprints/lib/index.js +0 -0
  14. package/docs/build/data.json +413 -413
  15. package/lib/models/host-info-cache.js +3 -5
  16. package/lib/models/per-bundle-addon-cache/index.js +2 -3
  17. package/lib/tasks/npm-task.js +1 -1
  18. package/lib/utilities/get-lang-arg.js +45 -45
  19. package/package.json +25 -25
  20. package/.github/ISSUE_TEMPLATE.md +0 -12
  21. package/.github/dependabot.yml +0 -15
  22. package/.github/workflows/coverage.yml +0 -31
  23. package/docs/analytics.md +0 -44
  24. package/docs/architecture.md +0 -316
  25. package/docs/assets/architecture/Ember-CLI architecture.png +0 -0
  26. package/docs/assets/architecture/Ember-CLI architecture.xml +0 -1
  27. package/docs/assets/architecture/README.md +0 -5
  28. package/docs/brocfile-transition.md +0 -46
  29. package/docs/build/api.js +0 -44
  30. package/docs/build/assets/css/external-small.png +0 -0
  31. package/docs/build/assets/css/logo.png +0 -0
  32. package/docs/build/assets/css/main.css +0 -555
  33. package/docs/build/assets/favicon.ico +0 -0
  34. package/docs/build/assets/img/spinner.gif +0 -0
  35. package/docs/build/assets/index.html +0 -10
  36. package/docs/build/assets/js/api-filter.js +0 -56
  37. package/docs/build/assets/js/api-list.js +0 -255
  38. package/docs/build/assets/js/api-search.js +0 -98
  39. package/docs/build/assets/js/apidocs.js +0 -376
  40. package/docs/build/assets/js/yui-prettify.js +0 -17
  41. package/docs/build/assets/vendor/prettify/CHANGES.html +0 -130
  42. package/docs/build/assets/vendor/prettify/COPYING +0 -202
  43. package/docs/build/assets/vendor/prettify/README.html +0 -203
  44. package/docs/build/assets/vendor/prettify/prettify-min.css +0 -1
  45. package/docs/build/assets/vendor/prettify/prettify-min.js +0 -1
  46. package/docs/build/classes/Addon.html +0 -4318
  47. package/docs/build/classes/AmdTransformAddon.html +0 -202
  48. package/docs/build/classes/Blueprint.html +0 -4796
  49. package/docs/build/classes/Builder.html +0 -611
  50. package/docs/build/classes/CLI.html +0 -810
  51. package/docs/build/classes/Command.html +0 -1655
  52. package/docs/build/classes/DefaultPackager.html +0 -202
  53. package/docs/build/classes/EmberAddon.html +0 -2207
  54. package/docs/build/classes/EmberApp.html +0 -2225
  55. package/docs/build/classes/HardwareInfo.html +0 -620
  56. package/docs/build/classes/HistorySupportAddon.html +0 -203
  57. package/docs/build/classes/Instrumentation.html +0 -695
  58. package/docs/build/classes/NodeModulesList.html +0 -460
  59. package/docs/build/classes/NpmTask.html +0 -333
  60. package/docs/build/classes/PackageInfo.html +0 -1390
  61. package/docs/build/classes/PackageInfoCache.html +0 -963
  62. package/docs/build/classes/PerBundleAddonCache {.html +0 -1010
  63. package/docs/build/classes/Project.html +0 -2083
  64. package/docs/build/classes/ServeFilesAddon.html +0 -260
  65. package/docs/build/classes/TestsServerAddon.html +0 -203
  66. package/docs/build/classes/WatcherAddon.html +0 -204
  67. package/docs/build/classes/WindowsSymlinkChecker.html +0 -1505
  68. package/docs/build/files/lib_broccoli_default-packager.js.html +0 -1426
  69. package/docs/build/files/lib_broccoli_ember-addon.js.html +0 -159
  70. package/docs/build/files/lib_broccoli_ember-app.js.html +0 -1913
  71. package/docs/build/files/lib_cli_cli.js.html +0 -417
  72. package/docs/build/files/lib_models_addon-info.js.html +0 -112
  73. package/docs/build/files/lib_models_addon.js.html +0 -1866
  74. package/docs/build/files/lib_models_blueprint.js.html +0 -1678
  75. package/docs/build/files/lib_models_builder.js.html +0 -417
  76. package/docs/build/files/lib_models_command.js.html +0 -804
  77. package/docs/build/files/lib_models_hardware-info.js.html +0 -479
  78. package/docs/build/files/lib_models_host-info-cache.js.html +0 -428
  79. package/docs/build/files/lib_models_installation-checker.js.html +0 -181
  80. package/docs/build/files/lib_models_instantiate-addons.js.html +0 -191
  81. package/docs/build/files/lib_models_instrumentation.js.html +0 -433
  82. package/docs/build/files/lib_models_package-info-cache_index.js.html +0 -793
  83. package/docs/build/files/lib_models_package-info-cache_node-modules-list.js.html +0 -208
  84. package/docs/build/files/lib_models_package-info-cache_package-info.js.html +0 -661
  85. package/docs/build/files/lib_models_per-bundle-addon-cache_addon-proxy.js.html +0 -252
  86. package/docs/build/files/lib_models_per-bundle-addon-cache_index.js.html +0 -485
  87. package/docs/build/files/lib_models_per-bundle-addon-cache_target-instance.js.html +0 -108
  88. package/docs/build/files/lib_models_project.js.html +0 -913
  89. package/docs/build/files/lib_models_task.js.html +0 -117
  90. package/docs/build/files/lib_tasks_build-watch.js.html +0 -157
  91. package/docs/build/files/lib_tasks_npm-task.js.html +0 -463
  92. package/docs/build/files/lib_tasks_serve.js.html +0 -207
  93. package/docs/build/files/lib_tasks_server_middleware_broccoli-serve-files_index.js.html +0 -127
  94. package/docs/build/files/lib_tasks_server_middleware_broccoli-watcher_index.js.html +0 -158
  95. package/docs/build/files/lib_tasks_server_middleware_history-support_index.js.html +0 -181
  96. package/docs/build/files/lib_tasks_server_middleware_tests-server_index.js.html +0 -171
  97. package/docs/build/files/lib_tasks_test-server.js.html +0 -167
  98. package/docs/build/files/lib_tasks_transforms_amd_index.js.html +0 -143
  99. package/docs/build/files/lib_utilities_ember-app-utils.js.html +0 -292
  100. package/docs/build/files/lib_utilities_insert-into-file.js.html +0 -219
  101. package/docs/build/files/lib_utilities_is-lazy-engine.js.html +0 -125
  102. package/docs/build/files/lib_utilities_is-yarn-project.js.html +0 -120
  103. package/docs/build/files/lib_utilities_valid-project-name.js.html +0 -142
  104. package/docs/build/files/lib_utilities_will-interrupt-process.js.html +0 -290
  105. package/docs/build/files/lib_utilities_windows-admin.js.html +0 -230
  106. package/docs/build/index.html +0 -125
  107. package/docs/build/modules/ember-cli.html +0 -152
  108. package/docs/build/modules/is-lazy-engine.html +0 -106
  109. package/docs/build-concurrency.md +0 -15
  110. package/docs/build-pipeline-debugging.md +0 -33
  111. package/docs/code-coverage.md +0 -14
  112. package/docs/error-propagation.md +0 -136
  113. package/docs/experiments.md +0 -53
  114. package/docs/node-support.md +0 -43
  115. package/docs/perf-guide.md +0 -250
  116. package/docs/project_version_preprocessor.js +0 -8
  117. package/docs/sourcemaps.md +0 -60
  118. package/docs/yuidoc.json +0 -13
@@ -1,913 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>lib/models/project.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-beta.4-beta-724190cca6
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/project.js</h1>
80
- </div>
81
-
82
- <pre class="code prettyprint linenums">
83
- &#x27;use strict&#x27;;
84
-
85
- /**
86
- @module ember-cli
87
- */
88
- const util = require(&#x27;util&#x27;);
89
- const path = require(&#x27;path&#x27;);
90
- const findup = require(&#x27;find-up&#x27;);
91
- const resolve = util.promisify(require(&#x27;resolve&#x27;));
92
- const fs = require(&#x27;fs-extra&#x27;);
93
- const _ = require(&#x27;ember-cli-lodash-subset&#x27;);
94
- const logger = require(&#x27;heimdalljs-logger&#x27;)(&#x27;ember-cli:project&#x27;);
95
- const versionUtils = require(&#x27;../utilities/version-utils&#x27;);
96
- const emberCLIVersion = versionUtils.emberCLIVersion;
97
- const findAddonByName = require(&#x27;../utilities/find-addon-by-name&#x27;);
98
- const heimdall = require(&#x27;heimdalljs&#x27;);
99
- const PackageInfoCache = require(&#x27;./package-info-cache&#x27;);
100
- const PerBundleAddonCache = require(&#x27;./per-bundle-addon-cache&#x27;);
101
- const instantiateAddons = require(&#x27;./instantiate-addons&#x27;);
102
- const HostInfoCache = require(&#x27;./host-info-cache&#x27;);
103
-
104
- let processCwd = process.cwd();
105
-
106
- // ensure NULL_PROJECT is a singleton
107
- let NULL_PROJECT;
108
-
109
- class Project {
110
- /**
111
- The Project model is tied to your package.json. It is instantiated
112
- by giving {{#crossLink &quot;Project/closestSync:method&quot;}}{{/crossLink}}
113
- the path to your project.
114
-
115
- @class Project
116
- @constructor
117
- @param {String} root Root directory for the project
118
- @param {Object} pkg Contents of package.json
119
- @param {UI} ui
120
- @param {CLI} cli
121
- */
122
- constructor(root, pkg, ui, cli) {
123
- logger.info(&#x27;init root: %s&#x27;, root);
124
-
125
- this.root = root;
126
- this.pkg = pkg;
127
- this.ui = ui;
128
- this.cli = cli;
129
- this.addonPackages = Object.create(null);
130
- this.addons = [];
131
- this.liveReloadFilterPatterns = [];
132
- this.setupBowerDirectory();
133
- this.configCache = new Map();
134
- this.hostInfoCache = new HostInfoCache(this);
135
-
136
- /**
137
- Set when the &#x60;Watcher.detectWatchman&#x60; helper method finishes running,
138
- so that other areas of the system can be aware that watchman is being used.
139
-
140
- For example, this information is used in the broccoli build pipeline to know
141
- if we can watch additional directories (like bower_components) &quot;cheaply&quot;.
142
-
143
- Contains &#x60;enabled&#x60; and &#x60;version&#x60;.
144
-
145
- @private
146
- @property _watchmanInfo
147
- @return {Object}
148
- @default false
149
- */
150
- this._watchmanInfo = {
151
- enabled: false,
152
- version: null,
153
- canNestRoots: false,
154
- };
155
-
156
- let instrumentation = (this._instrumentation = ensureInstrumentation(cli, ui));
157
- instrumentation.project = this;
158
-
159
- this.emberCLIVersion = emberCLIVersion;
160
-
161
- this._nodeModulesPath = null;
162
-
163
- if (this.cli &amp;&amp; this.cli.packageInfoCache) {
164
- this.packageInfoCache = this.cli.packageInfoCache;
165
- } else {
166
- this.packageInfoCache = new PackageInfoCache(this.ui);
167
- }
168
-
169
- // we&#x27;re not dealing with NULL_PROJECT (note that it has not
170
- // be set yet, so we can&#x27;t compare to that var.)
171
- this._packageInfo = this.packageInfoCache.loadProject(this);
172
-
173
- // force us to use the real path as the root.
174
- this.root = this._packageInfo.realPath;
175
-
176
- // XXX Need to decide what to do here about showing errors. For
177
- // a non-CLI project the cache is local and probably should. For
178
- // a CLI project the cache is there, but not sure when we&#x27;ll know
179
- // about all the errors, because there may be multiple projects.
180
- if (this.packageInfoCache.hasErrors()) {
181
- this.packageInfoCache.showErrors();
182
- }
183
-
184
- if (PerBundleAddonCache.isEnabled()) {
185
- this.perBundleAddonCache = new PerBundleAddonCache(this);
186
- }
187
- }
188
-
189
- /**
190
- * Sets the name of the bower directory for this project
191
- *
192
- * @private
193
- * @method setupBowerDirectory
194
- */
195
- setupBowerDirectory() {
196
- let bowerrcPath = path.join(this.root, &#x27;.bowerrc&#x27;);
197
-
198
- logger.info(&#x27;bowerrc path: %s&#x27;, bowerrcPath);
199
-
200
- if (fs.existsSync(bowerrcPath)) {
201
- try {
202
- this.bowerDirectory = fs.readJsonSync(bowerrcPath).directory;
203
- } catch (exception) {
204
- logger.info(&#x27;failed to parse bowerc: %s&#x27;, exception);
205
- this.bowerDirectory = null;
206
- }
207
- }
208
-
209
- this.bowerDirectory = this.bowerDirectory || &#x27;bower_components&#x27;;
210
- logger.info(&#x27;bowerDirectory: %s&#x27;, this.bowerDirectory);
211
- }
212
-
213
- // Checks whether the project&#x27;s npm dependencies are
214
- // present. Previously this just looked for a node_modules folder in
215
- // a fixed place (which is not compatible with node&#x27;s module
216
- // resolution algorithm). Now we just sample to see if we can
217
- // resolve the first dependency or devDependency we find.
218
- hasDependencies() {
219
- if (this.cli.disableDependencyChecker) {
220
- // Blueprint tests set this flag.
221
- return true;
222
- }
223
-
224
- for (let depName in this.dependencies()) {
225
- try {
226
- this.resolveSync(&#x60;${depName}/package.json&#x60;);
227
- return true;
228
- } catch (err) {
229
- if (err.code !== &#x27;MODULE_NOT_FOUND&#x27;) {
230
- throw err;
231
- }
232
- return false;
233
- }
234
- }
235
- return false;
236
- }
237
-
238
- static nullProject(ui, cli) {
239
- if (NULL_PROJECT) {
240
- return NULL_PROJECT;
241
- }
242
-
243
- NULL_PROJECT = new Project(processCwd, {}, ui, cli);
244
-
245
- NULL_PROJECT.isEmberCLIProject = function () {
246
- return false;
247
- };
248
-
249
- NULL_PROJECT.isEmberCLIAddon = function () {
250
- return false;
251
- };
252
-
253
- NULL_PROJECT.name = function () {
254
- return path.basename(process.cwd());
255
- };
256
-
257
- NULL_PROJECT.initializeAddons();
258
-
259
- return NULL_PROJECT;
260
- }
261
-
262
- /**
263
- Returns the name from package.json.
264
-
265
- @private
266
- @method name
267
- @return {String} Package name
268
- */
269
- name() {
270
- const getPackageBaseName = require(&#x27;../utilities/get-package-base-name&#x27;);
271
-
272
- return getPackageBaseName(this.pkg.name);
273
- }
274
-
275
- /**
276
- Returns whether or not this is an Ember CLI project.
277
- This checks whether ember-cli is listed in devDependencies.
278
-
279
- @private
280
- @method isEmberCLIProject
281
- @return {Boolean} Whether this is an Ember CLI project
282
- */
283
- isEmberCLIProject() {
284
- return (this.cli ? this.cli.npmPackage : &#x27;ember-cli&#x27;) in this.dependencies();
285
- }
286
-
287
- /**
288
- Returns whether or not this is an Ember CLI addon.
289
-
290
- @method isEmberCLIAddon
291
- @return {Boolean} Whether or not this is an Ember CLI Addon.
292
- */
293
- isEmberCLIAddon() {
294
- return !!this.pkg &amp;&amp; !!this.pkg.keywords &amp;&amp; this.pkg.keywords.indexOf(&#x27;ember-addon&#x27;) &gt; -1;
295
- }
296
-
297
- /**
298
- Returns the path to the configuration.
299
-
300
- @private
301
- @method configPath
302
- @return {String} Configuration path
303
- */
304
- configPath() {
305
- let configPath = &#x27;config&#x27;;
306
-
307
- if (this.pkg[&#x27;ember-addon&#x27;] &amp;&amp; this.pkg[&#x27;ember-addon&#x27;][&#x27;configPath&#x27;]) {
308
- configPath = this.pkg[&#x27;ember-addon&#x27;][&#x27;configPath&#x27;];
309
- }
310
-
311
- return path.join(this.root, configPath, &#x27;environment&#x27;);
312
- }
313
-
314
- /**
315
- Loads the configuration for this project and its addons.
316
-
317
- @public
318
- @method config
319
- @param {String} env Environment name
320
- @return {Object} Merged configuration object
321
- */
322
- config(env) {
323
- let _env = env === undefined ? process.env.EMBER_ENV : env;
324
- let key = &#x60;${this.configPath()}|${_env}&#x60;;
325
- let config = this.configCache.get(key);
326
- if (config === undefined) {
327
- config = this.configWithoutCache(_env);
328
- this.configCache.set(key, config);
329
- }
330
- return _.cloneDeep(config);
331
- }
332
-
333
- /**
334
- * @private
335
- * @method configWithoutCache
336
- * @param {String} env Environment name
337
- * @return {Object} Merged configuration object
338
- */
339
- configWithoutCache(env) {
340
- let configPath = this.configPath();
341
-
342
- if (fs.existsSync(&#x60;${configPath}.js&#x60;)) {
343
- let appConfig = this.require(configPath)(env);
344
- let addonsConfig = this.getAddonsConfig(env, appConfig);
345
-
346
- return _.merge(addonsConfig, appConfig);
347
- } else {
348
- return this.getAddonsConfig(env, {});
349
- }
350
- }
351
-
352
- /**
353
- Returns the targets of this project, or the default targets if not present.
354
-
355
- @public
356
- @property targets
357
- @return {Object} Targets object
358
- */
359
- get targets() {
360
- if (this._targets) {
361
- return this._targets;
362
- }
363
- let configPath = &#x27;config&#x27;;
364
-
365
- if (this.pkg[&#x27;ember-addon&#x27;] &amp;&amp; this.pkg[&#x27;ember-addon&#x27;][&#x27;configPath&#x27;]) {
366
- configPath = this.pkg[&#x27;ember-addon&#x27;][&#x27;configPath&#x27;];
367
- }
368
-
369
- let targetsPath = path.join(this.root, configPath, &#x27;targets&#x27;);
370
-
371
- if (fs.existsSync(&#x60;${targetsPath}.js&#x60;)) {
372
- this._targets = this.require(targetsPath);
373
- } else {
374
- this._targets = require(&#x27;../utilities/default-targets&#x27;);
375
- }
376
- return this._targets;
377
- }
378
-
379
- /**
380
- Returns the addons configuration.
381
-
382
- @private
383
- @method getAddonsConfig
384
- @param {String} env Environment name
385
- @param {Object} appConfig Application configuration
386
- @return {Object} Merged configuration of all addons
387
- */
388
- getAddonsConfig(env, appConfig) {
389
- this.initializeAddons();
390
-
391
- let initialConfig = _.merge({}, appConfig);
392
-
393
- return this.addons.reduce((config, addon) =&gt; {
394
- if (addon.config) {
395
- _.merge(config, addon.config(env, config));
396
- }
397
-
398
- return config;
399
- }, initialConfig);
400
- }
401
-
402
- /**
403
- Returns whether or not the given file name is present in this project.
404
-
405
- @private
406
- @method has
407
- @param {String} file File name
408
- @return {Boolean} Whether or not the file is present
409
- */
410
- has(file) {
411
- return fs.existsSync(path.join(this.root, file)) || fs.existsSync(path.join(this.root, &#x60;${file}.js&#x60;));
412
- }
413
-
414
- /**
415
- Resolves the absolute path to a file synchronously
416
-
417
- @private
418
- @method resolveSync
419
- @param {String} file File to resolve
420
- @return {String} Absolute path to file
421
- */
422
- resolveSync(file) {
423
- return resolve.sync(file, {
424
- basedir: process.env.EMBER_NODE_PATH || this.root,
425
- });
426
- }
427
-
428
- /**
429
- Calls &#x60;require&#x60; on a given module from the context of the project. For
430
- instance, an addon may want to require a class from the root project&#x27;s
431
- version of ember-cli.
432
-
433
- @public
434
- @method require
435
- @param {String} file File path or module name
436
- @return {Object} Imported module
437
- */
438
- require(file) {
439
- let path = this.resolveSync(file);
440
- return require(path);
441
- }
442
-
443
- /**
444
- Returns the dependencies from a package.json
445
-
446
- @private
447
- @method dependencies
448
- @param {Object} [pkg=this.pkg] Package object
449
- @param {Boolean} [excludeDevDeps=false] Whether or not development dependencies should be excluded
450
- @return {Object} Dependencies
451
- */
452
- dependencies(pkg, excludeDevDeps) {
453
- pkg = pkg || this.pkg || {};
454
-
455
- let devDependencies = pkg[&#x27;devDependencies&#x27;];
456
- if (excludeDevDeps) {
457
- devDependencies = {};
458
- }
459
-
460
- return Object.assign({}, devDependencies, pkg[&#x27;dependencies&#x27;]);
461
- }
462
-
463
- /**
464
- Returns the bower dependencies for this project.
465
-
466
- @private
467
- @method bowerDependencies
468
- @param {String} bower Path to bower.json
469
- @return {Object} Bower dependencies
470
- */
471
- bowerDependencies(bower) {
472
- if (!bower) {
473
- let bowerPath = path.join(this.root, &#x27;bower.json&#x27;);
474
- bower = fs.existsSync(bowerPath) ? require(bowerPath) : {};
475
- }
476
- return Object.assign({}, bower[&#x27;devDependencies&#x27;], bower[&#x27;dependencies&#x27;]);
477
- }
478
-
479
- /**
480
- Provides the list of paths to consult for addons that may be provided
481
- internally to this project. Used for middleware addons with built-in support.
482
-
483
- @private
484
- @method supportedInternalAddonPaths
485
- */
486
- supportedInternalAddonPaths() {
487
- if (!this.root) {
488
- return [];
489
- }
490
-
491
- let internalMiddlewarePath = path.join(__dirname, &#x27;../tasks/server/middleware&#x27;);
492
- let internalTransformPath = path.join(__dirname, &#x27;../tasks/transforms&#x27;);
493
-
494
- return [
495
- path.join(internalMiddlewarePath, &#x27;testem-url-rewriter&#x27;),
496
- path.join(internalMiddlewarePath, &#x27;tests-server&#x27;),
497
- path.join(internalMiddlewarePath, &#x27;history-support&#x27;),
498
- path.join(internalMiddlewarePath, &#x27;broccoli-watcher&#x27;),
499
- path.join(internalMiddlewarePath, &#x27;broccoli-serve-files&#x27;),
500
- path.join(internalMiddlewarePath, &#x27;proxy-server&#x27;),
501
- path.join(internalTransformPath, &#x27;amd&#x27;),
502
- ];
503
- }
504
-
505
- /**
506
- * Discovers all addons for this project and stores their names and
507
- * package.json contents in this.addonPackages as key-value pairs.
508
- *
509
- * Any packageInfos that we find that are marked as not valid are excluded.
510
- *
511
- * @private
512
- * @method discoverAddons
513
- */
514
- discoverAddons() {
515
- if (this._didDiscoverAddons) {
516
- this._didDiscoverAddons = true;
517
- return;
518
- }
519
-
520
- let addonPackageList = this._packageInfo.discoverProjectAddons();
521
- this.addonPackages = this._packageInfo.generateAddonPackages(addonPackageList);
522
-
523
- // in case any child addons are invalid, dump to the console about them.
524
- this._packageInfo.dumpInvalidAddonPackages(addonPackageList);
525
- }
526
-
527
- /**
528
- Loads and initializes all addons for this project.
529
-
530
- @private
531
- @method initializeAddons
532
- */
533
- initializeAddons() {
534
- if (this._addonsInitialized) {
535
- return;
536
- }
537
- this._addonsInitialized = true;
538
-
539
- logger.info(&#x27;initializeAddons for: %s&#x27;, this.name());
540
-
541
- this.discoverAddons();
542
-
543
- this.addons = instantiateAddons(this, this, this.addonPackages);
544
- this.addons.forEach((addon) =&gt; logger.info(&#x27;addon: %s&#x27;, addon.name));
545
- }
546
-
547
- /**
548
- Returns what commands are made available by addons by inspecting
549
- &#x60;includedCommands&#x60; for every addon.
550
-
551
- @private
552
- @method addonCommands
553
- @return {Object} Addon names and command maps as key-value pairs
554
- */
555
- addonCommands() {
556
- const Command = require(&#x27;../models/command&#x27;);
557
- let commands = Object.create(null);
558
- this.addons.forEach((addon) =&gt; {
559
- if (!addon.includedCommands) {
560
- return;
561
- }
562
-
563
- let token = heimdall.start({
564
- name: &#x60;lookup-commands: ${addon.name}&#x60;,
565
- addonName: addon.name,
566
- addonCommandInitialization: true,
567
- });
568
-
569
- let includedCommands = addon.includedCommands();
570
- let addonCommands = Object.create(null);
571
-
572
- for (let key in includedCommands) {
573
- if (typeof includedCommands[key] === &#x27;function&#x27;) {
574
- addonCommands[key] = includedCommands[key];
575
- } else {
576
- addonCommands[key] = Command.extend(includedCommands[key]);
577
- }
578
- }
579
- if (Object.keys(addonCommands).length) {
580
- commands[addon.name] = addonCommands;
581
- }
582
-
583
- token.stop();
584
- });
585
- return commands;
586
- }
587
-
588
- /**
589
- Execute a given callback for every addon command.
590
- Example:
591
-
592
- &#x60;&#x60;&#x60;
593
- project.eachAddonCommand(function(addonName, commands) {
594
- console.log(&#x27;Addon &#x27; + addonName + &#x27; exported the following commands:&#x27; + commands.keys().join(&#x27;, &#x27;));
595
- });
596
- &#x60;&#x60;&#x60;
597
-
598
- @private
599
- @method eachAddonCommand
600
- @param {Function} callback [description]
601
- */
602
- eachAddonCommand(callback) {
603
- if (this.initializeAddons &amp;&amp; this.addonCommands) {
604
- this.initializeAddons();
605
- let addonCommands = this.addonCommands();
606
-
607
- _.forOwn(addonCommands, (commands, addonName) =&gt; callback(addonName, commands));
608
- }
609
- }
610
-
611
- /**
612
- Path to the blueprints for this project.
613
-
614
- @private
615
- @method localBlueprintLookupPath
616
- @return {String} Path to blueprints
617
- */
618
- localBlueprintLookupPath() {
619
- return path.join(this.root, &#x27;blueprints&#x27;);
620
- }
621
-
622
- /**
623
- Returns a list of paths (including addon paths) where blueprints will be looked up.
624
-
625
- @private
626
- @method blueprintLookupPaths
627
- @return {Array} List of paths
628
- */
629
- blueprintLookupPaths() {
630
- if (this.isEmberCLIProject()) {
631
- let lookupPaths = [this.localBlueprintLookupPath()];
632
- let addonLookupPaths = this.addonBlueprintLookupPaths();
633
-
634
- return lookupPaths.concat(addonLookupPaths);
635
- } else {
636
- return this.addonBlueprintLookupPaths();
637
- }
638
- }
639
-
640
- /**
641
- Returns a list of addon paths where blueprints will be looked up.
642
-
643
- @private
644
- @method addonBlueprintLookupPaths
645
- @return {Array} List of paths
646
- */
647
- addonBlueprintLookupPaths() {
648
- let addonPaths = this.addons
649
- .reduce((sum, addon) =&gt; {
650
- if (addon.blueprintsPath) {
651
- let val = addon.blueprintsPath();
652
- if (val) {
653
- sum.push(val);
654
- }
655
- }
656
- return sum;
657
- }, [])
658
- .reverse();
659
-
660
- return addonPaths;
661
- }
662
-
663
- /**
664
- Reloads package.json of the project. Clears and reloads the packageInfo and
665
- per-bundle addon cache, too.
666
-
667
- @private
668
- @method reloadPkg
669
- @return {Object} Package content
670
- */
671
- reloadPkg() {
672
- let pkgPath = path.join(this.root, &#x27;package.json&#x27;);
673
-
674
- // We use readFileSync instead of require to avoid the require cache.
675
- this.pkg = fs.readJsonSync(pkgPath);
676
-
677
- this.packageInfoCache.reloadProjects();
678
-
679
- // update &#x60;_packageInfo&#x60; after reloading projects from the &#x60;PackageInfoCache&#x60; instance
680
- // if we don&#x27;t do this we get into a state where &#x60;_packageInfo&#x60; is referencing the old
681
- // pkginfo object that hasn&#x27;t been updated/reloaded
682
- this._packageInfo = this.packageInfoCache.loadProject(this);
683
-
684
- if (PerBundleAddonCache.isEnabled()) {
685
- this.perBundleAddonCache = new PerBundleAddonCache(this);
686
- }
687
-
688
- return this.pkg;
689
- }
690
-
691
- /**
692
- Re-initializes addons.
693
-
694
- @private
695
- @method reloadAddons
696
- */
697
- reloadAddons() {
698
- this.reloadPkg();
699
- this._addonsInitialized = false;
700
- return this.initializeAddons();
701
- }
702
-
703
- /**
704
- Find an addon by its name
705
-
706
- @public
707
- @method findAddonByName
708
- @param {String} name Addon name as specified in package.json
709
- @return {Addon} Addon instance
710
- */
711
- findAddonByName(name) {
712
- this.initializeAddons();
713
-
714
- return findAddonByName(this.addons, name);
715
- }
716
-
717
- /**
718
- Generate test file contents.
719
-
720
- This method is supposed to be overwritten by test framework addons
721
- like &#x60;ember-qunit&#x60; and &#x60;ember-mocha&#x60;.
722
-
723
- @public
724
- @method generateTestFile
725
- @param {String} moduleName Name of the test module (e.g. &#x60;JSHint&#x60;)
726
- @param {Object[]} tests Array of tests with &#x60;name&#x60;, &#x60;passed&#x60; and &#x60;errorMessage&#x60; properties
727
- @return {String} The test file content
728
- */
729
- generateTestFile() {
730
- let message = &#x27;Please install an Ember.js test framework addon or update your dependencies.&#x27;;
731
-
732
- if (this.ui) {
733
- this.ui.writeDeprecateLine(message);
734
- } else {
735
- console.warn(message);
736
- }
737
-
738
- return &#x27;&#x27;;
739
- }
740
-
741
- /**
742
- Returns a new project based on the first &#x60;package.json&#x60; that is found
743
- in &#x60;pathName&#x60;.
744
-
745
- If the above &#x60;package.json&#x60; specifies &#x60;ember-addon.projectRoot&#x60;, we load
746
- the project based on the relative path between this directory and the
747
- specified &#x60;projectRoot&#x60;.
748
-
749
- @private
750
- @static
751
- @method closestSync
752
- @param {String} pathName Path to your project
753
- @param {UI} _ui The UI instance to provide to the created Project.
754
- @return {Project} Project instance
755
- */
756
- static closestSync(pathName, _ui, _cli) {
757
- logger.info(&#x27;looking for package.json starting at %s&#x27;, pathName);
758
-
759
- let ui = ensureUI(_ui);
760
-
761
- let directory = findupPath(pathName);
762
- let pkg = fs.readJsonSync(path.join(directory, &#x27;package.json&#x27;));
763
- logger.info(&#x27;found package.json at %s&#x27;, directory);
764
-
765
- // allow &#x60;package.json&#x60; files to specify where the actual project lives
766
- if (pkg &amp;&amp; pkg[&#x27;ember-addon&#x27;] &amp;&amp; typeof pkg[&#x27;ember-addon&#x27;].projectRoot === &#x27;string&#x27;) {
767
- if (fs.existsSync(path.join(directory, &#x27;ember-cli-build.js&#x27;))) {
768
- throw new Error(
769
- &#x60;Both \&#x60;ember-addon.projectRoot\&#x60; and \&#x60;ember-cli-build.js\&#x60; exist as part of \&#x60;${directory}\&#x60;&#x60;
770
- );
771
- }
772
-
773
- return Project.closestSync(path.join(directory, pkg[&#x27;ember-addon&#x27;].projectRoot), _ui, _cli);
774
- }
775
-
776
- let relative = path.relative(directory, pathName);
777
- if (relative.indexOf(&#x27;tmp&#x27;) === 0) {
778
- logger.info(&#x27;ignoring parent project since we are in the tmp folder of the project&#x27;);
779
- return Project.nullProject(_ui, _cli);
780
- }
781
-
782
- logger.info(&#x27;project name: %s&#x27;, pkg &amp;&amp; pkg.name);
783
-
784
- if (!isEmberCliProject(pkg)) {
785
- logger.info(&#x27;ignoring parent project since it is not an ember-cli project&#x27;);
786
- return Project.nullProject(_ui, _cli);
787
- }
788
-
789
- return new Project(directory, pkg, ui, _cli);
790
- }
791
-
792
- /**
793
- Returns a new project based on the first package.json that is found
794
- in &#x60;pathName&#x60;, or the nullProject.
795
-
796
- The nullProject signifies no-project, but abides by the null object pattern
797
-
798
- @private
799
- @static
800
- @method projectOrnullProject
801
- @param {UI} _ui The UI instance to provide to the created Project.
802
- @return {Project} Project instance
803
- */
804
- static projectOrnullProject(_ui, _cli) {
805
- try {
806
- return Project.closestSync(process.cwd(), _ui, _cli);
807
- } catch (reason) {
808
- if (reason instanceof Project.NotFoundError) {
809
- return Project.nullProject(_ui, _cli);
810
- } else {
811
- throw reason;
812
- }
813
- }
814
- }
815
-
816
- /**
817
- Returns the project root based on the first package.json that is found
818
-
819
- @static
820
- @method getProjectRoot
821
- @return {String} The project root directory
822
- */
823
- static getProjectRoot() {
824
- let packagePath = findup.sync(&#x27;package.json&#x27;);
825
- if (!packagePath) {
826
- logger.info(&#x27;getProjectRoot: not found. Will use cwd: %s&#x27;, process.cwd());
827
- return process.cwd();
828
- }
829
-
830
- let directory = path.dirname(packagePath);
831
- const pkg = require(packagePath);
832
-
833
- if (pkg &amp;&amp; pkg.name === &#x27;ember-cli&#x27;) {
834
- logger.info(&quot;getProjectRoot: named &#x27;ember-cli&#x27;. Will use cwd: %s&quot;, process.cwd());
835
- return process.cwd();
836
- }
837
-
838
- logger.info(&#x27;getProjectRoot %s -&gt; %s&#x27;, process.cwd(), directory);
839
- return directory;
840
- }
841
- }
842
-
843
- class NotFoundError extends Error {
844
- constructor(message) {
845
- super(message);
846
- this.name = &#x27;NotFoundError&#x27;;
847
- this.stack = new Error().stack;
848
- }
849
- }
850
-
851
- Project.NotFoundError = NotFoundError;
852
-
853
- function ensureInstrumentation(cli, ui) {
854
- if (cli &amp;&amp; cli.instrumentation) {
855
- return cli.instrumentation;
856
- }
857
-
858
- // Instrumentation &#x60;require&#x60; needs to occur inline due to circular dependencies between
859
- // Instrumentation =&gt; getConfig =&gt; Project =&gt; Instrumentation. getConfig is used in Project to
860
- // get the project root.
861
- let Instrumentation = require(&#x27;./instrumentation&#x27;);
862
- // created without a &#x60;cli&#x60; object (possibly from deprecated &#x60;Brocfile.js&#x60;)
863
- return new Instrumentation({ ui, initInstrumentation: null });
864
- }
865
-
866
- function ensureUI(_ui) {
867
- let ui = _ui;
868
-
869
- if (!ui) {
870
- // TODO: one UI (lib/cli/index.js also has one for now...)
871
- const UI = require(&#x27;console-ui&#x27;);
872
- ui = new UI({
873
- inputStream: process.stdin,
874
- outputStream: process.stdout,
875
- ci: process.env.CI || /^(dumb|emacs)$/.test(process.env.TERM),
876
- writeLevel: process.argv.indexOf(&#x27;--silent&#x27;) !== -1 ? &#x27;ERROR&#x27; : undefined,
877
- });
878
- }
879
-
880
- return ui;
881
- }
882
-
883
- function findupPath(pathName) {
884
- let pkgPath = findup.sync(&#x27;package.json&#x27;, { cwd: pathName });
885
- if (!pkgPath) {
886
- throw new NotFoundError(&#x60;No project found at or up from: \&#x60;${pathName}\&#x60;&#x60;);
887
- }
888
-
889
- return path.dirname(pkgPath);
890
- }
891
-
892
- function isEmberCliProject(pkg) {
893
- return (
894
- pkg &amp;&amp;
895
- ((pkg.dependencies &amp;&amp; Object.keys(pkg.dependencies).indexOf(&#x27;ember-cli&#x27;) !== -1) ||
896
- (pkg.devDependencies &amp;&amp; Object.keys(pkg.devDependencies).indexOf(&#x27;ember-cli&#x27;) !== -1))
897
- );
898
- }
899
-
900
- // Export
901
- module.exports = Project;
902
-
903
- </pre>
904
-
905
- </div>
906
- </div>
907
- </div>
908
- </div>
909
- <script src="../assets/vendor/prettify/prettify-min.js"></script>
910
- <script>prettyPrint();</script>
911
- <script src="../assets/js/yui-prettify.js"></script>
912
- </body>
913
- </html>