DEV: Prepare jquery integration for Ember upgrade (#24566)

- Update optional-features to tie the `jquery-integration` flag to the current ember version
- Wrap ember-4-specific logic in ember-cli-build with a version check
- Update global-compat.js to add the jquery global if it doesn't exist (i.e. if we're on a modern ember version)

Extracted from https://github.com/discourse/discourse/pull/21720. This is a no-op under our current Ember 3.28 version.
This commit is contained in:
David Taylor 2023-11-27 14:01:27 +00:00 committed by GitHub
parent 04164f7dda
commit a9bc732837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 11 deletions

View File

@ -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;
}

View File

@ -1,6 +0,0 @@
{
"application-template-wrapper": false,
"default-async-observers": true,
"jquery-integration": true,
"template-only-glimmer-components": true
}

View File

@ -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,
};

View File

@ -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/") ||