Open HeavySnowJakarta opened 1 year ago
I'm not an expert myself, but this comment contains more explanation: https://github.com/holzschu/a-shell/issues/281#issuecomment-1508933511
I dont't think I can answer all your questions, but I can give more context.
jsc
is "JavaScript compiler", it's different from JavaScriptCore
, the Apple framework that executes JavaScript.jsc
executes a JavaScript file in a JavaScript environment. Most of your questions boil down to "which JavaScript environment?"
jsc
with no arguments executes JavaScript in a separate web page (that is not displayed). Advantages: we use Apple's fast JS engine, we have access to a browser environment, we can load WebAssembly.jsc --in-window
executes JavaScript in the web page that is currently displaying the terminal. Advantages: same as above, plus we can act on the terminal (change the cursor, as you said). This is because a-Shell uses hterm.org terminal for rendering text. You can look at hterm_all.js
for how it works, and how to change things. Inconvenients: you can completely break a-Shell if you're not careful.jsc_core
, or jsc
when running in-extension Shortcuts, executes JavaScript in a minimalist JavaScript environment (named JavaScriptCore). Nothing is defined here (not even global
). It's also not optimized (for security reasons, according to Apple).node.js
, the short answer is "I don't know". In theory, it should be possible to port npm
and install JS packages. I had a look at some point, but the source code of npm is hard to find, and the documentation basically assumes that you already have node
running. Porting node
is a lot of work (each new language is a lot of work, but node
is also poorly documented. Almost all of the documentation assumes you already have node, which brings a chicken-and-egg problem).jsc
and node
(as far as I understand the question): jsc
provides access to the file system using specific functions (type man jsc
for the documentation). It's not the same as node
, but it can do the work. jsc
and jsc --in-window
provide access to WebAssembly (it's disabled in jsc_core
by Apple, again for security reasons). By default, WebAssembly is designed to run a function inside JavaScript (but quickly), not interact with the rest of the system. wasi
is a glue to interface JavaScript with the rest of the system, providing standard C library functions. You have to load it explicitly (require('@wasmer/wasi/lib').WASI;
, in wasm.js
).I hope this helps you. Keep in mind that I'm not an expert in JavaScript. I only learned about it in order to make the terminal run.
For all questions related to node.js, the short answer is "I don't know". In theory, it should be possible to port npm and install JS packages. I had a look at some point, but the source code of npm is hard to find, and the documentation basically assumes that you already have node running. Porting node is a lot of work (each new language is a lot of work, but node is also poorly documented. Almost all of the documentation assumes you already have node, which brings a chicken-and-egg problem).
If you want to import pure node
, you may consider #611 which gives some ways to import it to iOS Apps. If you want to let jsc
do what node
does, it'll be much more challenging.
For all questions related to front-end projects, the answer is also "I don't know (but it's unlikely)". a-Shell is designed for command-line interface. You can maybe tweak it to run front-end projects, but you will likely encounter issues related to user interface.
For view
I noticed, I guess if a front-end web page can be packed to be "pure", just like saved web pages with a computer, which includes all src files to execute, but not designed to run on a server. In this case, it's not the JavaScript environment but WebKit (or call it Safari-inside) that works. I know it can view simple HTML files, but I'm not clear if more complex projects work.
Blink is more radical with it. It's terminal user interface can be turned to a Web interface. With it websites can be shown, vscode.dev for example.
But now it's not an essential thing obviously. At least we can run a "server" and use Safari to run it locally once location tracking is provided. If code-server
is proved to work some day, you can submit another App like Carnets with a built-in experience and out-of-box experience.
I've never met WebAssembly before. For its relation with JavaScript, I would like to research on JavaScriptCore first. For JavaScriptCore I have these problems:
node
than a browser environment. How does it goes differently fromnode
(except the differences of engines)?node.js
project runs above it? Some node projects use the apis provided bynode.js
, how to deal with them?wasi
?npm
is used to managenode
projects. If it's possible to port it tojsc
?view
to call system's api to view files. Is it possible to test front-end projects with it?jsc
, changing the cursor shape for example. Can you tell me more details of it?