diff --git a/app/assets/javascripts/discourse/models/site.js.es6 b/app/assets/javascripts/discourse/models/site.js.es6 index 81d4acca567..aa7a2b5ded6 100644 --- a/app/assets/javascripts/discourse/models/site.js.es6 +++ b/app/assets/javascripts/discourse/models/site.js.es6 @@ -9,6 +9,7 @@ import Singleton from "discourse/mixins/singleton"; import RestModel from "discourse/models/rest"; import TrustLevel from "discourse/models/trust-level"; import PreloadStore from "preload-store"; +import deprecated from "discourse-common/lib/deprecated"; const Site = RestModel.extend({ isReadOnly: alias("is_readonly"), @@ -214,4 +215,18 @@ Site.reopenClass(Singleton, { } }); +let warned = false; +Object.defineProperty(Discourse, "Site", { + get() { + if (!warned) { + deprecated("Import the Site class instead of using Discourse.Site", { + since: "2.4.0", + dropFrom: "2.6.0" + }); + warned = true; + } + return Site; + } +}); + export default Site; diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index b951631c60c..a5c3ae776a6 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -25,6 +25,7 @@ import { userPath } from "discourse/lib/url"; import Category from "discourse/models/category"; import { Promise } from "rsvp"; import { getProperties } from "@ember/object"; +import deprecated from "discourse-common/lib/deprecated"; export const SECOND_FACTOR_METHODS = { TOTP: 1, @@ -901,4 +902,18 @@ User.reopenClass(Singleton, { } }); +let warned = false; +Object.defineProperty(Discourse, "User", { + get() { + if (!warned) { + deprecated("Import the User class instead of using Discourse.User", { + since: "2.4.0", + dropFrom: "2.6.0" + }); + warned = true; + } + return User; + } +}); + export default User; diff --git a/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 b/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 index 2555cf6d129..4fa63bd11f2 100644 --- a/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 +++ b/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 @@ -8,6 +8,8 @@ import { default as TopicTrackingState } from "discourse/models/topic-tracking-state"; import ScreenTrack from "discourse/lib/screen-track"; +import Site from "discourse/models/site"; +import User from "discourse/models/user"; const ALL_TARGETS = ["controller", "component", "route", "model", "adapter"]; @@ -29,7 +31,7 @@ export default { app.register("message-bus:main", messageBus, { instantiate: false }); ALL_TARGETS.forEach(t => app.inject(t, "messageBus", "message-bus:main")); - const currentUser = Discourse.User.current(); + const currentUser = User.current(); app.register("current-user:main", currentUser, { instantiate: false }); const topicTrackingState = TopicTrackingState.create({ @@ -49,7 +51,7 @@ export default { app.inject(t, "siteSettings", "site-settings:main") ); - const site = Discourse.Site.current(); + const site = Site.current(); app.register("site:main", site, { instantiate: false }); ALL_TARGETS.forEach(t => app.inject(t, "site", "site:main")); diff --git a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb index 6ce0c88f992..f56f99d602d 100644 --- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb @@ -82,18 +82,6 @@ JS end end - def whitelisted?(path) - - @@whitelisted ||= Set.new( - [ - "discourse/models/site", - "discourse/models/user", - ] - ) - - @@whitelisted.include?(path) - end - def babel_transpile(source) klass = self.class klass.protect do @@ -131,33 +119,6 @@ JS @output = klass.v8.eval(source) end - # For backwards compatibility with plugins, for now export the Global format too. - # We should eventually have an upgrade system for plugins to use ES6 or some other - # resolve based API. - if whitelisted?(scope.logical_path) && - scope.logical_path =~ /(discourse|admin)\/(controllers|components|views|routes|mixins|models)\/(.*)/ - - type = Regexp.last_match[2] - file_name = Regexp.last_match[3].gsub(/[\-\/]/, '_') - class_name = file_name.classify - - # Rails removes pluralization when calling classify - if file_name.end_with?('s') && (!class_name.end_with?('s')) - class_name << "s" - end - require_name = module_name(scope.root_path, scope.logical_path) - - if require_name !~ /\-test$/ && require_name !~ /^discourse\/plugins\// - result = "#{class_name}#{type.classify}" - - result = result.gsub(/Model$/, '') - - if result != "PostMenuView" - @output << "\n\nDiscourse.#{result} = require('#{require_name}').default;\n" - end - end - end - @output end