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

support for recursive requires (creating a virtual enviornment) #27

Closed
wants to merge 8 commits into from

Conversation

alonbardavid
Copy link
Collaborator

I've added support for recursive requires - so that you can contain an entire virtual enviornment in sandbox.
That is if you sandbox a module that requires another module, the second module will also be loaded using SandboxedModule (using the same globals as the original sandboxed module)

You can enable it by passing options.recursive:true .

The new module creates a shared global state and provides it's own module cache implementation (of a sort).

@domenic
Copy link
Collaborator

domenic commented Oct 30, 2013

Oh awesome!! I've wanted this for a long time; see #11. I'll have time to review the code this weekend, or @searls can do it if he has time.

I think this should be the default, not necessary to enable through options.

@felixge
Copy link
Owner

felixge commented Oct 31, 2013

@Illniyar awesome, thank you so much. One question: It looks like your PR changed indention level from 2 to 4 spaces?

@alonbardavid
Copy link
Collaborator Author

sorry, sometimes my IDE does that. I've changed it back to 2 spaces.

@alonbardavid
Copy link
Collaborator Author

If you enable it by default you'll break backwards compatability (don't know if thats an issue in a testing oriented library, is anyone using this in live enviornments?)

@felixge
Copy link
Owner

felixge commented Oct 31, 2013

@Illniyar awesome, this makes the patch much easier to read. Breaking b/c is still ok I think, it's not like this library is used by a ton of people. So the focus should be to make it better / have reasonable defaults.

So I just gave you push access to merge this once your're happy with it (feel free to wait if @domenic has some time to provide more feedback). If you give me your npm account I'll add you there as well.

The only thing missing from my perspective is docs about the new behavior.

__filename: this.filename,
__dirname: path.dirname(this.filename),
module: this.module,
exports: this.exports
};
locals.require = this._requireInterceptor()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unnecessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is necessary for partial module loading support, which is required for loading modules in a cycle.
the interceptor caches exports before it finishes loading the module so that if another module requires the first module in a cycle we won't reload the module (which is how node's standard module caching works).
This means we need the exports variable assigned before we call the interceptor.
Otherwise we'll have an infinite loop if two modules require eachother in a cycle.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, cool. For something that esoteric though, it would be important to include a comment so that it doesn't get "refactored" later.

@domenic
Copy link
Collaborator

domenic commented Oct 31, 2013

Code review over, lots of nitpicks, nothing substantial. Awesome to have you on the team! :D

@alonbardavid
Copy link
Collaborator Author

I've committed changes based on the code review comments. Let me know if I missed something.

@felixge
Copy link
Owner

felixge commented Nov 1, 2013

💖 thx for reviewing in detail @domenic

@sindresorhus
Copy link

Can this be merged?

@buschtoens
Copy link

So... I kinda need this. Will you folks merge it or do we have to use the fork?

Poking @felixge @Illniyar @domenic :)

@domenic
Copy link
Collaborator

domenic commented Jun 11, 2014

Merged as 350321b; 1.0 release coming soon.

@domenic domenic closed this Jun 11, 2014
@buschtoens
Copy link

Awesome guys. Thanks!

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

Successfully merging this pull request may close these issues.

5 participants