[jsscripting] Fix node_modules handling (#14398)
Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
f3d48681b0
commit
223deffcfd
|
@ -89,8 +89,8 @@ public final class GraalJSScriptEngineFactory implements ScriptEngineFactory {
|
|||
if (!SCRIPT_TYPES.contains(scriptType)) {
|
||||
return null;
|
||||
}
|
||||
return new DebuggingGraalScriptEngine<>(
|
||||
new OpenhabGraalJSScriptEngine(injectionEnabled, useIncludedLibrary, jsScriptServiceUtil));
|
||||
return new DebuggingGraalScriptEngine<>(new OpenhabGraalJSScriptEngine(injectionEnabled, useIncludedLibrary,
|
||||
jsScriptServiceUtil, jsDependencyTracker));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -139,7 +139,7 @@ public class OpenhabGraalJSScriptEngine
|
|||
* lifecycle and provides hooks for scripts to do so too.
|
||||
*/
|
||||
public OpenhabGraalJSScriptEngine(boolean injectionEnabled, boolean useIncludedLibrary,
|
||||
JSScriptServiceUtil jsScriptServiceUtil) {
|
||||
JSScriptServiceUtil jsScriptServiceUtil, JSDependencyTracker jsDependencyTracker) {
|
||||
super(null); // delegate depends on fields not yet initialised, so we cannot set it immediately
|
||||
this.injectionEnabled = injectionEnabled;
|
||||
this.useIncludedLibrary = useIncludedLibrary;
|
||||
|
@ -149,7 +149,8 @@ public class OpenhabGraalJSScriptEngine
|
|||
|
||||
delegate = GraalJSScriptEngine.create(ENGINE,
|
||||
Context.newBuilder("js").allowExperimentalOptions(true).allowAllAccess(true)
|
||||
.allowHostAccess(HOST_ACCESS).option("js.commonjs-require-cwd", JSDependencyTracker.LIB_PATH)
|
||||
.allowHostAccess(HOST_ACCESS)
|
||||
.option("js.commonjs-require-cwd", jsDependencyTracker.getLibraryPath().toString())
|
||||
.option("js.nashorn-compat", "true") // Enable Nashorn compat mode as openhab-js relies on
|
||||
// accessors, see
|
||||
// https://github.com/oracle/graaljs/blob/master/docs/user/NashornMigrationGuide.md#accessors
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
package org.openhab.automation.jsscripting.internal.fs.watch;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
|
||||
|
@ -40,15 +39,11 @@ public class JSDependencyTracker extends AbstractScriptDependencyTracker {
|
|||
|
||||
private final Logger logger = LoggerFactory.getLogger(JSDependencyTracker.class);
|
||||
|
||||
public static final String LIB_PATH = String.join(File.separator, "automation", "js", "node_modules");
|
||||
private static final String LIB_PATH = String.join(File.separator, "automation", "js", "node_modules");
|
||||
|
||||
@Activate
|
||||
public JSDependencyTracker(@Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
|
||||
super(watchService, LIB_PATH);
|
||||
|
||||
if (Files.isRegularFile(this.libraryPath)) {
|
||||
logger.warn("Trying to watch directory '{}', however it is a file", this.libraryPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
|
|
Loading…
Reference in New Issue