diff --git a/app/assets/javascripts/discourse/app/global-compat.js b/app/assets/javascripts/discourse/app/global-compat.js index 97270c55b71..eddc30a2798 100644 --- a/app/assets/javascripts/discourse/app/global-compat.js +++ b/app/assets/javascripts/discourse/app/global-compat.js @@ -1,3 +1,4 @@ +import jQuery from "jquery"; import virtualDom from "virtual-dom"; import widgetHelpers from "discourse-widget-hbs/helpers"; @@ -5,3 +6,7 @@ window.__widget_helpers = widgetHelpers; // TODO: Eliminate this global window.virtualDom = virtualDom; + +if (!window.$) { + window.$ = window.jQuery = jQuery; +} diff --git a/app/assets/javascripts/discourse/config/optional-features.json b/app/assets/javascripts/discourse/config/optional-features.json deleted file mode 100644 index d0d7c47f937..00000000000 --- a/app/assets/javascripts/discourse/config/optional-features.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "application-template-wrapper": false, - "default-async-observers": true, - "jquery-integration": true, - "template-only-glimmer-components": true -} diff --git a/app/assets/javascripts/discourse/config/optional-features.json.js b/app/assets/javascripts/discourse/config/optional-features.json.js new file mode 100644 index 00000000000..1f6dd89d55c --- /dev/null +++ b/app/assets/javascripts/discourse/config/optional-features.json.js @@ -0,0 +1,11 @@ +const EMBER_MAJOR_VERSION = parseInt( + require("ember-source/package.json").version.split(".")[0], + 10 +); + +module.exports = { + "application-template-wrapper": false, + "default-async-observers": true, + "jquery-integration": EMBER_MAJOR_VERSION < 4, + "template-only-glimmer-components": true, +}; diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js index c7667f23dd1..6d7a2f33706 100644 --- a/app/assets/javascripts/discourse/ember-cli-build.js +++ b/app/assets/javascripts/discourse/ember-cli-build.js @@ -99,10 +99,12 @@ module.exports = function (defaults) { }, }); - // TODO: remove me - // Ember 3.28 still has some internal dependency on jQuery being a global, - // for the time being we will bring it in vendor.js - app.import("node_modules/jquery/dist/jquery.js", { prepend: true }); + if (EMBER_MAJOR_VERSION < 4) { + // TODO: remove me + // Ember 3.28 still has some internal dependency on jQuery being a global, + // for the time being we will bring it in vendor.js + app.import("node_modules/jquery/dist/jquery.js", { prepend: true }); + } // WARNING: We should only import scripts here if they are not in NPM. app.import(vendorJs + "bootbox.js"); @@ -177,7 +179,7 @@ module.exports = function (defaults) { if ( !request.includes("-embroider-implicit") && // TODO: delete special case for jquery when removing app.import() above - (request === "jquery" || + ((EMBER_MAJOR_VERSION < 4 && request === "jquery") || request.startsWith("admin/") || request.startsWith("wizard/") || request.startsWith("discourse/plugins/") ||