Skip to content

Commit

Permalink
Merge pull request #118 from mixonic/mixonic/requirejs-ember-access
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic authored Jul 4, 2021
2 parents e9044a2 + 6fa5784 commit 23e8017
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 149 deletions.
54 changes: 0 additions & 54 deletions generate-deprecations-tree.js

This file was deleted.

93 changes: 0 additions & 93 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
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:
//
Expand Down Expand Up @@ -52,91 +46,4 @@ module.exports = {

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);
}
},
};
4 changes: 4 additions & 0 deletions tests/dummy/config/deprecation-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ self.deprecationWorkflow.config = {
workflow: [
/*
* Actual controlled deprecations
*
* The ember-global log configuration is only required for
* ember-release-with-jquery. All other ember-try scenarios pass with that
* handler removed (and defaulting to a throw).
*/
{ matchId: 'ember-global', handler: 'log' },

Expand Down
6 changes: 4 additions & 2 deletions vendor/ember-cli-deprecation-workflow/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const LOG_LIMIT = 100;
}
}

Ember.Debug.registerDeprecationHandler(function handleDeprecationWorkflow(message, options, next){
let registerDeprecationHandler = require.has('@ember/debug') ? require('@ember/debug').registerDeprecationHandler : Ember.Debug.registerDeprecationHandler;

registerDeprecationHandler(function handleDeprecationWorkflow(message, options, next){
let config = self.deprecationWorkflow.config || {};

let matchingWorkflow = detectWorkflow(config, message, options);
Expand Down Expand Up @@ -68,7 +70,7 @@ const LOG_LIMIT = 100;
}
});

Ember.Debug.registerDeprecationHandler(function deprecationCollector(message, options, next){
registerDeprecationHandler(function deprecationCollector(message, options, next){
let key = options && options.id || message;
let matchKey = options && key === options.id ? 'matchId' : 'matchMessage';

Expand Down

0 comments on commit 23e8017

Please sign in to comment.