DEV: Resolve and unsilence `ember-global` deprecation (#20702)
One of the problems here was coming from the ember-jquery addon. This commit skips the problematic shim from the addon and re-implements in Discourse. This hack will only be required short-term - we'll be totally dropping the ember-jquery integration as part of our upgrade to Ember 4.x. Removing this shim means we can also remove our `discourse-ensure-deprecation-order` dummy addon which was ensuring that the ember-jquery-triggered deprecation was covered by ember-cli-deprecation-workflow.
This commit is contained in:
parent
64557c4076
commit
5e5024d3e7
|
@ -1,5 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
name: require("./package").name,
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"name": "discourse-ensure-deprecation-order",
|
||||
"version": "1.0.0",
|
||||
"description": "A dummy addon which ensures ember-cli-deprecation-workflow is loaded before @ember/jquery",
|
||||
"author": "Discourse",
|
||||
"license": "GPL-2.0-only",
|
||||
"keywords": [
|
||||
"ember-addon"
|
||||
],
|
||||
"ember-addon": {
|
||||
"before": "@ember/jquery",
|
||||
"after": "ember-cli-deprecation-workflow"
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
import Component from "@ember/component";
|
||||
import EmberObject from "@ember/object";
|
||||
import { actionModifier } from "./ember-action-modifier";
|
||||
import Ember from "ember";
|
||||
|
||||
/**
|
||||
* Classic Ember components (i.e. "@ember/component") rely upon "event
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import { assert, deprecate } from "@ember/debug";
|
||||
import EmberObject from "@ember/object";
|
||||
import Component from "@ember/component";
|
||||
import jQuery from "jquery";
|
||||
|
||||
let done = false;
|
||||
|
||||
// Adapted from https://github.com/emberjs/ember-jquery/blob/master/vendor/jquery/component.dollar.js
|
||||
// but implemented in a module to avoid transpiled version triggering the Ember Global deprecation.
|
||||
// To be dropped when we remove the jquery integration as part of the 4.x update.
|
||||
export default {
|
||||
name: "deprecate-jquery-integration",
|
||||
|
||||
initialize() {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
|
||||
EmberObject.reopen.call(Component, {
|
||||
$(sel) {
|
||||
assert(
|
||||
"You cannot access this.$() on a component with `tagName: ''` specified.",
|
||||
this.tagName !== ""
|
||||
);
|
||||
|
||||
deprecate(
|
||||
"Using this.$() in a component has been deprecated, consider using this.element",
|
||||
false,
|
||||
{
|
||||
id: "ember-views.curly-components.jquery-element",
|
||||
since: "3.4.0",
|
||||
until: "4.0.0",
|
||||
url: "https://emberjs.com/deprecations/v3.x#toc_jquery-apis",
|
||||
for: "ember-source",
|
||||
}
|
||||
);
|
||||
|
||||
if (this.element) {
|
||||
return sel ? jQuery(sel, this.element) : jQuery(this.element);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
done = true;
|
||||
},
|
||||
};
|
|
@ -3,7 +3,6 @@ globalThis.deprecationWorkflow.config = {
|
|||
// We're using RAISE_ON_DEPRECATION in environment.js instead of
|
||||
// `throwOnUnhandled` here since it is easier to toggle.
|
||||
workflow: [
|
||||
{ handler: "silence", matchId: "ember-global" },
|
||||
{ handler: "silence", matchId: "ember.built-in-components.reopen" },
|
||||
{ handler: "silence", matchId: "ember.built-in-components.import" },
|
||||
{ handler: "silence", matchId: "implicit-injections" },
|
||||
|
|
|
@ -163,6 +163,16 @@ module.exports = function (defaults) {
|
|||
}
|
||||
};
|
||||
|
||||
// @ember/jquery introduces a shim which triggers the ember-global deprecation.
|
||||
// We remove that shim, and re-implement ourselves in the deprecate-jquery-integration pre-initializer
|
||||
const vendorScripts = app._scriptOutputFiles["/assets/vendor.js"];
|
||||
const componentDollarShimIndex = vendorScripts.indexOf(
|
||||
"vendor/jquery/component.dollar.js"
|
||||
);
|
||||
if (componentDollarShimIndex) {
|
||||
vendorScripts.splice(componentDollarShimIndex, 1);
|
||||
}
|
||||
|
||||
// WARNING: We should only import scripts here if they are not in NPM.
|
||||
// For example: our very specific version of bootstrap-modal.
|
||||
app.import(vendorJs + "bootbox.js");
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
"deepmerge": "^4.3.0",
|
||||
"dialog-holder": "1.0.0",
|
||||
"discourse-common": "1.0.0",
|
||||
"discourse-ensure-deprecation-order": "1.0.0",
|
||||
"discourse-hbr": "1.0.0",
|
||||
"discourse-plugins": "1.0.0",
|
||||
"discourse-widget-hbs": "1.0.0",
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
throw "Unsupported browser detected";
|
||||
}
|
||||
|
||||
// In Ember 3.28, the `ember` package is responsible for configuring `Helper.helper`,
|
||||
// so we need to require('ember') before setting up any helpers.
|
||||
// https://github.com/emberjs/ember.js/blob/744e536d37/packages/ember/index.js#L493-L493
|
||||
// In modern Ember, the Helper.helper definition has moved to the helper module itself
|
||||
// https://github.com/emberjs/ember.js/blob/0c5518ea7b/packages/%40ember/-internals/glimmer/lib/helper.ts#L134-L138
|
||||
require("ember");
|
||||
|
||||
window.__widget_helpers = require("discourse-widget-hbs/helpers").default;
|
||||
|
||||
// TODO: Eliminate this global
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
"dialog-holder",
|
||||
"discourse",
|
||||
"discourse-common",
|
||||
"discourse-ensure-deprecation-order",
|
||||
"discourse-hbr",
|
||||
"discourse-plugins",
|
||||
"discourse-widget-hbs",
|
||||
|
|
Loading…
Reference in New Issue