i was working on this for last few days as well... the most important part is not the getScript function, but rather making the static folder available with:
as advised on github i will add my request here...
while i was working on this, i realized that you can not load <script type="module"></script>
currently i overcome this by injecting the script tag myself with
var st = document.createElement("script")
st.setAttribute("type","module")
st.setAttribute("src","enocean-js/test.js")
document.body.appendChild(st)
that seems a bit hackish to me, so i would really like to get this working cleanly.
I would like to write a PR for getting this to work. But as i'm still quite new to node-red it would be great if someone can give me a pointer in the right direction where loading the nodes .html file happens in the core.
not sure why that wouldn't work ? you haven't added the src in the <script version but I assume that is just a bad cut/paste ? What errors do you get ? Main thing is as you point out previously to ensure the server endpoint is in place.
<edit>oh yeah - on the client side we already have specific bits of script tags we look for so you can't have script inside script. Is that the problem ? where are you injecting your tag ? in oneditprepare ?
<script type="text/javascript">
RED.nodes.registerType(...bla bla bla)
console.log("one")
</script>
<script type="module" src="enocean-js/test.js"></script>
i get: Uncaught SyntaxError: Unexpected token {
that's the same error you get when you try to use esm modules without type="module"
Test 4
agian using the external file ("enocean-js/test.js")
import { foo } from 'bar'
console.log("three")
<script type="text/javascript">
RED.nodes.registerType(...bla bla bla)
console.log("one")
var st = document.createElement("script")
st.setAttribute("type","module")
st.setAttribute("src","enocean-js/test.js")
document.body.appendChild(st)
</script>
logs "one" and "three", and esm modules work as expected, no error
conclusion
from these test it seems that the attribute type="module" gets lost somewhere during registration
Test 2 is caused by a bug in jQuerys append function. it's fixed in jQuery 3.x, so i'm not going to fix it. I guess you have a reason to stick with 1.x...
Edit 2
fiddling around a bit more, i came up with a solution for Test 2 (without changing jQuery version).
The problem is, that jQuery uses .innerHTML in it's append() function. The fact that scripts not getting executed when inserted by .innerHTML is overcome by jQuery by evaling the textContent of the script elements. jQuery does this based on script type (which is absolutely correct, as there are script types out there that are not evalable) But at the time jQuery was written, there was no type="module"
So the script elements with type="module" do get inserted but not executed.
Knowing all this, the solution is again quite simple: get all scripts with type="module", create a new script element, copy the textContent over, and replace the old script with the new script.
By coincidence, upgrading to jQuery 3.x is in the plan for Node-RED 1.0 - and I've spent the morning on that - https://github.com/node-red/node-red/pull/2153 - so your workaround for that part wouldn't be needed. It isn't merged yet, but should be this week.
If you wanted to PR the other parts, we can review that. Please target the dev branch and not master.