thanks for all the answers.
For my usecases i would see some pro’s and con’s.
One usecase is the timeline picker and here there are more users with differnet OS. So i’m looking for a ‘robust’ solution.
Pro: pure js
con: it dosen`t work (see below)
pro: short
con: it’s not portable, windows dosen’t know cat
pro: All my rules in one place in this module
con: I think the folder node_modules is not the right place for configs
I tried delete require.cache['../test-function.js']
with relative and absolute path.
Unfortunaly i get the following error message. The relative path as key nor the absolute path as key changing this behavior.
2023-05-13 12:24:24.192 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: Cannot delete property "/etc/openhab/automation/js/test-function.js" of undefined
at <js>.:program(Unknown) ~[?:?]
at org.graalvm.polyglot.Context.eval(Context.java:399) ~[?:?]
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:400) ~[?:?]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) ~[java.scripting:?]
at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:58) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:84) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:58) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:84) ~[?:?]
at org.openhab.core.automation.module.script.internal.ScriptEngineManagerImpl.loadScript(ScriptEngineManagerImpl.java:185) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptFileWatcher.createAndLoad(AbstractScriptFileWatcher.java:276) ~[?:?]
at org.openhab.automation.jsscripting.internal.fs.watch.JSScriptFileWatcher.createAndLoad(JSScriptFileWatcher.java:63) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptFileWatcher.importFile(AbstractScriptFileWatcher.java:256) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptFileWatcher.lambda$5(AbstractScriptFileWatcher.java:248) ~[?:?]
at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptFileWatcher.importFileWhenReady(AbstractScriptFileWatcher.java:246) ~[?:?]
at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptFileWatcher.processWatchEvent(AbstractScriptFileWatcher.java:223) ~[?:?]
at org.openhab.automation.jsscripting.internal.fs.watch.JSScriptFileWatcher.processWatchEvent(JSScriptFileWatcher.java:56) ~[?:?]
at org.openhab.core.service.WatchQueueReader.lambda$5(WatchQueueReader.java:357) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
2023-05-13 12:24:24.202 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/js/test-require.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot delete property "/etc/openhab/automation/js/test-function.js" of undefined
The require object exist and i can write this to the log:
console.info(require)
log-output:
2023-05-13 12:24:24.189 [INFO ] [tomation.script.file.test-require.js] - org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine$$Lambda$1652/0x6433ee28@4aebb7
Is there something to get access to the propertys of the require object?