|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +const EMBER_VERSION_WITH_JQUERY_DEPRECATION = '3.0.0'; // @todo replace with real version |
| 4 | + |
3 | 5 | module.exports = {
|
4 | 6 | name: require('./package').name,
|
5 | 7 | included() {
|
6 | 8 | this._super.included.apply(this, arguments);
|
| 9 | + |
| 10 | + const VersionChecker = require('ember-cli-version-checker'); |
| 11 | + |
7 | 12 | let app = this._findHost();
|
8 | 13 | let optionalFeatures = app.project.findAddonByName("@ember/optional-features");
|
9 | 14 |
|
10 | 15 | if (!app.vendorFiles || !app.vendorFiles['jquery.js']) {
|
11 | 16 | app.import('vendor/jquery/jquery.js', { prepend: true });
|
12 | 17 | }
|
13 | 18 |
|
| 19 | + let checker = new VersionChecker(this); |
| 20 | + let ember = checker.forEmber(); |
| 21 | + |
| 22 | + if (ember.gte(EMBER_VERSION_WITH_JQUERY_DEPRECATION)) { |
| 23 | + app.import('vendor/jquery/component.dollar.js'); |
| 24 | + } |
| 25 | + |
14 | 26 | if (optionalFeatures && !optionalFeatures.isFeatureEnabled('jquery-integration')) {
|
15 | 27 | app.project.ui.writeDeprecateLine('You have disabled the `jquery-integration` optional feature. You now have to delete `@ember/jquery` from your package.json');
|
16 | 28 | }
|
17 | 29 | },
|
18 | 30 |
|
19 | 31 | treeForVendor: function() {
|
| 32 | + const BroccoliMergeTrees = require('broccoli-merge-trees'); |
20 | 33 | const Funnel = require('broccoli-funnel');
|
21 | 34 | const resolve = require('resolve');
|
22 | 35 | const path = require('path');
|
23 | 36 |
|
24 |
| - var jqueryPath; |
| 37 | + let jqueryPath; |
25 | 38 | try {
|
26 | 39 | jqueryPath = path.dirname(
|
27 | 40 | resolve.sync('jquery/package.json', { basedir: this.project.root })
|
28 | 41 | );
|
29 |
| - } catch (error) { |
| 42 | + } catch(error) { |
30 | 43 | jqueryPath = path.dirname(require.resolve('jquery/package.json'));
|
31 | 44 | }
|
32 | 45 |
|
33 |
| - var jquery = new Funnel(jqueryPath + '/dist', { |
| 46 | + let jquery = new Funnel(jqueryPath + '/dist', { |
34 | 47 | destDir: 'jquery',
|
35 | 48 | files: ['jquery.js'],
|
36 | 49 | });
|
37 | 50 |
|
38 |
| - return jquery; |
| 51 | + let babelAddon = this.project.findAddonByName('ember-cli-babel'); |
| 52 | + let componentDollarTree = new Funnel(path.join(__dirname, 'vendor'), { |
| 53 | + destDir: 'jquery', |
| 54 | + }); |
| 55 | + let transpiledComponentDollarTree = babelAddon.transpileTree(componentDollarTree); |
| 56 | + |
| 57 | + return new BroccoliMergeTrees([jquery, transpiledComponentDollarTree]); |
39 | 58 | },
|
40 | 59 | };
|
0 commit comments