DEV: remove @ember/jquery in favor of just jquery (#24034)

`@ember/jquery` was necessary to automate the `app.import()` but
that is no longer necessary with `ember-auto-import`. A secondary
thing it does is bringing back the `this.$` feature, but with a
deprecation. It is my understanding that the deprecation has long
be fully absorbed into both core and plugins so we shouldn't need
this package anymore.
This commit is contained in:
Godfrey Chan 2023-10-25 02:14:50 -07:00 committed by GitHub
parent a113f48ba3
commit 895036bd7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 47 deletions

View File

@ -28,6 +28,7 @@ loaderShim("discourse-i18n", () => importSync("discourse-i18n"));
loaderShim("ember-modifier", () => importSync("ember-modifier"));
loaderShim("ember-route-template", () => importSync("ember-route-template"));
loaderShim("handlebars", () => importSync("handlebars"));
loaderShim("jquery", () => importSync("jquery"));
loaderShim("js-yaml", () => importSync("js-yaml"));
loaderShim("message-bus-client", () => importSync("message-bus-client"));
loaderShim("virtual-dom", () => importSync("virtual-dom"));

View File

@ -71,6 +71,11 @@ 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 });
// WARNING: We should only import scripts here if they are not in NPM.
app.import(vendorJs + "bootbox.js");
app.import("node_modules/ember-source/dist/ember-template-compiler.js", {
@ -141,7 +146,9 @@ module.exports = function (defaults) {
function ({ request }, callback) {
if (
!request.includes("-embroider-implicit") &&
(request.startsWith("admin/") ||
// TODO: delete special case for jquery when removing app.import() above
(request === "jquery" ||
request.startsWith("admin/") ||
request.startsWith("wizard/") ||
(request.startsWith("pretty-text/engines/") &&
request !== "pretty-text/engines/discourse-markdown-it") ||
@ -160,6 +167,22 @@ module.exports = function (defaults) {
exportsPresence: "error",
},
},
rules: [
{
test: require.resolve("bootstrap/js/modal"),
use: [
{
loader: "imports-loader",
options: {
imports: {
moduleName: "jquery",
name: "jQuery",
},
},
},
],
},
],
},
},
},

View File

@ -31,7 +31,6 @@
"@discourse/backburner.js": "^2.7.1-0",
"@discourse/itsatrap": "^2.0.10",
"@ember-compat/tracked-built-ins": "^0.9.1",
"@ember/jquery": "^2.0.0",
"@ember/legacy-built-in-components": "^0.5.0",
"@ember/optional-features": "^2.0.0",
"@ember/render-modifiers": "^2.1.0",
@ -112,6 +111,7 @@
"float-kit": "1.0.0",
"html-entities": "^2.4.0",
"imports-loader": "^4.0.1",
"jquery": "^3.5.0",
"js-yaml": "^4.1.0",
"jsdom": "^22.1.0",
"loader.js": "^4.7.0",

View File

@ -1,32 +0,0 @@
diff --git a/node_modules/@ember/jquery/vendor/jquery/component.dollar.js b/node_modules/@ember/jquery/vendor/jquery/component.dollar.js
index 8c0cfd5..4c211e2 100644
--- a/node_modules/@ember/jquery/vendor/jquery/component.dollar.js
+++ b/node_modules/@ember/jquery/vendor/jquery/component.dollar.js
@@ -1,8 +1,16 @@
import { assert, deprecate } from '@ember/debug';
-import EmberObject from '@ember/object';
-import Component from '@ember/component';
(function() {
+ // importing these, specifically, is done so that we don't trigger the
+ // ember-global deprecation
+ //
+ // We had tried to import at the top of this file, but there is a build time transform
+ // removing those, and re-triggering the ember-global deprecation.
+ // See: https://deprecations.emberjs.com/v3.x#toc_ember-global
+ // for more information
+ const EmberObject = require("@ember/object").default;
+ const Component = require("@ember/component").default;
+
/*
* This non-standard use of `reopen` and `call` allows the component
* base class to be reopened without triggering the
@@ -28,6 +36,8 @@ import Component from '@ember/component';
);
if (this.element) {
+ // same technique the shim uses
+ let jQuery = self['jQuery'];
return sel ? jQuery(sel, this.element) : jQuery(this.element);
}
}

View File

@ -1129,17 +1129,6 @@
resolved "https://registry.yarnpkg.com/@ember/edition-utils/-/edition-utils-1.2.0.tgz#a039f542dc14c8e8299c81cd5abba95e2459cfa6"
integrity sha512-VmVq/8saCaPdesQmftPqbFtxJWrzxNGSQ+e8x8LLe3Hjm36pJ04Q8LeORGZkAeOhldoUX9seLGmSaHeXkIqoog==
"@ember/jquery@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@ember/jquery/-/jquery-2.0.0.tgz#083a1de32333b3fc938fad246a6f3ea7eefe5b10"
integrity sha512-f8+WNqzXBNxl96jo0IwJBO5QCi0bnUlba9I7WbZcGhgnzszC76INJkw6l8UepZ1PMGG1H1wYpoIGoBBp5ZVmFA==
dependencies:
broccoli-funnel "^3.0.6"
broccoli-merge-trees "^4.2.0"
ember-cli-babel "^7.26.6"
jquery "^3.5.0"
resolve "^1.15.1"
"@ember/legacy-built-in-components@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@ember/legacy-built-in-components/-/legacy-built-in-components-0.5.0.tgz#4c212fd5a15bf21a4e73d573917e64e08fca69cc"
@ -3507,7 +3496,7 @@ broccoli-funnel@^2.0.0, broccoli-funnel@^2.0.2:
symlink-or-copy "^1.0.0"
walk-sync "^0.3.1"
broccoli-funnel@^3.0.3, broccoli-funnel@^3.0.5, broccoli-funnel@^3.0.6, broccoli-funnel@^3.0.7, broccoli-funnel@^3.0.8:
broccoli-funnel@^3.0.3, broccoli-funnel@^3.0.5, broccoli-funnel@^3.0.7, broccoli-funnel@^3.0.8:
version "3.0.8"
resolved "https://registry.yarnpkg.com/broccoli-funnel/-/broccoli-funnel-3.0.8.tgz#f5b62e2763c3918026a15a3c833edc889971279b"
integrity sha512-ng4eIhPYiXqMw6SyGoxPHR3YAwEd2lr9FgBI1CyTbspl4txZovOsmzFkMkGAlu88xyvYXJqHiM2crfLa65T1BQ==
@ -9334,7 +9323,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha512-ZuF55hVUQaaczgOIwqWzkEcEidmlD/xl44x1UZnhOXcYuFN2S6+rcxpG+C1N3So0wvNI3DmJICUFfu2SxhBmvg==
resolve@^1.10.0, resolve@^1.11.1, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.20.0, resolve@^1.22.1, resolve@^1.3.3, resolve@^1.4.0, resolve@^1.5.0:
resolve@^1.10.0, resolve@^1.11.1, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.20.0, resolve@^1.22.1, resolve@^1.3.3, resolve@^1.4.0, resolve@^1.5.0:
version "1.22.2"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.2.tgz#0ed0943d4e301867955766c9f3e1ae6d01c6845f"
integrity sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==