GordonSmith / vscode-ojs

VS Code extension for ObservableHQ notebooks
https://marketplace.visualstudio.com/items?itemName=GordonSmith.observable-js
MIT License
58 stars 5 forks source link

fs/system apis #47

Open knoopx opened 1 year ago

knoopx commented 1 year ago

i see there's some fs module but I can't figure how to use. are fs/system apis supported in any way? what about running in a nodejs context? also what about CORS?

GordonSmith commented 1 year ago

In general if you:

import {xxx} from "@yyy/zzz";

... OR ...

data = FileAttachment("athletes.csv").csv({typed: true})

It will resolve back to ObservableHQ.com

But if you use relative paths:

import {xxx} from "./otherNotebook.ojsnb";

... OR ...

data = FileAttachment("./data/athletes.csv").csv({typed: true})

It will resolve locally.

Finally you can use "fetch" to get local files with relative paths or full URLs to get remote ones.

GordonSmith commented 1 year ago

You can also access all Observable StdLib functions: https://github.com/observablehq/stdlib

knoopx commented 1 year ago

in ojb/omd preview neither local or remote fetch works, local throws permission error and remote cors errors. FileAttachment works but you can't glob/list directories. unlocking net/fs/system apis will definitely make this project way more useful. have you tried mixing electron renderer+node integration with @hpcc-js/observable-md? about to try myself as this has same limitations as https://github.com/asg017/dataflow

GordonSmith commented 1 year ago

Sorry - I assumed you were using the ObservableJS Notebook feature (create a file with a ".ojsnb" file extension)...

If you give me a code snippet as an example, I will see what I can come up with - it should be relativly easy enough to find a workaround with the built in preview, but when exported to a standalone html page then you will be at the mercy of the usual CORs rules between hosting web server and API server.

GordonSmith commented 1 year ago

@knoopx FYI @hpcc-js/observable-md is being deprecated soon, you should switch to @hpcc-js/obersvablehq-compiler