How to know which file(s) were entry points? #225

Closed
leeola opened this Issue Oct 8, 2012 · 4 comments

Projects

None yet

3 participants

@leeola

In Node.js you can use require.main to know when a file was executed directly. Is something like this possible with Browserify?

It appears require doesn't even exist during runtime (i assume it's parsed during compile), so is there any way to make a file know if it was the entry point?

Eg: if require.main == module { // do stuff }

@EndangeredMassa

Can you provide an example of why you would need to know that in a module?

@leeola

For the same reasons you might need that in normal Node.

Importing a file and executing a file are usually considered two distinct actions. So with Browserify not being able to specify this, you are left with a void.. Was this entry-file imported? As it might be during tests/etc, or was this file run directly.

I consider a module that "does something" when imported to be rather volatile. Browserify forces this onto you (i believe), so i feel compelled to isolate this file.

@substack
Owner

Files that execute directly with side-effects are probably a good thing to isolate from modules that export functionality explicitly. This feature does not fit very well with the v2 changes either.

@substack substack closed this Feb 22, 2013
@leeola

Files that execute directly with side-effects are probably a good thing to isolate from modules that export functionality explicitly.

I would like to not have them at all. There is no need for it in Node, why have a need for it in Browserify?

This feature does not fit very well with the v2 changes either.

Ah, oh well. Thanks for responding :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment