Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run a single javascript file #11

Open
dominictarr opened this issue Aug 6, 2016 · 9 comments
Open

run a single javascript file #11

dominictarr opened this issue Aug 6, 2016 · 9 comments
Labels

Comments

@dominictarr
Copy link

How do I run a single javascript file? with browserify it's really easy to take a lot of javascript and run it on any javascript platform, however nucleus seems to insist on running directories that is constraining as often I just want to run, say, a test script.

I did get this to work, https://github.com/dominictarr/nucleus-run

and I understand that it is ment to be possible to create a new nucleus command by just appending a zip of the code? I tried this but was not able to find any documentation.

zip n ../nucleus-run/
cat ./target/debug/nucleus n.zip > nr

but that didn't seem to work.

bundling the zip file is a pretty great idea, but a single js file is still the lowest common denomenator of javascript, so it seems reasonable that works out of the box.

@Fishrock123
Copy link
Member

@dominictarr does -N --no-bundle work for what you want? (for single files or "node like")

It does not currently work with zips though.

I had this same problem with the original version of nucleus which is pretty much why I've added this.

See also nucleus-js/design#22 -- @creationix seems to think people will get confused and have problems with programs that were accessing files during testing but can't when zipped up. Not sure I agree though.

and I understand that it is ment to be possible to create a new nucleus command by just appending a zip of the code? I tried this but was not able to find any documentation.

Right, if you append a zip that has a main.js in it, it will execute starting with that file from within the zip.

This is documented in my PR for CLI options to the spec in https://github.com/nucleus-js/design/pull/30/files#diff-7becf02ad489c02e98feeccea97f1ad4R7, but should also be stated elsewhere.

(It should also be configurable ala #8)

@Fishrock123
Copy link
Member

(the fact that both you and I have had to ask this question means it is definitely a problem lol)

@dominictarr
Copy link
Author

oh, thanks!
-N, --no-bundle do not execute as a bundle
did not sound like what i was looking for
-f FILE execute a single file
would have been more obvious.

@Fishrock123
Copy link
Member

Makes sense, we can totally change it to that!

@dominictarr
Copy link
Author

hmm, okay so I recalled that zip files have an index at the end, and for that reason I thought maybe you could just append the zip. If you have to frame the zip, could you also have a framing that just appends a single file? also, would it be possible to have multiple files or zips that each bootstrap a layer?

@Fishrock123
Copy link
Member

Fishrock123 commented Aug 7, 2016

hmm, okay so I recalled that zip files have an index at the end, and for that reason I thought maybe you could just append the zip. If you have to frame the zip, could you also have a framing that just appends a single file?

If what you are asking is like this example from the design repo, then that would be correct:

# Manually build a standalone binary with nucleus embedded.
cat /usr/local/bin/nucleus app.zip > app
chmod +x app
./app args...

also, would it be possible to have multiple files or zips that each bootstrap a layer?

I have literally no idea, maybe @creationix knows

@dominictarr
Copy link
Author

I remembered @creationix describing how luvit worked, and structure of zip files make this easy:
https://en.wikipedia.org/wiki/Zip_(file_format)#Structure

It seems like a neat idea, but I can just imagine needing to have multiple layers of bootstrapping.

hmm, I guess you can jump to the directory, and that tells you the length of the file, and then you can just work backwards. you could apply this same idea to a file, by just appending a length as the last line..

cat $(which nucleus) app.js $(stat -c %s log.js)  > nukeapp

okay that might need a empty line at the end of app.js
but then you could read back, and then execute forward, and nukeapp could even be extended this way, it would be composable.

@creationix
Copy link
Member

There is no explicit framing in the design outside of the zip format itself.

Is it really that hard to make a zip file containing a single file? The nucleus CLI tool should make the zip for you even. I guess we just need a mode where you pass it a file instead of a directory and it creates a zip containing only that file as main.js. I would think that would work well as long as your single file doesn't expect ant other files to be present in the bundle.

@dominictarr
Copy link
Author

@creationix sure that would work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants