Skip to content

Commit

Permalink
Load @ember/debug via __loader instead of global
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jun 17, 2021
1 parent f6cd0c4 commit c4300b1
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ module.exports = {
})[0];
},

_monkeyPatch_EmberDeprecate(htmlbarsCompilerPreprocessor) {
_registerDeprecationHandler(htmlbarsCompilerPreprocessor) {
if (!htmlbarsCompilerPreprocessor._addon) {
// not a new enough ember-cli-htmlbars to monkey patch
// we need 1.0.3
throw new Error('ember-cli-deprecation-workflow does not support ember-cli-htmlbars <1.0.3');
return;
}
var addonContext = this;
Expand All @@ -77,47 +78,31 @@ module.exports = {
htmlbarsCompilerPreprocessor._addon.htmlbarsOptions = function () {
var options = originalHtmlbarsOptions.apply(this, arguments);
var Ember = options.templateCompiler._Ember;
var registerDeprecationHandler;

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();
}
});
if (Ember.__loader) {
registerDeprecationHandler = Ember.__loader.require('@ember/debug').registerDeprecationHandler;
}

var originalDeprecate = options.templateCompiler._Ember.deprecate;
Ember.deprecate = function (message, test, options) {
var noDeprecation;

if (typeof test === 'function') {
noDeprecation = test();
} else {
noDeprecation = test;
}
if (!registerDeprecationHandler) {
registerDeprecationHandler = Ember.Debug.registerDeprecationHandler;
}

if (!noDeprecation) {
addonContext._templateDeprecations.push({
message: JSON.stringify(message),
test: !!test,
options: JSON.stringify(options),
});
}
registerDeprecationHandler(function (
message,
options,
next
) {
addonContext._templateDeprecations.push({
message: JSON.stringify(message),
test: false,
options: JSON.stringify(options),
});

if (logToNodeConsole) {
return originalDeprecate.apply(this, arguments);
next();
}
};
});

return options;
};
Expand All @@ -128,7 +113,7 @@ module.exports = {
var htmlbarsCompilerPreprocessor =
this._findHtmlbarsPreprocessor(registry);

this._monkeyPatch_EmberDeprecate(htmlbarsCompilerPreprocessor);
this._registerDeprecationHandler(htmlbarsCompilerPreprocessor);
}
},

Expand Down

0 comments on commit c4300b1

Please sign in to comment.