# HG changeset patch # User Kim Alvefur # Date 1679057503 -3600 # Node ID 14a44b1a51d09e27f51fa34c0018fbf3d95b559e # Parent 59478b295137d859e8b214699e6d1e8fb3a7f38b prosody.loader: Allow loading modules under 'prosody' namespace (#1223) Actually `hg mv`-ing all the files is disruptive, basically breaking everything from rebasing all my WIP draft commits to the package building. So instead, what if we didn't and instead rewrote package names as they are `require()`-d? Debian packages produced by the Prosody are already installed into this structure so much will Just Work if all require calls are updated. diff -r 59478b295137 -r 14a44b1a51d0 GNUmakefile --- a/GNUmakefile Sat Mar 18 16:13:32 2023 +0100 +++ b/GNUmakefile Fri Mar 17 13:51:43 2023 +0100 @@ -42,6 +42,10 @@ $(INSTALL_EXEC) ./prosody.install $(BIN)/prosody $(INSTALL_EXEC) ./prosodyctl.install $(BIN)/prosodyctl +install-loader: + $(MKDIR) $(SOURCE) + $(INSTALL_DATA) loader.lua $(SOURCE) + install-core: $(MKDIR) $(SOURCE) $(MKDIR) $(SOURCE)/core @@ -89,7 +93,7 @@ install-data: $(MKDIR_PRIVATE) $(DATA) -install: install-util install-net install-core install-plugins install-bin install-etc install-man install-meta install-data +install: install-util install-net install-core install-plugins install-bin install-etc install-man install-meta install-data install-loader clean: rm -f prosody.install diff -r 59478b295137 -r 14a44b1a51d0 loader.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loader.lua Fri Mar 17 13:51:43 2023 +0100 @@ -0,0 +1,9 @@ +for i = #package.searchers, 1, -1 do + local search = package.searchers[i]; + table.insert(package.searchers, i, function(module_name) + local lib = module_name:match("^prosody%.(.*)$"); + if lib then + return search(lib); + end + end) +end diff -r 59478b295137 -r 14a44b1a51d0 makefile --- a/makefile Sat Mar 18 16:13:32 2023 +0100 +++ b/makefile Fri Mar 17 13:51:43 2023 +0100 @@ -44,6 +44,10 @@ $(INSTALL_EXEC) ./prosody.install $(BIN)/prosody $(INSTALL_EXEC) ./prosodyctl.install $(BIN)/prosodyctl +install-loader: + $(MKDIR) $(SOURCE) + $(INSTALL_DATA) loader.lua $(SOURCE) + install-core: $(MKDIR) $(SOURCE) $(MKDIR) $(SOURCE)/core @@ -91,7 +95,7 @@ install-data: $(MKDIR_PRIVATE) $(DATA) -install: install-util install-net install-core install-plugins install-bin install-etc install-man install-meta install-data +install: install-util install-net install-core install-plugins install-bin install-etc install-man install-meta install-data install-loader clean: rm -f prosody.install