-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing the GraalJS package with OH3 #2
Comments
So you've done everything right, however I don't yet have So I would suggest to either:
Either way, I'll update this once |
Right now I'm still using the javascript helpers provided for OH 2.5 with own Utils and same updates for OH3. Will it work to keep the set-up, maybe with minor adaptions to GraalJS? That would allow me a staggered migration ;-) |
Additional question: Going forward will I need to install npm to the Openhab docker image? That feels unhandy in terms of updates. |
npm shouldn't be required in the docker image. It only downloads and places the JS files, so can do it from the host. It's not needed to run the downloaded JS. |
As for migration; this is possible, but not as simple as you may expect (it's what I originally did, to try to keep compatibility, but ultimately abandoned). The reason is the global namespacing in the 2.5 helpers; almost all variables in the 2.5 helpers are dropped into the global namespace, whereas the pattern I use for 3.0 is the same as standard module-based JS, where they are put into a specific namespace. So for example: With namespacing:
Without namespacing:
I tried to ease migration by explicitly copying namespaced properties into the global namespace to try to emulate the 2.5 approach. This mostly worked, but there were unexpected clashes and overrides all the time that were frustrating. Saying this, if your usage of the 2.5 helpers is simple, it could certainly work. At the very least - examples of how you migrate could certainly help others. |
I have published a new version of |
Today I tried again. Following steps I did:
ohj package.json indicates right version:
Now I get this error: When changing the rule after startup:
|
I created another js file with some dummy set-up which works, so it seems I'm still struggling with the npm ohj package. Any idea what is going wrong? Dummy script, that works:
|
Ok I think I found one issue. In the readme you refer to install the npm package to the community folder, but it seems it has to be in the personal folder. Now I'm getting this error:
|
Sorry that you're having so many issues! I can see a few causes here:
|
Also: what version of I ask this because it's failing to load |
Here's a build of ohj-support: |
I backtraced the error to the osgi.js. the bundleContext seems to be undefined. |
Oh, and great news that the dummy script works - that signifies that the base JS + modules are working (plus I see it has ES6+ features in there like |
I've added the support addon, still bundleContext seems to be undefined in osgi.js. Any idea? |
I got it to work with changing the function "lookupService" in osgi,js like this (quick hack...):
|
Great! Thanks for letting me know. It looks like you are not resolving Either way, I wouldn't worry about it if I were you - your hack should work fine and I'll try to figure out why the standard version is not resolving. |
I'll use ohj as a starting point and combine with own scripts. For example, I've added most of the other OH triggers and conditions to the helpers... |
For the record: I was now able to sort out the issues I reported in jpg0/ohj#19 (basically a duplicate of this issue) with these steps:
I have just a limited set of rules defined with JS for now, but at least they are working now again w/ OH3! |
I've merged jpg0/ohj#20 and also included the fix from @LukasA83. Still not really sure why it was failing, but I'm guessing it's something related to the startup ordering issues in OH3. |
hi @jpg0,
as discussed in separate thread, I tried your package, but basically I struggle on the installation, I believe.
Setup:
OH3 Build 2094 (docker debian) on Raspi, installed npm 6.14.10.
"npm i ohj" run successfully from $OPENHAB_CONF/automation/lib/javascript/community.
I created a test rule:
`with(require('ohj').fluent){
}`
Somehow it seems not to work, logs:
15:06:27.278 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/javascript/personal/testGraalvm.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'ohj'
The text was updated successfully, but these errors were encountered: