Bug 39466 - Add plugins/js directory
Summary: Add plugins/js directory
Status: RESOLVED LATER
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Marcel de Rooy
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-27 09:44 UTC by Marcel de Rooy
Modified: 2025-05-14 14:33 UTC (History)
1 user (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 39466: Add plugins/js folder, add access in Apache (2.69 KB, patch)
2025-03-27 10:02 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel de Rooy 2025-03-27 09:44:35 UTC
See also bug 39435. We need a folder to store js associated with a plugin.
Comment 1 Marcel de Rooy 2025-03-27 10:02:35 UTC
Created attachment 179758 [details] [review]
Bug 39466: Add plugins/js folder, add access in Apache

Test plan:
Run the adjusted koha-create-dirs (or copy it to sbin and
run koha-create) and verify folder creation.
Remove the folders (manually or use koha-remove in case you
used koha-create).

Create the js folder in your own /var/lib/koha/YOUR_INSTANCE/plugins
folder. (Optionally, chmod 550 it.)
Copy the change in the apache-shared file into your /etc/koha
counterpart. Restart Apache.
Touch /var/lib/koha/YOUR_INSTANCE/plugins/js/test.txt.
Verify that you can reach it with URL /plugins/js/test.txt.
Comment 2 David Cook 2025-03-27 22:37:23 UTC
I'm not sure that I understand this one. Could you elaborate on it a bit more?
Comment 3 Marcel de Rooy 2025-03-28 06:37:04 UTC
(In reply to David Cook from comment #2)
> I'm not sure that I understand this one. Could you elaborate on it a bit
> more?

On the other bug a plugin sends back html which could include a js link to a script in this plugin folder. This js is not part of Koha, but part of the plugin.
Comment 4 David Cook 2025-03-31 23:42:33 UTC
(In reply to Marcel de Rooy from comment #3)
> (In reply to David Cook from comment #2)
> > I'm not sure that I understand this one. Could you elaborate on it a bit
> > more?
> 
> On the other bug a plugin sends back html which could include a js link to a
> script in this plugin folder. This js is not part of Koha, but part of the
> plugin.

But how would the Javascript get into this folder? It seems like it would have to be manually set up?
Comment 5 Marcel de Rooy 2025-04-01 11:43:15 UTC
(In reply to David Cook from comment #4)
> (In reply to Marcel de Rooy from comment #3)
> > (In reply to David Cook from comment #2)
> > > I'm not sure that I understand this one. Could you elaborate on it a bit
> > > more?
> > 
> > On the other bug a plugin sends back html which could include a js link to a
> > script in this plugin folder. This js is not part of Koha, but part of the
> > plugin.
> 
> But how would the Javascript get into this folder? It seems like it would
> have to be manually set up?

Yes we need some adjustment in the plugin install.
Comment 6 David Cook 2025-04-01 22:42:56 UTC
(In reply to Marcel de Rooy from comment #5)
> Yes we need some adjustment in the plugin install.

I don't know that it will work, since there's lots of different ways to deploy the plugins.

For instance, I actually separate my plugins into /var/lib/koha/<instance>/<plugin_name> and add them as separate pluginsdir entries, as I find this makes it much easier to manage them. Some people point to places like /opt/all_my_koha_plugins and stuff like that.

For the Javascript, you could use the "static_routes" plugin hook.
Comment 7 Marcel de Rooy 2025-04-02 06:24:27 UTC
(In reply to David Cook from comment #6)
> (In reply to Marcel de Rooy from comment #5)
> > Yes we need some adjustment in the plugin install.
> 
> I don't know that it will work, since there's lots of different ways to
> deploy the plugins.
> 
> For instance, I actually separate my plugins into
> /var/lib/koha/<instance>/<plugin_name> and add them as separate pluginsdir
> entries, as I find this makes it much easier to manage them. Some people
> point to places like /opt/all_my_koha_plugins and stuff like that.
> 
> For the Javascript, you could use the "static_routes" plugin hook.

Ok, didnt think about the static_routes here. But it might still be easier and faster to serve directly from this plugins/js folder.
When installing copy js files to that folder, and when uninstalling remove the same files again there. For common js libraries, we could define a dedicated plugin that only serves to install those common js files?

Or even call it plugins/static and copy whatever you have in [your_plugin]/static to the common folder?
Comment 8 David Cook 2025-04-02 23:02:41 UTC
(In reply to Marcel de Rooy from comment #7)
> Ok, didnt think about the static_routes here. But it might still be easier
> and faster to serve directly from this plugins/js folder.

That's true.

> When installing copy js files to that folder, and when uninstalling remove
> the same files again there.

Maybe but that would be a big shift in how plugins work I think. It would be interesting to see what heavy plugin users thing of that. 

Actually, I like the idea of changing how plugin deployments work. Honestly, I think I might prefer a system where plugin code got copied/moved at install/uninstall time.   (Not just the JS but all of it.)

Food for tought...

> For common js libraries, we could define a
> dedicated plugin that only serves to install those common js files?
>
> Or even call it plugins/static and copy whatever you have in
> [your_plugin]/static to the common folder?

I'm not sure that I understand what you're saying here.

If we did standardize the location of plugins, and install them under a plugin name (after all we already define namespaces in up-to-date plugins), we could use "AliasMatch" to serve static files out of /var/lib/<koha>/pluginsv2/<koha_plugin_namespace>/static or /var/lib/<koha>/pluginsv2/<koha_plugin_namespace>/public
Comment 9 Marcel de Rooy 2025-05-14 14:33:59 UTC
Closing this one for now.