forked from ember-cli/ember-cli-deprecation-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
145 lines (119 loc) · 3.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
module.exports = {
name: require('./package').name,
init() {
this._super.init && this._super.init.apply(this, arguments);
this._templateDeprecations = [];
},
_shouldInclude() {
// the presence of `this.app.tests` shows that we are in one of:
//
// * running non-production build
// * running tests against production
//
var app = this.app || this._findHost();
return app.tests;
},
included() {
// From https://github.com/rwjblue/ember-debug-handlers-polyfill/blob/master/index.js
var app = this.app || this._findHost();
if (this._shouldInclude()) {
app.import('vendor/ember-debug-handlers-polyfill/debug.js');
app.import(
'vendor/ember-cli-deprecation-workflow/deprecation-workflow.js'
);
app.import('vendor/ember-cli-deprecation-workflow/main.js');
} else {
app.import('vendor/ember-debug-handlers-polyfill/prod.js');
}
},
treeForVendor(tree) {
var root = process.env._DUMMY_CONFIG_ROOT_PATH || this.project.root;
var configDir = '/config';
if (
this.project.pkg['ember-addon'] &&
this.project.pkg['ember-addon']['configPath']
) {
configDir = '/' + this.project.pkg['ember-addon']['configPath'];
}
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var configTree = new Funnel(root + configDir, {
include: ['deprecation-workflow.js'],
destDir: 'ember-cli-deprecation-workflow',
});
return mergeTrees([tree, configTree], { overwrite: true });
},
_findHtmlbarsPreprocessor(registry) {
var plugins = registry.load('template');
return plugins.filter(function (plugin) {
return plugin.name === 'ember-cli-htmlbars';
})[0];
},
_monkeyPatch_EmberDeprecate(htmlbarsCompilerPreprocessor) {
if (!htmlbarsCompilerPreprocessor._addon) {
// not a new enough ember-cli-htmlbars to monkey patch
// we need 1.0.3
return;
}
var addonContext = this;
var originalHtmlbarsOptions =
htmlbarsCompilerPreprocessor._addon.htmlbarsOptions;
var logToNodeConsole = this.project.config(process.env.EMBER_ENV)
.logTemplateLintToConsole;
htmlbarsCompilerPreprocessor._addon.htmlbarsOptions = function () {
var options = originalHtmlbarsOptions.apply(this, arguments);
var Ember = options.templateCompiler._Ember;
if (Ember.Debug && Ember.Debug.registerDeprecationHandler) {
Ember.Debug.registerDeprecationHandler(function (
message,
options,
next
) {
addonContext._templateDeprecations.push({
message: JSON.stringify(message),
test: false,
options: JSON.stringify(options),
});
if (logToNodeConsole) {
next();
}
});
}
var originalDeprecate = options.templateCompiler._Ember.deprecate;
Ember.deprecate = function (message, test, options) {
var noDeprecation;
if (typeof test === 'function') {
noDeprecation = test();
} else {
noDeprecation = test;
}
if (!noDeprecation) {
addonContext._templateDeprecations.push({
message: JSON.stringify(message),
test: !!test,
options: JSON.stringify(options),
});
}
if (logToNodeConsole) {
return originalDeprecate.apply(this, arguments);
}
};
return options;
};
},
setupPreprocessorRegistry(type, registry) {
if (type === 'parent') {
var htmlbarsCompilerPreprocessor = this._findHtmlbarsPreprocessor(
registry
);
this._monkeyPatch_EmberDeprecate(htmlbarsCompilerPreprocessor);
}
},
lintTree(type, tree) {
if (type === 'template') {
var TemplateLinter = require('./generate-deprecations-tree');
return new TemplateLinter(this, tree);
}
},
};