FIX: Restore behavior of `window.Discourse` (#22167)
The work in fa509224f0
updated our initializer patterns to match modern Ember. This caused the initializer from the (deprecated) ember-export-application-global addon to change its behavior from exporting the ApplicationInstance to exporting the Application. This affects customizations which were using some long-deprecated APIs we had attached to the ApplicationInstance.
This commit removes the deprecated addon, restores the previous ApplicationInstance behavior which we've come to depend on, and adds a test for the expected behavior. It also bumps the `dropFrom` version to make it clear that we do not intend to remove these APIs during this release cycle.
This commit is contained in:
parent
987d5b9fce
commit
e061166a05
|
@ -10,13 +10,15 @@ export default {
|
||||||
// This is required for Ember CLI tests to work
|
// This is required for Ember CLI tests to work
|
||||||
setDefaultOwner(owner.__container__);
|
setDefaultOwner(owner.__container__);
|
||||||
|
|
||||||
|
window.Discourse = owner;
|
||||||
|
|
||||||
Object.defineProperty(owner, "SiteSettings", {
|
Object.defineProperty(owner, "SiteSettings", {
|
||||||
get() {
|
get() {
|
||||||
deprecated(
|
deprecated(
|
||||||
`use injected siteSettings instead of Discourse.SiteSettings`,
|
`use injected siteSettings instead of Discourse.SiteSettings`,
|
||||||
{
|
{
|
||||||
since: "2.8",
|
since: "2.8",
|
||||||
dropFrom: "2.9",
|
dropFrom: "3.2",
|
||||||
id: "discourse.global.site-settings",
|
id: "discourse.global.site-settings",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -29,7 +31,7 @@ export default {
|
||||||
`import discourse/models/user instead of using Discourse.User`,
|
`import discourse/models/user instead of using Discourse.User`,
|
||||||
{
|
{
|
||||||
since: "2.8",
|
since: "2.8",
|
||||||
dropFrom: "2.9",
|
dropFrom: "3.2",
|
||||||
id: "discourse.global.user",
|
id: "discourse.global.user",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -42,7 +44,7 @@ export default {
|
||||||
`import discourse/models/site instead of using Discourse.Site`,
|
`import discourse/models/site instead of using Discourse.Site`,
|
||||||
{
|
{
|
||||||
since: "2.8",
|
since: "2.8",
|
||||||
dropFrom: "2.9",
|
dropFrom: "3.2",
|
||||||
id: "discourse.global.site",
|
id: "discourse.global.site",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -50,4 +52,8 @@ export default {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
teardown() {
|
||||||
|
delete window.Discourse;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
"ember-cached-decorator-polyfill": "^1.0.1",
|
"ember-cached-decorator-polyfill": "^1.0.1",
|
||||||
"ember-decorators": "^6.1.1",
|
"ember-decorators": "^6.1.1",
|
||||||
"ember-exam": "^8.0.0",
|
"ember-exam": "^8.0.0",
|
||||||
"ember-export-application-global": "^2.0.1",
|
|
||||||
"ember-load-initializers": "^2.1.1",
|
"ember-load-initializers": "^2.1.1",
|
||||||
"ember-modifier": "^4.1.0",
|
"ember-modifier": "^4.1.0",
|
||||||
"ember-on-resize-modifier": "^1.1.0",
|
"ember-on-resize-modifier": "^1.1.0",
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { visit } from "@ember/test-helpers";
|
||||||
|
import { test } from "qunit";
|
||||||
|
import { getOwner } from "@ember/application";
|
||||||
|
import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
|
||||||
|
import User from "discourse/models/user";
|
||||||
|
import Site from "discourse/models/site";
|
||||||
|
|
||||||
|
acceptance("Acceptance | Globals", function () {
|
||||||
|
test("Globals function as expected", async function (assert) {
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
assert.ok(window.Discourse, "window.Discourse is present");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
window.Discourse,
|
||||||
|
getOwner(this),
|
||||||
|
"matches the expected application instance"
|
||||||
|
);
|
||||||
|
|
||||||
|
withSilencedDeprecations("discourse.global.user", () => {
|
||||||
|
assert.strictEqual(
|
||||||
|
window.Discourse.User,
|
||||||
|
User,
|
||||||
|
"Deprecated User alias is present"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
withSilencedDeprecations("discourse.global.site", () => {
|
||||||
|
assert.strictEqual(
|
||||||
|
window.Discourse.Site,
|
||||||
|
Site,
|
||||||
|
"Deprecated Site alias is present"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
withSilencedDeprecations("discourse.global.site-settings", () => {
|
||||||
|
assert.strictEqual(
|
||||||
|
window.Discourse.SiteSettings,
|
||||||
|
getOwner(this).lookup("service:site-settings"),
|
||||||
|
"Deprecated SiteSettings alias is present"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -4279,11 +4279,6 @@ ember-exam@^8.0.0:
|
||||||
semver "^7.3.2"
|
semver "^7.3.2"
|
||||||
silent-error "^1.1.1"
|
silent-error "^1.1.1"
|
||||||
|
|
||||||
ember-export-application-global@^2.0.1:
|
|
||||||
version "2.0.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/ember-export-application-global/-/ember-export-application-global-2.0.1.tgz#b120a70e322ab208defc9e2daebe8d0dfc2dcd46"
|
|
||||||
integrity sha512-B7wiurPgsxsSGzJuPFkpBWnaeuCu2PGpG2BjyrfA1VcL7//o+5RSnZqiCEY326y7qmxb2GoCgo0ft03KBU0rRw==
|
|
||||||
|
|
||||||
ember-functions-as-helper-polyfill@^2.1.1:
|
ember-functions-as-helper-polyfill@^2.1.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/ember-functions-as-helper-polyfill/-/ember-functions-as-helper-polyfill-2.1.1.tgz#25240db29b4cd0366a2d2954d2ea26ce0872ff8f"
|
resolved "https://registry.yarnpkg.com/ember-functions-as-helper-polyfill/-/ember-functions-as-helper-polyfill-2.1.1.tgz#25240db29b4cd0366a2d2954d2ea26ce0872ff8f"
|
||||||
|
|
Loading…
Reference in New Issue