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

Extending require() further #36

Closed
somebody1234 opened this issue Jul 15, 2016 · 4 comments
Closed

Extending require() further #36

somebody1234 opened this issue Jul 15, 2016 · 4 comments

Comments

@somebody1234
Copy link

I would like an option which is a function that takes vm2's require as an argument and returns a new function that should be used instead of vm2's require.

@bmewj
Copy link

bmewj commented Jul 23, 2016

Somewhat relevant: I'm using a custom file system for user submitted code. Is there a way I can manually deal with local requires, like require('./otherUserSubmittedFile'), fetching the file from the custom file system and handing it over to vm2 to then sandbox?

Update:
Very rough, but have implemented something along the lines of custom/virtual files: https://github.com/bartjoyce/vm2-with-custom-fs

Usage, would be something like this:

NodeVM.file('/customfs/main.js', {
  require: {
    external: true,
    root: '/customfs/', // restrict local requires to within the custom fs
  },
  customfs: {
    getFileContents: (filename) => /* handle /customfs/ file read */,
    exists: (filename) => /* ... */,
    isDirectory: (filename) => /* ... */
  }
})

@callumlocke
Copy link

@bartjoyce I need the same thing! Your link is broken, did you move it somewhere?

@bmewj
Copy link

bmewj commented Mar 30, 2017

@callumlocke I've since moved on to other projects and have stopped maintaining the code. The code I wrote is here: https://github.com/bartjoyce/vm2/

It's 30 commits behind, but at least you can see the modifications I've made.

Important commit is this one: bmewj@302e910

I've made additional changes to vm2 that are not in my repo. If you want to see those too, let me know.

@stale
Copy link

stale bot commented Jan 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 27, 2019
@stale stale bot closed this as completed Feb 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants