From ac73eda7107ab7adb07d4263597e7c38a84f8564 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 21 Aug 2023 14:23:46 +0100 Subject: [PATCH] DEV: Introduce backwards-compat shims for older Discourse core (#57) The changes in 8599bfcaff34993ab9e5e7d90edaabb1471a99b6 needed to be applied precisely in-step with the core changes from https://github.com/discourse/discourse/pull/23148. This is impossible to guarantee with a theme - `.discourse-compatibility` does not give us enough precision. So instead, we need some temporary backwards-compatibility shims so that the new relative-import paths still work on old discourse. --- .../pre-initializers/add-module-shims.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 javascripts/discourse/pre-initializers/add-module-shims.js diff --git a/javascripts/discourse/pre-initializers/add-module-shims.js b/javascripts/discourse/pre-initializers/add-module-shims.js new file mode 100644 index 0000000..96abe01 --- /dev/null +++ b/javascripts/discourse/pre-initializers/add-module-shims.js @@ -0,0 +1,35 @@ +// Backwards compatility for core versions before 82b16f4f +// Can be removed once 3.2.0.beta1 is released, and the compat file is updated + +const themeId = themePrefix("foo").match(/theme_translations\.(\d+)\.foo/)[1]; +const base = `discourse/theme-${themeId}`; + +if (!require.entries[`${base}/discourse/components/spreadsheet-editor`]) { + // eslint-disable-next-line no-console + console.warn( + "Running on an old version of core. discourse-table-builder is shimming modules to keep old imports working." + ); + + define( + `discourse/discourse-table-builder/lib/utilities`, + ["exports", `${base}/discourse-table-builder/lib/utilities`], + function (_exports, utilities) { + _exports.tokenRange = utilities.tokenRange; + _exports.arrayToTable = utilities.arrayToTable; + _exports.findTableRegex = utilities.findTableRegex; + } + ); + + define( + `discourse/discourse-table-builder/lib/locale-mapping`, + ["exports", `${base}/discourse-table-builder/lib/locale-mapping`], + function (_exports, localeMapping) { + _exports.localeMapping = localeMapping.localeMapping; + } + ); +} + +export default { + name: "add-template-module-shims", + initialize() {}, +};