Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/discourse/app/loader-shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do anything right now/yet, since ember-source@3.28 also brings a shim for this (loadShim checks for require.has and no-op)

It'll be needed once we upgrade ember-source

loaderShim("js-yaml", () => importSync("js-yaml"));
loaderShim("message-bus-client", () => importSync("message-bus-client"));
loaderShim("virtual-dom", () => importSync("virtual-dom"));
Expand Down
25 changes: 24 additions & 1 deletion app/assets/javascripts/discourse/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we stop doing this, one difference will be that, when evaluated as a "real-ish" module, jQuery detects that and does not define the window.$ and window.jQuery globals. We can add that back in the jquery-plugins initializer.

Currently on 3.28 that is not very feasible as the ember internals gets loaded before our initializer runs and expects the global to be defined. Once we are on 4+, that problem goes away.

When we are in control of adding the window.$ global may want to consider adding our own deprecation for it (asking to import $ from "jquery";) instead, which would pave the way for a better chance of us being able to eventually stop shipping jQuery in core. That way, at least we have some hope of statically scanning for the import, though the long term proper solution is to have plugins declare the dependency.


// 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", {
Expand Down Expand Up @@ -154,7 +159,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") ||
Expand All @@ -173,6 +180,22 @@ module.exports = function (defaults) {
exportsPresence: "error",
},
},
rules: [
{
test: require.resolve("bootstrap/js/modal"),
use: [
{
loader: "imports-loader",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports-loader is otherwise unused as of #23971, so if we don't end up merging this PR, we can remove that dependency

options: {
imports: {
moduleName: "jquery",
name: "jQuery",
},
},
},
],
},
],
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/discourse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -114,6 +113,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",
Expand Down
32 changes: 0 additions & 32 deletions app/assets/javascripts/patches/@ember+jquery+2.0.0.patch

This file was deleted.

15 changes: 2 additions & 13 deletions app/assets/javascripts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1134,17 +1134,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"
Expand Down Expand Up @@ -3561,7 +3550,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==
Expand Down Expand Up @@ -9601,7 +9590,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==
Expand Down