a-shell icon indicating copy to clipboard operation
a-shell copied to clipboard

Jsc: can't find http

Open HeavySnowJakarta opened this issue 2 years ago • 12 comments

Now I'm learning node.js to understand jsc better. I'm using the following code:

const module=require("http");
module.createServer(function(request, response){
        response.writeHead(200, {'Content-Type': 'text/plain'});
        response.end('Hello, world!');
}).listen(8888);
console.log('Server running at http://127.0.0.1:8888/')

But it can't run:

jsc: Error in file require.js at line 209, column 52: Error: Could not find module http

I wonder how to install modules now.

HeavySnowJakarta avatar Apr 28 '23 12:04 HeavySnowJakarta

These are two questions.

One is how to install modules. require() is implemented here: https://github.com/holzschu/a-shell/blob/master/require.js, I'm not sure on how to modify it to allow looking at several directories. I think that's here: https://github.com/holzschu/a-shell/blob/f11fdf5f6e6256fcf6a33d075e333d7395458885/require.js#L228 but I'm not sure. Especially since I need to make it dependent on the home directory, which changes at each install.

The other is how to create a server. I'm almost sure that the flavor of JS we have in iOS will not be able to run a server on its own (but I could be wrong).

holzschu avatar Apr 28 '23 13:04 holzschu

The other is how to create a server. I'm almost sure that the flavor of JS we have in iOS will not be able to run a server on its own (but I could be wrong).

If a server can't be set, how Jupyter works then? How you made it to work?

HeavySnowJakarta avatar Apr 29 '23 04:04 HeavySnowJakarta

./node_modules? Maybe you have to see what they exactly are at that folder.

HeavySnowJakarta avatar Apr 29 '23 04:04 HeavySnowJakarta

I'm trying to edit config.paths now, but what is the separator? |, ;, : or space?

HeavySnowJakarta avatar Apr 29 '23 05:04 HeavySnowJakarta

I'm trying to edit config.paths now, but what is the separator? |, ;, : or space?

Emm it's a list 😂

HeavySnowJakarta avatar Apr 29 '23 05:04 HeavySnowJakarta

I'm back on this issue (because of markdown-it.js, see #665). I might make it work this time. If it works, there will be two place for modules: $APPDIR/node_modules and ~/Library/node_modules. I don't think there will be something like npm in the first run, but pkg install <packageName>. And adventurous users can place what they want in ~/Library/node_modules, with no guarantees that it'll work.

holzschu avatar Dec 01 '23 09:12 holzschu

I'm looking for install.sh of npm. It works with dash. We have jsc, tar and curl.

HeavySnowJakarta avatar Dec 03 '23 12:12 HeavySnowJakarta

the key part of install.sh:

echo "fetching: $url" >&2

cd "$TMP" \
  && curl -SsL -o npm.tgz "$url" \
  && $tar -xzf npm.tgz \
  && cd "$TMP"/package \
  && echo "removing existing npm" \
  && "$node" bin/npm-cli.js rm npm -gf --loglevel=silent \
  && echo "installing npm@$t" \
  && "$node" bin/npm-cli.js install -gf ../npm.tgz \
  && cd "$BACK" \
  && rm -rf "$TMP" \
  && echo "successfully installed npm@$t"

HeavySnowJakarta avatar Dec 03 '23 12:12 HeavySnowJakarta

Thanks a lot for that. My plan is to experiment with more JS packages first, see what works and what doesn't, then see if I can make an automatic install process.

holzschu avatar Dec 07 '23 13:12 holzschu

Thanks a lot for that.

My plan is to experiment with more JS packages first, see what works and what doesn't, then see if I can make an automatic install process.

When I have time I'll see if npm works. I really hope so.

HeavySnowJakarta avatar Dec 09 '23 09:12 HeavySnowJakarta

After a quick experiment with http-server and others, I can report: a lot of npm packages rely on "os", "fs" and "process". These can be replaced, partially, with jsc, but that means that the code needs to be edited to work. Also "portfinder" does not work with the "require.js" that I have (only one export is active).

holzschu avatar Dec 09 '23 10:12 holzschu

At least we should reproduce the built-in modules, such as os, fs, http, https, path, events. Then the remained would work.

HeavySnowJakarta avatar Dec 10 '23 12:12 HeavySnowJakarta