Add support for specifying include paths to the nodejs API

I tried passing this as a component of the file name (uri style with a query),
but nodejs wants only valid paths for
require() calls. So instead this uses simply an environment variable.
This commit is contained in:
Simon Hausmann 2020-07-19 18:29:37 +02:00
parent a178b9b2e3
commit 0aaa163058

View file

@ -25,8 +25,14 @@ scoped_tls_hkt::scoped_thread_local!(static GLOBAL_CONTEXT:
fn load(mut cx: FunctionContext) -> JsResult<JsValue> {
let path = cx.argument::<JsString>(0)?.value();
let path = std::path::Path::new(path.as_str());
let include_paths = match std::env::var_os("SIXTYFPS_INCLUDE_PATH") {
Some(paths) => {
std::env::split_paths(&paths).filter(|path| !path.as_os_str().is_empty()).collect()
}
None => vec![],
};
let source = std::fs::read_to_string(&path).or_else(|e| cx.throw_error(e.to_string()))?;
let c = match sixtyfps_interpreter::load(source, &path, &[]) {
let c = match sixtyfps_interpreter::load(source, &path, &include_paths) {
Ok(c) => c,
Err(diag) => {
diag.print();