[jsscripting] Fix regressions from #14135 & Log stack on `IllegalArgumentException` (#14142)

* [jsscripting] Fix bundling of global script & regression from #14135

Fixes the regression from https://github.com/openhab/openhab-addons/pull/14135#issuecomment-1369231126.

While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint).

* [jsscripting] Enable stack logging for IllegalArgumentExceptions
* [jsscripting] Upgrade openhab-js to 3.2.4
* [jsscripting] Update README for recent PR

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
Florian Hotze 2023-01-03 20:45:23 +01:00 committed by GitHub
parent 7c3fbfdde3
commit f082df923f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 6 deletions

View File

@ -1,6 +1,6 @@
# JavaScript Scripting # JavaScript Scripting
This add-on provides support for JavaScript (ECMAScript 2021+) that can be used as a scripting language within automation rules. This add-on provides support for JavaScript (ECMAScript 2022+) that can be used as a scripting language within automation rules.
Also included is [openhab-js](https://github.com/openhab/openhab-js/), a fairly high-level ES6 library to support automation in openHAB. It provides convenient access Also included is [openhab-js](https://github.com/openhab/openhab-js/), a fairly high-level ES6 library to support automation in openHAB. It provides convenient access
to common openHAB functionality within rules including items, things, actions, logging and more. to common openHAB functionality within rules including items, things, actions, logging and more.

View File

@ -24,7 +24,7 @@
</bnd.importpackage> </bnd.importpackage>
<graal.version>22.0.0.2</graal.version> <!-- DO NOT UPGRADE: 22.0.0.2 is the latest version working on armv7l / OpenJDK 11.0.16 & armv7l / Zulu 17.0.5+8 --> <graal.version>22.0.0.2</graal.version> <!-- DO NOT UPGRADE: 22.0.0.2 is the latest version working on armv7l / OpenJDK 11.0.16 & armv7l / Zulu 17.0.5+8 -->
<oh.version>${project.version}</oh.version> <oh.version>${project.version}</oh.version>
<ohjs.version>openhab@3.2.1</ohjs.version> <ohjs.version>openhab@3.2.4</ohjs.version>
</properties> </properties>
<build> <build>
@ -66,11 +66,23 @@
<goal>npm</goal> <goal>npm</goal>
</goals> </goals>
<configuration> <configuration>
<!--suppress UnresolvedMavenProperty -->
<arguments>install ${ohjs.version} webpack@5.75.0 webpack-cli@4.10.0</arguments> <!-- webpack-cli >= 5.0.0 doesn't properly process the given entrypoint --> <arguments>install ${ohjs.version} webpack@5.75.0 webpack-cli@4.10.0</arguments> <!-- webpack-cli >= 5.0.0 doesn't properly process the given entrypoint -->
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>npx webpack</id> <id>npx webpack (openhab-js globals injection)</id>
<goals>
<goal>npx</goal>
</goals>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<arguments>webpack -c ./node_modules/openhab/@globals-webpack.config.js --entry
./node_modules/openhab/@openhab-globals.js -o ./dist</arguments>
</configuration>
</execution>
<execution>
<id>npx webpack (openhab-js)</id>
<goals> <goals>
<goal>npx</goal> <goal>npx</goal>
</goals> </goals>

View File

@ -39,6 +39,9 @@ class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable & AutoClosea
@Override @Override
public Exception afterThrowsInvocation(Exception e) { public Exception afterThrowsInvocation(Exception e) {
Throwable cause = e.getCause(); Throwable cause = e.getCause();
if (cause instanceof IllegalArgumentException) {
STACK_LOGGER.error("Failed to execute script:", e);
}
if (cause instanceof PolyglotException) { if (cause instanceof PolyglotException) {
STACK_LOGGER.error("Failed to execute script:", cause); STACK_LOGGER.error("Failed to execute script:", cause);
} }

View File

@ -71,7 +71,6 @@ public class OpenhabGraalJSScriptEngine
private static final Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class); private static final Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class);
private static Source GLOBAL_SOURCE; private static Source GLOBAL_SOURCE;
static { static {
try { try {
GLOBAL_SOURCE = Source.newBuilder("js", getFileAsReader("node_modules/@jsscripting-globals.js"), GLOBAL_SOURCE = Source.newBuilder("js", getFileAsReader("node_modules/@jsscripting-globals.js"),
@ -82,7 +81,6 @@ public class OpenhabGraalJSScriptEngine
} }
private static Source OPENHAB_JS_SOURCE; private static Source OPENHAB_JS_SOURCE;
static { static {
try { try {
OPENHAB_JS_SOURCE = Source OPENHAB_JS_SOURCE = Source
@ -92,7 +90,7 @@ public class OpenhabGraalJSScriptEngine
throw new RuntimeException("Failed to load @openhab-globals.js", e); throw new RuntimeException("Failed to load @openhab-globals.js", e);
} }
} }
private static String OPENHAB_JS_INJECTION_CODE = "Object.assign(this, require('openhab'));"; private static final String OPENHAB_JS_INJECTION_CODE = "Object.assign(this, require('openhab'));";
private static final String REQUIRE_WRAPPER_NAME = "__wraprequire__"; private static final String REQUIRE_WRAPPER_NAME = "__wraprequire__";
/** Final CommonJS search path for our library */ /** Final CommonJS search path for our library */