mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
`discourse-common` was created in the past to share logic between the 'wizard' app and the main 'discourse' app. Since then, the wizard has been consolidated into the main app, so the separation of `discourse-common` is no longer useful. This commit moves `discourse-common/resolver` into `discourse/resolver`, adds shims for the imports, and updates existing uses in core.
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import DiscourseTemplateMap from "discourse/lib/discourse-template-map";
|
|
import { expireConnectorCache } from "discourse/lib/plugin-connectors";
|
|
import { expireModuleTrieCache } from "discourse/resolver";
|
|
|
|
const modifications = [];
|
|
|
|
function generateTemporaryModule(defaultExport) {
|
|
return function (_exports) {
|
|
Object.defineProperty(_exports, "__esModule", {
|
|
value: true,
|
|
});
|
|
_exports.default = defaultExport;
|
|
};
|
|
}
|
|
|
|
export function registerTemporaryModule(moduleName, defaultExport) {
|
|
const modificationData = {
|
|
moduleName,
|
|
existingModule: requirejs.entries[moduleName],
|
|
};
|
|
delete requirejs.entries[moduleName];
|
|
define(moduleName, ["exports"], generateTemporaryModule(defaultExport));
|
|
modifications.push(modificationData);
|
|
expireConnectorCache();
|
|
expireModuleTrieCache();
|
|
DiscourseTemplateMap.setModuleNames(Object.keys(requirejs.entries));
|
|
}
|
|
|
|
export function cleanupTemporaryModuleRegistrations() {
|
|
for (const modificationData of modifications.reverse()) {
|
|
const { moduleName, existingModule } = modificationData;
|
|
delete requirejs.entries[moduleName];
|
|
if (existingModule) {
|
|
requirejs.entries[moduleName] = existingModule;
|
|
}
|
|
}
|
|
if (modifications.length) {
|
|
expireConnectorCache();
|
|
DiscourseTemplateMap.setModuleNames(Object.keys(requirejs.entries));
|
|
}
|
|
modifications.clear();
|
|
}
|